1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "wxVtkMPR2DView.h"
28 #include "vtkInteractorStyleBaseView.h"
30 #include "vtkCellArray.h"
31 #include "vtkImageActor.h"
38 wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction)
39 :wxVtk2DBaseView(parent)
44 _direction = direction;
53 _interactorstylemprview = NULL;
56 //-------------------------------------------------------------------
57 wxVtkMPR2DView::~wxVtkMPR2DView()
59 if (_ptsA!=NULL) { _ptsA -> Delete(); }
60 if (_lineAActor!=NULL) { _lineAActor -> Delete(); }
61 if (_lineAMapper!=NULL) { _lineAMapper -> Delete(); }
62 if (_pdA!=NULL) { _pdA -> Delete(); }
63 if (_ptsB!=NULL) { _ptsB -> Delete(); }
64 if (_lineBActor!=NULL) { _lineBActor -> Delete(); }
65 if (_lineBMapper!=NULL) { _lineBMapper -> Delete(); }
66 if (_pdB!=NULL) { _pdB -> Delete(); }
68 //-------------------------------------------------------------------
69 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
71 return (vtkMPRBaseData*)GetVtkBaseData();
73 //-------------------------------------------------------------------
74 void wxVtkMPR2DView::Configure()
76 wxVtk2DBaseView::Configure();
77 int x1,x2,y1,y2,z1,z2;
78 GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
80 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
81 if(_interactorstylemprview==NULL)
83 _interactorstylemprview = new vtkInteractorStyleMPRView();
84 ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview );
88 double* origin = img->GetOrigin();
89 img->GetExtent(x1,x2,y1,y2,z1,z2);
97 x1 = (int)(x1*spc[0]);
98 y1 = (int)(y1*spc[1]);
99 z1 = (int)(z1*spc[2]);
100 x2 = (int)(x2*spc[0]);
101 y2 = (int)(y2*spc[1]);
102 z2 = (int)(z2*spc[2]);
107 if(_lineAActor==NULL){
108 _lineAActor = vtkActor::New();
109 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
110 _lineAActor->GetProperty()->SetLineWidth(0.5);
112 _ptsA = vtkPoints::New();
113 _ptsA->SetNumberOfPoints(2);
114 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
115 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
116 _pdA = vtkPolyData::New();
117 _lineAMapper = vtkPolyDataMapper::New();
118 _lineAMapper->SetInput(_pdA);
119 _lineAMapper->ImmediateModeRenderingOn();
120 _lineAActor->SetMapper(_lineAMapper);
123 vtkCellArray *linesA = vtkCellArray::New();
124 linesA->InsertNextCell(2);
125 linesA->InsertCellPoint(0);
126 linesA->InsertCellPoint(1);
127 _pdA->SetPoints( _ptsA );
128 _pdA->SetLines( linesA );
129 linesA->Delete(); //do not delete lines ??
130 // _lineAActor->GetProperty()->BackfaceCullingOn();
134 if(_lineBActor==NULL){
135 _lineBActor = vtkActor::New();
136 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
137 _lineBActor->GetProperty()->SetLineWidth(0.5);
138 _lineBMapper = vtkPolyDataMapper::New();
139 _lineBActor->SetMapper(_lineBMapper);
140 _ptsB = vtkPoints::New();
141 _ptsB->SetNumberOfPoints(2);
142 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
143 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
144 // _lineBActor->GetProperty()->BackfaceCullingOn();
147 vtkCellArray *linesB;
148 linesB = vtkCellArray::New();
149 linesB->InsertNextCell(2);
150 linesB->InsertCellPoint(0);
151 linesB->InsertCellPoint(1);
152 _pdB = vtkPolyData::New();
153 _pdB->SetPoints( _ptsB );
154 _pdB->SetLines( linesB );
155 linesB->Delete(); //do not delete lines ??
156 _lineBMapper->SetInput(_pdB);
157 _lineBMapper->ImmediateModeRenderingOn();
158 if(_imageViewer2XYZ){
159 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
160 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
161 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
164 //EED 21 mars 2012 FLIP problem ..PLOP..
166 if (_direction==0) { // YZ
167 camera->SetViewUp ( 0 , 0 , 1 );
168 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
169 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
170 camera->SetParallelScale( (z2-z1)/3.0 );
173 if (_direction==1) { // XZ
174 camera->SetViewUp ( 0 , 0 , 1 );
175 camera->SetPosition ((x1+x2)/2 , -10000 , (z1+z2)/2 );
176 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
177 camera->SetParallelScale( (x2-x1)/3.0 );
180 if (_direction==2) { // XY
181 camera->SetViewUp ( 0 , -1 , 0 );
182 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
183 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
184 camera->SetParallelScale( (x2-x1)/3.0 );
188 if (_direction==0) { // YZ
189 camera->SetViewUp ( 0 , 1 , 0 );
190 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
191 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
192 camera->SetParallelScale( (z2-z1)/3.0 );
195 if (_direction==1) { // XZ
196 camera->SetViewUp ( 0 , 0 , -1 );
197 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
198 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
199 camera->SetParallelScale( (x2-x1)/3.0 );
202 if (_direction==2) { // XY
203 camera->SetViewUp ( 0 , 1 , 0 );
204 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
205 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
206 camera->SetParallelScale( (x2-x1)/3.0 );
210 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
211 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
215 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
217 if (ok!=_visibleAxis)
220 if (_visibleAxis==true)
222 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
223 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
225 if (_visibleAxis==false)
227 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
228 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
234 //-------------------------------------------------------------------
235 void wxVtkMPR2DView::Refresh()
237 //wxVtk2DBaseView::Refresh();
238 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
241 // int x = 0, y = 0, z = 0;
242 double x = 0, y = 0, z = 0;
244 int xx = 0, yy = 0, zz = 0;
248 double xx1,yy1,zz1,xx2,yy2,zz2;
250 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
253 origin = img->GetOrigin();
254 img->GetExtent(x1,x2,y1,y2,z1,z2);
255 spc = img->GetSpacing();
271 x1 = (int)(x1*spc[0]);
272 y1 = (int)(y1*spc[1]);
273 z1 = (int)(z1*spc[2]);
275 x2 = (int)(x2*spc[0]);
276 y2 = (int)(y2*spc[1]);
277 z2 = (int)(z2*spc[2]);
279 xx = (int)(GetVtkmprbasedata()->GetX());
280 yy = (int)(GetVtkmprbasedata()->GetY());
281 zz = (int)(GetVtkmprbasedata()->GetZ());
284 // x = round(xx*spc[0]);
285 // y = round(yy*spc[1]);
286 // z = round(zz*spc[2]);
292 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ))
295 if (_direction==0) { // YZ
298 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
300 //EED 21 mars 2012 FLIP probleme ..PLOP..
301 //_ptsA->SetPoint(0, x2, y1 , z );
302 //_ptsA->SetPoint(1, x2, y2 , z );
303 //_ptsB->SetPoint(0, x2, y , z1);
304 //_ptsB->SetPoint(1, x2, y , z2);
305 _ptsA->SetPoint(0, xx2, yy1 , z );
306 _ptsA->SetPoint(1, xx2, yy2 , z );
307 _ptsB->SetPoint(0, xx2, y , zz1);
308 _ptsB->SetPoint(1, xx2, y , zz2);
310 if (_direction==1) { // XZ
313 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
315 //EED 21 mars 2012 FLIP probleme ..PLOP..
316 //_ptsA->SetPoint(0, x1 , y2 , z );
317 //_ptsA->SetPoint(1, x2 , y2 , z );
318 //_ptsB->SetPoint(0, x , y2 , z1);
319 //_ptsB->SetPoint(1, x , y2 , z2);
320 _ptsA->SetPoint(0, xx1 , y1 , z );
321 _ptsA->SetPoint(1, xx2 , y1 , z );
322 _ptsB->SetPoint(0, x , y1 , zz1);
323 _ptsB->SetPoint(1, x , y1 , zz2);
325 if (_direction==2) { // XY
328 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
330 // _ptsA->SetPoint(0, x1 , y , -z2 );
331 // _ptsA->SetPoint(1, x2 , y , -z2 );
332 // _ptsB->SetPoint(0, x , y1, -z2 );
333 // _ptsB->SetPoint(1, x , y2, -z2 );
336 //EED 21 mars 2012 FLIP probleme ..PLOP..
337 //_ptsA->SetPoint(0, x1 , y , z2 );
338 //_ptsA->SetPoint(1, x2 , y , z2 );
339 //_ptsB->SetPoint(0, x , y1, z2 );
340 //_ptsB->SetPoint(1, x , y2, z2 );
342 _ptsA->SetPoint(0, xx1 , y , z1 );
343 _ptsA->SetPoint(1, xx2 , y , z1 );
344 _ptsB->SetPoint(0, x , yy1, z1 );
345 _ptsB->SetPoint(1, x , yy2, z1 );
355 vtkImageActor *imageactor = _imageViewer2XYZ->GetVtkImageViewer2()->GetImageActor();
356 imageactor->SetInterpolate( GetVtkBaseData()->GetInterpolate() );
358 UpdateColorWindowLevel();
359 wxVtkBaseView::Refresh();
363 //-------------------------------------------------------------------
364 int wxVtkMPR2DView::GetActualSlice() // virtual
369 result = (int)(GetVtkmprbasedata()->GetX());
373 result = (int)(GetVtkmprbasedata()->GetY());
377 result = (int)(GetVtkmprbasedata()->GetZ());
381 //-------------------------------------------------------------------
382 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
386 GetVtkmprbasedata()->SetX(slice);
390 GetVtkmprbasedata()->SetY(slice);
394 GetVtkmprbasedata()->SetZ(slice);
397 //-------------------------------------------------------------------
398 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
407 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
414 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
421 //-------------------------------------------------------------------
422 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
428 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
438 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
445 //-------------------------------------------------------------------
446 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
452 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
459 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
469 //-------------------------------------------------------------------
470 void wxVtkMPR2DView::MoveX(double x, double y, double z)
477 GetVtkmprbasedata()->SetX(x);
481 GetVtkmprbasedata()->SetX(x);
484 //-------------------------------------------------------------------
485 void wxVtkMPR2DView::MoveY(double x, double y, double z)
489 GetVtkmprbasedata()->SetY(y);
496 GetVtkmprbasedata()->SetY(y);
499 //-------------------------------------------------------------------
500 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
504 GetVtkmprbasedata()->SetZ(z);
508 GetVtkmprbasedata()->SetZ(z);
514 //-------------------------------------------------------------------
515 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
517 double c1r=1,c1g=1,c1b=0;
518 double c2r=1,c2g=0,c2b=0;
522 if (IfMouseTouchY(x,y,z)==true)
524 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
526 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
528 if (IfMouseTouchZ(x,y,z)==true)
530 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
532 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
538 if (IfMouseTouchX(x,y,z)==true)
540 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
542 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
544 if (IfMouseTouchZ(x,y,z)==true)
546 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
548 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
554 if (IfMouseTouchX(x,y,z)==true)
556 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
558 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
560 if (IfMouseTouchY(x,y,z)==true)
562 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
564 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
572 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
573 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
576 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
578 if ((_direction==0) && (keepNormalDirection==true) )
580 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
583 if ((_direction==1) && (keepNormalDirection==true) )
585 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
588 if ((_direction==2) && (keepNormalDirection==true) )
590 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
595 //-------------------------------------------------------------------
596 int wxVtkMPR2DView::GetDirection() // virtual
602 //-------------------------------------------------------------------
603 //-------------------------------------------------------------------
604 //-------------------------------------------------------------------
605 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
606 // if (eventId==vtkCommand::StartInteractionEvent){
607 // _renWin->SetDesiredUpdateRate(10);
609 // if (eventId==vtkCommand::InteractionEvent){
610 // _renWin->SetDesiredUpdateRate(0.001);
612 // if (eventId==vtkCommand::EndInteractionEvent){
613 // vtkPlanes *planes = vtkPlanes::New();
614 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
615 // boxwidget->GetPlanes(planes);
616 // _volumeMapper->SetClippingPlanes(planes);
617 // planes -> Delete();
621 //-------------------------------------------------------------------
622 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
625 //-------------------------------------------------------------------
626 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
627 // _volumeMapper = volumeMapper;