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)
44 _layerImageBase=layerImageBase;
48 //---------------------------------------------------------------------------------------------
49 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
54 //---------------------------------------------------------------------------------------------
55 bool ColorLayerImageBasevtkInteractor::OnMouseMove() // vitual
57 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
62 wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
63 wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
65 wxVTKiren->GetEventPosition(px, py);
68 double X = (double) px;
69 double Y = (double) py;
70 double Z = wxvtk2Dbaseview->GetActualSlice();
71 // wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z,true, typeView);
72 wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z, true);
74 // _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
76 _layerImageBase->SetZ( (int)Z );
77 _layerImageBase->onThreshold();
78 // _layerImageBase->Refresh();
81 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
83 if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
85 _layerImageBase->GetvtkImageReslice()->Modified();
87 printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
93 bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
95 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
100 bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual
102 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
108 //---------------------------------------------------------------------------------------------
109 //---------------------------------------------------------------------------------------------
110 //---------------------------------------------------------------------------------------------
114 LayerImageBase::LayerImageBase()
116 _actorPresent = false;
118 _thresholdTable = NULL;
119 _thresholdMapper = NULL;
120 _thresholdActor = NULL;
123 _imageReslicer = vtkImageReslice::New();
127 //----------------------------------------------------------------------------
128 LayerImageBase::~LayerImageBase()
132 //----------------------------------------------------------------------------
133 void LayerImageBase::SetZ(int z)
138 //----------------------------------------------------------------------------
139 int LayerImageBase::GetZ() // virtual
144 //----------------------------------------------------------------------------
145 vtkImageData* LayerImageBase::GetImage()
150 //----------------------------------------------------------------------------
151 bool LayerImageBase::GetActorPresent()
153 return _actorPresent;
158 //----------------------------------------------------------------------------
159 void LayerImageBase::SetImage(vtkImageData* image)
164 //----------------------------------------------------------------------------
165 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
167 printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
169 _baseView = baseview;
171 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
172 isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
174 printf("EED LayerImageBase::SetwxVtkBaseView end \n");
177 //----------------------------------------------------------------------------
178 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
183 //----------------------------------------------------------------------------
184 void LayerImageBase::Refresh()
186 printf("EED LayerImageBase::Refresh\n");
189 _baseView->Refresh();
194 //----------------------------------------------------------------------------
195 vtkLookupTable* LayerImageBase::GetThresholdTable()
197 return _thresholdTable;
200 //----------------------------------------------------------------------------
201 int LayerImageBase::CleanZ(int z)
204 _image->GetWholeExtent(ext);
211 if ( z > (ext[5]-ext[4]) )
219 //----------------------------------------------------------------------------
220 void LayerImageBase::onThreshold()
223 printf("EED LayerImageBase::onThreshold start \n");
225 if ((_image!=NULL) && (_baseView!=NULL))
228 GetImage()-> GetSpacing(spc);
229 double z = CleanZ( GetZ() );
232 printf("EED LayerImageBase::onThreshold z = %d spcZ%f\n" , z, spc[2]);
236 if (!GetActorPresent())
238 if (_thresholdTable==NULL)
241 _thresholdTable = vtkLookupTable::New();
244 if (_thresholdMapper==NULL)
246 _thresholdMapper = vtkImageMapToColors::New( );
249 if (_thresholdActor==NULL)
251 _thresholdActor = vtkImageActor::New( );
252 _thresholdActor->SetOpacity( 0.6 );
253 _thresholdActor->InterpolateOn( );
254 _thresholdActor->SetPosition( 0,0, -900-1 );
256 _baseView->GetRenderer()->AddActor( _thresholdActor );
257 _actorPresent = true;
258 } // !GetActorPresent()
260 ConfigLookupTable(); // virtual method
261 _imageReslicer->SetInput( GetImage() );
262 _imageReslicer->SetInformationInput( GetImage() );
263 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
264 _imageReslicer->SetOutputDimensionality(2);
265 // _imageReslicer->SetInterpolationModeToLinear();
266 _imageReslicer->SetInterpolationModeToNearestNeighbor();
267 _imageReslicer->SetResliceAxesOrigin(0,0,z);
269 vtkImageData *img = _imageReslicer->GetOutput();
271 // img->UpdateInformation();
273 _thresholdMapper->SetInput( img );
274 _thresholdMapper->SetLookupTable( _thresholdTable );
275 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
277 printf("EED LayerImageBase::onThreshold working \n");
281 printf("EED LayerImageBase::onThreshold end \n");
286 //----------------------------------------------------------------------------
287 void LayerImageBase::onThresholdChange()
295 //----------------------------------------------------------------------------
296 void LayerImageBase::onThresholdInterpolation(bool interpolate)
298 if (_thresholdActor!=NULL)
302 _thresholdActor->InterpolateOn( );
306 _thresholdActor->InterpolateOff( );
311 //----------------------------------------------------------------------------
312 void LayerImageBase::onThresholdChangeOpacity (int opacity)
316 _thresholdActor->SetOpacity(opacity*0.1);
320 //----------------------------------------------------------------------------
321 void LayerImageBase::onThresholdRemove()
325 wxVtkBaseView * baseView = _baseView;
326 baseView->GetRenderer()->RemoveActor( _thresholdActor );
327 _actorPresent = false;
331 //----------------------------------------------------------------------------
332 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
334 return _thresholdTable;
337 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
339 return _imageReslicer;