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 _thresholdActor = NULL;
152 _imageReslicer = vtkImageReslice::New();
156 //----------------------------------------------------------------------------
157 LayerImageBase::~LayerImageBase()
161 //----------------------------------------------------------------------------
162 void LayerImageBase::SetX(int x)
167 //----------------------------------------------------------------------------
168 void LayerImageBase::SetY(int y)
173 //----------------------------------------------------------------------------
174 void LayerImageBase::SetZ(int z)
179 //----------------------------------------------------------------------------
180 int LayerImageBase::GetX() // virtual
185 //----------------------------------------------------------------------------
186 int LayerImageBase::GetY() // virtual
190 //----------------------------------------------------------------------------
191 int LayerImageBase::GetZ() // virtual
197 //----------------------------------------------------------------------------
198 vtkImageData* LayerImageBase::GetImage()
203 //----------------------------------------------------------------------------
204 bool LayerImageBase::GetActorPresent()
206 return _actorPresent;
211 //----------------------------------------------------------------------------
212 void LayerImageBase::SetImage(vtkImageData* image)
217 //----------------------------------------------------------------------------
218 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
222 _baseView = baseview;
223 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
224 isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
228 //----------------------------------------------------------------------------
229 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
234 //----------------------------------------------------------------------------
235 void LayerImageBase::Refresh()
239 _baseView->Refresh();
244 //----------------------------------------------------------------------------
245 vtkLookupTable* LayerImageBase::GetThresholdTable()
247 return _thresholdTable;
250 //----------------------------------------------------------------------------
251 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
254 _image->GetWholeExtent(ext);
271 if ( x > (ext[1]-ext[0]) )
276 if ( y > (ext[3]-ext[2]) )
281 if ( z > (ext[5]-ext[4]) )
289 //----------------------------------------------------------------------------
290 void LayerImageBase::onThreshold()
292 if ((_image!=NULL) && (_baseView!=NULL))
295 GetImage()-> GetSpacing(spc);
305 vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
306 int directionViewer=0;
307 if (camera->GetParallelProjection()==1)
309 wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
310 directionViewer = wxvtk2dbasevie->GetDirection();
311 } // ParallelProjection
314 if (!GetActorPresent())
316 if (_thresholdTable==NULL)
319 _thresholdTable = vtkLookupTable::New();
322 if (_thresholdMapper==NULL)
324 _thresholdMapper = vtkImageMapToColors::New( );
327 if (_thresholdActor==NULL)
329 _thresholdActor = vtkImageActor::New( );
330 _thresholdActor->SetOpacity( 0.6 );
331 _thresholdActor->InterpolateOn( );
332 if (directionViewer==0)
334 _thresholdActor->SetPosition( 900-1,0,0 );
335 _thresholdActor->RotateY( -90 );
337 if (directionViewer==1)
339 _thresholdActor->SetPosition( 0,-900-1, 0 );
340 _thresholdActor->RotateX( 90 );
342 if (directionViewer==2)
344 _thresholdActor->SetPosition( 0,0, -900-1 );
347 _baseView->GetRenderer()->AddActor( _thresholdActor );
348 _actorPresent = true;
349 } // !GetActorPresent()
351 ConfigLookupTable(); // virtual method
352 _imageReslicer->SetInput( GetImage() );
353 _imageReslicer->SetInformationInput( GetImage() );
355 if (directionViewer==0)
357 _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
358 _imageReslicer->SetResliceAxesOrigin(x,0,0);
361 if (directionViewer==1)
363 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
364 _imageReslicer->SetResliceAxesOrigin(0,y,0);
367 if (directionViewer==2)
369 _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
370 _imageReslicer->SetResliceAxesOrigin(0,0,z);
374 _imageReslicer->SetOutputDimensionality(2);
375 // _imageReslicer->SetInterpolationModeToLinear();
376 _imageReslicer->SetInterpolationModeToNearestNeighbor();
378 vtkImageData *img = _imageReslicer->GetOutput();
380 // img->UpdateInformation();
382 _thresholdMapper->SetInput( img );
383 _thresholdMapper->SetLookupTable( _thresholdTable );
384 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
391 //----------------------------------------------------------------------------
392 void LayerImageBase::onThresholdChange()
400 //----------------------------------------------------------------------------
401 void LayerImageBase::onThresholdInterpolation(bool interpolate)
403 if (_thresholdActor!=NULL)
407 _thresholdActor->InterpolateOn( );
411 _thresholdActor->InterpolateOff( );
416 //----------------------------------------------------------------------------
417 void LayerImageBase::onThresholdChangeOpacity (int opacity)
421 _thresholdActor->SetOpacity(opacity*0.1);
425 //----------------------------------------------------------------------------
426 void LayerImageBase::onThresholdRemove()
430 wxVtkBaseView * baseView = _baseView;
431 baseView->GetRenderer()->RemoveActor( _thresholdActor );
432 _actorPresent = false;
436 //----------------------------------------------------------------------------
437 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
439 return _thresholdTable;
442 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
444 return _imageReslicer;