1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0031149: Visualization - using clipping planes for FitAll of V3d_View

(cherry picked from commit 60d61bea5e)
This commit is contained in:
nds
2019-11-11 14:04:39 +03:00
parent 0252a0a4fb
commit 40ea9e83b8
11 changed files with 151 additions and 4 deletions

View 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.

View 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();
}
}

View 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.

View 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;

View 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

View 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())

View 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,

View 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 :

View 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;

View 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 :

View 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.