From 13036964b0400fd27001c1f68352bb5384154f79 Mon Sep 17 00:00:00 2001 From: isn Date: Mon, 3 Oct 2016 11:03:28 +0300 Subject: [PATCH] first remarks --- src/BRepFill/BRepFill_OffsetWire.cxx | 135 ++++++++++++++------------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/src/BRepFill/BRepFill_OffsetWire.cxx b/src/BRepFill/BRepFill_OffsetWire.cxx index 769c3fd1b9..a1cfcf9507 100644 --- a/src/BRepFill/BRepFill_OffsetWire.cxx +++ b/src/BRepFill/BRepFill_OffsetWire.cxx @@ -118,6 +118,9 @@ #include #include #include +#include +#include +#include #include #ifdef OCCT_DEBUG @@ -151,14 +154,16 @@ typedef NCollection_UBTree BRepFill_BndBoxTree; class BRepFill_BndBoxTreeSelector : public BRepFill_BndBoxTree::Selector { public: - BRepFill_BndBoxTreeSelector( TopTools_SequenceOfShape& theSeqOfEdges, + BRepFill_BndBoxTreeSelector( TopTools_IndexedMapOfShape& theMapOfEdges, const TopoDS_Face& theWFace, + NCollection_IndexedDataMap>& theOutMapOfResult, Standard_Real thePrec) - : BRepFill_BndBoxTreeSelector::Selector(), mySeqOfEdges (theSeqOfEdges), - myWFace (theWFace), myPrec(thePrec) {} + : BRepFill_BndBoxTreeSelector::Selector(), myMapOfEdges (theMapOfEdges), + myWFace (theWFace), myPrec(thePrec), + myOutMapOfResult (theOutMapOfResult){} + + - BRepFill_BndBoxTreeSelector(const BRepFill_BndBoxTreeSelector& ); - BRepFill_BndBoxTreeSelector& operator=(const BRepFill_BndBoxTreeSelector& ); Standard_Boolean Reject (const Bnd_Box2d& theBox) const { @@ -170,8 +175,8 @@ public: //intersection between bounding boxes is found, try to find intersection of edges if (theObj < myCInd) //intersection operation on some diff edges is symmetrical { - TopoDS_Edge E1 = TopoDS::Edge(mySeqOfEdges(theObj)); - TopoDS_Edge E2 = TopoDS::Edge(mySeqOfEdges(myCInd)); + TopoDS_Edge E1 = TopoDS::Edge(myMapOfEdges(theObj)); + TopoDS_Edge E2 = TopoDS::Edge(myMapOfEdges(myCInd)); { BRepAdaptor_Curve2d BA1(E1, myWFace); BRepAdaptor_Curve2d BA2(E2, myWFace); @@ -180,7 +185,7 @@ public: { //check result points relative to already existing vertices TopTools_IndexedMapOfShape aVV; - TopExp::MapShapes(E1, TopAbs_VERTEX, aVV); //?? create for all vertexes at once? + TopExp::MapShapes(E1, TopAbs_VERTEX, aVV); TopExp::MapShapes(E2, TopAbs_VERTEX, aVV); for (Standard_Integer i = 1; i <= inter.NbPoints(); i++) { @@ -211,7 +216,7 @@ public: const TopoDS_Vertex& V = TopoDS::Vertex(aVV.FindKey(i)); gp_Pnt PV = BRep_Tool::Pnt(V); Standard_Real TolV = BRep_Tool::Tolerance(V); - if (PV.SquareDistance(IntPnt) < (TolV+aFutTol)*(TolV+aFutTol)) //?? + if (PV.SquareDistance(IntPnt) < (TolV+aFutTol)*(TolV+aFutTol)) { CreateNewV = Standard_False; break; @@ -250,7 +255,7 @@ public: } else if (theObj == myCInd) //try to find self-intersection of edge { - TopoDS_Edge E = TopoDS::Edge(mySeqOfEdges(theObj)); + TopoDS_Edge E = TopoDS::Edge(myMapOfEdges(theObj)); BRepAdaptor_Curve2d BA(E, myWFace); Geom2dInt_GInter inter(BA, myPrec, myPrec); @@ -272,11 +277,14 @@ public: aCur->D0(Param1, p3d1); aCur->D0(Param2, p3d2); if (!Loc1.IsIdentity()) + { p3d1.Transform(Loc1.Transformation()); + p3d2.Transform(Loc1.Transformation()); + } gp_Pnt IntPnt((p3d1.XYZ() + p3d2.XYZ())/2.); Standard_Real TolE1 = BRep_Tool::Tolerance(E); - myBuilder.MakeVertex(V, IntPnt, 1.01* (TolE1 + (p3d1.Distance(p3d2)/2.))); + myBuilder.MakeVertex(V, IntPnt, 1.001* (TolE1 + (p3d1.Distance(p3d2)/2.))); // Save result of intersection to the map (edge -> seq. of parameters/vert on it) if (!myOutMapOfResult.Contains(E)) @@ -309,16 +317,14 @@ public: myCInd = theInd; } - void GetResult( NCollection_IndexedDataMap>& theOutMapOfResult) - { - theOutMapOfResult = myOutMapOfResult; - } +private: + BRepFill_BndBoxTreeSelector(const BRepFill_BndBoxTreeSelector& ); + BRepFill_BndBoxTreeSelector& operator=(const BRepFill_BndBoxTreeSelector& ); private: - TopTools_SequenceOfShape& mySeqOfEdges; //edges to be intersected with each other + TopTools_IndexedMapOfShape& myMapOfEdges; //edges to be intersected with each other const TopoDS_Face& myWFace; //work spine - NCollection_IndexedDataMap> myOutMapOfResult; // edge to it's intersection parameters (param + vertex) + NCollection_IndexedDataMap>& myOutMapOfResult; // edge to it's intersection parameters (param + vertex) //?? NCollection_DataMap - typedef this?? Bnd_Box2d myCBox; Standard_Integer myCInd; @@ -327,27 +333,22 @@ private: }; -class Poly_Helper : public Poly_MakeLoops2D::Helper +class BRepFill_PolyHelper : public Poly_MakeLoops2D::Helper { public: - Poly_Helper( const NCollection_DataMap& mL2TI, + BRepFill_PolyHelper( const NCollection_DataMap& mL2TI, const NCollection_DataMap& themNode2ListOfLinks) : myL2TI (mL2TI), mymNode2ListOfLinks (themNode2ListOfLinks) { - //Poly_MakeLoops2D::Helper(); - }; - Poly_Helper(const Poly_Helper& theOther) : Poly_MakeLoops2D::Helper(theOther), - mymNode2ListOfLinks (theOther.mymNode2ListOfLinks), myL2TI (theOther.myL2TI) - { - }; - Poly_Helper& operator= (const Poly_Helper &theOther); + }; virtual const Poly_MakeLoops2D::ListOfLink& GetAdjacentLinks (Standard_Integer theNode) const { return mymNode2ListOfLinks(theNode); } + virtual Standard_Boolean GetFirstTangent(const Poly_MakeLoops2D::Link& theLink, gp_Dir2d& theDir) const { theDir = myL2TI(theLink).myD1F; @@ -359,6 +360,9 @@ public: theDir = myL2TI(theLink).myD1L; return Standard_True; } +private: + + BRepFill_PolyHelper& operator= (const BRepFill_PolyHelper &theOther); private: const NCollection_DataMap& myL2TI; @@ -3084,28 +3088,31 @@ static void CollectWires(TopoDS_Compound& outCmp, Standard_Integer ind, void FindWireIntersections(const TopoDS_Wire& theW, const TopoDS_Face& theWorkSpine, NCollection_IndexedDataMap>& theME2IP) { - TopExp_Explorer ExpE( theW, TopAbs_EDGE ); - TopTools_SequenceOfShape Seq; - for (; ExpE.More(); ExpE.Next()) - Seq.Append( ExpE.Current() ); + //TopExp_Explorer ExpE( theW, TopAbs_EDGE ); + //TopTools_SequenceOfShape Seq; + //for (; ExpE.More(); ExpE.Next()) + // Seq.Append( ExpE.Current() ); + TopTools_IndexedMapOfShape EdgeMap; + TopExp::MapShapes(theW, TopAbs_EDGE, EdgeMap); //Prepare UBTree filler BRepFill_BndBoxTree aTree; NCollection_UBTreeFiller aTreeFiller (aTree); - BRepFill_BndBoxTreeSelector aSelector(Seq, theWorkSpine, Precision::Confusion()); + BRepFill_BndBoxTreeSelector aSelector(EdgeMap, theWorkSpine, theME2IP, Precision::Confusion()); // Prepare bounding boxes - NCollection_Sequence BndBoxesOfEdges; - for (Standard_Integer i = 1; i <= Seq.Length(); i++) + int nbBoxes = EdgeMap.Extent(); + NCollection_Array1 BndBoxesOfEdges(1, nbBoxes); + for (Standard_Integer i = 1; i <= nbBoxes; i++) { Standard_Real f, l; //too many calls of CurveOnSurface in removeloops. try to use adaptors and cache them?? - Handle_Geom2d_Curve aCur = BRep_Tool::CurveOnSurface(TopoDS::Edge(Seq(i)), theWorkSpine, f, l ); + Handle_Geom2d_Curve aCur = BRep_Tool::CurveOnSurface(TopoDS::Edge(EdgeMap(i)), theWorkSpine, f, l ); Bnd_Box2d aBox; BndLib_Add2dCurve::Add( aCur, f, l, 0., aBox ); aTreeFiller.Add(i, aBox); - BndBoxesOfEdges.Append(aBox); + BndBoxesOfEdges(i) = aBox; } aTreeFiller.Fill(); @@ -3118,7 +3125,7 @@ void FindWireIntersections(const TopoDS_Wire& theW, const TopoDS_Face& theWorkSp aTree.Select(aSelector); } - aSelector.GetResult(theME2IP); + //aSelector.GetResult(theME2IP); } void InsertIntersectionPoints(const NCollection_IndexedDataMap>& theME2IP, @@ -3131,9 +3138,9 @@ void InsertIntersectionPoints(const NCollection_IndexedDataMap& Params = theME2IP.FindFromIndex(i); - Handle_Geom_Curve aCur; + //Handle_Geom_Curve aCur; Standard_Real f, l; - aCur = BRep_Tool::Curve(E, f, l ); + BRep_Tool::Range(E, f, l ); //prepare params on the edge Standard_Integer nbPext = Params.Extent(); @@ -3145,7 +3152,7 @@ void InsertIntersectionPoints(const NCollection_IndexedDataMap, Standard_Real>::Perform(ParamArr, NCollection_Comparator(), ParamArr.Lower(), ParamArr.Upper()); + std::sort(ParamArr.begin(), ParamArr.end()); NCollection_Array1 aVOnEdge (1, nbPext + 2); //Vertexes on the edge which divide it by the intersection points into sequence of edges aVOnEdge(1) = TopExp::FirstVertex(E); @@ -3163,11 +3170,11 @@ void InsertIntersectionPoints(const NCollection_IndexedDataMap::Iterator aMapIt (mL2E); aMapIt.More(); aMapIt.Next()) aLoopMaker.AddLink(aMapIt.Key()); @@ -3320,7 +3327,7 @@ Standard_Boolean FindLoops(const TopoDS_Wire& theW, const TopoDS_Face& theWorkSp Standard_Integer NbLoops = aLoopMaker.GetNbLoops(); Standard_Integer NbHangs = aLoopMaker.GetNbHanging(); - if (NbLoops == 0 || NbHangs != 0 ) //or allow hang wires?? + if (NbLoops == 0 || NbHangs != 0 ) return Standard_False; for (Standard_Integer i = 1; i <= NbLoops; i++) //loops to wires @@ -3339,8 +3346,8 @@ Standard_Boolean FindLoops(const TopoDS_Wire& theW, const TopoDS_Face& theWorkSp if (aWM.IsDone()) { TopoDS_Wire W = aWM.Wire(); - if (W.Closed()) //?? just ignore non closed wires?? - theLoops.Append(W); + Standard_ASSERT_VOID(!W.Closed(), "BRepFill_OffsetWire: non closed wire"); + theLoops.Append(W); } } @@ -3353,7 +3360,7 @@ Standard_Boolean ClassifyLoops(const NCollection_List& theLoops, N NCollection_Sequence& theHoleWires, const TopoDS_Face& theWorkSpine, Standard_Integer& MaxMassInd, Standard_Boolean& IsMaxIsHole ) { // try to classify wires - BRepTopAdaptor_FClass2d* CFPointer = NULL; + NCollection_Handle CFPointer = NULL; NCollection_List::Iterator itL(theLoops); Standard_Real MaxMass = 0; @@ -3377,27 +3384,25 @@ Standard_Boolean ClassifyLoops(const NCollection_List& theLoops, N BB.Add (af, OSh); //try to use class2d only if mass is really low?? (after sprops checking) - BRepTopAdaptor_FClass2d* FClass = new BRepTopAdaptor_FClass2d(af, 0); + NCollection_Handle FClass = new BRepTopAdaptor_FClass2d(af, 0); TopAbs_State st = FClass->PerformInfinitePoint(); + Standard_ASSERT_VOID(st == TopAbs_UNKNOWN || st == TopAbs_ON, "BRepFill_OffsetWire: wrong infinite point classification result"); if (st == TopAbs_IN) theHoleWires.Append(TopoDS::Wire(OSh)); else if (st == TopAbs_OUT) theIWires.Append(TopoDS::Wire(OSh)); - else - { - delete FClass; //just exclude this loop if ori == unknown?? - continue; - } + + // IN or OUT states GProp_GProps pr; - BRepGProp::SurfaceProperties(af, pr, 0.); + BRepGProp::SurfaceProperties(af, pr); Standard_Real CurMass = Abs(pr.Mass()); if (CurMass > MaxMass) { MaxMass = CurMass; - delete CFPointer; + CFPointer.Nullify(); CFPointer = FClass; if (st == TopAbs_IN) { @@ -3410,16 +3415,16 @@ Standard_Boolean ClassifyLoops(const NCollection_List& theLoops, N IsMaxIsHole = Standard_False; } } - else - delete FClass; + + } if (!IsMaxIsHole && theIWires.Length() <= theHoleWires.Length() || IsMaxIsHole && theIWires.Length() >= theHoleWires.Length()) { - if (CFPointer) - delete CFPointer; + //if (CFPointer) + //delete CFPointer; return Standard_False; } @@ -3450,7 +3455,7 @@ Standard_Boolean ClassifyLoops(const NCollection_List& theLoops, N } } - delete CFPointer; + //delete CFPointer; if (!bFoundOuterP) return Standard_False; //cant find an outer wire @@ -3483,8 +3488,8 @@ static Standard_Boolean RemoveLoops(TopoDS_Shape& theInputSh, const TopoDS_Face& InsertIntersectionPoints(ME2IP, aW); - if (!ReorderWires(aW)) - continue; + //if (!ReorderWires(aW)) + //continue; NCollection_List aLoops; if (!FindLoops(aW, theWorkSpine, aLoops)) -- 2.39.5