1 #include "wxVtkMPR2DView.h"
3 #include "vtkInteractorStyleBaseView.h"
5 #include "vtkCellArray.h"
11 wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction)
12 :wxVtk2DBaseView(parent)
17 _direction = direction;
26 _interactorstylemprview = NULL;
29 //-------------------------------------------------------------------
30 wxVtkMPR2DView::~wxVtkMPR2DView()
32 if (_ptsA!=NULL) { _ptsA -> Delete(); }
33 if (_lineAActor!=NULL) { _lineAActor -> Delete(); }
34 if (_lineAMapper!=NULL) { _lineAMapper -> Delete(); }
35 if (_pdA!=NULL) { _pdA -> Delete(); }
36 if (_ptsB!=NULL) { _ptsB -> Delete(); }
37 if (_lineBActor!=NULL) { _lineBActor -> Delete(); }
38 if (_lineBMapper!=NULL) { _lineBMapper -> Delete(); }
39 if (_pdB!=NULL) { _pdB -> Delete(); }
41 //-------------------------------------------------------------------
42 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
44 return (vtkMPRBaseData*)GetVtkBaseData();
46 //-------------------------------------------------------------------
47 void wxVtkMPR2DView::Configure()
49 printf("EED wxVtkMPR2DView::Configure");
51 wxVtk2DBaseView::Configure();
54 int x1,x2,y1,y2,z1,z2;
55 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
58 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
59 if(_interactorstylemprview==NULL)
61 _interactorstylemprview = new vtkInteractorStyleMPRView();
62 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
66 double* origin = img->GetOrigin();
67 img->GetExtent(x1,x2,y1,y2,z1,z2);
75 x1 = (int)(x1*spc[0]);
76 y1 = (int)(y1*spc[1]);
77 z1 = (int)(z1*spc[2]);
79 x2 = (int)(x2*spc[0]);
80 y2 = (int)(y2*spc[1]);
81 z2 = (int)(z2*spc[2]);
90 if(_lineAActor==NULL){
91 _lineAActor = vtkActor::New();
92 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
93 _lineAActor->GetProperty()->SetLineWidth(0.5);
95 _ptsA = vtkPoints::New();
96 _ptsA->SetNumberOfPoints(2);
97 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
98 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
100 _pdA = vtkPolyData::New();
102 _lineAMapper = vtkPolyDataMapper::New();
104 _lineAMapper->SetInput(_pdA);
105 _lineAMapper->ImmediateModeRenderingOn();
106 _lineAActor->SetMapper(_lineAMapper);
109 vtkCellArray *linesA = vtkCellArray::New();
110 linesA->InsertNextCell(2);
111 linesA->InsertCellPoint(0);
112 linesA->InsertCellPoint(1);
113 _pdA->SetPoints( _ptsA );
114 _pdA->SetLines( linesA );
115 linesA->Delete(); //do not delete lines ??
116 // _lineAActor->GetProperty()->BackfaceCullingOn();
120 if(_lineBActor==NULL){
121 _lineBActor = vtkActor::New();
122 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
123 _lineBActor->GetProperty()->SetLineWidth(0.5);
124 _lineBMapper = vtkPolyDataMapper::New();
125 _lineBActor->SetMapper(_lineBMapper);
127 _ptsB = vtkPoints::New();
128 _ptsB->SetNumberOfPoints(2);
129 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
130 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
132 // _lineBActor->GetProperty()->BackfaceCullingOn();
135 vtkCellArray *linesB;
136 linesB = vtkCellArray::New();
137 linesB->InsertNextCell(2);
138 linesB->InsertCellPoint(0);
139 linesB->InsertCellPoint(1);
140 _pdB = vtkPolyData::New();
141 _pdB->SetPoints( _ptsB );
142 _pdB->SetLines( linesB );
143 linesB->Delete(); //do not delete lines ??
146 _lineBMapper->SetInput(_pdB);
147 _lineBMapper->ImmediateModeRenderingOn();
150 if(_imageViewer2XYZ){
151 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
152 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
153 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
156 //EED 21 mars 2012 FLIP problem ..PLOP..
158 if (_direction==0) { // YZ
159 camera->SetViewUp ( 0 , 0 , 1 );
160 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
161 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
162 camera->SetParallelScale( (z2-z1)/3.0 );
165 if (_direction==1) { // XZ
166 camera->SetViewUp ( 0 , 0 , 1 );
167 camera->SetPosition ((x1+x2)/2 , -10000 , (z1+z2)/2 );
168 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
169 camera->SetParallelScale( (x2-x1)/3.0 );
172 if (_direction==2) { // XY
173 camera->SetViewUp ( 0 , -1 , 0 );
174 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
175 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
176 camera->SetParallelScale( (x2-x1)/3.0 );
180 if (_direction==0) { // YZ
181 camera->SetViewUp ( 0 , 1 , 0 );
182 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
183 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
184 camera->SetParallelScale( (z2-z1)/3.0 );
187 if (_direction==1) { // XZ
188 camera->SetViewUp ( 0 , 0 , -1 );
189 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
190 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
191 camera->SetParallelScale( (x2-x1)/3.0 );
194 if (_direction==2) { // XY
195 camera->SetViewUp ( 0 , 1 , 0 );
196 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
197 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
198 camera->SetParallelScale( (x2-x1)/3.0 );
202 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
203 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
208 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
210 if (ok!=_visibleAxis)
213 if (_visibleAxis==true)
215 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
216 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
218 if (_visibleAxis==false)
220 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
221 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
227 //-------------------------------------------------------------------
228 void wxVtkMPR2DView::Refresh()
231 printf("wxVtkMPR2DView::Refresh start\n");
233 //wxVtk2DBaseView::Refresh();
236 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
237 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
240 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
241 int x = 0, y = 0, z = 0;
242 int xx = 0, yy = 0, zz = 0;
246 double xx1,yy1,zz1,xx2,yy2,zz2;
249 //GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
252 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
254 origin = img->GetOrigin();
255 img->GetExtent(x1,x2,y1,y2,z1,z2);
256 spc = img->GetSpacing();
272 x1 = (int)(x1*spc[0]);
273 y1 = (int)(y1*spc[1]);
274 z1 = (int)(z1*spc[2]);
276 x2 = (int)(x2*spc[0]);
277 y2 = (int)(y2*spc[1]);
278 z2 = (int)(z2*spc[2]);
280 xx = (int)(GetVtkmprbasedata()->GetX());
281 yy = (int)(GetVtkmprbasedata()->GetY());
282 zz = (int)(GetVtkmprbasedata()->GetZ());
284 x = round(xx*spc[0]);
285 y = round(yy*spc[1]);
286 z = round(zz*spc[2]);
288 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ)) {
290 if (_direction==0) { // YZ
293 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
295 //EED 21 mars 2012 FLIP probleme ..PLOP..
296 //_ptsA->SetPoint(0, x2, y1 , z );
297 //_ptsA->SetPoint(1, x2, y2 , z );
298 //_ptsB->SetPoint(0, x2, y , z1);
299 //_ptsB->SetPoint(1, x2, y , z2);
300 _ptsA->SetPoint(0, xx2, yy1 , z );
301 _ptsA->SetPoint(1, xx2, yy2 , z );
302 _ptsB->SetPoint(0, xx2, y , zz1);
303 _ptsB->SetPoint(1, xx2, y , zz2);
305 if (_direction==1) { // XZ
308 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
310 //EED 21 mars 2012 FLIP probleme ..PLOP..
311 //_ptsA->SetPoint(0, x1 , y2 , z );
312 //_ptsA->SetPoint(1, x2 , y2 , z );
313 //_ptsB->SetPoint(0, x , y2 , z1);
314 //_ptsB->SetPoint(1, x , y2 , z2);
315 _ptsA->SetPoint(0, xx1 , y1 , z );
316 _ptsA->SetPoint(1, xx2 , y1 , z );
317 _ptsB->SetPoint(0, x , y1 , zz1);
318 _ptsB->SetPoint(1, x , y1 , zz2);
320 if (_direction==2) { // XY
323 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
325 // _ptsA->SetPoint(0, x1 , y , -z2 );
326 // _ptsA->SetPoint(1, x2 , y , -z2 );
327 // _ptsB->SetPoint(0, x , y1, -z2 );
328 // _ptsB->SetPoint(1, x , y2, -z2 );
331 //EED 21 mars 2012 FLIP probleme ..PLOP..
332 //_ptsA->SetPoint(0, x1 , y , z2 );
333 //_ptsA->SetPoint(1, x2 , y , z2 );
334 //_ptsB->SetPoint(0, x , y1, z2 );
335 //_ptsB->SetPoint(1, x , y2, z2 );
337 _ptsA->SetPoint(0, xx1 , y , z1 );
338 _ptsA->SetPoint(1, xx2 , y , z1 );
339 _ptsB->SetPoint(0, x , yy1, z1 );
340 _ptsB->SetPoint(1, x , yy2, z1 );
350 _imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->Modified();
352 wxVtkBaseView::Refresh();
354 printf("wxVtkMPR2DView::Refresh end\n");
358 //-------------------------------------------------------------------
359 int wxVtkMPR2DView::GetActualSlice() // virtual
364 result = (int)(GetVtkmprbasedata()->GetX());
368 result = (int)(GetVtkmprbasedata()->GetY());
372 result = (int)(GetVtkmprbasedata()->GetZ());
376 //-------------------------------------------------------------------
377 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
381 GetVtkmprbasedata()->SetX(slice);
385 GetVtkmprbasedata()->SetY(slice);
389 GetVtkmprbasedata()->SetZ(slice);
392 //-------------------------------------------------------------------
393 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
402 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
409 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
416 //-------------------------------------------------------------------
417 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
423 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
433 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
440 //-------------------------------------------------------------------
441 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
447 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
454 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
464 //-------------------------------------------------------------------
465 void wxVtkMPR2DView::MoveX(double x, double y, double z)
472 GetVtkmprbasedata()->SetX(x);
476 GetVtkmprbasedata()->SetX(x);
479 //-------------------------------------------------------------------
480 void wxVtkMPR2DView::MoveY(double x, double y, double z)
484 GetVtkmprbasedata()->SetY(y);
491 GetVtkmprbasedata()->SetY(y);
494 //-------------------------------------------------------------------
495 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
499 GetVtkmprbasedata()->SetZ(z);
503 GetVtkmprbasedata()->SetZ(z);
509 //-------------------------------------------------------------------
510 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
512 double c1r=1,c1g=1,c1b=0;
513 double c2r=1,c2g=0,c2b=0;
517 if (IfMouseTouchY(x,y,z)==true)
519 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
521 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
523 if (IfMouseTouchZ(x,y,z)==true)
525 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
527 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
533 if (IfMouseTouchX(x,y,z)==true)
535 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
537 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
539 if (IfMouseTouchZ(x,y,z)==true)
541 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
543 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
549 if (IfMouseTouchX(x,y,z)==true)
551 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
553 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
555 if (IfMouseTouchY(x,y,z)==true)
557 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
559 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
567 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
568 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
571 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
573 if ((_direction==0) && (keepNormalDirection==true) )
575 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
578 if ((_direction==1) && (keepNormalDirection==true) )
580 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
583 if ((_direction==2) && (keepNormalDirection==true) )
585 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
590 //-------------------------------------------------------------------
591 int wxVtkMPR2DView::GetDirection() // virtual
597 //-------------------------------------------------------------------
598 //-------------------------------------------------------------------
599 //-------------------------------------------------------------------
600 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
601 // if (eventId==vtkCommand::StartInteractionEvent){
602 // _renWin->SetDesiredUpdateRate(10);
604 // if (eventId==vtkCommand::InteractionEvent){
605 // _renWin->SetDesiredUpdateRate(0.001);
607 // if (eventId==vtkCommand::EndInteractionEvent){
608 // vtkPlanes *planes = vtkPlanes::New();
609 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
610 // boxwidget->GetPlanes(planes);
611 // _volumeMapper->SetClippingPlanes(planes);
612 // planes -> Delete();
616 //-------------------------------------------------------------------
617 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
620 //-------------------------------------------------------------------
621 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
622 // _volumeMapper = volumeMapper;