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 | |
42cf5bc1 |
18 | |
19 | #include <BOPAlgo_PaveFiller.hxx> |
20 | #include <BOPAlgo_SectionAttribute.hxx> |
4e57c75e |
21 | #include <BOPCol_MapOfInteger.hxx> |
a0a3f6ac |
22 | #include <BOPCol_NCVector.hxx> |
c7b59798 |
23 | #include <BOPCol_Parallel.hxx> |
42cf5bc1 |
24 | #include <BOPDS_Curve.hxx> |
25 | #include <BOPDS_DS.hxx> |
26 | #include <BOPDS_FaceInfo.hxx> |
4e57c75e |
27 | #include <BOPDS_Interf.hxx> |
42cf5bc1 |
28 | #include <BOPDS_Iterator.hxx> |
4e57c75e |
29 | #include <BOPDS_MapOfPaveBlock.hxx> |
42cf5bc1 |
30 | #include <BOPDS_PaveBlock.hxx> |
31 | #include <BOPDS_SubIterator.hxx> |
32 | #include <BOPDS_VectorOfInterfVF.hxx> |
33 | #include <BRep_Builder.hxx> |
34 | #include <BRep_Tool.hxx> |
35 | #include <BRepBndLib.hxx> |
36 | #include <gp_Pnt.hxx> |
37 | #include <IntTools_Context.hxx> |
38 | #include <NCollection_IncAllocator.hxx> |
39 | #include <TopoDS_Face.hxx> |
40 | #include <TopoDS_Vertex.hxx> |
4e57c75e |
41 | |
42cf5bc1 |
42 | // |
43 | // |
44 | // |
45 | // |
46 | // |
a0a3f6ac |
47 | //======================================================================= |
48 | //class : BOPAlgo_VertexFace |
49 | //purpose : |
50 | //======================================================================= |
36f4947b |
51 | class BOPAlgo_VertexFace : public BOPAlgo_Algo { |
a0a3f6ac |
52 | public: |
36f4947b |
53 | DEFINE_STANDARD_ALLOC |
54 | |
55 | BOPAlgo_VertexFace() : |
56 | BOPAlgo_Algo(), |
57 | myIV(-1), myIF(-1), myIVx(-1), |
a0a3f6ac |
58 | myFlag(-1), myT1(-1.), myT2(-1.) { |
59 | } |
60 | // |
36f4947b |
61 | virtual ~BOPAlgo_VertexFace(){ |
a0a3f6ac |
62 | } |
63 | // |
64 | void SetIndices(const Standard_Integer nV, |
65 | const Standard_Integer nF, |
66 | const Standard_Integer nVx) { |
67 | myIV=nV; |
68 | myIF=nF; |
69 | myIVx=nVx; |
70 | } |
71 | // |
72 | void Indices(Standard_Integer& nV, |
73 | Standard_Integer& nF, |
74 | Standard_Integer& nVx) const { |
75 | nV=myIV; |
76 | nF=myIF; |
77 | nVx=myIVx; |
78 | } |
79 | // |
80 | void SetVertex(const TopoDS_Vertex& aV) { |
81 | myV=aV; |
82 | } |
83 | // |
84 | const TopoDS_Vertex& Vertex()const { |
85 | return myV; |
86 | } |
87 | // |
88 | void SetFace(const TopoDS_Face& aF) { |
89 | myF=aF; |
90 | } |
91 | // |
92 | const TopoDS_Face& Face()const { |
93 | return myF; |
94 | } |
95 | // |
96 | Standard_Integer Flag()const { |
97 | return myFlag; |
98 | } |
99 | // |
100 | void Parameters(Standard_Real& aT1, |
101 | Standard_Real& aT2)const { |
102 | aT1=myT1; |
103 | aT2=myT2; |
104 | } |
105 | // |
1e143abb |
106 | void SetContext(const Handle(IntTools_Context)& aContext) { |
a0a3f6ac |
107 | myContext=aContext; |
108 | } |
109 | // |
1e143abb |
110 | const Handle(IntTools_Context)& Context()const { |
a0a3f6ac |
111 | return myContext; |
112 | } |
113 | // |
36f4947b |
114 | virtual void Perform() { |
115 | BOPAlgo_Algo::UserBreak(); |
a0a3f6ac |
116 | myFlag=myContext->ComputeVF(myV, myF, myT1, myT2); |
117 | } |
118 | // |
119 | protected: |
120 | Standard_Integer myIV; |
121 | Standard_Integer myIF; |
122 | Standard_Integer myIVx; |
123 | Standard_Integer myFlag; |
124 | Standard_Real myT1; |
125 | Standard_Real myT2; |
126 | TopoDS_Vertex myV; |
127 | TopoDS_Face myF; |
1e143abb |
128 | Handle(IntTools_Context) myContext; |
a0a3f6ac |
129 | }; |
130 | //======================================================================= |
131 | typedef BOPCol_NCVector<BOPAlgo_VertexFace> |
132 | BOPAlgo_VectorOfVertexFace; |
133 | // |
c7b59798 |
134 | typedef BOPCol_ContextFunctor |
a0a3f6ac |
135 | <BOPAlgo_VertexFace, |
136 | BOPAlgo_VectorOfVertexFace, |
1e143abb |
137 | Handle(IntTools_Context), |
138 | IntTools_Context> BOPAlgo_VertexFaceFunctor; |
a0a3f6ac |
139 | // |
c7b59798 |
140 | typedef BOPCol_ContextCnt |
a0a3f6ac |
141 | <BOPAlgo_VertexFaceFunctor, |
142 | BOPAlgo_VectorOfVertexFace, |
1e143abb |
143 | Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt; |
a0a3f6ac |
144 | // |
4e57c75e |
145 | //======================================================================= |
146 | // function: PerformVF |
147 | // purpose: |
148 | //======================================================================= |
a0a3f6ac |
149 | void BOPAlgo_PaveFiller::PerformVF() |
4e57c75e |
150 | { |
151 | Standard_Boolean bJustAdd; |
402bfe81 |
152 | Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, aNbVF, k; |
4e57c75e |
153 | Standard_Real aT1, aT2, aTolF, aTolV; |
154 | BRep_Builder aBB; |
a0a3f6ac |
155 | BOPAlgo_VectorOfVertexFace aVVF; |
4e57c75e |
156 | // |
157 | myErrorStatus=0; |
158 | // |
159 | myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE); |
160 | iSize=myIterator->ExpectedLength(); |
161 | if (iSize) { |
162 | // |
163 | BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF(); |
4e57c75e |
164 | aVFs.SetIncrement(iSize); |
4e57c75e |
165 | // |
166 | for (; myIterator->More(); myIterator->Next()) { |
167 | myIterator->Value(nV, nF, bJustAdd); |
168 | if(bJustAdd) { |
169 | continue; |
170 | } |
171 | // |
172 | if (myDS->IsSubShape(nV, nF)) { |
173 | continue; |
174 | } |
175 | // |
176 | if (myDS->HasInterfShapeSubShapes(nV, nF)) { |
c1746a0a |
177 | myDS->ChangeFaceInfo(nF); |
4e57c75e |
178 | continue; |
179 | } |
180 | // |
181 | nVx=nV; |
182 | if (myDS->HasShapeSD(nV, nVSD)) { |
183 | nVx=nVSD; |
184 | } |
185 | // |
186 | if (myDS->HasInterf(nVx, nF)) { |
187 | continue; |
188 | } |
189 | // |
a0a3f6ac |
190 | myDS->ChangeFaceInfo(nF);// ! |
191 | // |
4e57c75e |
192 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); |
193 | const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); |
194 | // |
a0a3f6ac |
195 | BOPAlgo_VertexFace& aVertexFace=aVVF.Append1(); |
196 | // |
197 | aVertexFace.SetIndices(nV, nF, nVx); |
198 | aVertexFace.SetVertex(aV); |
199 | aVertexFace.SetFace(aF); |
36f4947b |
200 | aVertexFace.SetProgressIndicator(myProgressIndicator); |
a0a3f6ac |
201 | }//for (; myIterator->More(); myIterator->Next()) { |
202 | // |
203 | aNbVF=aVVF.Extent(); |
204 | //================================================================ |
205 | BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext); |
206 | //================================================================ |
207 | // |
208 | for (k=0; k < aNbVF; ++k) { |
209 | const BOPAlgo_VertexFace& aVertexFace=aVVF(k); |
210 | // |
211 | iFlag=aVertexFace.Flag(); |
212 | if (iFlag) { |
213 | continue; |
214 | } |
215 | // |
216 | aVertexFace.Indices(nV, nF, nVx); |
217 | aVertexFace.Parameters(aT1, aT2); |
218 | const TopoDS_Vertex& aV=aVertexFace.Vertex(); |
219 | const TopoDS_Face& aF=aVertexFace.Face(); |
220 | // 1 |
402bfe81 |
221 | BOPDS_InterfVF& aVF=aVFs.Append1(); |
a0a3f6ac |
222 | aVF.SetIndices(nVx, nF); |
223 | aVF.SetUV(aT1, aT2); |
224 | // 2 |
225 | myDS->AddInterf(nVx, nF); |
226 | // 3 |
227 | BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF); |
228 | BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn(); |
229 | aMVIn.Add(nVx); |
230 | // 4 |
4e57c75e |
231 | aTolV = BRep_Tool::Tolerance(aV); |
232 | aTolF = BRep_Tool::Tolerance(aF); |
a0a3f6ac |
233 | if (aTolV < aTolF) { |
234 | aBB.UpdateVertex(aV, aTolF); |
235 | BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVx); |
236 | Bnd_Box& aBoxV = aSIV.ChangeBox(); |
237 | BRepBndLib::Add(aV, aBoxV); |
4e57c75e |
238 | } |
a0a3f6ac |
239 | }//for (k=0; k < aNbVF; ++k) { |
4e57c75e |
240 | }// if (iSize) { |
241 | else { |
242 | iSize=10; |
243 | BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF(); |
4e57c75e |
244 | aVFs.SetIncrement(iSize); |
4e57c75e |
245 | } |
c1746a0a |
246 | // |
4e57c75e |
247 | TreatVerticesEE(); |
a0a3f6ac |
248 | } |
4e57c75e |
249 | //======================================================================= |
250 | //function : TreatVerticesEE |
251 | //purpose : |
252 | //======================================================================= |
a0a3f6ac |
253 | void BOPAlgo_PaveFiller::TreatVerticesEE() |
4e57c75e |
254 | { |
402bfe81 |
255 | Standard_Integer i, aNbS,aNbEEs, nF, nV, iFlag; |
4e57c75e |
256 | Standard_Real aT1, aT2; |
257 | BOPCol_ListIteratorOfListOfInteger aItLI; |
258 | Handle(NCollection_IncAllocator) aAllocator; |
259 | // |
4e57c75e |
260 | aAllocator=new NCollection_IncAllocator(); |
261 | BOPCol_ListOfInteger aLIV(aAllocator), aLIF(aAllocator); |
262 | BOPCol_MapOfInteger aMI(100, aAllocator); |
263 | BOPDS_MapOfPaveBlock aMPBF(100, aAllocator); |
264 | // |
265 | myErrorStatus=0; |
266 | // |
267 | |
268 | aNbS=myDS->NbSourceShapes(); |
269 | // |
270 | BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE(); |
271 | aNbEEs=aEEs.Extent(); |
272 | for (i=0; i<aNbEEs; ++i) { |
273 | BOPDS_InterfEE& aEE=aEEs(i); |
274 | if (aEE.HasIndexNew()) { |
275 | nV=aEE.IndexNew(); |
276 | if (aMI.Add(nV)) { |
277 | aLIV.Append(nV); |
278 | } |
279 | } |
280 | } |
281 | if (!aLIV.Extent()) { |
282 | aAllocator.Nullify(); |
283 | return; |
284 | } |
285 | // |
286 | aNbS=myDS->NbSourceShapes(); |
287 | for (nF=0; nF<aNbS; ++nF) { |
288 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(nF); |
289 | if (aSI.ShapeType()==TopAbs_FACE) { |
290 | aLIF.Append(nF); |
291 | } |
292 | } |
293 | if (!aLIF.Extent()) { |
294 | aAllocator.Nullify(); |
295 | return; |
296 | } |
297 | //------------------------------------------------------------- |
298 | BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF(); |
299 | // |
300 | BOPDS_SubIterator aIt(aAllocator); |
301 | // |
302 | aIt.SetDS(myDS); |
303 | aIt.SetSubSet1(aLIF); |
304 | aIt.SetSubSet2(aLIV); |
305 | aIt.Prepare(); |
306 | aIt.Initialize(); |
307 | for (; aIt.More(); aIt.Next()) { |
308 | aIt.Value(nV, nF); |
309 | // |
310 | BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF); |
311 | const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn(); |
312 | // |
313 | if (!aMVOn.Contains(nV)) { |
314 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV))); |
315 | const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); |
316 | iFlag=myContext->ComputeVF(aV, aF, aT1, aT2); |
317 | if (!iFlag) { |
318 | // 1 |
402bfe81 |
319 | BOPDS_InterfVF& aVF=aVFs.Append1(); |
320 | i=aVFs.Extent()-1; |
4e57c75e |
321 | aVF.SetIndices(nV, nF); |
322 | aVF.SetUV(aT1, aT2); |
323 | // 2 |
324 | myDS->AddInterf(nV, nF); |
325 | // |
326 | BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn(); |
327 | aMVIn.Add(nV); |
328 | } |
329 | } |
330 | } |
331 | // |
332 | aAllocator.Nullify(); |
4e57c75e |
333 | } |