]> Creatis software - creaMaracasVisu.git/commitdiff
#2719 creaMaracasVisu Bug New Normal - Color Layer not Refresh correctly with new...
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Wed, 21 Oct 2015 13:54:31 +0000 (15:54 +0200)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Wed, 21 Oct 2015 13:54:31 +0000 (15:54 +0200)
lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewManager.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h

index e01c2f3945ac7ec857b145ca9393e8bce48620da..1f66131a66e8263cea5772564875569df9136b97 100644 (file)
@@ -134,11 +134,14 @@ int ColorLayerImageView::GetZ() // virtual
 void ColorLayerImageView::SetBaseColors(std::vector<double> & 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 ( minRange<GetGreyLevelBoundaries(0) )
          {
-                       start = 0;      
+                       start   = 0;    
                        end     = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(0) );  
                        FillColorTable(start,end, 0,0,0, 0,0,0, 0,0);
      }
 
      if ( maxRange>GetGreyLevelBoundaries(  _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);
index 86ceb68b2a00a2367a7ec967a760565609e45073..eef06161e20d27f7da595bb953b58bfec5eecd22 100644 (file)
@@ -109,7 +109,7 @@ class  ColorLayerImageView : public LayerImageBase
          void  SetDefaultGreyLevelBoundary();
          void  SetDefaultBaseColorAndGreyLevelBoundary();
          virtual void ConfigLookupTable();
-     int       maxColorsThresholdTable;
+         int   maxColorsThresholdTable;
 
 
 
index 92a8aad1bb2ec778688a296c4a41d1286126764a..b00693026f57b2d393679faae249e8924a81535e 100644 (file)
@@ -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<double> & base_color);
-         double GetBaseColors(unsigned int index);
-         void SetGreyLevelBoundaries(std::vector<double> & grey_level_boundary);
-         void SetBaseTransparence(std::vector<double> & base_transparence);
-         void SetRangeForColorBar(std::vector<double> & 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<double> & base_color);
+         double        GetBaseColors(unsigned int index);
+         void          SetGreyLevelBoundaries(std::vector<double> & grey_level_boundary);
+         void          SetBaseTransparence(std::vector<double> & base_transparence);
+         void          SetRangeForColorBar(std::vector<double> & 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;
index f7d28feb9559e31fc364fc435bea5e149ac6de58..925dc8f84157ab708b9b93d0fb7de3255b327952 100644 (file)
@@ -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<double> &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
index 7735f0a598e8b88ea9c792c1ae19dd950cfcc9ae..f9989b0176ba4f8a258f797d898f7e08b45fa3cd 100644 (file)
@@ -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: