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)
45 _layerImageBase=layerImageBase;
49 //---------------------------------------------------------------------------------------------
50 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
54 //---------------------------------------------------------------------------------------------
55 bool ColorLayerImageBasevtkInteractor::OnChar()
61 //---------------------------------------------------------------------------------------------
62 bool ColorLayerImageBasevtkInteractor::OnMouseMove() // vitual
64 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove start \n");
66 vtkRenderWindowInteractor *interactor = _vtkInteractorStyleBaseView->GetInteractor();
68 // For example in ManualPaint Action
69 // This is not working, because the order of insertion events mecanism (_vtkInteractorStyleBaseView)
70 // Layer first Paint after.
71 // the only way to make it works is to take the axes an paint. this force a first SetParent_refresh_waiting()
72 // if ( this->_vtkInteractorStyleBaseView->GetParent_refresh_waiting() == true )
74 if ( interactor->GetControlKey()==1 ) // EED This if for ManaulPaint Interaction compatibility
76 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove need Refresh \n" );
77 _layerImageBase->onThreshold();
78 _layerImageBase->GetvtkImageReslice()->Modified();
81 printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove NOT need Refresh \n" );
85 if ( (_state==true) && (_layerImageBase->GetActorPresent()) )
87 wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
88 wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
90 wxVTKiren->GetEventPosition(px, py);
93 double X = (double) px;
94 double Y = (double) py;
95 double Z = wxvtk2Dbaseview->GetActualSlice();
96 // wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z,true, typeView);
97 wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z, true);
99 // _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
101 _layerImageBase->SetX( (int)X );
102 _layerImageBase->SetY( (int)Y );
103 _layerImageBase->SetZ( (int)Z );
104 _layerImageBase->onThreshold();
105 // _layerImageBase->Refresh();
107 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
109 if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
111 _layerImageBase->GetvtkImageReslice()->Modified();
113 printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
118 //---------------------------------------------------------------------------------------------
119 bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
121 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
126 //---------------------------------------------------------------------------------------------
127 bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual
129 printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
135 //---------------------------------------------------------------------------------------------
136 //---------------------------------------------------------------------------------------------
137 //---------------------------------------------------------------------------------------------
141 LayerImageBase::LayerImageBase()
143 _actorPresent = false;
147 _thresholdTable = NULL;
148 _thresholdMapper = NULL;
149 _scalarbarActor = NULL;
150 _thresholdActor = NULL;
153 _imageReslicer = vtkImageReslice::New();
157 //----------------------------------------------------------------------------
158 LayerImageBase::~LayerImageBase()
162 //----------------------------------------------------------------------------
163 void LayerImageBase::SetX(int x)
168 //----------------------------------------------------------------------------
169 void LayerImageBase::SetY(int y)
174 //----------------------------------------------------------------------------
175 void LayerImageBase::SetZ(int z)
180 //----------------------------------------------------------------------------
181 int LayerImageBase::GetX() // virtual
186 //----------------------------------------------------------------------------
187 int LayerImageBase::GetY() // virtual
191 //----------------------------------------------------------------------------
192 int LayerImageBase::GetZ() // virtual
198 //----------------------------------------------------------------------------
199 vtkImageData* LayerImageBase::GetImage()
204 //----------------------------------------------------------------------------
205 bool LayerImageBase::GetActorPresent()
207 return _actorPresent;
212 //----------------------------------------------------------------------------
213 void LayerImageBase::SetImage(vtkImageData* image)
218 //----------------------------------------------------------------------------
219 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
223 _baseView = baseview;
224 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
225 isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
229 //----------------------------------------------------------------------------
230 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
235 //----------------------------------------------------------------------------
236 void LayerImageBase::Refresh()
240 _baseView->Refresh();
245 //----------------------------------------------------------------------------
246 vtkLookupTable* LayerImageBase::GetThresholdTable()
248 return _thresholdTable;
251 //----------------------------------------------------------------------------
252 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
255 _image->GetWholeExtent(ext);
272 if ( x > (ext[1]-ext[0]) )
277 if ( y > (ext[3]-ext[2]) )
282 if ( z > (ext[5]-ext[4]) )
290 //----------------------------------------------------------------------------
291 void LayerImageBase::onThreshold()
293 if ((_image!=NULL) && (_baseView!=NULL))
296 GetImage()-> GetSpacing(spc);
306 vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
307 int directionViewer=0;
308 if (camera->GetParallelProjection()==1)
310 wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
311 directionViewer = wxvtk2dbasevie->GetDirection();
312 } // ParallelProjection
315 if (!GetActorPresent())
317 if (_thresholdTable==NULL)
320 _thresholdTable = vtkLookupTable::New();
323 if (_thresholdMapper==NULL)
325 _thresholdMapper = vtkImageMapToColors::New( );
328 if (_thresholdActor==NULL)
330 _thresholdActor = vtkImageActor::New( );
331 _scalarbarActor = vtkScalarBarActor::New();
332 _thresholdActor->SetOpacity( 0.6 );
333 _thresholdActor->InterpolateOn( );
334 if (directionViewer==0)
336 _thresholdActor->SetPosition( 900-1,0,0 );
337 _thresholdActor->RotateY( -90 );
339 if (directionViewer==1)
341 _thresholdActor->SetPosition( 0,-900-1, 0 );
342 _thresholdActor->RotateX( 90 );
344 if (directionViewer==2)
346 _thresholdActor->SetPosition( 0,0, -900-1 );
349 _baseView->GetRenderer()->AddActor( _thresholdActor );
350 _baseView->GetRenderer()->AddActor2D( _scalarbarActor );
351 _actorPresent = true;
352 } // !GetActorPresent()
354 ConfigLookupTable(); // virtual method
355 _imageReslicer->SetInput( GetImage() );
356 _imageReslicer->SetInformationInput( GetImage() );
358 if (directionViewer==0)
360 _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
361 _imageReslicer->SetResliceAxesOrigin(x,0,0);
364 if (directionViewer==1)
366 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
367 _imageReslicer->SetResliceAxesOrigin(0,y,0);
370 if (directionViewer==2)
372 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
373 _imageReslicer->SetResliceAxesOrigin(0,0,z);
377 _imageReslicer->SetOutputDimensionality(2);
378 // _imageReslicer->SetInterpolationModeToLinear();
379 _imageReslicer->SetInterpolationModeToNearestNeighbor();
381 vtkImageData *img = _imageReslicer->GetOutput();
383 // img->UpdateInformation();
385 // _thresholdTable->Update();
386 _thresholdMapper->SetInput( img );
387 _thresholdMapper->SetLookupTable( _thresholdTable );
388 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
390 // _scalarbarActor->SetLookupTable( _thresholdTable );
391 _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
393 _scalarbarActor->SetTitle("Value");
394 _scalarbarActor->SetNumberOfLabels(5);
395 // _scalarbarActor->SetTextPad(4); ??
402 //----------------------------------------------------------------------------
403 void LayerImageBase::onThresholdChange()
411 //----------------------------------------------------------------------------
412 void LayerImageBase::onThresholdInterpolation(bool interpolate)
414 if (_thresholdActor!=NULL)
418 _thresholdActor->InterpolateOn( );
422 _thresholdActor->InterpolateOff( );
427 //----------------------------------------------------------------------------
428 void LayerImageBase::onThresholdChangeOpacity (int opacity)
432 _thresholdActor->SetOpacity(opacity*0.1);
436 //----------------------------------------------------------------------------
437 void LayerImageBase::onThresholdRemove()
441 wxVtkBaseView * baseView = _baseView;
442 baseView->GetRenderer()->RemoveActor( _thresholdActor );
443 baseView->GetRenderer()->RemoveActor( _scalarbarActor );
445 _actorPresent = false;
449 //----------------------------------------------------------------------------
450 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
452 return _thresholdTable;
455 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
457 return _imageReslicer;