ThresholdImageView.cxx

Go to the documentation of this file.
00001 
00007 #include "ThresholdImageView.h"
00008 
00009   //=========================================================================
00010         ThresholdImageView::ThresholdImageView( )
00011   {
00012           _actorPresent                         =       false;
00013           _Z                                            =       0;
00014           _minValue                                     =       0;
00015           _maxValue                                     =       1000;
00016           _image                                        =       NULL;
00017           _imageReslicer                        =       NULL;
00018           _thresholdTable                       =       NULL;
00019           _thresholdMapper                      =       NULL;
00020           _thresholdActor                       =       NULL;
00021           _baseColorR                           =       1;
00022           _baseColorG                           =       0;
00023           _baseColorB                           =       0;
00024   }
00025 
00026   //=========================================================================
00027   ThresholdImageView::~ThresholdImageView()
00028   {
00029   }
00030   //=========================================================================
00031 
00032 
00033 //----------------------------------------------------------------------------
00034 void ThresholdImageView::SetImage(vtkImageData* image)
00035 {
00036         _image = image;
00037 }
00038 
00039 //----------------------------------------------------------------------------
00040 void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview)
00041 {
00042         _baseView = baseview;
00043 }
00044 
00045 //----------------------------------------------------------------------------
00046 wxVtkBaseView *ThresholdImageView::GetwxVtkBaseView()
00047 {
00048         return _baseView;
00049 }
00050 
00051 //----------------------------------------------------------------------------
00052 void ThresholdImageView::SetZ(int z)
00053 {
00054         _Z = z;
00055 }
00056 
00057 //----------------------------------------------------------------------------
00058 void ThresholdImageView::SetminMaxValue(int min, int max)
00059 {
00060         _minValue = min;
00061         _maxValue = max;
00062 }
00063 
00064 //----------------------------------------------------------------------------
00065 void ThresholdImageView::onThreshold()
00066 {
00067         int     z = _Z;
00068         double range[2];
00069         
00070         vtkImageData *img = _image;
00071         img->GetScalarRange(range);
00072         if (range[1]==0)
00073         {
00074                 range[1]=255;
00075         }
00076         
00077         int minTot = floor (range[0]);
00078         int maxTot = ceil (range[1]);
00079         
00080         int minVal = floor (_minValue);
00081         int maxVal = floor (_maxValue);
00082         
00083         if (!_actorPresent)
00084         {
00085                 if (_imageReslicer==NULL)
00086                 {
00087                         _imageReslicer = vtkImageReslice::New();
00088                         _imageReslicer->SetInput( img );
00089                         _imageReslicer->SetInformationInput(img);                       
00090                         _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
00091                         _imageReslicer->SetOutputDimensionality(2);
00092                         _imageReslicer->SetInterpolationModeToLinear();
00093                 }
00094                 
00095                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
00096                 
00097                 img = _imageReslicer->GetOutput();
00098                 img->Update();
00099                 img->UpdateInformation();
00100                 
00101                 wxVtkBaseView *baseView = _baseView;
00102                 
00103                 if (_thresholdTable==NULL)
00104                 {
00105                         //Lookup Table
00106                         _thresholdTable = vtkLookupTable::New();
00107                         _thresholdTable->SetNumberOfTableValues(maxTot+1);
00108                         _thresholdTable->SetTableRange(range); 
00109                         _thresholdTable->SetAlphaRange(0, 1);
00110                         _thresholdTable->SetValueRange(0, 1);
00111                         _thresholdTable->SetSaturationRange(0, 0); 
00112                         _thresholdTable->SetRampToLinear( );
00113                 }
00114                 
00115                 //Assign a fake color for the upper image, and set the white as transparent
00116                 int i;
00117                 for(i = minTot; i <= maxTot; i++)
00118                 {
00119                         if( i >= minVal && i <= maxVal )
00120                         {
00121                                 _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
00122                         }
00123                         else if( i >= minTot && i < minVal )
00124                         {
00125                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
00126                         }
00127                         else if( i > maxVal && i < maxTot )
00128                         {
00129                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
00130                         }
00131                         else
00132                         {
00133                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
00134                         }
00135                 }
00136                 _thresholdTable->Build( );
00137                 
00138                 if (_thresholdMapper==NULL)
00139                 {
00140                         _thresholdMapper = vtkImageMapToColors::New( );
00141                 }
00142                 
00143                 _thresholdMapper->SetLookupTable( _thresholdTable );
00144                 _thresholdMapper->SetInput( img );
00145                 
00146                 if (_thresholdActor==NULL)
00147                 {
00148                         _thresholdActor = vtkImageActor::New( );
00149                         _thresholdActor->SetOpacity( 0.6 );
00150                         _thresholdActor->InterpolateOn(  );
00151                         _thresholdActor->SetPosition( 0,0, 900-1 );
00152                 }
00153                 
00154                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
00155                 
00156                 baseView->GetRenderer()->AddActor( _thresholdActor );
00157                 _actorPresent = true;
00158         }
00159         else
00160         {
00161                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
00162                 img = _imageReslicer->GetOutput();
00163                 img->Update();
00164                 img->UpdateInformation();
00165                 
00166                 //Assign a fake color for the upper image, and set the white as transparent
00167                 int i;
00168                 for(i = minTot; i <= maxTot; i++)
00169                 {
00170                         if( i >= minVal && i <= maxVal )
00171                         {
00172                                 _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
00173                         }
00174                         else if( i >= minTot && i < minVal )
00175                         {
00176                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
00177                         }
00178                         else if( i > maxVal && i < maxTot )
00179                         {
00180                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
00181                         }
00182                         else
00183                         {
00184                                 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
00185                         }
00186                 }
00187                 _thresholdTable->Build( );
00188                 _thresholdMapper->SetLookupTable( _thresholdTable );
00189                 _thresholdMapper->SetInput( img );
00190                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
00191         }
00192 }
00193 
00194 
00195 //----------------------------------------------------------------------------
00196 void ThresholdImageView::onThresholdChange()
00197 {
00198         if (_actorPresent)
00199         {
00200                 onThreshold();
00201         }
00202 }
00203 
00204 //----------------------------------------------------------------------------
00205 void ThresholdImageView::onThresholdInterpolation(bool interpolate)
00206 {
00207         if (_thresholdActor!=NULL)
00208         {
00209                 if (interpolate)
00210                 {
00211                         _thresholdActor->InterpolateOn( );
00212                 }
00213                 else
00214                 {
00215                         _thresholdActor->InterpolateOff( );
00216                 }               
00217         }
00218 }
00219 
00220 //----------------------------------------------------------------------------
00221 void ThresholdImageView::onThresholdChangeOpacity (int opacity)
00222 {
00223         if (_actorPresent)
00224         {
00225                 _thresholdActor->SetOpacity(opacity*0.1);
00226         }
00227 }
00228 
00229 //----------------------------------------------------------------------------
00230 void ThresholdImageView::onThresholdRemove()
00231 {
00232         if (_actorPresent)
00233         {
00234                 wxVtkBaseView * baseView = _baseView;
00235                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
00236                 _actorPresent = false;
00237         }       
00238 }
00239 
00240 
00241 //----------------------------------------------------------------------------
00242 void ThresholdImageView::SetBaseColor(double r, double g, double b)
00243 {
00244         _baseColorR = r;
00245         _baseColorG = g;
00246         _baseColorB = b;
00247 }
00248 
00249 
00250 // EOF
00251 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1