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 );
140 if (_direction==0) { // YZ
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 );
147 if (_direction==1) { // XZ
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 );
154 if (_direction==2) { // XY
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());
223 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
225 if (_direction==0) { // YZ
226 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
227 _ptsA->SetPoint(0, x2, y1 , z );
228 _ptsA->SetPoint(1, x2, y2 , z );
229 _ptsB->SetPoint(0, x2, y , z1);
230 _ptsB->SetPoint(1, x2, y , z2);
232 if (_direction==1) { // XZ
233 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
234 _ptsA->SetPoint(0, x1 , y2 , z );
235 _ptsA->SetPoint(1, x2 , y2 , z );
236 _ptsB->SetPoint(0, x , y2 , z1);
237 _ptsB->SetPoint(1, x , y2 , z2);
239 if (_direction==2) { // XY
240 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
241 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
242 // _ptsA->SetPoint(0, x1 , y , -z2 );
243 // _ptsA->SetPoint(1, x2 , y , -z2 );
244 // _ptsB->SetPoint(0, x , y1, -z2 );
245 // _ptsB->SetPoint(1, x , y2, -z2 );
247 _ptsA->SetPoint(0, x1 , y , z2 );
248 _ptsA->SetPoint(1, x2 , y , z2 );
249 _ptsB->SetPoint(0, x , y1, z2 );
250 _ptsB->SetPoint(1, x , y2, z2 );
256 wxVtkBaseView::Refresh();
259 //-------------------------------------------------------------------
260 int wxVtkMPR2DView::GetActualSlice() // virtual
265 result = (int)(GetVtkmprbasedata()->GetX());
269 result = (int)(GetVtkmprbasedata()->GetY());
273 result = (int)(GetVtkmprbasedata()->GetZ());
277 //-------------------------------------------------------------------
278 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
282 GetVtkmprbasedata()->SetX(slice);
286 GetVtkmprbasedata()->SetY(slice);
290 GetVtkmprbasedata()->SetZ(slice);
293 //-------------------------------------------------------------------
294 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
303 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
310 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
317 //-------------------------------------------------------------------
318 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
324 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
334 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
341 //-------------------------------------------------------------------
342 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
348 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
355 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
365 //-------------------------------------------------------------------
366 void wxVtkMPR2DView::MoveX(double x, double y, double z)
373 GetVtkmprbasedata()->SetX(x);
377 GetVtkmprbasedata()->SetX(x);
380 //-------------------------------------------------------------------
381 void wxVtkMPR2DView::MoveY(double x, double y, double z)
385 GetVtkmprbasedata()->SetY(y);
392 GetVtkmprbasedata()->SetY(y);
395 //-------------------------------------------------------------------
396 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
400 GetVtkmprbasedata()->SetZ(z);
404 GetVtkmprbasedata()->SetZ(z);
410 //-------------------------------------------------------------------
411 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
413 double c1r=1,c1g=1,c1b=0;
414 double c2r=1,c2g=0,c2b=0;
418 if (IfMouseTouchY(x,y,z)==true)
420 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
422 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
424 if (IfMouseTouchZ(x,y,z)==true)
426 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
428 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
434 if (IfMouseTouchX(x,y,z)==true)
436 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
438 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
440 if (IfMouseTouchZ(x,y,z)==true)
442 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
444 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
450 if (IfMouseTouchX(x,y,z)==true)
452 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
454 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
456 if (IfMouseTouchY(x,y,z)==true)
458 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
460 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
468 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
469 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
472 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
474 if ((_direction==0) && (keepNormalDirection==true) )
476 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
479 if ((_direction==1) && (keepNormalDirection==true) )
481 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
484 if ((_direction==2) && (keepNormalDirection==true) )
486 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
492 //-------------------------------------------------------------------
493 //-------------------------------------------------------------------
494 //-------------------------------------------------------------------
495 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
496 // if (eventId==vtkCommand::StartInteractionEvent){
497 // _renWin->SetDesiredUpdateRate(10);
499 // if (eventId==vtkCommand::InteractionEvent){
500 // _renWin->SetDesiredUpdateRate(0.001);
502 // if (eventId==vtkCommand::EndInteractionEvent){
503 // vtkPlanes *planes = vtkPlanes::New();
504 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
505 // boxwidget->GetPlanes(planes);
506 // _volumeMapper->SetClippingPlanes(planes);
507 // planes -> Delete();
511 //-------------------------------------------------------------------
512 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
515 //-------------------------------------------------------------------
516 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
517 // _volumeMapper = volumeMapper;