From c1381d59ade907f7e946e62bc1a9f43ecaf4d9e7 Mon Sep 17 00:00:00 2001 From: pkv Date: Wed, 28 Sep 2005 09:05:21 +0000 Subject: [PATCH] Implementation the class controlling the local and global scalar bars --- src/PIPELINE/VISU_ScalarBarCtrl.cxx | 301 ++++++++++++++++++++++++++++ src/PIPELINE/VISU_ScalarBarCtrl.hxx | 96 +++++++++ 2 files changed, 397 insertions(+) create mode 100644 src/PIPELINE/VISU_ScalarBarCtrl.cxx create mode 100644 src/PIPELINE/VISU_ScalarBarCtrl.hxx diff --git a/src/PIPELINE/VISU_ScalarBarCtrl.cxx b/src/PIPELINE/VISU_ScalarBarCtrl.cxx new file mode 100644 index 00000000..1fa1cfcb --- /dev/null +++ b/src/PIPELINE/VISU_ScalarBarCtrl.cxx @@ -0,0 +1,301 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +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; iSetOrientation(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-1 && theIndexGetPositionCoordinate(); + 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; iSetRange(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; jGetPointer(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; jGetPointer(j); + + if (jaG[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; iAddActor2D(mySBA[i]); + } + } +} +//================================================================== +// function : RemoveFromRender +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::RemoveFromRender(vtkRenderer* theRenderer) +{ + for (int i=0; iRemoveActor2D(mySBA[i]); + } +} diff --git a/src/PIPELINE/VISU_ScalarBarCtrl.hxx b/src/PIPELINE/VISU_ScalarBarCtrl.hxx new file mode 100644 index 00000000..803a2361 --- /dev/null +++ b/src/PIPELINE/VISU_ScalarBarCtrl.hxx @@ -0,0 +1,96 @@ +// 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 +#include + +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 -- 2.39.2