4 * \brief Class bbtk::ThresholdImageView .
8 #include "ThresholdImageView.h"
12 //=========================================================================
13 ThresholdImageView::ThresholdImageView( )
15 _actorPresent = false;
20 _imageReslicer = NULL;
21 _thresholdTable = NULL;
22 _thresholdMapper = NULL;
23 _thresholdActor = NULL;
29 //=========================================================================
30 ThresholdImageView::~ThresholdImageView()
33 //=========================================================================
36 //----------------------------------------------------------------------------
37 void ThresholdImageView::SetImage(vtkImageData* image)
39 printf("ThresholdImageView::SetImage %p\n", image);
43 //----------------------------------------------------------------------------
44 void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview)
49 //----------------------------------------------------------------------------
50 wxVtkBaseView *ThresholdImageView::GetwxVtkBaseView()
55 //----------------------------------------------------------------------------
56 void ThresholdImageView::SetZ(int z)
61 //----------------------------------------------------------------------------
62 void ThresholdImageView::SetminMaxValue(int min, int max)
68 //----------------------------------------------------------------------------
69 void ThresholdImageView::onThreshold()
74 vtkImageData *img = _image;
75 img->GetScalarRange(range);
82 int minTot = floor (range[0]);
83 int maxTot = ceil (range[1]);
86 int minVal = floor (_minValue);
87 int maxVal = floor (_maxValue);
92 if (_imageReslicer==NULL)
94 _imageReslicer = vtkImageReslice::New();
95 _imageReslicer->SetInput( img );
96 _imageReslicer->SetInformationInput(img);
97 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
98 _imageReslicer->SetOutputDimensionality(2);
99 _imageReslicer->SetInterpolationModeToLinear();
102 _imageReslicer->SetResliceAxesOrigin(0,0,z);
104 img = _imageReslicer->GetOutput();
106 img->UpdateInformation();
108 wxVtkBaseView *baseView = _baseView;
110 if (_thresholdTable==NULL)
113 _thresholdTable = vtkLookupTable::New();
114 _thresholdTable->SetNumberOfTableValues(maxTot+1);
115 _thresholdTable->SetTableRange(range);
116 _thresholdTable->SetAlphaRange(0, 1);
117 _thresholdTable->SetValueRange(0, 1);
118 _thresholdTable->SetSaturationRange(0, 0);
119 _thresholdTable->SetRampToLinear( );
122 //Assign a fake color for the upper image, and set the white as transparent
124 for(i = minTot; i <= maxTot; i++)
126 if( i >= minVal && i <= maxVal )
128 _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
130 else if( i >= minTot && i < minVal )
132 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
134 else if( i > maxVal && i < maxTot )
136 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
140 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
143 _thresholdTable->Build( );
145 if (_thresholdMapper==NULL)
147 _thresholdMapper = vtkImageMapToColors::New( );
150 _thresholdMapper->SetLookupTable( _thresholdTable );
151 _thresholdMapper->SetInput( img );
153 if (_thresholdActor==NULL)
155 _thresholdActor = vtkImageActor::New( );
156 _thresholdActor->SetOpacity( 0.6 );
157 _thresholdActor->InterpolateOn( );
158 _thresholdActor->SetPosition( 0,0, 900-1 );
161 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
163 baseView->GetRenderer()->AddActor( _thresholdActor );
164 _actorPresent = true;
169 _imageReslicer->SetResliceAxesOrigin(0,0,z);
170 img = _imageReslicer->GetOutput();
172 img->UpdateInformation();
174 //Assign a fake color for the upper image, and set the white as transparent
176 for(i = minTot; i <= maxTot; i++)
178 if( i >= minVal && i <= maxVal )
180 _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
182 else if( i >= minTot && i < minVal )
184 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
186 else if( i > maxVal && i < maxTot )
188 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
192 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
196 _thresholdTable->Build( );
197 _thresholdMapper->SetLookupTable( _thresholdTable );
198 _thresholdMapper->SetInput( img );
199 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
204 //----------------------------------------------------------------------------
205 void ThresholdImageView::onThresholdChange()
213 //----------------------------------------------------------------------------
214 void ThresholdImageView::onThresholdInterpolation(bool interpolate)
216 if (_thresholdActor!=NULL)
220 _thresholdActor->InterpolateOn( );
225 _thresholdActor->InterpolateOff( );
228 //EED _theViewPanel->RefreshInterface();
232 //----------------------------------------------------------------------------
233 void ThresholdImageView::onThresholdChangeOpacity (int opacity)
237 _thresholdActor->SetOpacity(opacity*0.1);
240 //EED _theViewPanel->RefreshInterface();
243 //----------------------------------------------------------------------------
244 void ThresholdImageView::onThresholdRemove()
248 wxVtkBaseView * baseView = _baseView;
249 baseView->GetRenderer()->RemoveActor( _thresholdActor );
250 _actorPresent = false;
253 //EED _theViewPanel->RefreshInterface();
257 //----------------------------------------------------------------------------
258 void ThresholdImageView::SetBaseColor(double r, double g, double b)