From: rkv Date: Fri, 22 Nov 2013 08:26:55 +0000 (+0000) Subject: - Bathymethries are colored now by all colors (including red etc.) X-Git-Tag: BR_hydro_v_0_3_1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9e5f9721be88b2f58dcf4ae6564b2bee69fdb65e;p=modules%2Fhydro.git - Bathymethries are colored now by all colors (including red etc.) - Hide/show is fixed for bathymetries with automatic viewer opening; - Global automatically updated scalar bar is added in VTK viewer --- diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 3b45b680..b5cf925c 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -743,6 +743,26 @@ void HYDROGUI_Module::setObjectVTKPrs( const int theViewId if( theObject.IsNull() ) return; + // Compute the new global Z range from the added presentation and the old global Z range. + double* aGlobalRange = getVTKDisplayer()->GetZRange(); + double* aRange = theShape->getInternalZRange(); + bool anIsUpdate = false; + if ( aRange[0] < aGlobalRange[0] ) + { + aGlobalRange[0] = aRange[0]; + anIsUpdate = true; + } + if ( aRange[1] > aGlobalRange[1] ) + { + aGlobalRange[1] = aRange[1]; + anIsUpdate = true; + } + + //if ( anIsUpdate ) + //{ + updateVTKZRange( aGlobalRange ); + //} + ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ]; aViewShapes.append( theShape ); } @@ -768,6 +788,10 @@ void HYDROGUI_Module::removeObjectVTKPrs( const int theVie ++i; } + + // Invalidate global Z range + double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() }; + getVTKDisplayer()->SetZRange( anInvalidRange ); } void HYDROGUI_Module::removeViewVTKPrs( const int theViewId ) @@ -785,6 +809,28 @@ void HYDROGUI_Module::removeViewVTKPrs( const int theViewId ) myVTKPrsMap.remove( theViewId ); } + +void HYDROGUI_Module::updateVTKZRange( double theRange[] ) +{ + // For all VTK viewers ... + QList aViewIdList = myVTKPrsMap.keys(); + foreach( int aViewId, aViewIdList ) + { + // ... update all VTK presentations ... + const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( aViewId ); + HYDROGUI_VTKPrs* aShape; + for ( int i = 0, n = aViewShapes.length(); i < n; ++i ) + { + aShape = aViewShapes.at( i ); + if ( aShape ) + { + aShape->setZRange( theRange ); + } + } + } + // ... and update the global color legend scalar bar. + getVTKDisplayer()->SetZRange( theRange ); +} /////////////////// END OF VTKPrs PROCESSING CAM_DataModel* HYDROGUI_Module::createDataModel() diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 384e5e71..808958f6 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -143,6 +143,10 @@ public: void removeViewVTKPrs( const int theViewId ); void removeObjectVTKPrs( const int theViewId, const Handle(HYDROData_Entity)& theObject ); + /** + * Update global imposed range of Z values for VTK viewer + */ + void updateVTKZRange( double theRange[] ); QStringList GetGeomObjectsToImport(); diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index 755e933a..d06c59f2 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -80,11 +80,14 @@ void HYDROGUI_ShowHideOp::startOperation() } } + int anUpdateFlags = 0; + SUIT_ViewManager* aVTKMgr = 0; + // for selected objects if( myId == ShowId || myId == ShowOnlyId || myId == HideId ) { HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); - + bool aVisibility = myId == ShowId || myId == ShowOnlyId; Handle( HYDROData_Entity ) anObject; for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) @@ -109,17 +112,34 @@ void HYDROGUI_ShowHideOp::startOperation() } } } + else if ( anObject->GetKind() == KIND_BATHYMETRY && aVisibility ) + { + // Activate VTK viewer if show a bathymetry + aVTKMgr = module()->getApp()->viewManager( SVTK_Viewer::Type() ); + if ( !aVTKMgr ) + { + aVTKMgr = module()->getApp()->createViewManager( SVTK_Viewer::Type() ); + } + if ( aVTKMgr ) + { + module()->setObjectVisible( (size_t)aVTKMgr->getViewModel(), anObject, aVisibility ); + } + } } } } - int anUpdateFlags = 0; - if ( myId == ShowOnlyId || myId == ShowId || myId == ShowAllId ) { - anUpdateFlags = UF_FitAll; + anUpdateFlags |= UF_FitAll; } + // Set VTK viewer active if show a bathymetry + if ( aVTKMgr ) + { + anUpdateFlags |= UF_VTKViewer; + aVTKMgr->setShown( true ); + } SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager(); if ( aViewMgr ) { diff --git a/src/HYDROGUI/HYDROGUI_VTKPrs.cxx b/src/HYDROGUI/HYDROGUI_VTKPrs.cxx index ad2fd392..671a2cdc 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrs.cxx @@ -23,6 +23,8 @@ #include "HYDROGUI_VTKPrs.h" #include "HYDROGUI_DataObject.h" +#include +#include //======================================================================= // name : HYDROGUI_VTKPrs @@ -36,6 +38,8 @@ HYDROGUI_VTKPrs::HYDROGUI_VTKPrs( const Handle(HYDROData_Entity)& theObject ) QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject ); myIO = new SALOME_InteractiveObject( anEntry.toAscii(), QString::number( theObject->GetKind() ).toAscii(), theObject->GetName().toAscii() ); + myZRange[0] = HYDROData_IAltitudeObject::GetInvalidAltitude(); + myZRange[1] = HYDROData_IAltitudeObject::GetInvalidAltitude(); } //======================================================================= @@ -53,3 +57,18 @@ HYDROGUI_VTKPrs::~HYDROGUI_VTKPrs() void HYDROGUI_VTKPrs::compute() { } + +//======================================================================= +// name : setZRange +// Purpose : Compute the presentation +//======================================================================= +void HYDROGUI_VTKPrs::setZRange( double theRange[] ) +{ + myZRange[0] = theRange[0]; + myZRange[1] = theRange[1]; + vtkMapper* aMapper = mapper(); + if ( aMapper ) + { + mapper()->SetScalarRange( myZRange ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrs.h b/src/HYDROGUI/HYDROGUI_VTKPrs.h index d679856a..d6a8b206 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrs.h +++ b/src/HYDROGUI/HYDROGUI_VTKPrs.h @@ -24,10 +24,13 @@ #define HYDROGUI_VTKPrs_H #include +#include #include #include +class vtkMapper; + /* Class : HYDROGUI_VTKPrs Description : Base class for all HYDRO presentation in VTK viewer @@ -40,17 +43,37 @@ public: virtual void compute(); + static double InvalidZValue() { return HYDROData_AltitudeObject::GetInvalidAltitude(); } + public: Handle(HYDROData_Entity) getObject() const { return myObject; } Handle(SALOME_InteractiveObject) getIO() const { return myIO; } bool getIsToUpdate() const { return myIsToUpdate; } void setIsToUpdate( bool theState ) { myIsToUpdate = theState; } + /** + * \brief Set the range of Z values for the color mapping. + */ + virtual void setZRange( double theRange[] ); + /** + * \brief Get the range of Z values for the color mapping. + */ + virtual double* getZRange() { return myZRange; } + /** + * \brief Get an actual Z values range of the presented object. + */ + virtual double* getInternalZRange() { return myInternalZRange; } + +protected: + virtual vtkMapper* mapper() { return 0; } + + double myInternalZRange[2]; //!< Actual Z values range of the presented object private: Handle(HYDROData_Entity) myObject; Handle(SALOME_InteractiveObject) myIO; bool myIsToUpdate; + double myZRange[2]; //!< Imposed Z values range for colors mapping }; #endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx index 769879de..381923d8 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx @@ -33,17 +33,16 @@ #include #include #include -#include +#include #include -#define NB_COLORS 32 -#define Z_MIN -100 +/*! \def Z_MAX + \brief Maximum Z value used in bathymetry presentation. + + This value is used instead of invalid values. +*/ #define Z_MAX 1 -#define HUE_START 0.69 -#define HUE_END 0.41 -#define SATURATION_START 1.0 -#define SATURATION_END 0.4 //======================================================================= // name : HYDROGUI_VTKPrsBathymetry @@ -89,7 +88,7 @@ void HYDROGUI_VTKPrsBathymetry::compute() vtkVertex* aVertex = vtkVertex::New(); int aZ; - int anInvalidZ = aBathymetry->GetInvalidAltitude(); + int anInvalidZ = InvalidZValue(); for (int i = 0; i < aNbPoints; i++ ) { anAltPnt = anAltPoints.at( i ); @@ -113,24 +112,51 @@ void HYDROGUI_VTKPrsBathymetry::compute() aVertexGrid->SetPoints( aPoints ); aVertexGrid->GetPointData()->SetScalars( aZValues ); - vtkLookupTable* aLut = vtkLookupTable::New(); - aLut->SetHueRange( HUE_START, HUE_END ); - aLut->SetSaturationRange( SATURATION_START, SATURATION_END ); - aLut->SetTableRange( Z_MIN, Z_MAX ); - aLut->SetValueRange( 1.0, 1.0 ); - aLut->SetAlphaRange( 1.0, 1.0 ); - aLut->SetNumberOfColors( NB_COLORS ); - aLut->Build(); - - vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); - aMapper->SetScalarRange( Z_MIN, Z_MAX ); - aMapper->ScalarVisibilityOn(); - aMapper->SetScalarModeToUsePointData(); - aMapper->SetLookupTable( aLut ); - aMapper->SetInputData( aVertexGrid ); + //vtkLookupTable* aLut = vtkLookupTable::New(); + //aLut->SetHueRange( HUE_START, HUE_END ); + //aLut->SetSaturationRange( SATURATION_START, SATURATION_END ); + //aLut->SetTableRange( Z_MIN, Z_MAX ); + //aLut->SetValueRange( 1.0, 1.0 ); + //aLut->SetAlphaRange( 1.0, 1.0 ); + //aLut->SetNumberOfColors( NB_COLORS ); + //aLut->Build(); + + // Update the lookup table range if this bathymetry is out of it + if ( myLookupTable ) + { + aZValues->GetRange( myInternalZRange ); + + double* aGlobalRange = myLookupTable->GetRange(); + // If the global range is not yet initialized or the current one is out of scope then update the global + bool anIsUpdated; + if ( ValuesEquals( aGlobalRange[0], anInvalidZ ) || ( aGlobalRange[0] > myInternalZRange[0] ) ) + { + aGlobalRange[0] = myInternalZRange[0]; + anIsUpdated = true; + } + + if ( ValuesEquals( aGlobalRange[1], anInvalidZ ) || ( aGlobalRange[1] < myInternalZRange[1] ) ) + { + aGlobalRange[1] = myInternalZRange[1]; + anIsUpdated = true; + } + + if ( anIsUpdated ) + { + myLookupTable->SetRange( aGlobalRange ); + myLookupTable->Build(); + } + + myMapper->SetScalarRange( aGlobalRange ); + myMapper->ScalarVisibilityOn(); + myMapper->SetScalarModeToUsePointData(); + myMapper->SetLookupTable( myLookupTable ); + } + + myMapper->SetInputData( aVertexGrid ); SALOME_Actor* anActor = SALOME_Actor::New(); - anActor->SetMapper( aMapper ); + anActor->SetMapper( myMapper.GetPointer() ); anActor->setIO( getIO() ); AddObject( anActor ); } diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h index 3a4098c7..25e357d5 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h @@ -27,6 +27,11 @@ #include +#include +#include +#include +#include + /* Class : HYDROGUI_VTKPrsBathymetry Description : Presentation for Bathymetry object @@ -38,6 +43,16 @@ public: virtual ~HYDROGUI_VTKPrsBathymetry(); virtual void compute(); + + //! Get the range of colored + void setLookupTable( vtkScalarsToColors* theTable ) { myLookupTable = theTable; } + +protected: + virtual vtkMapper* mapper() { return myMapper.GetPointer(); } + +private: + vtkWeakPointer< vtkScalarsToColors > myLookupTable; + vtkNew< vtkPolyDataMapper > myMapper; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx index a00cc17a..a0731472 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx @@ -26,8 +26,9 @@ #include -HYDROGUI_VTKPrsBathymetryDriver::HYDROGUI_VTKPrsBathymetryDriver() +HYDROGUI_VTKPrsBathymetryDriver::HYDROGUI_VTKPrsBathymetryDriver( vtkScalarBarActor* theScalarBar ) { + myScalarBar = theScalarBar; } HYDROGUI_VTKPrsBathymetryDriver::~HYDROGUI_VTKPrsBathymetryDriver() @@ -50,10 +51,8 @@ bool HYDROGUI_VTKPrsBathymetryDriver::Update( const Handle(HYDROData_Entity)& th thePrs = new HYDROGUI_VTKPrsBathymetry( aBathymetry ); HYDROGUI_VTKPrsBathymetry* aPrsBathymetry = (HYDROGUI_VTKPrsBathymetry*)thePrs; - - //aPrsBathymetry->setName( aBathymetry->GetName() ); - //aPrsBathymetry->setPath( aBathymetry->GetPainterPath() ); - + // Update global colors table during compute if necessary + aPrsBathymetry->setLookupTable( myScalarBar->GetLookupTable() ); aPrsBathymetry->compute(); return true; diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h index 37bee693..a5b23b3a 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h @@ -23,7 +23,9 @@ #ifndef HYDROGUI_VTKPrsBathymetryDRIVER_H #define HYDROGUI_VTKPrsBathymetryDRIVER_H -#include +#include "HYDROGUI_VTKPrsDriver.h" + +#include /** * \class HYDROGUI_VTKPrsBathymetryDriver @@ -35,7 +37,7 @@ public: /** * \brief Constructor. */ - HYDROGUI_VTKPrsBathymetryDriver(); + HYDROGUI_VTKPrsBathymetryDriver( vtkScalarBarActor* theScalarBar ); /** * \brief Destructor. @@ -51,6 +53,9 @@ public: */ virtual bool Update( const Handle(HYDROData_Entity)& theObj, HYDROGUI_VTKPrs*& thePrs ); + +private: + vtkScalarBarActor* myScalarBar; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx index 6839219f..afa82b52 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -28,6 +28,7 @@ #include "HYDROGUI_VTKPrsBathymetryDriver.h" #include "HYDROGUI_Tool.h" +#include "HYDROData_Tool.h" #include #include #include @@ -36,11 +37,39 @@ #include #include +#include +#include +#include +#include + #include +#define NB_COLORS 32 + +// Saturation of blue +//#define HUE_START 0.69 +//#define HUE_END 0.41 +//#define SATURATION_START 1.0 +//#define SATURATION_END 0.4 + +#define HUE_START 1.0 +#define HUE_END 0.0 +#define SATURATION_START 1.0 +#define SATURATION_END 1.0 + HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule ) : HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ) { + // The invalid value is used to identify the case when the table range is not initialized yet. + double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue(); + vtkLookupTable* aTable = vtkLookupTable::New(); + aTable->SetHueRange( HUE_START, HUE_END ); + aTable->SetSaturationRange( SATURATION_START, SATURATION_END ); + aTable->SetTableRange( anInvalidValue, anInvalidValue ); + aTable->SetValueRange( 1.0, 1.0 ); + aTable->SetAlphaRange( 1.0, 1.0 ); + aTable->SetNumberOfColors( NB_COLORS ); + myScalarBar->SetLookupTable( aTable ); } HYDROGUI_VTKPrsDisplayer::~HYDROGUI_VTKPrsDisplayer() @@ -113,6 +142,22 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); if( aViewer ) { + // Invalidate global Z range + double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() }; + SetZRange( anInvalidRange ); + // Hide colors legend bar + SVTK_ViewWindow* aView = dynamic_cast( + aViewer->getViewManager()->getActiveView() ); + if ( aView ) + { + if ( aView->getRenderer()->HasViewProp( myScalarBar.GetPointer() ) ) + { + aView->getRenderer()->RemoveActor2D( myScalarBar.GetPointer() ); + } + } + + + int anInvalidZ = HYDROGUI_VTKPrs::InvalidZValue(); bool isChanged = false; HYDROGUI_VTKPrs* aPrs; for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) @@ -139,7 +184,29 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb { if ( anIsVisible ) { + + // Extend the global Z range if necessary + double* aGlobalRange = GetZRange(); + double* aRange = aPrs->getInternalZRange(); + bool anIsUpdate = false; + if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) ) + { + aGlobalRange[0] = aRange[0]; + anIsUpdate = true; + } + if ( aRange[1] > aGlobalRange[1] || ValuesEquals( aGlobalRange[1], anInvalidZ ) ) + { + aGlobalRange[1] = aRange[1]; + anIsUpdate = true; + } + + if ( anIsUpdate ) + { + module()->updateVTKZRange( aGlobalRange ); + } + aViewer->Display( aPrs ); + } else { @@ -150,6 +217,15 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb } } + if ( isChanged ) + { + // Show colors legend bar + if ( aView ) + { + aView->getRenderer()->AddActor2D( myScalarBar.GetPointer() ); + } + } + if ( theDoFitAll ) { // Repaint is done inside OnFitAll() @@ -201,7 +277,7 @@ HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDRODa { if ( !myDriver ) { - myDriver = new HYDROGUI_VTKPrsBathymetryDriver(); + myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBar.GetPointer() ); } aDriver = myDriver; } @@ -213,3 +289,13 @@ QString HYDROGUI_VTKPrsDisplayer::GetType() const { return SVTK_Viewer::Type(); } + +void HYDROGUI_VTKPrsDisplayer::SetZRange( double theRange[] ) +{ + myScalarBar->GetLookupTable()->SetRange( theRange ); +} + +double* HYDROGUI_VTKPrsDisplayer::GetZRange() const +{ + return myScalarBar->GetLookupTable()->GetRange(); +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h index 6e53647a..2be387c1 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h @@ -24,6 +24,8 @@ #define HYDROGUI_VTKPRSDISPLAYER_H #include "HYDROGUI_AbstractDisplayer.h" +#include +#include class HYDROGUI_VTKPrsDriver; @@ -45,7 +47,6 @@ public: */ virtual ~HYDROGUI_VTKPrsDisplayer(); -public: /** * \brief Force the specified objects to be updated. * \param theObjs sequence of objects to update @@ -59,6 +60,16 @@ public: */ virtual QString GetType() const; + /** + * \brief Set the range of Z values for the color legend bar. + */ + void SetZRange( double theRange[] ); + + /** + * \brief Get the range of Z values for the color legend bar. + */ + double* GetZRange() const; + protected: /** * \brief Erase all viewer objects. @@ -100,7 +111,9 @@ private: */ HYDROGUI_VTKPrsDriver* getDriver( const Handle(HYDROData_Entity)& theObj ); - HYDROGUI_VTKPrsDriver* myDriver; + HYDROGUI_VTKPrsDriver* myDriver; + + vtkNew< vtkScalarBarActor > myScalarBar; //!< The colors legend presentation }; #endif