From d8bf73d5167157eadfbf8e7f440b9697e6c2469d Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 14 May 2019 14:29:21 +0300 Subject: [PATCH] 0030695: Visualization - selection by box should use clipping planes set for viewer - if object touches the clipping plane and not outside, the proposed result state of probeBox is Graphic3d_ClipState_In. --- src/Graphic3d/Graphic3d_ClipPlane.hxx | 15 ++++ src/SelectMgr/SelectMgr_ViewerSelector.cxx | 80 +++++++++++++++++--- src/StdSelect/StdSelect_ViewerSelector3d.cxx | 4 + tests/bugs/vis/bug30695 | 36 +++++++++ 4 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 tests/bugs/vis/bug30695 diff --git a/src/Graphic3d/Graphic3d_ClipPlane.hxx b/src/Graphic3d/Graphic3d_ClipPlane.hxx index 8e4c34835e..8021edba57 100755 --- a/src/Graphic3d/Graphic3d_ClipPlane.hxx +++ b/src/Graphic3d/Graphic3d_ClipPlane.hxx @@ -226,6 +226,11 @@ public: } else if (!aPlaneIter->IsBoxFullOutHalfspace (theBox)) { + // the box is not fully out, and not fully in, check is it on (but not intersect) + if (ProbeBoxMaxPointHalfspace (theBox) != Graphic3d_ClipState_Out) + { + return Graphic3d_ClipState_In; + } // if at least one full out test fail, clipping state is inconclusive (partially clipped) aState = Graphic3d_ClipState_On; } @@ -271,6 +276,16 @@ public: return IsPointOutHalfspace (aMaxPnt); } + //! Check if the given bounding box is fully outside of the half-space (e.g. should be discarded by clipping plane). + Graphic3d_ClipState ProbeBoxMaxPointHalfspace (const Graphic3d_BndBox3d& theBox) const + { + const Graphic3d_Vec4d aMaxPnt (myEquation.x() > 0.0 ? theBox.CornerMax().x() : theBox.CornerMin().x(), + myEquation.y() > 0.0 ? theBox.CornerMax().y() : theBox.CornerMin().y(), + myEquation.z() > 0.0 ? theBox.CornerMax().z() : theBox.CornerMin().z(), + 1.0); + return ProbePointHalfspace (aMaxPnt); + } + //! Check if the given bounding box is fully inside (or touches from inside) the half-space (e.g. NOT discarded by clipping plane). bool IsBoxFullInHalfspace (const Graphic3d_BndBox3d& theBox) const { diff --git a/src/SelectMgr/SelectMgr_ViewerSelector.cxx b/src/SelectMgr/SelectMgr_ViewerSelector.cxx index 0476e7fd6b..34faa79580 100644 --- a/src/SelectMgr/SelectMgr_ViewerSelector.cxx +++ b/src/SelectMgr/SelectMgr_ViewerSelector.cxx @@ -420,7 +420,36 @@ void SelectMgr_ViewerSelector::traverseObject (const Handle(SelectMgr_Selectable { return; } + // in case of Box/Polyline selection - keep only Owners having all Entities detected + if (!theMgr.ViewClipping().IsNull() && + theMgr.GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Box) + //&& theMgr.GetActiveSelectionType() != SelectBasics_SelectingVolumeManager::Polyline)) + { + Graphic3d_BndBox3d aBBox (aSensitivesTree->MinPoint (0), aSensitivesTree->MaxPoint (0)); + // If box selection is active, and the whole sensitive tree is out of the clip planes + // selection is empty for this object + const Handle(Graphic3d_SequenceOfHClipPlane)& aViewPlanes = theMgr.ViewClipping(); + + for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aViewPlanes); aPlaneIt.More(); aPlaneIt.Next()) + { + const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value(); + if (!aPlane->IsOn()) + { + continue; + } + Graphic3d_ClipState aState = aPlane->ProbeBox (aBBox); + if (aState == Graphic3d_ClipState_Out) // do not process only whole trees, next check on the tree node + { + return; + } + //if (aState == Graphic3d_ClipState_On && !mySelectingVolumeMgr.IsOverlapAllowed()) // partially clipped + //{ + // return; + //} + } + } + const Standard_Integer aFirstStored = mystored.Extent() + 1; Standard_Integer aStack[BVH_Constants_MaxTreeDepth]; @@ -464,17 +493,50 @@ void SelectMgr_ViewerSelector::traverseObject (const Handle(SelectMgr_Selectable } else { - Standard_Integer aStartIdx = aSensitivesTree->BegPrimitive (aNode); - Standard_Integer anEndIdx = aSensitivesTree->EndPrimitive (aNode); - for (Standard_Integer anIdx = aStartIdx; anIdx <= anEndIdx; ++anIdx) + bool aClipped = false; + if (!theMgr.ViewClipping().IsNull() && + theMgr.GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Box) + //&& theMgr.GetActiveSelectionType() != SelectBasics_SelectingVolumeManager::Polyline)) { - const Handle(SelectMgr_SensitiveEntity)& aSensitive = anEntitySet->GetSensitiveById (anIdx); - if (aSensitive->IsActiveForSelection()) + Graphic3d_BndBox3d aBBox (aSensitivesTree->MinPoint (aNode), aSensitivesTree->MaxPoint (aNode)); + // If box selection is active, and the whole sensitive tree is out of the clip planes + // selection is empty for this object + const Handle(Graphic3d_SequenceOfHClipPlane)& aViewPlanes = theMgr.ViewClipping(); + + for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aViewPlanes); aPlaneIt.More(); aPlaneIt.Next()) { - const Handle(SelectBasics_SensitiveEntity)& anEnt = aSensitive->BaseSensitive(); - SelectMgr_SelectingVolumeManager aTmpMgr = aMgr; - computeFrustum (anEnt, theMgr, aInversedTrsf, aScaledTrnsfFrustums, aTmpMgr); - checkOverlap (anEnt, aInversedTrsf, aTmpMgr); + const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value(); + if (!aPlane->IsOn()) + { + continue; + } + Graphic3d_ClipState aState = aPlane->ProbeBox (aBBox); + if (aState == Graphic3d_ClipState_Out) + { + aClipped = true; + break; + } + if (aState == Graphic3d_ClipState_On && !mySelectingVolumeMgr.IsOverlapAllowed()) // partially clipped + { + aClipped = true; + break; + } + } + } + if (!aClipped) + { + Standard_Integer aStartIdx = aSensitivesTree->BegPrimitive (aNode); + Standard_Integer anEndIdx = aSensitivesTree->EndPrimitive (aNode); + for (Standard_Integer anIdx = aStartIdx; anIdx <= anEndIdx; ++anIdx) + { + const Handle(SelectMgr_SensitiveEntity)& aSensitive = anEntitySet->GetSensitiveById (anIdx); + if (aSensitive->IsActiveForSelection()) + { + const Handle(SelectBasics_SensitiveEntity)& anEnt = aSensitive->BaseSensitive(); + SelectMgr_SelectingVolumeManager aTmpMgr = aMgr; + computeFrustum (anEnt, theMgr, aInversedTrsf, aScaledTrnsfFrustums, aTmpMgr); + checkOverlap (anEnt, aInversedTrsf, aTmpMgr); + } } } if (aHead < 0) diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cxx b/src/StdSelect/StdSelect_ViewerSelector3d.cxx index 19fc15a01d..8ed26b7c6d 100644 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cxx @@ -175,6 +175,8 @@ void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin, mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos, aMaxMousePos); + mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes()); + TraverseSensitives(); } @@ -193,6 +195,8 @@ void StdSelect_ViewerSelector3d::Pick (const TColgp_Array1OfPnt2d& thePolyline, mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); mySelectingVolumeMgr.BuildSelectingVolume (thePolyline); + mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes()); + TraverseSensitives(); } diff --git a/tests/bugs/vis/bug30695 b/tests/bugs/vis/bug30695 new file mode 100644 index 0000000000..85e240d7ca --- /dev/null +++ b/tests/bugs/vis/bug30695 @@ -0,0 +1,36 @@ +puts "=============" +puts "0030695: Visualization - selection by box should use clipping planes set for viewer" +puts "=============" + +pload ALL +vinit View1 + +box b 10 10 10 +vdisplay b + +box b1 -5 0 0 2 2 2 +vdisplay b1 + +box b2 13 0 0 2 2 2 +vdisplay b2 + +box b3 16 0 0 2 2 2 +vdisplay b3 + +vsetdispmode 1 + +vtop +vfit +vzoom 0.5 +vselect 40 100 370 300 +vnbselected + +vclipplane create pln +vclipplane set pln view Driver1/Viewer1/View1 +vclipplane change pln equation -1 0 0 5 + +vselect 40 100 370 300 +vnbselected + +vselect 40 100 370 300 -allowoverlap 1 +vnbselected -- 2.39.5