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 );
89 double* origin = img->GetOrigin();
90 img->GetExtent(x1,x2,y1,y2,z1,z2);
98 x1 = (int)(x1*spc[0]);
99 y1 = (int)(y1*spc[1]);
100 z1 = (int)(z1*spc[2]);
101 x2 = (int)(x2*spc[0]);
102 y2 = (int)(y2*spc[1]);
103 z2 = (int)(z2*spc[2]);
108 if(_lineAActor==NULL){
109 _lineAActor = vtkActor::New();
110 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
111 _lineAActor->GetProperty()->SetLineWidth(0.5);
113 _ptsA = vtkPoints::New();
114 _ptsA->SetNumberOfPoints(2);
115 _ptsA->SetPoint(0, -1000 , -1000 , -1000 );
116 _ptsA->SetPoint(1, 1000 , 1000 , 1000 );
117 _pdA = vtkPolyData::New();
118 _lineAMapper = vtkPolyDataMapper::New();
120 //EED 2017-01-01 Migration VTK7
121 #if VTK_MAJOR_VERSION <= 5
122 _lineAMapper->SetInput(_pdA);
124 _lineAMapper->SetInputData(_pdA);
127 _lineAMapper->ImmediateModeRenderingOn();
128 _lineAActor->SetMapper(_lineAMapper);
131 vtkCellArray *linesA = vtkCellArray::New();
132 linesA->InsertNextCell(2);
133 linesA->InsertCellPoint(0);
134 linesA->InsertCellPoint(1);
135 _pdA->SetPoints( _ptsA );
136 _pdA->SetLines( linesA );
137 linesA->Delete(); //do not delete lines ??
138 // _lineAActor->GetProperty()->BackfaceCullingOn();
142 if(_lineBActor==NULL)
144 _lineBActor = vtkActor::New();
145 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
146 _lineBActor->GetProperty()->SetLineWidth(0.5);
147 _lineBMapper = vtkPolyDataMapper::New();
148 _lineBActor->SetMapper(_lineBMapper);
149 _ptsB = vtkPoints::New();
150 _ptsB->SetNumberOfPoints(2);
151 _ptsB->SetPoint(0, -1000 , -1000 , -1000 );
152 _ptsB->SetPoint(1, 1000 , 1000 , 1000 );
153 // _lineBActor->GetProperty()->BackfaceCullingOn();
156 vtkCellArray *linesB;
157 linesB = vtkCellArray::New();
158 linesB->InsertNextCell(2);
159 linesB->InsertCellPoint(0);
160 linesB->InsertCellPoint(1);
161 _pdB = vtkPolyData::New();
162 _pdB->SetPoints( _ptsB );
163 _pdB->SetLines( linesB );
164 linesB->Delete(); //do not delete lines ??
166 //EED 2017-01-01 Migration VTK7
167 #if VTK_MAJOR_VERSION <= 5
168 _lineBMapper->SetInput(_pdB);
170 _lineBMapper->SetInputData(_pdB);
173 _lineBMapper->ImmediateModeRenderingOn();
176 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
177 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
178 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
181 //EED 21 mars 2012 FLIP problem ..PLOP..
185 camera->SetViewUp ( 0 , 0 , 1 );
186 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
187 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
188 camera->SetParallelScale( (z2-z1)/3.0 );
192 camera->SetViewUp ( 0 , 0 , 1 );
193 camera->SetPosition ((x1+x2)/2 , -10000 , (z1+z2)/2 );
194 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
195 camera->SetParallelScale( (x2-x1)/3.0 );
199 camera->SetViewUp ( 0 , -1 , 0 );
200 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000);
201 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
202 camera->SetParallelScale( (x2-x1)/3.0 );
206 if (_direction==0) { // YZ
207 camera->SetViewUp ( 0 , 1 , 0 );
208 camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 );
209 camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 );
210 camera->SetParallelScale( (z2-z1)/3.0 );
213 if (_direction==1) { // XZ
214 camera->SetViewUp ( 0 , 0 , -1 );
215 camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 );
216 camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 );
217 camera->SetParallelScale( (x2-x1)/3.0 );
220 if (_direction==2) { // XY
221 camera->SetViewUp ( 0 , 1 , 0 );
222 camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000);
223 camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 );
224 camera->SetParallelScale( (x2-x1)/3.0 );
228 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
229 // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
233 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
235 if (ok != _visibleAxis)
238 if (_visibleAxis==true)
240 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
241 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
243 if (_visibleAxis==false)
245 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
246 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
252 //-------------------------------------------------------------------
253 void wxVtkMPR2DView::ResetBackXYZ()
261 //-------------------------------------------------------------------
262 void wxVtkMPR2DView::Refresh()
264 //wxVtk2DBaseView::Refresh();
265 int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0;
267 // int x = 0, y = 0, z = 0;
268 double x = 0, y = 0, z = 0;
269 int xx = 0, yy = 0, zz = 0;
272 double xx1,yy1,zz1,xx2,yy2,zz2;
275 vtkImageData* img = GetVtkmprbasedata()->GetImageData();
278 origin = img->GetOrigin();
279 img->GetExtent(x1,x2,y1,y2,z1,z2);
280 spc = img->GetSpacing();
293 x1 = (int)(x1*spc[0]);
294 y1 = (int)(y1*spc[1]);
295 z1 = (int)(z1*spc[2]);
296 x2 = (int)(x2*spc[0]);
297 y2 = (int)(y2*spc[1]);
298 z2 = (int)(z2*spc[2]);
299 xx = (int)(GetVtkmprbasedata()->GetX());
300 yy = (int)(GetVtkmprbasedata()->GetY());
301 zz = (int)(GetVtkmprbasedata()->GetZ());
305 fixAxis2D = GetVtkmprbasedata()->GetFixAxis2D();
306 opacityAxis = GetVtkmprbasedata()->GetOpacityAxis();
307 if ((xx!=_backX) || (yy!=_backY) || (zz!=_backZ) || (fixAxis2D!=_backFixAxis2D) || (opacityAxis!=_backOpacityAxis))
310 double focalpoint[3];
311 GetRenderer()->GetActiveCamera()->GetPosition(position);
312 GetRenderer()->GetActiveCamera()->GetFocalPoint(focalpoint);
313 if (_direction==0) { // YZ
316 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) );
318 //EED 21 mars 2012 FLIP probleme ..PLOP..
319 //_ptsA->SetPoint(0, x2, y1 , z );
320 //_ptsA->SetPoint(1, x2, y2 , z );
321 //_ptsB->SetPoint(0, x2, y , z1);
322 //_ptsB->SetPoint(1, x2, y , z2);
323 _ptsA->SetPoint(0, xx2, yy1 , z );
324 _ptsA->SetPoint(1, xx2, yy2 , z );
325 _ptsB->SetPoint(0, xx2, y , zz1);
326 _ptsB->SetPoint(1, xx2, y , zz2);
332 if (_direction==1) { // XZ
335 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) );
337 //EED 21 mars 2012 FLIP probleme ..PLOP..
338 //_ptsA->SetPoint(0, x1 , y2 , z );
339 //_ptsA->SetPoint(1, x2 , y2 , z );
340 //_ptsB->SetPoint(0, x , y2 , z1);
341 //_ptsB->SetPoint(1, x , y2 , z2);
342 _ptsA->SetPoint(0, xx1 , y1 , z );
343 _ptsA->SetPoint(1, xx2 , y1 , z );
344 _ptsB->SetPoint(0, x , y1 , zz1);
345 _ptsB->SetPoint(1, x , y1 , zz2);
351 if (_direction==2) { // XY
354 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) );
356 // _ptsA->SetPoint(0, x1 , y , -z2 );
357 // _ptsA->SetPoint(1, x2 , y , -z2 );
358 // _ptsB->SetPoint(0, x , y1, -z2 );
359 // _ptsB->SetPoint(1, x , y2, -z2 );
362 //EED 21 mars 2012 FLIP probleme ..PLOP..
363 //_ptsA->SetPoint(0, x1 , y , z2 );
364 //_ptsA->SetPoint(1, x2 , y , z2 );
365 //_ptsB->SetPoint(0, x , y1, z2 );
366 //_ptsB->SetPoint(1, x , y2, z2 );
367 _ptsA->SetPoint(0, xx1 , y , z1 );
368 _ptsA->SetPoint(1, xx2 , y , z1 );
369 _ptsB->SetPoint(0, x , yy1, z1 );
370 _ptsB->SetPoint(1, x , yy2, z1 );
377 //EED 2017-01-01 Migration VTK7
378 #if VTK_MAJOR_VERSION <= 5
385 if (fixAxis2D == true)
387 GetRenderer()->GetActiveCamera()->SetPosition(position);
388 GetRenderer()->GetActiveCamera()->SetFocalPoint(focalpoint);
390 _lineAActor->GetProperty()->SetOpacity( opacityAxis );
391 _lineBActor->GetProperty()->SetOpacity( opacityAxis );
392 SetOpacityText( opacityAxis );
396 _backFixAxis2D = fixAxis2D;
397 _backOpacityAxis= opacityAxis;
401 vtkImageActor *imageactor = _imageViewer2XYZ->GetVtkImageViewer2()->GetImageActor();
402 imageactor->SetInterpolate( GetVtkBaseData()->GetInterpolate() );
404 UpdateColorWindowLevel();
406 UpdateCameraParallelScale();
407 wxVtkBaseView::Refresh();
411 //-------------------------------------------------------------------
412 int wxVtkMPR2DView::GetActualSlice() // virtual
417 result = (int)(GetVtkmprbasedata()->GetX());
421 result = (int)(GetVtkmprbasedata()->GetY());
425 result = (int)(GetVtkmprbasedata()->GetZ());
429 //-------------------------------------------------------------------
430 void wxVtkMPR2DView::SetActualSlice(int slice) // virtual
434 GetVtkmprbasedata()->SetX(slice);
438 GetVtkmprbasedata()->SetY(slice);
442 GetVtkmprbasedata()->SetZ(slice);
445 //-------------------------------------------------------------------
446 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
455 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
462 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
469 //-------------------------------------------------------------------
470 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
476 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
486 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
493 //-------------------------------------------------------------------
494 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
500 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
507 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
517 //-------------------------------------------------------------------
518 void wxVtkMPR2DView::MoveX(double x, double y, double z)
525 GetVtkmprbasedata()->SetX(x);
529 GetVtkmprbasedata()->SetX(x);
532 //-------------------------------------------------------------------
533 void wxVtkMPR2DView::MoveY(double x, double y, double z)
537 GetVtkmprbasedata()->SetY(y);
544 GetVtkmprbasedata()->SetY(y);
547 //-------------------------------------------------------------------
548 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
552 GetVtkmprbasedata()->SetZ(z);
556 GetVtkmprbasedata()->SetZ(z);
562 //-------------------------------------------------------------------
563 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
565 double c1r=1,c1g=1,c1b=0;
566 double c2r=1,c2g=0,c2b=0;
570 if (IfMouseTouchY(x,y,z)==true)
572 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
574 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
576 if (IfMouseTouchZ(x,y,z)==true)
578 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
580 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
586 if (IfMouseTouchX(x,y,z)==true)
588 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
590 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
592 if (IfMouseTouchZ(x,y,z)==true)
594 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
596 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
602 if (IfMouseTouchX(x,y,z)==true)
604 _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
606 _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
608 if (IfMouseTouchY(x,y,z)==true)
610 _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
612 _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
620 //void wxVtkMPR2DView::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual
621 void wxVtkMPR2DView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
624 wxVtkBaseView::TransFromCoordScreenToWorld(X,Y,Z,keepNormalDirection,_direction);
626 if ((_direction==0) && (keepNormalDirection==true) )
628 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
631 if ((_direction==1) && (keepNormalDirection==true) )
633 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
636 if ((_direction==2) && (keepNormalDirection==true) )
638 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
643 //-------------------------------------------------------------------
644 int wxVtkMPR2DView::GetDirection() // virtual
650 //-------------------------------------------------------------------
651 //-------------------------------------------------------------------
652 //-------------------------------------------------------------------
653 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
654 // if (eventId==vtkCommand::StartInteractionEvent){
655 // _renWin->SetDesiredUpdateRate(10);
657 // if (eventId==vtkCommand::InteractionEvent){
658 // _renWin->SetDesiredUpdateRate(0.001);
660 // if (eventId==vtkCommand::EndInteractionEvent){
661 // vtkPlanes *planes = vtkPlanes::New();
662 // vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
663 // boxwidget->GetPlanes(planes);
664 // _volumeMapper->SetClippingPlanes(planes);
665 // planes -> Delete();
669 //-------------------------------------------------------------------
670 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
673 //-------------------------------------------------------------------
674 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
675 // _volumeMapper = volumeMapper;