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(){
48 wxVtk2DBaseView::Configure();
51 int x1,x2,y1,y2,z1,z2;
52 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
55 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
56 if(_interactorstylemprview==NULL)
58 _interactorstylemprview = new vtkInteractorStyleMPRView();
59 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
63 double* origin = img->GetOrigin();
64 img->GetExtent(x1,x2,y1,y2,z1,z2);
72 x1 = (int)(x1*spc[0]);
73 y1 = (int)(y1*spc[1]);
74 z1 = (int)(z1*spc[2]);
76 x2 = (int)(x2*spc[0]);
77 y2 = (int)(y2*spc[1]);
78 z2 = (int)(z2*spc[2]);
87 if(_lineAActor==NULL){
88 _lineAActor = vtkActor::New();
89 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
90 _lineAActor->GetProperty()->SetLineWidth(0.5);
92 _ptsA = vtkPoints::New();
93 _ptsA->SetNumberOfPoints(2);
94 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
95 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
97 _pdA = vtkPolyData::New();
99 _lineAMapper = vtkPolyDataMapper::New();
101 _lineAMapper->SetInput(_pdA);
102 _lineAMapper->ImmediateModeRenderingOn();
103 _lineAActor->SetMapper(_lineAMapper);
106 vtkCellArray *linesA = vtkCellArray::New();
107 linesA->InsertNextCell(2);
108 linesA->InsertCellPoint(0);
109 linesA->InsertCellPoint(1);
110 _pdA->SetPoints( _ptsA );
111 _pdA->SetLines( linesA );
112 linesA->Delete(); //do not delete lines ??
113 // _lineAActor->GetProperty()->BackfaceCullingOn();
117 if(_lineBActor==NULL){
118 _lineBActor = vtkActor::New();
119 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
120 _lineBActor->GetProperty()->SetLineWidth(0.5);
121 _lineBMapper = vtkPolyDataMapper::New();
122 _lineBActor->SetMapper(_lineBMapper);
124 _ptsB = vtkPoints::New();
125 _ptsB->SetNumberOfPoints(2);
126 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
127 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
129 // _lineBActor->GetProperty()->BackfaceCullingOn();
132 vtkCellArray *linesB;
133 linesB = vtkCellArray::New();
134 linesB->InsertNextCell(2);
135 linesB->InsertCellPoint(0);
136 linesB->InsertCellPoint(1);
137 _pdB = vtkPolyData::New();
138 _pdB->SetPoints( _ptsB );
139 _pdB->SetLines( linesB );
140 linesB->Delete(); //do not delete lines ??
143 _lineBMapper->SetInput(_pdB);
144 _lineBMapper->ImmediateModeRenderingOn();
147 if(_imageViewer2XYZ){
148 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
149 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
150 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
153 //EED 21 mars 2012 FLIP problem ..PLOP..
155 if (_direction==0) { // YZ
156 camera->SetViewUp ( 0 , 0 , 1 );
157 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
158 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
159 camera->SetParallelScale( (z2-z1)/3.0 );
162 if (_direction==1) { // XZ
163 camera->SetViewUp ( 0 , 0 , 1 );
164 camera->SetPosition ((x1+x2)/2 , -10000 , (z1+z2)/2 );
165 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
166 camera->SetParallelScale( (x2-x1)/3.0 );
169 if (_direction==2) { // XY
170 camera->SetViewUp ( 0 , -1 , 0 );
171 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
172 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
173 camera->SetParallelScale( (x2-x1)/3.0 );
177 if (_direction==0) { // YZ
178 camera->SetViewUp ( 0 , 1 , 0 );
179 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
180 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
181 camera->SetParallelScale( (z2-z1)/3.0 );
184 if (_direction==1) { // XZ
185 camera->SetViewUp ( 0 , 0 , -1 );
186 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
187 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
188 camera->SetParallelScale( (x2-x1)/3.0 );
191 if (_direction==2) { // XY
192 camera->SetViewUp ( 0 , 1 , 0 );
193 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
194 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
195 camera->SetParallelScale( (x2-x1)/3.0 );
199 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
200 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
205 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
207 if (ok!=_visibleAxis)
210 if (_visibleAxis==true)
212 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
213 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
215 if (_visibleAxis==false)
217 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
218 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
224 //-------------------------------------------------------------------
225 void wxVtkMPR2DView::Refresh()
229 //wxVtk2DBaseView::Refresh();
232 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
233 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
236 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
237 int x = 0, y = 0, z = 0;
238 int xx = 0, yy = 0, zz = 0;
242 double xx1,yy1,zz1,xx2,yy2,zz2;
245 //GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
248 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
250 origin = img->GetOrigin();
251 img->GetExtent(x1,x2,y1,y2,z1,z2);
252 spc = img->GetSpacing();
268 x1 = (int)(x1*spc[0]);
269 y1 = (int)(y1*spc[1]);
270 z1 = (int)(z1*spc[2]);
272 x2 = (int)(x2*spc[0]);
273 y2 = (int)(y2*spc[1]);
274 z2 = (int)(z2*spc[2]);
276 xx = (int)(GetVtkmprbasedata()->GetX());
277 yy = (int)(GetVtkmprbasedata()->GetY());
278 zz = (int)(GetVtkmprbasedata()->GetZ());
280 x = round(xx*spc[0]);
281 y = round(yy*spc[1]);
282 z = round(zz*spc[2]);
284 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ)) {
286 if (_direction==0) { // YZ
289 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
291 //EED 21 mars 2012 FLIP probleme ..PLOP..
292 //_ptsA->SetPoint(0, x2, y1 , z );
293 //_ptsA->SetPoint(1, x2, y2 , z );
294 //_ptsB->SetPoint(0, x2, y , z1);
295 //_ptsB->SetPoint(1, x2, y , z2);
296 _ptsA->SetPoint(0, xx2, yy1 , z );
297 _ptsA->SetPoint(1, xx2, yy2 , z );
298 _ptsB->SetPoint(0, xx2, y , zz1);
299 _ptsB->SetPoint(1, xx2, y , zz2);
301 if (_direction==1) { // XZ
304 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
306 //EED 21 mars 2012 FLIP probleme ..PLOP..
307 //_ptsA->SetPoint(0, x1 , y2 , z );
308 //_ptsA->SetPoint(1, x2 , y2 , z );
309 //_ptsB->SetPoint(0, x , y2 , z1);
310 //_ptsB->SetPoint(1, x , y2 , z2);
311 _ptsA->SetPoint(0, xx1 , y1 , z );
312 _ptsA->SetPoint(1, xx2 , y1 , z );
313 _ptsB->SetPoint(0, x , y1 , zz1);
314 _ptsB->SetPoint(1, x , y1 , zz2);
316 if (_direction==2) { // XY
319 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
321 // _ptsA->SetPoint(0, x1 , y , -z2 );
322 // _ptsA->SetPoint(1, x2 , y , -z2 );
323 // _ptsB->SetPoint(0, x , y1, -z2 );
324 // _ptsB->SetPoint(1, x , y2, -z2 );
327 //EED 21 mars 2012 FLIP probleme ..PLOP..
328 //_ptsA->SetPoint(0, x1 , y , z2 );
329 //_ptsA->SetPoint(1, x2 , y , z2 );
330 //_ptsB->SetPoint(0, x , y1, z2 );
331 //_ptsB->SetPoint(1, x , y2, z2 );
333 _ptsA->SetPoint(0, xx1 , y , z1 );
334 _ptsA->SetPoint(1, xx2 , y , z1 );
335 _ptsB->SetPoint(0, x , yy1, z1 );
336 _ptsB->SetPoint(1, x , yy2, z1 );
346 _imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->Modified();
348 wxVtkBaseView::Refresh();
351 //-------------------------------------------------------------------
352 int wxVtkMPR2DView::GetActualSlice() // virtual
357 result = (int)(GetVtkmprbasedata()->GetX());
361 result = (int)(GetVtkmprbasedata()->GetY());
365 result = (int)(GetVtkmprbasedata()->GetZ());
369 //-------------------------------------------------------------------
370 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
374 GetVtkmprbasedata()->SetX(slice);
378 GetVtkmprbasedata()->SetY(slice);
382 GetVtkmprbasedata()->SetZ(slice);
385 //-------------------------------------------------------------------
386 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
395 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
402 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
409 //-------------------------------------------------------------------
410 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
416 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
426 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
433 //-------------------------------------------------------------------
434 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
440 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
447 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
457 //-------------------------------------------------------------------
458 void wxVtkMPR2DView::MoveX(double x, double y, double z)
465 GetVtkmprbasedata()->SetX(x);
469 GetVtkmprbasedata()->SetX(x);
472 //-------------------------------------------------------------------
473 void wxVtkMPR2DView::MoveY(double x, double y, double z)
477 GetVtkmprbasedata()->SetY(y);
484 GetVtkmprbasedata()->SetY(y);
487 //-------------------------------------------------------------------
488 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
492 GetVtkmprbasedata()->SetZ(z);
496 GetVtkmprbasedata()->SetZ(z);
502 //-------------------------------------------------------------------
503 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
505 double c1r=1,c1g=1,c1b=0;
506 double c2r=1,c2g=0,c2b=0;
510 if (IfMouseTouchY(x,y,z)==true)
512 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
514 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
516 if (IfMouseTouchZ(x,y,z)==true)
518 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
520 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
526 if (IfMouseTouchX(x,y,z)==true)
528 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
530 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
532 if (IfMouseTouchZ(x,y,z)==true)
534 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
536 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
542 if (IfMouseTouchX(x,y,z)==true)
544 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
546 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
548 if (IfMouseTouchY(x,y,z)==true)
550 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
552 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
560 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
561 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
564 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
566 if ((_direction==0) && (keepNormalDirection==true) )
568 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
571 if ((_direction==1) && (keepNormalDirection==true) )
573 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
576 if ((_direction==2) && (keepNormalDirection==true) )
578 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
583 //-------------------------------------------------------------------
584 int wxVtkMPR2DView::GetDirection() // virtual
590 //-------------------------------------------------------------------
591 //-------------------------------------------------------------------
592 //-------------------------------------------------------------------
593 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
594 // if (eventId==vtkCommand::StartInteractionEvent){
595 // _renWin->SetDesiredUpdateRate(10);
597 // if (eventId==vtkCommand::InteractionEvent){
598 // _renWin->SetDesiredUpdateRate(0.001);
600 // if (eventId==vtkCommand::EndInteractionEvent){
601 // vtkPlanes *planes = vtkPlanes::New();
602 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
603 // boxwidget->GetPlanes(planes);
604 // _volumeMapper->SetClippingPlanes(planes);
605 // planes -> Delete();
609 //-------------------------------------------------------------------
610 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
613 //-------------------------------------------------------------------
614 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
615 // _volumeMapper = volumeMapper;