4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
4e57c75e |
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 | // |
973c2be1 |
7 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
8 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
4e57c75e |
14 | // |
973c2be1 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
4e57c75e |
17 | |
18 | #include <BOPAlgo_PaveFiller.ixx> |
a0a3f6ac |
19 | // |
4e57c75e |
20 | #include <NCollection_IncAllocator.hxx> |
a0a3f6ac |
21 | // |
4e57c75e |
22 | #include <TopoDS_Vertex.hxx> |
23 | #include <TopoDS_Face.hxx> |
24 | #include <BRep_Tool.hxx> |
25 | #include <BRep_Builder.hxx> |
26 | #include <BRepBndLib.hxx> |
a0a3f6ac |
27 | // |
4e57c75e |
28 | #include <BOPCol_MapOfInteger.hxx> |
a0a3f6ac |
29 | #include <BOPCol_NCVector.hxx> |
30 | #include <BOPCol_TBB.hxx> |
31 | // |
4e57c75e |
32 | #include <BOPInt_Context.hxx> |
a0a3f6ac |
33 | // |
4e57c75e |
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> |
4e57c75e |
40 | |
a0a3f6ac |
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(BOPInt_Context)& aContext) { |
98 | myContext=aContext; |
99 | } |
100 | // |
101 | const Handle(BOPInt_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(BOPInt_Context) myContext; |
119 | }; |
120 | //======================================================================= |
121 | typedef BOPCol_NCVector<BOPAlgo_VertexFace> |
122 | BOPAlgo_VectorOfVertexFace; |
123 | // |
124 | typedef BOPCol_TBBContextFunctor |
125 | <BOPAlgo_VertexFace, |
126 | BOPAlgo_VectorOfVertexFace, |
857ffd5e |
127 | Handle(BOPInt_Context), |
a0a3f6ac |
128 | BOPInt_Context> BOPAlgo_VertexFaceFunctor; |
129 | // |
130 | typedef BOPCol_TBBContextCnt |
131 | <BOPAlgo_VertexFaceFunctor, |
132 | BOPAlgo_VectorOfVertexFace, |
857ffd5e |
133 | Handle(BOPInt_Context)> BOPAlgo_VertexFaceCnt; |
a0a3f6ac |
134 | // |
4e57c75e |
135 | //======================================================================= |
136 | // function: PerformVF |
137 | // purpose: |
138 | //======================================================================= |
a0a3f6ac |
139 | void BOPAlgo_PaveFiller::PerformVF() |
4e57c75e |
140 | { |
141 | Standard_Boolean bJustAdd; |
a0a3f6ac |
142 | Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, i, aNbVF, k; |
4e57c75e |
143 | Standard_Real aT1, aT2, aTolF, aTolV; |
144 | BRep_Builder aBB; |
a0a3f6ac |
145 | BOPAlgo_VectorOfVertexFace aVVF; |
4e57c75e |
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)) { |
c1746a0a |
169 | myDS->ChangeFaceInfo(nF); |
4e57c75e |
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 | // |
a0a3f6ac |
182 | myDS->ChangeFaceInfo(nF);// ! |
183 | // |
4e57c75e |
184 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); |
185 | const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); |
186 | // |
a0a3f6ac |
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 |
4e57c75e |
223 | aTolV = BRep_Tool::Tolerance(aV); |
224 | aTolF = BRep_Tool::Tolerance(aF); |
a0a3f6ac |
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); |
4e57c75e |
230 | } |
a0a3f6ac |
231 | }//for (k=0; k < aNbVF; ++k) { |
4e57c75e |
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 | } |
c1746a0a |
240 | // |
4e57c75e |
241 | TreatVerticesEE(); |
a0a3f6ac |
242 | } |
4e57c75e |
243 | //======================================================================= |
244 | //function : TreatVerticesEE |
245 | //purpose : |
246 | //======================================================================= |
a0a3f6ac |
247 | void BOPAlgo_PaveFiller::TreatVerticesEE() |
4e57c75e |
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 | // |
4e57c75e |
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(); |
4e57c75e |
327 | } |