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"
36 #include "vtkTextProperty.h"
39 //---------------------------------------------------------------------------------------------
40 //---------------------------------------------------------------------------------------------
41 //---------------------------------------------------------------------------------------------
43 // Callback for the interaction
44 class ColorLayerObserver : public vtkCommand{
46 virtual char const *GetClassName() const { return "ColorLayerObserver";}
48 static ColorLayerObserver *New() { return new ColorLayerObserver; }
52 _layerimagebase = NULL;
55 virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata)
57 if (_layerimagebase!= NULL)
60 wxVtkBaseView *wxvtkbaseview = _layerimagebase->GetwxVtkBaseView();
61 if (wxvtkbaseview!=NULL)
64 vtkMPRBaseData *vtkmprbasedata = (vtkMPRBaseData*)wxvtkbaseview->GetVtkBaseData();
65 if (vtkmprbasedata!=NULL)
67 _layerimagebase->SetX( vtkmprbasedata->GetX() );
68 _layerimagebase->SetY( vtkmprbasedata->GetY() );
69 _layerimagebase->SetZ( vtkmprbasedata->GetZ() );
70 _layerimagebase->onThresholdChange();
77 void SetLayerImageBase(LayerImageBase* layerimagebase)
79 _layerimagebase = layerimagebase;
83 LayerImageBase* _layerimagebase;
88 //---------------------------------------------------------------------------------------------
89 //---------------------------------------------------------------------------------------------
90 //---------------------------------------------------------------------------------------------
94 LayerImageBase::LayerImageBase()
96 _actorPresent = false;
100 _thresholdTable = NULL;
101 _thresholdMapper = NULL;
102 _scalarbarActor = NULL;
103 _thresholdActor = NULL;
106 _imageReslicer = vtkImageReslice::New();
109 //----------------------------------------------------------------------------
110 LayerImageBase::~LayerImageBase()
114 //----------------------------------------------------------------------------
115 void LayerImageBase::SetX(int x)
120 //----------------------------------------------------------------------------
121 void LayerImageBase::SetY(int y)
126 //----------------------------------------------------------------------------
127 void LayerImageBase::SetZ(int z)
132 //----------------------------------------------------------------------------
133 int LayerImageBase::GetX() // virtual
138 //----------------------------------------------------------------------------
139 int LayerImageBase::GetY() // virtual
143 //----------------------------------------------------------------------------
144 int LayerImageBase::GetZ() // virtual
150 //----------------------------------------------------------------------------
151 vtkImageData* LayerImageBase::GetImage()
156 //----------------------------------------------------------------------------
157 bool LayerImageBase::GetActorPresent()
159 return _actorPresent;
164 //----------------------------------------------------------------------------
165 void LayerImageBase::SetImage(vtkImageData* image)
170 //----------------------------------------------------------------------------
171 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
175 _baseView = baseview;
176 // Old EED 2014 11 13
177 // vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
178 // isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
180 ColorLayerObserver *colorlayerobserver = ColorLayerObserver::New();
181 _baseView->GetVtkBaseData()->AddObserver( 1, colorlayerobserver );
182 colorlayerobserver->SetLayerImageBase(this);
187 //----------------------------------------------------------------------------
188 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
193 //----------------------------------------------------------------------------
194 void LayerImageBase::Refresh()
198 _baseView->Refresh();
203 //----------------------------------------------------------------------------
204 vtkLookupTable* LayerImageBase::GetThresholdTable()
206 return _thresholdTable;
209 //----------------------------------------------------------------------------
210 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
213 _image->GetWholeExtent(ext);
230 if ( x > (ext[1]-ext[0]) )
235 if ( y > (ext[3]-ext[2]) )
240 if ( z > (ext[5]-ext[4]) )
248 //----------------------------------------------------------------------------
249 void LayerImageBase::onThreshold()
251 if ((_image!=NULL) && (_baseView!=NULL))
254 GetImage()-> GetSpacing(spc);
264 vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
265 int directionViewer=0;
266 if (camera->GetParallelProjection()==1)
268 wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
269 directionViewer = wxvtk2dbasevie->GetDirection();
270 } // ParallelProjection
273 if (!GetActorPresent())
275 if (_thresholdTable==NULL)
278 _thresholdTable = vtkLookupTable::New();
281 if (_thresholdMapper==NULL)
283 _thresholdMapper = vtkImageMapToColors::New( );
286 if (_thresholdActor==NULL)
288 _thresholdActor = vtkImageActor::New( );
289 _scalarbarActor = vtkScalarBarActor::New();
290 _thresholdActor->SetOpacity( 0.6 );
291 _thresholdActor->InterpolateOn( );
292 if (directionViewer==0)
294 _thresholdActor->SetPosition( 900-1,0,0 );
295 _thresholdActor->RotateY( -90 );
297 if (directionViewer==1)
299 _thresholdActor->SetPosition( 0,-900-1, 0 );
300 _thresholdActor->RotateX( 90 );
302 if (directionViewer==2)
304 _thresholdActor->SetPosition( 0,0, -900-1 );
307 _baseView->GetRenderer()->AddActor( _thresholdActor );
308 _baseView->GetRenderer()->AddActor2D( _scalarbarActor );
309 _actorPresent = true;
310 } // !GetActorPresent()
312 ConfigLookupTable(); // virtual method
313 _imageReslicer->SetInput( GetImage() );
314 _imageReslicer->SetInformationInput( GetImage() );
316 if (directionViewer==0)
318 _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
319 _imageReslicer->SetResliceAxesOrigin(x,0,0);
322 if (directionViewer==1)
324 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
325 _imageReslicer->SetResliceAxesOrigin(0,y,0);
328 if (directionViewer==2)
330 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
331 _imageReslicer->SetResliceAxesOrigin(0,0,z);
335 _imageReslicer->SetOutputDimensionality(2);
336 // _imageReslicer->SetInterpolationModeToLinear();
337 _imageReslicer->SetInterpolationModeToNearestNeighbor();
339 vtkImageData *img = _imageReslicer->GetOutput();
341 // img->UpdateInformation();
343 // _thresholdTable->Update();
344 _thresholdMapper->SetInput( img );
345 _thresholdMapper->SetLookupTable( _thresholdTable );
346 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
348 // _scalarbarActor->SetLookupTable( _thresholdTable );
349 _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
350 _scalarbarActor->SetTitle("Value");
351 _scalarbarActor->SetNumberOfLabels(4);
352 int fontsize = _scalarbarActor->GetLabelTextProperty()->GetFontSize();
353 _scalarbarActor->GetLabelTextProperty()->SetFontSize(fontsize/2);
355 // _scalarbarActor->SetTextPad(4); ??
362 //----------------------------------------------------------------------------
363 void LayerImageBase::onThresholdChange()
371 //----------------------------------------------------------------------------
372 void LayerImageBase::onThresholdInterpolation(bool interpolate)
374 if (_thresholdActor!=NULL)
378 _thresholdActor->InterpolateOn( );
382 _thresholdActor->InterpolateOff( );
387 //----------------------------------------------------------------------------
388 void LayerImageBase::onThresholdChangeOpacity (int opacity)
392 _thresholdActor->SetOpacity(opacity*0.1);
396 //----------------------------------------------------------------------------
397 void LayerImageBase::onThresholdRemove()
401 wxVtkBaseView * baseView = _baseView;
402 baseView->GetRenderer()->RemoveActor( _thresholdActor );
403 baseView->GetRenderer()->RemoveActor( _scalarbarActor );
405 _actorPresent = false;
409 //----------------------------------------------------------------------------
410 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
412 return _thresholdTable;
415 //----------------------------------------------------------------------------
416 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
418 return _imageReslicer;