]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx
no message
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ThresholdImageView.cxx
1
2 /**
3  *  \file 
4  *  \brief Class bbtk::ThresholdImageView . 
5  */
6
7
8 #include "ThresholdImageView.h"
9
10
11
12   //=========================================================================
13         ThresholdImageView::ThresholdImageView( )
14   {
15           _actorPresent                         = false;
16   }
17
18   //=========================================================================
19   ThresholdImageView::~ThresholdImageView()
20   {
21   }
22   //=========================================================================
23
24
25 //----------------------------------------------------------------------------
26 void ThresholdImageView::SetImage(vtkImageData* image)
27 {
28         _image = image;
29 }
30
31 //----------------------------------------------------------------------------
32 void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview)
33 {
34         _baseView = baseview;
35 }
36
37 //----------------------------------------------------------------------------
38 void ThresholdImageView::SetZ(int z)
39 {
40         _Z = z;
41 }
42
43 //----------------------------------------------------------------------------
44 void ThresholdImageView::SetminMax(int min, int max)
45 {
46         _min = min;
47         _max = max;
48 }
49
50 //----------------------------------------------------------------------------
51 void ThresholdImageView::onThreshold()
52 {
53         int     z = _Z;
54         double range[2];
55         
56         vtkImageData *img = _image;
57         img->GetScalarRange(range);
58         
59         int minTot = floor (range[0]);
60         int maxTot = ceil (range[1]);
61         
62 //EED   _pannew->onThresholdInstantChange(minMax);
63         
64         int minVal = floor (_min);
65         int maxVal = floor (_max);
66         
67         if (!_actorPresent)
68         {
69                 if (_imageReslicer==NULL)
70                 {
71                         _imageReslicer = vtkImageReslice::New();
72                         _imageReslicer->SetInput( img );
73                         _imageReslicer->SetInformationInput(img);
74                         _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
75                         _imageReslicer->SetOutputDimensionality(2);
76                         _imageReslicer->SetInterpolationModeToLinear();
77                 }
78                 
79                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
80                 
81                 img = _imageReslicer->GetOutput();
82                 img->Update();
83                 img->UpdateInformation();
84                 
85                 wxVtkBaseView *baseView = _baseView;
86                 
87                 if (_thresholdTable==NULL)
88                 {
89                         //Lookup Table
90                         _thresholdTable = vtkLookupTable::New();
91                         _thresholdTable->SetNumberOfTableValues(maxTot+1);
92                         _thresholdTable->SetTableRange(range); 
93                         _thresholdTable->SetAlphaRange(0, 1);
94                         _thresholdTable->SetValueRange(0, 1);
95                         _thresholdTable->SetSaturationRange(0, 0); 
96                         _thresholdTable->SetRampToLinear( );
97                 }
98                 
99                 //Assign a fake color for the upper image, and set the white as transparent
100                 int i;
101                 for(i = minTot; i <= maxTot; i++)
102                 {
103                         if( i >= minVal && i <= maxVal )
104                         {
105                                 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
106                         }
107                         else if( i >= minTot && i < minVal )
108                         {
109                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
110                         }
111                         else if( i > maxVal && i < maxTot )
112                         {
113                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
114                         }
115                         else
116                         {
117                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
118                         }
119                 }
120                 _thresholdTable->Build( );
121                 
122                 if (_thresholdMapper==NULL)
123                 {
124                         _thresholdMapper = vtkImageMapToColors::New( );
125                 }
126                 
127                 _thresholdMapper->SetLookupTable( _thresholdTable );
128                 _thresholdMapper->SetInput( img );
129                 
130                 if (_thresholdActor==NULL)
131                 {
132                         _thresholdActor = vtkImageActor::New( );
133                         _thresholdActor->SetOpacity( 0.6 );
134                         _thresholdActor->InterpolateOn(  );
135                         _thresholdActor->SetPosition( 0,0, 900-1 );
136                 }
137                 
138                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
139                 
140                 baseView->GetRenderer()->AddActor( _thresholdActor );
141                 _actorPresent = true;
142         }
143         
144         else
145         {
146                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
147                 img = _imageReslicer->GetOutput();
148                 img->Update();
149                 img->UpdateInformation();
150                 
151                 //Assign a fake color for the upper image, and set the white as transparent
152                 int i;
153                 for(i = minTot; i <= maxTot; i++)
154                 {
155                         if( i >= minVal && i <= maxVal )
156                         {
157                                 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
158                         }
159                         else if( i >= minTot && i < minVal )
160                         {
161                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
162                         }
163                         else if( i > maxVal && i < maxTot )
164                         {
165                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
166                         }
167                         else
168                         {
169                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
170                         }
171                 }
172                 
173                 _thresholdTable->Build( );
174                 _thresholdMapper->SetLookupTable( _thresholdTable );
175                 _thresholdMapper->SetInput( img );
176                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
177         }
178         /*
179          vtkImageViewer2* viewer = vtkImageViewer2::New();       
180          viewer->SetInput( upperImageActor->GetInput() ); 
181          viewer->SetColorLevel((range[1]-range[0])/2);
182          viewer->SetColorWindow(range[1]);
183          viewer->GetRenderer()->AddActor( upperImageActor );
184          viewer->Render();
185          */
186 //EED   _theViewPanel->RefreshInterface();
187 }
188
189
190 //----------------------------------------------------------------------------
191 void ThresholdImageView::onThresholdChange()
192 {
193         if (_actorPresent)
194         {
195                 onThreshold();
196         }
197 }
198
199 //----------------------------------------------------------------------------
200 void ThresholdImageView::onThresholdInterpolation(bool interpolate)
201 {
202         if (_thresholdActor!=NULL)
203         {
204                 if (interpolate)
205                 {
206                         _thresholdActor->InterpolateOn( );
207                 }
208                 
209                 else
210                 {
211                         _thresholdActor->InterpolateOff( );
212                 }
213                 
214 //EED           _theViewPanel->RefreshInterface();
215         }
216 }
217
218 //----------------------------------------------------------------------------
219 void ThresholdImageView::onThresholdChangeOpacity (int opacity)
220 {
221         if (_actorPresent)
222         {
223                 _thresholdActor->SetOpacity(opacity*0.1);
224         }
225         
226 //EED   _theViewPanel->RefreshInterface();
227 }
228
229 //----------------------------------------------------------------------------
230 void ThresholdImageView::onThresholdRemove()
231 {
232         if (_actorPresent)
233         {
234                 wxVtkBaseView * baseView = _baseView;
235                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
236                 _actorPresent = false;
237         }
238         
239 //EED   _theViewPanel->RefreshInterface();
240 }
241
242
243
244
245 // EOF
246