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 if(_lineAActor==NULL){
67 _ptsA = vtkPoints::New();
68 _ptsA->SetNumberOfPoints(2);
69 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
70 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
72 linesA = vtkCellArray::New();
73 linesA->InsertNextCell(2);
74 linesA->InsertCellPoint(0);
75 linesA->InsertCellPoint(1);
76 _pdA = vtkPolyData::New();
77 _pdA->SetPoints( _ptsA );
78 _pdA->SetLines( linesA );
79 linesA->Delete(); //do not delete lines ??
80 _lineAActor = vtkActor::New();
81 _lineAMapper = vtkPolyDataMapper::New();
83 _lineAMapper->SetInput(_pdA);
84 _lineAMapper->ImmediateModeRenderingOn();
85 _lineAActor->SetMapper(_lineAMapper);
86 // _lineAActor->GetProperty()->BackfaceCullingOn();
87 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
88 _lineAActor->GetProperty()->SetLineWidth(2);
89 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
96 if(_lineBActor==NULL){
97 _ptsB = vtkPoints::New();
98 _ptsB->SetNumberOfPoints(2);
99 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
100 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
101 vtkCellArray *linesB;
102 linesB = vtkCellArray::New();
103 linesB->InsertNextCell(2);
104 linesB->InsertCellPoint(0);
105 linesB->InsertCellPoint(1);
106 _pdB = vtkPolyData::New();
107 _pdB->SetPoints( _ptsB );
108 _pdB->SetLines( linesB );
109 linesB->Delete(); //do not delete lines ??
110 _lineBActor = vtkActor::New();
111 _lineBMapper = vtkPolyDataMapper::New();
112 _lineBMapper->SetInput(_pdB);
113 _lineBMapper->ImmediateModeRenderingOn();
114 _lineBActor->SetMapper(_lineBMapper);
115 // _lineBActor->GetProperty()->BackfaceCullingOn();
116 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
117 _lineBActor->GetProperty()->SetLineWidth(2);
118 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
122 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
127 camera->SetViewUp ( 0 , -1 , 0 );
128 camera->SetPosition ( -10000,(y1+y2)/2 , (z1+z2)/2 );
129 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
130 camera->SetParallelScale( (z2-z1)/3.0 );
134 camera->SetViewUp ( 0 , 0 , -1 );
135 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
136 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
137 camera->SetParallelScale( (x2-x1)/3.0 );
141 camera->SetViewUp ( 0 , -1 , 0 );
142 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
143 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
144 camera->SetParallelScale( (x2-x1)/3.0 );
148 if (_direction==0) { // YZ
149 camera->SetViewUp ( 0 , 1 , 0 );
150 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
151 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
152 camera->SetParallelScale( (z2-z1)/3.0 );
155 if (_direction==1) { // XZ
156 camera->SetViewUp ( 0 , 0 , -1 );
157 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
158 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
159 camera->SetParallelScale( (x2-x1)/3.0 );
162 if (_direction==2) { // XY
163 camera->SetViewUp ( 0 , 1 , 0 );
164 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
165 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
166 camera->SetParallelScale( (x2-x1)/3.0 );
173 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
174 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
178 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
180 if (ok!=_visibleAxis)
183 if (_visibleAxis==true)
185 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
186 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
188 if (_visibleAxis==false)
190 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
191 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
197 //-------------------------------------------------------------------
198 void wxVtkMPR2DView::Refresh()
200 //wxVtk2DBaseView::Refresh();
203 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
204 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
208 int x1,x2,y1,y2,z1,z2;
209 GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
212 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
214 img->GetSpacing(spc);
215 x1 = (int)(x1*spc[0]);
216 y1 = (int)(y1*spc[1]);
217 z1 = (int)(z1*spc[2]);
219 x2 = (int)(x2*spc[0]);
220 y2 = (int)(y2*spc[1]);
221 z2 = (int)(z2*spc[2]);
223 int x = (int)(GetVtkmprbasedata()->GetX());
224 int y = (int)(GetVtkmprbasedata()->GetY());
225 int z = (int)(GetVtkmprbasedata()->GetZ());
231 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
233 if (_direction==0) { // YZ
234 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
235 _ptsA->SetPoint(0, x2, y1 , z );
236 _ptsA->SetPoint(1, x2, y2 , z );
237 _ptsB->SetPoint(0, x2, y , z1);
238 _ptsB->SetPoint(1, x2, y , z2);
240 if (_direction==1) { // XZ
241 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
242 _ptsA->SetPoint(0, x1 , y2 , z );
243 _ptsA->SetPoint(1, x2 , y2 , z );
244 _ptsB->SetPoint(0, x , y2 , z1);
245 _ptsB->SetPoint(1, x , y2 , z2);
247 if (_direction==2) { // XY
248 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
249 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
250 // _ptsA->SetPoint(0, x1 , y , -z2 );
251 // _ptsA->SetPoint(1, x2 , y , -z2 );
252 // _ptsB->SetPoint(0, x , y1, -z2 );
253 // _ptsB->SetPoint(1, x , y2, -z2 );
255 _ptsA->SetPoint(0, x1 , y , z2 );
256 _ptsA->SetPoint(1, x2 , y , z2 );
257 _ptsB->SetPoint(0, x , y1, z2 );
258 _ptsB->SetPoint(1, x , y2, z2 );
264 wxVtkBaseView::Refresh();
267 //-------------------------------------------------------------------
268 int wxVtkMPR2DView::GetActualSlice() // virtual
273 result = (int)(GetVtkmprbasedata()->GetX());
277 result = (int)(GetVtkmprbasedata()->GetY());
281 result = (int)(GetVtkmprbasedata()->GetZ());
285 //-------------------------------------------------------------------
286 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
290 GetVtkmprbasedata()->SetX(slice);
294 GetVtkmprbasedata()->SetY(slice);
298 GetVtkmprbasedata()->SetZ(slice);
301 //-------------------------------------------------------------------
302 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
311 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
318 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
325 //-------------------------------------------------------------------
326 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
332 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
342 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
349 //-------------------------------------------------------------------
350 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
356 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
363 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
373 //-------------------------------------------------------------------
374 void wxVtkMPR2DView::MoveX(double x, double y, double z)
381 GetVtkmprbasedata()->SetX(x);
385 GetVtkmprbasedata()->SetX(x);
388 //-------------------------------------------------------------------
389 void wxVtkMPR2DView::MoveY(double x, double y, double z)
393 GetVtkmprbasedata()->SetY(y);
400 GetVtkmprbasedata()->SetY(y);
403 //-------------------------------------------------------------------
404 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
408 GetVtkmprbasedata()->SetZ(z);
412 GetVtkmprbasedata()->SetZ(z);
418 //-------------------------------------------------------------------
419 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
421 double c1r=1,c1g=1,c1b=0;
422 double c2r=1,c2g=0,c2b=0;
426 if (IfMouseTouchY(x,y,z)==true)
428 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
430 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
432 if (IfMouseTouchZ(x,y,z)==true)
434 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
436 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
442 if (IfMouseTouchX(x,y,z)==true)
444 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
446 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
448 if (IfMouseTouchZ(x,y,z)==true)
450 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
452 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
458 if (IfMouseTouchX(x,y,z)==true)
460 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
462 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
464 if (IfMouseTouchY(x,y,z)==true)
466 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
468 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
476 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
477 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
480 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
482 if ((_direction==0) && (keepNormalDirection==true) )
484 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
487 if ((_direction==1) && (keepNormalDirection==true) )
489 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
492 if ((_direction==2) && (keepNormalDirection==true) )
494 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
500 //-------------------------------------------------------------------
501 //-------------------------------------------------------------------
502 //-------------------------------------------------------------------
503 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
504 // if (eventId==vtkCommand::StartInteractionEvent){
505 // _renWin->SetDesiredUpdateRate(10);
507 // if (eventId==vtkCommand::InteractionEvent){
508 // _renWin->SetDesiredUpdateRate(0.001);
510 // if (eventId==vtkCommand::EndInteractionEvent){
511 // vtkPlanes *planes = vtkPlanes::New();
512 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
513 // boxwidget->GetPlanes(planes);
514 // _volumeMapper->SetClippingPlanes(planes);
515 // planes -> Delete();
519 //-------------------------------------------------------------------
520 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
523 //-------------------------------------------------------------------
524 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
525 // _volumeMapper = volumeMapper;