]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
no message
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
1
2 /**
3  *  \file
4  *  \brief Class bbtk::ThresholdImageView .
5  */
6
7 #include "LayerImageBase.h"
8
9
10 //---------------------------------------------------------------------------------------------
11 //---------------------------------------------------------------------------------------------
12 //---------------------------------------------------------------------------------------------
13
14 ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
15 {
16     _layerImageBase=layerImageBase;
17 }
18
19 //---------------------------------------------------------------------------------------------
20 ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
21 {
22 }
23
24
25 //---------------------------------------------------------------------------------------------
26 bool ColorLayerImageBasevtkInteractor::OnMouseMove()
27 {
28         printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
29     if  (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
30     {
31         _layerImageBase->GetvtkImageReslice()->Modified();
32     }
33
34     return true;
35 }
36
37
38 //---------------------------------------------------------------------------------------------
39 //---------------------------------------------------------------------------------------------
40 //---------------------------------------------------------------------------------------------
41
42
43
44 LayerImageBase::LayerImageBase()
45 {
46         _actorPresent                   =       false;
47         _Z                                              =       0;
48         _thresholdTable                 =       NULL;
49         _thresholdMapper                =       NULL;
50         _thresholdActor                 =       NULL;
51         _image                                  =       NULL;
52         _baseView               =   NULL;
53         _imageReslicer                  =       vtkImageReslice::New();
54
55 }
56
57 //----------------------------------------------------------------------------
58   LayerImageBase::~LayerImageBase()
59   {
60   }
61
62 //----------------------------------------------------------------------------
63 void LayerImageBase::SetZ(int z)
64 {
65         _Z = z;
66 }
67
68 //----------------------------------------------------------------------------
69 int LayerImageBase::GetZ()  // virtual
70 {
71         return _Z;
72 }
73
74 //----------------------------------------------------------------------------
75 vtkImageData* LayerImageBase::GetImage()
76 {
77         return _image;
78 }
79
80 //----------------------------------------------------------------------------
81 bool LayerImageBase::GetActorPresent()
82 {
83         return _actorPresent;
84 }
85
86
87
88 //----------------------------------------------------------------------------
89 void LayerImageBase::SetImage(vtkImageData* image)
90 {
91         _image = image;
92 }
93
94 //----------------------------------------------------------------------------
95 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
96 {
97         printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
98
99         _baseView = baseview;
100
101     vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
102     isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
103         
104         printf("EED LayerImageBase::SetwxVtkBaseView end \n");
105 }
106
107 //----------------------------------------------------------------------------
108 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
109 {
110         return _baseView;
111 }
112
113 //----------------------------------------------------------------------------
114 void LayerImageBase::Refresh()
115 {
116     printf("EED LayerImageBase::Refresh\n");
117     if (_baseView!=NULL)
118     {
119         _baseView->Refresh();
120     }
121 }
122
123
124 //----------------------------------------------------------------------------
125 vtkLookupTable* LayerImageBase::GetThresholdTable()
126 {
127         return _thresholdTable;
128 }
129
130 //----------------------------------------------------------------------------
131 int LayerImageBase::CleanZ(int z)
132 {
133         int ext[6];
134         _image->GetWholeExtent(ext);
135
136         if (z<0)
137         {
138                 z=0;
139         }
140
141         if ( z > (ext[5]-ext[4]) )
142         {
143                 z=ext[5]-ext[4];
144         }
145
146         return z;
147 }
148
149 //----------------------------------------------------------------------------
150 void LayerImageBase::onThreshold()
151 {
152         
153         printf("EED LayerImageBase::onThreshold start \n");
154         
155         if ((_image!=NULL) && (_baseView!=NULL))
156         {
157                 int z=CleanZ( GetZ() );
158
159                 if (!GetActorPresent())
160                 {
161                         if (_thresholdTable==NULL)
162                         {
163                                 //Lookup Table
164                                 _thresholdTable = vtkLookupTable::New();
165                         } // _thresholdTable
166
167                         if (_thresholdMapper==NULL)
168                         {
169                                 _thresholdMapper = vtkImageMapToColors::New( );
170                         }
171
172                         if (_thresholdActor==NULL)
173                         {
174                                 _thresholdActor = vtkImageActor::New( );
175                                 _thresholdActor->SetOpacity( 0.6 );
176                                 _thresholdActor->InterpolateOn(  );
177                                 _thresholdActor->SetPosition( 0,0, 900-1 );
178                         } // _thresholdActor
179                         _baseView->GetRenderer()->AddActor( _thresholdActor );
180                         _actorPresent = true;
181                 }  // !GetActorPresent()
182
183                 ConfigLookupTable();  // virtual method
184                 _imageReslicer->SetInput( GetImage() );
185                 _imageReslicer->SetInformationInput( GetImage() );
186                 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
187                 _imageReslicer->SetOutputDimensionality(2);
188                 _imageReslicer->SetInterpolationModeToLinear();
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