From d40f88aeb2e3bf3619875d913eb876a6c82e6009 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Wed, 21 Oct 2015 15:54:31 +0200 Subject: [PATCH] #2719 creaMaracasVisu Bug New Normal - Color Layer not Refresh correctly with new image --- .../ColorLayerImageView.cxx | 62 +++++++++++-------- .../ThresholdImageView/ColorLayerImageView.h | 2 +- .../ColorLayerImageViewManager.h | 34 +++++----- .../ThresholdImageView/LayerImageBase.cxx | 29 ++++++--- .../ThresholdImageView/LayerImageBase.h | 9 +-- 5 files changed, 80 insertions(+), 56 deletions(-) diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx index e01c2f3..1f66131 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx @@ -134,11 +134,14 @@ int ColorLayerImageView::GetZ() // virtual void ColorLayerImageView::SetBaseColors(std::vector & base_color) { // The base color vector must be of a size multiple of 3, not null. - if (base_color.size() != 0 && base_color.size() % 3 == 0) - _base_color = base_color; - // Otherwise, an exception should be thrown. - else if (base_color.size() != 0) - std::cout << "CM ColorLayerImageView::SetBaseColors : ERROR!!! The base color vector has an inconsistent size. It must be of a size multiple of 3, different from 0, but its size is: "<< base_color.size() << ". Therefore, the default values will be used as base colors." << std::endl; +//EED if ((base_color.size() != 0) && (base_color.size() % 3 == 0)) + if ( base_color.size() % 3 == 0) + { + _base_color = base_color; + } else if (base_color.size() != 0) // Otherwise, an exception should be thrown. + { + std::cout << "CM ColorLayerImageView::SetBaseColors : ERROR!!! The base color vector has an inconsistent size. It must be of a size multiple of 3, different from 0, but its size is: "<< base_color.size() << ". Therefore, the default values will be used as base colors." << std::endl; + } } @@ -215,9 +218,9 @@ void ColorLayerImageView::SetDefaultGreyLevelBoundary() int i; double delta; - // Grey level extrema are set by default to the image grey level extrema. - double minTot = _range[0]; - double maxTot = _range[1]; + // Grey level extrema are set by default to the image grey level extrema. + double minTot = _range[0]; + double maxTot = _range[1]; if (_color_type) { @@ -299,11 +302,11 @@ void ColorLayerImageView::SetDefaultBaseColorAndGreyLevelBoundary() void ColorLayerImageView::ConfigLookupTable() // virtual { // CM 2014 - // EED 28/01/2015 - + // EED 28/01/2015 // Grey level extrema retrieved from the image grey level extrema. - - GetImage()->GetScalarRange(_range); +//EED 20 oct 2015 +// GetImage()->GetScalarRange(_range); + GetImageScalarRange(); double minRange = _range[0]; double maxRange = _range[1]; @@ -332,6 +335,7 @@ void ColorLayerImageView::ConfigLookupTable() // virtual // ------------------ Defining the Threshold Table vtkLookupTable* thresholdTable = GetThresholdTable(); + double thresholdTable_range[2]; double r1,r2,g1,g2,b1,b2,t1,t2; int start,end; @@ -340,6 +344,9 @@ void ColorLayerImageView::ConfigLookupTable() // virtual thresholdTable_range[1]= std::max( GetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) , ceil(maxRange) ); thresholdTable_range[0]= std::min( GetGreyLevelBoundaries(0), floor(minRange) ); + thresholdTable_range[1]= GetGreyLevelBoundaries( _grey_level_boundary.size()-1 ); + thresholdTable_range[0]= GetGreyLevelBoundaries(0); + thresholdTable->SetTableRange(thresholdTable_range); thresholdTable->SetAlphaRange( 0,1 ); thresholdTable->SetValueRange( 0,1 ); @@ -349,6 +356,7 @@ void ColorLayerImageView::ConfigLookupTable() // virtual maxColorsThresholdTable = 1000; thresholdTable->SetNumberOfTableValues( maxColorsThresholdTable ); + thresholdTable->SetNanColor(0,0,0,0); // Defines the lookup table. @@ -361,14 +369,14 @@ void ColorLayerImageView::ConfigLookupTable() // virtual { if ( minRangeGetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) ) { - start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) ); + start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) ); end = GrayLevel_TO_colorTableIndex( maxRange ); FillColorTable(start,end, 0,0,0, 0,0,0, 0,0); } @@ -377,9 +385,9 @@ void ColorLayerImageView::ConfigLookupTable() // virtual r1 = GetBaseColors(iColor*3+0); g1 = GetBaseColors(iColor*3+1); b1 = GetBaseColors(iColor*3+2); - start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) ); + start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) ); end = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor+1) ); - t1 = _transparence_level_boundary[iColor]; + t1 = _transparence_level_boundary[iColor]; // t2 = _transparence_level_boundary[iColor+1]; FillColorTable(start,end, r1,g1,b1,r1,g1,b1,t1,t1); } // for i @@ -394,9 +402,9 @@ void ColorLayerImageView::ConfigLookupTable() // virtual r2 = GetBaseColors( (iColor+1)*3+0); g2 = GetBaseColors( (iColor+1)*3+1); b2 = GetBaseColors( (iColor+1)*3+2); - start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) ); + start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) ); end = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor+1) ); - t1 = _transparence_level_boundary[iColor]; + t1 = _transparence_level_boundary[iColor]; t2 = _transparence_level_boundary[iColor+1]; FillColorTable( start,end, r1,g1,b1, r2,g2,b2, t1,t2 ); }// for @@ -421,7 +429,11 @@ void ColorLayerImageView::ConfigLookupTable() // virtual int ColorLayerImageView::GrayLevel_TO_colorTableIndex( double VALUE ) { GetImage()->Update(); - GetImage()->GetScalarRange(_range); + +//EED 20 oct 2015 +// GetImage()->GetScalarRange(_range); + GetImageScalarRange(); + double minRange = _range[0]; double maxRange = _range[1]; return maxColorsThresholdTable * (VALUE-minRange) / (maxRange-minRange); @@ -431,12 +443,12 @@ int ColorLayerImageView::GrayLevel_TO_colorTableIndex( double VALUE ) void ColorLayerImageView::FillColorTable(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2, double t1, double t2) { vtkLookupTable* thresholdTable = GetThresholdTable(); - int iTable; - double delta = end-start; - double dr = (r2-r1)/delta; - double dg = (g2-g1)/delta; - double db = (b2-b1)/delta; - double dt = (t2-t1)/delta; + int iTable; + double delta = end-start; + double dr = (r2-r1)/delta; + double dg = (g2-g1)/delta; + double db = (b2-b1)/delta; + double dt = (t2-t1)/delta; for (iTable=0; iTable<=delta; iTable++) { thresholdTable->SetTableValue( iTable+start , r1+dr*iTable, g1+dg*iTable, b1+db*iTable,t1+dt*iTable); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h index 86ceb68..eef0616 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h @@ -109,7 +109,7 @@ class ColorLayerImageView : public LayerImageBase void SetDefaultGreyLevelBoundary(); void SetDefaultBaseColorAndGreyLevelBoundary(); virtual void ConfigLookupTable(); - int maxColorsThresholdTable; + int maxColorsThresholdTable; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewManager.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewManager.h index 92a8aad..b006930 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewManager.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewManager.h @@ -50,23 +50,23 @@ class ColorLayerImageViewManager virtual int GetX(); virtual int GetY(); virtual int GetZ(); - void SetwxVtkBaseView(int id, wxVtkBaseView *baseview); - void SetBaseColors(std::vector & base_color); - double GetBaseColors(unsigned int index); - void SetGreyLevelBoundaries(std::vector & grey_level_boundary); - void SetBaseTransparence(std::vector & base_transparence); - void SetRangeForColorBar(std::vector & range); - double GetGreyLevelBoundaries(unsigned int index); - void SetPlainOrGradientColor(bool color_type); - int GetBaseColorNb(); - void Refresh(); - void onThreshold(); - void onThresholdRemove(); - void onThresholdChange(); - void onThresholdInterpolation(bool interpolation); - void SetSliceFixDynamic( bool fixdin ); - void onThresholdChangeOpacity( int opacity); - void SetImage( vtkImageData* img ); + void SetwxVtkBaseView(int id, wxVtkBaseView *baseview); + void SetBaseColors(std::vector & base_color); + double GetBaseColors(unsigned int index); + void SetGreyLevelBoundaries(std::vector & grey_level_boundary); + void SetBaseTransparence(std::vector & base_transparence); + void SetRangeForColorBar(std::vector & range); + double GetGreyLevelBoundaries(unsigned int index); + void SetPlainOrGradientColor(bool color_type); + int GetBaseColorNb(); + void Refresh(); + void onThreshold(); + void onThresholdRemove(); + void onThresholdChange(); + void onThresholdInterpolation( bool interpolation ); + void SetSliceFixDynamic( bool fixdin ); + void onThresholdChangeOpacity( int opacity ); + void SetImage( vtkImageData* img ); private: std::vector< ColorLayerImageView* > _colorLayerImageViewLst; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx index f7d28fe..925dc8f 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx @@ -93,17 +93,17 @@ private: LayerImageBase::LayerImageBase() { - _actorPresent = false; - _X = 0; - _Y = 0; - _Z = 0; + _actorPresent = false; + _X = 0; + _Y = 0; + _Z = 0; _thresholdTable = NULL; - _thresholdMapper = NULL; + _thresholdMapper = NULL; _scalarbarActor = NULL; _thresholdActor = NULL; - _image = NULL; - _baseView = NULL; - _imageReslicer = vtkImageReslice::New(); + _image = NULL; + _baseView = NULL; + _imageReslicer = vtkImageReslice::New(); } //---------------------------------------------------------------------------- @@ -179,7 +179,8 @@ void LayerImageBase::SetImage(vtkImageData* image) SetY( ssy ); SetZ( ssz ); _image->Update(); - _image->GetScalarRange( _range ); + _image->GetScalarRange( _range ); + _thresholdTable = vtkLookupTable::New(); } void LayerImageBase::SetRangeForColorBar(std::vector &range) @@ -448,6 +449,16 @@ vtkImageReslice *LayerImageBase::GetvtkImageReslice() return _imageReslicer; } +//---------------------------------------------------------------------------- +void LayerImageBase::GetImageScalarRange() +{ + double min,max; + GetRangeForColorBar(min,max); +// _image->GetScalarRange(_range); + _range[0]=min; + _range[1]=max; +} + // EOF diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h index 7735f0a..f9989b0 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h @@ -104,24 +104,25 @@ class LayerImageBase virtual int GetY(); virtual int GetZ(); bool GetActorPresent(); + void GetImageScalarRange(); private: int _X; int _Y; int _Z; - bool _actorPresent; + bool _actorPresent; vtkImageData *_image; - vtkImageReslice *_imageReslicer; + vtkImageReslice *_imageReslicer; vtkLookupTable *_thresholdTable; - vtkImageMapToColors *_thresholdMapper; + vtkImageMapToColors *_thresholdMapper; vtkImageActor *_thresholdActor; wxVtkBaseView *_baseView; vtkScalarBarActor *_scalarbarActor; virtual void ConfigLookupTable() = 0; - void CleanXYZ(double &x, double &y, double &z); + void CleanXYZ(double &x, double &y, double &z); protected: -- 2.45.1