4 * \brief Class bbtk::ThresholdImageView .
8 #include "ThresholdImageView.h"
12 //=========================================================================
13 ThresholdImageView::ThresholdImageView( )
15 _actorPresent = false;
18 //=========================================================================
19 ThresholdImageView::~ThresholdImageView()
22 //=========================================================================
25 //----------------------------------------------------------------------------
26 void ThresholdImageView::SetImage(vtkImageData* image)
31 //----------------------------------------------------------------------------
32 void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview)
37 //----------------------------------------------------------------------------
38 void ThresholdImageView::SetZ(int z)
43 //----------------------------------------------------------------------------
44 void ThresholdImageView::SetminMax(int min, int max)
50 //----------------------------------------------------------------------------
51 void ThresholdImageView::onThreshold()
56 vtkImageData *img = _image;
57 img->GetScalarRange(range);
59 int minTot = floor (range[0]);
60 int maxTot = ceil (range[1]);
62 //EED _pannew->onThresholdInstantChange(minMax);
64 int minVal = floor (_min);
65 int maxVal = floor (_max);
69 if (_imageReslicer==NULL)
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();
79 _imageReslicer->SetResliceAxesOrigin(0,0,z);
81 img = _imageReslicer->GetOutput();
83 img->UpdateInformation();
85 wxVtkBaseView *baseView = _baseView;
87 if (_thresholdTable==NULL)
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( );
99 //Assign a fake color for the upper image, and set the white as transparent
101 for(i = minTot; i <= maxTot; i++)
103 if( i >= minVal && i <= maxVal )
105 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
107 else if( i >= minTot && i < minVal )
109 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
111 else if( i > maxVal && i < maxTot )
113 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
117 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
120 _thresholdTable->Build( );
122 if (_thresholdMapper==NULL)
124 _thresholdMapper = vtkImageMapToColors::New( );
127 _thresholdMapper->SetLookupTable( _thresholdTable );
128 _thresholdMapper->SetInput( img );
130 if (_thresholdActor==NULL)
132 _thresholdActor = vtkImageActor::New( );
133 _thresholdActor->SetOpacity( 0.6 );
134 _thresholdActor->InterpolateOn( );
135 _thresholdActor->SetPosition( 0,0, 900-1 );
138 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
140 baseView->GetRenderer()->AddActor( _thresholdActor );
141 _actorPresent = true;
146 _imageReslicer->SetResliceAxesOrigin(0,0,z);
147 img = _imageReslicer->GetOutput();
149 img->UpdateInformation();
151 //Assign a fake color for the upper image, and set the white as transparent
153 for(i = minTot; i <= maxTot; i++)
155 if( i >= minVal && i <= maxVal )
157 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
159 else if( i >= minTot && i < minVal )
161 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
163 else if( i > maxVal && i < maxTot )
165 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
169 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
173 _thresholdTable->Build( );
174 _thresholdMapper->SetLookupTable( _thresholdTable );
175 _thresholdMapper->SetInput( img );
176 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
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 );
186 //EED _theViewPanel->RefreshInterface();
190 //----------------------------------------------------------------------------
191 void ThresholdImageView::onThresholdChange()
199 //----------------------------------------------------------------------------
200 void ThresholdImageView::onThresholdInterpolation(bool interpolate)
202 if (_thresholdActor!=NULL)
206 _thresholdActor->InterpolateOn( );
211 _thresholdActor->InterpolateOff( );
214 //EED _theViewPanel->RefreshInterface();
218 //----------------------------------------------------------------------------
219 void ThresholdImageView::onThresholdChangeOpacity (int opacity)
223 _thresholdActor->SetOpacity(opacity*0.1);
226 //EED _theViewPanel->RefreshInterface();
229 //----------------------------------------------------------------------------
230 void ThresholdImageView::onThresholdRemove()
234 wxVtkBaseView * baseView = _baseView;
235 baseView->GetRenderer()->RemoveActor( _thresholdActor );
236 _actorPresent = false;
239 //EED _theViewPanel->RefreshInterface();