]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
2315 creaMaracasVisu Feature New Normal Color Layer synchronisation
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 /**
27  *  \file
28  *  \brief Class bbtk::ThresholdImageView .
29  */
30
31 #include "LayerImageBase.h"
32
33 #include "wxVtk2DBaseView.h"
34 #include "wxVTKRenderWindowInteractor.h"
35
36
37 //---------------------------------------------------------------------------------------------
38 //---------------------------------------------------------------------------------------------
39 //---------------------------------------------------------------------------------------------
40
41 ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
42 {
43     _state=false;
44     _layerImageBase=layerImageBase;
45
46 }
47
48 //---------------------------------------------------------------------------------------------
49 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
50 {
51 }
52
53
54 //---------------------------------------------------------------------------------------------
55 bool ColorLayerImageBasevtkInteractor::OnMouseMove()   // vitual
56 {
57         printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
58         
59         if (_state==true)
60         {
61
62                 wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
63                 wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
64                 int px, py;
65                 wxVTKiren->GetEventPosition(px, py);
66
67 //        int     typeView = 1;
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);
73
74 //              _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
75
76                 _layerImageBase->SetZ( (int)Z );
77                 _layerImageBase->onThreshold();
78 //              _layerImageBase->Refresh();
79
80
81                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
82
83                 if  (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
84                 {
85                         _layerImageBase->GetvtkImageReslice()->Modified();
86                 }
87         printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
88         }
89         return true;
90 }
91
92
93 bool  ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
94 {
95         printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
96         _state=true;
97         return true;
98 }
99
100 bool  ColorLayerImageBasevtkInteractor::OnRightButtonUp()  // virtual
101 {
102         printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
103         _state=false;
104         return true;
105 }
106
107
108 //---------------------------------------------------------------------------------------------
109 //---------------------------------------------------------------------------------------------
110 //---------------------------------------------------------------------------------------------
111
112
113
114 LayerImageBase::LayerImageBase()
115 {
116         _actorPresent                   =       false;
117         _Z                              =       0;
118         _thresholdTable                 =       NULL;
119         _thresholdMapper                =       NULL;
120         _thresholdActor                 =       NULL;
121         _image                          =       NULL;
122         _baseView                       =       NULL;
123         _imageReslicer                  =       vtkImageReslice::New();
124
125 }
126
127 //----------------------------------------------------------------------------
128   LayerImageBase::~LayerImageBase()
129   {
130   }
131
132 //----------------------------------------------------------------------------
133 void LayerImageBase::SetZ(int z)
134 {
135         _Z = z;
136 }
137
138 //----------------------------------------------------------------------------
139 int LayerImageBase::GetZ()  // virtual
140 {
141         return _Z;
142 }
143
144 //----------------------------------------------------------------------------
145 vtkImageData* LayerImageBase::GetImage()
146 {
147         return _image;
148 }
149
150 //----------------------------------------------------------------------------
151 bool LayerImageBase::GetActorPresent()
152 {
153         return _actorPresent;
154 }
155
156
157
158 //----------------------------------------------------------------------------
159 void LayerImageBase::SetImage(vtkImageData* image)
160 {
161         _image = image;
162 }
163
164 //----------------------------------------------------------------------------
165 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
166 {
167         printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
168
169         _baseView = baseview;
170
171     vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
172     isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
173         
174         printf("EED LayerImageBase::SetwxVtkBaseView end \n");
175 }
176
177 //----------------------------------------------------------------------------
178 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
179 {
180         return _baseView;
181 }
182
183 //----------------------------------------------------------------------------
184 void LayerImageBase::Refresh()
185 {
186     printf("EED LayerImageBase::Refresh\n");
187     if (_baseView!=NULL)
188     {
189         _baseView->Refresh();
190     }
191 }
192
193
194 //----------------------------------------------------------------------------
195 vtkLookupTable* LayerImageBase::GetThresholdTable()
196 {
197         return _thresholdTable;
198 }
199
200 //----------------------------------------------------------------------------
201 int LayerImageBase::CleanZ(int z)
202 {
203         int ext[6];
204         _image->GetWholeExtent(ext);
205
206         if (z<0)
207         {
208                 z=0;
209         }
210
211         if ( z > (ext[5]-ext[4]) )
212         {
213                 z=ext[5]-ext[4];
214         }
215
216         return z;
217 }
218
219 //----------------------------------------------------------------------------
220 void LayerImageBase::onThreshold()
221 {
222
223         printf("EED LayerImageBase::onThreshold start \n");
224         
225         if ((_image!=NULL) && (_baseView!=NULL))
226         {
227                 double spc[3];
228                 GetImage()-> GetSpacing(spc);
229                 double  z = CleanZ( GetZ() );
230                         z = z*spc[2];
231
232         printf("EED LayerImageBase::onThreshold z = %d   spcZ%f\n" , z, spc[2]);
233                 
234
235
236                 if (!GetActorPresent())
237                 {
238                         if (_thresholdTable==NULL)
239                         {
240                                 //Lookup Table
241                                 _thresholdTable = vtkLookupTable::New();
242                         } // _thresholdTable
243
244                         if (_thresholdMapper==NULL)
245                         {
246                                 _thresholdMapper = vtkImageMapToColors::New( );
247                         }
248
249                         if (_thresholdActor==NULL)
250                         {
251                                 _thresholdActor = vtkImageActor::New( );
252                                 _thresholdActor->SetOpacity( 0.6 );
253                                 _thresholdActor->InterpolateOn(  );
254                                 _thresholdActor->SetPosition( 0,0, -900-1 );
255                         } // _thresholdActor
256                         _baseView->GetRenderer()->AddActor( _thresholdActor );
257                         _actorPresent = true;
258                 }  // !GetActorPresent()
259
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);
268
269                 vtkImageData *img = _imageReslicer->GetOutput();
270 //              img->Update();
271 //              img->UpdateInformation();
272
273                 _thresholdMapper->SetInput( img );
274                 _thresholdMapper->SetLookupTable( _thresholdTable );
275                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
276
277                 printf("EED LayerImageBase::onThreshold working \n");
278                 
279                 
280                 } // _image
281         printf("EED LayerImageBase::onThreshold end \n");
282 }
283
284
285
286 //----------------------------------------------------------------------------
287 void LayerImageBase::onThresholdChange()
288 {
289         if (_actorPresent)
290         {
291                 onThreshold();
292         }
293 }
294
295 //----------------------------------------------------------------------------
296 void LayerImageBase::onThresholdInterpolation(bool interpolate)
297 {
298         if (_thresholdActor!=NULL)
299         {
300                 if (interpolate)
301                 {
302                         _thresholdActor->InterpolateOn( );
303                 }
304                 else
305                 {
306                         _thresholdActor->InterpolateOff( );
307                 }
308         }
309 }
310
311 //----------------------------------------------------------------------------
312 void LayerImageBase::onThresholdChangeOpacity (int opacity)
313 {
314         if (_actorPresent)
315         {
316                 _thresholdActor->SetOpacity(opacity*0.1);
317         }
318 }
319
320 //----------------------------------------------------------------------------
321 void LayerImageBase::onThresholdRemove()
322 {
323         if (_actorPresent)
324         {
325                 wxVtkBaseView * baseView = _baseView;
326                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
327                 _actorPresent = false;
328         }
329 }
330
331 //----------------------------------------------------------------------------
332 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
333 {
334     return _thresholdTable;
335 }
336
337 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
338 {
339     return _imageReslicer;
340 }
341
342
343
344 // EOF
345