Salome HOME
Restore support of med-2.1 in MEDWrapper
[modules/visu.git] / src / PIPELINE / VISU_ScalarBarCtrl.cxx
index 5dbf6e47845fbcb471eba2af6b5a238ca41bbe15..cb2807a213735c38487499d010617e5e6eec226d 100644 (file)
@@ -1,32 +1,33 @@
-//  VISU OBJECT : interactive object for VISU entities implementation
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  VISU OBJECT : interactive object for VISU entities implementation
 // File:    VISU_ScalarBarCtrl.cxx
 // Author:  Peter KURNEV
 // Module : VISU
-
+//
 #include "VISU_ScalarBarCtrl.hxx"
-#include <VISU_LookupTable.hxx>
-#include <VISU_ScalarBarActor.hxx>
+#include "VISU_LookupTable.hxx"
+#include "VISU_ScalarBarActor.hxx"
 
 #include <vtkObjectFactory.h>
 #include <vtkActor2D.h> 
 #include <string.h>
 
 
-//----------------------------------------------------------------------------
-namespace
-{
-  inline
-  void
-  MarkValueByColor(VISU_LookupTable* theTable,
-                  vtkFloatingPointType theValue,
-                  unsigned char* theColor)
-  { 
-    vtkIdType anIndex = theTable->GetIndex(theValue);
-    unsigned char *aTablePtr = theTable->GetPointer(anIndex);
-    aTablePtr[0] = theColor[0];
-    aTablePtr[1] = theColor[1];
-    aTablePtr[2] = theColor[2];
-  }
-
-  inline
-  void
-  CopyColor(unsigned char* theTaget, const unsigned char* theSource)
-  {
-    theTaget[0] = theSource[0];
-    theTaget[1] = theSource[1];
-    theTaget[2] = theSource[2];
-  }
-
-  void
-  FillByColor(VISU_LookupTable* theTable,
-             unsigned char* theColor)
-  {
-    vtkIdType aNbColors = theTable->GetNumberOfColors();
-    for(int i = 0; i < aNbColors; i++){
-      unsigned char *aTablePtr = theTable->GetPointer(i);
-      CopyColor(aTablePtr,theColor);
-    }
-  }
-
-  void
-  MakeBiColor(VISU_LookupTable* theTable)
-  {
-    unsigned char aRedPtr[3] = {255, 0, 0};
-    unsigned char aBluePtr[3] = {0, 0, 255};
-
-    vtkFloatingPointType aRange[2];
-    theTable->GetTableRange(aRange);
-    vtkIdType aNbColors = theTable->GetNumberOfColors();
-
-    vtkFloatingPointType aDelta = (aRange[1]-aRange[0])/aNbColors;
-    vtkFloatingPointType aValue = aRange[0]+0.5*aDelta;
-    for(int i = 0; i < aNbColors; i++){
-      vtkIdType anIndex = theTable->GetIndex(aValue);
-      unsigned char* aTablePtr = theTable->GetPointer(anIndex);
-      if(aValue > 0.0){
-       CopyColor(aTablePtr,aRedPtr);
-      }else{
-       CopyColor(aTablePtr,aBluePtr);
-      }
-      aValue += aDelta;
-    }
-  }
-}
-
-
 //----------------------------------------------------------------------------
 vtkStandardNewMacro(VISU_ScalarBarCtrl);
 
@@ -214,7 +153,7 @@ VISU_ScalarBarCtrl
 void
 VISU_ScalarBarCtrl
 ::SetRangeLocal(vtkFloatingPointType theMin,
-               vtkFloatingPointType theMax)
+                vtkFloatingPointType theMax)
 {
   myLocalLookupTable->SetTableRange(theMin,theMax);
 }
@@ -231,7 +170,7 @@ VISU_ScalarBarCtrl
 void
 VISU_ScalarBarCtrl
 ::SetRangeGlobal(vtkFloatingPointType theMin,
-                vtkFloatingPointType theMax)
+                 vtkFloatingPointType theMax)
 {
   myGlobalLookupTable->SetTableRange(theMin,theMax);
 }
@@ -435,16 +374,16 @@ VISU_ScalarBarCtrl
 {
   if(myMarked){
     if(myMode == eGlobal){
-      MarkValueByColor(myGlobalLookupTable, myMarkedValue, myBlack);
+      myGlobalLookupTable->MarkValueByColor( myMarkedValue, myBlack );
     }else{
-      MarkValueByColor(myLocalLookupTable, myMarkedValue, myBlack);
+      myLocalLookupTable->MarkValueByColor( myMarkedValue, myBlack );
     }
   }
   if(myGlobalRangeIsDefined){
     vtkFloatingPointType aLocalRange[2];
     myLocalLookupTable->GetTableRange(aLocalRange);
-    MarkValueByColor(myGlobalLookupTable, aLocalRange[0], myBlack);
-    MarkValueByColor(myGlobalLookupTable, aLocalRange[1], myBlack);
+    myGlobalLookupTable->MarkValueByColor( aLocalRange[0], myBlack );
+    myGlobalLookupTable->MarkValueByColor( aLocalRange[1], myBlack );
   }
 }
 
@@ -453,8 +392,8 @@ VISU_ScalarBarCtrl
 void
 VISU_ScalarBarCtrl
 ::PrepareTables(VISU_ScalarBarActor* theScalarBarActor,
-               VISU_LookupTable *theLookupTable,
-               vtkIdType theId)
+                VISU_LookupTable *theLookupTable,
+                vtkIdType theId)
 {
   vtkCoordinate * aCoordinate = theScalarBarActor->GetPositionCoordinate();
   aCoordinate->SetCoordinateSystemToNormalizedViewport();
@@ -490,9 +429,9 @@ VISU_ScalarBarCtrl
 ::UpdateForColor()
 {
   if(myMode == eGlobal){ 
-    FillByColor(myLocalLookupTable,myGrey);
+    myLocalLookupTable->FillByColor( myGrey );
   }else if(myMode == eLocal){
-    FillByColor(myGlobalLookupTable,myGrey);
+    myGlobalLookupTable->FillByColor( myGrey );
   }
 }
 
@@ -506,15 +445,15 @@ VISU_ScalarBarCtrl
   myLocalLookupTable->Build();
 
   if(myMode == eSimple){
-    MakeBiColor(myLocalLookupTable);
+    myLocalLookupTable->MakeBiColor();
     return;
   }
 
   if(myMode == eGlobal){
-    MakeBiColor(myGlobalLookupTable);
-    FillByColor(myLocalLookupTable,myGrey);
+    myGlobalLookupTable->MakeBiColor();
+    myLocalLookupTable->FillByColor( myGrey );
   }else if(myMode == eLocal){
-    MakeBiColor(myLocalLookupTable);
-    FillByColor(myGlobalLookupTable,myGrey);
+    myLocalLookupTable->MakeBiColor();
+    myGlobalLookupTable->FillByColor( myGrey );
   }
 }