]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #432: bathymetry in OCCT viewer
authorasl <asl@opencascade.com>
Tue, 26 Aug 2014 07:01:34 +0000 (07:01 +0000)
committerasl <asl@opencascade.com>
Tue, 26 Aug 2014 07:01:34 +0000 (07:01 +0000)
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h
src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx
src/HYDROGUI/HYDROGUI_OCCDisplayer.h
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Shape.h
src/HYDROGUI/HYDROGUI_ShowHideOp.cxx
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx

index bd3b1a16fa0fe47439fc07b4111fd68ba84b5baf..6f2a8e0d35c407de0d7f1140b1d0371f6aae45a9 100644 (file)
@@ -937,6 +937,23 @@ void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
 }
 
 /////////////////// OCC SHAPES PROCESSING
+QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int  theViewId,
+                                                         ObjectKind theKind ) const
+{
+  QList<HYDROGUI_Shape*> aResult;
+
+  if ( myShapesMap.contains( theViewId ) )
+  {
+    const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
+    foreach ( HYDROGUI_Shape* aShape, aViewShapes )
+    {
+      if( aShape && aShape->getObject()->GetKind()==theKind )
+        aResult.append( aShape );
+    }
+  }
+  return aResult;
+}
+
 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
                                                  const Handle(HYDROData_Entity)& theObject ) const
 {
index e2dee3ee51dfc18f657a5f7f5bd2be705df80c3b..963a734e19924df3e8aec6db040d2decd0ef39a7 100644 (file)
@@ -135,6 +135,8 @@ public:
    */
   void                            setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
                                                  const bool theState = true );
+  QList<HYDROGUI_Shape*>          getObjectShapes( const int  theViewId,
+                                                   ObjectKind theKind ) const;
   HYDROGUI_Shape*                 getObjectShape( const int                       theViewId,
                                                   const Handle(HYDROData_Entity)& theObject ) const;
   void                            setObjectShape( const int                       theViewId,
index 310e84de0cdb63dd854393fc4a98ff9c9342eee5..43df09486392ad354db7731045661da9e197cf33 100644 (file)
@@ -34,6 +34,8 @@
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_ListOfInteractive.hxx>
 
+#include <Aspect_ColorScale.hxx>
+
 #include <TColStd_SequenceOfInteger.hxx>
 
 #include <LightApp_Application.h>
@@ -42,6 +44,7 @@
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
 
 HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule )
 : HYDROGUI_AbstractDisplayer( theModule )
@@ -120,6 +123,7 @@ void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId )
     return;
 
   module()->removeViewShapes( (size_t)aViewer );
+  UpdateColorScale( aViewer );
 }
 
 void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
@@ -138,6 +142,7 @@ void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
     module()->removeObjectShape( (size_t)aViewer, anObj );
   }
   aViewer->update();
+  UpdateColorScale( aViewer );
 }
 
 HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int                             theViewerId,
@@ -275,6 +280,8 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
   else if ( !aCtx.IsNull() ) { // TODO: determine if this code is necessary (added as a fix for issue# 359)
     aCtx->UpdateSelected();
   }
+
+  UpdateColorScale( aViewer );
 }
 
 void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId )
@@ -352,6 +359,7 @@ bool HYDROGUI_OCCDisplayer::Display( const Handle(HYDROData_Entity)& theObject,
     aRes = true;
   }
 
+  UpdateColorScale( theViewer );
   return aRes;
 }
 
@@ -377,6 +385,66 @@ void HYDROGUI_OCCDisplayer::SetZLayer( const OCCViewer_Viewer* theViewer,
 
   // Set Z layer
   if ( anObjShape ) {
-    aCtx->SetZLayer( anObjShape->getAISShape(), theZLayerId );
+    aCtx->SetZLayer( anObjShape->getAISObject(), theZLayerId );
+  }
+}
+
+void HYDROGUI_OCCDisplayer::UpdateColorScale( const OCCViewer_Viewer* theViewer )
+{
+  OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>( theViewer->getViewManager()->getActiveView() );
+  Handle(V3d_View) aView = aWnd->getViewPort()->getView();
+
+  int aViewerId = (size_t)theViewer;//TODO: check if viewer id is correct
+  QList<HYDROGUI_Shape*> aBaths = module()->getObjectShapes( aViewerId, KIND_BATHYMETRY );
+
+  bool isDisplayColorScale = !aBaths.empty();
+  Standard_Real anXPos = 0.05; //TODO
+  Standard_Real anYPos = 0.1; //TODO
+  Standard_Real aWidth = 0.2; //TODO
+  Standard_Real aHeight = 0.5; //TODO
+  Standard_Integer aTextHeight = 14; //TODO
+  Standard_Integer aNbIntervals = 20; //TODO
+  TCollection_ExtendedString aColorScaleTitle = "";//TODO
+
+  Standard_Real aColorScaleMin = 0, aColorScaleMax = 1, aMin, aMax;
+  bool isFirst = true;
+  foreach( HYDROGUI_Shape* aBathShape, aBaths )
+  {
+    aBathShape->GetRange( aMin, aMax );
+
+    if( isFirst || aMin < aColorScaleMin )
+      aColorScaleMin = aMin;
+    if( isFirst || aMax > aColorScaleMax )
+      aColorScaleMax = aMax;
+
+    isFirst = false;
+  }
+
+  if( isDisplayColorScale )
+  {
+    Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
+    if( !aColorScale.IsNull() )
+    {
+      aColorScale->SetXPosition( anXPos );
+      aColorScale->SetYPosition( anYPos );
+      aColorScale->SetWidth( aWidth );
+      aColorScale->SetHeight( aHeight );
+
+      aColorScale->SetTextHeight( aTextHeight );
+      aColorScale->SetNumberOfIntervals( aNbIntervals );
+
+      aColorScale->SetTitle( aColorScaleTitle );
+      aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
+
+      foreach( HYDROGUI_Shape* aBathShape, aBaths )
+        aBathShape->UpdateWithColorScale( aColorScale );
+    }
+    if( !aView->ColorScaleIsDisplayed() )
+      aView->ColorScaleDisplay();
+  }
+  else
+  {
+    if( aView->ColorScaleIsDisplayed() )
+      aView->ColorScaleErase();
   }
-}
\ No newline at end of file
+}
index ffa2ef9fd2e2684240a1d634805666321a84e53f..95b391cf2ab85dd7f94c8a928da234676b337021 100644 (file)
@@ -110,6 +110,8 @@ protected:
    */
   void                            purgeObjects( const int theViewerId );
 
+  void UpdateColorScale( const OCCViewer_Viewer* );
+
 private:
   /**
    * \brief Creates new OCC shape.
index eb05a9b4dd816d214b3f9fb818d9e4a49b1d7e32..f18e3870720d810cd0af10f59c0e7e2086752a01 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <AIS_Drawer.hxx>
 #include <AIS_TexturedShape.hxx>
-
+#include <AIS_PointCloud.hxx>
 #include <V3d_Viewer.hxx>
 
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_MaterialAspect.hxx>
 
+#include <Aspect_ColorScale.hxx>
+
 #include <HYDROData_Channel.h>
 #include <HYDROData_Document.h>
+#include <HYDROData_Bathymetry.h>
 #include <HYDROData_DummyObject3D.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_ImmersibleZone.h>
@@ -66,7 +69,7 @@
 #include <Prs3d_ShadingAspect.hxx>
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
-
+#include <Prs3d_PointAspect.hxx>
 #include <SUIT_MessageBox.h>
 
 #include <QColor>
@@ -397,6 +400,11 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
 
       setShape( aCompound, false, false );  
     }
+    else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Bathymetry) ) )
+    {
+      buildShape();
+      updateShape( false, false );
+    }
   }
  
   if ( myShape.IsNull() || !isVisible() )
@@ -584,29 +592,48 @@ void HYDROGUI_Shape::setZLayer( const int theZLayer )
     myContext->SetZLayer( myShape, myZLayer );
 }
 
+#include <NCollection_Sequence.hxx>
 void HYDROGUI_Shape::buildShape()
 {
   // Erase previously created shape
   erase();
 
-  if ( myTopoShape.IsNull() ) {
+  Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( myObject );
+  bool isBath = !aBath.IsNull();
+
+  if( !isBath && myTopoShape.IsNull() ) {
     myShape.Nullify();
     return;
   }
 
   QString aTextureFileName = getTextureFileName();
   bool anIsTexture = !aTextureFileName.isEmpty();
-
   if ( anIsTexture )
   {
     myShape = new AIS_TexturedShape( myTopoShape );
   }
+  else if( isBath )
+  {
+    Handle_AIS_PointCloud aPntCloud = new AIS_PointCloud();
+    aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0));
+
+    myShape = aPntCloud;
+    const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
+    int aLower = aBathPoints.Lower();
+    int anUpper = aBathPoints.Upper();
+    myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
+    myColors = new Quantity_HArray1OfColor( aLower, anUpper );
+    for( int i=aLower; i<=anUpper; i++ )
+      myCoords->SetValue( i, aBathPoints.Value( i ) );
+  }
   else
   {
     myShape = new AIS_Shape( myTopoShape );
   }
 
-  myShape->SetHLRAngleAndDeviation( 0.001 );
+  Handle_AIS_Shape anAISShape = Handle_AIS_Shape::DownCast( myShape );
+  if( !anAISShape.IsNull() )
+    anAISShape ->SetHLRAngleAndDeviation( 0.001 );
 
   if ( !myObject.IsNull() )
     myShape->SetOwner( myObject );
@@ -733,38 +760,41 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
                                getQuantityColorVal( theColor.green() ),
                                getQuantityColorVal( theColor.blue() ),
                                Quantity_TOC_RGB );
-
   
-  if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode
-  {
-    myShape->SetColor( aBorderColor );
-  } else if ( myDisplayMode == AIS_Shaded )
+  if( !myTopoShape.IsNull() )
   {
-    if ( theColor.alpha() == 0 )
+    if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode
     {
-      anAttributes->SetFaceBoundaryDraw( false );
+      myShape->SetColor( aBorderColor );
     }
-    else
+    else if ( myDisplayMode == AIS_Shaded )
     {
-      anAttributes->SetFaceBoundaryDraw( true );
-
-      Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
-      if ( !aBoundaryAspect.IsNull() )
+      if ( theColor.alpha() == 0 )
       {
-        aBoundaryAspect->SetColor( aBorderColor );
-        anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
+        anAttributes->SetFaceBoundaryDraw( false );
       }
-      Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect();
-      if ( !aWireAspect.IsNull() )
+      else
       {
-        aWireAspect->SetColor( aBorderColor );
-        anAttributes->SetWireAspect( aWireAspect );
+        anAttributes->SetFaceBoundaryDraw( true );
+  
+        Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
+        if ( !aBoundaryAspect.IsNull() )
+        {
+          aBoundaryAspect->SetColor( aBorderColor );
+          anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
+        }
+        Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect();
+        if ( !aWireAspect.IsNull() )
+        {
+          aWireAspect->SetColor( aBorderColor );
+          anAttributes->SetWireAspect( aWireAspect );
+        }
       }
     }
-  }
-  else if ( myDisplayMode == AIS_WireFrame )
-  {
-    myShape->SetColor( aBorderColor );
+    else if ( myDisplayMode == AIS_WireFrame )
+    {
+      myShape->SetColor( aBorderColor );
+    }
   }
 }
 
@@ -815,3 +845,36 @@ QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeL
   }
   return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
 }
+
+void HYDROGUI_Shape::GetRange( double& theMin, double& theMax ) const
+{
+  theMin = 0;
+  theMax = 0;
+  if( myCoords.IsNull() )
+    return;
+
+  bool isFirst = true;
+  for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
+  {
+    double aValue = myCoords->Value( i ).Z();
+    if( isFirst || aValue < theMin )
+      theMin = aValue;
+    if( isFirst || aValue > theMax )
+      theMax = aValue;
+    isFirst = false;
+  }
+}
+
+void HYDROGUI_Shape::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
+{
+  for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
+  {
+    double z = myCoords->Value( i ).Z();
+    Quantity_Color aColor;
+    theColorScale->FindColor( z, aColor );
+    myColors->SetValue( i, aColor );
+  }
+  Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( myShape );
+  aPntCloud->SetPoints( myCoords, myColors );
+  myContext->Redisplay( aPntCloud, Standard_False );
+}
index 6226f542fbcff620d7907c1012eef022af2d6007..c5b3b41ffe9f4b9d242505dd85daea71f9cf02d0 100644 (file)
 #define HYDROGUI_SHAPE_H
 
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_Shape.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <Aspect_ColorScale.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <Quantity_HArray1OfColor.hxx>
 
 #include <HYDROData_Entity.h>
 
@@ -99,10 +102,13 @@ public:
                                                  const bool     theIsUpdateViewer = true );
   virtual QString            getTextureFileName() const;
 
-  virtual Handle(AIS_Shape)  getAISShape() const { return myShape; }
+  virtual Handle(AIS_InteractiveObject)  getAISObject() const { return myShape; }
 
   void                       setZLayer( const int theZLayer );
 
+  void GetRange( double& theMin, double& theMax ) const;
+  void UpdateWithColorScale( const Handle(Aspect_ColorScale)& );
+
 protected:
   virtual void               buildShape();
   virtual void               updateShape( const bool theToDisplay      = true,
@@ -123,7 +129,7 @@ private:
 private:
   Handle(AIS_InteractiveContext) myContext;
   Handle(HYDROData_Entity)       myObject;
-  Handle(AIS_Shape)              myShape;
+  Handle(AIS_InteractiveObject)  myShape;
 
   int                            myZLayer;
 
@@ -139,6 +145,9 @@ private:
   QColor                         myHighlightColor;
 
   QString                        myTextureFileName;
+
+  Handle_TColgp_HArray1OfPnt     myCoords;
+  Handle_Quantity_HArray1OfColor myColors;
 };
 
 #endif
index d754a33a9d55c336e3d4853a085a768f5537bd7f..4dba86de8bea240269a8c7c8135c6f9e89253be6 100644 (file)
@@ -147,7 +147,11 @@ void HYDROGUI_ShowHideOp::startOperation()
         }
         else if ( anObject->GetKind() == KIND_BATHYMETRY && aVisibility )
         {
-          if ( !(anUpdateFlags & UF_VTKViewer) )
+          if ( anUpdateFlags & UF_OCCViewer )
+          {
+            aModule->setObjectVisible( aViewId, anObject, aVisibility );
+          }
+          else if ( !(anUpdateFlags & UF_VTKViewer) )
           {
             // Activate VTK viewer if show a bathymetry
             aVTKMgr = aModule->getApp()->viewManager( SVTK_Viewer::Type() );
index 51404eaed7eb174fdea98388e12def5033e3eca9..75526f52e295f1b136eb90d9b85a84d2875bb616 100644 (file)
@@ -229,7 +229,8 @@ bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& the
          anObjectKind == KIND_STREAM ||
          anObjectKind == KIND_CHANNEL ||
          anObjectKind == KIND_DIGUE ||
-         anObjectKind == KIND_DUMMY_3D
+         anObjectKind == KIND_DUMMY_3D || 
+         anObjectKind == KIND_BATHYMETRY
 #ifdef DEB_GROUPS
          || anObjectKind == KIND_SHAPES_GROUP ||
          anObjectKind == KIND_SPLITTED_GROUP
index 97d0d6c1237256fa0bffe31157b63819054ada1e..1500654565d928fe36a92c8e3146093abc1f9816 100644 (file)
@@ -26,7 +26,7 @@
 #include <HYDROData_Tool.h>
 
 #include <SALOME_Actor.h>
-#include <gp_XYZ.hxx>
+#include <gp_Pnt.hxx>
 #include <vtkDoubleArray.h>
 #include <vtkPoints.h>
 #include <vtkPolyData.h>