]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
#2855 creaMaracasVisu Bug New Normal - ColorLayer box spacing size not identified
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ColorLayerImageView.cxx
index e01c2f3945ac7ec857b145ca9393e8bce48620da..38f25f35139a03833313d5b32021c68a0c48e0b6 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;
+       }
 }
 
 
@@ -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);