0024940: WOK: Cyclic dependency detected between: BOPInt IntTools
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_4.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18 #include <BOPAlgo_PaveFiller.ixx>
19 //
20 #include <NCollection_IncAllocator.hxx>
21 //
22 #include <TopoDS_Vertex.hxx>
23 #include <TopoDS_Face.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRepBndLib.hxx>
27 //
28 #include <BOPCol_MapOfInteger.hxx>
29 #include <BOPCol_NCVector.hxx>
30 #include <BOPCol_TBB.hxx>
31 //
32 #include <IntTools_Context.hxx>
33 //
34 #include <BOPDS_Iterator.hxx>
35 #include <BOPDS_VectorOfInterfVF.hxx>
36 #include <BOPDS_Interf.hxx>
37 #include <BOPDS_SubIterator.hxx>
38 #include <BOPDS_MapOfPaveBlock.hxx>
39 #include <BOPDS_FaceInfo.hxx>
40
41 //=======================================================================
42 //class    : BOPAlgo_VertexFace
43 //purpose  : 
44 //=======================================================================
45 class BOPAlgo_VertexFace {
46  public:
47   BOPAlgo_VertexFace()
48     : myIV(-1), myIF(-1), myIVx(-1), 
49     myFlag(-1), myT1(-1.),  myT2(-1.) {
50   }
51   //
52   ~BOPAlgo_VertexFace(){
53   }
54   //
55   void SetIndices(const Standard_Integer nV,
56                   const Standard_Integer nF,
57                   const Standard_Integer nVx) {
58     myIV=nV;
59     myIF=nF;
60     myIVx=nVx;
61   }
62   //
63   void Indices(Standard_Integer& nV,
64                Standard_Integer& nF,
65                Standard_Integer& nVx) const {
66     nV=myIV;
67     nF=myIF;
68     nVx=myIVx;
69   }
70   //
71   void SetVertex(const TopoDS_Vertex& aV) {
72     myV=aV;
73   }
74   //
75   const TopoDS_Vertex& Vertex()const {
76     return myV;
77   }
78   //
79   void SetFace(const TopoDS_Face& aF) {
80     myF=aF;
81   }
82   //
83   const TopoDS_Face& Face()const {
84     return myF;
85   }
86   //
87   Standard_Integer Flag()const {
88     return myFlag;
89   }
90   //
91   void Parameters(Standard_Real& aT1,
92                   Standard_Real& aT2)const {
93     aT1=myT1;
94     aT2=myT2;
95   }
96   //
97   void SetContext(const Handle(IntTools_Context)& aContext) {
98     myContext=aContext;
99   }
100   //
101   const Handle(IntTools_Context)& Context()const {
102     return myContext;
103   }
104   //
105   void Perform() {
106     myFlag=myContext->ComputeVF(myV, myF, myT1, myT2);
107   }
108   //
109  protected:
110   Standard_Integer myIV;
111   Standard_Integer myIF;
112   Standard_Integer myIVx;
113   Standard_Integer myFlag;
114   Standard_Real myT1;
115   Standard_Real myT2;
116   TopoDS_Vertex myV;
117   TopoDS_Face myF;
118   Handle(IntTools_Context) myContext;
119 };
120 //=======================================================================
121 typedef BOPCol_NCVector<BOPAlgo_VertexFace>
122   BOPAlgo_VectorOfVertexFace; 
123 //
124 typedef BOPCol_TBBContextFunctor 
125   <BOPAlgo_VertexFace,
126   BOPAlgo_VectorOfVertexFace,
127   Handle(IntTools_Context), 
128   IntTools_Context> BOPAlgo_VertexFaceFunctor;
129 //
130 typedef BOPCol_TBBContextCnt 
131   <BOPAlgo_VertexFaceFunctor,
132   BOPAlgo_VectorOfVertexFace,
133   Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;
134 //
135 //=======================================================================
136 // function: PerformVF
137 // purpose: 
138 //=======================================================================
139 void BOPAlgo_PaveFiller::PerformVF()
140 {
141   Standard_Boolean bJustAdd;
142   Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, i, aNbVF, k;
143   Standard_Real aT1, aT2, aTolF, aTolV;
144   BRep_Builder aBB;
145   BOPAlgo_VectorOfVertexFace aVVF; 
146   //
147   myErrorStatus=0;
148   //
149   myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
150   iSize=myIterator->ExpectedLength();
151   if (iSize) {
152     //
153     BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
154     aVFs.SetStartSize(iSize);
155     aVFs.SetIncrement(iSize);
156     aVFs.Init();
157     //
158     for (; myIterator->More(); myIterator->Next()) {
159       myIterator->Value(nV, nF, bJustAdd);
160       if(bJustAdd) {
161         continue;
162       }
163       //
164       if (myDS->IsSubShape(nV, nF)) {
165         continue;
166       }
167       //
168       if (myDS->HasInterfShapeSubShapes(nV, nF)) {
169         myDS->ChangeFaceInfo(nF);
170         continue;
171       }
172       //
173       nVx=nV;
174       if (myDS->HasShapeSD(nV, nVSD)) {
175         nVx=nVSD;
176       }
177       //
178       if (myDS->HasInterf(nVx, nF)) {
179         continue;
180       }
181       //
182       myDS->ChangeFaceInfo(nF);// !
183       //
184       const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
185       const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
186       //
187       BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
188       //
189       aVertexFace.SetIndices(nV, nF, nVx);
190       aVertexFace.SetVertex(aV);
191       aVertexFace.SetFace(aF);
192     }//for (; myIterator->More(); myIterator->Next()) {
193     //
194     aNbVF=aVVF.Extent();
195     //================================================================
196     BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
197     //================================================================
198     //
199     for (k=0; k < aNbVF; ++k) {
200       const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
201       // 
202       iFlag=aVertexFace.Flag();
203       if (iFlag) {
204         continue;
205       }
206       //
207       aVertexFace.Indices(nV, nF, nVx);
208       aVertexFace.Parameters(aT1, aT2);
209       const TopoDS_Vertex& aV=aVertexFace.Vertex();
210       const TopoDS_Face& aF=aVertexFace.Face();
211       // 1
212       i=aVFs.Append()-1;
213       BOPDS_InterfVF& aVF=aVFs(i);
214       aVF.SetIndices(nVx, nF);
215       aVF.SetUV(aT1, aT2);
216       // 2
217       myDS->AddInterf(nVx, nF);
218       // 3
219       BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
220       BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
221       aMVIn.Add(nVx);
222       // 4
223       aTolV = BRep_Tool::Tolerance(aV);
224       aTolF = BRep_Tool::Tolerance(aF);
225       if (aTolV < aTolF) {
226         aBB.UpdateVertex(aV, aTolF);
227         BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVx);
228         Bnd_Box& aBoxV = aSIV.ChangeBox();
229         BRepBndLib::Add(aV, aBoxV);
230       }
231     }//for (k=0; k < aNbVF; ++k) {
232   }// if (iSize) {
233   else {
234     iSize=10;
235     BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
236     aVFs.SetStartSize(iSize);
237     aVFs.SetIncrement(iSize);
238     aVFs.Init();
239   }
240   //
241   TreatVerticesEE();
242 }
243 //=======================================================================
244 //function : TreatVerticesEE
245 //purpose  : 
246 //=======================================================================
247 void BOPAlgo_PaveFiller::TreatVerticesEE()
248 {
249   Standard_Integer i, aNbS, aNbEEs, nF, nV, iFlag;
250   Standard_Real aT1, aT2;
251   BOPCol_ListIteratorOfListOfInteger aItLI;
252   Handle(NCollection_IncAllocator) aAllocator;
253   //
254   aAllocator=new NCollection_IncAllocator();
255   BOPCol_ListOfInteger aLIV(aAllocator), aLIF(aAllocator);
256   BOPCol_MapOfInteger aMI(100, aAllocator);
257   BOPDS_MapOfPaveBlock aMPBF(100, aAllocator);
258   //
259   myErrorStatus=0;
260   //
261   
262   aNbS=myDS->NbSourceShapes();
263   //
264   BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
265   aNbEEs=aEEs.Extent();
266   for (i=0; i<aNbEEs; ++i) {
267     BOPDS_InterfEE& aEE=aEEs(i);
268     if (aEE.HasIndexNew()) {
269       nV=aEE.IndexNew();
270       if (aMI.Add(nV)) {
271         aLIV.Append(nV);
272       }   
273     }   
274   }
275   if (!aLIV.Extent()) {
276     aAllocator.Nullify();
277     return;
278   }
279   //
280   aNbS=myDS->NbSourceShapes();
281   for (nF=0; nF<aNbS; ++nF) {
282     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(nF);
283     if (aSI.ShapeType()==TopAbs_FACE) {
284       aLIF.Append(nF);
285     }
286   }
287   if (!aLIF.Extent()) {
288     aAllocator.Nullify();
289     return;
290   }
291   //-------------------------------------------------------------
292   BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
293   //
294   BOPDS_SubIterator aIt(aAllocator);
295   //
296   aIt.SetDS(myDS);
297   aIt.SetSubSet1(aLIF);
298   aIt.SetSubSet2(aLIV);
299   aIt.Prepare();
300   aIt.Initialize();
301   for (; aIt.More(); aIt.Next()) {
302     aIt.Value(nV, nF);
303     //
304     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
305     const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn();
306     //
307     if (!aMVOn.Contains(nV)) {
308       const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV))); 
309       const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
310       iFlag=myContext->ComputeVF(aV, aF, aT1, aT2);
311       if (!iFlag) {
312         // 1
313         i=aVFs.Append()-1;
314         BOPDS_InterfVF& aVF=aVFs(i);
315         aVF.SetIndices(nV, nF);
316         aVF.SetUV(aT1, aT2);
317         // 2
318         myDS->AddInterf(nV, nF);
319         //
320         BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
321         aMVIn.Add(nV);
322       }
323     }
324   }
325   //
326   aAllocator.Nullify();
327 }