1 #include "wxVtkMPR2DView.h"
3 #include "vtkInteractorStyleBaseView.h"
5 #include "vtkCellArray.h"
7 wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction)
8 :wxVtk2DBaseView(parent)
13 _direction = direction;
24 //-------------------------------------------------------------------
25 wxVtkMPR2DView::~wxVtkMPR2DView()
27 if (_ptsA!=NULL) { _ptsA -> Delete(); }
28 if (_lineAActor!=NULL) { _lineAActor -> Delete(); }
29 if (_lineAMapper!=NULL) { _lineAMapper -> Delete(); }
30 if (_pdA!=NULL) { _pdA -> Delete(); }
31 if (_ptsB!=NULL) { _ptsB -> Delete(); }
32 if (_lineBActor!=NULL) { _lineBActor -> Delete(); }
33 if (_lineBMapper!=NULL) { _lineBMapper -> Delete(); }
34 if (_pdB!=NULL) { _pdB -> Delete(); }
36 //-------------------------------------------------------------------
37 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
39 return (vtkMPRBaseData*)GetVtkBaseData();
41 //-------------------------------------------------------------------
42 void wxVtkMPR2DView::Configure(){
43 wxVtk2DBaseView::Configure();
45 _interactorstylemprview = new vtkInteractorStyleMPRView();
46 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
48 int x1,x2,y1,y2,z1,z2;
49 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
52 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
55 x1 = (int)(x1*spc[0]);
56 y1 = (int)(y1*spc[1]);
57 z1 = (int)(z1*spc[2]);
59 x2 = (int)(x2*spc[0]);
60 y2 = (int)(y2*spc[1]);
61 z2 = (int)(z2*spc[2]);
66 _ptsA = vtkPoints::New();
67 _ptsA->SetNumberOfPoints(2);
68 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
69 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
71 linesA = vtkCellArray::New();
72 linesA->InsertNextCell(2);
73 linesA->InsertCellPoint(0);
74 linesA->InsertCellPoint(1);
75 _pdA = vtkPolyData::New();
76 _pdA->SetPoints( _ptsA );
77 _pdA->SetLines( linesA );
78 linesA->Delete(); //do not delete lines ??
79 _lineAActor = vtkActor::New();
80 _lineAMapper = vtkPolyDataMapper::New();
81 _lineAMapper->SetInput(_pdA);
82 _lineAMapper->ImmediateModeRenderingOn();
83 _lineAActor->SetMapper(_lineAMapper);
84 // _lineAActor->GetProperty()->BackfaceCullingOn();
85 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
86 _lineAActor->GetProperty()->SetLineWidth(2);
87 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
90 _ptsB = vtkPoints::New();
91 _ptsB->SetNumberOfPoints(2);
92 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
93 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
95 linesB = vtkCellArray::New();
96 linesB->InsertNextCell(2);
97 linesB->InsertCellPoint(0);
98 linesB->InsertCellPoint(1);
99 _pdB = vtkPolyData::New();
100 _pdB->SetPoints( _ptsB );
101 _pdB->SetLines( linesB );
102 linesB->Delete(); //do not delete lines ??
103 _lineBActor = vtkActor::New();
104 _lineBMapper = vtkPolyDataMapper::New();
105 _lineBMapper->SetInput(_pdB);
106 _lineBMapper->ImmediateModeRenderingOn();
107 _lineBActor->SetMapper(_lineBMapper);
108 // _lineBActor->GetProperty()->BackfaceCullingOn();
109 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
110 _lineBActor->GetProperty()->SetLineWidth(2);
111 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
114 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
119 camera->SetViewUp ( 0 , -1 , 0 );
120 camera->SetPosition ( -10000,(y1+y2)/2 , (z1+z2)/2 );
121 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
122 camera->SetParallelScale( (z2-z1)/3.0 );
126 camera->SetViewUp ( 0 , 0 , -1 );
127 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
128 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
129 camera->SetParallelScale( (x2-x1)/3.0 );
133 camera->SetViewUp ( 0 , -1 , 0 );
134 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
135 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
136 camera->SetParallelScale( (x2-x1)/3.0 );
141 camera->SetViewUp ( 0 , 1 , 0 );
142 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
143 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
144 camera->SetParallelScale( (z2-z1)/3.0 );
148 camera->SetViewUp ( 0 , 0 , -1 );
149 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
150 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
151 camera->SetParallelScale( (x2-x1)/3.0 );
155 camera->SetViewUp ( 0 , 1 , 0 );
156 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
157 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
158 camera->SetParallelScale( (x2-x1)/3.0 );
165 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
166 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
170 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
172 if (ok!=_visibleAxis)
175 if (_visibleAxis==true)
177 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
178 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
180 if (_visibleAxis==false)
182 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
183 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
189 //-------------------------------------------------------------------
190 void wxVtkMPR2DView::Refresh()
192 //wxVtk2DBaseView::Refresh();
195 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
196 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
200 int x1,x2,y1,y2,z1,z2;
201 GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
204 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
206 img->GetSpacing(spc);
207 x1 = (int)(x1*spc[0]);
208 y1 = (int)(y1*spc[1]);
209 z1 = (int)(z1*spc[2]);
211 x2 = (int)(x2*spc[0]);
212 y2 = (int)(y2*spc[1]);
213 z2 = (int)(z2*spc[2]);
215 int x = (int)(GetVtkmprbasedata()->GetX());
216 int y = (int)(GetVtkmprbasedata()->GetY());
217 int z = (int)(GetVtkmprbasedata()->GetZ());
225 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
228 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
229 _ptsA->SetPoint(0, -x2, y1 , z );
230 _ptsA->SetPoint(1, -x2, y2 , z );
231 _ptsB->SetPoint(0, -x2, y , z1);
232 _ptsB->SetPoint(1, -x2, y , z2);
235 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
236 _ptsA->SetPoint(0, x1 , y2 , z );
237 _ptsA->SetPoint(1, x2 , y2 , z );
238 _ptsB->SetPoint(0, x , y2 , z1);
239 _ptsB->SetPoint(1, x , y2 , z2);
242 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
243 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
244 // _ptsA->SetPoint(0, x1 , y , -z2 );
245 // _ptsA->SetPoint(1, x2 , y , -z2 );
246 // _ptsB->SetPoint(0, x , y1, -z2 );
247 // _ptsB->SetPoint(1, x , y2, -z2 );
249 _ptsA->SetPoint(0, x1 , y , z2 );
250 _ptsA->SetPoint(1, x2 , y , z2 );
251 _ptsB->SetPoint(0, x , y1, z2 );
252 _ptsB->SetPoint(1, x , y2, z2 );
258 wxVtkBaseView::Refresh();
261 //-------------------------------------------------------------------
262 int wxVtkMPR2DView::GetActualSlice() // virtual
267 result = (int)(GetVtkmprbasedata()->GetX());
271 result = (int)(GetVtkmprbasedata()->GetY());
275 result = (int)(GetVtkmprbasedata()->GetZ());
279 //-------------------------------------------------------------------
280 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
284 GetVtkmprbasedata()->SetX(slice);
288 GetVtkmprbasedata()->SetY(slice);
292 GetVtkmprbasedata()->SetZ(slice);
295 //-------------------------------------------------------------------
296 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
305 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
312 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
319 //-------------------------------------------------------------------
320 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
326 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
336 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
343 //-------------------------------------------------------------------
344 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
350 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
357 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
367 //-------------------------------------------------------------------
368 void wxVtkMPR2DView::MoveX(double x, double y, double z)
375 GetVtkmprbasedata()->SetX(x);
379 GetVtkmprbasedata()->SetX(x);
382 //-------------------------------------------------------------------
383 void wxVtkMPR2DView::MoveY(double x, double y, double z)
387 GetVtkmprbasedata()->SetY(y);
394 GetVtkmprbasedata()->SetY(y);
397 //-------------------------------------------------------------------
398 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
402 GetVtkmprbasedata()->SetZ(z);
406 GetVtkmprbasedata()->SetZ(z);
412 //-------------------------------------------------------------------
413 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
415 double c1r=1,c1g=1,c1b=0;
416 double c2r=1,c2g=0,c2b=0;
420 if (IfMouseTouchY(x,y,z)==true)
422 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
424 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
426 if (IfMouseTouchZ(x,y,z)==true)
428 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
430 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
436 if (IfMouseTouchX(x,y,z)==true)
438 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
440 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
442 if (IfMouseTouchZ(x,y,z)==true)
444 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
446 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
452 if (IfMouseTouchX(x,y,z)==true)
454 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
456 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
458 if (IfMouseTouchY(x,y,z)==true)
460 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
462 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
467 //-------------------------------------------------------------------
468 void wxVtkMPR2DView::TransfromeCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
470 wxVtkBaseView::TransfromeCoordScreenToWorld(X,Y,Z,_direction);
474 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
478 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
482 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
485 //-------------------------------------------------------------------
486 //-------------------------------------------------------------------
487 //-------------------------------------------------------------------
488 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
489 // if (eventId==vtkCommand::StartInteractionEvent){
490 // _renWin->SetDesiredUpdateRate(10);
492 // if (eventId==vtkCommand::InteractionEvent){
493 // _renWin->SetDesiredUpdateRate(0.001);
495 // if (eventId==vtkCommand::EndInteractionEvent){
496 // vtkPlanes *planes = vtkPlanes::New();
497 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
498 // boxwidget->GetPlanes(planes);
499 // _volumeMapper->SetClippingPlanes(planes);
500 // planes -> Delete();
504 //-------------------------------------------------------------------
505 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
508 //-------------------------------------------------------------------
509 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
510 // _volumeMapper = volumeMapper;