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 <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
20 #include <BOPCol_IndexedMapOfShape.hxx>
21 #include <BOPCol_ListOfShape.hxx>
22 #include <BOPCol_MapOfShape.hxx>
23 #include <BOPCol_NCVector.hxx>
24 #include <BOPCol_Parallel.hxx>
25 #include <BOPTools.hxx>
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Wire.hxx>
35 //=======================================================================
38 //=======================================================================
39 BOPAlgo_WireSplitter::BOPAlgo_WireSplitter()
46 //=======================================================================
49 //=======================================================================
50 BOPAlgo_WireSplitter::BOPAlgo_WireSplitter
51 (const Handle(NCollection_BaseAllocator)& theAllocator)
53 BOPAlgo_Algo(theAllocator),
58 //=======================================================================
61 //=======================================================================
62 BOPAlgo_WireSplitter::~BOPAlgo_WireSplitter()
65 //=======================================================================
68 //=======================================================================
69 void BOPAlgo_WireSplitter::SetWES(const BOPAlgo_WireEdgeSet& theWES)
71 myWES=(BOPAlgo_WireEdgeSet*)&theWES;
73 //=======================================================================
76 //=======================================================================
77 BOPAlgo_WireEdgeSet& BOPAlgo_WireSplitter::WES()
81 //=======================================================================
82 // function: CheckData
84 //=======================================================================
85 void BOPAlgo_WireSplitter::CheckData()
93 //=======================================================================
96 //=======================================================================
97 void BOPAlgo_WireSplitter::Perform()
106 MakeConnexityBlocks();
110 //=======================================================================
111 //function : MakeConnexityBlocks
113 //=======================================================================
114 void BOPAlgo_WireSplitter::MakeConnexityBlocks()
116 Standard_Boolean bRegular, bClosed;
117 Standard_Integer i, j, aNbV, aNbVS, aNbVP, k;
118 TopoDS_Iterator aItE;
120 BOPCol_ListIteratorOfListOfShape aIt;
122 BOPCol_IndexedDataMapOfShapeListOfShape aMVE(100, myAllocator);
123 BOPCol_IndexedMapOfShape aMVP(100, myAllocator);
124 BOPCol_IndexedMapOfShape aMEC(100, myAllocator);
125 BOPCol_MapOfShape aMER(100, myAllocator);
126 BOPCol_MapOfShape aMEP(100, myAllocator);
127 BOPCol_IndexedMapOfShape aMVAdd(100, myAllocator);
128 BOPCol_MapOfShape aMVS(100, myAllocator);
132 const BOPCol_ListOfShape& aLSE=myWES->StartElements();
133 aIt.Initialize(aLSE);
134 for (; aIt.More(); aIt.Next()) {
135 const TopoDS_Shape& aE=aIt.Value();
137 BOPTools::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
146 for (i=1; i<=aNbV; ++i) {
152 const TopoDS_Shape& aV=aMVE.FindKey(i);
157 // aMVS - globally processed vertices
159 //------------------------------------- goal: aMEC
160 aMEC.Clear(); // aMEC - edges of CB
161 aMVP.Clear(); // aMVP - vertices to process right now
162 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
168 for (k=1; k<=aNbVP; ++k) {
169 const TopoDS_Shape& aVP=aMVP(k);
170 const BOPCol_ListOfShape& aLE=aMVE.FindFromKey(aVP);
172 for (; aIt.More(); aIt.Next()) {
173 const TopoDS_Shape& aE=aIt.Value();
176 for (; aItE.More(); aItE.Next()) {
177 const TopoDS_Shape& aVE=aItE.Value();
184 }//for (k=1; k<=aNbVP; ++k) {
186 aNbVP=aMVAdd.Extent();
188 break; // from while(1)
193 for (k=1; k<=aNbVP; ++k) {
194 const TopoDS_Shape& aVE=aMVAdd(k);
200 //-------------------------------------
201 BOPTools_ConnexityBlock aCB(myAllocator);
202 BOPCol_ListOfShape& aLEC=aCB.ChangeShapes();
204 BOPCol_IndexedDataMapOfShapeListOfShape aMVER(100, myAllocator);
206 bRegular=Standard_True;
207 Standard_Integer aNbCB = aMEC.Extent();
208 for (j = 1; j <= aNbCB; j++) {
211 if (aMER.Contains(aER)) {
212 aER.Orientation(TopAbs_FORWARD);
214 aER.Orientation(TopAbs_REVERSED);
216 bRegular=Standard_False;
223 BOPTools::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
228 Standard_Integer aNbVR, aNbER;
230 aNbVR=aMVER.Extent();
231 for (k=1; k<=aNbVR; ++k) {
232 const BOPCol_ListOfShape& aLER=aMVER(k);
235 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
236 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
249 aCB.SetRegular(bRegular);
253 /////////////////////////////////////////////////////////////////////////
255 typedef BOPCol_NCVector<BOPTools_ConnexityBlock> \
256 BOPTools_VectorOfConnexityBlock;
258 //=======================================================================
259 //class : WireSplitterFunctor
261 //=======================================================================
262 class BOPAlgo_WireSplitterFunctor
266 BOPTools_VectorOfConnexityBlock* myPVCB;
270 BOPAlgo_WireSplitterFunctor(const TopoDS_Face& aF,
271 BOPTools_VectorOfConnexityBlock& aVCB)
272 : myFace(aF), myPVCB(&aVCB)
276 void operator()( const Standard_Integer& theIndex ) const
278 BOPTools_VectorOfConnexityBlock& aVCB = *myPVCB;
279 BOPTools_ConnexityBlock& aCB = aVCB(theIndex);
280 BOPAlgo_WireSplitter::SplitBlock(myFace, aCB);
283 //=======================================================================
284 //class : BOPAlgo_WireSplitterCnt
286 //=======================================================================
287 class BOPAlgo_WireSplitterCnt
290 //-------------------------------
293 static void Perform(const Standard_Boolean bRunParallel,
294 const TopoDS_Face& aF,
295 BOPTools_VectorOfConnexityBlock& aVCB)
298 BOPAlgo_WireSplitterFunctor aWSF(aF, aVCB);
299 Standard_Integer aNbVCB = aVCB.Extent();
301 OSD_Parallel::For(0, aNbVCB, aWSF, !bRunParallel);
304 //=======================================================================
305 //function : MakeWires
307 //=======================================================================
308 void BOPAlgo_WireSplitter::MakeWires()
310 Standard_Boolean bIsRegular;
311 Standard_Integer aNbVCB, k;
313 BOPTools_ListIteratorOfListOfConnexityBlock aItCB;
314 BOPCol_ListIteratorOfListOfShape aIt;
315 BOPTools_VectorOfConnexityBlock aVCB;
317 aItCB.Initialize(myLCB);
318 for (; aItCB.More(); aItCB.Next()) {
319 BOPTools_ConnexityBlock& aCB=aItCB.ChangeValue();
320 bIsRegular=aCB.IsRegular();
322 BOPCol_ListOfShape& aLE=aCB.ChangeShapes();
323 BOPAlgo_WireSplitter::MakeWire(aLE, aW);
331 aNbVCB=aVCB.Extent();
332 const TopoDS_Face& aF=myWES->Face();
333 //===================================================
334 BOPAlgo_WireSplitterCnt::Perform(myRunParallel, aF, aVCB);
335 //===================================================
336 for (k=0; k<aNbVCB; ++k) {
337 const BOPTools_ConnexityBlock& aCB=aVCB(k);
338 const BOPCol_ListOfShape& aLW=aCB.Loops();
340 for (; aIt.More(); aIt.Next()) {
341 const TopoDS_Shape& aWx=aIt.Value();
342 myWES->AddShape(aWx);