--- /dev/null
+// VISU OBJECT : interactive object for VISU entities implementation
+//
+// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+// File: VISU_ScalarBarCtrl.cxx
+// Author: Peter KURNEV
+// Module : VISU
+
+#include "VISU_ScalarBarCtrl.hxx"
+#include <vtkObjectFactory.h>
+#include <vtkActor2D.h>
+#include <vtkCoordinate.h>
+#include <vtkRenderer.h>
+#include <vtkScalarsToColors.h>
+#include <vtkLookupTable.h>
+#include <vtkTextProperty.h>
+#include <vtkScalarBarActor.h>
+#include <vtkIdType.h>
+#include <string.h>
+//
+vtkStandardNewMacro(VISU_ScalarBarCtrl);
+//==================================================================
+// function : Constructor
+// purpose :
+//==================================================================
+VISU_ScalarBarCtrl::VISU_ScalarBarCtrl()
+{
+ myDistance=0.15;
+ myL=0.8;
+ myB=0.15;
+ myX0=0.05;
+ myY0=0.1;
+ //
+ int i;
+ //
+ for (i=0; i<2; ++i){
+ float aX;
+
+ aX=(float)i;
+ myRangeLocal[i]=aX;
+ myRangeGlobal[i]=aX;
+ }
+ //
+ //myMode=0; //0-simple ; 1-global; 2-local
+ SetMode(0);
+ //
+ myScalarBarNumberMax=2;
+ for (i=0; i<myScalarBarNumberMax; ++i){
+ myXLT[i]=vtkLookupTable::New();
+ mySBA[i]=vtkScalarBarActor::New();
+ }
+ //
+ SetOrientation(1);//VERTICAL
+}
+//==================================================================
+// function : ~
+// purpose :
+//==================================================================
+VISU_ScalarBarCtrl::~VISU_ScalarBarCtrl()
+{
+}
+//==================================================================
+// function : SetMode
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::SetMode(const int theMode)
+{
+ myMode=theMode;
+ myScalarBarNumber=myScalarBarNumberMax;
+ if(!myMode){
+ myScalarBarNumber=1;
+ }
+}
+//==================================================================
+// function : GetMode
+// purpose :
+//==================================================================
+int VISU_ScalarBarCtrl::GetMode()const
+{
+ return myMode;
+}
+//==================================================================
+// function : SetRangeLocal
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::SetRangeLocal(const float *theX)
+{
+ SetRangeLocal(theX[0], theX[1]);
+}
+//==================================================================
+// function : SetRangeLocal
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::SetRangeLocal(const float theX1,
+ const float theX2)
+{
+ myRangeLocal[0]=theX1;
+ myRangeLocal[1]=theX2;
+}
+//==================================================================
+// function : GetRangeLocal
+// purpose :
+//==================================================================
+const float* VISU_ScalarBarCtrl::GetRangeLocal()const
+{
+ return myRangeLocal;
+}
+//==================================================================
+// function : SetRangeGlobal
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::SetRangeGlobal(const float *theX)
+{
+ SetRangeGlobal(theX[0], theX[1]);
+}
+//==================================================================
+// function : SetRangeGlobal
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::SetRangeGlobal(const float theX1,
+ const float theX2)
+{
+ myRangeGlobal[0]=theX1;
+ myRangeGlobal[1]=theX2;
+}
+//==================================================================
+// function : GetRangeGlobal
+// purpose :
+//==================================================================
+const float* VISU_ScalarBarCtrl::GetRangeGlobal()const
+{
+ return myRangeGlobal;
+}
+//==================================================================
+// function : SetOrientation
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::SetOrientation(const int theOrientation)
+{
+ for (int i=0; i<myScalarBarNumberMax; ++i){
+ mySBA[i]->SetOrientation(theOrientation);
+ }
+}
+//==================================================================
+// function : GetOrientation
+// purpose :
+//==================================================================
+int VISU_ScalarBarCtrl::GetOrientation()const
+{
+ return mySBA[0]->GetOrientation();
+}
+//==================================================================
+// function : GetScalarBarActor
+// purpose :
+//==================================================================
+vtkScalarBarActor* VISU_ScalarBarCtrl::GetScalarBarActor(const int theIndex)
+{
+ if (theIndex>-1 && theIndex<myScalarBarNumberMax){
+ return mySBA[theIndex];
+ }
+ return NULL;
+}
+//==================================================================
+// function : GetLookupTable
+// purpose :
+//==================================================================
+vtkLookupTable* VISU_ScalarBarCtrl::GetLookupTable(const int theIndex)
+{
+ if (theIndex>-1 && theIndex<myScalarBarNumberMax){
+ return myXLT[theIndex];
+ }
+ return NULL;
+}
+//==================================================================
+// function : PrepareData
+// purpose :
+//==================================================================
+int VISU_ScalarBarCtrl::PrepareData()
+{
+ int i, aOrientation;
+ //
+ // Apply Orientation
+ aOrientation=GetOrientation();
+ //
+ for (i=0; i<myScalarBarNumberMax; ++i){
+ vtkCoordinate * pCoordinate=mySBA[i]->GetPositionCoordinate();
+ pCoordinate->SetCoordinateSystemToNormalizedViewport();
+ //
+ if (aOrientation) {// VERTICAL
+ pCoordinate->SetValue(myX0+i*myDistance, myY0);
+ mySBA[i]->SetWidth(myB);
+ mySBA[i]->SetHeight(myL);
+ }
+ else {
+ pCoordinate->SetValue(myX0, myY0+i*myDistance);
+ mySBA[i]->SetWidth(myL);
+ mySBA[i]->SetHeight(myB);
+ }
+ }
+ //
+ // Initialize Lookup Tables and Scalar Bars
+ for (i=0; i<myScalarBarNumberMax; ++i){
+ myXLT[i]->SetRange(myRangeGlobal[0], myRangeGlobal[1]);
+ myXLT[i]->Build();
+ mySBA[i]->SetLookupTable(myXLT[i]);
+ }
+ //
+ if (!myMode){
+ return 0; //nothing to do
+ }
+ //
+ // Fill Lookup Tables
+ size_t aN4=4*sizeof(unsigned char);
+ unsigned char *pTL, *pTG;
+ vtkIdType j, aNbColors, aG[2], dG;
+ //
+ for (j=0; j<2; ++j) {
+ aG[j]=myXLT[0]->GetIndex(myRangeLocal[j]);
+ }
+ dG=aG[1]-aG[0];
+ aNbColors=myXLT[0]->GetNumberOfColors();
+ //
+ if (myMode==1){
+ vtkIdType aGj;
+ //
+ for (j=0; j<aNbColors; ++j){
+ pTL=myXLT[1]->GetPointer(j);
+
+ aGj=aG[0]+j*dG/aNbColors;
+ pTG=myXLT[0]->GetPointer(aGj);
+ memcpy(pTL, pTG, aN4);
+ }
+ }
+ else {
+ unsigned char *pTL0, *pTL1;
+ vtkIdType aLj;
+ //
+ pTL0=myXLT[1]->GetPointer(0);
+ pTL1=myXLT[1]->GetPointer(aNbColors-1);
+ for (j=0; j<aNbColors; ++j){
+ pTG=myXLT[0]->GetPointer(j);
+
+ if (j<aG[0]) {
+ pTL=pTL0;
+ }
+ else if (j>aG[1]) {
+ pTL=pTL1;
+ }
+ else {
+ aLj=(j-aG[0])*aNbColors/dG;
+ pTL=myXLT[1]->GetPointer(aLj);
+ }
+ memcpy(pTG, pTL, aN4);
+ }
+ }
+ myXLT[1]->SetRange(myRangeLocal[0], myRangeLocal[1]);
+ return 0;
+}
+//==================================================================
+// function : AddToRender
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::AddToRender(vtkRenderer* theRenderer)
+{
+ int i, iErr;
+ //
+ iErr=PrepareData();
+ if (!iErr){
+ for (i=0; i<myScalarBarNumber; ++i){
+ theRenderer->AddActor2D(mySBA[i]);
+ }
+ }
+}
+//==================================================================
+// function : RemoveFromRender
+// purpose :
+//==================================================================
+void VISU_ScalarBarCtrl::RemoveFromRender(vtkRenderer* theRenderer)
+{
+ for (int i=0; i<myScalarBarNumber; ++i){
+ theRenderer->RemoveActor2D(mySBA[i]);
+ }
+}
--- /dev/null
+// VISU OBJECT : interactive object for VISU entities implementation
+//
+// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+// File: VISU_ScalarBarCtrl.hxx
+// Author: Peter KURNEV
+// Module : VISU
+
+#ifndef VISU_ScalarBarCtrl_HeaderFile
+#define VISU_ScalarBarCtrl_HeaderFile
+
+#include <vtkScalarBarActor.h>
+#include <vtkLookupTable.h>
+
+class vtkRenderer;
+class VISU_ScalarBarCtrl : public vtkObject {
+
+public:
+ vtkTypeMacro(VISU_ScalarBarCtrl, vtkObject);
+ static VISU_ScalarBarCtrl* New();
+ //
+ // Mode
+ void SetMode(const int theNumber);
+ int GetMode()const;
+ //
+ // Ranges
+ void SetRangeGlobal(const float theX1,
+ const float theX2);
+
+ void SetRangeGlobal(const float *theX);
+
+ const float* GetRangeGlobal()const;
+
+ void SetRangeLocal(const float theX1,
+ const float theX2);
+
+ void SetRangeLocal(const float *theX);
+
+ const float* GetRangeLocal()const;
+ //
+ //Orientation
+ void SetOrientationToHorizontal() {
+ SetOrientation(0);
+ }
+ void SetOrientationToVertical() {
+ SetOrientation(1);
+ }
+
+ void SetOrientation(const int theOrientation);
+
+ int GetOrientation()const;
+ //
+ vtkScalarBarActor* GetScalarBarActor(const int theIndex);
+ vtkLookupTable* GetLookupTable(const int theIndex);
+ //
+ // Renderer
+ void AddToRender(vtkRenderer* theRenderer);
+ void RemoveFromRender(vtkRenderer* theRenderer);
+ //
+protected:
+ VISU_ScalarBarCtrl();
+ virtual ~VISU_ScalarBarCtrl();
+
+ int PrepareData();
+
+protected:
+ int myMode;
+ int myScalarBarNumber;
+ int myScalarBarNumberMax;
+ float myDistance, myX0, myY0, myL, myB;
+ float myRangeLocal[2];
+ float myRangeGlobal[2];
+ //
+ vtkScalarBarActor *mySBA[2];
+ vtkLookupTable *myXLT[2];
+};
+
+#endif