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 "wxMPRBaseData.h"
34 #include "wxVtk2DBaseView.h"
35 #include "wxVTKRenderWindowInteractor.h"
40 //---------------------------------------------------------------------------------------------
41 //---------------------------------------------------------------------------------------------
42 //---------------------------------------------------------------------------------------------
44 // Callback for the interaction
45 class ColorLayerObserver : public vtkCommand{
47 virtual char const *GetClassName() const { return "ColorLayerObserver";}
49 static ColorLayerObserver *New() { return new ColorLayerObserver; }
53 _layerimagebase = NULL;
56 virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata)
58 if (_layerimagebase!= NULL)
61 wxVtkBaseView *wxvtkbaseview = _layerimagebase->GetwxVtkBaseView();
62 if (wxvtkbaseview!=NULL)
65 vtkMPRBaseData *vtkmprbasedata = (vtkMPRBaseData*)wxvtkbaseview->GetVtkBaseData();
66 if (vtkmprbasedata!=NULL)
68 _layerimagebase->SetX( vtkmprbasedata->GetX() );
69 _layerimagebase->SetY( vtkmprbasedata->GetY() );
70 _layerimagebase->SetZ( vtkmprbasedata->GetZ() );
71 _layerimagebase->onThresholdChange();
78 void SetLayerImageBase(LayerImageBase* layerimagebase)
80 _layerimagebase = layerimagebase;
84 LayerImageBase* _layerimagebase;
88 //---------------------------------------------------------------------------------------------
89 //---------------------------------------------------------------------------------------------
90 //---------------------------------------------------------------------------------------------
92 ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
96 _layerImageBase = layerImageBase;
100 //---------------------------------------------------------------------------------------------
101 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
105 //---------------------------------------------------------------------------------------------
106 bool ColorLayerImageBasevtkInteractor::OnChar()
112 //---------------------------------------------------------------------------------------------
113 bool ColorLayerImageBasevtkInteractor::OnMouseMove() // vitual
115 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove start \n");
117 vtkRenderWindowInteractor *interactor = _vtkInteractorStyleBaseView->GetInteractor();
119 // For example in ManualPaint Action
120 // This is not working, because the order of insertion events mecanism (_vtkInteractorStyleBaseView)
121 // Layer first Paint after.
122 // the only way to make it works is to take the axes an paint. this force a first SetParent_refresh_waiting()
123 // if ( this->_vtkInteractorStyleBaseView->GetParent_refresh_waiting() == true )
125 if ( interactor->GetControlKey()==1 ) // EED This if for ManaulPaint Interaction compatibility
127 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove need Refresh \n" );
128 _layerImageBase->onThreshold();
129 _layerImageBase->GetvtkImageReslice()->Modified();
131 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove NOT need Refresh \n" );
135 if ( (_state==true) && (_layerImageBase->GetActorPresent()) )
137 wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
138 wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
140 wxVTKiren->GetEventPosition(px, py);
143 double X = (double) px;
144 double Y = (double) py;
145 double Z = wxvtk2Dbaseview->GetActualSlice();
146 // wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z,true, typeView);
147 wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z, true);
149 // _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
151 _layerImageBase->SetX( (int)X );
152 _layerImageBase->SetY( (int)Y );
153 _layerImageBase->SetZ( (int)Z );
154 _layerImageBase->onThreshold();
155 // _layerImageBase->Refresh();
157 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
159 if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
161 _layerImageBase->GetvtkImageReslice()->Modified();
163 printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
168 //---------------------------------------------------------------------------------------------
169 bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
171 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
177 //---------------------------------------------------------------------------------------------
178 bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual
180 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
186 //---------------------------------------------------------------------------------------------
187 //---------------------------------------------------------------------------------------------
188 //---------------------------------------------------------------------------------------------
192 LayerImageBase::LayerImageBase()
194 _actorPresent = false;
198 _thresholdTable = NULL;
199 _thresholdMapper = NULL;
200 _scalarbarActor = NULL;
201 _thresholdActor = NULL;
204 _imageReslicer = vtkImageReslice::New();
207 //----------------------------------------------------------------------------
208 LayerImageBase::~LayerImageBase()
212 //----------------------------------------------------------------------------
213 void LayerImageBase::SetX(int x)
218 //----------------------------------------------------------------------------
219 void LayerImageBase::SetY(int y)
224 //----------------------------------------------------------------------------
225 void LayerImageBase::SetZ(int z)
230 //----------------------------------------------------------------------------
231 int LayerImageBase::GetX() // virtual
236 //----------------------------------------------------------------------------
237 int LayerImageBase::GetY() // virtual
241 //----------------------------------------------------------------------------
242 int LayerImageBase::GetZ() // virtual
248 //----------------------------------------------------------------------------
249 vtkImageData* LayerImageBase::GetImage()
254 //----------------------------------------------------------------------------
255 bool LayerImageBase::GetActorPresent()
257 return _actorPresent;
262 //----------------------------------------------------------------------------
263 void LayerImageBase::SetImage(vtkImageData* image)
268 //----------------------------------------------------------------------------
269 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
273 _baseView = baseview;
274 // Old EED 2014 11 13
275 // vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
276 // isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
278 ColorLayerObserver *colorlayerobserver = ColorLayerObserver::New();
279 _baseView->GetVtkBaseData()->AddObserver( 1, colorlayerobserver );
280 colorlayerobserver->SetLayerImageBase(this);
285 //----------------------------------------------------------------------------
286 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
291 //----------------------------------------------------------------------------
292 void LayerImageBase::Refresh()
296 _baseView->Refresh();
301 //----------------------------------------------------------------------------
302 vtkLookupTable* LayerImageBase::GetThresholdTable()
304 return _thresholdTable;
307 //----------------------------------------------------------------------------
308 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
311 _image->GetWholeExtent(ext);
328 if ( x > (ext[1]-ext[0]) )
333 if ( y > (ext[3]-ext[2]) )
338 if ( z > (ext[5]-ext[4]) )
346 //----------------------------------------------------------------------------
347 void LayerImageBase::onThreshold()
349 if ((_image!=NULL) && (_baseView!=NULL))
352 GetImage()-> GetSpacing(spc);
362 vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
363 int directionViewer=0;
364 if (camera->GetParallelProjection()==1)
366 wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
367 directionViewer = wxvtk2dbasevie->GetDirection();
368 } // ParallelProjection
371 if (!GetActorPresent())
373 if (_thresholdTable==NULL)
376 _thresholdTable = vtkLookupTable::New();
379 if (_thresholdMapper==NULL)
381 _thresholdMapper = vtkImageMapToColors::New( );
384 if (_thresholdActor==NULL)
386 _thresholdActor = vtkImageActor::New( );
387 _scalarbarActor = vtkScalarBarActor::New();
388 _thresholdActor->SetOpacity( 0.6 );
389 _thresholdActor->InterpolateOn( );
390 if (directionViewer==0)
392 _thresholdActor->SetPosition( 900-1,0,0 );
393 _thresholdActor->RotateY( -90 );
395 if (directionViewer==1)
397 _thresholdActor->SetPosition( 0,-900-1, 0 );
398 _thresholdActor->RotateX( 90 );
400 if (directionViewer==2)
402 _thresholdActor->SetPosition( 0,0, -900-1 );
405 _baseView->GetRenderer()->AddActor( _thresholdActor );
406 _baseView->GetRenderer()->AddActor2D( _scalarbarActor );
407 _actorPresent = true;
408 } // !GetActorPresent()
410 ConfigLookupTable(); // virtual method
411 _imageReslicer->SetInput( GetImage() );
412 _imageReslicer->SetInformationInput( GetImage() );
414 if (directionViewer==0)
416 _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
417 _imageReslicer->SetResliceAxesOrigin(x,0,0);
420 if (directionViewer==1)
422 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
423 _imageReslicer->SetResliceAxesOrigin(0,y,0);
426 if (directionViewer==2)
428 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
429 _imageReslicer->SetResliceAxesOrigin(0,0,z);
433 _imageReslicer->SetOutputDimensionality(2);
434 // _imageReslicer->SetInterpolationModeToLinear();
435 _imageReslicer->SetInterpolationModeToNearestNeighbor();
437 vtkImageData *img = _imageReslicer->GetOutput();
439 // img->UpdateInformation();
441 // _thresholdTable->Update();
442 _thresholdMapper->SetInput( img );
443 _thresholdMapper->SetLookupTable( _thresholdTable );
444 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
446 // _scalarbarActor->SetLookupTable( _thresholdTable );
447 _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
449 _scalarbarActor->SetTitle("Value");
450 _scalarbarActor->SetNumberOfLabels(5);
451 // _scalarbarActor->SetTextPad(4); ??
458 //----------------------------------------------------------------------------
459 void LayerImageBase::onThresholdChange()
467 //----------------------------------------------------------------------------
468 void LayerImageBase::onThresholdInterpolation(bool interpolate)
470 if (_thresholdActor!=NULL)
474 _thresholdActor->InterpolateOn( );
478 _thresholdActor->InterpolateOff( );
483 //----------------------------------------------------------------------------
484 void LayerImageBase::onThresholdChangeOpacity (int opacity)
488 _thresholdActor->SetOpacity(opacity*0.1);
492 //----------------------------------------------------------------------------
493 void LayerImageBase::onThresholdRemove()
497 wxVtkBaseView * baseView = _baseView;
498 baseView->GetRenderer()->RemoveActor( _thresholdActor );
499 baseView->GetRenderer()->RemoveActor( _scalarbarActor );
501 _actorPresent = false;
505 //----------------------------------------------------------------------------
506 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
508 return _thresholdTable;
511 //----------------------------------------------------------------------------
512 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
514 return _imageReslicer;