From: pkv Date: Thu, 29 Sep 2005 14:47:40 +0000 (+0000) Subject: Provide the funcionality of two scalar bars X-Git-Tag: BR-D5-38-2003_D2005-12-10~108 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6cf345e18d8136e1901232811a92bc3f176dcae1;p=modules%2Fvisu.git Provide the funcionality of two scalar bars --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 5a322872..d80157ca 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -31,6 +31,8 @@ #include "VISU_GaussPtsDeviceActor.h" #include "VISU_ImplicitFunctionWidget.h" #include "VISU_OpenGLPointSpriteMapper.hxx" +#include "VISU_ScalarBarCtrl.hxx" +#include "VISU_ScalarBarActor.hxx" #include "SVTK_Actor.h" @@ -38,7 +40,7 @@ #include #include #include - +#include #include #include @@ -120,6 +122,7 @@ VISU_GaussPtsAct myCellActor(vtkActor::New()) { if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<Delete(); myDeviceActor->Delete(); @@ -176,6 +179,15 @@ VISU_GaussPtsAct myCellActor->GetProperty()->SetAmbient(1.0); myCellActor->GetProperty()->SetDiffuse(0.0); myCellActor->GetProperty()->SetRepresentationToWireframe(); + mySBCtrl=VISU_ScalarBarCtrl::New(); + mySBCtrl->Delete(); + mySBCtrl->SetMode(0); + mySBCtrl->SetRangeGlobal(0.,10.); + mySBCtrl->SetOrientationToHorizontal(); + mySBCtrl->GetScalarBarActor(0)->SetTitle("GLB"); + mySBCtrl->GetScalarBarActor(1)->SetTitle("LOC"); + + myScalarBar->SetVisibility(0); } VISU_GaussPtsAct @@ -266,6 +278,7 @@ VISU_GaussPtsAct theRenderer->AddActor(myCellActor.GetPointer()); myCursorPyramid->AddToRender(theRenderer); + mySBCtrl->AddToRender(theRenderer); } void @@ -284,6 +297,7 @@ VISU_GaussPtsAct theRenderer->RemoveActor(myCellActor.GetPointer()); myCursorPyramid->RemoveFromRender(theRenderer); + mySBCtrl->RemoveFromRender(theRenderer); } void @@ -799,7 +813,25 @@ VISU_GaussPtsAct return bRet; } +//================================================================== +// function : SetBarVisibility +// purpose : +//================================================================== +void VISU_GaussPtsAct::SetBarVisibility(bool theMode) +{ + myBarVisibility = theMode; + mySBCtrl->SetBarVisibility(myBarVisibility); + //VISU_ScalarMapAct::SetBarVisibility(theMode); +} +//================================================================== +// function : GetScalarBarCtrl +// purpose : +//================================================================== +VISU_ScalarBarCtrl* VISU_GaussPtsAct::GetScalarBarCtrl() +{ + return mySBCtrl.GetPointer(); +} //============================================================================== vtkStandardNewMacro(VISU_GaussPtsAct1); diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index 1abf7cfc..85e10a6e 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -56,6 +56,7 @@ class vtkDataSetMapper; class vtkInteractorObserver; class vtkCallbackCommand; +class VISU_ScalarBarCtrl; class VTKOCC_EXPORT VISU_OutsideCursorSettings : public vtkObject { @@ -201,6 +202,9 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight); + virtual void SetBarVisibility(bool theMode); + VISU_ScalarBarCtrl* GetScalarBarCtrl(); + protected: //---------------------------------------------------------------------------- VISU_GaussPtsAct(); @@ -253,6 +257,7 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct vtkSmartPointer myCellSource; vtkSmartPointer myCellActor; + vtkSmartPointer mySBCtrl; vtkSmartPointer myOutsideCursorSettings; }; diff --git a/src/PIPELINE/VISU_ScalarBarCtrl.cxx b/src/PIPELINE/VISU_ScalarBarCtrl.cxx index 1fa1cfcb..2132b677 100644 --- a/src/PIPELINE/VISU_ScalarBarCtrl.cxx +++ b/src/PIPELINE/VISU_ScalarBarCtrl.cxx @@ -43,11 +43,13 @@ vtkStandardNewMacro(VISU_ScalarBarCtrl); //================================================================== VISU_ScalarBarCtrl::VISU_ScalarBarCtrl() { - myDistance=0.15; + myBarVisibility=true; + myDistance=0.02; myL=0.8; myB=0.15; - myX0=0.05; - myY0=0.1; + myPosition[0]=0.05; + myPosition[1]=0.1; + myBicolor=false; // int i; // @@ -65,6 +67,7 @@ VISU_ScalarBarCtrl::VISU_ScalarBarCtrl() myScalarBarNumberMax=2; for (i=0; iSetHueRange(0.667,0.0); mySBA[i]=vtkScalarBarActor::New(); } // @@ -98,6 +101,22 @@ int VISU_ScalarBarCtrl::GetMode()const return myMode; } //================================================================== +// function : SetBarVisibility +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::SetBarVisibility(const bool theFlag) +{ + myBarVisibility=theFlag; +} +//================================================================== +// function : GetBarVisibility +// purpose : +//================================================================== +bool VISU_ScalarBarCtrl::GetBarVisibility()const +{ + return myBarVisibility; +} +//================================================================== // function : SetRangeLocal // purpose : //================================================================== @@ -189,11 +208,123 @@ vtkLookupTable* VISU_ScalarBarCtrl::GetLookupTable(const int theIndex) } return NULL; } + +//================================================================== +// function : AddToRender +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::AddToRender(vtkRenderer* theRenderer) +{ + int i; + // + Update(); + for (i=0; iAddActor2D(mySBA[i]); + } +} +//================================================================== +// function : RemoveFromRender +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::RemoveFromRender(vtkRenderer* theRenderer) +{ + for (int i=0; iRemoveActor2D(mySBA[i]); + } +} +//================================================================== +// function : SetWidth +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::SetWidth(const float theWidth) +{ + myL=theWidth; +} +//================================================================== +// function : GetWidth +// purpose : +//================================================================== +float VISU_ScalarBarCtrl::GetWidth()const +{ + return myL; +} +//================================================================== +// function : SetHeight +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::SetHeight(const float theHeight) +{ + myB=theHeight; +} +//================================================================== +// function : GetHeight +// purpose : +//================================================================== +float VISU_ScalarBarCtrl::GetHeight()const +{ + return myB; +} //================================================================== -// function : PrepareData +// function : SetPosition // purpose : //================================================================== -int VISU_ScalarBarCtrl::PrepareData() +void VISU_ScalarBarCtrl::SetPosition(const float* thePosition) +{ + myPosition[0]=thePosition[0]; + myPosition[1]=thePosition[1]; +} +//================================================================== +// function : GetPosition +// purpose : +//================================================================== +const float* VISU_ScalarBarCtrl::GetPosition()const +{ + return myPosition; +} +//================================================================== +// function : SetBicolor +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::SetBicolor(const bool theBicolor) +{ + myBicolor=theBicolor; +} +//================================================================== +// function : GetBicolor +// purpose : +//================================================================== +bool VISU_ScalarBarCtrl::GetBicolor()const +{ + return myBicolor; +} +//================================================================== +// function : Update +// purpose : +//================================================================== +int VISU_ScalarBarCtrl::Update() +{ + if (!myBarVisibility) { + for (int i=0; iSetVisibility(myBarVisibility); + } + return 0; + } + // + PrepareTables(); + // + if (myBicolor) { + UpdateForBicolor(); + } + else { + UpdateForColor(); + } + return 0; +} +//================================================================== +// function : PrepareTables +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::PrepareTables() { int i, aOrientation; // @@ -205,26 +336,39 @@ int VISU_ScalarBarCtrl::PrepareData() pCoordinate->SetCoordinateSystemToNormalizedViewport(); // if (aOrientation) {// VERTICAL - pCoordinate->SetValue(myX0+i*myDistance, myY0); - mySBA[i]->SetWidth(myB); - mySBA[i]->SetHeight(myL); + pCoordinate->SetValue(myPosition[0]+i*0.5*(myL+myDistance), myPosition[1]); + mySBA[i]->SetWidth(0.5*(myL-myDistance)); + mySBA[i]->SetHeight(myB); } else { - pCoordinate->SetValue(myX0, myY0+i*myDistance); + pCoordinate->SetValue(myPosition[0], myPosition[1]+i*0.5*(myB+myDistance)); mySBA[i]->SetWidth(myL); - mySBA[i]->SetHeight(myB); + mySBA[i]->SetHeight(0.5*(myB-myDistance)); } } // // Initialize Lookup Tables and Scalar Bars for (i=0; iSetRange(myRangeGlobal[0], myRangeGlobal[1]); - myXLT[i]->Build(); + myXLT[i]->Modified(); + myXLT[i]->Build(); + // mySBA[i]->SetLookupTable(myXLT[i]); + mySBA[i]->SetVisibility(myBarVisibility); + mySBA[i]->Modified(); } +} +//================================================================== +// function : UpdateForColor +// purpose : +//================================================================== +void VISU_ScalarBarCtrl::UpdateForColor() +{ + int i; // if (!myMode){ - return 0; //nothing to do + mySBA[1]->VisibilityOff(); + return ; } // // Fill Lookup Tables @@ -272,30 +416,53 @@ int VISU_ScalarBarCtrl::PrepareData() } } myXLT[1]->SetRange(myRangeLocal[0], myRangeLocal[1]); - return 0; } + //================================================================== -// function : AddToRender +// function : UpdateForBicolor // purpose : //================================================================== -void VISU_ScalarBarCtrl::AddToRender(vtkRenderer* theRenderer) +void VISU_ScalarBarCtrl::UpdateForBicolor() { - int i, iErr; + size_t aN4=4*sizeof(unsigned char); + unsigned char *pTi, *pTRed, *pTBlue; + int i, j, aNb; + float aXi, aX0, dX; + vtkIdType aIndex, aNbColors; // - iErr=PrepareData(); - if (!iErr){ - for (i=0; iAddActor2D(mySBA[i]); - } + aNbColors=myXLT[0]->GetNumberOfColors(); + // + pTBlue=myXLT[0]->GetPointer(0); + pTRed=myXLT[0]->GetPointer(aNbColors-1); + // + if (myMode){ + aNb=2; + myXLT[1]->SetRange(myRangeLocal[0], myRangeLocal[1]); + myXLT[1]->Modified(); + myXLT[1]->Build(); + // + mySBA[1]->SetLookupTable(myXLT[1]); + mySBA[1]->Modified(); } -} -//================================================================== -// function : RemoveFromRender -// purpose : -//================================================================== -void VISU_ScalarBarCtrl::RemoveFromRender(vtkRenderer* theRenderer) -{ - for (int i=0; iRemoveActor2D(mySBA[i]); + else { + aNb=1; + mySBA[1]->VisibilityOff(); + } + // + for (j=0; jGetIndex(aXi); + pTi=myXLT[j]->GetPointer(aIndex); + if (aXi > 0.) { + memcpy(pTi, pTRed, aN4); + } + else { + memcpy(pTi, pTBlue, aN4); + } + } } } diff --git a/src/PIPELINE/VISU_ScalarBarCtrl.hxx b/src/PIPELINE/VISU_ScalarBarCtrl.hxx index 803a2361..711be719 100644 --- a/src/PIPELINE/VISU_ScalarBarCtrl.hxx +++ b/src/PIPELINE/VISU_ScalarBarCtrl.hxx @@ -75,19 +75,39 @@ public: void AddToRender(vtkRenderer* theRenderer); void RemoveFromRender(vtkRenderer* theRenderer); // + // Visibility + void SetBarVisibility(const bool theFlag); + bool GetBarVisibility()const; + // + int Update(); + // + void SetWidth(const float theWidth); + float GetWidth()const; + void SetHeight(const float theHeight); + float GetHeight()const; + void SetPosition(const float* thePosition); + const float* GetPosition()const; + + bool GetBicolor() const; + void SetBicolor(const bool theBicolor); + protected: VISU_ScalarBarCtrl(); virtual ~VISU_ScalarBarCtrl(); - int PrepareData(); - + void UpdateForBicolor(); + void UpdateForColor(); + void PrepareTables(); + protected: int myMode; int myScalarBarNumber; int myScalarBarNumberMax; - float myDistance, myX0, myY0, myL, myB; + float myDistance, myL, myB, myPosition[2]; float myRangeLocal[2]; float myRangeGlobal[2]; + bool myBicolor; + bool myBarVisibility; // vtkScalarBarActor *mySBA[2]; vtkLookupTable *myXLT[2]; diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx index 80e53916..ec9cd58e 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx @@ -80,16 +80,16 @@ VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent, bool S BarTypeGroup->setFrameStyle( QFrame::NoFrame ); BarTypeGroup->layout()->setMargin( 0 ); - QRadioButton* LocalButton = new QRadioButton( tr( "LOCAL" ), BarTypeGroup ); - LocalButton->setChecked( true ); + myRBLocal = new QRadioButton( tr( "LOCAL" ), BarTypeGroup ); + myRBLocal->setChecked( true ); QRadioButton* GlobalButton = new QRadioButton( tr( "GLOBAL" ), BarTypeGroup ); - QCheckBox* DisplayedBox = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup ); - DisplayedBox->setChecked( true ); - DisplayedBox->setEnabled( false ); + myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup ); + myCBDisplayed->setChecked( true ); + myCBDisplayed->setEnabled( false ); ActiveBarGroupLayout->addMultiCellWidget( BarTypeGroup, 0, 1, 0, 0); - ActiveBarGroupLayout->addWidget( DisplayedBox, 1, 1); + ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1); // Range ============================================================ RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup"); @@ -246,7 +246,7 @@ VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent, bool S myTextDlg->setTitleVisible(!SetPref); // signals and slots connections =========================================== - connect( GlobalButton, SIGNAL( toggled( bool ) ), DisplayedBox, SLOT( setEnabled( bool ) ) ); + connect( GlobalButton, SIGNAL( toggled( bool ) ), myCBDisplayed, SLOT( setEnabled( bool ) ) ); connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) ); connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) ); connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) ); @@ -574,7 +574,8 @@ int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) { thePrs->SetPosition(XSpin->value(), YSpin->value()); thePrs->SetSize(WidthSpin->value(), HeightSpin->value()); thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL); - + thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked()); + thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked()); thePrs->SetSourceRange(); thePrs->SetNbColors(ColorSpin->value()); thePrs->SetLabels(LabelSpin->value()); diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.h b/src/VISUGUI/VisuGUI_GaussPointsDlg.h index 2e117301..a34cd1e1 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsDlg.h +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.h @@ -102,6 +102,8 @@ class VisuGUI_GaussScalarBarPane : public QVBox QComboBox* myModeCombo; QPushButton* myTextBtn; VisuGUI_TextPrefDlg* myTextDlg; + QRadioButton* myRBLocal; + QCheckBox* myCBDisplayed; double Imin, Imax, /* Fmin, Fmax,*/ Rmin, Rmax; double myHorX, myHorY, myHorW, myHorH; diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index c6561a2b..68f662f6 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -31,9 +31,13 @@ #include "VISU_GaussPointsPL.hxx" #include "VISU_OpenGLPointSpriteMapper.hxx" +#include "VISU_ScalarBarCtrl.hxx" #include #include +#include +#include + using namespace VISU; using namespace std; @@ -97,6 +101,8 @@ GaussPoints_i(Result_i* theResult, ScalarMap_i(theResult,theAddToStudy), myGaussPointsPL(NULL), myIsColored(true), + myIsActiveLocalScalarBar(true), + myIsDispGlobalScalarBar(true), myColor(Qt::blue) { if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<GetStudyDocument()), Prs3d_i(theResult,theSObject), ScalarMap_i(theResult,theSObject), - myGaussPointsPL(NULL) + myGaussPointsPL(NULL), + myIsActiveLocalScalarBar(true), + myIsDispGlobalScalarBar(true) { if(MYDEBUG) MESSAGE("GaussPoints_i::GaussPoints_i - this = "<(theActor)){ if(IsColored()){ anActor->SetBarVisibility(true); myPipeLine->GetMapper()->SetScalarVisibility(1); - }else{ + } + else{ anActor->SetBarVisibility(false); myPipeLine->GetMapper()->SetScalarVisibility(0); @@ -351,6 +358,81 @@ VISU::GaussPoints_i myColor.green() / 255.0, myColor.blue() / 255.0); } + // + VISU_ScalarBarCtrl *aSBCtrl = anActor->GetScalarBarCtrl(); + // + // Ranges + float *pRange=myScalarMapPL->GetBarTable()->GetRange(); + // + + VISU::TField *pField=myField.get(); + vtkIdType aIndexOfComponent=(vtkIdType)GetScalarMode(); + TMinMax aTMinMax=pField->GetMinMax(aIndexOfComponent); + aSBCtrl->SetRangeGlobal(aTMinMax.first, aTMinMax.second); + + /* Stub for testing + { + float dR; + // + dR=0.5*(pRange[1]-pRange[0]); + aSBCtrl->SetRangeGlobal (pRange[0]-dR, pRange[1]+dR); + } + */ + aSBCtrl->SetRangeLocal (pRange); + aSBCtrl->SetOrientation(myOrientation); + // + // Mode + int iSBMode; + // + if (myIsActiveLocalScalarBar) { + iSBMode=1; + } + else { + if (myIsDispGlobalScalarBar) { + iSBMode=2; + } + else { + iSBMode=0; + aSBCtrl->SetRangeGlobal(pRange); + } + } + aSBCtrl->SetMode(iSBMode); + // + // Position + aSBCtrl->SetWidth(myWidth); + aSBCtrl->SetHeight(myHeight); + aSBCtrl->SetPosition(myPosition); + // + // Bicolor + bool bBicolor=GetGaussPointsPL()->GetBicolor(); + aSBCtrl->SetBicolor(bBicolor); + // + aSBCtrl->Update(); + // + for (int i=0; i<2; ++i) { + vtkScalarBarActor *aScalarBar = aSBCtrl->GetScalarBarActor(i); + + aScalarBar->SetTitle(myTitle.c_str()); + + aScalarBar->SetNumberOfLabels(myNumberOfLabels); + + vtkTextProperty* aTitleProp = aScalarBar->GetTitleTextProperty(); + aTitleProp->SetFontFamily(myTitFontType); + aTitleProp->SetColor(myTitleColor); + (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff(); + (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff(); + (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff(); + + vtkTextProperty* aLabelProp = aScalarBar->GetLabelTextProperty(); + aLabelProp->SetFontFamily(myLblFontType); + aLabelProp->SetColor(myLabelColor); + (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff(); + (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff(); + (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff(); + + aScalarBar->Modified(); + } + // VISU::ScalarMap_i::UpdateActor(theActor); } } @@ -399,4 +481,19 @@ VISU::GaussPoints_i anImageData->Delete(); } } - +//---------------------------------------------------------------------------- +void VISU::GaussPoints_i::SetIsActiveLocalScalarBar(const bool theFlag){ + myIsActiveLocalScalarBar=theFlag; +} +//---------------------------------------------------------------------------- +bool VISU::GaussPoints_i::GetIsActiveLocalScalarBar()const { + return myIsActiveLocalScalarBar; +} +//---------------------------------------------------------------------------- +void VISU::GaussPoints_i::SetIsDispGlobalScalarBar(const bool theFlag){ + myIsDispGlobalScalarBar=theFlag; +} +//---------------------------------------------------------------------------- +bool VISU::GaussPoints_i::GetIsDispGlobalScalarBar()const { + return myIsDispGlobalScalarBar; +} diff --git a/src/VISU_I/VISU_GaussPoints_i.hh b/src/VISU_I/VISU_GaussPoints_i.hh index a0b0a47e..d29e5d3b 100644 --- a/src/VISU_I/VISU_GaussPoints_i.hh +++ b/src/VISU_I/VISU_GaussPoints_i.hh @@ -93,6 +93,11 @@ namespace VISU SetTextures( const QString& theMainTexture, const QString& theAlphaTexture ); + void SetIsActiveLocalScalarBar(const bool theFlag); + bool GetIsActiveLocalScalarBar()const; + void SetIsDispGlobalScalarBar(const bool theFlag); + bool GetIsDispGlobalScalarBar()const; + protected: virtual void @@ -120,6 +125,8 @@ namespace VISU VISU_GaussPointsPL *myGaussPointsPL; bool myIsColored; + bool myIsDispGlobalScalarBar; + bool myIsActiveLocalScalarBar; QColor myColor; QString myMainTexture;