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->SetX( (int)X );
77 _layerImageBase->SetY( (int)Y );
78 _layerImageBase->SetZ( (int)Z );
79 _layerImageBase->onThreshold();
80 // _layerImageBase->Refresh();
83 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
85 if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
87 _layerImageBase->GetvtkImageReslice()->Modified();
89 printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
95 bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
97 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
102 bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual
104 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
110 //---------------------------------------------------------------------------------------------
111 //---------------------------------------------------------------------------------------------
112 //---------------------------------------------------------------------------------------------
116 LayerImageBase::LayerImageBase()
118 _actorPresent = false;
122 _thresholdTable = NULL;
123 _thresholdMapper = NULL;
124 _thresholdActor = NULL;
127 _imageReslicer = vtkImageReslice::New();
131 //----------------------------------------------------------------------------
132 LayerImageBase::~LayerImageBase()
136 //----------------------------------------------------------------------------
137 void LayerImageBase::SetX(int x)
142 //----------------------------------------------------------------------------
143 void LayerImageBase::SetY(int y)
148 //----------------------------------------------------------------------------
149 void LayerImageBase::SetZ(int z)
154 //----------------------------------------------------------------------------
155 int LayerImageBase::GetX() // virtual
160 //----------------------------------------------------------------------------
161 int LayerImageBase::GetY() // virtual
165 //----------------------------------------------------------------------------
166 int LayerImageBase::GetZ() // virtual
172 //----------------------------------------------------------------------------
173 vtkImageData* LayerImageBase::GetImage()
178 //----------------------------------------------------------------------------
179 bool LayerImageBase::GetActorPresent()
181 return _actorPresent;
186 //----------------------------------------------------------------------------
187 void LayerImageBase::SetImage(vtkImageData* image)
192 //----------------------------------------------------------------------------
193 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
195 printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
198 _baseView = baseview;
199 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
200 isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
202 printf("EED LayerImageBase::SetwxVtkBaseView end \n");
205 //----------------------------------------------------------------------------
206 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
211 //----------------------------------------------------------------------------
212 void LayerImageBase::Refresh()
214 printf("EED LayerImageBase::Refresh\n");
217 _baseView->Refresh();
222 //----------------------------------------------------------------------------
223 vtkLookupTable* LayerImageBase::GetThresholdTable()
225 return _thresholdTable;
228 //----------------------------------------------------------------------------
229 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
232 _image->GetWholeExtent(ext);
249 if ( x > (ext[1]-ext[0]) )
254 if ( y > (ext[3]-ext[2]) )
259 if ( z > (ext[5]-ext[4]) )
267 //----------------------------------------------------------------------------
268 void LayerImageBase::onThreshold()
271 printf("EED LayerImageBase::onThreshold start \n");
273 if ((_image!=NULL) && (_baseView!=NULL))
276 GetImage()-> GetSpacing(spc);
287 printf("EED LayerImageBase::onThreshold z = %d spcZ%f\n" , z, spc[2]);
290 vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
291 int directionViewer=0;
292 if (camera->GetParallelProjection()==1)
294 wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
295 directionViewer = wxvtk2dbasevie->GetDirection();
296 } // ParallelProjection
298 printf("EED LayerImageBase::onThreshold projection = %d\n" , camera->GetParallelProjection() );
299 printf("EED LayerImageBase::onThreshold direction = %d\n" , directionViewer );
302 if (!GetActorPresent())
304 if (_thresholdTable==NULL)
307 _thresholdTable = vtkLookupTable::New();
310 if (_thresholdMapper==NULL)
312 _thresholdMapper = vtkImageMapToColors::New( );
315 if (_thresholdActor==NULL)
317 _thresholdActor = vtkImageActor::New( );
318 _thresholdActor->SetOpacity( 0.6 );
319 _thresholdActor->InterpolateOn( );
320 if (directionViewer==0)
322 _thresholdActor->SetPosition( 900-1,0,0 );
323 _thresholdActor->RotateY( -90 );
325 if (directionViewer==1)
327 _thresholdActor->SetPosition( 0,-900-1, 0 );
328 _thresholdActor->RotateX( 90 );
330 if (directionViewer==2)
332 _thresholdActor->SetPosition( 0,0, -900-1 );
335 _baseView->GetRenderer()->AddActor( _thresholdActor );
336 _actorPresent = true;
337 } // !GetActorPresent()
339 ConfigLookupTable(); // virtual method
340 _imageReslicer->SetInput( GetImage() );
341 _imageReslicer->SetInformationInput( GetImage() );
343 if (directionViewer==0)
345 _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
346 _imageReslicer->SetResliceAxesOrigin(x,0,0);
349 if (directionViewer==1)
351 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
352 _imageReslicer->SetResliceAxesOrigin(0,y,0);
355 if (directionViewer==2)
357 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
358 _imageReslicer->SetResliceAxesOrigin(0,0,z);
362 _imageReslicer->SetOutputDimensionality(2);
363 // _imageReslicer->SetInterpolationModeToLinear();
364 _imageReslicer->SetInterpolationModeToNearestNeighbor();
366 vtkImageData *img = _imageReslicer->GetOutput();
368 // img->UpdateInformation();
370 _thresholdMapper->SetInput( img );
371 _thresholdMapper->SetLookupTable( _thresholdTable );
372 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
374 printf("EED LayerImageBase::onThreshold working \n");
378 printf("EED LayerImageBase::onThreshold end \n");
383 //----------------------------------------------------------------------------
384 void LayerImageBase::onThresholdChange()
392 //----------------------------------------------------------------------------
393 void LayerImageBase::onThresholdInterpolation(bool interpolate)
395 if (_thresholdActor!=NULL)
399 _thresholdActor->InterpolateOn( );
403 _thresholdActor->InterpolateOff( );
408 //----------------------------------------------------------------------------
409 void LayerImageBase::onThresholdChangeOpacity (int opacity)
413 _thresholdActor->SetOpacity(opacity*0.1);
417 //----------------------------------------------------------------------------
418 void LayerImageBase::onThresholdRemove()
422 wxVtkBaseView * baseView = _baseView;
423 baseView->GetRenderer()->RemoveActor( _thresholdActor );
424 _actorPresent = false;
428 //----------------------------------------------------------------------------
429 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
431 return _thresholdTable;
434 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
436 return _imageReslicer;