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

0027884: Modeling Algorithms - Possible improvement for 2d classifier

Added the implementation of bndbox<->line and bndbox<->segment intersections for 2D to Bnd_Box2d
Added the speedup for 2d classification to BRepClass_Intersector.cxx
Added the test for our improvement
This commit is contained in:
abulyche
2021-07-14 23:40:32 +03:00
committed by bugmaster
parent fceeb82917
commit 715fcb5a92
14 changed files with 513 additions and 101 deletions

View File

@@ -17,6 +17,7 @@
#include <BRepClass_Edge.hxx>
#include <NCollection_IndexedDataMap.hxx>
#include <Precision.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
@@ -25,7 +26,7 @@
//function : BRepClass_Edge
//purpose :
//=======================================================================
BRepClass_Edge::BRepClass_Edge()
BRepClass_Edge::BRepClass_Edge() : myMaxTolerance(Precision::Infinite()), myUseBndBox(Standard_False)
{
}
@@ -47,7 +48,7 @@ void BRepClass_Edge::SetNextEdge(const TopTools_IndexedDataMapOfShapeListOfShape
return;
}
const TopTools_ListOfShape* aListE = theMapVE.Seek(aVL);
if ((*aListE).Extent() == 2)
if (aListE->Extent() == 2)
{
for (TopTools_ListIteratorOfListOfShape anIt(*aListE); anIt.More(); anIt.Next())
{
@@ -68,7 +69,9 @@ void BRepClass_Edge::SetNextEdge(const TopTools_IndexedDataMapOfShapeListOfShape
BRepClass_Edge::BRepClass_Edge(const TopoDS_Edge& E,
const TopoDS_Face& F) :
myEdge(E),
myFace(F)
myFace(F),
myMaxTolerance(Precision::Infinite()),
myUseBndBox(Standard_False)
{
}

View File

@@ -57,6 +57,33 @@ const TopoDS_Face& Face() const;
//! Finds and sets the next Edge for the current
Standard_EXPORT void SetNextEdge(const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE);
//! Returns the maximum tolerance
Standard_Real MaxTolerance() const
{
return myMaxTolerance;
}
//! Sets the maximum tolerance at
//! which to start checking in the intersector
void SetMaxTolerance(const Standard_Real theValue)
{
myMaxTolerance = theValue;
}
//! Returns true if we are using boxes
//! in the intersector
Standard_Boolean UseBndBox() const
{
return myUseBndBox;
}
//! Sets the status of whether we are
//! using boxes or not
void SetUseBndBox(const Standard_Boolean theValue)
{
myUseBndBox = theValue;
}
protected:
@@ -71,6 +98,8 @@ private:
TopoDS_Edge myEdge;
TopoDS_Face myFace;
TopoDS_Edge myNextEdge;
Standard_Real myMaxTolerance;
Standard_Boolean myUseBndBox;
};

View File

@@ -46,33 +46,41 @@ BRepClass_FaceClassifier::BRepClass_FaceClassifier(BRepClass_FaceExplorer& F,
//function : BRepClass_FaceClassifier
//purpose :
//=======================================================================
BRepClass_FaceClassifier::BRepClass_FaceClassifier(const TopoDS_Face& F,
const gp_Pnt& P,
const Standard_Real Tol)
BRepClass_FaceClassifier::BRepClass_FaceClassifier(const TopoDS_Face& theF,
const gp_Pnt& theP,
const Standard_Real theTol,
const Standard_Boolean theUseBndBox,
const Standard_Real theGapCheckTol)
{
Perform(F,P,Tol);
Perform(theF, theP, theTol, theUseBndBox, theGapCheckTol);
}
//=======================================================================
//function : BRepClass_FaceClassifier
//purpose :
//=======================================================================
BRepClass_FaceClassifier::BRepClass_FaceClassifier(const TopoDS_Face& F,
const gp_Pnt2d& P,
const Standard_Real Tol)
BRepClass_FaceClassifier::BRepClass_FaceClassifier(const TopoDS_Face& theF,
const gp_Pnt2d& theP,
const Standard_Real theTol,
const Standard_Boolean theUseBndBox,
const Standard_Real theGapCheckTol)
{
Perform(F,P,Tol);
Perform(theF, theP, theTol, theUseBndBox, theGapCheckTol);
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void BRepClass_FaceClassifier::Perform(const TopoDS_Face& F,
const gp_Pnt2d& P,
const Standard_Real Tol)
void BRepClass_FaceClassifier::Perform(const TopoDS_Face& theF,
const gp_Pnt2d& theP,
const Standard_Real theTol,
const Standard_Boolean theUseBndBox,
const Standard_Real theGapCheckTol)
{
BRepClass_FaceExplorer Fex(F);
BRepClass_FClassifier::Perform(Fex,P,Tol);
BRepClass_FaceExplorer aFex(theF);
aFex.SetMaxTolerance(theGapCheckTol);
aFex.SetUseBndBox(theUseBndBox);
BRepClass_FClassifier::Perform(aFex, theP, theTol);
}
@@ -84,9 +92,11 @@ void BRepClass_FaceClassifier::Perform(const TopoDS_Face& F,
//function : Perform
//purpose :
//=======================================================================
void BRepClass_FaceClassifier::Perform(const TopoDS_Face& aF,
const gp_Pnt& aP,
const Standard_Real aTol)
void BRepClass_FaceClassifier::Perform(const TopoDS_Face& theF,
const gp_Pnt& theP,
const Standard_Real theTol,
const Standard_Boolean theUseBndBox,
const Standard_Real theGapCheckTol)
{
Standard_Integer aNbExt, aIndice, i;
Standard_Real aU1, aU2, aV1, aV2, aMaxDist, aD;
@@ -96,14 +106,14 @@ void BRepClass_FaceClassifier::Perform(const TopoDS_Face& aF,
aMaxDist=RealLast();
aIndice=0;
//
BRepAdaptor_Surface aSurf(aF, Standard_False);
BRepTools::UVBounds(aF, aU1, aU2, aV1, aV2);
aExtrema.Initialize(aSurf, aU1, aU2, aV1, aV2, aTol, aTol);
BRepAdaptor_Surface aSurf(theF, Standard_False);
BRepTools::UVBounds(theF, aU1, aU2, aV1, aV2);
aExtrema.Initialize(aSurf, aU1, aU2, aV1, aV2, theTol, theTol);
//
//modified by NIZNHY-PKV Wed Aug 13 11:28:47 2008f
rejected=Standard_True;
//modified by NIZNHY-PKV Wed Aug 13 11:28:49 2008t
aExtrema.Perform(aP);
aExtrema.Perform(theP);
if(!aExtrema.IsDone()) {
return;
}
@@ -124,6 +134,6 @@ void BRepClass_FaceClassifier::Perform(const TopoDS_Face& aF,
if(aIndice) {
aExtrema.Point(aIndice).Parameter(aU1, aU2);
aPuv.SetCoord(aU1, aU2);
Perform(aF, aPuv, aTol);
Perform(theF, aPuv, theTol, theUseBndBox, theGapCheckTol);
}
}

View File

@@ -46,19 +46,31 @@ public:
//! Creates an algorithm to classify the Point P with
//! Tolerance <T> on the face <F>.
Standard_EXPORT BRepClass_FaceClassifier(const TopoDS_Face& F, const gp_Pnt2d& P, const Standard_Real Tol);
//! Recommended to use Bnd_Box if the number of edges > 10
//! and the geometry is mostly spline
Standard_EXPORT BRepClass_FaceClassifier(const TopoDS_Face& theF, const gp_Pnt2d& theP, const Standard_Real theTol,
const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);
//! Classify the Point P with Tolerance <T> on the
//! face described by <F>.
Standard_EXPORT void Perform (const TopoDS_Face& F, const gp_Pnt2d& P, const Standard_Real Tol);
//! Recommended to use Bnd_Box if the number of edges > 10
//! and the geometry is mostly spline
Standard_EXPORT void Perform (const TopoDS_Face& theF, const gp_Pnt2d& theP, const Standard_Real theTol,
const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);
//! Creates an algorithm to classify the Point P with
//! Tolerance <T> on the face <F>.
Standard_EXPORT BRepClass_FaceClassifier(const TopoDS_Face& F, const gp_Pnt& P, const Standard_Real Tol);
//! Recommended to use Bnd_Box if the number of edges > 10
//! and the geometry is mostly spline
Standard_EXPORT BRepClass_FaceClassifier(const TopoDS_Face& theF, const gp_Pnt& theP, const Standard_Real theTol,
const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);
//! Classify the Point P with Tolerance <T> on the
//! face described by <F>.
Standard_EXPORT void Perform (const TopoDS_Face& F, const gp_Pnt& P, const Standard_Real Tol);
//! Recommended to use Bnd_Box if the number of edges > 10
//! and the geometry is mostly spline
Standard_EXPORT void Perform (const TopoDS_Face& theF, const gp_Pnt& theP, const Standard_Real theTol,
const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);

View File

@@ -36,14 +36,17 @@ static const Standard_Real Probing_Step = 0.2111;
//purpose :
//=======================================================================
BRepClass_FaceExplorer::BRepClass_FaceExplorer(const TopoDS_Face& F) :
BRepClass_FaceExplorer::BRepClass_FaceExplorer(const TopoDS_Face& F) :
myFace(F),
myCurEdgeInd(1),
myCurEdgePar(Probing_Start),
myMaxTolerance(0.1),
myUseBndBox(Standard_False),
myUMin (Precision::Infinite()),
myUMax (-Precision::Infinite()),
myVMin (Precision::Infinite()),
myVMax (-Precision::Infinite())
{
myFace.Orientation(TopAbs_FORWARD);
}
@@ -338,5 +341,7 @@ void BRepClass_FaceExplorer::CurrentEdge(BRepClass_Edge& E,
E.Face() = myFace;
Or = E.Edge().Orientation();
E.SetNextEdge(myMapVE);
E.SetMaxTolerance(myMaxTolerance);
E.SetUseBndBox(myUseBndBox);
}

View File

@@ -94,6 +94,33 @@ public:
//! Current edge in current wire and its orientation.
Standard_EXPORT void CurrentEdge (BRepClass_Edge& E, TopAbs_Orientation& Or) const;
//! Returns the maximum tolerance
Standard_Real MaxTolerance() const
{
return myMaxTolerance;
}
//! Sets the maximum tolerance at
//! which to start checking in the intersector
void SetMaxTolerance(const Standard_Real theValue)
{
myMaxTolerance = theValue;
}
//! Returns true if we are using boxes
//! in the intersector
Standard_Boolean UseBndBox() const
{
return myUseBndBox;
}
//! Sets the status of whether we are
//! using boxes or not
void SetUseBndBox(const Standard_Boolean theValue)
{
myUseBndBox = theValue;
}
@@ -112,6 +139,8 @@ private:
TopExp_Explorer myEExplorer;
Standard_Integer myCurEdgeInd;
Standard_Real myCurEdgePar;
Standard_Real myMaxTolerance;
Standard_Boolean myUseBndBox;
TopTools_IndexedDataMapOfShapeListOfShape myMapVE;
Standard_Real myUMin;

View File

@@ -15,6 +15,8 @@
// commercial license or contractual agreement.
#include <Bnd_Box2d.hxx>
#include <BndLib_Add2dCurve.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <BRepAdaptor_Surface.hxx>
@@ -53,10 +55,10 @@ static
Standard_Boolean CheckOn(IntRes2d_IntersectionPoint& thePntInter,
const TopoDS_Face& theF,
const gp_Lin2d& theL,
Geom2dAdaptor_Curve& theCur,
Standard_Real theTolZ,
Standard_Real theFin,
Standard_Real theDeb);
const Geom2dAdaptor_Curve& theCur,
Standard_Real& theTolZ,
const Standard_Real theFin,
const Standard_Real theDeb);
static
void CheckSkip(Geom2dInt_GInter& theInter,
@@ -66,22 +68,93 @@ void CheckSkip(Geom2dInt_GInter& theInter,
const IntRes2d_Domain& theDL,
Geom2dAdaptor_Curve& theCur,
const Geom2dAdaptor_Curve& theCGA,
Standard_Real theFin,
Standard_Real theDeb,
Standard_Real theMaxTol,
gp_Pnt2d thePdeb,
gp_Pnt2d thePfin);
Standard_Real& theFin,
Standard_Real& theDeb,
const Standard_Real theMaxTol,
gp_Pnt2d& thePdeb,
gp_Pnt2d& thePfin);
static
Standard_Real MaxTol2DCurEdge(const TopoDS_Vertex& theV1,
const TopoDS_Vertex& theV2,
const TopoDS_Face& theF,
const Standard_Real theTol);
static
Standard_Boolean IsInter(Bnd_Box2d& theBox,
const gp_Lin2d& theL,
const Standard_Real theP);
//=======================================================================
//function : BRepClass_Intersector
//purpose :
//=======================================================================
BRepClass_Intersector::BRepClass_Intersector() : myMaxTolerance(0.1)
BRepClass_Intersector::BRepClass_Intersector()
{
}
//=======================================================================
//function : MaxTol2DCurEdge
//purpose :
//=======================================================================
Standard_Real MaxTol2DCurEdge(const TopoDS_Vertex& theV1,
const TopoDS_Vertex& theV2,
const TopoDS_Face& theF,
const Standard_Real theTol)
{
Standard_Real aTolV3D1, aTolV3D2;
if (theV1.IsNull())
{
aTolV3D1 = 0.0;
}
else
{
aTolV3D1 = BRep_Tool::Tolerance(theV1);
}
if (theV2.IsNull())
{
aTolV3D2 = 0.0;
}
else
{
aTolV3D2 = BRep_Tool::Tolerance(theV2);
}
Standard_Real aTol2D, anUr, aVr;
Standard_Real aTolV3D = Max(aTolV3D1, aTolV3D2);
BRepAdaptor_Surface aS(theF, Standard_False);
anUr = aS.UResolution(aTolV3D);
aVr = aS.VResolution(aTolV3D);
aTol2D = Max(anUr, aVr);
//
aTol2D = Max(aTol2D, theTol);
return aTol2D;
}
//=======================================================================
//function : IsInter
//purpose :
//=======================================================================
Standard_Boolean IsInter(Bnd_Box2d& theBox,
const gp_Lin2d& theL,
const Standard_Real theP)
{
Standard_Boolean aStatusInter = Standard_True;
if (Precision::IsInfinite(theP))
{
aStatusInter = theBox.IsOut(theL);
}
else
{
gp_Pnt2d aPntF = theL.Location();
gp_Pnt2d aPntL = ElCLib::Value(theP, theL);
aStatusInter = theBox.IsOut(aPntF, aPntL);
}
return !aStatusInter;
}
//=======================================================================
//function : CheckOn
//purpose :
@@ -89,10 +162,10 @@ BRepClass_Intersector::BRepClass_Intersector() : myMaxTolerance(0.1)
Standard_Boolean CheckOn(IntRes2d_IntersectionPoint& thePntInter,
const TopoDS_Face& theF,
const gp_Lin2d& theL,
Geom2dAdaptor_Curve& theCur,
Standard_Real theTolZ,
Standard_Real theFin,
Standard_Real theDeb)
const Geom2dAdaptor_Curve& theCur,
Standard_Real& theTolZ,
const Standard_Real theFin,
const Standard_Real theDeb)
{
Extrema_ExtPC2d anExtPC2d(theL.Location(), theCur);
Standard_Real aMinDist = RealLast();
@@ -153,11 +226,11 @@ void CheckSkip(Geom2dInt_GInter& theInter,
const IntRes2d_Domain& theDL,
Geom2dAdaptor_Curve& theCur,
const Geom2dAdaptor_Curve& theCGA,
Standard_Real theFin,
Standard_Real theDeb,
Standard_Real theMaxTol,
gp_Pnt2d thePdeb,
gp_Pnt2d thePfin)
Standard_Real& theFin,
Standard_Real& theDeb,
const Standard_Real theMaxTol,
gp_Pnt2d& thePdeb,
gp_Pnt2d& thePfin)
{
if (theE.Edge().IsNull() || theE.Face().IsNull())
{
@@ -272,10 +345,10 @@ void CheckSkip(Geom2dInt_GInter& theInter,
//function : Perform
//purpose :
//=======================================================================
void BRepClass_Intersector::Perform(const gp_Lin2d& L,
const Standard_Real P,
const Standard_Real Tol,
const BRepClass_Edge& E)
void BRepClass_Intersector::Perform(const gp_Lin2d& L,
const Standard_Real P,
const Standard_Real Tol,
const BRepClass_Edge& E)
{
Standard_Real deb = 0.0, fin = 0.0, aTolZ = Tol;
Handle(Geom2d_Curve) aC2D;
@@ -284,69 +357,92 @@ void BRepClass_Intersector::Perform(const gp_Lin2d& L,
const TopoDS_Face& F = E.Face();
//
aC2D=BRep_Tool::CurveOnSurface(EE, F, deb, fin);
aC2D = BRep_Tool::CurveOnSurface(EE, F, deb, fin);
if (aC2D.IsNull()) {
done = Standard_False; // !IsDone()
return;
}
//
Geom2dAdaptor_Curve C(aC2D, deb, fin);
Bnd_Box2d aBond;
gp_Pnt2d aPntF;
Standard_Boolean anUseBndBox = E.UseBndBox();
if (anUseBndBox)
{
BndLib_Add2dCurve::Add(aC2D, deb, fin, 0., aBond);
aBond.SetGap(aTolZ);
aPntF = L.Location();
}
//
deb = C.FirstParameter();
fin = C.LastParameter();
Geom2dAdaptor_Curve C(aC2D, deb, fin);
//
// Case of "ON": direct check of belonging to edge
// taking into account the tolerance
Standard_Boolean aStatusOn = Standard_False;
IntRes2d_IntersectionPoint aPntInter;
aStatusOn = CheckOn(aPntInter, F, L, C, aTolZ, fin, deb);
if (aStatusOn)
if (!anUseBndBox || (anUseBndBox && !aBond.IsOut(aPntF)))
{
Append(aPntInter);
done = Standard_True;
return;
Standard_Boolean aStatusOn = Standard_False;
IntRes2d_IntersectionPoint aPntInter;
aStatusOn = CheckOn(aPntInter, F, L, C, aTolZ, fin, deb);
if (aStatusOn)
{
Append(aPntInter);
done = Standard_True;
return;
}
}
//
gp_Pnt2d pdeb,pfin;
C.D0(deb,pdeb);
C.D0(fin,pfin);
//
if (anUseBndBox)
{
TopoDS_Vertex aVF, aVL;
TopExp::Vertices(EE, aVF, aVL);
aTolZ = MaxTol2DCurEdge(aVF, aVL, F, Tol);
aBond.SetGap(aTolZ);
if (!IsInter(aBond, L, P))
{
done = Standard_False;
return;
}
}
gp_Pnt2d pdeb, pfin;
C.D0(deb, pdeb);
C.D0(fin, pfin);
Standard_Real toldeb = 1.e-5, tolfin = 1.e-5;
IntRes2d_Domain DL;
//
if(P!=RealLast()) {
DL.SetValues(L.Location(),0.,Precision::PConfusion(),ElCLib::Value(P,L),P,Precision::PConfusion());
if (P != RealLast()) {
DL.SetValues(L.Location(), 0., Precision::PConfusion(), ElCLib::Value(P, L), P, Precision::PConfusion());
}
else {
DL.SetValues(L.Location(),0.,Precision::PConfusion(),Standard_True);
else {
DL.SetValues(L.Location(), 0., Precision::PConfusion(), Standard_True);
}
IntRes2d_Domain DE(pdeb,deb,toldeb,pfin,fin,tolfin);
IntRes2d_Domain DE(pdeb, deb, toldeb, pfin, fin, tolfin);
// temporary periodic domain
if (C.Curve()->IsPeriodic()) {
DE.SetEquivalentParameters(C.FirstParameter(),
C.FirstParameter() +
C.FirstParameter() +
C.Curve()->LastParameter() -
C.Curve()->FirstParameter());
}
Handle(Geom2d_Line) GL= new Geom2d_Line(L);
Handle(Geom2d_Line) GL = new Geom2d_Line(L);
Geom2dAdaptor_Curve CGA(GL);
Geom2dInt_GInter Inter(CGA,DL,C,DE,
Geom2dInt_GInter Inter(CGA, DL, C, DE,
Precision::PConfusion(),
Precision::PIntersection());
//
// The check is for hitting the intersector to
// a vertex with high tolerance
if (Inter.IsEmpty())
if (Inter.IsEmpty())
{
CheckSkip(Inter, L, E, aC2D, DL,
C, CGA, fin, deb, MaxTolerance(), pdeb, pfin);
CheckSkip(Inter, L, E, aC2D, DL,
C, CGA, fin, deb, E.MaxTolerance(), pdeb, pfin);
}
//
//
SetValues(Inter);
}

View File

@@ -47,19 +47,6 @@ public:
//! <U>.
Standard_EXPORT void LocalGeometry (const BRepClass_Edge& E, const Standard_Real U, gp_Dir2d& T, gp_Dir2d& N, Standard_Real& C) const;
//! Returns the maximum tolerance
Standard_Real MaxTolerance()
{
return myMaxTolerance;
}
//! Sets the maximum tolerance at
//! which to start checking in the intersector
void SetMaxTolerance(const Standard_Real theValue)
{
myMaxTolerance = theValue;
}
protected:
@@ -71,7 +58,6 @@ protected:
private:
Standard_Real myMaxTolerance;
};