From c4362927dc958358996bee5a711eef2733a63154 Mon Sep 17 00:00:00 2001 From: emv Date: Tue, 30 Jun 2015 12:22:42 +0300 Subject: [PATCH] Fix for correct shells splitting when building solids. --- src/BOPAlgo/BOPAlgo_MakerVolume.cxx | 2 +- src/BOPAlgo/BOPAlgo_ShellSplitter.cxx | 160 +++++++++++++++----------- 2 files changed, 95 insertions(+), 67 deletions(-) diff --git a/src/BOPAlgo/BOPAlgo_MakerVolume.cxx b/src/BOPAlgo/BOPAlgo_MakerVolume.cxx index 3b10f0714e..3e4f1a8189 100644 --- a/src/BOPAlgo/BOPAlgo_MakerVolume.cxx +++ b/src/BOPAlgo/BOPAlgo_MakerVolume.cxx @@ -244,7 +244,7 @@ void BOPAlgo_MakerVolume::MakeBox(BOPCol_MapOfShape& theBoxFaces) // Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, anExt; // - anExt = myBBox.SquareExtent() * 0.5; + anExt = sqrt(myBBox.SquareExtent()) * 0.5; myBBox.Enlarge(anExt); myBBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); // diff --git a/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx b/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx index 9b35a30af7..b188eb1363 100644 --- a/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx +++ b/src/BOPAlgo/BOPAlgo_ShellSplitter.cxx @@ -43,7 +43,8 @@ static TopoDS_Shell& ); // static - void RefineShell(TopoDS_Shell& theShell); + void RefineShell(TopoDS_Shell& theShell, + BOPCol_ListOfShape& aLShX); // static void MapEdgesAndFaces @@ -329,8 +330,9 @@ void BOPAlgo_ShellSplitter::SplitBlock(BOPTools_ConnexityBlock& aCB) BOPTools_CoupleOfShape aCSOff; BOPCol_MapOfOrientedShape AddedFacesMap; BOPCol_IndexedDataMapOfShapeListOfShape aEFMap, aMEFP; + Handle (IntTools_Context) aContext; // - Handle (IntTools_Context) aContext=new IntTools_Context; + aContext=new IntTools_Context; // const BOPCol_ListOfShape& myShapes=aCB.Shapes(); // @@ -454,15 +456,18 @@ void BOPAlgo_ShellSplitter::SplitBlock(BOPTools_ConnexityBlock& aCB) } // for (; aExp.More(); aExp.Next()) { } // for (; aItS.More(); aItS.Next()) { // - if (BRep_Tool::IsClosed(aShell)) { - aShell.Closed (Standard_True); - myLoops.Append(aShell); - } - else { - RefineShell(aShell); - if (BRep_Tool::IsClosed(aShell)) { - aShell.Closed (Standard_True); - myLoops.Append(aShell); + BOPCol_ListOfShape aLShX; + BOPCol_ListIteratorOfListOfShape aItLShX; + // + RefineShell(aShell, aLShX); + // + aItLShX.Initialize(aLShX); + for (; aItLShX.More(); aItLShX.Next()) { + TopoDS_Shell& aShX=*((TopoDS_Shell*)&aItLShX.Value()); + // + if (BRep_Tool::IsClosed(aShX)) { + aShX.Closed(Standard_True); + myLoops.Append(aShX); } } } // for (; aItF.More(); aItF.Next()) { @@ -471,7 +476,8 @@ void BOPAlgo_ShellSplitter::SplitBlock(BOPTools_ConnexityBlock& aCB) //function : RefineShell //purpose : //======================================================================= -void RefineShell(TopoDS_Shell& theShell) +void RefineShell(TopoDS_Shell& theShell, + BOPCol_ListOfShape& aLShX) { TopoDS_Iterator aIt; // @@ -480,12 +486,12 @@ void RefineShell(TopoDS_Shell& theShell) return; } // - Standard_Integer i, aNbMEF, aNbF; + Standard_Integer i, aNbMEF, aNbF, aNbMFB; BOPCol_IndexedDataMapOfShapeListOfShape aMEF; TopoDS_Builder aBB; TopExp_Explorer aExp; - BOPCol_MapOfShape aMEStop, aMFB; - BOPCol_MapIteratorOfMapOfShape aItM; + BOPCol_IndexedMapOfShape aMFB; + BOPCol_MapOfShape aMEStop, aMFProcessed; BOPCol_ListIteratorOfListOfShape aItLF, aItLFP; BOPCol_ListOfShape aLFP, aLFP1; // @@ -494,6 +500,7 @@ void RefineShell(TopoDS_Shell& theShell) TopAbs_EDGE, TopAbs_FACE, aMEF); + // aNbMEF=aMEF.Extent(); for (i=1; i<=aNbMEF; ++i) { const TopoDS_Shape& aE=aMEF.FindKey(i); @@ -505,68 +512,89 @@ void RefineShell(TopoDS_Shell& theShell) } // if (aMEStop.IsEmpty()) { + aLShX.Append(theShell); return; } // // The first Face - const TopoDS_Shape& aF1=aIt.Value(); - aMFB.Add(aF1); - aLFP.Append(aF1); - // - // Trying to reach the branch point - for (;;) { - aItLFP.Initialize(aLFP); - for (; aItLFP.More(); aItLFP.Next()) { - const TopoDS_Shape& aFP=aItLFP.Value(); - // - aExp.Init(aFP, TopAbs_EDGE); - for (; aExp.More(); aExp.Next()) { - const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); - if (aMEStop.Contains(aE)) { - continue; - } - // - if (BRep_Tool::Degenerated(aE)) { - continue; - } - // - const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE); + for (; aIt.More(); aIt.Next()) { + const TopoDS_Shape& aF1=aIt.Value(); + if (!aMFProcessed.Add(aF1)) { + continue; + } + // + aMFB.Clear(); + aLFP.Clear(); + // + aMFB.Add(aF1); + aLFP.Append(aF1); + // + // Trying to reach the branch point + for (;;) { + aItLFP.Initialize(aLFP); + for (; aItLFP.More(); aItLFP.Next()) { + const TopoDS_Shape& aFP=aItLFP.Value(); // - aItLF.Initialize(aLF); - for (; aItLF.More(); aItLF.Next()) { - const TopoDS_Shape& aFP1=aItLF.Value(); - if (aFP1.IsSame(aFP)) { + aExp.Init(aFP, TopAbs_EDGE); + for (; aExp.More(); aExp.Next()) { + const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); + if (aMEStop.Contains(aE)) { continue; } - if (aMFB.Contains(aFP1)) { + // + if (aE.Orientation() == TopAbs_INTERNAL) { continue; } - aMFB.Add(aFP1); - aLFP1.Append(aFP1); - }// for (; aItLF.More(); aItLF.Next()) { - }// for (; aExp.More(); aExp.Next()) { - }// for (; aItLFP.More(); aItLFP.Next()) { - // - // - if (aLFP1.IsEmpty()) { - break; - } + // + if (BRep_Tool::Degenerated(aE)) { + continue; + } + // + const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE); + // + aItLF.Initialize(aLF); + for (; aItLF.More(); aItLF.Next()) { + const TopoDS_Shape& aFP1=aItLF.Value(); + if (aFP1.IsSame(aFP)) { + continue; + } + if (aMFB.Contains(aFP1)) { + continue; + } + // + aMFProcessed.Add(aFP1); + aMFB.Add(aFP1); + aLFP1.Append(aFP1); + }// for (; aItLF.More(); aItLF.Next()) { + }// for (; aExp.More(); aExp.Next()) { + } // for (; aItLFP.More(); aItLFP.Next()) { + // + // + if (aLFP1.IsEmpty()) { + break; + } + // + aLFP.Clear(); + aItLF.Initialize(aLFP1); + for (; aItLF.More(); aItLF.Next()) { + const TopoDS_Shape& aFP1=aItLF.Value(); + aLFP.Append(aFP1); + } + aLFP1.Clear(); + }// for (;;) { // - aLFP.Clear(); - aItLF.Initialize(aLFP1); - for (; aItLF.More(); aItLF.Next()) { - const TopoDS_Shape& aFP1=aItLF.Value(); - aLFP.Append(aFP1); + aNbMFB=aMFB.Extent(); + if (aNbMFB) { + TopoDS_Shell aShX; + aBB.MakeShell(aShX); + // + for (i=1; i<=aNbMFB; ++i) { + const TopoDS_Shape& aFB=aMFB(i); + aBB.Add(aShX, aFB); + } + aLShX.Append(aShX); } - aLFP1.Clear(); - }// for (;;) { - // - // Remove all faces before the branch point - aItM.Initialize(aMFB); - for (; aItM.More(); aItM.Next()) { - const TopoDS_Shape& aFB=aItM.Value(); - aBB.Remove(theShell, aFB); - } + }//for (; aIt.More(); aIt.Next()) { } //======================================================================= //function : MakeShells -- 2.39.5