4 * \brief Class bbtk::ThresholdImageView .
7 #include "ThresholdImageView.h"
9 //=========================================================================
10 ThresholdImageView::ThresholdImageView( )
12 _actorPresent = false;
17 _imageReslicer = NULL;
18 _thresholdTable = NULL;
19 _thresholdMapper = NULL;
20 _thresholdActor = NULL;
26 //=========================================================================
27 ThresholdImageView::~ThresholdImageView()
30 //=========================================================================
33 //----------------------------------------------------------------------------
34 void ThresholdImageView::SetImage(vtkImageData* image)
39 //----------------------------------------------------------------------------
40 void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview)
45 //----------------------------------------------------------------------------
46 wxVtkBaseView *ThresholdImageView::GetwxVtkBaseView()
51 //----------------------------------------------------------------------------
52 void ThresholdImageView::SetZ(int z)
57 //----------------------------------------------------------------------------
58 void ThresholdImageView::SetminMaxValue(int min, int max)
64 //----------------------------------------------------------------------------
65 void ThresholdImageView::onThreshold()
70 vtkImageData *img = _image;
71 img->GetScalarRange(range);
77 int minTot = floor (range[0]);
78 int maxTot = ceil (range[1]);
80 int minVal = floor (_minValue);
81 int maxVal = floor (_maxValue);
85 if (_imageReslicer==NULL)
87 _imageReslicer = vtkImageReslice::New();
88 _imageReslicer->SetInput( img );
89 _imageReslicer->SetInformationInput(img);
90 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
91 _imageReslicer->SetOutputDimensionality(2);
92 _imageReslicer->SetInterpolationModeToLinear();
95 _imageReslicer->SetResliceAxesOrigin(0,0,z);
97 img = _imageReslicer->GetOutput();
99 img->UpdateInformation();
101 wxVtkBaseView *baseView = _baseView;
103 if (_thresholdTable==NULL)
106 _thresholdTable = vtkLookupTable::New();
107 _thresholdTable->SetNumberOfTableValues(maxTot+1);
108 _thresholdTable->SetTableRange(range);
109 _thresholdTable->SetAlphaRange(0, 1);
110 _thresholdTable->SetValueRange(0, 1);
111 _thresholdTable->SetSaturationRange(0, 0);
112 _thresholdTable->SetRampToLinear( );
115 //Assign a fake color for the upper image, and set the white as transparent
117 for(i = minTot; i <= maxTot; i++)
119 if( i >= minVal && i <= maxVal )
121 _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
123 else if( i >= minTot && i < minVal )
125 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
127 else if( i > maxVal && i < maxTot )
129 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
133 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
136 _thresholdTable->Build( );
138 if (_thresholdMapper==NULL)
140 _thresholdMapper = vtkImageMapToColors::New( );
143 _thresholdMapper->SetLookupTable( _thresholdTable );
144 _thresholdMapper->SetInput( img );
146 if (_thresholdActor==NULL)
148 _thresholdActor = vtkImageActor::New( );
149 _thresholdActor->SetOpacity( 0.6 );
150 _thresholdActor->InterpolateOn( );
151 _thresholdActor->SetPosition( 0,0, 900-1 );
154 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
156 baseView->GetRenderer()->AddActor( _thresholdActor );
157 _actorPresent = true;
161 _imageReslicer->SetResliceAxesOrigin(0,0,z);
162 img = _imageReslicer->GetOutput();
164 img->UpdateInformation();
166 //Assign a fake color for the upper image, and set the white as transparent
168 for(i = minTot; i <= maxTot; i++)
170 if( i >= minVal && i <= maxVal )
172 _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
174 else if( i >= minTot && i < minVal )
176 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
178 else if( i > maxVal && i < maxTot )
180 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
184 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
187 _thresholdTable->Build( );
188 _thresholdMapper->SetLookupTable( _thresholdTable );
189 _thresholdMapper->SetInput( img );
190 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
195 //----------------------------------------------------------------------------
196 void ThresholdImageView::onThresholdChange()
204 //----------------------------------------------------------------------------
205 void ThresholdImageView::onThresholdInterpolation(bool interpolate)
207 if (_thresholdActor!=NULL)
211 _thresholdActor->InterpolateOn( );
215 _thresholdActor->InterpolateOff( );
220 //----------------------------------------------------------------------------
221 void ThresholdImageView::onThresholdChangeOpacity (int opacity)
225 _thresholdActor->SetOpacity(opacity*0.1);
229 //----------------------------------------------------------------------------
230 void ThresholdImageView::onThresholdRemove()
234 wxVtkBaseView * baseView = _baseView;
235 baseView->GetRenderer()->RemoveActor( _thresholdActor );
236 _actorPresent = false;
241 //----------------------------------------------------------------------------
242 void ThresholdImageView::SetBaseColor(double r, double g, double b)