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;
22 _interactorstylemprview = NULL;
25 //-------------------------------------------------------------------
26 wxVtkMPR2DView::~wxVtkMPR2DView()
28 if (_ptsA!=NULL) { _ptsA -> Delete(); }
29 if (_lineAActor!=NULL) { _lineAActor -> Delete(); }
30 if (_lineAMapper!=NULL) { _lineAMapper -> Delete(); }
31 if (_pdA!=NULL) { _pdA -> Delete(); }
32 if (_ptsB!=NULL) { _ptsB -> Delete(); }
33 if (_lineBActor!=NULL) { _lineBActor -> Delete(); }
34 if (_lineBMapper!=NULL) { _lineBMapper -> Delete(); }
35 if (_pdB!=NULL) { _pdB -> Delete(); }
37 //-------------------------------------------------------------------
38 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
40 return (vtkMPRBaseData*)GetVtkBaseData();
42 //-------------------------------------------------------------------
43 void wxVtkMPR2DView::Configure(){
44 wxVtk2DBaseView::Configure();
46 if(_interactorstylemprview==NULL)
48 _interactorstylemprview = new vtkInteractorStyleMPRView();
49 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
54 int x1,x2,y1,y2,z1,z2;
55 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
58 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
61 x1 = (int)(x1*spc[0]);
62 y1 = (int)(y1*spc[1]);
63 z1 = (int)(z1*spc[2]);
65 x2 = (int)(x2*spc[0]);
66 y2 = (int)(y2*spc[1]);
67 z2 = (int)(z2*spc[2]);
72 if(_lineAActor==NULL){
73 _ptsA = vtkPoints::New();
74 _ptsA->SetNumberOfPoints(2);
75 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
76 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
78 linesA = vtkCellArray::New();
79 linesA->InsertNextCell(2);
80 linesA->InsertCellPoint(0);
81 linesA->InsertCellPoint(1);
82 _pdA = vtkPolyData::New();
83 _pdA->SetPoints( _ptsA );
84 _pdA->SetLines( linesA );
85 linesA->Delete(); //do not delete lines ??
86 _lineAActor = vtkActor::New();
87 _lineAMapper = vtkPolyDataMapper::New();
89 _lineAMapper->SetInput(_pdA);
90 _lineAMapper->ImmediateModeRenderingOn();
91 _lineAActor->SetMapper(_lineAMapper);
92 // _lineAActor->GetProperty()->BackfaceCullingOn();
93 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
94 _lineAActor->GetProperty()->SetLineWidth(2);
95 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
102 if(_lineBActor==NULL){
103 _ptsB = vtkPoints::New();
104 _ptsB->SetNumberOfPoints(2);
105 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
106 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
107 vtkCellArray *linesB;
108 linesB = vtkCellArray::New();
109 linesB->InsertNextCell(2);
110 linesB->InsertCellPoint(0);
111 linesB->InsertCellPoint(1);
112 _pdB = vtkPolyData::New();
113 _pdB->SetPoints( _ptsB );
114 _pdB->SetLines( linesB );
115 linesB->Delete(); //do not delete lines ??
116 _lineBActor = vtkActor::New();
117 _lineBMapper = vtkPolyDataMapper::New();
118 _lineBMapper->SetInput(_pdB);
119 _lineBMapper->ImmediateModeRenderingOn();
120 _lineBActor->SetMapper(_lineBMapper);
121 // _lineBActor->GetProperty()->BackfaceCullingOn();
122 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
123 _lineBActor->GetProperty()->SetLineWidth(2);
124 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
128 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
133 camera->SetViewUp ( 0 , -1 , 0 );
134 camera->SetPosition ( -10000,(y1+y2)/2 , (z1+z2)/2 );
135 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
136 camera->SetParallelScale( (z2-z1)/3.0 );
140 camera->SetViewUp ( 0 , 0 , -1 );
141 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
142 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
143 camera->SetParallelScale( (x2-x1)/3.0 );
147 camera->SetViewUp ( 0 , -1 , 0 );
148 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
149 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
150 camera->SetParallelScale( (x2-x1)/3.0 );
154 if (_direction==0) { // YZ
155 camera->SetViewUp ( 0 , 1 , 0 );
156 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
157 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
158 camera->SetParallelScale( (z2-z1)/3.0 );
161 if (_direction==1) { // XZ
162 camera->SetViewUp ( 0 , 0 , -1 );
163 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
164 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
165 camera->SetParallelScale( (x2-x1)/3.0 );
168 if (_direction==2) { // XY
169 camera->SetViewUp ( 0 , 1 , 0 );
170 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
171 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
172 camera->SetParallelScale( (x2-x1)/3.0 );
179 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
180 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
184 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
186 if (ok!=_visibleAxis)
189 if (_visibleAxis==true)
191 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
192 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
194 if (_visibleAxis==false)
196 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
197 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
203 //-------------------------------------------------------------------
204 void wxVtkMPR2DView::Refresh()
206 //wxVtk2DBaseView::Refresh();
209 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
210 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
214 int x1,x2,y1,y2,z1,z2;
215 GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
218 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
220 img->GetSpacing(spc);
221 x1 = (int)(x1*spc[0]);
222 y1 = (int)(y1*spc[1]);
223 z1 = (int)(z1*spc[2]);
225 x2 = (int)(x2*spc[0]);
226 y2 = (int)(y2*spc[1]);
227 z2 = (int)(z2*spc[2]);
229 int x = (int)(GetVtkmprbasedata()->GetX());
230 int y = (int)(GetVtkmprbasedata()->GetY());
231 int z = (int)(GetVtkmprbasedata()->GetZ());
237 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
239 if (_direction==0) { // YZ
240 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
241 _ptsA->SetPoint(0, x2, y1 , z );
242 _ptsA->SetPoint(1, x2, y2 , z );
243 _ptsB->SetPoint(0, x2, y , z1);
244 _ptsB->SetPoint(1, x2, y , z2);
246 if (_direction==1) { // XZ
247 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
248 _ptsA->SetPoint(0, x1 , y2 , z );
249 _ptsA->SetPoint(1, x2 , y2 , z );
250 _ptsB->SetPoint(0, x , y2 , z1);
251 _ptsB->SetPoint(1, x , y2 , z2);
253 if (_direction==2) { // XY
254 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
255 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
256 // _ptsA->SetPoint(0, x1 , y , -z2 );
257 // _ptsA->SetPoint(1, x2 , y , -z2 );
258 // _ptsB->SetPoint(0, x , y1, -z2 );
259 // _ptsB->SetPoint(1, x , y2, -z2 );
261 _ptsA->SetPoint(0, x1 , y , z2 );
262 _ptsA->SetPoint(1, x2 , y , z2 );
263 _ptsB->SetPoint(0, x , y1, z2 );
264 _ptsB->SetPoint(1, x , y2, z2 );
270 wxVtkBaseView::Refresh();
273 //-------------------------------------------------------------------
274 int wxVtkMPR2DView::GetActualSlice() // virtual
279 result = (int)(GetVtkmprbasedata()->GetX());
283 result = (int)(GetVtkmprbasedata()->GetY());
287 result = (int)(GetVtkmprbasedata()->GetZ());
291 //-------------------------------------------------------------------
292 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
296 GetVtkmprbasedata()->SetX(slice);
300 GetVtkmprbasedata()->SetY(slice);
304 GetVtkmprbasedata()->SetZ(slice);
307 //-------------------------------------------------------------------
308 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
317 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
324 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
331 //-------------------------------------------------------------------
332 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
338 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
348 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
355 //-------------------------------------------------------------------
356 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
362 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
369 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
379 //-------------------------------------------------------------------
380 void wxVtkMPR2DView::MoveX(double x, double y, double z)
387 GetVtkmprbasedata()->SetX(x);
391 GetVtkmprbasedata()->SetX(x);
394 //-------------------------------------------------------------------
395 void wxVtkMPR2DView::MoveY(double x, double y, double z)
399 GetVtkmprbasedata()->SetY(y);
406 GetVtkmprbasedata()->SetY(y);
409 //-------------------------------------------------------------------
410 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
414 GetVtkmprbasedata()->SetZ(z);
418 GetVtkmprbasedata()->SetZ(z);
424 //-------------------------------------------------------------------
425 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
427 double c1r=1,c1g=1,c1b=0;
428 double c2r=1,c2g=0,c2b=0;
432 if (IfMouseTouchY(x,y,z)==true)
434 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
436 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
438 if (IfMouseTouchZ(x,y,z)==true)
440 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
442 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
448 if (IfMouseTouchX(x,y,z)==true)
450 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
452 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
454 if (IfMouseTouchZ(x,y,z)==true)
456 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
458 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
464 if (IfMouseTouchX(x,y,z)==true)
466 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
468 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
470 if (IfMouseTouchY(x,y,z)==true)
472 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
474 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
482 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
483 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
486 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
488 if ((_direction==0) && (keepNormalDirection==true) )
490 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
493 if ((_direction==1) && (keepNormalDirection==true) )
495 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
498 if ((_direction==2) && (keepNormalDirection==true) )
500 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
506 //-------------------------------------------------------------------
507 //-------------------------------------------------------------------
508 //-------------------------------------------------------------------
509 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
510 // if (eventId==vtkCommand::StartInteractionEvent){
511 // _renWin->SetDesiredUpdateRate(10);
513 // if (eventId==vtkCommand::InteractionEvent){
514 // _renWin->SetDesiredUpdateRate(0.001);
516 // if (eventId==vtkCommand::EndInteractionEvent){
517 // vtkPlanes *planes = vtkPlanes::New();
518 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
519 // boxwidget->GetPlanes(planes);
520 // _volumeMapper->SetClippingPlanes(planes);
521 // planes -> Delete();
525 //-------------------------------------------------------------------
526 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
529 //-------------------------------------------------------------------
530 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
531 // _volumeMapper = volumeMapper;