From 144bba28d8aad27eed721016473fee7f0d984b39 Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 20 Nov 2013 17:17:08 +0000 Subject: [PATCH] - Bathymethries are colored now - Hide/show is fixed for bathymetries (however still without automatic viewer opening) --- src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx | 13 ++++-- src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx | 48 +++++++++++++++++++-- src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx | 22 +++++++--- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx b/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx index 8a1262bd..afeb1ab2 100644 --- a/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx @@ -27,6 +27,7 @@ #include "HYDROGUI_Tool.h" #include +#include HYDROGUI_AbstractDisplayer::HYDROGUI_AbstractDisplayer( HYDROGUI_Module* theModule ) : myModule( theModule ) @@ -77,14 +78,20 @@ void HYDROGUI_AbstractDisplayer::Update( const HYDROData_SequenceOfObjects& theO // Now dig in the data model HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay; + SUIT_ViewModel* aViewer = module()->getViewManager( theViewerId )->getViewModel(); for( int i = 1, n = theObjs.Length(); i <= n; i++ ) { const Handle(HYDROData_Entity)& anObj = theObjs.Value( i ); - if( anObj.IsNull() ) - anObjectsToErase.Append( anObj ); - else + + if( module()->isObjectVisible( (size_t)aViewer, anObj ) ) + { anObjectsToDisplay.Append( anObj ); + } + else + { + anObjectsToErase.Append( anObj ); + } } if( anObjectsToErase.Length() ) diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx index 16983bf2..769879de 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx @@ -23,16 +23,28 @@ #include "HYDROGUI_VTKPrsBathymetry.h" #include +#include #include #include +#include #include #include +#include #include #include +#include #include +#define NB_COLORS 32 +#define Z_MIN -100 +#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 // Purpose : Constructor @@ -71,28 +83,56 @@ void HYDROGUI_VTKPrsBathymetry::compute() vtkPolyData* aVertexGrid = vtkPolyData::New(); aVertexGrid->Allocate( aNbPoints ); + vtkDoubleArray* aZValues = vtkDoubleArray::New(); + aZValues->Allocate( aNbPoints ); + vtkVertex* aVertex = vtkVertex::New(); + int aZ; + int anInvalidZ = aBathymetry->GetInvalidAltitude(); 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 ); + 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 ); + SALOME_Actor* anActor = SALOME_Actor::New(); anActor->SetMapper( aMapper ); anActor->setIO( getIO() ); - //anActor->setName( aBathymetry->GetName().toLatin1() ); AddObject( anActor ); - //anActor.AddPosition(0, 0, 6); - //anActor.GetProperty().SetDiffuseColor(1, 1, 1); } } } diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx index 101176f8..6839219f 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -97,7 +97,10 @@ void HYDROGUI_VTKPrsDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs { aViewer->Erase( aPrs, true ); } - module()->removeObjectVTKPrs( (size_t)aViewer, anObj ); + if ( anObj->IsRemoved() ) + { + module()->removeObjectVTKPrs( (size_t)aViewer, anObj ); + } } } } @@ -117,7 +120,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( !anObj.IsNull() ) { - bool anIsVisible = module()->isObjectVisible( (size_t)(aViewer->getViewManager()->getViewModel()), anObj ); + bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj ); aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj ); bool anIsInserted = ( aPrs != 0 ); @@ -127,16 +130,21 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb { if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted ) { - module()->setObjectVTKPrs( theViewerId, anObj, aPrs ); - aViewer->Display( aPrs ); - isChanged = true; + module()->setObjectVTKPrs( (size_t)aViewer, anObj, aPrs ); } } } - if( aPrs && !anIsVisible ) + if( aPrs ) { - aViewer->Erase( aPrs ); + if ( anIsVisible ) + { + aViewer->Display( aPrs ); + } + else + { + aViewer->Erase( aPrs ); + } isChanged = true; } } -- 2.39.2