]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
- new version
[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->SetInterpolationModeToNearestNeighbor();
190                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
191
192                 vtkImageData *img = _imageReslicer->GetOutput();
193 //              img->Update();
194 //              img->UpdateInformation();
195
196                 _thresholdMapper->SetInput( img );
197                 _thresholdMapper->SetLookupTable( _thresholdTable );
198                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
199
200                 printf("EED LayerImageBase::onThreshold working \n");
201                 
202                 
203                 } // _image
204         printf("EED LayerImageBase::onThreshold end");
205 }
206
207
208
209 //----------------------------------------------------------------------------
210 void LayerImageBase::onThresholdChange()
211 {
212         if (_actorPresent)
213         {
214                 onThreshold();
215         }
216 }
217
218 //----------------------------------------------------------------------------
219 void LayerImageBase::onThresholdInterpolation(bool interpolate)
220 {
221         if (_thresholdActor!=NULL)
222         {
223                 if (interpolate)
224                 {
225                         _thresholdActor->InterpolateOn( );
226                 }
227                 else
228                 {
229                         _thresholdActor->InterpolateOff( );
230                 }
231         }
232 }
233
234 //----------------------------------------------------------------------------
235 void LayerImageBase::onThresholdChangeOpacity (int opacity)
236 {
237         if (_actorPresent)
238         {
239                 _thresholdActor->SetOpacity(opacity*0.1);
240         }
241 }
242
243 //----------------------------------------------------------------------------
244 void LayerImageBase::onThresholdRemove()
245 {
246         if (_actorPresent)
247         {
248                 wxVtkBaseView * baseView = _baseView;
249                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
250                 _actorPresent = false;
251         }
252 }
253
254 //----------------------------------------------------------------------------
255 vtkLookupTable *LayerImageBase::GetvtkLookupTable()
256 {
257     return _thresholdTable;
258 }
259
260 vtkImageReslice *LayerImageBase::GetvtkImageReslice()
261 {
262     return _imageReslicer;
263 }
264
265
266
267 // EOF
268