From ac09d33e8fa542d652bc40dbc2f9f2087bc08a2c Mon Sep 17 00:00:00 2001 From: emv Date: Mon, 4 Apr 2016 15:37:55 +0300 Subject: [PATCH] BRepOffset_MakeOffset::IntersectFaces() - Careful definition of the vertices to avoid while trimming the new edges. --- src/BRepOffset/BRepOffset_Inter2d.cdl | 9 +- src/BRepOffset/BRepOffset_Inter2d.cxx | 2 +- src/BRepOffset/BRepOffset_MakeOffset.cxx | 276 ++++++++++++++--------- 3 files changed, 175 insertions(+), 112 deletions(-) diff --git a/src/BRepOffset/BRepOffset_Inter2d.cdl b/src/BRepOffset/BRepOffset_Inter2d.cdl index 30ea15943a..1b11fc7188 100644 --- a/src/BRepOffset/BRepOffset_Inter2d.cdl +++ b/src/BRepOffset/BRepOffset_Inter2d.cdl @@ -25,6 +25,7 @@ uses AsDes from BRepAlgo, Offset from BRepOffset, Face from TopoDS, + Edge from TopoDS, IndexedMapOfShape from TopTools, DataMapOfShapeShape from TopTools, Real from Standard @@ -52,6 +53,12 @@ is Offset : Real from Standard; Tol : Real from Standard); -- Modified by skv - Fri Dec 26 16:53:16 2003 OCC4455 End - + + ExtentEdge(myclass ; + E : Edge from TopoDS; + NE : out Edge from TopoDS; + Offset : Real from Standard); + ---Purpose: Extents the edge + end Inter2d; diff --git a/src/BRepOffset/BRepOffset_Inter2d.cxx b/src/BRepOffset/BRepOffset_Inter2d.cxx index 1b733cb477..a67719c0be 100644 --- a/src/BRepOffset/BRepOffset_Inter2d.cxx +++ b/src/BRepOffset/BRepOffset_Inter2d.cxx @@ -925,7 +925,7 @@ static Standard_Boolean ExtendPCurve(const Handle(Geom2d_Curve)& aPCurve, // Modified by skv - Fri Dec 26 17:00:55 2003 OCC4455 Begin //static void ExtentEdge(const TopoDS_Edge& E,TopoDS_Edge& NE) -static void ExtentEdge(const TopoDS_Edge& E,TopoDS_Edge& NE, const Standard_Real theOffset) +void BRepOffset_Inter2d::ExtentEdge(const TopoDS_Edge& E,TopoDS_Edge& NE, const Standard_Real theOffset) { //BRepLib::BuildCurve3d(E); diff --git a/src/BRepOffset/BRepOffset_MakeOffset.cxx b/src/BRepOffset/BRepOffset_MakeOffset.cxx index 3fbeb16818..2213c92db3 100644 --- a/src/BRepOffset/BRepOffset_MakeOffset.cxx +++ b/src/BRepOffset/BRepOffset_MakeOffset.cxx @@ -528,6 +528,7 @@ static static void TrimEdges(const TopoDS_Shape& theShape, + const Standard_Real theOffset, BRepOffset_DataMapOfShapeOffset& theMapSF, TopTools_DataMapOfShapeShape& theMES, TopTools_DataMapOfShapeShape& theBuild, @@ -1426,7 +1427,7 @@ void BRepOffset_MakeOffset::BuildOffsetByInter() //Map of edges obtained after FACE-FACE (offsetted) intersection. //Key1 is edge trimmed by intersection points with other edges; //Item is not-trimmed edge. - TrimEdges(myShape, MapSF, MES, Build, AsDes, AsDes2d, NewEdges, aETrimEInf, anEdgesOrigins); + TrimEdges(myShape, myOffset, MapSF, MES, Build, AsDes, AsDes2d, NewEdges, aETrimEInf, anEdgesOrigins); // //--------------------------------- // Intersection 2D on // @@ -3783,6 +3784,7 @@ void BRepOffset_MakeOffset::IntersectEdges(const TopoDS_Shape& theShape, //purpose : //======================================================================= void TrimEdges(const TopoDS_Shape& theShape, + const Standard_Real theOffset, BRepOffset_DataMapOfShapeOffset& theMapSF, TopTools_DataMapOfShapeShape& theMES, TopTools_DataMapOfShapeShape& theBuild, @@ -3894,7 +3896,12 @@ void TrimEdges(const TopoDS_Shape& theShape, TrimEdge (TopoDS::Edge(NE), theAsDes2d, theAsDes, theETrimEInf); } } - theAsDes->Add(NF,NE); + else { + TopoDS_Edge aNewEdge; + BRepOffset_Inter2d::ExtentEdge(TopoDS::Edge(NE), aNewEdge, theOffset); + theETrimEInf.Bind(NE, aNewEdge); + } + theAsDes->Add(NF, NE); } } } @@ -3963,8 +3970,9 @@ void IntersectTrimmedEdges(const TopTools_ListOfShape& theLF, continue; } // - theNewEdges.Add(aE); - aLS.Append(aE); + if (theNewEdges.Add(aE)) { + aLS.Append(aE); + } } } // @@ -4940,14 +4948,33 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui } // Standard_Integer i, j, k, aNbInv; - TopTools_ListIteratorOfListOfShape aItLE, aItLEO, aItLF; - TopTools_MapOfShape aMFence, aMVBounds; - TopTools_DataMapOfShapeListOfShape aDMEF, aMDone, aEImages; - TopTools_IndexedDataMapOfShapeListOfShape aFLE; + TopTools_ListIteratorOfListOfShape aItLF, aItLE; TopExp_Explorer aExp; - BRep_Builder aBB; // - // Add all faces to rebuild to outgoing map, plus link valid edges to faces + // get vertices from invalid edges + TopTools_MapOfShape aMVInv, aMVInvAll; + aNbInv = theInvEdges.Extent(); + for (i = 1; i <= aNbInv; ++i) { + const TopoDS_Shape& aEInv = theInvEdges(i); + Standard_Boolean bValid = theValidEdges.Contains(aEInv); + aExp.Init(aEInv, TopAbs_VERTEX); + for (; aExp.More(); aExp.Next()) { + const TopoDS_Shape& aV = aExp.Current(); + aMVInvAll.Add(aV); + if (!bValid) { + aMVInv.Add(aV); + } + } + } + // + Standard_Boolean bLookVertToAvoid = (aMVInv.Extent() > 0); + // + TopTools_DataMapOfShapeListOfShape aDMSF, aMDone, aMEInfETrim, aDMVEFull; + TopTools_IndexedDataMapOfShapeListOfShape aFLE, aDMEFInv; + // + // Add all faces to rebuild to outgoing map , + // plus link edges and vertices to the faces to + // define intersection faces for (i = 1; i <= aNbFR; ++i) { const TopoDS_Shape& aF = theFToRebuild.FindKey(i); // @@ -4956,112 +4983,175 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui aMDone.Bind(aF, aLE); // const TopTools_ListOfShape& aLFIm = theDMFFIm.FindFromKey(aF); - aItLE.Initialize(aLFIm); - for (; aItLE.More(); aItLE.Next()) { - const TopoDS_Shape& aFIm = aItLE.Value(); - // + aItLF.Initialize(aLFIm); + for (; aItLF.More(); aItLF.Next()) { + const TopoDS_Shape& aFIm = aItLF.Value(); aExp.Init(aFIm, TopAbs_EDGE); for (; aExp.More(); aExp.Next()) { const TopoDS_Shape& aE = aExp.Current(); - // - if (aE.Orientation() == TopAbs_INTERNAL) { - //continue; - } - // - if (aDMEF.IsBound(aE)) { - TopTools_ListOfShape& aLF = aDMEF.ChangeFind(aE); + // save connection to untrimmed face + if (aDMSF.IsBound(aE)) { + TopTools_ListOfShape& aLF = aDMSF.ChangeFind(aE); AppendToList(aLF, aF); } else { TopTools_ListOfShape aLF; aLF.Append(aF); - aDMEF.Bind(aE, aLF); + aDMSF.Bind(aE, aLF); + } + // + // save connection to untrimmed edge + const TopoDS_Shape& aEInf = theETrimEInf.Find(aE); + if (aMEInfETrim.IsBound(aEInf)) { + TopTools_ListOfShape& aLETrim = aMEInfETrim.ChangeFind(aEInf); + AppendToList(aLETrim, aE); + } + else { + TopTools_ListOfShape aLETrim; + aLETrim.Append(aE); + aMEInfETrim.Bind(aEInf, aLETrim); } // TopExp_Explorer aExpV(aE, TopAbs_VERTEX); for (; aExpV.More(); aExpV.Next()) { const TopoDS_Shape& aV = aExpV.Current(); - if (aDMEF.IsBound(aV)) { - TopTools_ListOfShape& aLF = aDMEF.ChangeFind(aV); + // save connection to face + if (aDMSF.IsBound(aV)) { + TopTools_ListOfShape& aLFV = aDMSF.ChangeFind(aV); + AppendToList(aLFV, aF); + } + else { + TopTools_ListOfShape aLFV; + aLFV.Append(aF); + aDMSF.Bind(aV, aLFV); + } + // + if (bLookVertToAvoid) { + // save connection to edges + if (aDMVEFull.IsBound(aV)) { + TopTools_ListOfShape& aLEV = aDMVEFull.ChangeFind(aV); + AppendToList(aLEV, aE); + } + else { + TopTools_ListOfShape aLEV; + aLEV.Append(aE); + aDMVEFull.Bind(aV, aLEV); + } + } + } + } + } + // + if (bLookVertToAvoid) { + // get edges of invalid faces (from invalid splits only) + if (!theInvFaces.Contains(aF) || theArtInvFaces.IsBound(aF)) { + continue; + } + // + const TopTools_ListOfShape& aLFInv = theInvFaces.FindFromKey(aF); + // + aItLF.Initialize(aLFInv); + for (; aItLF.More(); aItLF.Next()) { + const TopoDS_Shape& aFInv = aItLF.Value(); + aExp.Init(aFInv, TopAbs_EDGE); + for (; aExp.More(); aExp.Next()) { + const TopoDS_Shape& aE = aExp.Current(); + if (aDMEFInv.Contains(aE)) { + TopTools_ListOfShape& aLF = aDMEFInv.ChangeFromKey(aE); AppendToList(aLF, aF); } else { TopTools_ListOfShape aLF; aLF.Append(aF); - aDMEF.Bind(aV, aLF); + aDMEFInv.Add(aE, aLF); } } } } } // - // Collect vertices to avoid while trimming the edges - TopTools_MapOfShape aMVInv, aMVRInv, aMVInvAll; - // - // get vertices from invalid edges - aNbInv = theInvEdges.Extent(); + // Find vertices to avoid while trimming the edges. + // These vertices are taken from the invalid edges common between + // splits of different invalid, but not artificially, faces. + // Additional condition for these vertices is that all + // edges adjacent to this vertex must be either invalid + // or contained in invalid faces + TopTools_MapOfShape aMFence, aMVRInv = theVertsToAvoid; + aNbInv = aDMEFInv.Extent(); for (i = 1; i <= aNbInv; ++i) { - const TopoDS_Shape& aEInv = theInvEdges(i); - Standard_Boolean bValid = theValidEdges.Contains(aEInv); - TopExp_Explorer aExp(aEInv, TopAbs_VERTEX); + const TopTools_ListOfShape& aLFInv = aDMEFInv(i); + if (aLFInv.Extent() == 1) { + continue; + } + // + const TopoDS_Shape& aE = aDMEFInv.FindKey(i); + if (!theInvEdges.Contains(aE) || theValidEdges.Contains(aE)) { + continue; + } + // + aExp.Init(aE, TopAbs_VERTEX); for (; aExp.More(); aExp.Next()) { const TopoDS_Shape& aV = aExp.Current(); - aMVInvAll.Add(aV); - if (!bValid) { - aMVInv.Add(aV); + if (!aDMVEFull.IsBound(aV)) { + aMVRInv.Add(aV); + continue; + } + // + const TopTools_ListOfShape& aLE = aDMVEFull.Find(aV); + // + aItLE.Initialize(aLE); + for (; aItLE.More(); aItLE.Next()) { + const TopoDS_Shape& aEV = aItLE.Value(); + if (!theInvEdges.Contains(aEV) && !aDMEFInv.Contains(aEV)) { + break; + } + } + if (!aItLE.More()) { + aMVRInv.Add(aV); } } } // - // vertices to avoid from previous steps - TopTools_MapIteratorOfMapOfShape aItM(theVertsToAvoid); - for (; aItM.More(); aItM.Next()) { - aMVRInv.Add(aItM.Key()); - } - // - // Save connections between not trimmed edge and its trimmed parts - TopTools_DataMapOfShapeListOfShape aDMEETrim; - // // The faces should be intersected selectively - - // intersect only faces neighboring to the same invalid face - // and connected somehow to its invalid edges - // - // compound of valid edges of invalid faces - TopoDS_Compound aCEInv; - aBB.MakeCompound(aCEInv); - // + // intersect only faces neighboring to the same invalid faceupdatevla + // and connected to its invalid edges and its valid edges with free bounds + TopTools_MapOfShape aMEAlone; + TopTools_IndexedDataMapOfShapeListOfShape aDMVEVal; aMFence.Clear(); + // aNbInv = theInvFaces.Extent(); - for (k = 1; k <= aNbInv; ++k) { - const TopTools_ListOfShape& aLFInv = theInvFaces(k); - TopTools_ListIteratorOfListOfShape aIt(aLFInv); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Shape& aFIm = aIt.Value(); - aExp.Init(aFIm, TopAbs_EDGE); + for (i = 1; i <= aNbInv; ++i) { + const TopTools_ListOfShape& aLFInv = theInvFaces(i); + aItLF.Initialize(aLFInv); + for (; aItLF.More(); aItLF.Next()) { + const TopoDS_Shape& aFInv = aItLF.Value(); + aExp.Init(aFInv, TopAbs_EDGE); for (; aExp.More(); aExp.Next()) { const TopoDS_Shape& aE = aExp.Current(); if (!theInvEdges.Contains(aE) && aMFence.Add(aE)) { - aBB.Add(aCEInv, aE); + TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aDMVEVal); } } } } // // collect edges with free vertices - TopTools_MapOfShape aMEAlone; - TopTools_IndexedDataMapOfShapeListOfShape aDMVE; - TopExp::MapShapesAndAncestors(aCEInv, TopAbs_VERTEX, TopAbs_EDGE, aDMVE); - // - Standard_Integer aNbV = aDMVE.Extent(); + Standard_Integer aNbV = aDMVEVal.Extent(); for (i = 1; i <= aNbV; ++i) { - const TopTools_ListOfShape& aLEV = aDMVE(i); + const TopTools_ListOfShape& aLEV = aDMVEVal(i); if (aLEV.Extent() == 1) { const TopoDS_Shape& aE = aLEV.First(); aMEAlone.Add(aE); } } // - aMFence.Clear(); + // Bounding vertices of not trimmed edges + TopTools_MapOfShape aMVBounds; + // Save connections between not trimmed edge and its trimmed parts + TopTools_DataMapOfShapeListOfShape aDMEETrim; + // Splits of the new edges + TopTools_DataMapOfShapeListOfShape aEImages; + BRep_Builder aBB; // aNbInv = theInvFaces.Extent(); for (k = 1; k <= aNbInv; ++k) { @@ -5114,8 +5204,6 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui for (; aItLCBE.More(); aItLCBE.Next()) { const TopoDS_Shape& aCBELoc = aItLCBE.Value(); // - // map to keep connection between vertices and edges - TopTools_IndexedDataMapOfShapeListOfShape aDMVE; // map of edges and vertices of processing invalidity TopTools_IndexedMapOfShape aME; // map of vertices to trim the new edges @@ -5135,8 +5223,8 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui Standard_Integer aNbE = aME.Extent(); for (i = 1; i <= aNbE; ++i) { const TopoDS_Shape& aS = aME(i); - if (aDMEF.IsBound(aS)) { - const TopTools_ListOfShape& aLF = aDMEF.Find(aS); + if (aDMSF.IsBound(aS)) { + const TopTools_ListOfShape& aLF = aDMSF.Find(aS); aItLE.Initialize(aLF); for (; aItLE.More(); aItLE.Next()) { const TopoDS_Shape& aF = aItLE.Value(); @@ -5155,7 +5243,6 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui for (; aItLFIm.More(); aItLFIm.Next()) { const TopoDS_Shape& aFIm = aItLFIm.Value(); aLFInt.Append(aFIm); - TopExp::MapShapesAndAncestors(aFIm, TopAbs_VERTEX, TopAbs_EDGE, aDMVE); } } } @@ -5213,18 +5300,11 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui const TopoDS_Shape& aEInt = theETrimEInf.Find(aEC); // find the edges of the same original edge // and take their vertices as well - TopExp_Explorer aExpV(aEC, TopAbs_VERTEX); - for (; aExpV.More(); aExpV.Next()) { - const TopoDS_Shape& aV = aExpV.Current(); - const TopTools_ListOfShape& aLVE = aDMVE.FindFromKey(aV); - TopTools_ListIteratorOfListOfShape aItLVE(aLVE); - for (; aItLVE.More(); aItLVE.Next()) { - const TopoDS_Shape& aECx = aItLVE.Value(); - const TopoDS_Shape& aEIntx = theETrimEInf.Find(aECx); - if (aEInt.IsSame(aEIntx)) { - TopExp::MapShapes(aECx, TopAbs_VERTEX, aMECV); - } - } + const TopTools_ListOfShape& aLVE = aMEInfETrim.Find(aEInt); + TopTools_ListIteratorOfListOfShape aItLVE(aLVE); + for (; aItLVE.More(); aItLVE.Next()) { + const TopoDS_Shape& aECx = aItLVE.Value(); + TopExp::MapShapes(aECx, TopAbs_VERTEX, aMECV); } // // bind unlimited edge to its trimmed part in face to update maps of @@ -5248,26 +5328,6 @@ void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebui // check if both these faces are invalid and sharing edges if (theInvFaces.Contains(aFi) && theInvFaces.Contains(aFj) && !theArtInvFaces.IsBound(aFi) && !theArtInvFaces.IsBound(aFj)) { - const TopTools_ListOfShape& aLFInvi = theInvFaces.FindFromKey(aFi); - const TopTools_ListOfShape& aLFInvj = theInvFaces.FindFromKey(aFj); - // - // try to find common parts between these two lists - TopTools_ListOfShape aLFInvij; - FindCommonParts(aLFInvi, aLFInvj, aLFInvij); - // - if (aLFInvij.Extent()) { - TopTools_ListIteratorOfListOfShape aItLEInv(aLFInvij); - for (; aItLEInv.More(); aItLEInv.Next()) { - const TopoDS_Shape& aEx = aItLEInv.Value(); - if (theInvEdges.Contains(aEx) && !theValidEdges.Contains(aEx)) { - TopExp_Explorer aExpV(aEx, TopAbs_VERTEX); - for (; aExpV.More(); aExpV.Next()) { - const TopoDS_Shape& aVx = aExpV.Current(); - aMVRInv.Add(aVx); - } - } - } - } continue; } // @@ -6546,9 +6606,6 @@ void UpdateIntersectedEdges(const TopTools_ListOfShape& theLA, TopTools_DataMapOfShapeShape& theETrimEInf, BOPAlgo_Builder& theB) { - if(!theB.HasModified()) { - return; - } TopTools_ListIteratorOfListOfShape aItA, aIt; // aItA.Initialize(theLA); @@ -6564,12 +6621,11 @@ void UpdateIntersectedEdges(const TopTools_ListOfShape& theLA, continue; } // - const TopoDS_Edge& anEInf = TopoDS::Edge(theETrimEInf.Find(aS)); - // + const TopoDS_Shape& anEInf = theETrimEInf.Find(aS); + // aIt.Initialize(aLSIm); for (; aIt.More(); aIt.Next()) { - const TopoDS_Edge& anE = TopoDS::Edge(aIt.Value()); - // + const TopoDS_Shape& anE = aIt.Value(); if (!theETrimEInf.IsBound(anE)) { theETrimEInf.Bind(anE, anEInf); } -- 2.39.5