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 wxVtk2DBaseView::Configure();
50 int x1,x2,y1,y2,z1,z2;
51 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
53 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
54 if(_interactorstylemprview==NULL)
56 _interactorstylemprview = new vtkInteractorStyleMPRView();
57 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
61 double* origin = img->GetOrigin();
62 img->GetExtent(x1,x2,y1,y2,z1,z2);
70 x1 = (int)(x1*spc[0]);
71 y1 = (int)(y1*spc[1]);
72 z1 = (int)(z1*spc[2]);
74 x2 = (int)(x2*spc[0]);
75 y2 = (int)(y2*spc[1]);
76 z2 = (int)(z2*spc[2]);
82 if(_lineAActor==NULL){
83 _lineAActor = vtkActor::New();
84 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
85 _lineAActor->GetProperty()->SetLineWidth(0.5);
87 _ptsA = vtkPoints::New();
88 _ptsA->SetNumberOfPoints(2);
89 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
90 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
91 _pdA = vtkPolyData::New();
92 _lineAMapper = vtkPolyDataMapper::New();
93 _lineAMapper->SetInput(_pdA);
94 _lineAMapper->ImmediateModeRenderingOn();
95 _lineAActor->SetMapper(_lineAMapper);
98 vtkCellArray *linesA = vtkCellArray::New();
99 linesA->InsertNextCell(2);
100 linesA->InsertCellPoint(0);
101 linesA->InsertCellPoint(1);
102 _pdA->SetPoints( _ptsA );
103 _pdA->SetLines( linesA );
104 linesA->Delete(); //do not delete lines ??
105 // _lineAActor->GetProperty()->BackfaceCullingOn();
109 if(_lineBActor==NULL){
110 _lineBActor = vtkActor::New();
111 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
112 _lineBActor->GetProperty()->SetLineWidth(0.5);
113 _lineBMapper = vtkPolyDataMapper::New();
114 _lineBActor->SetMapper(_lineBMapper);
115 _ptsB = vtkPoints::New();
116 _ptsB->SetNumberOfPoints(2);
117 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
118 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
119 // _lineBActor->GetProperty()->BackfaceCullingOn();
122 vtkCellArray *linesB;
123 linesB = vtkCellArray::New();
124 linesB->InsertNextCell(2);
125 linesB->InsertCellPoint(0);
126 linesB->InsertCellPoint(1);
127 _pdB = vtkPolyData::New();
128 _pdB->SetPoints( _ptsB );
129 _pdB->SetLines( linesB );
130 linesB->Delete(); //do not delete lines ??
131 _lineBMapper->SetInput(_pdB);
132 _lineBMapper->ImmediateModeRenderingOn();
133 if(_imageViewer2XYZ){
134 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
135 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
136 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
139 //EED 21 mars 2012 FLIP problem ..PLOP..
141 if (_direction==0) { // YZ
142 camera->SetViewUp ( 0 , 0 , 1 );
143 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
144 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
145 camera->SetParallelScale( (z2-z1)/3.0 );
148 if (_direction==1) { // XZ
149 camera->SetViewUp ( 0 , 0 , 1 );
150 camera->SetPosition ((x1+x2)/2 , -10000 , (z1+z2)/2 );
151 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
152 camera->SetParallelScale( (x2-x1)/3.0 );
155 if (_direction==2) { // XY
156 camera->SetViewUp ( 0 , -1 , 0 );
157 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
158 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
159 camera->SetParallelScale( (x2-x1)/3.0 );
163 if (_direction==0) { // YZ
164 camera->SetViewUp ( 0 , 1 , 0 );
165 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
166 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
167 camera->SetParallelScale( (z2-z1)/3.0 );
170 if (_direction==1) { // XZ
171 camera->SetViewUp ( 0 , 0 , -1 );
172 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
173 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
174 camera->SetParallelScale( (x2-x1)/3.0 );
177 if (_direction==2) { // XY
178 camera->SetViewUp ( 0 , 1 , 0 );
179 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
180 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
181 camera->SetParallelScale( (x2-x1)/3.0 );
185 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
186 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
190 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
192 if (ok!=_visibleAxis)
195 if (_visibleAxis==true)
197 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
198 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
200 if (_visibleAxis==false)
202 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
203 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
209 //-------------------------------------------------------------------
210 void wxVtkMPR2DView::Refresh()
212 //wxVtk2DBaseView::Refresh();
213 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
214 int x = 0, y = 0, z = 0;
215 int xx = 0, yy = 0, zz = 0;
219 double xx1,yy1,zz1,xx2,yy2,zz2;
221 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
223 origin = img->GetOrigin();
224 img->GetExtent(x1,x2,y1,y2,z1,z2);
225 spc = img->GetSpacing();
241 x1 = (int)(x1*spc[0]);
242 y1 = (int)(y1*spc[1]);
243 z1 = (int)(z1*spc[2]);
245 x2 = (int)(x2*spc[0]);
246 y2 = (int)(y2*spc[1]);
247 z2 = (int)(z2*spc[2]);
249 xx = (int)(GetVtkmprbasedata()->GetX());
250 yy = (int)(GetVtkmprbasedata()->GetY());
251 zz = (int)(GetVtkmprbasedata()->GetZ());
253 x = round(xx*spc[0]);
254 y = round(yy*spc[1]);
255 z = round(zz*spc[2]);
257 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ)) {
259 if (_direction==0) { // YZ
262 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
264 //EED 21 mars 2012 FLIP probleme ..PLOP..
265 //_ptsA->SetPoint(0, x2, y1 , z );
266 //_ptsA->SetPoint(1, x2, y2 , z );
267 //_ptsB->SetPoint(0, x2, y , z1);
268 //_ptsB->SetPoint(1, x2, y , z2);
269 _ptsA->SetPoint(0, xx2, yy1 , z );
270 _ptsA->SetPoint(1, xx2, yy2 , z );
271 _ptsB->SetPoint(0, xx2, y , zz1);
272 _ptsB->SetPoint(1, xx2, y , zz2);
274 if (_direction==1) { // XZ
277 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
279 //EED 21 mars 2012 FLIP probleme ..PLOP..
280 //_ptsA->SetPoint(0, x1 , y2 , z );
281 //_ptsA->SetPoint(1, x2 , y2 , z );
282 //_ptsB->SetPoint(0, x , y2 , z1);
283 //_ptsB->SetPoint(1, x , y2 , z2);
284 _ptsA->SetPoint(0, xx1 , y1 , z );
285 _ptsA->SetPoint(1, xx2 , y1 , z );
286 _ptsB->SetPoint(0, x , y1 , zz1);
287 _ptsB->SetPoint(1, x , y1 , zz2);
289 if (_direction==2) { // XY
292 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
294 // _ptsA->SetPoint(0, x1 , y , -z2 );
295 // _ptsA->SetPoint(1, x2 , y , -z2 );
296 // _ptsB->SetPoint(0, x , y1, -z2 );
297 // _ptsB->SetPoint(1, x , y2, -z2 );
300 //EED 21 mars 2012 FLIP probleme ..PLOP..
301 //_ptsA->SetPoint(0, x1 , y , z2 );
302 //_ptsA->SetPoint(1, x2 , y , z2 );
303 //_ptsB->SetPoint(0, x , y1, z2 );
304 //_ptsB->SetPoint(1, x , y2, z2 );
306 _ptsA->SetPoint(0, xx1 , y , z1 );
307 _ptsA->SetPoint(1, xx2 , y , z1 );
308 _ptsB->SetPoint(0, x , yy1, z1 );
309 _ptsB->SetPoint(1, x , yy2, z1 );
319 UpdateColorWindowLevel();
320 wxVtkBaseView::Refresh();
323 //-------------------------------------------------------------------
324 int wxVtkMPR2DView::GetActualSlice() // virtual
329 result = (int)(GetVtkmprbasedata()->GetX());
333 result = (int)(GetVtkmprbasedata()->GetY());
337 result = (int)(GetVtkmprbasedata()->GetZ());
341 //-------------------------------------------------------------------
342 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
346 GetVtkmprbasedata()->SetX(slice);
350 GetVtkmprbasedata()->SetY(slice);
354 GetVtkmprbasedata()->SetZ(slice);
357 //-------------------------------------------------------------------
358 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
367 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
374 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
381 //-------------------------------------------------------------------
382 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
388 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
398 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
405 //-------------------------------------------------------------------
406 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
412 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
419 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
429 //-------------------------------------------------------------------
430 void wxVtkMPR2DView::MoveX(double x, double y, double z)
437 GetVtkmprbasedata()->SetX(x);
441 GetVtkmprbasedata()->SetX(x);
444 //-------------------------------------------------------------------
445 void wxVtkMPR2DView::MoveY(double x, double y, double z)
449 GetVtkmprbasedata()->SetY(y);
456 GetVtkmprbasedata()->SetY(y);
459 //-------------------------------------------------------------------
460 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
464 GetVtkmprbasedata()->SetZ(z);
468 GetVtkmprbasedata()->SetZ(z);
474 //-------------------------------------------------------------------
475 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
477 double c1r=1,c1g=1,c1b=0;
478 double c2r=1,c2g=0,c2b=0;
482 if (IfMouseTouchY(x,y,z)==true)
484 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
486 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
488 if (IfMouseTouchZ(x,y,z)==true)
490 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
492 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
498 if (IfMouseTouchX(x,y,z)==true)
500 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
502 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
504 if (IfMouseTouchZ(x,y,z)==true)
506 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
508 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
514 if (IfMouseTouchX(x,y,z)==true)
516 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
518 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
520 if (IfMouseTouchY(x,y,z)==true)
522 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
524 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
532 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
533 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
536 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
538 if ((_direction==0) && (keepNormalDirection==true) )
540 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
543 if ((_direction==1) && (keepNormalDirection==true) )
545 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
548 if ((_direction==2) && (keepNormalDirection==true) )
550 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
555 //-------------------------------------------------------------------
556 int wxVtkMPR2DView::GetDirection() // virtual
562 //-------------------------------------------------------------------
563 //-------------------------------------------------------------------
564 //-------------------------------------------------------------------
565 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
566 // if (eventId==vtkCommand::StartInteractionEvent){
567 // _renWin->SetDesiredUpdateRate(10);
569 // if (eventId==vtkCommand::InteractionEvent){
570 // _renWin->SetDesiredUpdateRate(0.001);
572 // if (eventId==vtkCommand::EndInteractionEvent){
573 // vtkPlanes *planes = vtkPlanes::New();
574 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
575 // boxwidget->GetPlanes(planes);
576 // _volumeMapper->SetClippingPlanes(planes);
577 // planes -> Delete();
581 //-------------------------------------------------------------------
582 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
585 //-------------------------------------------------------------------
586 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
587 // _volumeMapper = volumeMapper;