]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
c6d8465096bfd21a7ec43484e7ed82244e2eef78
[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
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         _baseView = baseview;
98
99     vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
100     isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
101 }
102
103 //----------------------------------------------------------------------------
104 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
105 {
106         return _baseView;
107 }
108
109 //----------------------------------------------------------------------------
110 void LayerImageBase::Refresh()
111 {
112     printf("EED LayerImageBase::Refresh\n");
113     if (_baseView!=NULL)
114     {
115         _baseView->Refresh();
116     }
117 }
118
119
120 //----------------------------------------------------------------------------
121 vtkLookupTable* LayerImageBase::GetThresholdTable()
122 {
123         return _thresholdTable;
124 }
125
126 //----------------------------------------------------------------------------
127 int LayerImageBase::CleanZ(int z)
128 {
129         int ext[6];
130         _image->GetWholeExtent(ext);
131
132         if (z<0)
133         {
134                 z=0;
135         }
136
137         if ( z > (ext[5]-ext[4]) )
138         {
139                 z=ext[5]-ext[4];
140         }
141
142         return z;
143 }
144
145 //----------------------------------------------------------------------------
146 void LayerImageBase::onThreshold()
147 {
148
149         if ((_image!=NULL) && (_baseView!=NULL))
150         {
151                 int z=CleanZ( GetZ() );
152
153                 if (!GetActorPresent())
154                 {
155                         if (_thresholdTable==NULL)
156                         {
157                                 //Lookup Table
158                                 _thresholdTable = vtkLookupTable::New();
159                         } // _thresholdTable
160
161                         if (_thresholdMapper==NULL)
162                         {
163                                 _thresholdMapper = vtkImageMapToColors::New( );
164                         }
165
166                         if (_thresholdActor==NULL)
167                         {
168                                 _thresholdActor = vtkImageActor::New( );
169                                 _thresholdActor->SetOpacity( 0.6 );
170                                 _thresholdActor->InterpolateOn(  );
171                                 _thresholdActor->SetPosition( 0,0, 900-1 );
172                         } // _thresholdActor
173                         _baseView->GetRenderer()->AddActor( _thresholdActor );
174                         _actorPresent = true;
175                 }  // !GetActorPresent()
176
177                 ConfigLookupTable();  // virtual method
178                 _imageReslicer->SetInput( GetImage() );
179                 _imageReslicer->SetInformationInput( GetImage() );
180                 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
181                 _imageReslicer->SetOutputDimensionality(2);
182                 _imageReslicer->SetInterpolationModeToLinear();
183                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
184
185                 vtkImageData *img = _imageReslicer->GetOutput();
186 //              img->Update();
187 //              img->UpdateInformation();
188
189                 _thresholdMapper->SetInput( img );
190                 _thresholdMapper->SetLookupTable( _thresholdTable );
191                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
192                 } // _image
193 }
194
195
196
197 //----------------------------------------------------------------------------
198 void LayerImageBase::onThresholdChange()
199 {
200         if (_actorPresent)
201         {
202                 onThreshold();
203         }
204 }
205
206 //----------------------------------------------------------------------------
207 void LayerImageBase::onThresholdInterpolation(bool interpolate)
208 {
209         if (_thresholdActor!=NULL)
210         {
211                 if (interpolate)
212                 {
213                         _thresholdActor->InterpolateOn( );
214                 }
215                 else
216                 {
217                         _thresholdActor->InterpolateOff( );
218                 }
219         }
220 }
221
222 //----------------------------------------------------------------------------
223 void LayerImageBase::onThresholdChangeOpacity (int opacity)
224 {
225         if (_actorPresent)
226         {
227                 _thresholdActor->SetOpacity(opacity*0.1);
228         }
229 }
230
231 //----------------------------------------------------------------------------
232 void LayerImageBase::onThresholdRemove()
233 {
234         if (_actorPresent)
235         {
236                 wxVtkBaseView * baseView = _baseView;
237                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
238                 _actorPresent = false;
239         }
240 }
241
242 //----------------------------------------------------------------------------
243 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
244 {
245     return _thresholdTable;
246 }
247
248 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
249 {
250     return _imageReslicer;
251 }
252
253
254
255 // EOF
256