Salome HOME
- Bathymethries are colored now
authorrkv <rkv@opencascade.com>
Wed, 20 Nov 2013 17:17:08 +0000 (17:17 +0000)
committerrkv <rkv@opencascade.com>
Wed, 20 Nov 2013 17:17:08 +0000 (17:17 +0000)
- Hide/show is fixed for bathymetries (however still without automatic viewer opening)

src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx
src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx
src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx

index 8a1262bd1f49f902413af6d735a57636f6d9c859..afeb1ab2bb45a2455e074ef7a8df86110cce0152 100644 (file)
@@ -27,6 +27,7 @@
 #include "HYDROGUI_Tool.h"
 
 #include <SUIT_ViewManager.h>
 #include "HYDROGUI_Tool.h"
 
 #include <SUIT_ViewManager.h>
+#include <SUIT_ViewModel.h>
 
 HYDROGUI_AbstractDisplayer::HYDROGUI_AbstractDisplayer( HYDROGUI_Module* theModule )
 : myModule( theModule )
 
 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;
 
   // 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 );
 
   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 );
       anObjectsToDisplay.Append( anObj );
+    }
+    else
+    {
+      anObjectsToErase.Append( anObj );
+    }
   }
 
   if( anObjectsToErase.Length() )
   }
 
   if( anObjectsToErase.Length() )
index 16983bf278d1978c61f3590d5ac8b5e6c1561aaf..769879de2be344ac39acb438daf4f61eab2c1dbe 100644 (file)
 #include "HYDROGUI_VTKPrsBathymetry.h"
 
 #include <HYDROData_Entity.h>
 #include "HYDROGUI_VTKPrsBathymetry.h"
 
 #include <HYDROData_Entity.h>
+#include <HYDROData_Tool.h>
 
 #include <SALOME_Actor.h>
 #include <gp_XYZ.hxx>
 
 #include <SALOME_Actor.h>
 #include <gp_XYZ.hxx>
+#include <vtkDoubleArray.h>
 #include <vtkPoints.h>
 #include <vtkPolyData.h>
 #include <vtkPoints.h>
 #include <vtkPolyData.h>
+#include <vtkPointData.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkVertex.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkVertex.h>
+#include <vtkLookupTable.h>
 
 #include <QString>
 
 
 #include <QString>
 
+#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
 //=======================================================================
 // name    : HYDROGUI_VTKPrsBathymetry
 // Purpose : Constructor
@@ -71,28 +83,56 @@ void HYDROGUI_VTKPrsBathymetry::compute()
       vtkPolyData* aVertexGrid = vtkPolyData::New();
       aVertexGrid->Allocate( aNbPoints );
 
       vtkPolyData* aVertexGrid = vtkPolyData::New();
       aVertexGrid->Allocate( aNbPoints );
 
+      vtkDoubleArray* aZValues = vtkDoubleArray::New();
+      aZValues->Allocate( aNbPoints );
+
       vtkVertex* aVertex = vtkVertex::New();
 
       vtkVertex* aVertex = vtkVertex::New();
 
+      int aZ;
+      int anInvalidZ = aBathymetry->GetInvalidAltitude();
       for (int i = 0; i < aNbPoints; i++ )
       {
         anAltPnt = anAltPoints.at( i );
       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());
         aVertex->GetPointIds()->SetId( 0, i );
         aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
+        aZValues->InsertNextValue( aZ );
       }
 
       aVertex->Delete();
 
       aVertexGrid->SetPoints( aPoints );
       }
 
       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();
       vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
+      aMapper->SetScalarRange( Z_MIN, Z_MAX );
+      aMapper->ScalarVisibilityOn();
+      aMapper->SetScalarModeToUsePointData();
+      aMapper->SetLookupTable( aLut );
       aMapper->SetInputData( aVertexGrid );
       aMapper->SetInputData( aVertexGrid );
+      
       SALOME_Actor* anActor = SALOME_Actor::New();
       anActor->SetMapper( aMapper );
       anActor->setIO( getIO() );
       SALOME_Actor* anActor = SALOME_Actor::New();
       anActor->SetMapper( aMapper );
       anActor->setIO( getIO() );
-      //anActor->setName( aBathymetry->GetName().toLatin1() );
       AddObject( anActor );
       AddObject( anActor );
-      //anActor.AddPosition(0, 0, 6);
-      //anActor.GetProperty().SetDiffuseColor(1, 1, 1);
     }
   }
 }
     }
   }
 }
index 101176f88f6d5d39b97216b0b6f2baf22f10fa29..6839219f59c5a1f03f63ed65a08d9079ec4eec83 100644 (file)
@@ -97,7 +97,10 @@ void HYDROGUI_VTKPrsDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs
       {
         aViewer->Erase( aPrs, true );
       }
       {
         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() )
       {
       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 );
         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 )
             {
           {
             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;
         }
       }
           isChanged = true;
         }
       }