]> OCCT Git - occt-copy.git/commitdiff
0031149: Visualization - using clipping planes for FitAll of V3d_View CR31149
authornds <nds@opencascade.com>
Mon, 11 Nov 2019 11:04:39 +0000 (14:04 +0300)
committernds <nds@opencascade.com>
Mon, 11 Nov 2019 11:06:04 +0000 (14:06 +0300)
(cherry picked from commit 60d61bea5e6bdb2a20c51bc1f27da2133ec60ca7)

src/AIS/AIS_InteractiveContext.hxx
src/AIS/AIS_InteractiveContext_2.cxx
src/Graphic3d/Graphic3d_CStructure.hxx
src/Graphic3d/Graphic3d_CView.cxx
src/Graphic3d/Graphic3d_CView.hxx
src/Graphic3d/Graphic3d_Layer.cxx
src/Graphic3d/Graphic3d_Layer.hxx
src/OpenGl/OpenGl_Structure.cxx
src/OpenGl/OpenGl_Structure.hxx
src/OpenGl/OpenGl_View.cxx
src/OpenGl/OpenGl_View.hxx

index d897b044c5523ea7f936bdb99b93eb9098963a04..de2065ce609ba14f5f54cff4da7bcfe6b5ba3f39 100644 (file)
@@ -701,6 +701,9 @@ public: //! @name immediate mode rendering
   //! Redraws immediate structures in all views of the viewer given taking into account its visibility.
   void RedrawImmediate (const Handle(V3d_Viewer)& theViewer) { myMainPM->RedrawImmediate (theViewer); }
 
+  //! Change state to reset V3d_View bounding boxes. It should be used after a clipping plane was changed
+  Standard_EXPORT void InvalidateBoundingBox();
+
 public: //! @name management of active Selection Modes
 
   //! Activates or deactivates the selection mode for specified object.
index 9ce6fa886fc6bbbc90d1ead31e8b6853e17a6524..97ea8cf4f1888905add30633c65e56eaae962a31 100644 (file)
@@ -454,3 +454,17 @@ Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
   myMainPM->EndImmediateDraw (myMainVwr);
   return Standard_True;
 }
+
+//=======================================================================
+//function : InvalidateBoundingBox
+//purpose  :
+//=======================================================================
+
+void AIS_InteractiveContext::InvalidateBoundingBox()
+{
+  const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
+  for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->View()->InvalidateAllLayerBoundingBox();
+  }
+}
index d7c9f7caa0758e06f46c714f7fb48f01303c8f97..ac23858994b321666a52ed6e1a2f872b6a36ef50 100644 (file)
@@ -133,6 +133,9 @@ public:
   //! highlight flag is set to true
   const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
 
+  //! Returns true if the structure is clipped with set planes
+  virtual Standard_Boolean IsClipped (const Handle(Graphic3d_SequenceOfHClipPlane)& theClipPlane) const  = 0;
+
 public:
 
   //! Returns FALSE if the structure hits the current view volume, otherwise returns TRUE.
index 829151db39beb063d0ea0ddc24e609fa60843385..2b3fd492c4c364df99e5ad8c336f3e181fbb5b57 100644 (file)
@@ -369,6 +369,18 @@ void Graphic3d_CView::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theL
     }
   }
 }
+// =======================================================================
+// function : InvalidateAllLayerBoundingBox
+// purpose  :
+// =======================================================================
+void Graphic3d_CView::InvalidateAllLayerBoundingBox()
+{
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (Layers()); aLayerIter.More(); aLayerIter.Next())
+  {
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    aLayer->InvalidateBoundingBox();
+  }
+}
 
 // =======================================================================
 // function : ContainsFacet
@@ -436,7 +448,8 @@ Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxili
     Bnd_Box aBox = aLayer->BoundingBox (Identification(),
                                         aCamera,
                                         aWinSize.x(), aWinSize.y(),
-                                        theToIncludeAuxiliary);
+                                        theToIncludeAuxiliary,
+                                        ClipPlanes());
     aResult.Add (aBox);
   }
   return aResult;
index ac0df39b97e1a67129f3b5a5a73c40c5931ca70f..eb6b3fab283bb28f9e1a9686cc13c62849709c15 100644 (file)
@@ -298,6 +298,9 @@ public:
   //! Returns the bounding box of all structures displayed in the Z layer.
   Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId);
 
+  //! Returns the bounding box of all structures displayed in the Z layer.
+  Standard_EXPORT virtual void InvalidateAllLayerBoundingBox();
+
   //! Remove Z layer from the specified view. All structures
   //! displayed at the moment in layer will be displayed in default layer
   //! ( the bottom-level z layer ). To unset layer ID from associated
index 70a4eaf439e70396d266eb5a4379bf8ee4d0411e..c555c7bd719862cfaae5b278ee49a4dfb9a3d757 100644 (file)
@@ -179,7 +179,8 @@ Bnd_Box Graphic3d_Layer::BoundingBox (Standard_Integer theViewId,
                                       const Handle(Graphic3d_Camera)& theCamera,
                                       Standard_Integer theWindowWidth,
                                       Standard_Integer theWindowHeight,
-                                      Standard_Boolean theToIncludeAuxiliary) const
+                                      Standard_Boolean theToIncludeAuxiliary,
+                                      const Handle(Graphic3d_SequenceOfHClipPlane)& theClipPlanes) const
 {
   updateBVH();
 
@@ -202,6 +203,11 @@ Bnd_Box Graphic3d_Layer::BoundingBox (Standard_Integer theViewId,
           continue;
         }
 
+        if (aStructure->IsClipped (theClipPlanes) || aStructure->IsClipped (aStructure->ClipPlanes()))
+        {
+          continue;
+        }
+
         // "FitAll" operation ignores object with transform persistence parameter
         // but adds transform persistence point in a bounding box of layer (only zoom pers. objects).
         if (!aStructure->TransformPersistence().IsNull())
index 820113e13fd0ac78e935364836e8ba6a7a42d07b..b314e6c6a72c5ba49ec0a8c88f62ab289b7c45db 100644 (file)
@@ -24,6 +24,8 @@
 #include <NCollection_IndexedMap.hxx>
 #include <NCollection_Sequence.hxx>
 
+class Graphic3d_SequenceOfHClipPlane;
+
 //! Defines index map of structures.
 typedef NCollection_IndexedMap<const Graphic3d_CStructure*> Graphic3d_IndexedMapOfStructure;
 
@@ -110,7 +112,8 @@ public:
                                        const Handle(Graphic3d_Camera)& theCamera,
                                        Standard_Integer theWindowWidth,
                                        Standard_Integer theWindowHeight,
-                                       Standard_Boolean theToIncludeAuxiliary) const;
+                                       Standard_Boolean theToIncludeAuxiliary,
+                                       const Handle(Graphic3d_SequenceOfHClipPlane)& theClipPlanes = Handle(Graphic3d_SequenceOfHClipPlane)()) const;
 
   //! Returns zoom-scale factor.
   Standard_EXPORT Standard_Real considerZoomPersistenceObjects (Standard_Integer theViewId,
index 927a4a0eacd665779c43fcc1172d5a6f42ffce20..24030482826b8cb29f13cdc9cb434a1fb09db5ff 100644 (file)
@@ -234,6 +234,94 @@ Standard_Boolean OpenGl_Structure::IsRaytracable() const
      &&  myInstancedStructure->IsRaytracable();
 }
 
+// =======================================================================
+// function : IsClipped
+// purpose  :
+// =======================================================================
+Standard_Boolean OpenGl_Structure::IsClipped (const Handle(Graphic3d_SequenceOfHClipPlane)& theClipPlane) const
+{
+  // True if structure is fully clipped
+  bool isClipped = false;
+  bool hasDisabled = false;
+
+  //const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+  //if (aCtx->Clipping().IsClippingOrCappingOn())
+  {
+    const Graphic3d_BndBox3d& aBBox = BoundingBox();
+    if (!theClipPlane.IsNull()
+      && theClipPlane->ToOverrideGlobal())
+    {
+      //aCtx->ChangeClipping().DisableGlobal();
+      //hasDisabled = aCtx->Clipping().HasDisabled();
+    }
+    else if (!myTrsfPers.IsNull())
+    {
+      if (myTrsfPers->IsZoomOrRotate())
+      {
+        // Zoom/rotate persistence object lives in two worlds at the same time.
+        // Global clipping planes can not be trivially applied without being converted
+        // into local space of transformation persistence object.
+        // As more simple alternative - just clip entire object by its anchor point defined in the world space.
+        const gp_Pnt anAnchor = myTrsfPers->AnchorPoint();
+        for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (theClipPlane); aPlaneIt.More(); aPlaneIt.Next()/*, ++aPlaneId*/)
+        {
+          const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+        //for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More() && aPlaneIt.IsGlobal(); aPlaneIt.Next())
+        ///for (OpenGl_ClippingIterator aPlaneIt (myClipPlanes); aPlaneIt.More() && aPlaneIt.IsGlobal(); aPlaneIt.Next())
+        //{
+        //  const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+          if (!aPlane->IsOn())
+          {
+            continue;
+          }
+
+          // check for clipping
+          const Graphic3d_Vec4d aCheckPnt (anAnchor.X(), anAnchor.Y(), anAnchor.Z(), 1.0);
+          if (aPlane->ProbePoint (aCheckPnt) == Graphic3d_ClipState_Out)
+          {
+            isClipped = true;
+            break;
+          }
+        }
+      }
+
+      //aCtx->ChangeClipping().DisableGlobal();
+      //hasDisabled = aCtx->Clipping().HasDisabled();
+    }
+
+    // Set of clipping planes that do not intersect the structure,
+    // and thus can be disabled to improve rendering performance
+    if (aBBox.IsValid()
+     && myTrsfPers.IsNull())
+    {
+      //for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More(); aPlaneIt.Next())
+      //{
+      //  const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+      for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (theClipPlane); aPlaneIt.More(); aPlaneIt.Next()/*, ++aPlaneId*/)
+      {
+        const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+        if (!aPlane->IsOn())//aPlaneIt.IsDisabled())
+        {
+          continue;
+        }
+
+        const Graphic3d_ClipState aBoxState = aPlane->ProbeBox (aBBox);
+        if (aBoxState == Graphic3d_ClipState_In)
+        {
+          //aCtx->ChangeClipping().SetEnabled (aPlaneIt, false);
+          //hasDisabled = true;
+        }
+        else if (aBoxState == Graphic3d_ClipState_Out && myBndBoxClipCheck)
+        {
+          isClipped = true;
+          break;
+        }
+      }
+    }
+  }
+  return isClipped; 
+}
+
 // =======================================================================
 // function : UpdateRaytracableState
 // purpose  :
index 58c3a0e29f7a4f6955a53e2196367b3c89849279..0adf9e690ddbb1476cf617b6dbeb672a930f074a 100644 (file)
@@ -125,6 +125,9 @@ public:
   //! Is the structure ray-tracable (contains ray-tracable elements)?
   Standard_Boolean IsRaytracable() const;
 
+  //! Returns true if the structure is clipped with set planes
+  Standard_EXPORT virtual Standard_Boolean IsClipped (const Handle(Graphic3d_SequenceOfHClipPlane)& theClipPlane) const;
+
   //! Update render transformation matrix.
   Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE;
 
index 17f44efa7ce0297533fcbabfeb815de53ca7c1d6..899af4c3c96a456a507ebcea78d264410e63ecf8 100644 (file)
@@ -807,6 +807,17 @@ void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructu
   myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
 }
 
+//=======================================================================
+//function : SetClipPlanes
+//purpose  :
+//=======================================================================
+void OpenGl_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
+{
+  myClipPlanes = thePlanes;
+
+  InvalidateAllLayerBoundingBox();
+}
+
 //=======================================================================
 //function : DiagnosticInformation
 //purpose  :
index 1b05ee72006ab25d9df54f2cf0321c30d06534ba..a0061a91508d73a64fe9303971e7ce8ce5095048 100644 (file)
@@ -260,7 +260,7 @@ public:
   virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
 
   //! Sets list of clip planes for the view.
-  virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
+  Standard_EXPORT virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE;
 
   //! Fill in the dictionary with diagnostic info.
   //! Should be called within rendering thread.