0025769: Replace BOPCol_Array1 with NCollection_Vector
[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 : public BOPAlgo_Algo {
46  public:
47   DEFINE_STANDARD_ALLOC
48
49   BOPAlgo_VertexFace() : 
50     BOPAlgo_Algo(),
51     myIV(-1), myIF(-1), myIVx(-1), 
52     myFlag(-1), myT1(-1.),  myT2(-1.) {
53   }
54   //
55   virtual ~BOPAlgo_VertexFace(){
56   }
57   //
58   void SetIndices(const Standard_Integer nV,
59                   const Standard_Integer nF,
60                   const Standard_Integer nVx) {
61     myIV=nV;
62     myIF=nF;
63     myIVx=nVx;
64   }
65   //
66   void Indices(Standard_Integer& nV,
67                Standard_Integer& nF,
68                Standard_Integer& nVx) const {
69     nV=myIV;
70     nF=myIF;
71     nVx=myIVx;
72   }
73   //
74   void SetVertex(const TopoDS_Vertex& aV) {
75     myV=aV;
76   }
77   //
78   const TopoDS_Vertex& Vertex()const {
79     return myV;
80   }
81   //
82   void SetFace(const TopoDS_Face& aF) {
83     myF=aF;
84   }
85   //
86   const TopoDS_Face& Face()const {
87     return myF;
88   }
89   //
90   Standard_Integer Flag()const {
91     return myFlag;
92   }
93   //
94   void Parameters(Standard_Real& aT1,
95                   Standard_Real& aT2)const {
96     aT1=myT1;
97     aT2=myT2;
98   }
99   //
100   void SetContext(const Handle(IntTools_Context)& aContext) {
101     myContext=aContext;
102   }
103   //
104   const Handle(IntTools_Context)& Context()const {
105     return myContext;
106   }
107   //
108   virtual void Perform() {
109     BOPAlgo_Algo::UserBreak();
110     myFlag=myContext->ComputeVF(myV, myF, myT1, myT2);
111   }
112   //
113  protected:
114   Standard_Integer myIV;
115   Standard_Integer myIF;
116   Standard_Integer myIVx;
117   Standard_Integer myFlag;
118   Standard_Real myT1;
119   Standard_Real myT2;
120   TopoDS_Vertex myV;
121   TopoDS_Face myF;
122   Handle(IntTools_Context) myContext;
123 };
124 //=======================================================================
125 typedef BOPCol_NCVector<BOPAlgo_VertexFace>
126   BOPAlgo_VectorOfVertexFace; 
127 //
128 typedef BOPCol_TBBContextFunctor 
129   <BOPAlgo_VertexFace,
130   BOPAlgo_VectorOfVertexFace,
131   Handle(IntTools_Context), 
132   IntTools_Context> BOPAlgo_VertexFaceFunctor;
133 //
134 typedef BOPCol_TBBContextCnt 
135   <BOPAlgo_VertexFaceFunctor,
136   BOPAlgo_VectorOfVertexFace,
137   Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;
138 //
139 //=======================================================================
140 // function: PerformVF
141 // purpose: 
142 //=======================================================================
143 void BOPAlgo_PaveFiller::PerformVF()
144 {
145   Standard_Boolean bJustAdd;
146   Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, aNbVF, k;
147   Standard_Real aT1, aT2, aTolF, aTolV;
148   BRep_Builder aBB;
149   BOPAlgo_VectorOfVertexFace aVVF; 
150   //
151   myErrorStatus=0;
152   //
153   myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
154   iSize=myIterator->ExpectedLength();
155   if (iSize) {
156     //
157     BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
158     aVFs.SetIncrement(iSize);
159     //
160     for (; myIterator->More(); myIterator->Next()) {
161       myIterator->Value(nV, nF, bJustAdd);
162       if(bJustAdd) {
163         continue;
164       }
165       //
166       if (myDS->IsSubShape(nV, nF)) {
167         continue;
168       }
169       //
170       if (myDS->HasInterfShapeSubShapes(nV, nF)) {
171         myDS->ChangeFaceInfo(nF);
172         continue;
173       }
174       //
175       nVx=nV;
176       if (myDS->HasShapeSD(nV, nVSD)) {
177         nVx=nVSD;
178       }
179       //
180       if (myDS->HasInterf(nVx, nF)) {
181         continue;
182       }
183       //
184       myDS->ChangeFaceInfo(nF);// !
185       //
186       const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
187       const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
188       //
189       BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
190       //
191       aVertexFace.SetIndices(nV, nF, nVx);
192       aVertexFace.SetVertex(aV);
193       aVertexFace.SetFace(aF);
194       aVertexFace.SetProgressIndicator(myProgressIndicator);
195     }//for (; myIterator->More(); myIterator->Next()) {
196     //
197     aNbVF=aVVF.Extent();
198     //================================================================
199     BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
200     //================================================================
201     //
202     for (k=0; k < aNbVF; ++k) {
203       const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
204       // 
205       iFlag=aVertexFace.Flag();
206       if (iFlag) {
207         continue;
208       }
209       //
210       aVertexFace.Indices(nV, nF, nVx);
211       aVertexFace.Parameters(aT1, aT2);
212       const TopoDS_Vertex& aV=aVertexFace.Vertex();
213       const TopoDS_Face& aF=aVertexFace.Face();
214       // 1
215       BOPDS_InterfVF& aVF=aVFs.Append1();
216       aVF.SetIndices(nVx, nF);
217       aVF.SetUV(aT1, aT2);
218       // 2
219       myDS->AddInterf(nVx, nF);
220       // 3
221       BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
222       BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
223       aMVIn.Add(nVx);
224       // 4
225       aTolV = BRep_Tool::Tolerance(aV);
226       aTolF = BRep_Tool::Tolerance(aF);
227       if (aTolV < aTolF) {
228         aBB.UpdateVertex(aV, aTolF);
229         BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVx);
230         Bnd_Box& aBoxV = aSIV.ChangeBox();
231         BRepBndLib::Add(aV, aBoxV);
232       }
233     }//for (k=0; k < aNbVF; ++k) {
234   }// if (iSize) {
235   else {
236     iSize=10;
237     BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
238     aVFs.SetIncrement(iSize);
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         BOPDS_InterfVF& aVF=aVFs.Append1();
314         i=aVFs.Extent()-1;
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 }