#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 <vtkLookupTable.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
vtkPolyData* aVertexGrid = vtkPolyData::New();
aVertexGrid->Allocate( aNbPoints );
+ vtkDoubleArray* aZValues = vtkDoubleArray::New();
+ aZValues->Allocate( aNbPoints );
+
vtkVertex* aVertex = vtkVertex::New();
+ int aZ;
+ int anInvalidZ = InvalidZValue();
for (int i = 0; i < aNbPoints; i++ )
{
anAltPnt = anAltPoints.at( i );
- aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), anAltPnt.Z() );
+ aZ = anAltPnt.Z();
+ if ( ValuesLessEquals( aZ, anInvalidZ ) )
+ {
+ aZ = Z_MAX;
+ }
+ else
+ {
+ aZ = -aZ;
+ }
+ 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 );
+ aVertexGrid->GetPointData()->SetScalars( aZValues );
+
+ // Update the lookup table range if this bathymetry is out of it
+ if ( myLookupTable )
+ {
+ double* aRange = aZValues->GetRange();
+ myInternalZRange[0] = -aRange[1];
+ myInternalZRange[1] = -aRange[0];
+
+ 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[1], -aGlobalRange[0] );
+ myMapper->ScalarVisibilityOn();
+ myMapper->SetScalarModeToUsePointData();
+
+
+ vtkLookupTable* aTable = vtkLookupTable::New();
+ vtkLookupTable* aGlobalTable = vtkLookupTable::SafeDownCast( myLookupTable );
+ double* aHueRange = aGlobalTable->GetHueRange();
+ // Revert hue range to keep it the same as for appropriate positive Z values in scalar bar
+ aTable->SetHueRange( aHueRange[1], aHueRange[0] );
+ aTable->SetSaturationRange( aGlobalTable->GetSaturationRange() );
+ // Revert the Z values range from positive to negative to show them as depth
+ aTable->SetTableRange( -aGlobalRange[1], -aGlobalRange[0] );
+ aTable->SetValueRange( aGlobalTable->GetValueRange() );
+ aTable->SetAlphaRange( aGlobalTable->GetAlphaRange() );
+ aTable->SetNumberOfColors( aGlobalTable->GetNumberOfColors() );
+ aTable->Build();
+
+ myMapper->SetLookupTable( aTable );
+ aTable->Delete();
+// myMapper->SetLookupTable( myLookupTable );
+ }
+
+ myMapper->SetInputData( aVertexGrid );
+
SALOME_Actor* anActor = SALOME_Actor::New();
- anActor->SetMapper( aMapper );
+ 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);
+
+ anActor->Delete();
+ aVertexGrid->Delete();
+ aZValues->Delete();
}
}
}