Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / PIPELINE / VISU_LookupTable.cxx
index 06f21c5a526bc4d7d1f9ee72681297388d3f11b2..c15fdd27c4b9208735b23f3bd3573f99cd97776b 100644 (file)
@@ -40,7 +40,26 @@ VISU_LookupTable *VISU_LookupTable::New() {
 }
 
 VISU_LookupTable::VISU_LookupTable(int sze, int ext)
-  : vtkLookupTable(sze, ext), myScale(1.0) {}
+  : vtkLookupTable(sze, ext), myScale(1.0), myBicolor(false) {}
+
+void VISU_LookupTable::SetMapScale(float theScale)
+{
+  if( myScale != theScale )
+  {
+    myScale = theScale;
+    Modified();
+  }
+}
+
+void VISU_LookupTable::SetBicolor( bool theBicolor )
+{
+  if( myBicolor != theBicolor )
+  {
+    myBicolor = theBicolor;
+    Modified();
+  }
+}
+
 
 int VISU_LookupTable::ComputeLogRange(float inRange[2], float outRange[2]){
   if(inRange[0] >= inRange[1])
@@ -65,9 +84,13 @@ unsigned char* VISU_LookupTable::MapValue(float v) {
     float aLowBound = log10(this->TableRange[0]);
     v = pow(10.0f,aLowBound + (v - aLowBound)*myScale);
     return vtkLookupTable::MapValue(v);
-  }else{
+  } else if (!myBicolor) {
     v = this->TableRange[0] + (v - this->TableRange[0])*myScale;
     return vtkLookupTable::MapValue(v);
+  } else {
+    unsigned char* table = this->Table->GetPointer(0);
+    int index = v > 0 ? 4*static_cast<int>(this->GetNumberOfColors()-1) : 0;
+    return &table[index];
   }
 }
 
@@ -113,29 +136,35 @@ inline float VISU_ApplyLogScale(float v, float range[2],
 inline unsigned char *VISU_LinearLookup(float v,   
                                        unsigned char *table,
                                        float maxIndex,
-                                       float shift, float scale)
+                                       float shift, float scale,
+                                       bool bicolor)
 {
-  float findx = (v + shift)*scale;
-  if (findx < 0)
-    {
-    findx = 0;
-    }
-  if (findx > maxIndex)
-    {
-    findx = maxIndex;
-    }
-  return &table[4*static_cast<int>(findx)];
-  /* round
-  return &table[4*(int)(findx + 0.5f)];
-  */
+  if( !bicolor )
+  {
+    float findx = (v + shift)*scale;
+    if (findx < 0)
+      findx = 0;
+    if (findx > maxIndex)
+      findx = maxIndex;
+
+    return &table[4*static_cast<int>(findx)];
+    // round
+    //return &table[4*(int)(findx + 0.5f)];
+  }
+  else
+  {
+    int index = v > 0 ? 4*static_cast<int>(maxIndex) : 0;
+    return &table[index];
+  }
 }
 
 // accelerate the mapping by copying the data in 32-bit chunks instead
 // of 8-bit chunks
 template<class T>
 void VISU_LookupTableMapData(vtkLookupTable *self, T *input, 
-                           unsigned char *output, int length, 
-                           int inIncr, int outFormat, float theMapScale)
+                            unsigned char *output, int length, 
+                            int inIncr, int outFormat,
+                            float theMapScale, bool bicolor)
 {
   int i = length;
   float *range = self->GetTableRange();
@@ -169,7 +198,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -182,7 +211,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -194,7 +223,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           *output++ = cptr[3];
@@ -206,7 +235,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           input += inIncr;
@@ -233,7 +262,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -245,7 +274,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -256,7 +285,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           *output++ = cptr[3];
@@ -267,7 +296,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           input += inIncr;
@@ -300,7 +329,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -313,7 +342,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -325,7 +354,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           *output++ = static_cast<unsigned char>(alpha*cptr[3]);
@@ -337,7 +366,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         while (--i >= 0) 
           {
           val = VISU_ApplyLogScale(*input, range, logRange);
-          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); 
+          cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           input += inIncr;
@@ -364,7 +393,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -376,7 +405,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); 
           *output++ = *cptr++;
           *output++ = *cptr++;
           *output++ = *cptr++;
@@ -387,7 +416,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           *output++ = static_cast<unsigned char>(cptr[3]*alpha);
@@ -398,7 +427,7 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
         {
         while (--i >= 0) 
           {
-          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); 
+          cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale, bicolor); 
           *output++ = static_cast<unsigned char>(cptr[0]*0.30 + cptr[1]*0.59 + 
                                                  cptr[2]*0.11 + 0.5);
           input += inIncr;
@@ -414,7 +443,8 @@ void VISU_LookupTableMapData(vtkLookupTable *self, T *input,
 template<class T>
 void VISU_LookupTableMapMag(vtkLookupTable *self, T *input, 
                            unsigned char *output, int length, 
-                           int inIncr, int outFormat, float theMapScale)
+                           int inIncr, int outFormat,
+                           float theMapScale, bool bicolor)
 {
   double tmp, sum;
   double *mag;
@@ -433,7 +463,7 @@ void VISU_LookupTableMapMag(vtkLookupTable *self, T *input,
     mag[i] = sqrt(sum);
     }
 
-  VISU_LookupTableMapData(self, mag, output, length, 1, outFormat, theMapScale);
+  VISU_LookupTableMapData(self, mag, output, length, 1, outFormat, theMapScale, bicolor);
 
   delete [] mag;
 }
@@ -455,43 +485,43 @@ void VISU_LookupTable::MapScalarsThroughTable2(void *input,
         break;
       case VTK_CHAR:
         VISU_LookupTableMapMag(this,static_cast<char *>(input),output,
-                              numberOfValues,inputIncrement,outputFormat,myScale);
+                              numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return; 
       case VTK_UNSIGNED_CHAR:
         VISU_LookupTableMapMag(this,static_cast<unsigned char *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_SHORT:
         VISU_LookupTableMapMag(this,static_cast<short *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_UNSIGNED_SHORT:
         VISU_LookupTableMapMag(this,static_cast<unsigned short *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_INT:
         VISU_LookupTableMapMag(this,static_cast<int *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_UNSIGNED_INT:
         VISU_LookupTableMapMag(this,static_cast<unsigned int *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_LONG:
         VISU_LookupTableMapMag(this,static_cast<long *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_UNSIGNED_LONG:
         VISU_LookupTableMapMag(this,static_cast<unsigned long *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_FLOAT:
         VISU_LookupTableMapMag(this,static_cast<float *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       case VTK_DOUBLE:
         VISU_LookupTableMapMag(this,static_cast<double *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
         return;
       default:
         vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
@@ -515,7 +545,7 @@ void VISU_LookupTable::MapScalarsThroughTable2(void *input,
       VISU_LookupTableMapData(this,
                              static_cast<unsigned char*>(newInput->GetPointer(0)),
                              output,numberOfValues,
-                             inputIncrement,outputFormat,myScale);
+                             inputIncrement,outputFormat,myScale,myBicolor);
       newInput->Delete();
       bitArray->Delete();
       }
@@ -523,52 +553,52 @@ void VISU_LookupTable::MapScalarsThroughTable2(void *input,
       
     case VTK_CHAR:
       VISU_LookupTableMapData(this,static_cast<char *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_UNSIGNED_CHAR:
       VISU_LookupTableMapData(this,static_cast<unsigned char *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_SHORT:
       VISU_LookupTableMapData(this,static_cast<short *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_UNSIGNED_SHORT:
       VISU_LookupTableMapData(this,static_cast<unsigned short *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_INT:
       VISU_LookupTableMapData(this,static_cast<int *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_UNSIGNED_INT:
       VISU_LookupTableMapData(this,static_cast<unsigned int *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_LONG:
       VISU_LookupTableMapData(this,static_cast<long *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_UNSIGNED_LONG:
       VISU_LookupTableMapData(this,static_cast<unsigned long *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_FLOAT:
       VISU_LookupTableMapData(this,static_cast<float *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     case VTK_DOUBLE:
       VISU_LookupTableMapData(this,static_cast<double *>(input),output,
-                             numberOfValues,inputIncrement,outputFormat,myScale);
+                             numberOfValues,inputIncrement,outputFormat,myScale,myBicolor);
       break;
       
     default: