Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_VTKPrsBathymetry.cxx
index 381923d88e483bd101664345e9bf874b6d2e7c53..84d5b8e76ace726946fd409da2808b276605a7ca 100644 (file)
@@ -34,6 +34,7 @@
 #include <vtkPolyDataMapper.h>
 #include <vtkVertex.h>
 #include <vtkScalarBarActor.h>
+#include <vtkLookupTable.h>
 
 #include <QString>
 
@@ -112,23 +113,16 @@ void HYDROGUI_VTKPrsBathymetry::compute()
       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();
-      
       // Update the lookup table range if this bathymetry is out of it
       if ( myLookupTable )
       {
-        aZValues->GetRange( myInternalZRange );
+        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;
+        bool anIsUpdated = false;
         if (  ValuesEquals( aGlobalRange[0], anInvalidZ ) || ( aGlobalRange[0] > myInternalZRange[0] ) )
         {
           aGlobalRange[0] = myInternalZRange[0];
@@ -147,10 +141,27 @@ void HYDROGUI_VTKPrsBathymetry::compute()
           myLookupTable->Build();
         }
 
-        myMapper->SetScalarRange( aGlobalRange );
+        myMapper->SetScalarRange( -aGlobalRange[1], -aGlobalRange[0] );
         myMapper->ScalarVisibilityOn();
         myMapper->SetScalarModeToUsePointData();
-        myMapper->SetLookupTable( myLookupTable );
+
+
+        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 );
@@ -159,6 +170,10 @@ void HYDROGUI_VTKPrsBathymetry::compute()
       anActor->SetMapper( myMapper.GetPointer() );
       anActor->setIO( getIO() );
       AddObject( anActor );
+
+      anActor->Delete();
+      aVertexGrid->Delete();
+      aZValues->Delete();
     }
   }
 }