From 3b77eff652a4a8c0c0d840eb5a005986fcb567a9 Mon Sep 17 00:00:00 2001 From: emv Date: Tue, 21 Mar 2017 15:47:34 +0300 Subject: [PATCH] 0028577: Get rid of the TopOpeBRep* algorithms in TKOffset toolkit The TKOffset toolkit has been cleared from the usage of the obsolete TopOpeBRep* classes. --- src/BRepLib/BRepLib_FuseEdges.cxx | 21 --- src/BRepOffset/BRepOffset_Inter3d.cxx | 72 +++++--- src/BRepOffset/BRepOffset_Tool.cxx | 9 +- .../BRepOffsetAPI_DraftAngle.cxx | 159 +++++++++--------- 4 files changed, 123 insertions(+), 138 deletions(-) diff --git a/src/BRepLib/BRepLib_FuseEdges.cxx b/src/BRepLib/BRepLib_FuseEdges.cxx index 877111d56d..528eabd0b7 100644 --- a/src/BRepLib/BRepLib_FuseEdges.cxx +++ b/src/BRepLib/BRepLib_FuseEdges.cxx @@ -71,9 +71,6 @@ #include #include -//#ifdef OCCT_DEBUG -//Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceFE(); -//#endif static void BCSmoothing(Handle(Geom_BSplineCurve)& theC, const Standard_Integer theCont, const Standard_Real theTol) @@ -366,11 +363,6 @@ TopoDS_Shape& BRepLib_FuseEdges::Shape() void BRepLib_FuseEdges::BuildListEdges() { - -//#ifdef OCCT_DEBUG - //Standard_Boolean tFE = TopOpeBRepBuild_GettraceFE(); -//#endif - //-------------------------------------------------------- // Step One : Build the map ancestors //-------------------------------------------------------- @@ -416,11 +408,6 @@ void BRepLib_FuseEdges::BuildListEdges() void BRepLib_FuseEdges::BuildListResultEdges() { - -//#ifdef OCCT_DEBUG - //Standard_Boolean tFE = TopOpeBRepBuild_GettraceFE(); -//#endif - // if we have edges to fuse if (myMapLstEdg.Extent() > 0) { TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape itLstEdg; @@ -545,11 +532,6 @@ void BRepLib_FuseEdges::BuildListResultEdges() void BRepLib_FuseEdges::Perform() { - -//#ifdef OCCT_DEBUG - //Standard_Boolean tFE = TopOpeBRepBuild_GettraceFE(); -//#endif - if (!myResultEdgesDone) { BuildListResultEdges(); } @@ -803,9 +785,6 @@ Standard_Boolean BRepLib_FuseEdges::SameSupport(const TopoDS_Edge& E1, typC1 != STANDARD_TYPE(Geom_Ellipse) && typC1 != STANDARD_TYPE(Geom_BSplineCurve) && typC1 != STANDARD_TYPE(Geom_BezierCurve)) { -#ifdef OCCT_DEBUG - cout << " TopOpeBRepTool_FuseEdge : Type de Support non traite" << endl; -#endif return Standard_False; } diff --git a/src/BRepOffset/BRepOffset_Inter3d.cxx b/src/BRepOffset/BRepOffset_Inter3d.cxx index d8de6e90c3..9296c5288f 100644 --- a/src/BRepOffset/BRepOffset_Inter3d.cxx +++ b/src/BRepOffset/BRepOffset_Inter3d.cxx @@ -40,12 +40,15 @@ #include #include #include -#include #include #include #include #include // +#include +#include +#include +// #include //======================================================================= @@ -160,40 +163,55 @@ void BRepOffset_Inter3d::CompletInt(const TopTools_ListOfShape& SetOfFaces, // Calculate the intersections of offset faces // Distinction of intersection between faces // tangents. //--------------------------------------------------------------- - TopoDS_Face F2; - TopTools_ListIteratorOfListOfShape it; - //--------------------------------------------------------------- - // Construction of bounding boxes - //--------------------------------------------------------------- - TopOpeBRepTool_BoxSort BOS; - BRep_Builder B; - TopoDS_Compound CompOS; - B.MakeCompound(CompOS); - - for (it.Initialize(SetOfFaces); it.More(); it.Next()) { - const TopoDS_Shape& OS = it.Value(); - B.Add(CompOS,OS); + // Prepare tools for sorting the bounding boxes + BOPCol_BoxBndTree aBBTree; + NCollection_UBTreeFiller aTreeFiller(aBBTree); + // + NCollection_IndexedDataMap aMFaces; + // Construct bounding boxes for faces and add them to the tree + TopTools_ListIteratorOfListOfShape aItL(SetOfFaces); + for (; aItL.More(); aItL.Next()) { + const TopoDS_Face& aF = TopoDS::Face(aItL.Value()); + // + // compute bounding box + Bnd_Box aBoxF; + BRepBndLib::Add(aF, aBoxF); + // + Standard_Integer i = aMFaces.Add(aF, aBoxF); + // + aTreeFiller.Add(i, aBoxF); } - BOS.AddBoxesMakeCOB(CompOS,TopAbs_FACE); - - //--------------------------- - // Intersection of faces // - //--------------------------- - for (it.Initialize(SetOfFaces); it.More(); it.Next()) { - const TopoDS_Face& F1 = TopoDS::Face(it.Value()); - TColStd_ListIteratorOfListOfInteger itLI = BOS.Compare(F1); - for (; itLI.More(); itLI.Next()) { - F2 = TopoDS::Face(BOS.TouchedShape(itLI)); - FaceInter(F1,F2,InitOffsetFace); + // + // shake tree filler + aTreeFiller.Fill(); + // + // get faces with interfering bounding boxes + aItL.Initialize(SetOfFaces); + for (; aItL.More(); aItL.Next()) { + const TopoDS_Face& aF1 = TopoDS::Face(aItL.Value()); + const Bnd_Box& aBoxF1 = aMFaces.FindFromKey(aF1); + // + BOPCol_BoxBndTreeSelector aSelector; + aSelector.SetBox(aBoxF1); + aBBTree.Select(aSelector); + // + const BOPCol_ListOfInteger& aLI = aSelector.Indices(); + BOPCol_ListIteratorOfListOfInteger aItLI(aLI); + for (; aItLI.More(); aItLI.Next()) { + Standard_Integer i = aItLI.Value(); + const TopoDS_Face& aF2 = TopoDS::Face(aMFaces.FindKey(i)); + // + // intersect faces + FaceInter(aF1, aF2, InitOffsetFace); } } } //======================================================================= -//function : CompletInt -//purpose : +//function : FaceInter +//purpose : Performs intersection of the given faces //======================================================================= void BRepOffset_Inter3d::FaceInter(const TopoDS_Face& F1, diff --git a/src/BRepOffset/BRepOffset_Tool.cxx b/src/BRepOffset/BRepOffset_Tool.cxx index e7488cde97..8122387913 100644 --- a/src/BRepOffset/BRepOffset_Tool.cxx +++ b/src/BRepOffset/BRepOffset_Tool.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -113,14 +114,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_DraftAngle.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_DraftAngle.cxx index bac073c8c3..c3425a8ee8 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_DraftAngle.cxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_DraftAngle.cxx @@ -51,12 +51,13 @@ #include #include #include -#include -#include #include #include #include +#include +#include + //======================================================================= //function : BRepOffsetAPI_DraftAngle //purpose : @@ -365,6 +366,19 @@ void BRepOffsetAPI_DraftAngle::CorrectWires() CurEdge = Eseq(i); CurWire = Wseq(i); CurFace = Fseq(i); + // + const TopoDS_Face& aFace = TopoDS::Face(CurFace); + // + // Prepare 2D adaptors for intersection. + // The seam edge has two 2D curve, thus we have to create 2 adaptors + BRepAdaptor_Curve2d aBAC2D1(TopoDS::Edge(CurEdge), aFace); + BRepAdaptor_Curve2d aBAC2D1R(TopoDS::Edge(CurEdge.Reversed()), aFace); + // Get surface of the face to get 3D intersection point + TopLoc_Location aLoc; + const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aLoc); + // Get the tolerance of the current edge to compare intersection points + Standard_Real aTolCurE = BRep_Tool::Tolerance(TopoDS::Edge(CurEdge)); + // wit.Initialize( CurFace ); for (; wit.More(); wit.Next()) { @@ -372,102 +386,83 @@ void BRepOffsetAPI_DraftAngle::CorrectWires() if (! aWire.IsSame( CurWire )) { TColgp_SequenceOfPnt pts; - TopTools_SequenceOfShape edges; - TColStd_SequenceOfReal pars; Standard_Boolean Wadd = Standard_False; eit.Initialize( aWire ); for (; eit.More(); eit.Next()) { - TopoDS_Shape anEdge = eit.Value(); - TopOpeBRep_EdgesIntersector EInter; - EInter.SetFaces( CurFace, CurFace ); - EInter.ForceTolerances( TolInter, TolInter ); - EInter.Perform( CurEdge, anEdge ); - if (EInter.IsEmpty()) - { - EInter.Perform( CurEdge.Reversed(), anEdge ); - if (EInter.IsEmpty()) + const TopoDS_Edge& anEdge = TopoDS::Edge(eit.Value()); + // + // Prepare 2D adaptor for intersection + BRepAdaptor_Curve2d aBAC2D2(anEdge, aFace); + // Perform intersection + Geom2dInt_GInter aGInter; + aGInter.Perform(aBAC2D1, aBAC2D2, TolInter, TolInter); + if (!aGInter.IsDone() || aGInter.IsEmpty()) { + // If first intersection is empty try intersection with reversed edge + aGInter.Perform(aBAC2D1R, aBAC2D2, TolInter, TolInter); + if (!aGInter.IsDone() || aGInter.IsEmpty()) { continue; + } } + // Wadd = Standard_True; if (! WFmap.IsBound( aWire )) WFmap.Bind( aWire, CurFace ); Standard_Integer ind = 0; - for (j = 1; j <= NonSeam.Length(); j++) - if (anEdge.IsSame( NonSeam(j) )) + for (j = 1; j <= NonSeam.Length(); j++) { + if (anEdge.IsSame(NonSeam(j))) { ind = j; break; } - if (ind == 0) - { - NonSeam.Append( anEdge ); - NonSeamWires.Append( aWire ); - ind = NonSeam.Length(); - TColStd_SequenceOfReal emptyseq1, emptyseq2; - TopTools_SequenceOfShape emptyedgeseq; - ParsNonSeam.Append( emptyseq1 ); - Seam.Append( emptyedgeseq ); - ParsSeam.Append( emptyseq2 ); - } - if (! Emap.IsBound( CurEdge )) - { - TColStd_SequenceOfReal emptyseq; - Emap.Bind( CurEdge, emptyseq ); - } - EInter.InitPoint(); - for (; EInter.MorePoint(); EInter.NextPoint()) - { - const TopOpeBRep_Point2d& bp = EInter.Point(); - if (bp.IsVertex(2)) + } + if (ind == 0) + { + NonSeam.Append(anEdge); + NonSeamWires.Append(aWire); + ind = NonSeam.Length(); + TColStd_SequenceOfReal emptyseq1, emptyseq2; + TopTools_SequenceOfShape emptyedgeseq; + ParsNonSeam.Append(emptyseq1); + Seam.Append(emptyedgeseq); + ParsSeam.Append(emptyseq2); + } + if (!Emap.IsBound(CurEdge)) + { + TColStd_SequenceOfReal emptyseq; + Emap.Bind(CurEdge, emptyseq); + } + // + // Get the tolerance of edge to compare intersection points + Standard_Real aTolE = BRep_Tool::Tolerance(anEdge); + // Tolerance to compare the intersection points is the maximal + // tolerance of intersecting edges + Standard_Real aTolCmp = Max(aTolCurE, aTolE); + // + Standard_Integer k, aNbIntPnt = aGInter.NbPoints(); + for (k = 1; k <= aNbIntPnt; ++k) { + const IntRes2d_IntersectionPoint& aP2DInt = aGInter.Point(k); + const gp_Pnt2d& aP2D = aP2DInt.Value(); + gp_Pnt aP3D = aSurf->Value(aP2D.X(), aP2D.Y()); + // + // Check if the intersection point is new + Standard_Integer ied = 0; + for (j = 1; j <= pts.Length(); j++) { + if (aP3D.IsEqual(pts(j), aTolCmp)) { - gp_Pnt Pnt = bp.Value(); - Standard_Integer ied = 0; - for (j = 1; j <= pts.Length(); j++) - if (Pnt.IsEqual( pts(j), Precision::Confusion() )) - { - ied = j; - break; - } - if (ied == 0) - { - pts.Append( Pnt ); - edges.Append( anEdge ); - pars.Append( bp.Parameter(2) ); - Emap(CurEdge).Append( bp.Parameter(1) ); - ParsNonSeam(ind).Append( bp.Parameter(2) ); - Seam(ind).Append( CurEdge ); - ParsSeam(ind).Append( bp.Parameter(1) ); - } - /* - else - { - Standard_Real ParOnSeam = bp.Parameter(1); - Standard_Real Par1 = pars(ied); - Standard_Real Par2 = bp.Parameter(2); - BRepAdaptor_Curve2d SeamCurve( CurEdge, CurFace ); - BRepAdaptor_Curve2d Curve1( edges(ied), CurFace ); - BRepAdaptor_Curve2d Curve2( anEdge. CurFace ); - gp_Pnt2d P2d; - gp_Vec2d SeamDer, Der1, Der2; - //SeamCurve->D1( ParOnSeam, P2d, SeamDer ); - //Curve1->D1( Par1, P2d, Der1 ); - //Curve2->D1( Par2, P2d, Der2 ); - Standard_Real Crossed1 = SeamDer ^ Der1; - Standard_Real Crossed2 = SeamDer ^ Der2; - //if (Crossed1 > 0 - } - */ + ied = j; + break; } - else // ! bp.IsVertex(2) - { - //Temporary the case of tangency is not implemented - Emap(CurEdge).Append( bp.Parameter(1) ); - ParsNonSeam(ind).Append( bp.Parameter(2) ); - Seam(ind).Append( CurEdge ); - ParsSeam(ind).Append( bp.Parameter(1) ); - } - } //for (; EInter.MorePoint(); EInter.NextPoint()) + } + if (ied == 0) + { + pts.Append(aP3D); + Emap(CurEdge).Append(aP2DInt.ParamOnFirst()); + ParsNonSeam(ind).Append(aP2DInt.ParamOnSecond()); + Seam(ind).Append(CurEdge); + ParsSeam(ind).Append(aP2DInt.ParamOnFirst()); + } + } } //for (; eit.More(); eit.Next()) if (Wadd) {