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 <BOPTools_AlgoTools.ixx> |
19 | // |
20 | #include <Precision.hxx> |
21 | // |
22 | #include <gp_Pnt.hxx> |
23 | #include <gp_XYZ.hxx> |
24 | #include <gp_Pnt2d.hxx> |
df017cc9 |
25 | #include <gp_Cylinder.hxx> |
26 | #include <gp_Cone.hxx> |
27 | #include <gp_Sphere.hxx> |
28 | #include <gp_Torus.hxx> |
b92a64cc |
29 | #include <gp_Lin.hxx> |
4e57c75e |
30 | // |
31 | #include <Geom2d_Curve.hxx> |
32 | #include <Geom_Surface.hxx> |
df017cc9 |
33 | #include <Geom_Plane.hxx> |
4e57c75e |
34 | #include <Geom_TrimmedCurve.hxx> |
35 | #include <Geom_Curve.hxx> |
36 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
37 | #include <Geom2dInt_Geom2dCurveTool.hxx> |
38 | // |
39 | #include <TopAbs_Orientation.hxx> |
40 | // |
41 | #include <TopoDS_Compound.hxx> |
42 | #include <TopoDS_CompSolid.hxx> |
43 | #include <TopoDS_Solid.hxx> |
44 | #include <TopoDS_Shell.hxx> |
45 | #include <TopoDS_Wire.hxx> |
46 | // |
47 | #include <BRep_Builder.hxx> |
48 | #include <BRep_Tool.hxx> |
49 | #include <BRepLib.hxx> |
50 | #include <BRepAdaptor_Curve2d.hxx> |
bb58e462 |
51 | #include <BRepAdaptor_Surface.hxx> |
4e57c75e |
52 | #include <BRepClass3d_SolidClassifier.hxx> |
53 | #include <TopExp.hxx> |
54 | #include <TopExp_Explorer.hxx> |
55 | // |
56 | #include <IntTools_Tools.hxx> |
57 | // |
df017cc9 |
58 | #include <BOPTools.hxx> |
59 | #include <BOPTools_CoupleOfShape.hxx> |
60 | #include <BOPTools_ListOfCoupleOfShape.hxx> |
4e57c75e |
61 | #include <BOPTools_AlgoTools2D.hxx> |
62 | #include <BOPTools_AlgoTools3D.hxx> |
63 | // |
64 | #include <BOPCol_IndexedMapOfShape.hxx> |
65 | #include <BOPCol_MapOfShape.hxx> |
66 | // |
1e143abb |
67 | #include <IntTools_ShrunkRange.hxx> |
df017cc9 |
68 | // |
4e57c75e |
69 | |
70 | static |
71 | Standard_Real AngleWithRef(const gp_Dir& theD1, |
72 | const gp_Dir& theD2, |
73 | const gp_Dir& theDRef); |
4e57c75e |
74 | |
75 | static |
76 | Standard_Boolean FindFacePairs (const TopoDS_Edge& theE, |
77 | const BOPCol_ListOfShape& thLF, |
78 | BOPTools_ListOfCoupleOfShape& theLCFF, |
1e143abb |
79 | Handle(IntTools_Context)& theContext); |
4e57c75e |
80 | static |
81 | TopAbs_Orientation Orientation(const TopoDS_Edge& anE, |
82 | const TopoDS_Face& aF); |
83 | |
bb58e462 |
84 | static |
df017cc9 |
85 | void GetFaceDir(const TopoDS_Edge& aE, |
86 | const TopoDS_Face& aF, |
87 | const gp_Pnt& aP, |
88 | const Standard_Real aT, |
89 | const gp_Dir& aDTgt, |
90 | gp_Dir& aDN, |
91 | gp_Dir& aDB, |
1e143abb |
92 | Handle(IntTools_Context)& theContext, |
f56518cd |
93 | GeomAPI_ProjectPointOnSurf& aProjPL, |
94 | const Standard_Real aDt); |
bb58e462 |
95 | static |
f56518cd |
96 | Standard_Boolean FindPointInFace(const TopoDS_Face& aF, |
df017cc9 |
97 | const gp_Pnt& aP, |
df017cc9 |
98 | gp_Dir& aDB, |
99 | gp_Pnt& aPOut, |
1e143abb |
100 | Handle(IntTools_Context)& theContext, |
f56518cd |
101 | GeomAPI_ProjectPointOnSurf& aProjPL, |
393598eb |
102 | const Standard_Real aDt, |
103 | const Standard_Real aTolE); |
f56518cd |
104 | static |
105 | Standard_Real MinStep3D(const TopoDS_Edge& theE1, |
106 | const TopoDS_Face& theF1, |
107 | const BOPTools_ListOfCoupleOfShape& theLCS, |
108 | const gp_Pnt& aP); |
4e57c75e |
109 | |
110 | //======================================================================= |
111 | // function: MakeConnexityBlocks |
112 | // purpose: |
113 | //======================================================================= |
505abfb8 |
114 | void BOPTools_AlgoTools::MakeConnexityBlocks |
115 | (const TopoDS_Shape& theS, |
116 | const TopAbs_ShapeEnum theType1, |
117 | const TopAbs_ShapeEnum theType2, |
118 | BOPCol_ListOfShape& theLCB) |
4e57c75e |
119 | { |
120 | Standard_Integer aNbF, aNbAdd, aNbAdd1, i; |
121 | BRep_Builder aBB; |
122 | TopoDS_Compound aC; |
123 | TopoDS_Iterator aIt; |
124 | TopExp_Explorer aExp; |
125 | BOPCol_MapOfShape aMP; |
126 | BOPCol_IndexedMapOfShape aMCB, aMAdd, aMAdd1; |
127 | BOPCol_IndexedDataMapOfShapeListOfShape aMEF; |
128 | BOPCol_ListIteratorOfListOfShape aItLF; |
129 | // |
130 | // 1. aMEF |
131 | BOPTools::MapShapesAndAncestors(theS, theType1, theType2, aMEF); |
132 | // |
133 | // 2. aMCB |
134 | aIt.Initialize(theS); |
135 | for (; aIt.More(); aIt.Next()) { |
136 | const TopoDS_Shape& aF1=aIt.Value(); |
137 | if (aMP.Contains(aF1)) { |
138 | continue; |
139 | } |
140 | // |
141 | aMCB.Clear(); |
142 | aMAdd.Clear(); |
143 | aMAdd.Add(aF1); |
144 | // |
302f96fb |
145 | for(;;) { |
4e57c75e |
146 | aMAdd1.Clear(); |
147 | // |
148 | aNbAdd = aMAdd.Extent(); |
149 | for (i=1; i<=aNbAdd; ++i) { |
150 | const TopoDS_Shape& aF=aMAdd(i); |
151 | // |
152 | aExp.Init(aF, theType1); |
153 | for (; aExp.More(); aExp.Next()) { |
154 | const TopoDS_Shape& aE=aExp.Current(); |
155 | // |
156 | const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE); |
157 | aItLF.Initialize(aLF); |
158 | for (; aItLF.More(); aItLF.Next()) { |
159 | const TopoDS_Shape& aFx=aItLF.Value(); |
160 | if (aFx.IsSame(aF)) { |
161 | continue; |
162 | } |
163 | if (aMCB.Contains(aFx)) { |
164 | continue; |
165 | } |
166 | aMAdd1.Add(aFx); |
167 | } |
168 | }//for (; aExp.More(); aExp.Next()){ |
169 | aMCB.Add(aF); |
170 | }// for (i=1; i<=aNbAdd; ++i) { |
171 | // |
172 | aNbAdd1=aMAdd1.Extent(); |
173 | if (!aNbAdd1) { |
174 | break;// ->make new CB from aMCB |
175 | } |
176 | // |
177 | aMAdd.Clear(); |
178 | for (i=1; i<=aNbAdd1; ++i) { |
179 | const TopoDS_Shape& aFAdd = aMAdd1(i); |
180 | aMAdd.Add(aFAdd); |
181 | } |
182 | }//while(1) { |
183 | // |
184 | aNbF=aMCB.Extent(); |
185 | if (aNbF) { |
186 | aBB.MakeCompound(aC); |
187 | // |
188 | for (i=1; i<=aNbF; ++i) { |
189 | const TopoDS_Shape& aF=aMCB(i); |
190 | aBB.Add(aC, aF); |
191 | aMP.Add(aF); |
192 | } |
193 | theLCB.Append(aC); |
194 | } |
195 | }// for (; aIt.More(); aIt.Next()) |
196 | } |
197 | //======================================================================= |
198 | // function: OrientFacesOnShell |
199 | // purpose: |
200 | //======================================================================= |
744511c8 |
201 | void BOPTools_AlgoTools::OrientFacesOnShell (TopoDS_Shape& aShell) |
4e57c75e |
202 | { |
203 | Standard_Boolean bIsProcessed1, bIsProcessed2; |
204 | Standard_Integer i, aNbE, aNbF, j; |
205 | TopAbs_Orientation anOrE1, anOrE2; |
206 | TopoDS_Face aF1x, aF2x; |
207 | TopoDS_Shape aShellNew; |
208 | BOPCol_IndexedDataMapOfShapeListOfShape aEFMap; |
209 | BOPCol_IndexedMapOfShape aProcessedFaces; |
210 | BRep_Builder aBB; |
211 | // |
212 | BOPTools_AlgoTools::MakeContainer(TopAbs_SHELL, aShellNew); |
213 | // |
505abfb8 |
214 | BOPTools::MapShapesAndAncestors(aShell, |
215 | TopAbs_EDGE, TopAbs_FACE, |
216 | aEFMap); |
4e57c75e |
217 | aNbE=aEFMap.Extent(); |
218 | // |
219 | // One seam edge in aEFMap contains 2 equivalent faces. |
220 | for (i=1; i<=aNbE; ++i) { |
221 | BOPCol_ListOfShape& aLF=aEFMap.ChangeFromIndex(i); |
222 | aNbF=aLF.Extent(); |
223 | if (aNbF>1) { |
224 | BOPCol_ListOfShape aLFTmp; |
225 | BOPCol_IndexedMapOfShape aFM; |
226 | // |
227 | BOPCol_ListIteratorOfListOfShape anIt(aLF); |
228 | for (; anIt.More(); anIt.Next()) { |
229 | const TopoDS_Shape& aF=anIt.Value(); |
230 | if (!aFM.Contains(aF)) { |
231 | aFM.Add(aF); |
232 | aLFTmp.Append(aF); |
233 | } |
234 | } |
235 | aLF.Clear(); |
236 | aLF=aLFTmp; |
237 | } |
238 | } |
239 | // |
240 | // Do |
241 | for (i=1; i<=aNbE; ++i) { |
242 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aEFMap.FindKey(i))); |
243 | if (BRep_Tool::Degenerated(aE)) { |
244 | continue; |
245 | } |
246 | // |
247 | const BOPCol_ListOfShape& aLF=aEFMap.FindFromIndex(i); |
248 | aNbF=aLF.Extent(); |
249 | if (aNbF!=2) { |
250 | continue; |
251 | } |
252 | // |
253 | TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First())); |
254 | TopoDS_Face& aF2=(*(TopoDS_Face*)(&aLF.Last())); |
255 | // |
256 | bIsProcessed1=aProcessedFaces.Contains(aF1); |
257 | bIsProcessed2=aProcessedFaces.Contains(aF2); |
258 | if (bIsProcessed1 && bIsProcessed2) { |
259 | continue; |
260 | } |
261 | |
262 | if (!bIsProcessed1 && !bIsProcessed2) { |
263 | aProcessedFaces.Add(aF1); |
264 | aBB.Add(aShellNew, aF1); |
265 | bIsProcessed1=!bIsProcessed1; |
266 | } |
267 | // |
268 | aF1x=aF1; |
269 | if (bIsProcessed1) { |
270 | j=aProcessedFaces.FindIndex(aF1); |
271 | aF1x=(*(TopoDS_Face*)(&aProcessedFaces.FindKey(j))); |
272 | } |
273 | // |
274 | aF2x=aF2; |
275 | if (bIsProcessed2) { |
276 | j=aProcessedFaces.FindIndex(aF2); |
277 | aF2x=(*(TopoDS_Face*)(&aProcessedFaces.FindKey(j))); |
278 | } |
279 | // |
280 | anOrE1=Orientation(aE, aF1x); |
281 | anOrE2=Orientation(aE, aF2x); |
282 | // |
283 | if (bIsProcessed1 && !bIsProcessed2) { |
284 | if (anOrE1==anOrE2) { |
285 | if (!BRep_Tool::IsClosed(aE, aF1) && |
286 | !BRep_Tool::IsClosed(aE, aF2)) { |
287 | aF2.Reverse(); |
288 | } |
289 | } |
290 | aProcessedFaces.Add(aF2); |
291 | aBB.Add(aShellNew, aF2); |
292 | } |
293 | else if (!bIsProcessed1 && bIsProcessed2) { |
294 | if (anOrE1==anOrE2) { |
295 | if (!BRep_Tool::IsClosed(aE, aF1) && |
296 | !BRep_Tool::IsClosed(aE, aF2)) { |
297 | aF1.Reverse(); |
298 | } |
299 | } |
300 | aProcessedFaces.Add(aF1); |
301 | aBB.Add(aShellNew, aF1); |
302 | } |
303 | } |
304 | // |
305 | // |
306 | for (i=1; i<=aNbE; ++i) { |
307 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aEFMap.FindKey(i))); |
308 | if (BRep_Tool::Degenerated(aE)) { |
309 | continue; |
310 | } |
311 | // |
312 | const BOPCol_ListOfShape& aLF=aEFMap.FindFromIndex(i); |
313 | aNbF=aLF.Extent(); |
314 | if (aNbF!=2) { |
315 | BOPCol_ListIteratorOfListOfShape anIt(aLF); |
316 | for(; anIt.More(); anIt.Next()) { |
317 | const TopoDS_Face& aF=(*(TopoDS_Face*)(&anIt.Value())); |
318 | if (!aProcessedFaces.Contains(aF)) { |
319 | aProcessedFaces.Add(aF); |
320 | aBB.Add(aShellNew, aF); |
321 | } |
322 | } |
323 | } |
324 | } |
325 | aShell=aShellNew; |
326 | } |
327 | //======================================================================= |
328 | //function : Orientation |
329 | //purpose : |
330 | //======================================================================= |
744511c8 |
331 | TopAbs_Orientation Orientation(const TopoDS_Edge& anE, |
bb58e462 |
332 | const TopoDS_Face& aF) |
4e57c75e |
333 | { |
334 | TopAbs_Orientation anOr=TopAbs_INTERNAL; |
335 | |
336 | TopExp_Explorer anExp; |
337 | anExp.Init(aF, TopAbs_EDGE); |
338 | for (; anExp.More(); anExp.Next()) { |
339 | const TopoDS_Edge& anEF1=(*(TopoDS_Edge*)(&anExp.Current())); |
340 | if (anEF1.IsSame(anE)) { |
341 | anOr=anEF1.Orientation(); |
342 | break; |
343 | } |
344 | } |
345 | return anOr; |
346 | } |
4e57c75e |
347 | //======================================================================= |
348 | // function: MakeConnexityBlock. |
349 | // purpose: |
350 | //======================================================================= |
505abfb8 |
351 | void BOPTools_AlgoTools::MakeConnexityBlock |
352 | (BOPCol_ListOfShape& theLFIn, |
353 | BOPCol_IndexedMapOfShape& theMEAvoid, |
354 | BOPCol_ListOfShape& theLCB, |
355 | const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
356 | { |
357 | Standard_Integer aNbF, aNbAdd1, aNbAdd, i; |
358 | TopExp_Explorer aExp; |
359 | BOPCol_ListIteratorOfListOfShape aIt; |
360 | // |
361 | BOPCol_IndexedMapOfShape aMCB(100, theAllocator); |
362 | BOPCol_IndexedMapOfShape aMAdd(100, theAllocator); |
363 | BOPCol_IndexedMapOfShape aMAdd1(100, theAllocator); |
364 | BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, theAllocator); |
365 | // |
366 | // 1. aMEF |
367 | aNbF=theLFIn.Extent(); |
368 | aIt.Initialize(theLFIn); |
369 | for (; aIt.More(); aIt.Next()) { |
370 | const TopoDS_Shape& aF=aIt.Value(); |
371 | BOPTools::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aMEF); |
372 | } |
373 | // |
374 | // 2. aMCB |
375 | const TopoDS_Shape& aF1=theLFIn.First(); |
376 | aMAdd.Add(aF1); |
377 | // |
302f96fb |
378 | for(;;) { |
4e57c75e |
379 | aMAdd1.Clear(); |
380 | aNbAdd = aMAdd.Extent(); |
381 | for (i=1; i<=aNbAdd; ++i) { |
382 | const TopoDS_Shape& aF=aMAdd(i); |
383 | // |
384 | //aMAdd1.Clear(); |
385 | aExp.Init(aF, TopAbs_EDGE); |
386 | for (; aExp.More(); aExp.Next()) { |
387 | const TopoDS_Shape& aE=aExp.Current(); |
388 | if (theMEAvoid.Contains(aE)){ |
389 | continue; |
390 | } |
391 | // |
392 | const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE); |
393 | aIt.Initialize(aLF); |
394 | for (; aIt.More(); aIt.Next()) { |
395 | const TopoDS_Shape& aFx=aIt.Value(); |
396 | if (aFx.IsSame(aF)) { |
397 | continue; |
398 | } |
399 | if (aMCB.Contains(aFx)) { |
400 | continue; |
401 | } |
402 | aMAdd1.Add(aFx); |
403 | } |
404 | }//for (; aExp.More(); aExp.Next()){ |
405 | aMCB.Add(aF); |
406 | }// for (i=1; i<=aNbAdd; ++i) { |
407 | // |
408 | aNbAdd1=aMAdd1.Extent(); |
409 | if (!aNbAdd1) { |
410 | break; |
411 | } |
412 | // |
413 | aMAdd.Clear(); |
414 | for (i=1; i<=aNbAdd1; ++i) { |
415 | const TopoDS_Shape& aFAdd=aMAdd1(i); |
416 | aMAdd.Add(aFAdd); |
417 | } |
418 | // |
419 | }//while(1) { |
420 | |
421 | // |
422 | aNbF=aMCB.Extent(); |
423 | for (i=1; i<=aNbF; ++i) { |
424 | const TopoDS_Shape& aF=aMCB(i); |
425 | theLCB.Append(aF); |
426 | } |
427 | } |
428 | //======================================================================= |
429 | // function: ComputeStateByOnePoint |
430 | // purpose: |
431 | //======================================================================= |
505abfb8 |
432 | TopAbs_State BOPTools_AlgoTools::ComputeStateByOnePoint |
433 | (const TopoDS_Shape& theS, |
434 | const TopoDS_Solid& theRef, |
435 | const Standard_Real theTol, |
1e143abb |
436 | Handle(IntTools_Context)& theContext) |
4e57c75e |
437 | { |
438 | TopAbs_State aState; |
439 | TopAbs_ShapeEnum aType; |
440 | // |
441 | aState=TopAbs_UNKNOWN; |
442 | aType=theS.ShapeType(); |
443 | if (aType==TopAbs_VERTEX) { |
444 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&theS)); |
445 | aState=BOPTools_AlgoTools::ComputeState(aV, theRef, theTol, theContext); |
446 | } |
447 | else if (aType==TopAbs_EDGE) { |
448 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&theS)); |
449 | aState=BOPTools_AlgoTools::ComputeState(aE, theRef, theTol, theContext); |
450 | } |
451 | return aState; |
452 | } |
453 | |
454 | //======================================================================= |
455 | // function: ComputeState |
456 | // purpose: |
457 | //======================================================================= |
505abfb8 |
458 | TopAbs_State BOPTools_AlgoTools::ComputeState |
459 | (const TopoDS_Face& theF, |
460 | const TopoDS_Solid& theRef, |
461 | const Standard_Real theTol, |
462 | BOPCol_IndexedMapOfShape& theBounds, |
1e143abb |
463 | Handle(IntTools_Context)& theContext) |
4e57c75e |
464 | { |
465 | TopAbs_State aState; |
466 | TopExp_Explorer aExp; |
467 | TopoDS_Edge aE1; |
468 | gp_Pnt2d aP2D; |
469 | gp_Pnt aP3D; |
470 | // |
471 | aState=TopAbs_UNKNOWN; |
472 | // |
473 | aExp.Init(theF, TopAbs_EDGE); |
474 | for (; aExp.More(); aExp.Next()) { |
475 | const TopoDS_Edge& aSE=(*(TopoDS_Edge*)(&aExp.Current())); |
476 | if (BRep_Tool::Degenerated(aSE)) { |
477 | continue; |
478 | } |
479 | // |
480 | if (!theBounds.Contains(aSE)) { |
481 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aSE)); |
505abfb8 |
482 | aState=BOPTools_AlgoTools::ComputeState(aE, theRef, theTol, |
483 | theContext); |
4e57c75e |
484 | return aState; |
485 | } |
486 | if (aE1.IsNull()) { |
487 | aE1=(*(TopoDS_Edge*)(&aSE)); |
488 | } |
489 | } |
490 | // !!<- process edges that are all on theRef |
491 | if (!aE1.IsNull()) { |
505abfb8 |
492 | BOPTools_AlgoTools3D::PointNearEdge(aE1, theF, |
493 | aP2D, aP3D, theContext); |
494 | aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol, |
495 | theContext); |
4e57c75e |
496 | } |
497 | // |
498 | return aState; |
499 | } |
500 | //======================================================================= |
501 | // function: ComputeState |
502 | // purpose: |
503 | //======================================================================= |
505abfb8 |
504 | TopAbs_State BOPTools_AlgoTools::ComputeState |
505 | (const TopoDS_Vertex& theV, |
506 | const TopoDS_Solid& theRef, |
507 | const Standard_Real theTol, |
1e143abb |
508 | Handle(IntTools_Context)& theContext) |
4e57c75e |
509 | { |
510 | TopAbs_State aState; |
511 | gp_Pnt aP3D; |
512 | // |
513 | aP3D=BRep_Tool::Pnt(theV); |
505abfb8 |
514 | aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol, |
515 | theContext); |
4e57c75e |
516 | return aState; |
517 | } |
518 | //======================================================================= |
519 | // function: ComputeState |
520 | // purpose: |
521 | //======================================================================= |
505abfb8 |
522 | TopAbs_State BOPTools_AlgoTools::ComputeState |
523 | (const TopoDS_Edge& theE, |
524 | const TopoDS_Solid& theRef, |
525 | const Standard_Real theTol, |
1e143abb |
526 | Handle(IntTools_Context)& theContext) |
4e57c75e |
527 | { |
528 | Standard_Real aT1, aT2, aT = 0.; |
529 | TopAbs_State aState; |
530 | Handle(Geom_Curve) aC3D; |
531 | gp_Pnt aP3D; |
532 | // |
533 | aC3D = BRep_Tool::Curve(theE, aT1, aT2); |
534 | // |
535 | if(aC3D.IsNull()) { |
536 | //it means that we are in degenerated edge |
537 | const TopoDS_Vertex& aV = TopExp::FirstVertex(theE); |
538 | if(aV.IsNull()){ |
539 | return TopAbs_UNKNOWN; |
540 | } |
541 | aP3D=BRep_Tool::Pnt(aV); |
542 | } |
543 | else {//usual case |
544 | Standard_Boolean bF2Inf, bL2Inf; |
545 | Standard_Real dT=10.; |
546 | // |
547 | bF2Inf = Precision::IsNegativeInfinite(aT1); |
548 | bL2Inf = Precision::IsPositiveInfinite(aT2); |
549 | // |
550 | if (bF2Inf && !bL2Inf) { |
551 | aT=aT2-dT; |
552 | } |
553 | else if (!bF2Inf && bL2Inf) { |
554 | aT=aT1+dT; |
555 | } |
556 | else if (bF2Inf && bL2Inf) { |
557 | aT=0.; |
558 | } |
559 | else { |
560 | aT=IntTools_Tools::IntermediatePoint(aT1, aT2); |
561 | } |
562 | aC3D->D0(aT, aP3D); |
563 | } |
564 | // |
505abfb8 |
565 | aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol, |
566 | theContext); |
4e57c75e |
567 | // |
568 | return aState; |
569 | } |
570 | //======================================================================= |
571 | // function: ComputeState |
572 | // purpose: |
573 | //======================================================================= |
505abfb8 |
574 | TopAbs_State BOPTools_AlgoTools::ComputeState |
575 | (const gp_Pnt& theP, |
576 | const TopoDS_Solid& theRef, |
577 | const Standard_Real theTol, |
1e143abb |
578 | Handle(IntTools_Context)& theContext) |
4e57c75e |
579 | { |
580 | TopAbs_State aState; |
581 | // |
582 | BRepClass3d_SolidClassifier& aSC=theContext->SolidClassifier(theRef); |
583 | aSC.Perform(theP, theTol); |
584 | // |
585 | aState=aSC.State(); |
586 | // |
587 | return aState; |
588 | } |
589 | //======================================================================= |
590 | //function : IsInternalFace |
591 | //purpose : |
592 | //======================================================================= |
744511c8 |
593 | Standard_Integer BOPTools_AlgoTools::IsInternalFace |
594 | (const TopoDS_Face& theFace, |
595 | const TopoDS_Solid& theSolid, |
596 | BOPCol_IndexedDataMapOfShapeListOfShape& theMEF, |
597 | const Standard_Real theTol, |
1e143abb |
598 | Handle(IntTools_Context)& theContext) |
4e57c75e |
599 | { |
744511c8 |
600 | Standard_Boolean bDegenerated; |
601 | Standard_Integer aNbF, iRet, iFound; |
4e57c75e |
602 | TopAbs_Orientation aOr; |
744511c8 |
603 | TopoDS_Edge aE1; |
4e57c75e |
604 | TopExp_Explorer aExp; |
605 | BOPCol_ListIteratorOfListOfShape aItF; |
606 | // |
744511c8 |
607 | // For all invoked functions: [::IsInternalFace(...)] |
608 | // the returned value iRet means: |
609 | // iRet=0; - state is not IN |
610 | // iRet=1; - state is IN |
611 | // iRet=2; - state can not be found by the method of angles |
612 | // |
613 | // For this function the returned value iRet means: |
614 | // iRet=0; - state is not IN |
615 | // iRet=1; - state is IN |
4e57c75e |
616 | // |
744511c8 |
617 | iRet=0; |
4e57c75e |
618 | // 1 Try to find an edge from theFace in theMEF |
744511c8 |
619 | iFound=0; |
4e57c75e |
620 | aExp.Init(theFace, TopAbs_EDGE); |
621 | for(; aExp.More(); aExp.Next()) { |
622 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); |
623 | if (!theMEF.Contains(aE)) { |
624 | continue; |
625 | } |
626 | // |
744511c8 |
627 | ++iFound; |
628 | // |
4e57c75e |
629 | aOr=aE.Orientation(); |
630 | if (aOr==TopAbs_INTERNAL) { |
631 | continue; |
632 | } |
633 | bDegenerated=BRep_Tool::Degenerated(aE); |
634 | if (bDegenerated){ |
635 | continue; |
636 | } |
637 | // aE |
638 | BOPCol_ListOfShape& aLF=theMEF.ChangeFromKey(aE); |
639 | aNbF=aLF.Extent(); |
640 | if (!aNbF) { |
744511c8 |
641 | return iRet; // it can not be so |
4e57c75e |
642 | } |
744511c8 |
643 | // |
4e57c75e |
644 | else if (aNbF==1) { |
645 | // aE is internal edge on aLF.First() |
646 | const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First())); |
744511c8 |
647 | BOPTools_AlgoTools::GetEdgeOnFace(aE, aF1, aE1); |
648 | if (aE1.Orientation()!=TopAbs_INTERNAL) { |
bb58e462 |
649 | iRet=2; |
650 | break; |
744511c8 |
651 | } |
652 | // |
505abfb8 |
653 | iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aF1, aF1, |
654 | theContext); |
744511c8 |
655 | break; |
4e57c75e |
656 | } |
744511c8 |
657 | // |
4e57c75e |
658 | else if (aNbF==2) { |
659 | const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First())); |
660 | const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aLF.Last())); |
661 | // |
662 | if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) { |
663 | // treat as it was for 1 face |
505abfb8 |
664 | iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aF1, aF2, |
665 | theContext); |
bb58e462 |
666 | break; |
4e57c75e |
667 | } |
668 | } |
744511c8 |
669 | // |
4e57c75e |
670 | if (aNbF%2) { |
744511c8 |
671 | iRet=0; |
672 | return iRet; // it can not be so |
4e57c75e |
673 | } |
674 | else { // aNbF=2,4,6,8,... |
505abfb8 |
675 | iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aLF, |
676 | theContext); |
744511c8 |
677 | break; |
4e57c75e |
678 | } |
679 | }//for(; aExp.More(); aExp.Next()) { |
680 | // |
744511c8 |
681 | if (!iFound) { |
682 | // the face has no shared edges with the solid |
683 | iRet=2; |
684 | } |
685 | // |
686 | if (iRet!=2) { |
687 | return iRet; |
688 | } |
689 | // |
4e57c75e |
690 | //======================================== |
691 | // 2. Classify face using classifier |
692 | // |
693 | TopAbs_State aState; |
694 | BOPCol_IndexedMapOfShape aBounds; |
695 | // |
744511c8 |
696 | BOPTools::MapShapes(theSolid, TopAbs_EDGE, aBounds); |
697 | // |
505abfb8 |
698 | aState=BOPTools_AlgoTools::ComputeState(theFace, theSolid, |
699 | theTol, aBounds, theContext); |
4e57c75e |
700 | // |
744511c8 |
701 | iRet=(aState==TopAbs_IN)? 1 : 0; |
702 | // |
703 | return iRet; |
4e57c75e |
704 | } |
705 | //======================================================================= |
706 | //function : IsInternalFace |
707 | //purpose : |
708 | //======================================================================= |
505abfb8 |
709 | Standard_Integer BOPTools_AlgoTools::IsInternalFace |
710 | (const TopoDS_Face& theFace, |
711 | const TopoDS_Edge& theEdge, |
712 | BOPCol_ListOfShape& theLF, |
1e143abb |
713 | Handle(IntTools_Context)& theContext) |
4e57c75e |
714 | { |
744511c8 |
715 | Standard_Integer aNbF, iRet; |
4e57c75e |
716 | // |
744511c8 |
717 | iRet=0; |
4e57c75e |
718 | // |
719 | aNbF=theLF.Extent(); |
720 | if (aNbF==2) { |
721 | const TopoDS_Face& aF1=(*(TopoDS_Face*)(&theLF.First())); |
722 | const TopoDS_Face& aF2=(*(TopoDS_Face*)(&theLF.Last())); |
505abfb8 |
723 | iRet=BOPTools_AlgoTools::IsInternalFace(theFace, theEdge, aF1, aF2, |
724 | theContext); |
744511c8 |
725 | return iRet; |
4e57c75e |
726 | } |
727 | // |
728 | else { |
729 | BOPTools_ListOfCoupleOfShape aLCFF; |
730 | BOPTools_ListIteratorOfListOfCoupleOfShape aIt; |
731 | // |
732 | FindFacePairs(theEdge, theLF, aLCFF, theContext); |
733 | // |
734 | aIt.Initialize(aLCFF); |
735 | for (; aIt.More(); aIt.Next()) { |
736 | BOPTools_CoupleOfShape& aCSFF=aIt.ChangeValue(); |
737 | // |
738 | const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aCSFF.Shape1())); |
739 | const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCSFF.Shape2())); |
505abfb8 |
740 | iRet=BOPTools_AlgoTools::IsInternalFace(theFace, theEdge, aF1, aF2, |
741 | theContext); |
744511c8 |
742 | if (iRet) { |
743 | return iRet; |
4e57c75e |
744 | } |
745 | } |
746 | } |
744511c8 |
747 | return iRet; |
4e57c75e |
748 | } |
749 | //======================================================================= |
750 | //function : IsInternalFace |
751 | //purpose : |
752 | //======================================================================= |
744511c8 |
753 | Standard_Integer BOPTools_AlgoTools::IsInternalFace |
754 | (const TopoDS_Face& theFace, |
755 | const TopoDS_Edge& theEdge, |
756 | const TopoDS_Face& theFace1, |
757 | const TopoDS_Face& theFace2, |
1e143abb |
758 | Handle(IntTools_Context)& theContext) |
4e57c75e |
759 | { |
760 | Standard_Boolean bRet; |
744511c8 |
761 | Standard_Integer iRet; |
4e57c75e |
762 | TopoDS_Edge aE1, aE2; |
763 | TopoDS_Face aFOff; |
764 | BOPTools_ListOfCoupleOfShape theLCSOff; |
765 | BOPTools_CoupleOfShape aCS1, aCS2; |
766 | // |
767 | BOPTools_AlgoTools::GetEdgeOnFace(theEdge, theFace1, aE1); |
768 | if (aE1.Orientation()==TopAbs_INTERNAL) { |
769 | aE2=aE1; |
770 | aE1.Orientation(TopAbs_FORWARD); |
771 | aE2.Orientation(TopAbs_REVERSED); |
772 | } |
773 | else if (theFace1==theFace2) { |
774 | aE2=aE1; |
775 | aE1.Orientation(TopAbs_FORWARD); |
776 | aE2.Orientation(TopAbs_REVERSED); |
777 | } |
778 | else { |
779 | BOPTools_AlgoTools::GetEdgeOnFace(theEdge, theFace2, aE2); |
780 | } |
781 | // |
782 | aCS1.SetShape1(theEdge); |
783 | aCS1.SetShape2(theFace); |
784 | theLCSOff.Append(aCS1); |
785 | // |
786 | aCS2.SetShape1(aE2); |
787 | aCS2.SetShape2(theFace2); |
788 | theLCSOff.Append(aCS2); |
789 | // |
744511c8 |
790 | bRet=GetFaceOff(aE1, theFace1, theLCSOff, aFOff, theContext); |
4e57c75e |
791 | // |
744511c8 |
792 | iRet=0; // theFace is not internal |
793 | if (theFace.IsEqual(aFOff)) { |
794 | // theFace is internal |
795 | iRet=1; |
796 | if (!bRet) { |
797 | // theFace seems to be internal |
798 | iRet=2; |
799 | } |
800 | } |
801 | return iRet; |
4e57c75e |
802 | } |
803 | //======================================================================= |
804 | //function : GetFaceOff |
805 | //purpose : |
806 | //======================================================================= |
744511c8 |
807 | Standard_Boolean BOPTools_AlgoTools::GetFaceOff |
808 | (const TopoDS_Edge& theE1, |
809 | const TopoDS_Face& theF1, |
810 | BOPTools_ListOfCoupleOfShape& theLCSOff, |
811 | TopoDS_Face& theFOff, |
1e143abb |
812 | Handle(IntTools_Context)& theContext) |
4e57c75e |
813 | { |
744511c8 |
814 | Standard_Boolean bRet; |
f56518cd |
815 | Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin, aDt3D; |
bb58e462 |
816 | Standard_Real aUmin, aUsup, aVmin, aVsup; |
4e57c75e |
817 | gp_Pnt aPn1, aPn2, aPx; |
df017cc9 |
818 | gp_Dir aDN1, aDN2, aDBF, aDBF2, aDTF; |
4e57c75e |
819 | gp_Vec aVTgt; |
df017cc9 |
820 | TopAbs_Orientation aOr; |
4e57c75e |
821 | Handle(Geom_Curve)aC3D; |
bb58e462 |
822 | Handle(Geom_Plane) aPL; |
4e57c75e |
823 | BOPTools_ListIteratorOfListOfCoupleOfShape aIt; |
bb58e462 |
824 | GeomAPI_ProjectPointOnSurf aProjPL; |
4e57c75e |
825 | // |
826 | aAngleMin=100.; |
827 | aTwoPI=M_PI+M_PI; |
828 | aC3D =BRep_Tool::Curve(theE1, aT1, aT2); |
4e57c75e |
829 | aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2); |
830 | aC3D->D0(aT, aPx); |
df017cc9 |
831 | // |
4e57c75e |
832 | BOPTools_AlgoTools2D::EdgeTangent(theE1, aT, aVTgt); |
df017cc9 |
833 | gp_Dir aDTgt(aVTgt), aDTgt2; |
834 | aOr = theE1.Orientation(); |
835 | // |
bb58e462 |
836 | aPL = new Geom_Plane(aPx, aDTgt); |
837 | aPL->Bounds(aUmin, aUsup, aVmin, aVsup); |
838 | aProjPL.Init(aPL, aUmin, aUsup, aVmin, aVsup); |
839 | // |
f56518cd |
840 | aDt3D = MinStep3D(theE1, theF1, theLCSOff, aPx); |
505abfb8 |
841 | GetFaceDir(theE1, theF1, aPx, aT, aDTgt, aDN1, aDBF, theContext, |
f56518cd |
842 | aProjPL, aDt3D); |
df017cc9 |
843 | // |
4e57c75e |
844 | aDTF=aDN1^aDBF; |
845 | // |
744511c8 |
846 | bRet=Standard_True; |
4e57c75e |
847 | aIt.Initialize(theLCSOff); |
848 | for (; aIt.More(); aIt.Next()) { |
849 | const BOPTools_CoupleOfShape& aCS=aIt.Value(); |
850 | const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&aCS.Shape1())); |
851 | const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCS.Shape2())); |
852 | // |
df017cc9 |
853 | aDTgt2 = (aE2.Orientation()==aOr) ? aDTgt : aDTgt.Reversed(); |
505abfb8 |
854 | GetFaceDir(aE2, aF2, aPx, aT, aDTgt2, aDN2, aDBF2, theContext, |
f56518cd |
855 | aProjPL, aDt3D); |
4e57c75e |
856 | //Angle |
857 | aAngle=AngleWithRef(aDBF, aDBF2, aDTF); |
858 | // |
859 | if(aAngle<0.) { |
860 | aAngle=aTwoPI+aAngle; |
861 | } |
df017cc9 |
862 | // |
863 | if (aAngle<Precision::Angular()) { |
864 | if (aF2==theF1) { |
865 | aAngle=M_PI; |
866 | } |
867 | else if (aF2.IsSame(theF1)) { |
868 | aAngle=aTwoPI; |
869 | } |
870 | } |
871 | // |
4e57c75e |
872 | if (aAngle<aAngleMin){ |
873 | aAngleMin=aAngle; |
874 | theFOff=aF2; |
875 | } |
744511c8 |
876 | else if (aAngle==aAngleMin) { |
877 | // the minimal angle can not be found |
878 | bRet=Standard_False; |
879 | } |
4e57c75e |
880 | } |
744511c8 |
881 | return bRet; |
4e57c75e |
882 | } |
883 | //======================================================================= |
884 | //function : GetEdgeOff |
885 | //purpose : |
886 | //======================================================================= |
bb58e462 |
887 | Standard_Boolean BOPTools_AlgoTools::GetEdgeOff(const TopoDS_Edge& theE1, |
888 | const TopoDS_Face& theF2, |
889 | TopoDS_Edge& theE2) |
4e57c75e |
890 | { |
891 | Standard_Boolean bFound; |
892 | TopAbs_Orientation aOr1, aOr1C, aOr2; |
893 | TopExp_Explorer anExp; |
894 | // |
895 | bFound=Standard_False; |
896 | aOr1=theE1.Orientation(); |
897 | aOr1C=TopAbs::Reverse(aOr1); |
898 | // |
899 | anExp.Init(theF2, TopAbs_EDGE); |
900 | for (; anExp.More(); anExp.Next()) { |
901 | const TopoDS_Edge& aEF2=(*(TopoDS_Edge*)(&anExp.Current())); |
902 | if (aEF2.IsSame(theE1)) { |
903 | aOr2=aEF2.Orientation(); |
904 | if (aOr2==aOr1C) { |
905 | theE2=aEF2; |
906 | bFound=!bFound; |
907 | return bFound; |
908 | } |
909 | } |
910 | } |
911 | return bFound; |
912 | } |
913 | |
914 | //======================================================================= |
915 | //function : AreFacesSameDomain |
916 | //purpose : |
917 | //======================================================================= |
505abfb8 |
918 | Standard_Boolean BOPTools_AlgoTools::AreFacesSameDomain |
919 | (const TopoDS_Face& theF1, |
920 | const TopoDS_Face& theF2, |
1e143abb |
921 | Handle(IntTools_Context)& theContext) |
4e57c75e |
922 | { |
923 | Standard_Boolean bFlag; |
e656bcbe |
924 | Standard_Integer iErr; |
4e57c75e |
925 | Standard_Real aTolF1, aTolF2, aTol; |
926 | gp_Pnt2d aP2D; |
927 | gp_Pnt aP; |
928 | TopoDS_Face aF1, aF2; |
929 | TopoDS_Edge aE1; |
930 | TopExp_Explorer aExp; |
931 | // |
932 | bFlag=Standard_False; |
933 | // |
934 | aF1=theF1; |
935 | aF1.Orientation(TopAbs_FORWARD); |
936 | aF2=theF2; |
937 | aF2.Orientation(TopAbs_FORWARD); |
938 | // |
939 | aTolF1=BRep_Tool::Tolerance(aF1); |
940 | // 1 |
4e57c75e |
941 | aExp.Init(aF1, TopAbs_EDGE); |
942 | for (; aExp.More(); aExp.Next()) { |
943 | aE1=(*(TopoDS_Edge*)(&aExp.Current())); |
944 | if (!BRep_Tool::Degenerated(aE1)) { |
4e57c75e |
945 | Standard_Real aTolE = BRep_Tool::Tolerance(aE1); |
946 | aTolF1 = (aTolE > aTolF1) ? aTolE : aTolF1; |
947 | } |
948 | } |
4e57c75e |
949 | // 2 |
950 | aTolF2=BRep_Tool::Tolerance(aF2); |
951 | aTol=aTolF1+aTolF2; |
952 | // |
505abfb8 |
953 | iErr = BOPTools_AlgoTools3D::PointInFace(aF1, aP, aP2D, |
954 | theContext); |
e656bcbe |
955 | if (!iErr) { |
956 | bFlag=theContext->IsValidPointForFace(aP, aF2, aTol); |
957 | } |
4e57c75e |
958 | // |
959 | return bFlag; |
960 | } |
961 | |
962 | //======================================================================= |
963 | //function : CheckSameGeom |
964 | //purpose : |
965 | //======================================================================= |
505abfb8 |
966 | Standard_Boolean BOPTools_AlgoTools::CheckSameGeom |
967 | (const TopoDS_Face& theF1, |
968 | const TopoDS_Face& theF2, |
1e143abb |
969 | Handle(IntTools_Context)& theContext) |
4e57c75e |
970 | { |
971 | Standard_Boolean bRet; |
972 | Standard_Real aTolF1, aTolF2, aTol; |
973 | gp_Pnt2d aP2D; |
974 | gp_Pnt aP; |
975 | TopExp_Explorer aExp; |
976 | // |
977 | bRet=Standard_False; |
978 | aExp.Init(theF1, TopAbs_EDGE); |
979 | for (; aExp.More(); aExp.Next()) { |
980 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); |
981 | if (!BRep_Tool::Degenerated(aE)) { |
982 | aTolF1=BRep_Tool::Tolerance(theF1); |
983 | aTolF2=BRep_Tool::Tolerance(theF2); |
984 | aTol=aTolF1+aTolF2; |
985 | BOPTools_AlgoTools3D::PointNearEdge(aE, theF1, aP2D, aP, theContext); |
986 | bRet=theContext->IsValidPointForFace(aP, theF2, aTol); |
987 | break; |
988 | } |
989 | } |
990 | return bRet; |
991 | } |
992 | //======================================================================= |
993 | // function: Sense |
994 | // purpose: |
995 | //======================================================================= |
bb58e462 |
996 | Standard_Integer BOPTools_AlgoTools::Sense (const TopoDS_Face& theF1, |
997 | const TopoDS_Face& theF2) |
4e57c75e |
998 | { |
999 | Standard_Integer iSense=0; |
1000 | gp_Dir aDNF1, aDNF2; |
1001 | TopoDS_Edge aE1, aE2; |
1002 | TopExp_Explorer aExp; |
1003 | // |
1004 | aExp.Init(theF1, TopAbs_EDGE); |
1005 | for (; aExp.More(); aExp.Next()) { |
1006 | aE1=(*(TopoDS_Edge*)(&aExp.Current())); |
1007 | if (!BRep_Tool::Degenerated(aE1)) { |
1008 | if (!BRep_Tool::IsClosed(aE1, theF1)) { |
1009 | break; |
1010 | } |
1011 | } |
1012 | } |
1013 | // |
1014 | aExp.Init(theF2, TopAbs_EDGE); |
1015 | for (; aExp.More(); aExp.Next()) { |
1016 | aE2=(*(TopoDS_Edge*)(&aExp.Current())); |
1017 | if (!BRep_Tool::Degenerated(aE2)) { |
1018 | if (!BRep_Tool::IsClosed(aE2, theF2)) { |
1019 | if (aE2.IsSame(aE1)) { |
1020 | iSense=1; |
1021 | break; |
1022 | } |
1023 | } |
1024 | } |
1025 | } |
1026 | // |
1027 | if (!iSense) { |
1028 | return iSense; |
1029 | } |
1030 | // |
1031 | BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1); |
1032 | BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2); |
1033 | // |
1034 | iSense=BOPTools_AlgoTools3D::SenseFlag(aDNF1, aDNF2); |
1035 | // |
1036 | return iSense; |
1037 | } |
1038 | //======================================================================= |
1039 | // function: IsSplitToReverse |
1040 | // purpose: |
1041 | //======================================================================= |
505abfb8 |
1042 | Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse |
1043 | (const TopoDS_Shape& theSp, |
1044 | const TopoDS_Shape& theSr, |
1e143abb |
1045 | Handle(IntTools_Context)& theContext) |
4e57c75e |
1046 | { |
1047 | Standard_Boolean bRet; |
1048 | TopAbs_ShapeEnum aType; |
1049 | // |
1050 | bRet=Standard_False; |
1051 | // |
1052 | aType=theSp.ShapeType(); |
1053 | switch (aType) { |
1054 | case TopAbs_EDGE: { |
1055 | const TopoDS_Edge& aESp=(*(TopoDS_Edge*)(&theSp)); |
1056 | const TopoDS_Edge& aESr=(*(TopoDS_Edge*)(&theSr)); |
1057 | bRet=BOPTools_AlgoTools::IsSplitToReverse(aESp, aESr, theContext); |
1058 | } |
1059 | break; |
1060 | // |
1061 | case TopAbs_FACE: { |
1062 | const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&theSp)); |
1063 | const TopoDS_Face& aFSr=(*(TopoDS_Face*)(&theSr)); |
1064 | bRet=BOPTools_AlgoTools::IsSplitToReverse(aFSp, aFSr, theContext); |
1065 | } |
1066 | break; |
1067 | // |
1068 | default: |
1069 | break; |
1070 | } |
1071 | return bRet; |
1072 | } |
1073 | //======================================================================= |
1074 | //function :IsSplitToReverse |
1075 | //purpose : |
1076 | //======================================================================= |
505abfb8 |
1077 | Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse |
1078 | (const TopoDS_Face& theFSp, |
1079 | const TopoDS_Face& theFSr, |
1e143abb |
1080 | Handle(IntTools_Context)& theContext) |
4e57c75e |
1081 | { |
1082 | Standard_Boolean bRet, bFound, bInFace; |
1083 | Standard_Real aT1, aT2, aT, aU, aV, aScPr; |
1084 | gp_Pnt aPFSp, aPFSr; |
1085 | gp_Dir aDNFSp; |
1086 | gp_Vec aD1U, aD1V; |
1087 | Handle(Geom_Surface) aSr, aSp; |
1088 | TopAbs_Orientation aOrSr, aOrSp; |
1089 | TopExp_Explorer anExp; |
1090 | TopoDS_Edge aESp; |
1091 | // |
1092 | bRet=Standard_False; |
1093 | // |
1094 | aSr=BRep_Tool::Surface(theFSr); |
1095 | aSp=BRep_Tool::Surface(theFSp); |
1096 | if (aSr==aSp) { |
1097 | aOrSr=theFSr.Orientation(); |
1098 | aOrSp=theFSp.Orientation(); |
1099 | bRet=(aOrSr!=aOrSp); |
1100 | return bRet; |
1101 | } |
1102 | // |
1103 | bFound=Standard_False; |
1104 | anExp.Init(theFSp, TopAbs_EDGE); |
1105 | for (; anExp.More(); anExp.Next()) { |
1106 | aESp=(*(TopoDS_Edge*)(&anExp.Current())); |
1107 | if (!BRep_Tool::Degenerated(aESp)) { |
1108 | if (!BRep_Tool::IsClosed(aESp, theFSp)) { |
1109 | bFound=!bFound; |
1110 | break; |
1111 | } |
1112 | } |
1113 | } |
1114 | if (!bFound) { |
1115 | Standard_Boolean bFlag; |
1116 | Standard_Integer iErr; |
1117 | gp_Pnt2d aP2DFSp; |
1118 | // |
505abfb8 |
1119 | iErr=BOPTools_AlgoTools3D::PointInFace(theFSp, aPFSp, aP2DFSp, |
1120 | theContext); |
4e57c75e |
1121 | if (iErr) { |
1122 | return bRet; |
1123 | } |
1124 | // |
1125 | aP2DFSp.Coord(aU, aV); |
1126 | bFlag=BOPTools_AlgoTools3D::GetNormalToSurface(aSp, aU, aV, aDNFSp); |
1127 | if (!bFlag) { |
1128 | return bRet; |
1129 | } |
5b98e25d |
1130 | // |
1131 | if (theFSp.Orientation()==TopAbs_REVERSED){ |
1132 | aDNFSp.Reverse(); |
1133 | } |
4e57c75e |
1134 | } |
1135 | else { |
1136 | BRep_Tool::Range(aESp, aT1, aT2); |
1137 | aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2); |
505abfb8 |
1138 | BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT, |
1139 | aPFSp, aDNFSp, |
1140 | theContext); |
4e57c75e |
1141 | } |
1142 | // |
1143 | // Parts of theContext->ComputeVS(..) |
1144 | GeomAPI_ProjectPointOnSurf& aProjector=theContext->ProjPS(theFSr); |
1145 | aProjector.Perform(aPFSp); |
1146 | if (!aProjector.IsDone()) { |
1147 | return bRet; |
1148 | } |
1149 | // |
1150 | aProjector.LowerDistanceParameters(aU, aV); |
1151 | gp_Pnt2d aP2D(aU, aV); |
1152 | bInFace=theContext->IsPointInFace (theFSr, aP2D); |
1153 | if (!bInFace) { |
1154 | return bRet; |
1155 | } |
1156 | // |
1157 | aSr->D1(aU, aV, aPFSr, aD1U, aD1V); |
1158 | gp_Dir aDD1U(aD1U); |
1159 | gp_Dir aDD1V(aD1V); |
1160 | gp_Dir aDNFSr=aDD1U^aDD1V; |
1161 | if (theFSr.Orientation()==TopAbs_REVERSED){ |
1162 | aDNFSr.Reverse(); |
1163 | } |
1164 | // |
1165 | aScPr=aDNFSp*aDNFSr; |
1166 | bRet=(aScPr<0.); |
1167 | // |
1168 | return bRet; |
1169 | } |
1170 | //======================================================================= |
1171 | //function :IsSplitToReverse |
1172 | //purpose : |
1173 | //======================================================================= |
505abfb8 |
1174 | Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse |
1175 | (const TopoDS_Edge& aEF1, |
1176 | const TopoDS_Edge& aEF2, |
1e143abb |
1177 | Handle(IntTools_Context)& theContext) |
4e57c75e |
1178 | { |
1179 | Standard_Boolean bRet, bIsDegenerated; |
1180 | // |
1181 | bRet=Standard_False; |
1182 | bIsDegenerated=(BRep_Tool::Degenerated(aEF1) || |
1183 | BRep_Tool::Degenerated(aEF2)); |
1184 | if (bIsDegenerated) { |
1185 | return bRet; |
1186 | } |
1187 | // |
1188 | Standard_Real a, b; |
1189 | TopAbs_Orientation aOrE, aOrSp; |
1190 | Handle(Geom_Curve)aC1, aC2; |
1191 | // |
1192 | aC2=BRep_Tool::Curve(aEF2, a, b); |
1193 | aC1=BRep_Tool::Curve(aEF1, a, b); |
1194 | // |
1195 | if (aC1==aC2) { |
1196 | aOrE=aEF2.Orientation(); |
1197 | aOrSp=aEF1.Orientation(); |
1198 | bRet=(aOrE!=aOrSp); |
1199 | return bRet; |
1200 | } |
1201 | // |
1202 | Standard_Real aT1, aT2, aScPr; |
1203 | gp_Vec aV1, aV2; |
1204 | gp_Pnt aP; |
1205 | // |
1206 | aT1=BOPTools_AlgoTools2D::IntermediatePoint(a, b); |
1207 | aC1->D0(aT1, aP); |
1208 | BOPTools_AlgoTools2D::EdgeTangent(aEF1, aT1, aV1); |
1209 | gp_Dir aDT1(aV1); |
1210 | // |
1211 | theContext->ProjectPointOnEdge(aP, aEF2, aT2); |
1212 | // |
1213 | BOPTools_AlgoTools2D::EdgeTangent(aEF2, aT2, aV2); |
1214 | gp_Dir aDT2(aV2); |
1215 | // |
1216 | aScPr=aDT1*aDT2; |
1217 | bRet=(aScPr<0.); |
1218 | // |
1219 | return bRet; |
1220 | } |
1221 | |
1222 | //======================================================================= |
1223 | //function : IsHole |
1224 | //purpose : |
1225 | //======================================================================= |
bb58e462 |
1226 | Standard_Boolean BOPTools_AlgoTools::IsHole(const TopoDS_Shape& aW, |
1227 | const TopoDS_Shape& aFace) |
4e57c75e |
1228 | { |
1229 | Standard_Boolean bIsHole; |
1230 | Standard_Integer i, aNbS; |
1231 | Standard_Real aT1, aT2, aS; |
96a95605 |
1232 | Standard_Real aU1, aU, dU; |
4e57c75e |
1233 | Standard_Real aX1, aY1, aX0, aY0; |
1234 | TopAbs_Orientation aOr; |
1235 | |
1236 | gp_Pnt2d aP2D0, aP2D1; |
1237 | Handle(Geom2d_Curve) aC2D; |
1238 | TopoDS_Face aF, aFF; |
1239 | TopoDS_Iterator aItW; |
1240 | // |
1241 | bIsHole=Standard_False; |
1242 | // |
1243 | aF=(*(TopoDS_Face *)(&aFace)); |
1244 | aFF=aF; |
1245 | aFF.Orientation(TopAbs_FORWARD); |
1246 | // |
1247 | aS=0.; |
1248 | aItW.Initialize(aW); |
1249 | for (; aItW.More(); aItW.Next()) { |
1250 | const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aItW.Value())); |
1251 | aOr=aE.Orientation(); |
1252 | if (!(aOr==TopAbs_FORWARD || |
1253 | aOr==TopAbs_REVERSED)) { |
1254 | continue; |
1255 | } |
1256 | // |
1257 | aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2); |
1258 | if (aC2D.IsNull()) { |
1259 | break; //xx |
1260 | } |
1261 | // |
1262 | BRepAdaptor_Curve2d aBAC2D(aE, aFF); |
1263 | aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D); |
1264 | if (aNbS>2) { |
1265 | aNbS*=4; |
1266 | } |
1267 | // |
1268 | dU=(aT2-aT1)/(Standard_Real)(aNbS-1); |
1269 | aU =aT1; |
1270 | aU1=aT1; |
4e57c75e |
1271 | if (aOr==TopAbs_REVERSED) { |
1272 | aU =aT2; |
1273 | aU1=aT2; |
4e57c75e |
1274 | dU=-dU; |
1275 | } |
1276 | // |
1277 | aC2D->D0(aU, aP2D0); |
1278 | for(i=2; i<=aNbS; i++) { |
1279 | aU=aU1+(i-1)*dU; |
1280 | aC2D->D0(aU, aP2D1); |
1281 | aP2D0.Coord(aX0, aY0); |
1282 | aP2D1.Coord(aX1, aY1); |
1283 | // |
1284 | aS=aS+(aY0+aY1)*(aX1-aX0); |
1285 | // |
1286 | aP2D0=aP2D1; |
1287 | } |
1288 | }//for (; aItW.More(); aItW.Next()) { |
1289 | bIsHole=(aS>0.); |
1290 | return bIsHole; |
1291 | } |
1292 | |
1293 | //======================================================================= |
1294 | // function: MakeContainer |
1295 | // purpose: |
1296 | //======================================================================= |
bb58e462 |
1297 | void BOPTools_AlgoTools::MakeContainer(const TopAbs_ShapeEnum theType, |
1298 | TopoDS_Shape& theC) |
4e57c75e |
1299 | { |
1300 | BRep_Builder aBB; |
1301 | // |
1302 | switch(theType) { |
1303 | case TopAbs_COMPOUND:{ |
1304 | TopoDS_Compound aC; |
1305 | aBB.MakeCompound(aC); |
1306 | theC=aC; |
1307 | } |
1308 | break; |
1309 | // |
1310 | case TopAbs_COMPSOLID:{ |
1311 | TopoDS_CompSolid aCS; |
1312 | aBB.MakeCompSolid(aCS); |
1313 | theC=aCS; |
1314 | } |
1315 | break; |
1316 | // |
1317 | case TopAbs_SOLID:{ |
1318 | TopoDS_Solid aSolid; |
1319 | aBB.MakeSolid(aSolid); |
1320 | theC=aSolid; |
1321 | } |
1322 | break; |
1323 | // |
1324 | // |
1325 | case TopAbs_SHELL:{ |
1326 | TopoDS_Shell aShell; |
1327 | aBB.MakeShell(aShell); |
1328 | theC=aShell; |
1329 | } |
1330 | break; |
1331 | // |
1332 | case TopAbs_WIRE: { |
1333 | TopoDS_Wire aWire; |
1334 | aBB.MakeWire(aWire); |
1335 | theC=aWire; |
1336 | } |
1337 | break; |
1338 | // |
1339 | default: |
1340 | break; |
1341 | } |
1342 | } |
1343 | //======================================================================= |
1344 | // function: MakePCurve |
1345 | // purpose: |
1346 | //======================================================================= |
bb58e462 |
1347 | void BOPTools_AlgoTools::MakePCurve(const TopoDS_Edge& aE, |
1348 | const TopoDS_Face& aF1, |
1349 | const TopoDS_Face& aF2, |
1350 | const IntTools_Curve& aIC, |
1351 | const Standard_Boolean bPC1, |
1352 | const Standard_Boolean bPC2) |
4e57c75e |
1353 | |
1354 | { |
1355 | Standard_Integer i; |
1356 | Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol; |
1357 | Handle(Geom2d_Curve) aC2D, aC2DA, aC2Dx1; |
1358 | TopoDS_Face aFFWD; |
1359 | BRep_Builder aBB; |
1360 | Standard_Boolean bPC; |
1361 | // |
1362 | aTolE=BRep_Tool::Tolerance(aE); |
1363 | // |
1364 | const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aT1, aT2); |
505abfb8 |
1365 | Handle(Geom_TrimmedCurve)aC3DETrim= |
1366 | new Geom_TrimmedCurve(aC3DE, aT1, aT2); |
4e57c75e |
1367 | // |
1368 | for (i=0; i<2; ++i) { |
1369 | bPC = !i ? bPC1 : bPC2; |
1370 | if (!bPC) { |
1371 | continue; |
1372 | } |
1373 | // |
1374 | if (!i) { |
1375 | aFFWD=aF1; |
1376 | aC2Dx1=aIC.FirstCurve2d(); |
1377 | } |
1378 | else { |
1379 | aFFWD=aF2; |
1380 | aC2Dx1=aIC.SecondCurve2d(); |
1381 | } |
1382 | // |
1383 | aFFWD.Orientation(TopAbs_FORWARD); |
1384 | // |
1385 | aC2D=aC2Dx1; |
1386 | if (aC2D.IsNull()) { |
1387 | BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aFFWD); |
1388 | BOPTools_AlgoTools2D::CurveOnSurface(aE, aFFWD, aC2D, |
1389 | aOutFirst, aOutLast, |
1390 | aOutTol); |
1391 | } |
1392 | // |
1393 | if (aC3DE->IsPeriodic()) { |
505abfb8 |
1394 | BOPTools_AlgoTools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2, aC2D, |
1395 | aC2DA); |
4e57c75e |
1396 | } |
1397 | else { |
505abfb8 |
1398 | BOPTools_AlgoTools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, |
1399 | aC2DA); |
4e57c75e |
1400 | } |
1401 | // |
1402 | aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE); |
1403 | //BRepLib::SameParameter(aE); |
1404 | } |
1405 | BRepLib::SameParameter(aE); |
1406 | } |
1407 | //======================================================================= |
1408 | // function: MakeEdge |
1409 | // purpose: |
1410 | //======================================================================= |
bb58e462 |
1411 | void BOPTools_AlgoTools::MakeEdge(const IntTools_Curve& theIC, |
1412 | const TopoDS_Vertex& theV1, |
1413 | const Standard_Real theT1, |
1414 | const TopoDS_Vertex& theV2, |
1415 | const Standard_Real theT2, |
1416 | const Standard_Real theTolR3D, |
1417 | TopoDS_Edge& theE) |
4e57c75e |
1418 | { |
1419 | Standard_Real aTolV; |
1420 | BRep_Builder aBB; |
1421 | // |
505abfb8 |
1422 | BOPTools_AlgoTools::MakeSectEdge (theIC, theV1, theT1, theV2, theT2, |
1423 | theE); |
4e57c75e |
1424 | // |
1425 | aBB.UpdateEdge(theE, theTolR3D); |
1426 | // |
1427 | aTolV=BRep_Tool::Tolerance(theV1); |
1428 | if (aTolV<theTolR3D) { |
1429 | aBB.UpdateVertex(theV1, theTolR3D); |
1430 | } |
1431 | // |
1432 | aTolV=BRep_Tool::Tolerance(theV2); |
1433 | if (aTolV<theTolR3D) { |
1434 | aBB.UpdateVertex(theV2, theTolR3D); |
1435 | } |
1436 | } |
1437 | //======================================================================= |
1438 | // function: ComputeVV |
1439 | // purpose: |
1440 | //======================================================================= |
bb58e462 |
1441 | Standard_Integer BOPTools_AlgoTools::ComputeVV(const TopoDS_Vertex& aV1, |
1442 | const gp_Pnt& aP2, |
1443 | const Standard_Real aTolP2) |
4e57c75e |
1444 | { |
1445 | Standard_Real aTolV1, aTolSum, aTolSum2, aD2; |
1446 | gp_Pnt aP1; |
1447 | // |
1448 | aTolV1=BRep_Tool::Tolerance(aV1); |
1449 | |
1450 | aTolSum=aTolV1+aTolP2; |
1451 | aTolSum2=aTolSum*aTolSum; |
1452 | // |
1453 | aP1=BRep_Tool::Pnt(aV1); |
1454 | // |
1455 | aD2=aP1.SquareDistance(aP2); |
1456 | if (aD2>aTolSum2) { |
1457 | return 1; |
1458 | } |
1459 | return 0; |
1460 | } |
1461 | //======================================================================= |
1462 | // function: ComputeVV |
1463 | // purpose: |
1464 | //======================================================================= |
bb58e462 |
1465 | Standard_Integer BOPTools_AlgoTools::ComputeVV(const TopoDS_Vertex& aV1, |
1466 | const TopoDS_Vertex& aV2) |
4e57c75e |
1467 | { |
1468 | Standard_Real aTolV1, aTolV2, aTolSum, aTolSum2, aD2; |
1469 | gp_Pnt aP1, aP2; |
1470 | // |
1471 | aTolV1=BRep_Tool::Tolerance(aV1); |
1472 | aTolV2=BRep_Tool::Tolerance(aV2); |
1473 | aTolSum=aTolV1+aTolV2; |
1474 | aTolSum2=aTolSum*aTolSum; |
1475 | // |
1476 | aP1=BRep_Tool::Pnt(aV1); |
1477 | aP2=BRep_Tool::Pnt(aV2); |
1478 | // |
1479 | aD2=aP1.SquareDistance(aP2); |
1480 | if (aD2>aTolSum2) { |
1481 | return 1; |
1482 | } |
1483 | return 0; |
1484 | } |
1485 | //======================================================================= |
1486 | // function: MakeVertex |
1487 | // purpose : |
1488 | //======================================================================= |
bb58e462 |
1489 | void BOPTools_AlgoTools::MakeVertex(BOPCol_ListOfShape& aLV, |
1490 | TopoDS_Vertex& aVnew) |
4e57c75e |
1491 | { |
1492 | Standard_Integer aNb; |
1493 | Standard_Real aTi, aDi, aDmax; |
1494 | gp_Pnt aPi, aP; |
1495 | gp_XYZ aXYZ(0.,0.,0.), aXYZi; |
1496 | BOPCol_ListIteratorOfListOfShape aIt; |
1497 | // |
1498 | aNb=aLV.Extent(); |
1499 | if (aNb) { |
1500 | aIt.Initialize(aLV); |
1501 | for (; aIt.More(); aIt.Next()) { |
1502 | TopoDS_Vertex& aVi=*((TopoDS_Vertex*)(&aIt.Value())); |
1503 | aPi=BRep_Tool::Pnt(aVi); |
1504 | aXYZi=aPi.XYZ(); |
1505 | aXYZ=aXYZ+aXYZi; |
1506 | } |
1507 | // |
1508 | aXYZ.Divide((Standard_Real)aNb); |
1509 | aP.SetXYZ(aXYZ); |
1510 | // |
1511 | aDmax=-1.; |
1512 | aIt.Initialize(aLV); |
1513 | for (; aIt.More(); aIt.Next()) { |
1514 | TopoDS_Vertex& aVi=*((TopoDS_Vertex*)(&aIt.Value())); |
1515 | aPi=BRep_Tool::Pnt(aVi); |
1516 | aTi=BRep_Tool::Tolerance(aVi); |
1517 | aDi=aP.SquareDistance(aPi); |
4889b44e |
1518 | aDi=sqrt(aDi); |
4e57c75e |
1519 | aDi=aDi+aTi; |
1520 | if (aDi > aDmax) { |
1521 | aDmax=aDi; |
1522 | } |
1523 | } |
1524 | // |
1525 | BRep_Builder aBB; |
1526 | aBB.MakeVertex (aVnew, aP, aDmax); |
1527 | } |
1528 | } |
1529 | //======================================================================= |
1530 | //function : GetEdgeOnFace |
1531 | //purpose : |
1532 | //======================================================================= |
505abfb8 |
1533 | Standard_Boolean BOPTools_AlgoTools::GetEdgeOnFace |
1534 | (const TopoDS_Edge& theE1, |
1535 | const TopoDS_Face& theF2, |
1536 | TopoDS_Edge& theE2) |
4e57c75e |
1537 | { |
1538 | Standard_Boolean bFound; |
1539 | TopoDS_Iterator aItF, aItW; |
1540 | // |
1541 | bFound=Standard_False; |
1542 | // |
1543 | aItF.Initialize(theF2); |
1544 | for (; aItF.More(); aItF.Next()) { |
1545 | const TopoDS_Shape& aW=aItF.Value(); |
1546 | aItW.Initialize(aW); |
1547 | for (; aItW.More(); aItW.Next()) { |
1548 | const TopoDS_Shape& aE=aItW.Value(); |
1549 | if (aE.IsSame(theE1)) { |
1550 | theE2=(*(TopoDS_Edge*)(&aE)); |
1551 | bFound=!bFound; |
1552 | return bFound; |
1553 | } |
1554 | } |
1555 | } |
1556 | return bFound; |
1557 | } |
1558 | //======================================================================= |
1559 | //function : FindFacePairs |
1560 | //purpose : |
1561 | //======================================================================= |
1562 | Standard_Boolean FindFacePairs (const TopoDS_Edge& theE, |
1563 | const BOPCol_ListOfShape& thLF, |
1564 | BOPTools_ListOfCoupleOfShape& theLCFF, |
1e143abb |
1565 | Handle(IntTools_Context)& theContext) |
4e57c75e |
1566 | { |
1567 | Standard_Boolean bFound; |
1568 | Standard_Integer i, aNbCEF; |
1d47d8d0 |
1569 | TopAbs_Orientation aOr, aOrC = TopAbs_FORWARD; |
4e57c75e |
1570 | BOPCol_MapOfShape aMFP; |
1571 | TopoDS_Face aF1, aF2; |
1572 | TopoDS_Edge aEL, aE1; |
1573 | BOPCol_ListIteratorOfListOfShape aItLF; |
1574 | BOPTools_CoupleOfShape aCEF, aCFF; |
1575 | BOPTools_ListOfCoupleOfShape aLCEF, aLCEFx; |
1576 | BOPTools_ListIteratorOfListOfCoupleOfShape aIt; |
1577 | // |
1578 | bFound=Standard_True; |
1579 | // |
1580 | // Preface aLCEF |
1581 | aItLF.Initialize(thLF); |
1582 | for (; aItLF.More(); aItLF.Next()) { |
1583 | const TopoDS_Face& aFL=(*(TopoDS_Face*)(&aItLF.Value())); |
1584 | // |
1585 | bFound=BOPTools_AlgoTools::GetEdgeOnFace(theE, aFL, aEL); |
1586 | if (!bFound) { |
1587 | return bFound; // it can not be so |
1588 | } |
1589 | // |
1590 | aCEF.SetShape1(aEL); |
1591 | aCEF.SetShape2(aFL); |
1592 | aLCEF.Append(aCEF); |
1593 | } |
1594 | // |
1595 | aNbCEF=aLCEF.Extent(); |
1596 | while(aNbCEF) { |
1597 | // |
1598 | // aLCEFx |
1599 | aLCEFx.Clear(); |
1600 | aIt.Initialize(aLCEF); |
1601 | for (i=0; aIt.More(); aIt.Next(), ++i) { |
1602 | const BOPTools_CoupleOfShape& aCSx=aIt.Value(); |
1603 | const TopoDS_Shape& aEx=aCSx.Shape1(); |
1604 | const TopoDS_Shape& aFx=aCSx.Shape2(); |
1605 | // |
1606 | aOr=aEx.Orientation(); |
1607 | // |
1608 | if (!i) { |
1609 | aOrC=TopAbs::Reverse(aOr); |
1610 | aE1=(*(TopoDS_Edge*)(&aEx)); |
1611 | aF1=(*(TopoDS_Face*)(&aFx)); |
1612 | aMFP.Add(aFx); |
1613 | continue; |
1614 | } |
1615 | // |
1616 | if (aOr==aOrC) { |
1617 | aLCEFx.Append(aCSx); |
1618 | aMFP.Add(aFx); |
1619 | } |
1620 | } |
1621 | // |
1622 | // F2 |
1623 | BOPTools_AlgoTools::GetFaceOff(aE1, aF1, aLCEFx, aF2, theContext); |
1624 | // |
1625 | aCFF.SetShape1(aF1); |
1626 | aCFF.SetShape2(aF2); |
1627 | theLCFF.Append(aCFF); |
1628 | // |
1629 | aMFP.Add(aF1); |
1630 | aMFP.Add(aF2); |
1631 | // |
1632 | // refine aLCEF |
1633 | aLCEFx.Clear(); |
1634 | aLCEFx=aLCEF; |
1635 | aLCEF.Clear(); |
1636 | aIt.Initialize(aLCEFx); |
1637 | for (; aIt.More(); aIt.Next()) { |
1638 | const BOPTools_CoupleOfShape& aCSx=aIt.Value(); |
1639 | const TopoDS_Shape& aFx=aCSx.Shape2(); |
1640 | if (!aMFP.Contains(aFx)) { |
1641 | aLCEF.Append(aCSx); |
1642 | } |
1643 | } |
1644 | // |
1645 | aNbCEF=aLCEF.Extent(); |
1646 | }//while(aNbCEF) { |
1647 | // |
1648 | return bFound; |
1649 | } |
1650 | //======================================================================= |
1651 | //function : AngleWithRef |
1652 | //purpose : |
1653 | //======================================================================= |
1654 | Standard_Real AngleWithRef(const gp_Dir& theD1, |
1655 | const gp_Dir& theD2, |
1656 | const gp_Dir& theDRef) |
1657 | { |
1658 | Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr; |
1659 | gp_XYZ aXYZ; |
1660 | // |
1661 | aHalfPI=0.5*M_PI; |
1662 | // |
1663 | const gp_XYZ& aXYZ1=theD1.XYZ(); |
1664 | const gp_XYZ& aXYZ2=theD2.XYZ(); |
1665 | aXYZ=aXYZ1.Crossed(aXYZ2); |
1666 | aSinus=aXYZ.Modulus(); |
1667 | aCosinus=theD1*theD2; |
1668 | // |
1669 | aBeta=0.; |
1670 | if (aSinus>=0.) { |
1671 | aBeta=aHalfPI*(1.-aCosinus); |
1672 | } |
1673 | else { |
1674 | aBeta=2.*M_PI-aHalfPI*(3.+aCosinus); |
1675 | } |
1676 | // |
1677 | aScPr=aXYZ.Dot(theDRef.XYZ()); |
1678 | if (aScPr<0.) { |
1679 | aBeta=-aBeta; |
1680 | } |
1681 | return aBeta; |
1682 | } |
4e57c75e |
1683 | //======================================================================= |
1684 | // function: IsBlockInOnFace |
1685 | // purpose: |
1686 | //======================================================================= |
505abfb8 |
1687 | Standard_Boolean BOPTools_AlgoTools::IsBlockInOnFace |
1688 | (const IntTools_Range& aShrR, |
1689 | const TopoDS_Face& aF, |
1690 | const TopoDS_Edge& aE1, |
1e143abb |
1691 | Handle(IntTools_Context)& aContext) |
4e57c75e |
1692 | { |
1693 | Standard_Boolean bFlag; |
1694 | Standard_Real f1, l1, ULD, VLD; |
1695 | gp_Pnt2d aP2D; |
1696 | gp_Pnt aP11, aP12; |
1697 | // |
1698 | aShrR.Range(f1, l1); |
1699 | Standard_Real dt=0.0075, k;//dt=0.001, k; |
1700 | k=dt*(l1-f1); |
1701 | f1=f1+k; |
1702 | l1=l1-k; |
1703 | // |
1704 | // Treatment P11 |
1705 | BOPTools_AlgoTools::PointOnEdge(aE1, f1, aP11); |
1706 | // |
1707 | GeomAPI_ProjectPointOnSurf& aProjector=aContext->ProjPS(aF); |
1708 | aProjector.Perform(aP11); |
1709 | // |
1710 | bFlag=aProjector.IsDone(); |
1711 | if (!bFlag) { |
1712 | return bFlag; |
1713 | } |
1714 | |
1715 | aProjector.LowerDistanceParameters(ULD, VLD); |
1716 | aP2D.SetCoord(ULD, VLD); |
1717 | // |
1718 | bFlag=aContext->IsPointInOnFace (aF, aP2D); |
1719 | // |
1720 | if (!bFlag) { |
1721 | return bFlag; |
1722 | } |
1723 | // |
1724 | // Treatment P12 |
1725 | BOPTools_AlgoTools::PointOnEdge(aE1, l1, aP12); |
1726 | // |
1727 | aProjector.Perform(aP12); |
1728 | // |
1729 | bFlag=aProjector.IsDone(); |
1730 | if (!bFlag) { |
1731 | return bFlag; |
1732 | } |
1733 | |
1734 | aProjector.LowerDistanceParameters(ULD, VLD); |
1735 | aP2D.SetCoord(ULD, VLD); |
1736 | // |
1737 | bFlag=aContext->IsPointInOnFace (aF, aP2D); |
1738 | // |
1739 | if (!bFlag) { |
1740 | return bFlag; |
1741 | } |
1742 | // |
1743 | // Treatment intemediate |
1744 | Standard_Real m1, aTolF, aTolE, aTol, aDist; |
1745 | m1=IntTools_Tools::IntermediatePoint(f1, l1); |
1746 | BOPTools_AlgoTools::PointOnEdge(aE1, m1, aP12); |
1747 | // |
1748 | aProjector.Perform(aP12); |
1749 | // |
1750 | bFlag=aProjector.IsDone(); |
1751 | if (!bFlag) { |
1752 | return bFlag; |
1753 | } |
1754 | // |
1755 | aTolE=BRep_Tool::Tolerance(aE1); |
1756 | aTolF=BRep_Tool::Tolerance(aF); |
1757 | aTol=aTolE+aTolF; |
1758 | aDist=aProjector.LowerDistance(); |
1759 | if (aDist > aTol){ |
1760 | return Standard_False; |
1761 | } |
1762 | |
1763 | aProjector.LowerDistanceParameters(ULD, VLD); |
1764 | aP2D.SetCoord(ULD, VLD); |
1765 | // |
1766 | bFlag=aContext->IsPointInOnFace (aF, aP2D); |
1767 | // |
1768 | if (!bFlag) { |
1769 | return bFlag; |
1770 | } |
1771 | return bFlag; |
1772 | } |
1773 | |
4e57c75e |
1774 | //======================================================================= |
1775 | //function : IsMicroEdge |
1776 | //purpose : |
1777 | //======================================================================= |
505abfb8 |
1778 | Standard_Boolean BOPTools_AlgoTools::IsMicroEdge |
1779 | (const TopoDS_Edge& aE, |
1e143abb |
1780 | const Handle(IntTools_Context)& aCtx) |
4e57c75e |
1781 | { |
1782 | Standard_Boolean bRet; |
1783 | Standard_Integer iErr; |
1784 | Standard_Real aT1, aT2, aTmp; |
1785 | Handle(Geom_Curve) aC3D; |
1786 | TopoDS_Vertex aV1, aV2; |
1787 | // |
1788 | bRet=(BRep_Tool::Degenerated(aE) || |
1789 | !BRep_Tool::IsGeometric(aE)); |
1790 | if (bRet) { |
1791 | return bRet; |
1792 | } |
1793 | // |
1794 | aC3D=BRep_Tool::Curve(aE, aT1, aT2); |
1795 | TopExp::Vertices(aE, aV1, aV2); |
1796 | aT1=BRep_Tool::Parameter(aV1, aE); |
1797 | aT2=BRep_Tool::Parameter(aV2, aE); |
1798 | if (aT2<aT1) { |
1799 | aTmp=aT1; |
1800 | aT1=aT2; |
1801 | aT2=aTmp; |
1802 | } |
1803 | // |
1e143abb |
1804 | IntTools_ShrunkRange aSR; |
505abfb8 |
1805 | aSR.SetContext(aCtx); |
1806 | aSR.SetData(aE, aT1, aT2, aV1, aV2); |
4e57c75e |
1807 | aSR.Perform(); |
1808 | iErr=aSR.ErrorStatus(); |
1809 | bRet = !(iErr==0); |
1810 | // |
1811 | return bRet; |
1812 | } |
1813 | |
4e57c75e |
1814 | //======================================================================= |
df017cc9 |
1815 | //function : GetFaceDir |
1816 | //purpose : Get binormal direction for the face in the point aP |
1817 | //======================================================================= |
bb58e462 |
1818 | void GetFaceDir(const TopoDS_Edge& aE, |
1819 | const TopoDS_Face& aF, |
1820 | const gp_Pnt& aP, |
1821 | const Standard_Real aT, |
1822 | const gp_Dir& aDTgt, |
1823 | gp_Dir& aDN, |
1824 | gp_Dir& aDB, |
1e143abb |
1825 | Handle(IntTools_Context)& theContext, |
f56518cd |
1826 | GeomAPI_ProjectPointOnSurf& aProjPL, |
1827 | const Standard_Real aDt) |
df017cc9 |
1828 | { |
393598eb |
1829 | Standard_Real aTolE; |
1830 | gp_Pnt aPx; |
1831 | // |
df017cc9 |
1832 | BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE, aF, aT, aDN); |
1833 | if (aF.Orientation()==TopAbs_REVERSED){ |
1834 | aDN.Reverse(); |
1835 | } |
393598eb |
1836 | // |
1837 | aTolE=BRep_Tool::Tolerance(aE); |
df017cc9 |
1838 | aDB = aDN^aDTgt; |
1839 | // |
393598eb |
1840 | if (!FindPointInFace(aF, aP, aDB, aPx, theContext, aProjPL, aDt, aTolE)) { |
505abfb8 |
1841 | BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(aE, aF, aT, aPx, |
1842 | aDN, theContext); |
bb58e462 |
1843 | aProjPL.Perform(aPx); |
1844 | aPx = aProjPL.NearestPoint(); |
1845 | gp_Vec aVec(aP, aPx); |
1846 | aDB.SetXYZ(aVec.XYZ()); |
4e57c75e |
1847 | } |
df017cc9 |
1848 | } |
df017cc9 |
1849 | //======================================================================= |
1850 | //function : FindPointInFace |
1851 | //purpose : Find a point in the face in direction of <aDB> |
1852 | //======================================================================= |
f56518cd |
1853 | Standard_Boolean FindPointInFace(const TopoDS_Face& aF, |
bb58e462 |
1854 | const gp_Pnt& aP, |
1855 | gp_Dir& aDB, |
1856 | gp_Pnt& aPOut, |
1e143abb |
1857 | Handle(IntTools_Context)& theContext, |
f56518cd |
1858 | GeomAPI_ProjectPointOnSurf& aProjPL, |
393598eb |
1859 | const Standard_Real aDt, |
1860 | const Standard_Real aTolE) |
df017cc9 |
1861 | { |
1862 | Standard_Integer aNbItMax; |
b9f6147d |
1863 | Standard_Real aDist, aDTol, aPM, anEps; |
df017cc9 |
1864 | Standard_Boolean bRet; |
393598eb |
1865 | gp_Pnt aP1, aPS; |
4e57c75e |
1866 | // |
59495dbe |
1867 | aDTol = Precision::Angular(); |
1868 | aPM = aP.XYZ().Modulus(); |
1869 | if (aPM > 1000.) { |
1870 | aDTol = 5.e-16 * aPM; |
1871 | } |
df017cc9 |
1872 | bRet = Standard_False; |
f56518cd |
1873 | aNbItMax = 15; |
b9f6147d |
1874 | anEps = Precision::SquareConfusion(); |
4e57c75e |
1875 | // |
df017cc9 |
1876 | GeomAPI_ProjectPointOnSurf& aProj=theContext->ProjPS(aF); |
4e57c75e |
1877 | // |
393598eb |
1878 | aPS=aP; |
1879 | aProj.Perform(aPS); |
1880 | if (!aProj.IsDone()) { |
1881 | return bRet; |
1882 | } |
1883 | aPS=aProj.NearestPoint(); |
1884 | aProjPL.Perform(aPS); |
1885 | aPS=aProjPL.NearestPoint(); |
1886 | // |
1887 | aPS.SetXYZ(aPS.XYZ()+2.*aTolE*aDB.XYZ()); |
b9f6147d |
1888 | aProj.Perform(aPS); |
393598eb |
1889 | if (!aProj.IsDone()) { |
1890 | return bRet; |
1891 | } |
1892 | aPS=aProj.NearestPoint(); |
1893 | aProjPL.Perform(aPS); |
1894 | aPS=aProjPL.NearestPoint(); |
1895 | // |
df017cc9 |
1896 | do { |
393598eb |
1897 | aP1.SetXYZ(aPS.XYZ()+aDt*aDB.XYZ()); |
df017cc9 |
1898 | // |
1899 | aProj.Perform(aP1); |
1900 | if (!aProj.IsDone()) { |
1901 | return bRet; |
1902 | } |
1903 | aPOut = aProj.NearestPoint(); |
1904 | aDist = aProj.LowerDistance(); |
1905 | // |
bb58e462 |
1906 | aProjPL.Perform(aPOut); |
1907 | aPOut = aProjPL.NearestPoint(); |
1908 | // |
393598eb |
1909 | gp_Vec aV(aPS, aPOut); |
b9f6147d |
1910 | if (aV.SquareMagnitude() < anEps) { |
1911 | return bRet; |
1912 | } |
df017cc9 |
1913 | aDB.SetXYZ(aV.XYZ()); |
59495dbe |
1914 | } while (aDist > aDTol && --aNbItMax); |
4e57c75e |
1915 | // |
59495dbe |
1916 | bRet = aDist < aDTol; |
df017cc9 |
1917 | return bRet; |
4e57c75e |
1918 | } |
30ecd5f8 |
1919 | //======================================================================= |
f56518cd |
1920 | //function : MinStep3D |
1921 | //purpose : |
1922 | //======================================================================= |
1923 | Standard_Real MinStep3D(const TopoDS_Edge& theE1, |
1924 | const TopoDS_Face& theF1, |
1925 | const BOPTools_ListOfCoupleOfShape& theLCS, |
1926 | const gp_Pnt& aP) |
1927 | { |
1928 | Standard_Real aDt, aTolE, aTolF, aDtMax, aDtMin, aR; |
1929 | BOPTools_CoupleOfShape aCS1; |
1930 | BOPTools_ListOfCoupleOfShape aLCS; |
1931 | BOPTools_ListIteratorOfListOfCoupleOfShape aIt; |
1932 | BRepAdaptor_Surface aBAS; |
1933 | // |
1934 | aLCS = theLCS; |
1935 | aCS1.SetShape1(theE1); |
1936 | aCS1.SetShape2(theF1); |
1937 | aLCS.Append(aCS1); |
1938 | // |
1939 | aTolE = BRep_Tool::Tolerance(theE1); |
1940 | aDtMax = -1.; |
1941 | aDtMin = 5.e-6; |
1942 | // |
1943 | aIt.Initialize(aLCS); |
1944 | for (; aIt.More(); aIt.Next()) { |
1945 | const BOPTools_CoupleOfShape& aCS = aIt.Value(); |
1946 | const TopoDS_Face& aF = (*(TopoDS_Face*)(&aCS.Shape2())); |
1947 | // |
1948 | aTolF = BRep_Tool::Tolerance(aF); |
1949 | aDt = 2*(aTolE + aTolF); |
1950 | // |
1951 | aR = 0.; |
1952 | aBAS.Initialize(aF, Standard_False); |
1953 | GeomAbs_SurfaceType aSType = aBAS.GetType(); |
b9f6147d |
1954 | switch (aSType) { |
1955 | case GeomAbs_Cylinder: { |
f56518cd |
1956 | aR = aBAS.Cylinder().Radius(); |
b9f6147d |
1957 | break; |
f56518cd |
1958 | } |
b9f6147d |
1959 | case GeomAbs_Cone: { |
f56518cd |
1960 | gp_Lin aL(aBAS.Cone().Axis()); |
1961 | aR = aL.Distance(aP); |
b9f6147d |
1962 | break; |
f56518cd |
1963 | } |
b9f6147d |
1964 | case GeomAbs_Sphere: { |
1965 | aDtMin = Max(aDtMin, 5.e-4); |
f56518cd |
1966 | aR = aBAS.Sphere().Radius(); |
b9f6147d |
1967 | break; |
f56518cd |
1968 | } |
b9f6147d |
1969 | case GeomAbs_Torus: { |
f56518cd |
1970 | aR = aBAS.Torus().MajorRadius(); |
b9f6147d |
1971 | break; |
f56518cd |
1972 | } |
b9f6147d |
1973 | default: |
1974 | aDtMin = Max(aDtMin, 5.e-4); |
1975 | break; |
f56518cd |
1976 | } |
1977 | // |
1978 | if (aR > 100.) { |
b9f6147d |
1979 | Standard_Real d = 10*Precision::PConfusion(); |
1980 | aDtMin = Max(aDtMin, sqrt(d*d + 2*d*aR)); |
f56518cd |
1981 | } |
1982 | // |
1983 | if (aDt > aDtMax) { |
1984 | aDtMax = aDt; |
1985 | } |
1986 | } |
1987 | // |
1988 | if (aDtMax < aDtMin) { |
1989 | aDtMax = aDtMin; |
1990 | } |
1991 | // |
1992 | return aDtMax; |
1993 | } |
1994 | //======================================================================= |
30ecd5f8 |
1995 | //function : IsOpenShell |
1996 | //purpose : |
1997 | //======================================================================= |
505abfb8 |
1998 | Standard_Boolean BOPTools_AlgoTools::IsOpenShell(const TopoDS_Shell& aSh) |
30ecd5f8 |
1999 | { |
2000 | Standard_Boolean bRet; |
2001 | Standard_Integer i, aNbE, aNbF; |
2002 | TopAbs_Orientation aOrF; |
2003 | BOPCol_IndexedDataMapOfShapeListOfShape aMEF; |
2004 | BOPCol_ListIteratorOfListOfShape aItLS; |
2005 | // |
2006 | bRet=Standard_False; |
2007 | // |
2008 | BOPTools::MapShapesAndAncestors(aSh, TopAbs_EDGE, TopAbs_FACE, aMEF); |
2009 | // |
2010 | aNbE=aMEF.Extent(); |
2011 | for (i=1; i<=aNbE; ++i) { |
2012 | const TopoDS_Edge& aE=*((TopoDS_Edge*)&aMEF.FindKey(i)); |
2013 | if (BRep_Tool::Degenerated(aE)) { |
2014 | continue; |
2015 | } |
2016 | // |
2017 | aNbF=0; |
2018 | const BOPCol_ListOfShape& aLF=aMEF(i); |
2019 | aItLS.Initialize(aLF); |
2020 | for (; aItLS.More(); aItLS.Next()) { |
2021 | const TopoDS_Shape& aF=aItLS.Value(); |
2022 | aOrF=aF.Orientation(); |
2023 | if (aOrF==TopAbs_INTERNAL || aOrF==TopAbs_EXTERNAL) { |
505abfb8 |
2024 | continue; |
30ecd5f8 |
2025 | } |
2026 | ++aNbF; |
2027 | } |
2028 | // |
2029 | if (aNbF==1) { |
2030 | bRet=!bRet; // True |
2031 | break; |
2032 | } |
2033 | } |
2034 | // |
2035 | return bRet; |
2036 | } |
2037 | //======================================================================= |
2038 | //function : IsInvertedSolid |
2039 | //purpose : |
2040 | //======================================================================= |
393598eb |
2041 | Standard_Boolean BOPTools_AlgoTools::IsInvertedSolid |
2042 | (const TopoDS_Solid& aSolid) |
30ecd5f8 |
2043 | { |
2044 | Standard_Real aTolS; |
2045 | TopAbs_State aState; |
2046 | BRepClass3d_SolidClassifier aSC(aSolid); |
2047 | // |
2048 | aTolS=1.e-7; |
2049 | aSC.PerformInfinitePoint(aTolS); |
2050 | aState=aSC.State(); |
2051 | return (aState==TopAbs_IN); |
2052 | } |