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();
119 //EED 2017-01-01 Migration VTK7
120 #if VTK_MAJOR_VERSION <= 5
121 _lineAMapper->SetInput(_pdA);
123 _lineAMapper->SetInputData(_pdA);
126 _lineAMapper->ImmediateModeRenderingOn();
127 _lineAActor->SetMapper(_lineAMapper);
130 vtkCellArray *linesA = vtkCellArray::New();
131 linesA->InsertNextCell(2);
132 linesA->InsertCellPoint(0);
133 linesA->InsertCellPoint(1);
134 _pdA->SetPoints( _ptsA );
135 _pdA->SetLines( linesA );
136 linesA->Delete(); //do not delete lines ??
137 // _lineAActor->GetProperty()->BackfaceCullingOn();
141 if(_lineBActor==NULL){
142 _lineBActor = vtkActor::New();
143 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
144 _lineBActor->GetProperty()->SetLineWidth(0.5);
145 _lineBMapper = vtkPolyDataMapper::New();
146 _lineBActor->SetMapper(_lineBMapper);
147 _ptsB = vtkPoints::New();
148 _ptsB->SetNumberOfPoints(2);
149 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
150 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
151 // _lineBActor->GetProperty()->BackfaceCullingOn();
154 vtkCellArray *linesB;
155 linesB = vtkCellArray::New();
156 linesB->InsertNextCell(2);
157 linesB->InsertCellPoint(0);
158 linesB->InsertCellPoint(1);
159 _pdB = vtkPolyData::New();
160 _pdB->SetPoints( _ptsB );
161 _pdB->SetLines( linesB );
162 linesB->Delete(); //do not delete lines ??
164 //EED 2017-01-01 Migration VTK7
165 #if VTK_MAJOR_VERSION <= 5
166 _lineBMapper->SetInput(_pdB);
168 _lineBMapper->SetInputData(_pdB);
171 _lineBMapper->ImmediateModeRenderingOn();
172 if(_imageViewer2XYZ){
173 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
174 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
175 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
178 //EED 21 mars 2012 FLIP problem ..PLOP..
180 if (_direction==0) { // YZ
181 camera->SetViewUp ( 0 , 0 , 1 );
182 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
183 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
184 camera->SetParallelScale( (z2-z1)/3.0 );
187 if (_direction==1) { // XZ
188 camera->SetViewUp ( 0 , 0 , 1 );
189 camera->SetPosition ((x1+x2)/2 , -10000 , (z1+z2)/2 );
190 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
191 camera->SetParallelScale( (x2-x1)/3.0 );
194 if (_direction==2) { // XY
195 camera->SetViewUp ( 0 , -1 , 0 );
196 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
197 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
198 camera->SetParallelScale( (x2-x1)/3.0 );
202 if (_direction==0) { // YZ
203 camera->SetViewUp ( 0 , 1 , 0 );
204 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
205 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
206 camera->SetParallelScale( (z2-z1)/3.0 );
209 if (_direction==1) { // XZ
210 camera->SetViewUp ( 0 , 0 , -1 );
211 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
212 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
213 camera->SetParallelScale( (x2-x1)/3.0 );
216 if (_direction==2) { // XY
217 camera->SetViewUp ( 0 , 1 , 0 );
218 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
219 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
220 camera->SetParallelScale( (x2-x1)/3.0 );
224 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
225 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
229 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
231 if (ok!=_visibleAxis)
234 if (_visibleAxis==true)
236 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
237 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
239 if (_visibleAxis==false)
241 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
242 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
248 //-------------------------------------------------------------------
249 void wxVtkMPR2DView::Refresh()
251 //wxVtk2DBaseView::Refresh();
252 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
255 // int x = 0, y = 0, z = 0;
256 double x = 0, y = 0, z = 0;
258 int xx = 0, yy = 0, zz = 0;
262 double xx1,yy1,zz1,xx2,yy2,zz2;
264 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
267 origin = img->GetOrigin();
268 img->GetExtent(x1,x2,y1,y2,z1,z2);
269 spc = img->GetSpacing();
285 x1 = (int)(x1*spc[0]);
286 y1 = (int)(y1*spc[1]);
287 z1 = (int)(z1*spc[2]);
289 x2 = (int)(x2*spc[0]);
290 y2 = (int)(y2*spc[1]);
291 z2 = (int)(z2*spc[2]);
293 xx = (int)(GetVtkmprbasedata()->GetX());
294 yy = (int)(GetVtkmprbasedata()->GetY());
295 zz = (int)(GetVtkmprbasedata()->GetZ());
298 // x = round(xx*spc[0]);
299 // y = round(yy*spc[1]);
300 // z = round(zz*spc[2]);
306 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ))
309 if (_direction==0) { // YZ
312 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
314 //EED 21 mars 2012 FLIP probleme ..PLOP..
315 //_ptsA->SetPoint(0, x2, y1 , z );
316 //_ptsA->SetPoint(1, x2, y2 , z );
317 //_ptsB->SetPoint(0, x2, y , z1);
318 //_ptsB->SetPoint(1, x2, y , z2);
319 _ptsA->SetPoint(0, xx2, yy1 , z );
320 _ptsA->SetPoint(1, xx2, yy2 , z );
321 _ptsB->SetPoint(0, xx2, y , zz1);
322 _ptsB->SetPoint(1, xx2, y , zz2);
324 if (_direction==1) { // XZ
327 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
329 //EED 21 mars 2012 FLIP probleme ..PLOP..
330 //_ptsA->SetPoint(0, x1 , y2 , z );
331 //_ptsA->SetPoint(1, x2 , y2 , z );
332 //_ptsB->SetPoint(0, x , y2 , z1);
333 //_ptsB->SetPoint(1, x , y2 , z2);
334 _ptsA->SetPoint(0, xx1 , y1 , z );
335 _ptsA->SetPoint(1, xx2 , y1 , z );
336 _ptsB->SetPoint(0, x , y1 , zz1);
337 _ptsB->SetPoint(1, x , y1 , zz2);
339 if (_direction==2) { // XY
342 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
344 // _ptsA->SetPoint(0, x1 , y , -z2 );
345 // _ptsA->SetPoint(1, x2 , y , -z2 );
346 // _ptsB->SetPoint(0, x , y1, -z2 );
347 // _ptsB->SetPoint(1, x , y2, -z2 );
350 //EED 21 mars 2012 FLIP probleme ..PLOP..
351 //_ptsA->SetPoint(0, x1 , y , z2 );
352 //_ptsA->SetPoint(1, x2 , y , z2 );
353 //_ptsB->SetPoint(0, x , y1, z2 );
354 //_ptsB->SetPoint(1, x , y2, z2 );
356 _ptsA->SetPoint(0, xx1 , y , z1 );
357 _ptsA->SetPoint(1, xx2 , y , z1 );
358 _ptsB->SetPoint(0, x , yy1, z1 );
359 _ptsB->SetPoint(1, x , yy2, z1 );
364 //EED 2017-01-01 Migration VTK7
365 #if VTK_MAJOR_VERSION <= 5
378 vtkImageActor *imageactor = _imageViewer2XYZ->GetVtkImageViewer2()->GetImageActor();
379 imageactor->SetInterpolate( GetVtkBaseData()->GetInterpolate() );
381 UpdateColorWindowLevel();
382 wxVtkBaseView::Refresh();
386 //-------------------------------------------------------------------
387 int wxVtkMPR2DView::GetActualSlice() // virtual
392 result = (int)(GetVtkmprbasedata()->GetX());
396 result = (int)(GetVtkmprbasedata()->GetY());
400 result = (int)(GetVtkmprbasedata()->GetZ());
404 //-------------------------------------------------------------------
405 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
409 GetVtkmprbasedata()->SetX(slice);
413 GetVtkmprbasedata()->SetY(slice);
417 GetVtkmprbasedata()->SetZ(slice);
420 //-------------------------------------------------------------------
421 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
430 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
437 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
444 //-------------------------------------------------------------------
445 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
451 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
461 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
468 //-------------------------------------------------------------------
469 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
475 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
482 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
492 //-------------------------------------------------------------------
493 void wxVtkMPR2DView::MoveX(double x, double y, double z)
500 GetVtkmprbasedata()->SetX(x);
504 GetVtkmprbasedata()->SetX(x);
507 //-------------------------------------------------------------------
508 void wxVtkMPR2DView::MoveY(double x, double y, double z)
512 GetVtkmprbasedata()->SetY(y);
519 GetVtkmprbasedata()->SetY(y);
522 //-------------------------------------------------------------------
523 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
527 GetVtkmprbasedata()->SetZ(z);
531 GetVtkmprbasedata()->SetZ(z);
537 //-------------------------------------------------------------------
538 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
540 double c1r=1,c1g=1,c1b=0;
541 double c2r=1,c2g=0,c2b=0;
545 if (IfMouseTouchY(x,y,z)==true)
547 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
549 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
551 if (IfMouseTouchZ(x,y,z)==true)
553 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
555 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
561 if (IfMouseTouchX(x,y,z)==true)
563 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
565 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
567 if (IfMouseTouchZ(x,y,z)==true)
569 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
571 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
577 if (IfMouseTouchX(x,y,z)==true)
579 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
581 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
583 if (IfMouseTouchY(x,y,z)==true)
585 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
587 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
595 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
596 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
599 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
601 if ((_direction==0) && (keepNormalDirection==true) )
603 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
606 if ((_direction==1) && (keepNormalDirection==true) )
608 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
611 if ((_direction==2) && (keepNormalDirection==true) )
613 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
618 //-------------------------------------------------------------------
619 int wxVtkMPR2DView::GetDirection() // virtual
625 //-------------------------------------------------------------------
626 //-------------------------------------------------------------------
627 //-------------------------------------------------------------------
628 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
629 // if (eventId==vtkCommand::StartInteractionEvent){
630 // _renWin->SetDesiredUpdateRate(10);
632 // if (eventId==vtkCommand::InteractionEvent){
633 // _renWin->SetDesiredUpdateRate(0.001);
635 // if (eventId==vtkCommand::EndInteractionEvent){
636 // vtkPlanes *planes = vtkPlanes::New();
637 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
638 // boxwidget->GetPlanes(planes);
639 // _volumeMapper->SetClippingPlanes(planes);
640 // planes -> Delete();
644 //-------------------------------------------------------------------
645 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
648 //-------------------------------------------------------------------
649 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
650 // _volumeMapper = volumeMapper;