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 );
}
++i;
}
+
+ // Invalidate global Z range
+ double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
+ getVTKDisplayer()->SetZRange( anInvalidRange );
}
void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
myVTKPrsMap.remove( theViewId );
}
+
+void HYDROGUI_Module::updateVTKZRange( double theRange[] )
+{
+ // For all VTK viewers ...
+ QList<int> 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()
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();
}
}
+ 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++ )
}
}
}
+ 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 )
{
#include "HYDROGUI_VTKPrs.h"
#include "HYDROGUI_DataObject.h"
+#include <HYDROData_IAltitudeObject.h>
+#include <vtkMapper.h>
//=======================================================================
// name : HYDROGUI_VTKPrs
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();
}
//=======================================================================
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 );
+ }
+}
#define HYDROGUI_VTKPrs_H
#include <HYDROData_Entity.h>
+#include <HYDROData_AltitudeObject.h>
#include <SALOME_InteractiveObject.hxx>
#include <SVTK_Prs.h>
+class vtkMapper;
+
/*
Class : HYDROGUI_VTKPrs
Description : Base class for all HYDRO presentation in VTK viewer
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
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkVertex.h>
-#include <vtkLookupTable.h>
+#include <vtkScalarBarActor.h>
#include <QString>
-#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
vtkVertex* aVertex = vtkVertex::New();
int aZ;
- int anInvalidZ = aBathymetry->GetInvalidAltitude();
+ int anInvalidZ = InvalidZValue();
for (int i = 0; i < aNbPoints; i++ )
{
anAltPnt = anAltPoints.at( i );
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 );
}
#include <HYDROData_Bathymetry.h>
+#include <vtkScalarsToColors.h>
+#include <vtkWeakPointer.h>
+#include <vtkNew.h>
+#include <vtkPolyDataMapper.h>
+
/*
Class : HYDROGUI_VTKPrsBathymetry
Description : Presentation for Bathymetry object
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
#include <HYDROData_Bathymetry.h>
-HYDROGUI_VTKPrsBathymetryDriver::HYDROGUI_VTKPrsBathymetryDriver()
+HYDROGUI_VTKPrsBathymetryDriver::HYDROGUI_VTKPrsBathymetryDriver( vtkScalarBarActor* theScalarBar )
{
+ myScalarBar = theScalarBar;
}
HYDROGUI_VTKPrsBathymetryDriver::~HYDROGUI_VTKPrsBathymetryDriver()
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;
#ifndef HYDROGUI_VTKPrsBathymetryDRIVER_H
#define HYDROGUI_VTKPrsBathymetryDRIVER_H
-#include <HYDROGUI_VTKPrsDriver.h>
+#include "HYDROGUI_VTKPrsDriver.h"
+
+#include <vtkScalarBarActor.h>
/**
* \class HYDROGUI_VTKPrsBathymetryDriver
/**
* \brief Constructor.
*/
- HYDROGUI_VTKPrsBathymetryDriver();
+ HYDROGUI_VTKPrsBathymetryDriver( vtkScalarBarActor* theScalarBar );
/**
* \brief Destructor.
*/
virtual bool Update( const Handle(HYDROData_Entity)& theObj,
HYDROGUI_VTKPrs*& thePrs );
+
+private:
+ vtkScalarBarActor* myScalarBar;
};
#endif
#include "HYDROGUI_VTKPrsBathymetryDriver.h"
#include "HYDROGUI_Tool.h"
+#include "HYDROData_Tool.h"
#include <SVTK_ViewModel.h>
#include <SVTK_ViewWindow.h>
#include <SALOME_ListIO.hxx>
#include <SUIT_ViewManager.h>
#include <SUIT_Accel.h>
+#include <vtkLookupTable.h>
+#include <vtkRenderer.h>
+#include <vtkWindow.h>
+#include <vtkActor2DCollection.h>
+
#include <QVector>
+#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()
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<SVTK_ViewWindow*>(
+ 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++ )
{
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
{
}
}
+ if ( isChanged )
+ {
+ // Show colors legend bar
+ if ( aView )
+ {
+ aView->getRenderer()->AddActor2D( myScalarBar.GetPointer() );
+ }
+ }
+
if ( theDoFitAll )
{
// Repaint is done inside OnFitAll()
{
if ( !myDriver )
{
- myDriver = new HYDROGUI_VTKPrsBathymetryDriver();
+ myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBar.GetPointer() );
}
aDriver = myDriver;
}
{
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
#define HYDROGUI_VTKPRSDISPLAYER_H
#include "HYDROGUI_AbstractDisplayer.h"
+#include <vtkNew.h>
+#include <vtkScalarBarActor.h>
class HYDROGUI_VTKPrsDriver;
*/
virtual ~HYDROGUI_VTKPrsDisplayer();
-public:
/**
* \brief Force the specified objects to be updated.
* \param theObjs sequence of objects to update
*/
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.
*/
HYDROGUI_VTKPrsDriver* getDriver( const Handle(HYDROData_Entity)& theObj );
- HYDROGUI_VTKPrsDriver* myDriver;
+ HYDROGUI_VTKPrsDriver* myDriver;
+
+ vtkNew< vtkScalarBarActor > myScalarBar; //!< The colors legend presentation
};
#endif