]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
#2651 creaMaracasVisu Feature New Normal - Color Layer: Transparent Base, Refresh
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ColorLayerImageView.cxx
index e01c2f3945ac7ec857b145ca9393e8bce48620da..ddfb35e0e5abea9a92dd27938426a30c363a7cbe 100644 (file)
@@ -45,7 +45,7 @@
 //=========================================================================
 ColorLayerImageView::ColorLayerImageView( )
 {
-  _z2                                  =       0;
+  _z2                          =       0;
   _fix_dynamic         =       true;
   _color_type          =       false;
 }
@@ -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;
+       }
 }
 
 
@@ -204,20 +207,21 @@ int ColorLayerImageView::GetBaseColorNb()
 //----------------------------------------------------------------------------
 void ColorLayerImageView::SetDefaultGreyLevelBoundary()
 {
-  // CM Sets the default behaviour concerning the lookup table keeping the base colors already set.
-  _grey_level_boundary.clear();
 
-  // This avoids a potential division by 0 through delta during the lookup table configuration.
-  if (_range[1]==0)
-    {
-      _range[1]=255;
+       // CM Sets the default behaviour concerning the lookup table keeping the base colors already set.
+       _grey_level_boundary.clear();
+
+       // This avoids a potential division by 0 through delta during the lookup table configuration.
+       if (_range[1]==0)
+       {
+               _range[1]=255;
     }
          
        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)
        {
@@ -234,12 +238,12 @@ void ColorLayerImageView::SetDefaultGreyLevelBoundary()
                        _grey_level_boundary.push_back(minTot + i * delta);
                } // for                
        } // if  
-
 }
 
 //----------------------------------------------------------------------------
 void ColorLayerImageView::SetDefaultBaseColorAndGreyLevelBoundary()
 {
+
   // CM Sets the default behaviour concerning the lookup table.
   _grey_level_boundary.clear();
   _base_color.clear();
@@ -299,25 +303,24 @@ 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];
 
   // ------------------ Setting Default Values
   // Checks the size consistency of vectors _base_color and _grey_level_boundary.
   // In case of inconsistency, an exception should be thrown. Instead, the default values are set.
-  if (GetBaseColorNb() == 0)
+       if (GetBaseColorNb() == 0)
        {
                SetDefaultBaseColorAndGreyLevelBoundary();
-       }
-   else {  // If at least one color has been set, set the grey level boundaries to build an equipartition of the image grey levels, keeping the base colors defined.
-      if (GetBaseColorNb() != (int)_grey_level_boundary.size() )
-      {
-                       std::cout << "CM ColorLayerImageView::ConfigLookupTable : ERROR!!! Inconsistency between the sizes of vectors _base_color and _grey_level_boundary. _base_color.size()/3 (=" <<_base_color.size()/3 << ") should be equal to _grey_level_boundary.size() - 1 (=" << _grey_level_boundary.size() - 1 << ")." << std::endl;
+       } else {  // If at least one color has been set, set the grey level boundaries to build an equipartition of the image grey levels, keeping the base colors defined.
+       if (GetBaseColorNb() != (int)_grey_level_boundary.size() )
+       {
+               std::cout << "CM ColorLayerImageView::ConfigLookupTable : ERROR!!! Inconsistency between the sizes of vectors _base_color and _grey_level_boundary. _base_color.size()/3 (=" <<_base_color.size()/3 << ") should be equal to _grey_level_boundary.size() (=" << _grey_level_boundary.size() << ")." << std::endl;
                        std::cout << "CM The default values for the base colors and the grey level boundaries will be set." << std::endl;
                        SetDefaultGreyLevelBoundary();     
       }
@@ -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 );
@@ -348,7 +355,8 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
   thresholdTable->SetRampToLinear( );
 
   maxColorsThresholdTable = 1000;
-  thresholdTable->SetNumberOfTableValues( maxColorsThresholdTable );
+  thresholdTable->SetNumberOfTableValues( maxColorsThresholdTable+1 );
+  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);