]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
Support #1768 CREATIS Licence insertion
[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
34 //---------------------------------------------------------------------------------------------
35 //---------------------------------------------------------------------------------------------
36 //---------------------------------------------------------------------------------------------
37
38 ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
39 {
40     _layerImageBase=layerImageBase;
41 }
42
43 //---------------------------------------------------------------------------------------------
44 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
45 {
46 }
47
48
49 //---------------------------------------------------------------------------------------------
50 bool ColorLayerImageBasevtkInteractor::OnMouseMove()
51 {
52         printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
53     if  (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
54     {
55         _layerImageBase->GetvtkImageReslice()->Modified();
56     }
57
58     return true;
59 }
60
61
62 //---------------------------------------------------------------------------------------------
63 //---------------------------------------------------------------------------------------------
64 //---------------------------------------------------------------------------------------------
65
66
67
68 LayerImageBase::LayerImageBase()
69 {
70         _actorPresent                   =       false;
71         _Z                              =       0;
72         _thresholdTable                 =       NULL;
73         _thresholdMapper                =       NULL;
74         _thresholdActor                 =       NULL;
75         _image                          =       NULL;
76         _baseView                       =       NULL;
77         _imageReslicer                  =       vtkImageReslice::New();
78
79 }
80
81 //----------------------------------------------------------------------------
82   LayerImageBase::~LayerImageBase()
83   {
84   }
85
86 //----------------------------------------------------------------------------
87 void LayerImageBase::SetZ(int z)
88 {
89         _Z = z;
90 }
91
92 //----------------------------------------------------------------------------
93 int LayerImageBase::GetZ()  // virtual
94 {
95         return _Z;
96 }
97
98 //----------------------------------------------------------------------------
99 vtkImageData* LayerImageBase::GetImage()
100 {
101         return _image;
102 }
103
104 //----------------------------------------------------------------------------
105 bool LayerImageBase::GetActorPresent()
106 {
107         return _actorPresent;
108 }
109
110
111
112 //----------------------------------------------------------------------------
113 void LayerImageBase::SetImage(vtkImageData* image)
114 {
115         _image = image;
116 }
117
118 //----------------------------------------------------------------------------
119 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
120 {
121         printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
122
123         _baseView = baseview;
124
125     vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
126     isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
127         
128         printf("EED LayerImageBase::SetwxVtkBaseView end \n");
129 }
130
131 //----------------------------------------------------------------------------
132 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
133 {
134         return _baseView;
135 }
136
137 //----------------------------------------------------------------------------
138 void LayerImageBase::Refresh()
139 {
140     printf("EED LayerImageBase::Refresh\n");
141     if (_baseView!=NULL)
142     {
143         _baseView->Refresh();
144     }
145 }
146
147
148 //----------------------------------------------------------------------------
149 vtkLookupTable* LayerImageBase::GetThresholdTable()
150 {
151         return _thresholdTable;
152 }
153
154 //----------------------------------------------------------------------------
155 int LayerImageBase::CleanZ(int z)
156 {
157         int ext[6];
158         _image->GetWholeExtent(ext);
159
160         if (z<0)
161         {
162                 z=0;
163         }
164
165         if ( z > (ext[5]-ext[4]) )
166         {
167                 z=ext[5]-ext[4];
168         }
169
170         return z;
171 }
172
173 //----------------------------------------------------------------------------
174 void LayerImageBase::onThreshold()
175 {
176         
177         printf("EED LayerImageBase::onThreshold start \n");
178         
179         if ((_image!=NULL) && (_baseView!=NULL))
180         {
181                 int z=CleanZ( GetZ() );
182
183                 if (!GetActorPresent())
184                 {
185                         if (_thresholdTable==NULL)
186                         {
187                                 //Lookup Table
188                                 _thresholdTable = vtkLookupTable::New();
189                         } // _thresholdTable
190
191                         if (_thresholdMapper==NULL)
192                         {
193                                 _thresholdMapper = vtkImageMapToColors::New( );
194                         }
195
196                         if (_thresholdActor==NULL)
197                         {
198                                 _thresholdActor = vtkImageActor::New( );
199                                 _thresholdActor->SetOpacity( 0.6 );
200                                 _thresholdActor->InterpolateOn(  );
201                                 _thresholdActor->SetPosition( 0,0, -900-1 );
202                         } // _thresholdActor
203                         _baseView->GetRenderer()->AddActor( _thresholdActor );
204                         _actorPresent = true;
205                 }  // !GetActorPresent()
206
207                 ConfigLookupTable();  // virtual method
208                 _imageReslicer->SetInput( GetImage() );
209                 _imageReslicer->SetInformationInput( GetImage() );
210                 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
211                 _imageReslicer->SetOutputDimensionality(2);
212 //              _imageReslicer->SetInterpolationModeToLinear();
213                 _imageReslicer->SetInterpolationModeToNearestNeighbor();
214                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
215
216                 vtkImageData *img = _imageReslicer->GetOutput();
217 //              img->Update();
218 //              img->UpdateInformation();
219
220                 _thresholdMapper->SetInput( img );
221                 _thresholdMapper->SetLookupTable( _thresholdTable );
222                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
223
224                 printf("EED LayerImageBase::onThreshold working \n");
225                 
226                 
227                 } // _image
228         printf("EED LayerImageBase::onThreshold end");
229 }
230
231
232
233 //----------------------------------------------------------------------------
234 void LayerImageBase::onThresholdChange()
235 {
236         if (_actorPresent)
237         {
238                 onThreshold();
239         }
240 }
241
242 //----------------------------------------------------------------------------
243 void LayerImageBase::onThresholdInterpolation(bool interpolate)
244 {
245         if (_thresholdActor!=NULL)
246         {
247                 if (interpolate)
248                 {
249                         _thresholdActor->InterpolateOn( );
250                 }
251                 else
252                 {
253                         _thresholdActor->InterpolateOff( );
254                 }
255         }
256 }
257
258 //----------------------------------------------------------------------------
259 void LayerImageBase::onThresholdChangeOpacity (int opacity)
260 {
261         if (_actorPresent)
262         {
263                 _thresholdActor->SetOpacity(opacity*0.1);
264         }
265 }
266
267 //----------------------------------------------------------------------------
268 void LayerImageBase::onThresholdRemove()
269 {
270         if (_actorPresent)
271         {
272                 wxVtkBaseView * baseView = _baseView;
273                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
274                 _actorPresent = false;
275         }
276 }
277
278 //----------------------------------------------------------------------------
279 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
280 {
281     return _thresholdTable;
282 }
283
284 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
285 {
286     return _imageReslicer;
287 }
288
289
290
291 // EOF
292