1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BOPAlgo_WireEdgeSet.hxx>
18 #include <BOPAlgo_WireSplitter.hxx>
19 #include <BOPAlgo_Alerts.hxx>
20 #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
21 #include <BOPCol_IndexedMapOfShape.hxx>
22 #include <BOPCol_ListOfShape.hxx>
23 #include <BOPCol_MapOfShape.hxx>
24 #include <BOPCol_NCVector.hxx>
25 #include <BOPCol_Parallel.hxx>
26 #include <BOPTools.hxx>
27 #include <BRep_Builder.hxx>
28 #include <BRep_Tool.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Wire.hxx>
36 //=======================================================================
39 //=======================================================================
40 BOPAlgo_WireSplitter::BOPAlgo_WireSplitter()
47 //=======================================================================
50 //=======================================================================
51 BOPAlgo_WireSplitter::BOPAlgo_WireSplitter
52 (const Handle(NCollection_BaseAllocator)& theAllocator)
54 BOPAlgo_Algo(theAllocator),
59 //=======================================================================
62 //=======================================================================
63 BOPAlgo_WireSplitter::~BOPAlgo_WireSplitter()
66 //=======================================================================
69 //=======================================================================
70 void BOPAlgo_WireSplitter::SetWES(const BOPAlgo_WireEdgeSet& theWES)
72 myWES=(BOPAlgo_WireEdgeSet*)&theWES;
74 //=======================================================================
77 //=======================================================================
78 BOPAlgo_WireEdgeSet& BOPAlgo_WireSplitter::WES()
82 //=======================================================================
83 //function : SetContext
85 //=======================================================================
86 void BOPAlgo_WireSplitter::SetContext(const Handle(IntTools_Context)& theContext)
88 myContext = theContext;
90 //=======================================================================
93 //=======================================================================
94 const Handle(IntTools_Context)& BOPAlgo_WireSplitter::Context()
98 //=======================================================================
99 // function: CheckData
101 //=======================================================================
102 void BOPAlgo_WireSplitter::CheckData()
105 AddError (new BOPAlgo_AlertNullInputShapes);
109 //=======================================================================
112 //=======================================================================
113 void BOPAlgo_WireSplitter::Perform()
115 GetReport()->Clear();
123 if (myContext.IsNull()) {
124 myContext = new IntTools_Context;
127 MakeConnexityBlocks();
131 //=======================================================================
132 //function : MakeConnexityBlocks
134 //=======================================================================
135 void BOPAlgo_WireSplitter::MakeConnexityBlocks()
137 Standard_Boolean bRegular, bClosed;
138 Standard_Integer i, j, aNbV, aNbVS, aNbVP, k;
139 TopoDS_Iterator aItE;
141 BOPCol_ListIteratorOfListOfShape aIt;
143 BOPCol_IndexedDataMapOfShapeListOfShape aMVE(100, myAllocator);
144 BOPCol_IndexedMapOfShape aMVP(100, myAllocator);
145 BOPCol_IndexedMapOfShape aMEC(100, myAllocator);
146 BOPCol_MapOfShape aMER(100, myAllocator);
147 BOPCol_MapOfShape aMEP(100, myAllocator);
148 BOPCol_IndexedMapOfShape aMVAdd(100, myAllocator);
149 BOPCol_MapOfShape aMVS(100, myAllocator);
153 const BOPCol_ListOfShape& aLSE=myWES->StartElements();
154 aIt.Initialize(aLSE);
155 for (; aIt.More(); aIt.Next()) {
156 const TopoDS_Shape& aE=aIt.Value();
158 BOPTools::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
167 for (i=1; i<=aNbV; ++i) {
173 const TopoDS_Shape& aV=aMVE.FindKey(i);
178 // aMVS - globally processed vertices
180 //------------------------------------- goal: aMEC
181 aMEC.Clear(); // aMEC - edges of CB
182 aMVP.Clear(); // aMVP - vertices to process right now
183 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
189 for (k=1; k<=aNbVP; ++k) {
190 const TopoDS_Shape& aVP=aMVP(k);
191 const BOPCol_ListOfShape& aLE=aMVE.FindFromKey(aVP);
193 for (; aIt.More(); aIt.Next()) {
194 const TopoDS_Shape& aE=aIt.Value();
197 for (; aItE.More(); aItE.Next()) {
198 const TopoDS_Shape& aVE=aItE.Value();
205 }//for (k=1; k<=aNbVP; ++k) {
207 aNbVP=aMVAdd.Extent();
209 break; // from while(1)
214 for (k=1; k<=aNbVP; ++k) {
215 const TopoDS_Shape& aVE=aMVAdd(k);
221 //-------------------------------------
222 BOPTools_ConnexityBlock aCB(myAllocator);
223 BOPCol_ListOfShape& aLEC=aCB.ChangeShapes();
225 BOPCol_IndexedDataMapOfShapeListOfShape aMVER(100, myAllocator);
227 bRegular=Standard_True;
228 Standard_Integer aNbCB = aMEC.Extent();
229 for (j = 1; j <= aNbCB; j++) {
232 if (aMER.Contains(aER)) {
233 aER.Orientation(TopAbs_FORWARD);
235 aER.Orientation(TopAbs_REVERSED);
237 bRegular=Standard_False;
244 BOPTools::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
249 Standard_Integer aNbVR, aNbER;
251 aNbVR=aMVER.Extent();
252 for (k=1; k<=aNbVR; ++k) {
253 const BOPCol_ListOfShape& aLER=aMVER(k);
256 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
257 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
270 aCB.SetRegular(bRegular);
274 /////////////////////////////////////////////////////////////////////////
275 class BOPAlgo_WS_ConnexityBlock {
277 BOPAlgo_WS_ConnexityBlock() {};
278 ~BOPAlgo_WS_ConnexityBlock() {};
280 void SetFace(const TopoDS_Face& theF) {
284 const TopoDS_Face& Face() const {
288 void SetConnexityBlock(const BOPTools_ConnexityBlock& theCB) {
292 const BOPTools_ConnexityBlock& ConnexityBlock() const {
296 void SetContext(const Handle(IntTools_Context)& aContext) {
297 myContext = aContext;
300 const Handle(IntTools_Context)& Context()const {
305 BOPAlgo_WireSplitter::SplitBlock(myFace, myCB, myContext);
310 BOPTools_ConnexityBlock myCB;
311 Handle(IntTools_Context) myContext;
314 typedef BOPCol_NCVector<BOPAlgo_WS_ConnexityBlock> \
315 BOPAlgo_VectorOfConnexityBlock;
317 typedef BOPCol_ContextFunctor
318 <BOPAlgo_WS_ConnexityBlock,
319 BOPAlgo_VectorOfConnexityBlock,
320 Handle(IntTools_Context),
321 IntTools_Context> BOPAlgo_SplitBlockFunctor;
323 typedef BOPCol_ContextCnt
324 <BOPAlgo_SplitBlockFunctor,
325 BOPAlgo_VectorOfConnexityBlock,
326 Handle(IntTools_Context)> BOPAlgo_SplitBlockCnt;
328 //=======================================================================
329 //function : MakeWires
331 //=======================================================================
332 void BOPAlgo_WireSplitter::MakeWires()
334 Standard_Boolean bIsRegular;
335 Standard_Integer aNbVCB, k;
337 BOPTools_ListIteratorOfListOfConnexityBlock aItCB;
338 BOPCol_ListIteratorOfListOfShape aIt;
339 BOPAlgo_VectorOfConnexityBlock aVCB;
341 const TopoDS_Face& aF=myWES->Face();
343 aItCB.Initialize(myLCB);
344 for (; aItCB.More(); aItCB.Next()) {
345 BOPTools_ConnexityBlock& aCB=aItCB.ChangeValue();
346 bIsRegular=aCB.IsRegular();
348 BOPCol_ListOfShape& aLE=aCB.ChangeShapes();
349 BOPAlgo_WireSplitter::MakeWire(aLE, aW);
353 BOPAlgo_WS_ConnexityBlock& aWSCB = aVCB.Append1();
355 aWSCB.SetConnexityBlock(aCB);
358 //===================================================
359 BOPAlgo_SplitBlockCnt::Perform(myRunParallel, aVCB, myContext);
360 //===================================================
361 aNbVCB=aVCB.Extent();
362 for (k=0; k<aNbVCB; ++k) {
363 const BOPAlgo_WS_ConnexityBlock& aCB=aVCB(k);
364 const BOPCol_ListOfShape& aLW=aCB.ConnexityBlock().Loops();
366 for (; aIt.More(); aIt.Next()) {
367 const TopoDS_Shape& aWx=aIt.Value();
368 myWES->AddShape(aWx);