Salome HOME
Fix for the bug #130: bathymetry sign is wrong
authorrkv <rkv@opencascade.com>
Mon, 25 Nov 2013 07:51:38 +0000 (07:51 +0000)
committerrkv <rkv@opencascade.com>
Mon, 25 Nov 2013 07:51:38 +0000 (07:51 +0000)
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h
src/HYDROGUI/HYDROGUI_ShowHideOp.cxx
src/HYDROGUI/HYDROGUI_VTKPrs.cxx
src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx
src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx
src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h

index b5cf925c011b4daf93cee3c070a3bbb994699919..2e32038f9b523cd00cde71c8f52e68f213105d05 100644 (file)
@@ -744,7 +744,7 @@ void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId
     return;
 
   // Compute the new global Z range from the added presentation and the old global Z range.
-  double* aGlobalRange = getVTKDisplayer()->GetZRange();
+  double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
   double* aRange = theShape->getInternalZRange();
   bool anIsUpdate = false;
   if ( aRange[0] < aGlobalRange[0] )
@@ -760,7 +760,7 @@ void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId
 
   //if ( anIsUpdate )
   //{
-    updateVTKZRange( aGlobalRange );
+    updateVTKZRange( theViewId, aGlobalRange );
   //}
 
   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
@@ -791,7 +791,7 @@ void HYDROGUI_Module::removeObjectVTKPrs( const int                       theVie
 
   // Invalidate global Z range
   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
-  getVTKDisplayer()->SetZRange( anInvalidRange );
+  getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
 }
 
 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
@@ -810,14 +810,12 @@ void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
   myVTKPrsMap.remove( theViewId );
 }
 
-void HYDROGUI_Module::updateVTKZRange( double theRange[] )
+void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
 {
-  // For all VTK viewers ...
-  QList<int> aViewIdList = myVTKPrsMap.keys();
-  foreach( int aViewId, aViewIdList )
+  if ( myVTKPrsMap.contains( theViewId ) )
   {
-    // ... update all VTK presentations ...
-    const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( aViewId );
+    // For the given viewer id update all VTK presentations ...
+    const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
     HYDROGUI_VTKPrs* aShape;
     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
     {
@@ -829,7 +827,7 @@ void HYDROGUI_Module::updateVTKZRange( double theRange[] )
     }
   }
   // ... and update the global color legend scalar bar.
-  getVTKDisplayer()->SetZRange( theRange );
+  getVTKDisplayer()->SetZRange( theViewId, theRange );
 }
 /////////////////// END OF VTKPrs PROCESSING
 
@@ -928,6 +926,16 @@ void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
         removeViewShapes( (size_t)anOCCViewer );
     }
 
+    if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
+    {
+      SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
+      if ( aVTKViewer )
+      {
+        getVTKDisplayer()->DeleteScalarBar( anId );
+        removeViewShapes( (size_t)aVTKViewer );
+      }
+    }
+
     myViewManagerMap.remove( anId );
   }
 }
index 808958f64ee96844d5074ec9f93c2bc05be68000..a0a117a92bfaed27cab0e28ac4751a540f290622 100644 (file)
@@ -144,9 +144,9 @@ public:
   void                            removeObjectVTKPrs( const int                      theViewId,
                                                      const Handle(HYDROData_Entity)& theObject );
   /**
-   * Update global imposed range of Z values for VTK viewer
+   * Update global imposed range of Z values for the given VTK viewer id
    */
-  void                            updateVTKZRange( double theRange[] );
+  void                            updateVTKZRange( const int theViewId, double theRange[] );
 
   QStringList                     GetGeomObjectsToImport();
 
index d06c59f26ce4c267f84d89fd05db87ba0c3d6e84..0d3352509a60d9019a753b715a514683870b8283 100644 (file)
@@ -82,13 +82,29 @@ void HYDROGUI_ShowHideOp::startOperation()
 
   int anUpdateFlags = 0;
   SUIT_ViewManager* aVTKMgr = 0;
+  SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager();
+  if ( aViewMgr )
+  {
+    if ( aViewMgr->getType() == GraphicsView_Viewer::Type() )
+    {
+      anUpdateFlags |= UF_Viewer;
+    }
+    else if ( aViewMgr->getType() == OCCViewer_Viewer::Type() )
+    {
+      anUpdateFlags |= UF_OCCViewer;
+    }
+    else if ( aViewMgr->getType() == SVTK_Viewer::Type() )
+    {
+      anUpdateFlags |= UF_VTKViewer;
+    }
+  }
 
   // for selected objects
   if( myId == ShowId || myId == ShowOnlyId || myId == HideId )
   {
     HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
   
-    bool aVisibility = myId == ShowId || myId == ShowOnlyId;
+    bool aVisibility = myId == ShowId || myId == ShowOnlyId || myId == ShowAllId;
     Handle( HYDROData_Entity ) anObject;
     for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
     {
@@ -114,15 +130,18 @@ void HYDROGUI_ShowHideOp::startOperation()
         }
         else if ( anObject->GetKind() == KIND_BATHYMETRY && aVisibility )
         {
-          // Activate VTK viewer if show a bathymetry
-          aVTKMgr = module()->getApp()->viewManager( SVTK_Viewer::Type() );
-          if ( !aVTKMgr )
-          {
-            aVTKMgr = module()->getApp()->createViewManager( SVTK_Viewer::Type() );
-          }
-          if ( aVTKMgr )
+          if ( !(anUpdateFlags & UF_VTKViewer) )
           {
-            module()->setObjectVisible( (size_t)aVTKMgr->getViewModel(), anObject, aVisibility );
+            // Activate VTK viewer if show a bathymetry
+            aVTKMgr = module()->getApp()->viewManager( SVTK_Viewer::Type() );
+            if ( !aVTKMgr )
+            {
+              aVTKMgr = module()->getApp()->createViewManager( SVTK_Viewer::Type() );
+            }
+            if ( aVTKMgr )
+            {
+              module()->setObjectVisible( (size_t)aVTKMgr->getViewModel(), anObject, aVisibility );
+            }
           }
         }
       }
@@ -140,22 +159,6 @@ void HYDROGUI_ShowHideOp::startOperation()
     anUpdateFlags |= UF_VTKViewer;
     aVTKMgr->setShown( true );
   }
-  SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager();
-  if ( aViewMgr )
-  {
-    if ( aViewMgr->getType() == GraphicsView_Viewer::Type() )
-    {
-      anUpdateFlags |= UF_Viewer;
-    }
-    else if ( aViewMgr->getType() == OCCViewer_Viewer::Type() )
-    {
-      anUpdateFlags |= UF_OCCViewer;
-    }
-    else if ( aViewMgr->getType() == SVTK_Viewer::Type() )
-    {
-      anUpdateFlags |= UF_VTKViewer;
-    }
-  }
 
   module()->update( anUpdateFlags );
   commit();
index 671a2cdccf4192d7892f912035c246aafc4762e6..588c7c8d71d60e46144ffad190e0e4c3e43c7d24 100644 (file)
@@ -69,6 +69,6 @@ void HYDROGUI_VTKPrs::setZRange( double theRange[] )
   vtkMapper* aMapper = mapper();
   if ( aMapper )
   {
-    mapper()->SetScalarRange( myZRange );
+    mapper()->SetScalarRange( -myZRange[1], -myZRange[0] );
   }
 }
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();
     }
   }
 }
index c22b85aa109063e89126a51f7466bf6ee356ad8c..909012353d23fffc6ad6de8103e0a11e6de9a561 100644 (file)
 //#define SATURATION_START 1.0 
 //#define SATURATION_END   0.4
 
-#define HUE_START 0.
-#define HUE_END   0.0
+#define HUE_START 0.0
+#define HUE_END   0.
 #define SATURATION_START 1.0 
 #define SATURATION_END   1.0
 
 HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule )
 : HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL )
 {
-  // The invalid value is used to identify the case when the table range is not initialized yet.
-  double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue();
-  vtkLookupTable* aTable = vtkLookupTable::New();
-  aTable->SetHueRange( HUE_START, HUE_END );
-  aTable->SetSaturationRange( SATURATION_START, SATURATION_END );
-  aTable->SetTableRange( anInvalidValue, anInvalidValue );
-  aTable->SetValueRange( 1.0, 1.0 );
-  aTable->SetAlphaRange( 1.0, 1.0 );
-  aTable->SetNumberOfColors( NB_COLORS );
-  myScalarBar->SetLookupTable( aTable );
 }
 
 HYDROGUI_VTKPrsDisplayer::~HYDROGUI_VTKPrsDisplayer()
@@ -108,6 +98,27 @@ void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId )
   }
 }
 
+void HYDROGUI_VTKPrsDisplayer::DeleteScalarBar( const int theViewerId )
+{
+  SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
+  if( aViewer )
+  {
+    SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(
+      aViewer->getViewManager()->getActiveView() );
+    if ( aView )
+    {
+      if ( myScalarBars.contains( (size_t)aViewer ) )
+      {
+        vtkScalarBarActor* aScalarBar = myScalarBars[ (size_t)aViewer ];
+        if ( aView->getRenderer()->HasViewProp( aScalarBar ) )
+        {
+          aView->getRenderer()->RemoveActor2D( aScalarBar );
+        }
+      }
+    }
+  }
+}
+
 void HYDROGUI_VTKPrsDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
                                 const int theViewerId )
 {
@@ -142,20 +153,27 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
   SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
   if( aViewer )
   {
-    // Invalidate global Z range
-    double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
-    SetZRange( anInvalidRange );
     // Hide colors legend bar
     SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(
       aViewer->getViewManager()->getActiveView() );
+    vtkScalarBarActor* aScalarBar = 0;
     if ( aView )
     {
-      if ( aView->getRenderer()->HasViewProp( myScalarBar.GetPointer() ) )
+      if ( !myScalarBars.contains( (size_t)aViewer ) )
       {
-        aView->getRenderer()->RemoveActor2D( myScalarBar.GetPointer() );
+        createScalarBar( (size_t)aViewer );
+      }
+      aScalarBar = myScalarBars[ (size_t)aViewer ];
+
+      if ( aView->getRenderer()->HasViewProp( aScalarBar ) )
+      {
+        aView->getRenderer()->RemoveActor2D( aScalarBar );
       }
     }
 
+    // Invalidate global Z range
+    double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
+    SetZRange( (size_t)aViewer, anInvalidRange );
 
     int anInvalidZ = HYDROGUI_VTKPrs::InvalidZValue();
     bool isChanged = false;
@@ -171,7 +189,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
         bool anIsInserted = ( aPrs != 0 );
         if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) )
         {
-          if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( anObj ) )
+          if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( (size_t)aViewer, anObj ) )
           {
             if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
             {
@@ -186,7 +204,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
           {
 
             // Extend the global Z range if necessary
-            double* aGlobalRange = GetZRange();
+            double* aGlobalRange = GetZRange( (size_t)aViewer );
             double* aRange = aPrs->getInternalZRange();
             bool anIsUpdate = false;
             if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) )
@@ -202,7 +220,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
 
             if ( anIsUpdate )
             {
-              module()->updateVTKZRange( aGlobalRange );
+              module()->updateVTKZRange( (size_t)aViewer, aGlobalRange );
             }
 
             aViewer->Display( aPrs );
@@ -217,23 +235,24 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
       }
     }
 
-    if ( isChanged )
+    if ( aView ) 
     {
-      // Show colors legend bar
-      if ( aView )
+      if ( isChanged && aScalarBar )
       {
-        aView->getRenderer()->AddActor2D( myScalarBar.GetPointer() );
+        // Show colors legend bar
+          aView->getRenderer()->AddActor2D( aScalarBar );
       }
-    }
 
-    if ( theDoFitAll )
-    {
-      // Repaint is done inside OnFitAll()
-      aViewer->getViewManager()->getActiveView()->onAccelAction( SUIT_Accel::ZoomFit );
-    } 
-    else if ( isChanged )
-    {
-      aViewer->Repaint();
+      // Refresh the view
+      if ( theDoFitAll )
+      {
+        // Repaint is done inside OnFitAll()
+        aView->onAccelAction( SUIT_Accel::ZoomFit );
+      } 
+      else if ( isChanged )
+      {
+        aView->Repaint();
+      }
     }
   }
 }
@@ -269,7 +288,7 @@ void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId )
   }
 }
 
-HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDROData_Entity)& theObj )
+HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const int theViewId, const Handle(HYDROData_Entity)& theObj )
 {
   HYDROGUI_VTKPrsDriver* aDriver = NULL;
   ObjectKind aKind = theObj->GetKind();
@@ -277,7 +296,7 @@ HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDRODa
   {
     if ( !myDriver )
     {
-      myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBar.GetPointer() );
+      myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBars[ theViewId ] );
     }
     aDriver = myDriver;
   }
@@ -290,12 +309,33 @@ QString HYDROGUI_VTKPrsDisplayer::GetType() const
   return SVTK_Viewer::Type();
 }
 
-void HYDROGUI_VTKPrsDisplayer::SetZRange( double theRange[] )
+void HYDROGUI_VTKPrsDisplayer::SetZRange( const int theViewId, double theRange[] )
+{
+  myScalarBars[ theViewId ]->GetLookupTable()->SetRange( theRange );
+}
+
+double* HYDROGUI_VTKPrsDisplayer::GetZRange( const int theViewId ) const
 {
-  myScalarBar->GetLookupTable()->SetRange( theRange );
+  return myScalarBars[ theViewId ]->GetLookupTable()->GetRange();
 }
 
-double* HYDROGUI_VTKPrsDisplayer::GetZRange() const
+void HYDROGUI_VTKPrsDisplayer::createScalarBar( const int theViewId )
 {
-  return myScalarBar->GetLookupTable()->GetRange();
-}
\ No newline at end of file
+  if ( !myScalarBars.contains( theViewId ) )
+  {
+    // The invalid value is used to identify the case when the table range is not initialized yet.
+    double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue();
+    vtkLookupTable* aTable = vtkLookupTable::New();
+    aTable->SetHueRange( HUE_START, HUE_END );
+    aTable->SetSaturationRange( SATURATION_START, SATURATION_END );
+    aTable->SetTableRange( anInvalidValue, anInvalidValue );
+    aTable->SetValueRange( 1.0, 1.0 );
+    aTable->SetAlphaRange( 1.0, 1.0 );
+    aTable->SetNumberOfColors( NB_COLORS );
+    aTable->Build();
+    vtkSmartPointer<vtkScalarBarActor> aScalarBar = vtkScalarBarActor::New();
+    aScalarBar->SetLookupTable( aTable );
+    aTable->Delete();
+    myScalarBars.insert( theViewId, aScalarBar );
+  }
+}
index 2be387c1d1f0b0d679f0ebfd64ae86b18ed2dd85..7a47a6f8402f51b288d6fe8357d4ae43352a33f1 100644 (file)
@@ -24,8 +24,9 @@
 #define HYDROGUI_VTKPRSDISPLAYER_H
 
 #include "HYDROGUI_AbstractDisplayer.h"
-#include <vtkNew.h>
+#include <vtkSmartPointer.h>
 #include <vtkScalarBarActor.h>
+#include <QMap>
 
 class HYDROGUI_VTKPrsDriver;
 
@@ -63,12 +64,18 @@ public:
   /**
    * \brief Set the range of Z values for the color legend bar.
    */
-  void             SetZRange( double theRange[] );
+  void             SetZRange( const int theViewerId, double theRange[] );
 
   /**
    * \brief Get the range of Z values for the color legend bar.
    */
-  double*          GetZRange() const;
+  double*          GetZRange( const int theViewerId ) const;
+
+  /**
+   * \brief Delete scalar bar for the given viewer id.
+   * \param theViewerId viewer identifier
+   */
+  void             DeleteScalarBar( const int theViewerId );
 
 protected:
   /**
@@ -105,15 +112,22 @@ protected:
   void             purgeObjects( const int theViewerId );
 
 private:
+
+  /**
+   * \brief Create a new scalar bar for the given view id.
+   * \param theViewId view identifier
+   */
+  void             createScalarBar( const int theViewId );
+
   /**
    * \brief Get the presentation driver for the specified data object.
    * \param theObj data object
    */
-  HYDROGUI_VTKPrsDriver* getDriver( const Handle(HYDROData_Entity)& theObj );
+  HYDROGUI_VTKPrsDriver* getDriver( const int theViewId, const Handle(HYDROData_Entity)& theObj );
 
-  HYDROGUI_VTKPrsDriver*      myDriver;
+  HYDROGUI_VTKPrsDriver*       myDriver;
 
-  vtkNew< vtkScalarBarActor > myScalarBar; //!< The colors legend presentation
+  QMap<int, vtkSmartPointer<vtkScalarBarActor>> myScalarBars; //!< Colors legend presentations
 };
 
 #endif