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();
47 int x1,x2,y1,y2,z1,z2;
48 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
51 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
52 if(_interactorstylemprview==NULL)
54 _interactorstylemprview = new vtkInteractorStyleMPRView();
55 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
59 double* origin = img->GetOrigin();
60 img->GetExtent(x1,x2,y1,y2,z1,z2);
68 x1 = (int)(x1*spc[0]);
69 y1 = (int)(y1*spc[1]);
70 z1 = (int)(z1*spc[2]);
72 x2 = (int)(x2*spc[0]);
73 y2 = (int)(y2*spc[1]);
74 z2 = (int)(z2*spc[2]);
83 if(_lineAActor==NULL){
84 _lineAActor = vtkActor::New();
85 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
86 _lineAActor->GetProperty()->SetLineWidth(2);
88 _ptsA = vtkPoints::New();
89 _ptsA->SetNumberOfPoints(2);
90 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
91 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
93 _pdA = vtkPolyData::New();
95 _lineAMapper = vtkPolyDataMapper::New();
97 _lineAMapper->SetInput(_pdA);
98 _lineAMapper->ImmediateModeRenderingOn();
99 _lineAActor->SetMapper(_lineAMapper);
102 vtkCellArray *linesA = vtkCellArray::New();
103 linesA->InsertNextCell(2);
104 linesA->InsertCellPoint(0);
105 linesA->InsertCellPoint(1);
106 _pdA->SetPoints( _ptsA );
107 _pdA->SetLines( linesA );
108 linesA->Delete(); //do not delete lines ??
109 // _lineAActor->GetProperty()->BackfaceCullingOn();
113 if(_lineBActor==NULL){
114 _lineBActor = vtkActor::New();
115 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
116 _lineBActor->GetProperty()->SetLineWidth(2);
117 _lineBMapper = vtkPolyDataMapper::New();
118 _lineBActor->SetMapper(_lineBMapper);
120 _ptsB = vtkPoints::New();
121 _ptsB->SetNumberOfPoints(2);
122 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
123 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
125 // _lineBActor->GetProperty()->BackfaceCullingOn();
128 vtkCellArray *linesB;
129 linesB = vtkCellArray::New();
130 linesB->InsertNextCell(2);
131 linesB->InsertCellPoint(0);
132 linesB->InsertCellPoint(1);
133 _pdB = vtkPolyData::New();
134 _pdB->SetPoints( _ptsB );
135 _pdB->SetLines( linesB );
136 linesB->Delete(); //do not delete lines ??
139 _lineBMapper->SetInput(_pdB);
140 _lineBMapper->ImmediateModeRenderingOn();
143 if(_imageViewer2XYZ){
144 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
145 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
146 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
151 camera->SetViewUp ( 0 , -1 , 0 );
152 camera->SetPosition ( -10000,(y1+y2)/2 , (z1+z2)/2 );
153 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
154 camera->SetParallelScale( (z2-z1)/3.0 );
158 camera->SetViewUp ( 0 , 0 , -1 );
159 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
160 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
161 camera->SetParallelScale( (x2-x1)/3.0 );
165 camera->SetViewUp ( 0 , -1 , 0 );
166 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
167 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
168 camera->SetParallelScale( (x2-x1)/3.0 );
172 if (_direction==0) { // YZ
173 camera->SetViewUp ( 0 , 1 , 0 );
174 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
175 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
176 camera->SetParallelScale( (z2-z1)/3.0 );
179 if (_direction==1) { // XZ
180 camera->SetViewUp ( 0 , 0 , -1 );
181 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
182 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
183 camera->SetParallelScale( (x2-x1)/3.0 );
186 if (_direction==2) { // XY
187 camera->SetViewUp ( 0 , 1 , 0 );
188 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
189 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
190 camera->SetParallelScale( (x2-x1)/3.0 );
194 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
195 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
200 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
202 if (ok!=_visibleAxis)
205 if (_visibleAxis==true)
207 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
208 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
210 if (_visibleAxis==false)
212 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
213 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
219 //-------------------------------------------------------------------
220 void wxVtkMPR2DView::Refresh()
222 //wxVtk2DBaseView::Refresh();
225 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
226 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
230 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0, x = 0, y = 0, z = 0;
235 //GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
238 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
240 origin = img->GetOrigin();
241 img->GetExtent(x1,x2,y1,y2,z1,z2);
242 spc = img->GetSpacing();
249 x1 = (int)(x1*spc[0]);
250 y1 = (int)(y1*spc[1]);
251 z1 = (int)(z1*spc[2]);
253 x2 = (int)(x2*spc[0]);
254 y2 = (int)(y2*spc[1]);
255 z2 = (int)(z2*spc[2]);
257 x = (int)(GetVtkmprbasedata()->GetX());
258 y = (int)(GetVtkmprbasedata()->GetY());
259 z = (int)(GetVtkmprbasedata()->GetZ());
265 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
267 if (_direction==0) { // YZ
269 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
270 _ptsA->SetPoint(0, x2, y1 , z );
271 _ptsA->SetPoint(1, x2, y2 , z );
272 _ptsB->SetPoint(0, x2, y , z1);
273 _ptsB->SetPoint(1, x2, y , z2);
275 if (_direction==1) { // XZ
277 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
278 _ptsA->SetPoint(0, x1 , y2 , z );
279 _ptsA->SetPoint(1, x2 , y2 , z );
280 _ptsB->SetPoint(0, x , y2 , z1);
281 _ptsB->SetPoint(1, x , y2 , z2);
283 if (_direction==2) { // XY
285 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
286 // _ptsA->SetPoint(0, x1 , y , -z2 );
287 // _ptsA->SetPoint(1, x2 , y , -z2 );
288 // _ptsB->SetPoint(0, x , y1, -z2 );
289 // _ptsB->SetPoint(1, x , y2, -z2 );
291 _ptsA->SetPoint(0, x1 , y , z2 );
292 _ptsA->SetPoint(1, x2 , y , z2 );
293 _ptsB->SetPoint(0, x , y1, z2 );
294 _ptsB->SetPoint(1, x , y2, z2 );
300 wxVtkBaseView::Refresh();
303 //-------------------------------------------------------------------
304 int wxVtkMPR2DView::GetActualSlice() // virtual
309 result = (int)(GetVtkmprbasedata()->GetX());
313 result = (int)(GetVtkmprbasedata()->GetY());
317 result = (int)(GetVtkmprbasedata()->GetZ());
321 //-------------------------------------------------------------------
322 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
326 GetVtkmprbasedata()->SetX(slice);
330 GetVtkmprbasedata()->SetY(slice);
334 GetVtkmprbasedata()->SetZ(slice);
337 //-------------------------------------------------------------------
338 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
347 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
354 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
361 //-------------------------------------------------------------------
362 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
368 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
378 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
385 //-------------------------------------------------------------------
386 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
392 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
399 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
409 //-------------------------------------------------------------------
410 void wxVtkMPR2DView::MoveX(double x, double y, double z)
417 GetVtkmprbasedata()->SetX(x);
421 GetVtkmprbasedata()->SetX(x);
424 //-------------------------------------------------------------------
425 void wxVtkMPR2DView::MoveY(double x, double y, double z)
429 GetVtkmprbasedata()->SetY(y);
436 GetVtkmprbasedata()->SetY(y);
439 //-------------------------------------------------------------------
440 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
444 GetVtkmprbasedata()->SetZ(z);
448 GetVtkmprbasedata()->SetZ(z);
454 //-------------------------------------------------------------------
455 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
457 double c1r=1,c1g=1,c1b=0;
458 double c2r=1,c2g=0,c2b=0;
462 if (IfMouseTouchY(x,y,z)==true)
464 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
466 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
468 if (IfMouseTouchZ(x,y,z)==true)
470 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
472 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
478 if (IfMouseTouchX(x,y,z)==true)
480 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
482 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
484 if (IfMouseTouchZ(x,y,z)==true)
486 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
488 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
494 if (IfMouseTouchX(x,y,z)==true)
496 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
498 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
500 if (IfMouseTouchY(x,y,z)==true)
502 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
504 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
512 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
513 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
516 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
518 if ((_direction==0) && (keepNormalDirection==true) )
520 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
523 if ((_direction==1) && (keepNormalDirection==true) )
525 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
528 if ((_direction==2) && (keepNormalDirection==true) )
530 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
536 //-------------------------------------------------------------------
537 //-------------------------------------------------------------------
538 //-------------------------------------------------------------------
539 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
540 // if (eventId==vtkCommand::StartInteractionEvent){
541 // _renWin->SetDesiredUpdateRate(10);
543 // if (eventId==vtkCommand::InteractionEvent){
544 // _renWin->SetDesiredUpdateRate(0.001);
546 // if (eventId==vtkCommand::EndInteractionEvent){
547 // vtkPlanes *planes = vtkPlanes::New();
548 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
549 // boxwidget->GetPlanes(planes);
550 // _volumeMapper->SetClippingPlanes(planes);
551 // planes -> Delete();
555 //-------------------------------------------------------------------
556 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
559 //-------------------------------------------------------------------
560 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
561 // _volumeMapper = volumeMapper;