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 # ------------------------------------------------------------------------ */
28 * \brief Class bbtk::ThresholdImageView .
31 #include "LayerImageBase.h"
33 #include "wxVtk2DBaseView.h"
34 #include "wxVTKRenderWindowInteractor.h"
37 //---------------------------------------------------------------------------------------------
38 //---------------------------------------------------------------------------------------------
39 //---------------------------------------------------------------------------------------------
41 ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
45 _layerImageBase=layerImageBase;
49 //---------------------------------------------------------------------------------------------
50 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
54 //---------------------------------------------------------------------------------------------
55 bool ColorLayerImageBasevtkInteractor::OnChar()
61 //---------------------------------------------------------------------------------------------
62 bool ColorLayerImageBasevtkInteractor::OnMouseMove() // vitual
64 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove start \n");
66 vtkRenderWindowInteractor *interactor = _vtkInteractorStyleBaseView->GetInteractor();
68 // For example in ManualPaint Action
69 // This is not working, because the order of insertion events mecanism (_vtkInteractorStyleBaseView)
70 // Layer first Paint after.
71 // the only way to make it works is to take the axes an paint. this force a first SetParent_refresh_waiting()
72 // if ( this->_vtkInteractorStyleBaseView->GetParent_refresh_waiting() == true )
74 if ( interactor->GetControlKey()==1 ) // EED This if for ManaulPaint Interaction compatibility
76 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove need Refresh \n" );
77 _layerImageBase->onThreshold();
78 _layerImageBase->GetvtkImageReslice()->Modified();
81 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove NOT need Refresh \n" );
87 wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
88 wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
90 wxVTKiren->GetEventPosition(px, py);
93 double X = (double) px;
94 double Y = (double) py;
95 double Z = wxvtk2Dbaseview->GetActualSlice();
96 // wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z,true, typeView);
97 wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z, true);
99 // _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
101 _layerImageBase->SetX( (int)X );
102 _layerImageBase->SetY( (int)Y );
103 _layerImageBase->SetZ( (int)Z );
104 _layerImageBase->onThreshold();
105 // _layerImageBase->Refresh();
107 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
109 if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
111 _layerImageBase->GetvtkImageReslice()->Modified();
113 printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
118 //---------------------------------------------------------------------------------------------
119 bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
121 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
126 //---------------------------------------------------------------------------------------------
127 bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual
129 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
135 //---------------------------------------------------------------------------------------------
136 //---------------------------------------------------------------------------------------------
137 //---------------------------------------------------------------------------------------------
141 LayerImageBase::LayerImageBase()
143 _actorPresent = false;
147 _thresholdTable = NULL;
148 _thresholdMapper = NULL;
149 _thresholdActor = NULL;
152 _imageReslicer = vtkImageReslice::New();
156 //----------------------------------------------------------------------------
157 LayerImageBase::~LayerImageBase()
161 //----------------------------------------------------------------------------
162 void LayerImageBase::SetX(int x)
167 //----------------------------------------------------------------------------
168 void LayerImageBase::SetY(int y)
173 //----------------------------------------------------------------------------
174 void LayerImageBase::SetZ(int z)
179 //----------------------------------------------------------------------------
180 int LayerImageBase::GetX() // virtual
185 //----------------------------------------------------------------------------
186 int LayerImageBase::GetY() // virtual
190 //----------------------------------------------------------------------------
191 int LayerImageBase::GetZ() // virtual
197 //----------------------------------------------------------------------------
198 vtkImageData* LayerImageBase::GetImage()
203 //----------------------------------------------------------------------------
204 bool LayerImageBase::GetActorPresent()
206 return _actorPresent;
211 //----------------------------------------------------------------------------
212 void LayerImageBase::SetImage(vtkImageData* image)
217 //----------------------------------------------------------------------------
218 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
220 printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
223 _baseView = baseview;
224 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
225 isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
227 printf("EED LayerImageBase::SetwxVtkBaseView end \n");
230 //----------------------------------------------------------------------------
231 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
236 //----------------------------------------------------------------------------
237 void LayerImageBase::Refresh()
239 printf("EED LayerImageBase::Refresh\n");
242 _baseView->Refresh();
247 //----------------------------------------------------------------------------
248 vtkLookupTable* LayerImageBase::GetThresholdTable()
250 return _thresholdTable;
253 //----------------------------------------------------------------------------
254 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
257 _image->GetWholeExtent(ext);
274 if ( x > (ext[1]-ext[0]) )
279 if ( y > (ext[3]-ext[2]) )
284 if ( z > (ext[5]-ext[4]) )
292 //----------------------------------------------------------------------------
293 void LayerImageBase::onThreshold()
296 printf("EED LayerImageBase::onThreshold start \n");
298 if ((_image!=NULL) && (_baseView!=NULL))
301 GetImage()-> GetSpacing(spc);
312 printf("EED LayerImageBase::onThreshold z = %d spcZ%f\n" , z, spc[2]);
315 vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
316 int directionViewer=0;
317 if (camera->GetParallelProjection()==1)
319 wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
320 directionViewer = wxvtk2dbasevie->GetDirection();
321 } // ParallelProjection
323 printf("EED LayerImageBase::onThreshold projection = %d\n" , camera->GetParallelProjection() );
324 printf("EED LayerImageBase::onThreshold direction = %d\n" , directionViewer );
327 if (!GetActorPresent())
329 if (_thresholdTable==NULL)
332 _thresholdTable = vtkLookupTable::New();
335 if (_thresholdMapper==NULL)
337 _thresholdMapper = vtkImageMapToColors::New( );
340 if (_thresholdActor==NULL)
342 _thresholdActor = vtkImageActor::New( );
343 _thresholdActor->SetOpacity( 0.6 );
344 _thresholdActor->InterpolateOn( );
345 if (directionViewer==0)
347 _thresholdActor->SetPosition( 900-1,0,0 );
348 _thresholdActor->RotateY( -90 );
350 if (directionViewer==1)
352 _thresholdActor->SetPosition( 0,-900-1, 0 );
353 _thresholdActor->RotateX( 90 );
355 if (directionViewer==2)
357 _thresholdActor->SetPosition( 0,0, -900-1 );
360 _baseView->GetRenderer()->AddActor( _thresholdActor );
361 _actorPresent = true;
362 } // !GetActorPresent()
364 ConfigLookupTable(); // virtual method
365 _imageReslicer->SetInput( GetImage() );
366 _imageReslicer->SetInformationInput( GetImage() );
368 if (directionViewer==0)
370 _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
371 _imageReslicer->SetResliceAxesOrigin(x,0,0);
374 if (directionViewer==1)
376 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
377 _imageReslicer->SetResliceAxesOrigin(0,y,0);
380 if (directionViewer==2)
382 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
383 _imageReslicer->SetResliceAxesOrigin(0,0,z);
387 _imageReslicer->SetOutputDimensionality(2);
388 // _imageReslicer->SetInterpolationModeToLinear();
389 _imageReslicer->SetInterpolationModeToNearestNeighbor();
391 vtkImageData *img = _imageReslicer->GetOutput();
393 // img->UpdateInformation();
395 _thresholdMapper->SetInput( img );
396 _thresholdMapper->SetLookupTable( _thresholdTable );
397 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
399 printf("EED LayerImageBase::onThreshold working \n");
403 printf("EED LayerImageBase::onThreshold end \n");
408 //----------------------------------------------------------------------------
409 void LayerImageBase::onThresholdChange()
417 //----------------------------------------------------------------------------
418 void LayerImageBase::onThresholdInterpolation(bool interpolate)
420 if (_thresholdActor!=NULL)
424 _thresholdActor->InterpolateOn( );
428 _thresholdActor->InterpolateOff( );
433 //----------------------------------------------------------------------------
434 void LayerImageBase::onThresholdChangeOpacity (int opacity)
438 _thresholdActor->SetOpacity(opacity*0.1);
442 //----------------------------------------------------------------------------
443 void LayerImageBase::onThresholdRemove()
447 wxVtkBaseView * baseView = _baseView;
448 baseView->GetRenderer()->RemoveActor( _thresholdActor );
449 _actorPresent = false;
453 //----------------------------------------------------------------------------
454 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
456 return _thresholdTable;
459 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
461 return _imageReslicer;