Reproduced VTK class Video Slice moving straight line get gray value

Source: Internet
Author: User

#include "stdafx.h"
#include "VtkActor.h"
#include "VtkCamera.h"
#include "VtkCommand.h"
#include "VtkImageData.h"
#include "VtkImagePlaneWidget.h"
#include "VtkInteractorEventRecorder.h"
#include "vtkKochanekSpline.h"
#include "VtkOutlineFilter.h"
#include "vtkparametricspline. h"
#include "vtkPlaneSource.h"
#include "VtkPointData.h"
#include "VtkPolyData.h"
#include "VtkPolyDataMapper.h"
#include "VtkProbeFilter.h"
#include "VtkProperty.h"
#include "VtkProperty2D.h"
#include "VtkRenderWindow.h"
#include "VtkRenderWindowInteractor.h"
#include "VtkRenderer.h"
#include "VtkSplineWidget.h"
#include "VtkTextProperty.h"
#include "VtkVolume16Reader.h"
#include "VtkXYPlotActor.h"

#include "VtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "VtkDebugLeaks.h"

Char tsweventlog[] =
"# streamversion 1\n"
"Charevent 133 0 0 98 1 i\n"
"Keyreleaseevent 133 0 0 98 1 i\n"
"Mousemoveevent 133 0 0 0 0 i\n"
"Rightbuttonpressevent 133 0 0 0 0 i\n"
"Mousemoveevent 133 123 0 0 0 0 i\n"
"Mousemoveevent 133 119 0 0 0 0 i\n"
"Mousemoveevent 0 0 0 0 i\n"
"Mousemoveevent 111 0 0 0 0 i\n"
"Mousemoveevent 107 0 0 0 0 i\n"
"Rightbuttonreleaseevent 107 0 0 0 0 i\n"
"Mousemoveevent 129 0 0 0 0 i\n"
"Leftbuttonpressevent 129 0 0 0 0 i\n"
"Mousemoveevent 0 0 0 0 i\n"
"Mousemoveevent 135 0 0 0 0 i\n"
"Mousemoveevent 143 0 0 0 0 i\n"
"Mousemoveevent 131 0 0 0 0 i\n"
"Mousemoveevent 159 0 0 0 0 i\n"
"Mousemoveevent 129 165 0 0 0 0 i\n"
"Mousemoveevent 127 0 0 0 0 i\n"
"mousemoveevent 176 0 0 0 0 i\n"
"Mousemoveevent 124 181 0 0 0 0 i\n"
"Mousemoveevent 122 183 0 0 0 0 i\n"
"Leftbuttonreleaseevent 122 183 0 0 0 0 i\n"
"Mousemoveevent 133 163 0 0 0 0 i\n"
"Middlebuttonpressevent 133 163 0 0 0 0 i\n"
"Mousemoveevent 161 0 0 0 0 i\n"
"Mousemoveevent 158 0 0 0 0 i\n"
"Mousemoveevent 124 155 0 0 0 0 i\n"
"Mousemoveevent 151 0 0 0 0 i\n"
"Mousemoveevent 147 0 0 0 0 i\n"
"Mousemoveevent 118 146 0 0 0 0 i\n"
"Mousemoveevent 121 148 0 0 0 0 i\n"
"Mousemoveevent 123 0 0 0 0 i\n"
"Mousemoveevent 154 0 0 0 0 i\n"
"Mousemoveevent 129 158 0 0 0 0 i\n"
"Mousemoveevent 161 0 0 0 0 i\n"
"Mousemoveevent 134 165 0 0 0 0 i\n"
"Mousemoveevent 136 168 0 0 0 0 i\n"
"Middlebuttonreleaseevent 136 168 0 0 0 0 i\n"
"Mousemoveevent 178 186 0 0 0 0 i\n"
"Keypressevent 178 186-128 0 0 1 control_l\n"
"Middlebuttonpressevent 178 186 8 0 0 0 control_l\n"
"Mousemoveevent 178 185 8 0 0 0 control_l\n"
"Mousemoveevent 179 183 8 0 0 0 control_l\n"
"Mousemoveevent 179 181 8 0 0 0 control_l\n"
"Mousemoveevent 179 179 8 0 0 0 control_l\n"
"Mousemoveevent 179 177 8 0 0 0 control_l\n"
"Mousemoveevent 179 175 8 0 0 0 control_l\n"
"Mousemoveevent 179 173 8 0 0 0 control_l\n"
"Mousemoveevent 179 171 8 0 0 0 control_l\n"
"Mousemoveevent 177 169 8 0 0 0 control_l\n"
"Mousemoveevent 176 167 8 0 0 0 control_l\n"
"Mousemoveevent 174 165 8 0 0 0 control_l\n"
"Mousemoveevent 172 164 8 0 0 0 control_l\n"
"Mousemoveevent 171 163 8 0 0 0 control_l\n"
"Middlebuttonreleaseevent 171 163 8 0 0 0 control_l\n"
"Keyreleaseevent 171 163 0 0 0 1 control_l\n"
"Mousemoveevent 167 0 0 0 0 control_l\n"
"Middlebuttonpressevent 167 0 0 0 0 control_l\n"
"Mousemoveevent 172 167 0 0 0 0 control_l\n"
"Mousemoveevent 176 167 0 0 0 0 control_l\n"
"Mousemoveevent 181 167 0 0 0 0 control_l\n"
"Mousemoveevent 188 167 0 0 0 0 control_l\n"
"Mousemoveevent 198 165 0 0 0 0 control_l\n"
"Mousemoveevent 205 163 0 0 0 0 control_l\n"
"Mousemoveevent 211 161 0 0 0 0 control_l\n"
"Mousemoveevent 216 0 0 0 0 control_l\n"
"Mousemoveevent 222 158 0 0 0 0 control_l\n"
"Middlebuttonreleaseevent 222 158 0 0 0 0 control_l\n"
"Mousemoveevent 158 0 0 0 0 control_l\n"
"Middlebuttonpressevent 158 0 0 0 0 control_l\n"
"Mousemoveevent 229 156 0 0 0 0 control_l\n"
"Mousemoveevent 228 153 0 0 0 0 control_l\n"
"Mousemoveevent 226 0 0 0 0 control_l\n"
"Mousemoveevent 224 148 0 0 0 0 control_l\n"
"Mousemoveevent 222 145 0 0 0 0 control_l\n"
"Mousemoveevent 141 0 0 0 0 control_l\n"
"Mousemoveevent 216 135 0 0 0 0 control_l\n"
"Mousemoveevent 214 129 0 0 0 0 control_l\n"
"Mousemoveevent 212 123 0 0 0 0 control_l\n"
"Mousemoveevent 209 118 0 0 0 0 control_l\n"
"Mousemoveevent 207 113 0 0 0 0 control_l\n"
"Mousemoveevent 204 109 0 0 0 0 control_l\n"
"Mousemoveevent 202 0 0 0 0 control_l\n"
"Mousemoveevent 103 0 0 0 0 control_l\n"
"Mousemoveevent 198 0 0 0 0 control_l\n"
"mousemoveevent 196 0 0 0 0 control_l\n"
"Mousemoveevent 194 0 0 0 0 control_l\n"
"Middlebuttonreleaseevent 194 0 0 0 0 control_l\n"
"Mousemoveevent 254 98 0 0 0 0 control_l\n"
"Middlebuttonpressevent 254 98 0 0 0 0 control_l\n"
"Mousemoveevent 254 0 0 0 0 control_l\n"
"Mousemoveevent 254 104 0 0 0 0 control_l\n"
"Mousemoveevent 255 108 0 0 0 0 control_l\n"
"Mousemoveevent 255 0 0 0 0 control_l\n"
"Mousemoveevent 255 0 0 0 0 control_l\n"
"Mousemoveevent 255 0 0 0 0 control_l\n"
"Mousemoveevent 124 0 0 0 0 control_l\n"
"Mousemoveevent 257 0 0 0 0 control_l\n"
"Mousemoveevent 257 0 0 0 0 control_l\n"
"Mousemoveevent 257 136 0 0 0 0 control_l\n"
"Mousemoveevent 258 141 0 0 0 0 control_l\n"
"Mousemoveevent 258 146 0 0 0 0 control_l\n"
"Mousemoveevent 258 151 0 0 0 0 control_l\n"
"Mousemoveevent 258 157 0 0 0 0 control_l\n"
"Mousemoveevent 258 159 0 0 0 0 control_l\n"
"Middlebuttonreleaseevent 206 0 0 0 0 control_l\n"
;

Callback for the image plane widget interaction
Class Vtkipwcallback:public Vtkcommand
{
Public
Static Vtkipwcallback *new ()
{return new Vtkipwcallback;}
virtual void Execute (Vtkobject *caller, unsigned long, void*)
{
Vtkimageplanewidget *planewidget = reinterpret_cast<vtkimageplanewidget*> (caller);
if (planewidget->getplaneorientation () = = 3)
{
Spline->setprojectionposition (0);
}
Else
{
Spline->setprojectionposition (Planewidget->getsliceposition ());
}
Spline->getpolydata (Poly);
}
Vtkipwcallback (): Spline (0), Poly (0) {};
Vtksplinewidget* Spline;
vtkpolydata* Poly;
};

Callback for the Spline widget interaction
Class Vtkswcallback:public Vtkcommand
{
Public
Static Vtkswcallback *new ()
{return new Vtkswcallback;}
virtual void Execute (Vtkobject *caller, unsigned long, void*)
{
Vtksplinewidget *spline = reinterpret_cast<vtksplinewidget*> (caller);
Spline->getpolydata (Poly);
}
Vtkswcallback ():P oly (0) {};
vtkpolydata* Poly;
};

int main (int argc, char *argv[])
{
char* fname = Vtktestutilities::expanddatafilename (argc, argv, "Data/headsq/quarter");

vtkvolume16reader* V16 = Vtkvolume16reader::new ();
V16->setdatadimensions (64, 64);
V16->setdatabyteordertolittleendian ();
V16->setimagerange (1, 93);
V16->setdataspacing (3.2, 3.2, 1.5);
V16->setfileprefix ("E://VTK 5.6/vtkdata/data/headsq/quarter");
V16->setdatamask (0X7FFF);
V16->update ();

Delete[] fname;

vtkrenderer* ren1 = Vtkrenderer::new ();
vtkrenderer* ren2 = Vtkrenderer::new ();
vtkrenderwindow* Renwin = Vtkrenderwindow::new ();
Renwin->setmultisamples (0);
Renwin->addrenderer (REN1);
Renwin->addrenderer (REN2);
vtkrenderwindowinteractor* Iren = Vtkrenderwindowinteractor::new ();
Iren->setrenderwindow (Renwin);

vtkoutlinefilter* outline = vtkoutlinefilter::new ();
Outline->setinputconnection (V16->getoutputport ());

vtkpolydatamapper* outlinemapper = Vtkpolydatamapper::new ();
Outlinemapper->setinputconnection (Outline->getoutputport ());

vtkactor* outlineactor = Vtkactor::new ();
Outlineactor->setmapper (Outlinemapper);

  vtkimageplanewidget* IPW = Vtkimageplanewidget::new ();
    Ipw->displaytexton ();
    Ipw->textureinterpolateoff ();
    Ipw->usercontrolledlookuptableoff ();
    Ipw->setinput (V16->getoutput ());
    Ipw->keypressactivationon ();
    ipw->setkeypressactivationvalue (' x ');
    Ipw->setresliceinterpolatetonearestneighbour ();
    Ipw->setinteractor (Iren);
    ipw->setplaneorientationtoxaxes ();
    Ipw->setsliceindex (32);
    Ipw->getplaneproperty ()->setcolor (1,0,0);

  vtksplinewidget* spline = Vtksplinewidget::new ();
    Spline->setinteractor (Iren);
    Spline->setinput (V16->getoutput ());
    spline->setpriority (1.0);
    Spline->keypressactivationoff ();
    spline->placewidget ();
    Spline->projecttoplaneon ();
    spline->setprojectionnormal (0);
    spline->setprojectionposition (102.4); //initial plane oriented position
     Spline->setprojectionnormal (3); Allow arbitrary oblique orientations
    spline->setplanesource (
       static_cast<vtkplanesource*> (Ipw->getpolydataalgorithm ()));


Specify the type of spline (change from default vtkcardinalspline)
vtkkochanekspline* xspline = Vtkkochanekspline::new ();
vtkkochanekspline* yspline = Vtkkochanekspline::new ();
vtkkochanekspline* zspline = Vtkkochanekspline::new ();

vtkparametricspline* para = Spline->getparametricspline ();

Para->setxspline (Xspline);
Para->setyspline (Yspline);
Para->setzspline (Zspline);

Xspline->delete ();
Yspline->delete ();
Zspline->delete ();

vtkpolydata* poly = Vtkpolydata::new ();
Spline->getpolydata (poly);

vtkprobefilter* probe = Vtkprobefilter::new ();
Probe->setinput (poly);
Probe->setsource (V16->getoutput ());

vtkipwcallback* IPWCB = Vtkipwcallback::new ();
Ipwcb->spline = Spline;
Ipwcb->poly = Poly;

Ipw->addobserver (VTKCOMMAND::INTERACTIONEVENT,IPWCB);

vtkswcallback* SWCB = Vtkswcallback::new ();
Swcb->poly = Poly;

Spline->addobserver (VTKCOMMAND::INTERACTIONEVENT,SWCB);

vtkimagedata* data = V16->getoutput ();
double* range = Data->getpointdata ()->getscalars ()->getrange ();

vtkxyplotactor* profile = Vtkxyplotactor::new ();
Profile->addinput (Probe->getoutput ());
Profile->getpositioncoordinate ()->setvalue (0.05, 0.05, 0);
Profile->getposition2coordinate ()->setvalue (0.95, 0.95, 0);
Profile->setxvaluestonormalizedarclength ();
Profile->setnumberofxlabels (6);
Profile->settitle ("Profile Data");
Profile->setxtitle ("s");
Profile->setytitle ("I (s)");
Profile->setxrange (0, 1);
Profile->setyrange (Range[0], range[1]);
Profile->getproperty ()->setcolor (0, 0, 0);
Profile->getproperty ()->setlinewidth (2);
Profile->setlabelformat ("%g");
vtktextproperty* Tprop = Profile->gettitletextproperty ();
Tprop->setcolor (0.02,0.06,0.62);
Tprop->setfontfamilytoarial ();
Profile->setaxistitletextproperty (Tprop);
Profile->setaxislabeltextproperty (Tprop);
Profile->settitletextproperty (Tprop);

Ren1->setbackground (0.1, 0.2, 0.4);
Ren1->setviewport (0, 0, 0.5, 1);
Ren1->addactor (Outlineactor);

Ren2->setbackground (1, 1, 1);
Ren2->setviewport (0.5, 0, 1, 1);
REN2->ADDACTOR2D (profile);

Renwin->setsize (600, 300);

Ipw->on ();
Ipw->setinteraction (0);
Ipw->setinteraction (1);
Spline->on ();
Spline->setnumberofhandles (4);
Spline->setnumberofhandles (5);
Spline->setresolution (399);

Set up an interesting viewpoint
vtkcamera* camera = Ren1->getactivecamera ();
Camera->elevation (110);
Camera->setviewup (0, 0,-1);
Camera->azimuth (45);
Camera->setfocalpoint (100.8,100.8,69);
Camera->setposition (560.949, 560.949,-167.853);
Ren1->resetcameraclippingrange ();

Position The actors
Renwin->render ();
Iren->seteventposition (200,200);
Iren->setkeycode (' R ');
Iren->invokeevent (Vtkcommand::charevent,null);
Ren1->resetcameraclippingrange ();
Renwin->render ();
Iren->setkeycode (' t ');
Iren->invokeevent (Vtkcommand::charevent,null);

Playback recorded Events
Vtkinteractoreventrecorder *recorder = Vtkinteractoreventrecorder::new ();
Recorder->setinteractor (Iren);
Recorder->readfrominputstringon ();
Recorder->setinputstring (Tsweventlog);

Test on OFF mechanism
ipw->setenabled (0);
Spline->enabledoff ();
ipw->setenabled (1);
Spline->enabledon ();

Test Set Get Handle positions
Double pos[3];
int i;
For (I=0;i<spline->getnumberofhandles (); i++)
{
Spline->gethandleposition (I,pos);
Spline->sethandleposition (I,pos);
}

Test Closed on Off
Spline->closedon ();
Spline->closedoff ();

Render the image
Iren->initialize ();
Renwin->render ();
Ren1->resetcamera ();
Recorder->play ();

Remove The observers so we can go interactive. Without this "-I"
Testing option fails.
Recorder->off ();

int retVal = Vtkregressiontestimage (Renwin);
if (RetVal = = Vtkregressiontester::D o_interactor)
{
Iren->start ();
}

Clean up
Recorder->off ();
Recorder->delete ();

Outlineactor->delete ();
Outlinemapper->delete ();
Outline->delete ();
Renwin->delete ();
Ren1->delete ();
Ren2->delete ();
Iren->delete ();

Ipw->removeobserver (IPWCB);
Ipw->delete ();
Ipwcb->delete ();
Spline->removeobserver (SWCB);
Spline->delete ();
Swcb->delete ();
Poly->delete ();
Probe->delete ();
Profile->delete ();
V16->delete ();

return!retval;
}

Reproduced VTK class Video Slice moving straight line get gray value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.