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