1 #include "wxVtkMPR2DView.h"
3 #include "vtkInteractorStyleBaseView.h"
5 #include "vtkCellArray.h"
11 wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction)
12 :wxVtk2DBaseView(parent)
17 _direction = direction;
26 _interactorstylemprview = NULL;
29 //-------------------------------------------------------------------
30 wxVtkMPR2DView::~wxVtkMPR2DView()
32 if (_ptsA!=NULL) { _ptsA -> Delete(); }
33 if (_lineAActor!=NULL) { _lineAActor -> Delete(); }
34 if (_lineAMapper!=NULL) { _lineAMapper -> Delete(); }
35 if (_pdA!=NULL) { _pdA -> Delete(); }
36 if (_ptsB!=NULL) { _ptsB -> Delete(); }
37 if (_lineBActor!=NULL) { _lineBActor -> Delete(); }
38 if (_lineBMapper!=NULL) { _lineBMapper -> Delete(); }
39 if (_pdB!=NULL) { _pdB -> Delete(); }
41 //-------------------------------------------------------------------
42 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
44 return (vtkMPRBaseData*)GetVtkBaseData();
46 //-------------------------------------------------------------------
47 void wxVtkMPR2DView::Configure(){
48 wxVtk2DBaseView::Configure();
51 int x1,x2,y1,y2,z1,z2;
52 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
55 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
56 if(_interactorstylemprview==NULL)
58 _interactorstylemprview = new vtkInteractorStyleMPRView();
59 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
63 double* origin = img->GetOrigin();
64 img->GetExtent(x1,x2,y1,y2,z1,z2);
72 x1 = (int)(x1*spc[0]);
73 y1 = (int)(y1*spc[1]);
74 z1 = (int)(z1*spc[2]);
76 x2 = (int)(x2*spc[0]);
77 y2 = (int)(y2*spc[1]);
78 z2 = (int)(z2*spc[2]);
87 if(_lineAActor==NULL){
88 _lineAActor = vtkActor::New();
89 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
90 _lineAActor->GetProperty()->SetLineWidth(2);
92 _ptsA = vtkPoints::New();
93 _ptsA->SetNumberOfPoints(2);
94 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
95 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
97 _pdA = vtkPolyData::New();
99 _lineAMapper = vtkPolyDataMapper::New();
101 _lineAMapper->SetInput(_pdA);
102 _lineAMapper->ImmediateModeRenderingOn();
103 _lineAActor->SetMapper(_lineAMapper);
106 vtkCellArray *linesA = vtkCellArray::New();
107 linesA->InsertNextCell(2);
108 linesA->InsertCellPoint(0);
109 linesA->InsertCellPoint(1);
110 _pdA->SetPoints( _ptsA );
111 _pdA->SetLines( linesA );
112 linesA->Delete(); //do not delete lines ??
113 // _lineAActor->GetProperty()->BackfaceCullingOn();
117 if(_lineBActor==NULL){
118 _lineBActor = vtkActor::New();
119 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
120 _lineBActor->GetProperty()->SetLineWidth(2);
121 _lineBMapper = vtkPolyDataMapper::New();
122 _lineBActor->SetMapper(_lineBMapper);
124 _ptsB = vtkPoints::New();
125 _ptsB->SetNumberOfPoints(2);
126 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
127 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
129 // _lineBActor->GetProperty()->BackfaceCullingOn();
132 vtkCellArray *linesB;
133 linesB = vtkCellArray::New();
134 linesB->InsertNextCell(2);
135 linesB->InsertCellPoint(0);
136 linesB->InsertCellPoint(1);
137 _pdB = vtkPolyData::New();
138 _pdB->SetPoints( _ptsB );
139 _pdB->SetLines( linesB );
140 linesB->Delete(); //do not delete lines ??
143 _lineBMapper->SetInput(_pdB);
144 _lineBMapper->ImmediateModeRenderingOn();
147 if(_imageViewer2XYZ){
148 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
149 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
150 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
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 );
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 );
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 );
176 if (_direction==0) { // YZ
177 camera->SetViewUp ( 0 , 1 , 0 );
178 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
179 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
180 camera->SetParallelScale( (z2-z1)/3.0 );
183 if (_direction==1) { // XZ
184 camera->SetViewUp ( 0 , 0 , -1 );
185 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
186 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
187 camera->SetParallelScale( (x2-x1)/3.0 );
190 if (_direction==2) { // XY
191 camera->SetViewUp ( 0 , 1 , 0 );
192 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
193 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
194 camera->SetParallelScale( (x2-x1)/3.0 );
198 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
199 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
204 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
206 if (ok!=_visibleAxis)
209 if (_visibleAxis==true)
211 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
212 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
214 if (_visibleAxis==false)
216 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
217 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
223 //-------------------------------------------------------------------
224 void wxVtkMPR2DView::Refresh()
228 //wxVtk2DBaseView::Refresh();
231 //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
232 //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
235 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
236 int x = 0, y = 0, z = 0;
237 int xx = 0, yy = 0, zz = 0;
242 //GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
245 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
247 origin = img->GetOrigin();
248 img->GetExtent(x1,x2,y1,y2,z1,z2);
249 spc = img->GetSpacing();
256 x1 = (int)(x1*spc[0]);
257 y1 = (int)(y1*spc[1]);
258 z1 = (int)(z1*spc[2]);
260 x2 = (int)(x2*spc[0]);
261 y2 = (int)(y2*spc[1]);
262 z2 = (int)(z2*spc[2]);
264 xx = (int)(GetVtkmprbasedata()->GetX());
265 yy = (int)(GetVtkmprbasedata()->GetY());
266 zz = (int)(GetVtkmprbasedata()->GetZ());
268 x = round(xx*spc[0]);
269 y = round(yy*spc[1]);
270 z = round(zz*spc[2]);
272 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ)) {
274 if (_direction==0) { // YZ
276 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
277 _ptsA->SetPoint(0, x2, y1 , z );
278 _ptsA->SetPoint(1, x2, y2 , z );
279 _ptsB->SetPoint(0, x2, y , z1);
280 _ptsB->SetPoint(1, x2, y , z2);
282 if (_direction==1) { // XZ
284 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
285 _ptsA->SetPoint(0, x1 , y2 , z );
286 _ptsA->SetPoint(1, x2 , y2 , z );
287 _ptsB->SetPoint(0, x , y2 , z1);
288 _ptsB->SetPoint(1, x , y2 , z2);
290 if (_direction==2) { // XY
292 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
293 // _ptsA->SetPoint(0, x1 , y , -z2 );
294 // _ptsA->SetPoint(1, x2 , y , -z2 );
295 // _ptsB->SetPoint(0, x , y1, -z2 );
296 // _ptsB->SetPoint(1, x , y2, -z2 );
298 _ptsA->SetPoint(0, x1 , y , z2 );
299 _ptsA->SetPoint(1, x2 , y , z2 );
300 _ptsB->SetPoint(0, x , y1, z2 );
301 _ptsB->SetPoint(1, x , y2, z2 );
309 _imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->Modified();
311 wxVtkBaseView::Refresh();
314 //-------------------------------------------------------------------
315 int wxVtkMPR2DView::GetActualSlice() // virtual
320 result = (int)(GetVtkmprbasedata()->GetX());
324 result = (int)(GetVtkmprbasedata()->GetY());
328 result = (int)(GetVtkmprbasedata()->GetZ());
332 //-------------------------------------------------------------------
333 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
337 GetVtkmprbasedata()->SetX(slice);
341 GetVtkmprbasedata()->SetY(slice);
345 GetVtkmprbasedata()->SetZ(slice);
348 //-------------------------------------------------------------------
349 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
358 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
365 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
372 //-------------------------------------------------------------------
373 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
379 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
389 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
396 //-------------------------------------------------------------------
397 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
403 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
410 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
420 //-------------------------------------------------------------------
421 void wxVtkMPR2DView::MoveX(double x, double y, double z)
428 GetVtkmprbasedata()->SetX(x);
432 GetVtkmprbasedata()->SetX(x);
435 //-------------------------------------------------------------------
436 void wxVtkMPR2DView::MoveY(double x, double y, double z)
440 GetVtkmprbasedata()->SetY(y);
447 GetVtkmprbasedata()->SetY(y);
450 //-------------------------------------------------------------------
451 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
455 GetVtkmprbasedata()->SetZ(z);
459 GetVtkmprbasedata()->SetZ(z);
465 //-------------------------------------------------------------------
466 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
468 double c1r=1,c1g=1,c1b=0;
469 double c2r=1,c2g=0,c2b=0;
473 if (IfMouseTouchY(x,y,z)==true)
475 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
477 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
479 if (IfMouseTouchZ(x,y,z)==true)
481 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
483 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
489 if (IfMouseTouchX(x,y,z)==true)
491 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
493 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
495 if (IfMouseTouchZ(x,y,z)==true)
497 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
499 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
505 if (IfMouseTouchX(x,y,z)==true)
507 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
509 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
511 if (IfMouseTouchY(x,y,z)==true)
513 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
515 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
523 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
524 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
527 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
529 if ((_direction==0) && (keepNormalDirection==true) )
531 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
534 if ((_direction==1) && (keepNormalDirection==true) )
536 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
539 if ((_direction==2) && (keepNormalDirection==true) )
541 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
546 //-------------------------------------------------------------------
547 int wxVtkMPR2DView::GetDirection() // virtual
553 //-------------------------------------------------------------------
554 //-------------------------------------------------------------------
555 //-------------------------------------------------------------------
556 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
557 // if (eventId==vtkCommand::StartInteractionEvent){
558 // _renWin->SetDesiredUpdateRate(10);
560 // if (eventId==vtkCommand::InteractionEvent){
561 // _renWin->SetDesiredUpdateRate(0.001);
563 // if (eventId==vtkCommand::EndInteractionEvent){
564 // vtkPlanes *planes = vtkPlanes::New();
565 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
566 // boxwidget->GetPlanes(planes);
567 // _volumeMapper->SetClippingPlanes(planes);
568 // planes -> Delete();
572 //-------------------------------------------------------------------
573 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
576 //-------------------------------------------------------------------
577 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
578 // _volumeMapper = volumeMapper;