From d0682fb28a2959aa1c02f1ab5f322097c7639f37 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 11 Nov 2019 14:04:39 +0300 Subject: [PATCH] 0031149: Visualization - using clipping planes for FitAll of V3d_View (cherry picked from commit 60d61bea5e6bdb2a20c51bc1f27da2133ec60ca7) (cherry picked from commit 40ea9e83b83067e4e22cc533016eeebedd2c33d3) --- src/AIS/AIS_InteractiveContext.hxx | 3 + src/AIS/AIS_InteractiveContext_2.cxx | 14 ++++ src/Graphic3d/Graphic3d_CStructure.hxx | 3 + src/Graphic3d/Graphic3d_CView.cxx | 15 ++++- src/Graphic3d/Graphic3d_CView.hxx | 3 + src/Graphic3d/Graphic3d_Layer.cxx | 8 ++- src/Graphic3d/Graphic3d_Layer.hxx | 5 +- src/OpenGl/OpenGl_Structure.cxx | 88 ++++++++++++++++++++++++++ src/OpenGl/OpenGl_Structure.hxx | 3 + src/OpenGl/OpenGl_View.cxx | 11 ++++ src/OpenGl/OpenGl_View.hxx | 2 +- 11 files changed, 151 insertions(+), 4 deletions(-) diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index aaa794cd0d..e2900a7ca8 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -675,6 +675,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. diff --git a/src/AIS/AIS_InteractiveContext_2.cxx b/src/AIS/AIS_InteractiveContext_2.cxx index 9ce6fa886f..97ea8cf4f1 100644 --- a/src/AIS/AIS_InteractiveContext_2.cxx +++ b/src/AIS/AIS_InteractiveContext_2.cxx @@ -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(); + } +} diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index d7c9f7caa0..ac23858994 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -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. diff --git a/src/Graphic3d/Graphic3d_CView.cxx b/src/Graphic3d/Graphic3d_CView.cxx index 829151db39..2b3fd492c4 100644 --- a/src/Graphic3d/Graphic3d_CView.cxx +++ b/src/Graphic3d/Graphic3d_CView.cxx @@ -369,6 +369,18 @@ void Graphic3d_CView::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theL } } } +// ======================================================================= +// function : InvalidateAllLayerBoundingBox +// purpose : +// ======================================================================= +void Graphic3d_CView::InvalidateAllLayerBoundingBox() +{ + for (NCollection_List::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; diff --git a/src/Graphic3d/Graphic3d_CView.hxx b/src/Graphic3d/Graphic3d_CView.hxx index f3a2836997..bae9771727 100644 --- a/src/Graphic3d/Graphic3d_CView.hxx +++ b/src/Graphic3d/Graphic3d_CView.hxx @@ -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 diff --git a/src/Graphic3d/Graphic3d_Layer.cxx b/src/Graphic3d/Graphic3d_Layer.cxx index 70a4eaf439..c555c7bd71 100644 --- a/src/Graphic3d/Graphic3d_Layer.cxx +++ b/src/Graphic3d/Graphic3d_Layer.cxx @@ -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()) diff --git a/src/Graphic3d/Graphic3d_Layer.hxx b/src/Graphic3d/Graphic3d_Layer.hxx index 820113e13f..b314e6c6a7 100644 --- a/src/Graphic3d/Graphic3d_Layer.hxx +++ b/src/Graphic3d/Graphic3d_Layer.hxx @@ -24,6 +24,8 @@ #include #include +class Graphic3d_SequenceOfHClipPlane; + //! Defines index map of structures. typedef NCollection_IndexedMap 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, diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index 927a4a0eac..2403048282 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -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 : diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index d09215b5d0..351d0ec4b4 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -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; diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index b5d5c23635..22e8a7c17e 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -850,6 +850,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 : diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index ddf1b537c9..fc6aae062f 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -281,7 +281,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. -- 2.39.5