From e2509516e281249369e6792239847216068556c4 Mon Sep 17 00:00:00 2001 From: Eduardo Davila Date: Fri, 16 Jul 2010 14:44:28 +0000 Subject: [PATCH] *** empty log message *** --- .../ThresholdImageView/LayerImageBase.cxx | 179 +++++++++++++++ .../ThresholdImageView/LayerImageBase.h | 62 +++++ .../ThresholdImageView/ThresholdImageView.cxx | 212 +++--------------- .../ThresholdImageView/ThresholdImageView.h | 32 +-- 4 files changed, 278 insertions(+), 207 deletions(-) create mode 100644 lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx create mode 100644 lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx new file mode 100644 index 0000000..a4946f0 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx @@ -0,0 +1,179 @@ + +/** + * \file + * \brief Class bbtk::ThresholdImageView . + */ + +#include "LayerImageBase.h" + +LayerImageBase::LayerImageBase() +{ + _actorPresent = false; + _Z = 0; + _thresholdTable = NULL; + _thresholdMapper = NULL; + _thresholdActor = NULL; + _image = NULL; + _imageReslicer = vtkImageReslice::New(); + +} + +//---------------------------------------------------------------------------- + LayerImageBase::~LayerImageBase() + { + } + +//---------------------------------------------------------------------------- +void LayerImageBase::SetZ(int z) +{ + _Z = z; +} + +//---------------------------------------------------------------------------- +int LayerImageBase::GetZ() +{ + return _Z; +} + +//---------------------------------------------------------------------------- +vtkImageData* LayerImageBase::GetImage() +{ + return _image; +} + +//---------------------------------------------------------------------------- +bool LayerImageBase::GetActorPresent() +{ + return _actorPresent; +} + + + +//---------------------------------------------------------------------------- +void LayerImageBase::SetImage(vtkImageData* image) +{ + _image = image; +} + +//---------------------------------------------------------------------------- +void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview) +{ + _baseView = baseview; +} + +//---------------------------------------------------------------------------- +wxVtkBaseView *LayerImageBase::GetwxVtkBaseView() +{ + return _baseView; +} + + + +//---------------------------------------------------------------------------- +vtkLookupTable* LayerImageBase::GetThresholdTable() +{ + return _thresholdTable; +} + + + +//---------------------------------------------------------------------------- +void LayerImageBase::onThreshold() +{ + int z = GetZ(); + + if (!GetActorPresent()) + { + if (_thresholdTable==NULL) + { + //Lookup Table + _thresholdTable = vtkLookupTable::New(); + } // _thresholdTable + + if (_thresholdMapper==NULL) + { + _thresholdMapper = vtkImageMapToColors::New( ); + } + + if (_thresholdActor==NULL) + { + _thresholdActor = vtkImageActor::New( ); + _thresholdActor->SetOpacity( 0.6 ); + _thresholdActor->InterpolateOn( ); + _thresholdActor->SetPosition( 0,0, 900-1 ); + } // _thresholdActor + + + _baseView->GetRenderer()->AddActor( _thresholdActor ); + _actorPresent = true; + } // !GetActorPresent() + + ConfigLookupTable(); // virtual method + _imageReslicer->SetInput( GetImage() ); + _imageReslicer->SetInformationInput( GetImage() ); + _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1); + _imageReslicer->SetOutputDimensionality(2); + _imageReslicer->SetInterpolationModeToLinear(); + _imageReslicer->SetResliceAxesOrigin(0,0,z); + + vtkImageData *img = _imageReslicer->GetOutput(); + img->Update(); + img->UpdateInformation(); + + _thresholdMapper->SetInput( img ); + _thresholdMapper->SetLookupTable( _thresholdTable ); + _thresholdActor->SetInput( _thresholdMapper->GetOutput() ); +} + + + +//---------------------------------------------------------------------------- +void LayerImageBase::onThresholdChange() +{ + if (_actorPresent) + { + onThreshold(); + } +} + +//---------------------------------------------------------------------------- +void LayerImageBase::onThresholdInterpolation(bool interpolate) +{ + if (_thresholdActor!=NULL) + { + if (interpolate) + { + _thresholdActor->InterpolateOn( ); + } + else + { + _thresholdActor->InterpolateOff( ); + } + } +} + +//---------------------------------------------------------------------------- +void LayerImageBase::onThresholdChangeOpacity (int opacity) +{ + if (_actorPresent) + { + _thresholdActor->SetOpacity(opacity*0.1); + } +} + +//---------------------------------------------------------------------------- +void LayerImageBase::onThresholdRemove() +{ + if (_actorPresent) + { + wxVtkBaseView * baseView = _baseView; + baseView->GetRenderer()->RemoveActor( _thresholdActor ); + _actorPresent = false; + } +} + + + + +// EOF + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h new file mode 100644 index 0000000..0af0e62 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h @@ -0,0 +1,62 @@ + + + +/** + * \file + * \brief Class ThresholdImageView . + */ + +/** + * \class ThresholdImageView + * \brief + */ + +#ifndef __LayerImageBase_h__ +#define __LayerImageBase_h__ + +#include +#include +#include +#include +#include +#include "wxVtkBaseView.h" + +class LayerImageBase + { + public: + LayerImageBase(); + ~LayerImageBase(); + void SetZ(int z); + void SetImage(vtkImageData* image); + void SetwxVtkBaseView(wxVtkBaseView *baseview); + + void onThreshold(); + void onThresholdChange(); + void onThresholdInterpolation(bool interpolate); + void onThresholdChangeOpacity (int opacity); + void onThresholdRemove(); + wxVtkBaseView *GetwxVtkBaseView(); + + private: + int _Z; + bool _actorPresent; + vtkImageData *_image; + vtkImageReslice *_imageReslicer; + vtkLookupTable *_thresholdTable; + vtkImageMapToColors *_thresholdMapper; + vtkImageActor *_thresholdActor; + wxVtkBaseView *_baseView; + + virtual void ConfigLookupTable() = 0; + int GetZ(); + bool GetActorPresent(); + + protected: + vtkLookupTable* GetThresholdTable(); + vtkImageData* GetImage(); + }; + + + +#endif // __LayerImageBase_h__ + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx index 4f4e5b5..7907cdf 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx @@ -5,19 +5,19 @@ */ #include "ThresholdImageView.h" +#include +#include +#include + + //========================================================================= + //========================================================================= + //========================================================================= //========================================================================= ThresholdImageView::ThresholdImageView( ) { - _actorPresent = false; - _Z = 0; _minValue = 0; _maxValue = 1000; - _image = NULL; - _imageReslicer = NULL; - _thresholdTable = NULL; - _thresholdMapper = NULL; - _thresholdActor = NULL; _baseColorR = 1; _baseColorG = 0; _baseColorB = 0; @@ -30,29 +30,6 @@ //========================================================================= -//---------------------------------------------------------------------------- -void ThresholdImageView::SetImage(vtkImageData* image) -{ - _image = image; -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview) -{ - _baseView = baseview; -} - -//---------------------------------------------------------------------------- -wxVtkBaseView *ThresholdImageView::GetwxVtkBaseView() -{ - return _baseView; -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::SetZ(int z) -{ - _Z = z; -} //---------------------------------------------------------------------------- void ThresholdImageView::SetminMaxValue(int min, int max) @@ -61,14 +38,13 @@ void ThresholdImageView::SetminMaxValue(int min, int max) _maxValue = max; } + //---------------------------------------------------------------------------- -void ThresholdImageView::onThreshold() +void ThresholdImageView::ConfigLookupTable() // virtual { - int z = _Z; double range[2]; - vtkImageData *img = _image; - img->GetScalarRange(range); + GetImage()->GetScalarRange(range); if (range[1]==0) { range[1]=255; @@ -79,162 +55,38 @@ void ThresholdImageView::onThreshold() int minVal = floor (_minValue); int maxVal = floor (_maxValue); - - if (!_actorPresent) + + vtkLookupTable* thresholdTable = GetThresholdTable(); + thresholdTable->SetNumberOfTableValues(maxTot+1); + thresholdTable->SetTableRange(range); + thresholdTable->SetAlphaRange(0, 1); + thresholdTable->SetValueRange(0, 1); + thresholdTable->SetSaturationRange(0, 0); + thresholdTable->SetRampToLinear( ); + + //Assign a fake color for the upper image, and set the white as transparent + int i; + for(i = minTot; i <= maxTot; i++) { - if (_imageReslicer==NULL) + if( i >= minVal && i <= maxVal ) { - _imageReslicer = vtkImageReslice::New(); - _imageReslicer->SetInput( img ); - _imageReslicer->SetInformationInput(img); - _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1); - _imageReslicer->SetOutputDimensionality(2); - _imageReslicer->SetInterpolationModeToLinear(); + thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1); } - - _imageReslicer->SetResliceAxesOrigin(0,0,z); - - img = _imageReslicer->GetOutput(); - img->Update(); - img->UpdateInformation(); - - wxVtkBaseView *baseView = _baseView; - - if (_thresholdTable==NULL) + else if( i >= minTot && i < minVal ) { - //Lookup Table - _thresholdTable = vtkLookupTable::New(); - _thresholdTable->SetNumberOfTableValues(maxTot+1); - _thresholdTable->SetTableRange(range); - _thresholdTable->SetAlphaRange(0, 1); - _thresholdTable->SetValueRange(0, 1); - _thresholdTable->SetSaturationRange(0, 0); - _thresholdTable->SetRampToLinear( ); + thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent } - - //Assign a fake color for the upper image, and set the white as transparent - int i; - for(i = minTot; i <= maxTot; i++) + else if( i > maxVal && i < maxTot ) { - if( i >= minVal && i <= maxVal ) - { - _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1); - } - else if( i >= minTot && i < minVal ) - { - _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent - } - else if( i > maxVal && i < maxTot ) - { - _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent - } - else - { - _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent - } - } - _thresholdTable->Build( ); - - if (_thresholdMapper==NULL) - { - _thresholdMapper = vtkImageMapToColors::New( ); - } - - _thresholdMapper->SetLookupTable( _thresholdTable ); - _thresholdMapper->SetInput( img ); - - if (_thresholdActor==NULL) - { - _thresholdActor = vtkImageActor::New( ); - _thresholdActor->SetOpacity( 0.6 ); - _thresholdActor->InterpolateOn( ); - _thresholdActor->SetPosition( 0,0, 900-1 ); - } - - _thresholdActor->SetInput( _thresholdMapper->GetOutput() ); - - baseView->GetRenderer()->AddActor( _thresholdActor ); - _actorPresent = true; - } - else - { - _imageReslicer->SetResliceAxesOrigin(0,0,z); - img = _imageReslicer->GetOutput(); - img->Update(); - img->UpdateInformation(); - - //Assign a fake color for the upper image, and set the white as transparent - int i; - for(i = minTot; i <= maxTot; i++) - { - if( i >= minVal && i <= maxVal ) - { - _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1); - } - else if( i >= minTot && i < minVal ) - { - _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent - } - else if( i > maxVal && i < maxTot ) - { - _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent - } - else - { - _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent - } - } - _thresholdTable->Build( ); - _thresholdMapper->SetLookupTable( _thresholdTable ); - _thresholdMapper->SetInput( img ); - _thresholdActor->SetInput( _thresholdMapper->GetOutput() ); - } -} - - -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdChange() -{ - if (_actorPresent) - { - onThreshold(); - } -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdInterpolation(bool interpolate) -{ - if (_thresholdActor!=NULL) - { - if (interpolate) - { - _thresholdActor->InterpolateOn( ); + thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent } else { - _thresholdActor->InterpolateOff( ); - } - } -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdChangeOpacity (int opacity) -{ - if (_actorPresent) - { - _thresholdActor->SetOpacity(opacity*0.1); - } -} + thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent + } + } // for + thresholdTable->Build( ); -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdRemove() -{ - if (_actorPresent) - { - wxVtkBaseView * baseView = _baseView; - baseView->GetRenderer()->RemoveActor( _thresholdActor ); - _actorPresent = false; - } } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.h index 5ca77b5..5a006d5 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.h @@ -14,48 +14,26 @@ #ifndef __ThresholdImageView_h__ #define __ThresholdImageView_h__ -#include -#include -#include -#include -#include -#include "wxVtkBaseView.h" +#include "LayerImageBase.h" - -class ThresholdImageView +class ThresholdImageView : public LayerImageBase { public: ThresholdImageView( ); ~ThresholdImageView(); - void onThreshold(); - void onThresholdChange(); - void onThresholdInterpolation(bool interpolate); - void onThresholdChangeOpacity (int opacity); - void onThresholdRemove(); - - void SetImage(vtkImageData* image); - void SetwxVtkBaseView(wxVtkBaseView *baseview); - wxVtkBaseView *GetwxVtkBaseView(); void SetBaseColor(double r, double g, double b); - - void SetZ(int z); void SetminMaxValue(int min, int max); private: - int _Z; double _baseColorR; double _baseColorG; double _baseColorB; double _minValue; double _maxValue; - bool _actorPresent; - vtkImageData *_image; - vtkImageReslice *_imageReslicer; - vtkLookupTable *_thresholdTable; - vtkImageMapToColors *_thresholdMapper; - vtkImageActor *_thresholdActor; - wxVtkBaseView *_baseView; + + virtual void ConfigLookupTable(); + protected: }; -- 2.45.1