]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
#2520 creaMaracasVisu - Bug New Normal - Color Layer with double images
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ColorLayerImageView.cxx
index 50cafdd9fcf780b2d383b938e398f46619a77450..6a6e3ad003e49cb68561152f202056296a13b51c 100644 (file)
@@ -82,8 +82,6 @@ void ColorLayerImageView::SetZ2(int z2)
   _z2 = z2;
 }
 
-
-
 //----------------------------------------------------------------------------
 int ColorLayerImageView::GetX() // virtual 
 {
@@ -280,7 +278,7 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
                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() != (_grey_level_boundary.size() - 1) )
+      if (GetBaseColorNb() != ((int)_grey_level_boundary.size() - 1) )
       {
                        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;
                        std::cout << "CM The default values for the base colors and the grey level boundaries will be set." << std::endl;
@@ -306,7 +304,8 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
   thresholdTable->SetSaturationRange(0, 0); 
   thresholdTable->SetRampToLinear( );
 
-  thresholdTable->SetNumberOfTableValues(1000);
+  maxColorsThresholdTable = 1000;
+  thresholdTable->SetNumberOfTableValues( maxColorsThresholdTable );
 
 
   // Defines the lookup table.
@@ -317,47 +316,29 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
   // Sets the plain color for each grey level interval.
   if (_color_type)
   {
-//     thresholdTable->SetNumberOfTableValues(thresholdTable_range[1] - thresholdTable_range[0] + 1);
 
      if ( minRange<GetGreyLevelBoundaries(0) )
          {
                        start = 0;      
-                       end     = 1000*(GetGreyLevelBoundaries(0)-minRange) / (maxRange-minRange);
+                       end     = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(0) );  
                        FillColorTable(start,end, 0,0,0, 0,0,0);
      }
 
      if ( maxRange>GetGreyLevelBoundaries(  _grey_level_boundary.size()-1   ) )
          {
-                       start = 1000*(GetGreyLevelBoundaries(  _grey_level_boundary.size()-1  )-minRange) / (maxRange-minRange);;       
-                       end     = 1000*(maxRange-minRange) / (maxRange-minRange);
+                       start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) );  
+                       end     = GrayLevel_TO_colorTableIndex( maxRange );  
                        FillColorTable(start,end, 0,0,0, 0,0,0);
      }
 
-               int delta;      
       for (int iColor = 0; iColor < GetBaseColorNb(); iColor++)
                {
-
-                       start = 1000*(GetGreyLevelBoundaries(iColor)-minRange) / (maxRange-minRange);   
-                       end     = 1000*(GetGreyLevelBoundaries(iColor+1)-minRange) / (maxRange-minRange);
-
                        r1              = GetBaseColors(iColor*3+0);
                        g1              = GetBaseColors(iColor*3+1);
                        b1              = GetBaseColors(iColor*3+2);
-
+                       start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) );  
+                       end     = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor+1) );  
                        FillColorTable(start,end, r1,g1,b1,r1,g1,b1);
-
-/*
-                       delta = GetGreyLevelBoundaries(i+1) - GetGreyLevelBoundaries(i);
-                       for (int ii = 1; ii <= delta; ii++)
-               {
-               thresholdTable->SetTableValue(GetGreyLevelBoundaries(i) + ii,
-                                           GetBaseColors(i*3), 
-                                           GetBaseColors(i*3 + 1),
-                                           GetBaseColors(i*3 + 2),
-                                           1);
-               } // for ii
-*/
-
                } // for i
        } // End Of if (_color_type)
 
@@ -365,7 +346,6 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
   else
   {
 //EED 28/01/2015
-          thresholdTable->SetNumberOfTableValues(1000);
       if (GetBaseColorNb() > 1)
                {
                        for (int iColor = 0; iColor < GetBaseColorNb(); iColor++)
@@ -384,31 +364,46 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
                                r2              = GetBaseColors(iColor*3+0);
                                g2              = GetBaseColors(iColor*3+1);
                                b2              = GetBaseColors(iColor*3+2);
-                               start = 1000*(GetGreyLevelBoundaries(iColor)-minRange) / (maxRange-minRange);   
-                               end     = 1000*(GetGreyLevelBoundaries(iColor+1)-minRange) / (maxRange-minRange);
-                               FillColorTable(start,end, r1,g1,b1,r2,g2,b2);
+                               start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) );  
+                               end     = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor+1) );  
+                               FillColorTable( start,end, r1,g1,b1, r2,g2,b2 );
                        }// for 
                } //if                          
   } //  End Of if (!_color_type)
 
+  thresholdTable->SetRange( minRange, maxRange );
+  thresholdTable->SetValueRange( 0.0, 1.0 );
+
   thresholdTable->Build( );
 
   //EO CM EED
 }
 
+//----------------------------------------------------------------------------
+int ColorLayerImageView::GrayLevel_TO_colorTableIndex( double VALUE )
+{
+  GetImage()->GetScalarRange(_range);
+  double minRange = _range[0];
+  double maxRange = _range[1];
+  return  maxColorsThresholdTable * (VALUE-minRange) / (maxRange-minRange);    
+}
 
+//----------------------------------------------------------------------------
 void ColorLayerImageView::FillColorTable(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2)
 {
    vtkLookupTable* thresholdTable = GetThresholdTable();
-       int             iTable;
-       double  delta = end-start;
-       double dr = (r2-r1)/delta;
-       double dg = (g2-g1)/delta;
-       double db = (b2-b1)/delta;
+       int      iTable;
+       double delta    = end-start;
+       double dr               = (r2-r1)/delta;
+       double dg               = (g2-g1)/delta;
+       double db               = (b2-b1)/delta;
        for (iTable=0; iTable<=delta; iTable++)
        {
                thresholdTable->SetTableValue(  iTable+start , r1+dr*iTable, g1+dg*iTable, b1+db*iTable,1);
        } // for iTable
+
+       if (start==0) thresholdTable->SetTableValue(  start , r1, g1, b1,0);   // The first color in the table is transparent
+
 }
 
 // EOF