25dfc507 |
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_CheckerSI.hxx> |
19 | |
20 | #include <BOPDS_DS.hxx> |
21 | #include <BOPDS_Interf.hxx> |
22 | #include <BOPDS_IteratorSI.hxx> |
23 | |
1155d05a |
24 | #include <BOPTools_Parallel.hxx> |
25dfc507 |
25 | |
26 | #include <BRep_Tool.hxx> |
27 | #include <BRepClass3d_SolidClassifier.hxx> |
28 | |
29 | #include <IntTools_Context.hxx> |
30 | |
31 | #include <gp_Pnt.hxx> |
1155d05a |
32 | |
33 | #include <NCollection_Vector.hxx> |
25dfc507 |
34 | #include <TopAbs_State.hxx> |
1155d05a |
35 | #include <TopoDS_Vertex.hxx> |
25dfc507 |
36 | #include <TopoDS_Solid.hxx> |
37 | |
38 | ///////////////////////////////////////////////////////////////////////// |
39 | //======================================================================= |
40 | //class : BOPAlgo_VertexSolid |
41 | //purpose : |
42 | //======================================================================= |
d03c0898 |
43 | class BOPAlgo_VertexSolid { |
25dfc507 |
44 | public: |
45 | DEFINE_STANDARD_ALLOC |
46 | |
d03c0898 |
47 | BOPAlgo_VertexSolid() : |
48 | myIV(-1), myIZ(-1), myState(TopAbs_UNKNOWN) { |
25dfc507 |
49 | }; |
50 | // |
51 | virtual ~BOPAlgo_VertexSolid(){ |
52 | }; |
53 | // |
54 | void SetIndices(const Standard_Integer nV, |
55 | const Standard_Integer nZ){ |
56 | myIV=nV; |
57 | myIZ=nZ; |
58 | } |
59 | // |
60 | void Indices(Standard_Integer& nV, |
61 | Standard_Integer& nZ) const { |
62 | nV=myIV; |
63 | nZ=myIZ; |
64 | } |
65 | // |
66 | void SetVertex(const TopoDS_Vertex& aV) { |
67 | myV=aV; |
68 | } |
69 | // |
70 | const TopoDS_Vertex& Vertex()const { |
71 | return myV; |
72 | } |
73 | // |
74 | void SetSolid(const TopoDS_Solid& aZ) { |
75 | myZ=aZ; |
76 | } |
77 | // |
78 | const TopoDS_Solid& Solid()const { |
79 | return myZ; |
80 | } |
81 | // |
82 | void SetContext(const Handle(IntTools_Context)& aContext) { |
83 | myContext=aContext; |
84 | } |
85 | // |
86 | const Handle(IntTools_Context)& Context()const { |
87 | return myContext; |
88 | } |
89 | // |
90 | TopAbs_State State() const{ |
91 | return myState; |
92 | }; |
93 | // |
d03c0898 |
94 | void SetProgressRange(const Message_ProgressRange& theRange) |
95 | { |
96 | myProgressRange = theRange; |
97 | } |
98 | // |
99 | virtual void Perform() { |
100 | Message_ProgressScope aPS(myProgressRange, NULL, 1); |
101 | if (!aPS.More()) |
102 | { |
103 | return; |
104 | } |
105 | |
25dfc507 |
106 | Standard_Real aTol; |
107 | gp_Pnt aPV; |
108 | // |
109 | BRepClass3d_SolidClassifier& aSC=myContext->SolidClassifier(myZ); |
110 | // |
111 | aPV=BRep_Tool::Pnt(myV); |
112 | aTol=BRep_Tool::Tolerance(myV); |
113 | // |
114 | aSC.Perform(aPV, aTol); |
115 | // |
116 | myState=aSC.State(); |
117 | }; |
118 | // |
119 | protected: |
120 | Standard_Integer myIV; |
121 | Standard_Integer myIZ; |
122 | TopAbs_State myState; |
123 | TopoDS_Vertex myV; |
124 | TopoDS_Solid myZ; |
125 | Handle(IntTools_Context) myContext; |
d03c0898 |
126 | Message_ProgressRange myProgressRange; |
25dfc507 |
127 | }; |
128 | //======================================================================= |
fc867b96 |
129 | typedef NCollection_Vector<BOPAlgo_VertexSolid> BOPAlgo_VectorOfVertexSolid; |
130 | |
25dfc507 |
131 | ///////////////////////////////////////////////////////////////////////// |
132 | //======================================================================= |
133 | //class : BOPAlgo_ShapeSolid |
134 | //purpose : |
135 | //======================================================================= |
d03c0898 |
136 | class BOPAlgo_ShapeSolid { |
25dfc507 |
137 | public: |
138 | DEFINE_STANDARD_ALLOC |
139 | |
140 | BOPAlgo_ShapeSolid() : |
141 | myIE(-1), |
142 | myIZ(-1), |
143 | myHasInterf(Standard_False), |
144 | myDS(NULL) { |
145 | }; |
146 | // |
147 | virtual ~BOPAlgo_ShapeSolid(){ |
148 | }; |
149 | // |
150 | void SetIndices(const Standard_Integer nE, |
151 | const Standard_Integer nZ){ |
152 | myIE=nE; |
153 | myIZ=nZ; |
154 | } |
155 | // |
156 | void Indices(Standard_Integer& nE, |
157 | Standard_Integer& nZ) const { |
158 | nE=myIE; |
159 | nZ=myIZ; |
160 | } |
161 | // |
162 | void SetDS(BOPDS_DS* pDS) { |
163 | myDS=pDS; |
164 | } |
165 | // |
166 | Standard_Boolean HasInterf() const{ |
167 | return myHasInterf; |
168 | }; |
169 | // |
d03c0898 |
170 | void SetProgressRange(const Message_ProgressRange& theRange) |
171 | { |
172 | myProgressRange = theRange; |
173 | } |
174 | // |
25dfc507 |
175 | virtual void Perform() { |
d03c0898 |
176 | Message_ProgressScope aPS(myProgressRange, NULL, 1); |
177 | if (!aPS.More()) |
178 | { |
179 | return; |
180 | } |
181 | |
25dfc507 |
182 | Standard_Boolean bHasInterf; |
183 | // |
184 | myHasInterf=Standard_False; |
185 | // |
186 | bHasInterf=myDS->HasInterfShapeSubShapes(myIE, myIZ); |
187 | if (!bHasInterf) { |
188 | myHasInterf=myDS->HasInterfShapeSubShapes(myIZ, myIE); |
189 | } |
190 | }; |
191 | // |
192 | protected: |
193 | Standard_Integer myIE; |
194 | Standard_Integer myIZ; |
195 | Standard_Boolean myHasInterf; |
196 | BOPDS_DS* myDS; |
d03c0898 |
197 | Message_ProgressRange myProgressRange; |
25dfc507 |
198 | }; |
199 | //======================================================================= |
fc867b96 |
200 | typedef NCollection_Vector<BOPAlgo_ShapeSolid> BOPAlgo_VectorOfShapeSolid; |
201 | |
25dfc507 |
202 | ///////////////////////////////////////////////////////////////////////// |
203 | //======================================================================= |
204 | //class : BOPAlgo_SolidSolid |
205 | //purpose : |
206 | //======================================================================= |
207 | class BOPAlgo_SolidSolid : public BOPAlgo_ShapeSolid { |
208 | public: |
209 | DEFINE_STANDARD_ALLOC |
210 | |
211 | BOPAlgo_SolidSolid() : |
212 | BOPAlgo_ShapeSolid() { |
213 | }; |
214 | // |
215 | virtual ~BOPAlgo_SolidSolid(){ |
216 | }; |
217 | // |
218 | virtual void Perform() { |
d03c0898 |
219 | Message_ProgressScope aPS(myProgressRange, NULL, 1); |
220 | if (!aPS.More()) |
221 | { |
222 | return; |
223 | } |
224 | |
25dfc507 |
225 | Standard_Boolean bFlag; |
226 | // |
227 | bFlag=Standard_False; |
228 | myHasInterf=Standard_False; |
229 | // |
230 | myHasInterf=myDS->HasInterfShapeSubShapes(myIZ, myIE, bFlag); |
231 | if (!myHasInterf) { |
232 | myHasInterf=myDS->HasInterfShapeSubShapes(myIE, myIZ, bFlag); |
233 | } |
234 | }; |
235 | }; |
236 | //======================================================================= |
fc867b96 |
237 | typedef NCollection_Vector<BOPAlgo_SolidSolid> BOPAlgo_VectorOfSolidSolid; |
25dfc507 |
238 | |
239 | //======================================================================= |
240 | //function : PerformVZ |
241 | //purpose : |
242 | //======================================================================= |
d03c0898 |
243 | void BOPAlgo_CheckerSI::PerformVZ(const Message_ProgressRange& theRange) |
25dfc507 |
244 | { |
d03c0898 |
245 | Message_ProgressScope aPSOuter(theRange, NULL, 1); |
246 | |
25dfc507 |
247 | Standard_Integer iSize, nV, nZ, k, aNbVVS; |
248 | TopAbs_State aState; |
249 | BOPDS_MapOfPair aMPK; |
250 | // |
25dfc507 |
251 | myIterator->Initialize(TopAbs_VERTEX, TopAbs_SOLID); |
252 | iSize=myIterator->ExpectedLength(); |
253 | if (!iSize) { |
254 | return; |
255 | } |
256 | // |
257 | BOPDS_VectorOfInterfVZ& aVZs=myDS->InterfVZ(); |
258 | aVZs.SetIncrement(iSize); |
259 | // |
260 | BOPAlgo_VectorOfVertexSolid aVVS; |
261 | // |
262 | for (; myIterator->More(); myIterator->Next()) { |
d03c0898 |
263 | if (UserBreak(aPSOuter)) |
264 | { |
265 | return; |
266 | } |
25dfc507 |
267 | myIterator->Value(nV, nZ); |
268 | // |
269 | if (myDS->HasInterfShapeSubShapes(nV, nZ)) { |
270 | continue; |
271 | } |
272 | // |
273 | Standard_Integer nVSD = nV; |
274 | myDS->HasShapeSD(nV, nVSD); |
275 | // |
276 | BOPDS_Pair aPK; |
277 | aPK.SetIndices(nVSD, nZ); |
278 | if (!aMPK.Add(aPK)) { |
279 | continue; |
280 | } |
281 | // |
282 | const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nVSD)); |
283 | const TopoDS_Solid& aZ=*((TopoDS_Solid*)&myDS->Shape(nZ)); |
284 | // |
1155d05a |
285 | BOPAlgo_VertexSolid& aVertexSolid=aVVS.Appended(); |
25dfc507 |
286 | aVertexSolid.SetIndices(nV, nZ); |
287 | aVertexSolid.SetVertex(aV); |
288 | aVertexSolid.SetSolid(aZ); |
289 | } |
290 | // |
1155d05a |
291 | aNbVVS=aVVS.Length(); |
d03c0898 |
292 | |
293 | Message_ProgressScope aPSParallel(aPSOuter.Next(), "Performing Vertex-Solid intersection", aNbVVS); |
294 | for (Standard_Integer iVS = 0; iVS < aNbVVS; ++iVS) |
295 | { |
296 | aVVS.ChangeValue(iVS).SetProgressRange(aPSParallel.Next()); |
297 | } |
25dfc507 |
298 | //============================================================= |
fc867b96 |
299 | BOPTools_Parallel::Perform (myRunParallel, aVVS, myContext); |
25dfc507 |
300 | //============================================================= |
d03c0898 |
301 | if (UserBreak(aPSOuter)) |
302 | { |
303 | return; |
304 | } |
25dfc507 |
305 | for (k=0; k < aNbVVS; ++k) { |
306 | const BOPAlgo_VertexSolid& aVertexSolid=aVVS(k); |
307 | aState=aVertexSolid.State(); |
308 | if (aState==TopAbs_IN) { |
309 | aVertexSolid.Indices(nV, nZ); |
310 | // |
1155d05a |
311 | BOPDS_InterfVZ& aVZ=aVZs.Appended(); |
25dfc507 |
312 | aVZ.SetIndices(nV, nZ); |
313 | // |
314 | myDS->AddInterf(nV, nZ); |
315 | } |
316 | } |
317 | } |
318 | //======================================================================= |
319 | //function : PerformEZ |
320 | //purpose : |
321 | //======================================================================= |
d03c0898 |
322 | void BOPAlgo_CheckerSI::PerformEZ(const Message_ProgressRange& theRange) |
25dfc507 |
323 | { |
d03c0898 |
324 | PerformSZ(TopAbs_EDGE, theRange); |
25dfc507 |
325 | } |
326 | //======================================================================= |
327 | //function : PerformFZ |
328 | //purpose : |
329 | //======================================================================= |
d03c0898 |
330 | void BOPAlgo_CheckerSI::PerformFZ(const Message_ProgressRange& theRange) |
25dfc507 |
331 | { |
d03c0898 |
332 | PerformSZ(TopAbs_FACE, theRange); |
25dfc507 |
333 | } |
334 | //======================================================================= |
335 | //function : PerformZZ |
336 | //purpose : |
337 | //======================================================================= |
d03c0898 |
338 | void BOPAlgo_CheckerSI::PerformZZ(const Message_ProgressRange& theRange) |
25dfc507 |
339 | { |
d03c0898 |
340 | Message_ProgressScope aPSOuter(theRange, NULL, 1); |
341 | |
25dfc507 |
342 | Standard_Boolean bHasInterf; |
343 | Standard_Integer iSize, nZ1, nZ, k, aNbSolidSolid; |
344 | // |
25dfc507 |
345 | myIterator->Initialize(TopAbs_SOLID, TopAbs_SOLID); |
346 | iSize=myIterator->ExpectedLength(); |
347 | if (!iSize) { |
348 | return; |
349 | } |
350 | // |
351 | BOPAlgo_VectorOfSolidSolid aVSolidSolid; |
352 | // |
353 | for (; myIterator->More(); myIterator->Next()) { |
354 | myIterator->Value(nZ1, nZ); |
355 | // |
1155d05a |
356 | BOPAlgo_SolidSolid& aSolidSolid=aVSolidSolid.Appended(); |
25dfc507 |
357 | aSolidSolid.SetIndices(nZ1, nZ); |
358 | aSolidSolid.SetDS(myDS); |
359 | } |
360 | // |
1155d05a |
361 | aNbSolidSolid=aVSolidSolid.Length(); |
d03c0898 |
362 | |
363 | Message_ProgressScope aPSParallel(aPSOuter.Next(), "Performing Solid-Solid intersection", aNbSolidSolid); |
364 | for (Standard_Integer iSS = 0; iSS < aNbSolidSolid; ++iSS) |
365 | { |
366 | aVSolidSolid.ChangeValue(iSS).SetProgressRange(aPSParallel.Next()); |
367 | } |
25dfc507 |
368 | //====================================================== |
fc867b96 |
369 | BOPTools_Parallel::Perform (myRunParallel, aVSolidSolid); |
25dfc507 |
370 | //====================================================== |
d03c0898 |
371 | if (UserBreak(aPSOuter)) |
372 | { |
373 | return; |
374 | } |
25dfc507 |
375 | // |
376 | BOPDS_VectorOfInterfZZ& aZZs=myDS->InterfZZ(); |
377 | // |
378 | aZZs.SetIncrement(iSize); |
379 | // |
380 | for (k=0; k < aNbSolidSolid; ++k) { |
381 | const BOPAlgo_SolidSolid& aSolidSolid=aVSolidSolid(k); |
382 | bHasInterf=aSolidSolid.HasInterf(); |
383 | if (bHasInterf) { |
384 | aSolidSolid.Indices(nZ1, nZ); |
385 | // |
1155d05a |
386 | BOPDS_InterfZZ& aZZ=aZZs.Appended(); |
25dfc507 |
387 | aZZ.SetIndices(nZ1, nZ); |
388 | // |
389 | myDS->AddInterf(nZ1, nZ); |
390 | } |
391 | } |
392 | } |
393 | //======================================================================= |
394 | //function : PerformSZ |
395 | //purpose : |
396 | //======================================================================= |
d03c0898 |
397 | void BOPAlgo_CheckerSI::PerformSZ(const TopAbs_ShapeEnum theTS, const Message_ProgressRange& theRange) |
25dfc507 |
398 | { |
d03c0898 |
399 | Message_ProgressScope aPSOuter(theRange, NULL, 1); |
400 | |
25dfc507 |
401 | Standard_Boolean bHasInterf; |
402 | Standard_Integer iSize, nS, nZ, k, aNbShapeSolid; |
403 | // |
d03c0898 |
404 | myIterator->Initialize(theTS, TopAbs_SOLID); |
25dfc507 |
405 | iSize=myIterator->ExpectedLength(); |
406 | if (!iSize) { |
407 | return; |
408 | } |
409 | // |
410 | BOPAlgo_VectorOfShapeSolid aVShapeSolid; |
411 | // |
412 | for (; myIterator->More(); myIterator->Next()) { |
413 | myIterator->Value(nS, nZ); |
414 | // |
1155d05a |
415 | BOPAlgo_ShapeSolid& aShapeSolid=aVShapeSolid.Appended(); |
25dfc507 |
416 | aShapeSolid.SetIndices(nS, nZ); |
417 | aShapeSolid.SetDS(myDS); |
418 | } |
419 | // |
1155d05a |
420 | aNbShapeSolid=aVShapeSolid.Length(); |
d03c0898 |
421 | |
422 | Message_ProgressScope aPSParallel(aPSOuter.Next(), |
423 | theTS == TopAbs_EDGE ? "Performing Edge-Solid intersection" : |
424 | "Performing Face-Solid intersection", |
425 | aNbShapeSolid); |
426 | for (Standard_Integer iSS = 0; iSS < aNbShapeSolid; ++iSS) |
427 | { |
428 | aVShapeSolid.ChangeValue(iSS).SetProgressRange(aPSParallel.Next()); |
429 | } |
25dfc507 |
430 | //====================================================== |
fc867b96 |
431 | BOPTools_Parallel::Perform (myRunParallel, aVShapeSolid); |
25dfc507 |
432 | //====================================================== |
d03c0898 |
433 | if (UserBreak(aPSOuter)) |
434 | { |
435 | return; |
436 | } |
25dfc507 |
437 | // |
438 | BOPDS_VectorOfInterfEZ& aEZs=myDS->InterfEZ(); |
439 | BOPDS_VectorOfInterfFZ& aFZs=myDS->InterfFZ(); |
440 | // |
d03c0898 |
441 | if (theTS==TopAbs_EDGE) { |
25dfc507 |
442 | aEZs.SetIncrement(iSize); |
443 | } |
444 | else {//if (aTS==TopAbs_FACE) |
445 | aFZs.SetIncrement(iSize); |
446 | } |
447 | // |
448 | for (k=0; k < aNbShapeSolid; ++k) { |
449 | const BOPAlgo_ShapeSolid& aShapeSolid=aVShapeSolid(k); |
450 | bHasInterf=aShapeSolid.HasInterf(); |
451 | if (bHasInterf) { |
452 | aShapeSolid.Indices(nS, nZ); |
453 | // |
d03c0898 |
454 | if (theTS==TopAbs_EDGE) { |
1155d05a |
455 | BOPDS_InterfEZ& aEZ=aEZs.Appended(); |
25dfc507 |
456 | aEZ.SetIndices(nS, nZ); |
457 | } |
458 | else {//if (aTS==TopAbs_FACE) |
1155d05a |
459 | BOPDS_InterfFZ& aFZ=aFZs.Appended(); |
25dfc507 |
460 | aFZ.SetIndices(nS, nZ); |
461 | } |
462 | // |
463 | myDS->AddInterf(nS, nZ); |
464 | } |
465 | } |
466 | } |