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"
34 //---------------------------------------------------------------------------------------------
35 //---------------------------------------------------------------------------------------------
36 //---------------------------------------------------------------------------------------------
38 ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
40 _layerImageBase=layerImageBase;
43 //---------------------------------------------------------------------------------------------
44 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
49 //---------------------------------------------------------------------------------------------
50 bool ColorLayerImageBasevtkInteractor::OnMouseMove()
52 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
53 if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
55 _layerImageBase->GetvtkImageReslice()->Modified();
62 //---------------------------------------------------------------------------------------------
63 //---------------------------------------------------------------------------------------------
64 //---------------------------------------------------------------------------------------------
68 LayerImageBase::LayerImageBase()
70 _actorPresent = false;
72 _thresholdTable = NULL;
73 _thresholdMapper = NULL;
74 _thresholdActor = NULL;
77 _imageReslicer = vtkImageReslice::New();
81 //----------------------------------------------------------------------------
82 LayerImageBase::~LayerImageBase()
86 //----------------------------------------------------------------------------
87 void LayerImageBase::SetZ(int z)
92 //----------------------------------------------------------------------------
93 int LayerImageBase::GetZ() // virtual
98 //----------------------------------------------------------------------------
99 vtkImageData* LayerImageBase::GetImage()
104 //----------------------------------------------------------------------------
105 bool LayerImageBase::GetActorPresent()
107 return _actorPresent;
112 //----------------------------------------------------------------------------
113 void LayerImageBase::SetImage(vtkImageData* image)
118 //----------------------------------------------------------------------------
119 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
121 printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
123 _baseView = baseview;
125 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
126 isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
128 printf("EED LayerImageBase::SetwxVtkBaseView end \n");
131 //----------------------------------------------------------------------------
132 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
137 //----------------------------------------------------------------------------
138 void LayerImageBase::Refresh()
140 printf("EED LayerImageBase::Refresh\n");
143 _baseView->Refresh();
148 //----------------------------------------------------------------------------
149 vtkLookupTable* LayerImageBase::GetThresholdTable()
151 return _thresholdTable;
154 //----------------------------------------------------------------------------
155 int LayerImageBase::CleanZ(int z)
158 _image->GetWholeExtent(ext);
165 if ( z > (ext[5]-ext[4]) )
173 //----------------------------------------------------------------------------
174 void LayerImageBase::onThreshold()
177 printf("EED LayerImageBase::onThreshold start \n");
179 if ((_image!=NULL) && (_baseView!=NULL))
181 int z=CleanZ( GetZ() );
183 if (!GetActorPresent())
185 if (_thresholdTable==NULL)
188 _thresholdTable = vtkLookupTable::New();
191 if (_thresholdMapper==NULL)
193 _thresholdMapper = vtkImageMapToColors::New( );
196 if (_thresholdActor==NULL)
198 _thresholdActor = vtkImageActor::New( );
199 _thresholdActor->SetOpacity( 0.6 );
200 _thresholdActor->InterpolateOn( );
201 _thresholdActor->SetPosition( 0,0, -900-1 );
203 _baseView->GetRenderer()->AddActor( _thresholdActor );
204 _actorPresent = true;
205 } // !GetActorPresent()
207 ConfigLookupTable(); // virtual method
208 _imageReslicer->SetInput( GetImage() );
209 _imageReslicer->SetInformationInput( GetImage() );
210 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
211 _imageReslicer->SetOutputDimensionality(2);
212 // _imageReslicer->SetInterpolationModeToLinear();
213 _imageReslicer->SetInterpolationModeToNearestNeighbor();
214 _imageReslicer->SetResliceAxesOrigin(0,0,z);
216 vtkImageData *img = _imageReslicer->GetOutput();
218 // img->UpdateInformation();
220 _thresholdMapper->SetInput( img );
221 _thresholdMapper->SetLookupTable( _thresholdTable );
222 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
224 printf("EED LayerImageBase::onThreshold working \n");
228 printf("EED LayerImageBase::onThreshold end");
233 //----------------------------------------------------------------------------
234 void LayerImageBase::onThresholdChange()
242 //----------------------------------------------------------------------------
243 void LayerImageBase::onThresholdInterpolation(bool interpolate)
245 if (_thresholdActor!=NULL)
249 _thresholdActor->InterpolateOn( );
253 _thresholdActor->InterpolateOff( );
258 //----------------------------------------------------------------------------
259 void LayerImageBase::onThresholdChangeOpacity (int opacity)
263 _thresholdActor->SetOpacity(opacity*0.1);
267 //----------------------------------------------------------------------------
268 void LayerImageBase::onThresholdRemove()
272 wxVtkBaseView * baseView = _baseView;
273 baseView->GetRenderer()->RemoveActor( _thresholdActor );
274 _actorPresent = false;
278 //----------------------------------------------------------------------------
279 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
281 return _thresholdTable;
284 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
286 return _imageReslicer;