#include "HYDROGUI_VTKPrsBathymetry.h"
#include <HYDROData_Entity.h>
+#include <HYDROData_Tool.h>
#include <SALOME_Actor.h>
#include <gp_XYZ.hxx>
+#include <vtkDoubleArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
+#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkVertex.h>
+#include <vtkScalarBarActor.h>
#include <QString>
+/*! \def Z_MAX
+ \brief Maximum Z value used in bathymetry presentation.
+
+ This value is used instead of invalid values.
+*/
+#define Z_MAX 1
+
//=======================================================================
// name : HYDROGUI_VTKPrsBathymetry
// Purpose : Constructor
//================================================================
void HYDROGUI_VTKPrsBathymetry::compute()
{
+ HYDROGUI_VTKPrs::compute();
+
if ( !getObject().IsNull() )
{
Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
if ( !aBathymetry.IsNull() )
{
HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints();
- int aNbPoints = anAltPoints.length();
+ int aNbPoints = anAltPoints.Length();
HYDROData_Bathymetry::AltitudePoint anAltPnt;
vtkPoints* aPoints = vtkPoints::New();
vtkPolyData* aVertexGrid = vtkPolyData::New();
aVertexGrid->Allocate( aNbPoints );
+ vtkDoubleArray* aZValues = vtkDoubleArray::New();
+ aZValues->Allocate( aNbPoints );
+
vtkVertex* aVertex = vtkVertex::New();
+ double aZ;
+ int anInvalidZ = InvalidZValue();
for (int i = 0; i < aNbPoints; i++ )
{
- anAltPnt = anAltPoints.at( i );
- aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), anAltPnt.Z() );
+ anAltPnt = anAltPoints.Value( i );
+ aZ = anAltPnt.Z();
+ if ( ValuesLessEquals( aZ, anInvalidZ ) )
+ {
+ aZ = Z_MAX; // If Z value is invalid then use Z_MAX
+ }
+ aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), aZ );
aVertex->GetPointIds()->SetId( 0, i );
aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
+ aZValues->InsertNextValue( aZ );
}
aVertex->Delete();
aVertexGrid->SetPoints( aPoints );
- vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
- aMapper->SetInputData( aVertexGrid );
- SALOME_Actor* anActor = SALOME_Actor::New();
- anActor->SetMapper( aMapper );
+ aVertexGrid->GetPointData()->SetScalars( aZValues );
+
+ // 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 = false;
+ 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 = getActor<SALOME_Actor>(this);
+ anActor->SetMapper( myMapper.GetPointer() );
anActor->setIO( getIO() );
- //anActor->setName( aBathymetry->GetName().toLatin1() );
AddObject( anActor );
- //anActor.AddPosition(0, 0, 6);
- //anActor.GetProperty().SetDiffuseColor(1, 1, 1);
+
+ aVertexGrid->Delete();
+ aZValues->Delete();
}
}
}