4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
6 | // |
973c2be1 |
7 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
8 | // |
d5f74e42 |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
11 | // by the Free Software Foundation, with special exception defined in the file |
12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
13 | // distribution for complete text of the license and disclaimer of any warranty. |
4e57c75e |
14 | // |
973c2be1 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
4e57c75e |
17 | |
18 | #include <BOPAlgo_PaveFiller.ixx> |
465d1fba |
19 | // |
4e57c75e |
20 | #include <Precision.hxx> |
21 | #include <NCollection_IncAllocator.hxx> |
22 | #include <Bnd_Box.hxx> |
23 | |
24 | #include <Geom_Curve.hxx> |
25 | #include <Geom2d_Curve.hxx> |
26 | |
27 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
28 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
29 | |
30 | #include <TopoDS_Edge.hxx> |
31 | #include <TopoDS_Face.hxx> |
32 | #include <TopoDS_Vertex.hxx> |
33 | #include <TopoDS_Compound.hxx> |
34 | |
1b7ae951 |
35 | #include <TopExp.hxx> |
4e57c75e |
36 | #include <TopExp_Explorer.hxx> |
37 | |
38 | #include <BRep_Builder.hxx> |
39 | #include <BRep_Tool.hxx> |
40 | |
1b7ae951 |
41 | #include <BRepBuilderAPI_MakeVertex.hxx> |
42 | |
4e57c75e |
43 | #include <BRepBndLib.hxx> |
44 | #include <BRepTools.hxx> |
45 | |
46 | #include <BRepAdaptor_Curve.hxx> |
47 | #include <BRepAdaptor_Surface.hxx> |
48 | |
49 | #include <IntTools_FaceFace.hxx> |
50 | #include <IntTools_SequenceOfCurves.hxx> |
51 | #include <IntTools_SequenceOfPntOn2Faces.hxx> |
52 | #include <IntTools_Curve.hxx> |
53 | #include <IntTools_PntOn2Faces.hxx> |
1b7ae951 |
54 | #include <IntTools_ShrunkRange.hxx> |
55 | #include <IntTools_Context.hxx> |
4e57c75e |
56 | #include <IntTools_Tools.hxx> |
1b7ae951 |
57 | #include <IntTools_EdgeFace.hxx> |
4e57c75e |
58 | |
59 | #include <IntSurf_ListOfPntOn2S.hxx> |
60 | #include <IntSurf_PntOn2S.hxx> |
61 | |
62 | #include <BOPTools_AlgoTools.hxx> |
63 | #include <BOPTools_AlgoTools3D.hxx> |
64 | |
65 | #include <BOPCol_MapOfInteger.hxx> |
66 | #include <BOPCol_ListOfShape.hxx> |
67 | #include <BOPCol_DataMapOfShapeInteger.hxx> |
68 | #include <BOPCol_ListOfInteger.hxx> |
69 | #include <BOPCol_IndexedMapOfInteger.hxx> |
b4109929 |
70 | #include <BOPCol_DataMapOfIntegerReal.hxx> |
a2098360 |
71 | #include <BOPCol_NCVector.hxx> |
72 | #include <BOPCol_TBB.hxx> |
4e57c75e |
73 | |
4e57c75e |
74 | #include <BOPDS_Interf.hxx> |
75 | #include <BOPDS_Iterator.hxx> |
76 | #include <BOPDS_Curve.hxx> |
77 | #include <BOPDS_Point.hxx> |
78 | #include <BOPDS_FaceInfo.hxx> |
79 | #include <BOPDS_Curve.hxx> |
80 | #include <BOPDS_MapOfPaveBlock.hxx> |
81 | #include <BOPDS_PaveBlock.hxx> |
82 | #include <BOPDS_VectorOfCurve.hxx> |
83 | #include <BOPDS_VectorOfPoint.hxx> |
84 | #include <BOPDS_ShapeInfo.hxx> |
85 | #include <BOPDS_PaveBlock.hxx> |
86 | #include <BOPDS_ListOfPave.hxx> |
87 | #include <BOPDS_ListOfPaveBlock.hxx> |
88 | #include <BOPDS_CoupleOfPaveBlocks.hxx> |
89 | #include <BOPDS_FaceInfo.hxx> |
90 | #include <BOPDS_CommonBlock.hxx> |
1b7ae951 |
91 | #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx> |
4e57c75e |
92 | |
93 | #include <BOPAlgo_Tools.hxx> |
4e57c75e |
94 | |
b4109929 |
95 | static void ToleranceFF(const BRepAdaptor_Surface& aBAS1, |
96 | const BRepAdaptor_Surface& aBAS2, |
4e57c75e |
97 | Standard_Real& aTolFF); |
98 | |
a2098360 |
99 | ///////////////////////////////////////////////////////////////////////// |
100 | //======================================================================= |
101 | //class : BOPAlgo_FaceFace |
102 | //purpose : |
103 | //======================================================================= |
36f4947b |
104 | class BOPAlgo_FaceFace : |
105 | public IntTools_FaceFace, |
106 | public BOPAlgo_Algo { |
107 | |
a2098360 |
108 | public: |
36f4947b |
109 | DEFINE_STANDARD_ALLOC |
110 | |
111 | BOPAlgo_FaceFace() : |
112 | IntTools_FaceFace(), |
113 | BOPAlgo_Algo(), |
114 | myIF1(-1), myIF2(-1), myTolFF(1.e-7) { |
a2098360 |
115 | } |
116 | // |
36f4947b |
117 | virtual ~BOPAlgo_FaceFace() { |
a2098360 |
118 | } |
119 | // |
120 | void SetIndices(const Standard_Integer nF1, |
121 | const Standard_Integer nF2) { |
122 | myIF1=nF1; |
123 | myIF2=nF2; |
124 | } |
125 | // |
126 | void Indices(Standard_Integer& nF1, |
127 | Standard_Integer& nF2) const { |
128 | nF1=myIF1; |
129 | nF2=myIF2; |
130 | } |
131 | // |
132 | void SetFaces(const TopoDS_Face& aF1, |
133 | const TopoDS_Face& aF2) { |
134 | myF1=aF1; |
135 | myF2=aF2; |
136 | } |
137 | // |
138 | const TopoDS_Face& Face1()const { |
139 | return myF1; |
140 | } |
141 | // |
142 | const TopoDS_Face& Face2()const { |
143 | return myF2; |
144 | } |
145 | // |
146 | void SetTolFF(const Standard_Real aTolFF) { |
147 | myTolFF=aTolFF; |
148 | } |
149 | // |
150 | Standard_Real TolFF() const{ |
151 | return myTolFF; |
152 | } |
153 | // |
36f4947b |
154 | virtual void Perform() { |
155 | BOPAlgo_Algo::UserBreak(); |
a2098360 |
156 | IntTools_FaceFace::Perform(myF1, myF2); |
157 | } |
158 | // |
159 | protected: |
160 | Standard_Integer myIF1; |
161 | Standard_Integer myIF2; |
162 | Standard_Real myTolFF; |
163 | TopoDS_Face myF1; |
164 | TopoDS_Face myF2; |
165 | }; |
166 | // |
167 | //======================================================================= |
168 | typedef BOPCol_NCVector |
169 | <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace; |
170 | // |
171 | typedef BOPCol_TBBFunctor |
172 | <BOPAlgo_FaceFace, |
173 | BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor; |
174 | // |
175 | typedef BOPCol_TBBCnt |
176 | <BOPAlgo_FaceFaceFunctor, |
177 | BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt; |
178 | ///////////////////////////////////////////////////////////////////////// |
4e57c75e |
179 | //======================================================================= |
180 | //function : PerformFF |
181 | //purpose : |
182 | //======================================================================= |
7ff8f019 |
183 | void BOPAlgo_PaveFiller::PerformFF() |
4e57c75e |
184 | { |
185 | Standard_Integer iSize; |
186 | Standard_Boolean bValid; |
187 | // |
188 | myErrorStatus=0; |
189 | // |
190 | myIterator->Initialize(TopAbs_FACE, TopAbs_FACE); |
191 | iSize=myIterator->ExpectedLength(); |
192 | if (!iSize) { |
193 | return; |
194 | } |
195 | // |
196 | Standard_Boolean bJustAdd, bApp, bCompC2D1, bCompC2D2, bIsDone; |
7ff8f019 |
197 | Standard_Boolean bToSplit, bTangentFaces; |
4e57c75e |
198 | Standard_Integer nF1, nF2, aNbCurves, aNbPoints, iX, i, iP, iC, aNbLP; |
a2098360 |
199 | Standard_Integer aNbFaceFace, k; |
4e57c75e |
200 | Standard_Real aApproxTol, aTolR3D, aTolR2D, aTolFF; |
b4109929 |
201 | BRepAdaptor_Surface aBAS1, aBAS2; |
af4e6dab |
202 | BOPCol_MapOfInteger aMI; |
a2098360 |
203 | BOPAlgo_VectorOfFaceFace aVFaceFace; |
4e57c75e |
204 | // |
205 | BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
206 | aFFs.SetStartSize(iSize); |
207 | aFFs.SetIncrement(iSize); |
208 | aFFs.Init(); |
209 | // |
210 | bApp=mySectionAttribute.Approximation(); |
211 | bCompC2D1=mySectionAttribute.PCurveOnS1(); |
212 | bCompC2D2=mySectionAttribute.PCurveOnS2(); |
213 | aApproxTol=1.e-7; |
214 | bToSplit = Standard_False; |
215 | // |
216 | for (; myIterator->More(); myIterator->Next()) { |
217 | myIterator->Value(nF1, nF2, bJustAdd); |
218 | if(bJustAdd) { |
219 | continue; |
220 | } |
221 | // |
222 | const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1))); |
223 | const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2))); |
224 | // |
b4109929 |
225 | aBAS1.Initialize(aF1, Standard_False); |
226 | aBAS2.Initialize(aF2, Standard_False); |
227 | // |
228 | if (aBAS1.GetType() == GeomAbs_Plane && |
229 | aBAS2.GetType() == GeomAbs_Plane) { |
230 | Standard_Boolean bToIntersect; |
231 | // |
af4e6dab |
232 | if (aMI.Add(nF1)) { |
78c66ef1 |
233 | myDS->UpdateFaceInfoOn(nF1); |
234 | myDS->UpdateFaceInfoIn(nF1); |
af4e6dab |
235 | } |
236 | if (aMI.Add(nF2)) { |
78c66ef1 |
237 | myDS->UpdateFaceInfoOn(nF2); |
238 | myDS->UpdateFaceInfoIn(nF2); |
af4e6dab |
239 | } |
240 | // |
b4109929 |
241 | bToIntersect = CheckPlanes(nF1, nF2); |
242 | if (!bToIntersect) { |
243 | myDS->AddInterf(nF1, nF2); |
244 | iX=aFFs.Append()-1; |
245 | BOPDS_InterfFF& aFF=aFFs(iX); |
246 | aFF.SetIndices(nF1, nF2); |
247 | aFF.Init(0, 0); |
248 | continue; |
249 | } |
250 | } |
251 | // |
a2098360 |
252 | ToleranceFF(aBAS1, aBAS2, aTolFF); |
253 | // |
254 | BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1(); |
255 | // |
256 | aFaceFace.SetIndices(nF1, nF2); |
257 | aFaceFace.SetFaces(aF1, aF2); |
258 | aFaceFace.SetTolFF(aTolFF); |
4e57c75e |
259 | // |
260 | IntSurf_ListOfPntOn2S aListOfPnts; |
261 | GetEFPnts(nF1, nF2, aListOfPnts); |
262 | aNbLP = aListOfPnts.Extent(); |
263 | if (aNbLP) { |
264 | aFaceFace.SetList(aListOfPnts); |
265 | } |
a2098360 |
266 | // |
4e57c75e |
267 | aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol); |
36f4947b |
268 | aFaceFace.SetProgressIndicator(myProgressIndicator); |
a2098360 |
269 | }//for (; myIterator->More(); myIterator->Next()) { |
270 | // |
271 | aNbFaceFace=aVFaceFace.Extent(); |
272 | //====================================================== |
273 | BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace); |
274 | //====================================================== |
275 | // |
276 | for (k=0; k < aNbFaceFace; ++k) { |
277 | BOPAlgo_FaceFace& aFaceFace=aVFaceFace(k); |
278 | // |
279 | aFaceFace.Indices(nF1, nF2); |
280 | aTolFF=aFaceFace.TolFF(); |
4e57c75e |
281 | // |
282 | bIsDone=aFaceFace.IsDone(); |
283 | if (bIsDone) { |
284 | aTolR3D=aFaceFace.TolReached3d(); |
285 | aTolR2D=aFaceFace.TolReached2d(); |
7ff8f019 |
286 | bTangentFaces=aFaceFace.TangentFaces(); |
4e57c75e |
287 | // |
4e57c75e |
288 | if (aTolR3D < aTolFF){ |
289 | aTolR3D=aTolFF; |
290 | } |
291 | if (aTolR2D < 1.e-7){ |
292 | aTolR2D=1.e-7; |
293 | } |
294 | // |
295 | aFaceFace.PrepareLines3D(bToSplit); |
296 | // |
297 | const IntTools_SequenceOfCurves& aCvsX=aFaceFace.Lines(); |
298 | const IntTools_SequenceOfPntOn2Faces& aPntsX=aFaceFace.Points(); |
299 | // |
300 | aNbCurves=aCvsX.Length(); |
301 | aNbPoints=aPntsX.Length(); |
302 | // |
955b3e71 |
303 | if (aNbCurves || aNbPoints) { |
304 | myDS->AddInterf(nF1, nF2); |
305 | } |
4e57c75e |
306 | // |
307 | iX=aFFs.Append()-1; |
308 | BOPDS_InterfFF& aFF=aFFs(iX); |
309 | aFF.SetIndices(nF1, nF2); |
310 | // |
311 | aFF.SetTolR3D(aTolR3D); |
312 | aFF.SetTolR2D(aTolR2D); |
7ff8f019 |
313 | aFF.SetTangentFaces(bTangentFaces); |
4e57c75e |
314 | // |
315 | // Curves, Points |
316 | aFF.Init(aNbCurves, aNbPoints); |
317 | // |
318 | // Curves |
319 | BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves(); |
320 | for (i=1; i<=aNbCurves; ++i) { |
321 | Bnd_Box aBox; |
322 | // |
323 | const IntTools_Curve& aIC=aCvsX(i); |
324 | const Handle(Geom_Curve)& aC3D= aIC.Curve(); |
1e143abb |
325 | bValid=IntTools_Tools::CheckCurve(aC3D, aTolR3D, aBox); |
4e57c75e |
326 | if (bValid) { |
327 | iC=aVNC.Append()-1; |
328 | BOPDS_Curve& aNC=aVNC(iC); |
329 | aNC.SetCurve(aIC); |
330 | aNC.SetBox(aBox); |
331 | } |
332 | } |
333 | // |
334 | // Points |
335 | BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints(); |
336 | for (i=1; i<=aNbPoints; ++i) { |
337 | const IntTools_PntOn2Faces& aPi=aPntsX(i); |
338 | const gp_Pnt& aP=aPi.P1().Pnt(); |
339 | // |
340 | iP=aVNP.Append()-1; |
341 | BOPDS_Point& aNP=aVNP(iP); |
342 | aNP.SetPnt(aP); |
343 | } |
344 | //}// if (aNbCs || aNbPs) |
345 | }// if (bIsDone) { |
346 | else {// 904/L1 |
347 | iX=aFFs.Append()-1; |
348 | BOPDS_InterfFF& aFF=aFFs(iX); |
349 | aFF.SetIndices(nF1, nF2); |
350 | aNbCurves=0; |
351 | aNbPoints=0; |
352 | aFF.Init(aNbCurves, aNbPoints); |
353 | } |
a2098360 |
354 | }// for (k=0; k < aNbFaceFace; ++k) { |
4e57c75e |
355 | } |
356 | //======================================================================= |
357 | //function : MakeBlocks |
358 | //purpose : |
359 | //======================================================================= |
78c66ef1 |
360 | void BOPAlgo_PaveFiller::MakeBlocks() |
4e57c75e |
361 | { |
362 | Standard_Integer aNbFF; |
363 | // |
364 | myErrorStatus=0; |
365 | // |
366 | BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
367 | aNbFF=aFFs.Extent(); |
368 | if (!aNbFF) { |
369 | return; |
370 | } |
371 | // |
372 | Standard_Boolean bExist, bValid2D; |
373 | Standard_Integer i, nF1, nF2, aNbC, aNbP, j; |
374 | Standard_Integer nV1, nV2; |
96a95605 |
375 | Standard_Real aTolR3D, aT1, aT2, aTol; |
4e57c75e |
376 | Handle(NCollection_IncAllocator) aAllocator; |
377 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB; |
378 | TopoDS_Edge aES; |
379 | Handle(BOPDS_PaveBlock) aPBOut; |
380 | // |
381 | //-----------------------------------------------------scope f |
382 | aAllocator=new NCollection_IncAllocator(); |
383 | // |
384 | BOPCol_ListOfInteger aLSE(aAllocator); |
385 | BOPCol_MapOfInteger aMVOnIn(100, aAllocator), aMF(100, aAllocator), |
386 | aMVStick(100,aAllocator), aMVEF(100, aAllocator), |
78c66ef1 |
387 | aMVB(100, aAllocator), aMI(100, aAllocator); |
decdfc94 |
388 | BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator); |
389 | BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator); |
4e57c75e |
390 | BOPDS_ListOfPaveBlock aLPB(aAllocator); |
391 | BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator); |
392 | BOPCol_DataMapOfShapeInteger aMVI(100, aAllocator); |
78c66ef1 |
393 | BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator); |
b4109929 |
394 | BOPCol_DataMapOfIntegerReal aMVTol(100, aAllocator); |
395 | BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV; |
78c66ef1 |
396 | BOPCol_DataMapOfIntegerInteger aDMI(100, aAllocator); |
4e57c75e |
397 | // |
398 | for (i=0; i<aNbFF; ++i) { |
36f4947b |
399 | // |
400 | UserBreak(); |
401 | // |
4e57c75e |
402 | BOPDS_InterfFF& aFF=aFFs(i); |
403 | aFF.Indices(nF1, nF2); |
404 | // |
405 | BOPDS_VectorOfPoint& aVP=aFF.ChangePoints(); |
406 | aNbP=aVP.Extent(); |
407 | BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves(); |
408 | aNbC=aVC.Extent(); |
409 | if (!aNbP && !aNbC) { |
410 | continue; |
411 | } |
412 | // |
413 | const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1))); |
414 | const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2))); |
415 | // |
416 | aTolR3D=aFF.TolR3D(); |
4e57c75e |
417 | // |
418 | // Update face info |
419 | if (aMF.Add(nF1)) { |
420 | myDS->UpdateFaceInfoOn(nF1); |
421 | } |
422 | if (aMF.Add(nF2)) { |
423 | myDS->UpdateFaceInfoOn(nF2); |
424 | } |
425 | |
426 | BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1); |
427 | BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2); |
428 | // |
429 | aMVOnIn.Clear(); |
430 | aMPBOnIn.Clear(); |
431 | aMVB.Clear(); |
b4109929 |
432 | aMVTol.Clear(); |
4e57c75e |
433 | // |
434 | myDS->VerticesOnIn(nF1, nF2, aMVOnIn, aMPBOnIn); |
435 | myDS->SharedEdges(nF1, nF2, aLSE, aAllocator); |
436 | |
437 | // 1. Treat Points |
438 | for (j=0; j<aNbP; ++j) { |
439 | TopoDS_Vertex aV; |
440 | BOPDS_CoupleOfPaveBlocks aCPB; |
441 | // |
442 | BOPDS_Point& aNP=aVP.ChangeValue(j); |
443 | const gp_Pnt& aP=aNP.Pnt(); |
444 | // |
445 | bExist=IsExistingVertex(aP, aTolR3D, aMVOnIn); |
446 | if (!bExist) { |
447 | BOPTools_AlgoTools::MakeNewVertex(aP, aTolR3D, aV); |
448 | // |
449 | aCPB.SetIndexInterf(i); |
450 | aCPB.SetIndex(j); |
451 | aMSCPB.Add(aV, aCPB); |
452 | } |
453 | } |
454 | // |
455 | // 2. Treat Curves |
456 | aMVStick.Clear(); |
457 | aMVEF.Clear(); |
78c66ef1 |
458 | GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI); |
4e57c75e |
459 | // |
460 | for (j=0; j<aNbC; ++j) { |
461 | BOPDS_Curve& aNC=aVC.ChangeValue(j); |
462 | const IntTools_Curve& aIC=aNC.Curve(); |
4e57c75e |
463 | // DEBt |
464 | aNC.InitPaveBlock1(); |
465 | // |
78c66ef1 |
466 | PutPavesOnCurve(aMVOnIn, aTolR3D, aNC, nF1, nF2, aMI, aMVEF, aMVTol); |
4e57c75e |
467 | // |
78c66ef1 |
468 | PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol); |
7ff8f019 |
469 | //904/F7 |
4e57c75e |
470 | if (aNbC == 1) { |
78c66ef1 |
471 | PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol); |
4e57c75e |
472 | } |
473 | // |
474 | if (aIC.HasBounds()) { |
b6a21c7e |
475 | PutBoundPaveOnCurve(aF1, aF2, aTolR3D, aNC, aMVB); |
4e57c75e |
476 | } |
477 | }//for (j=0; j<aNbC; ++j) { |
478 | // |
479 | // Put closing pave if needed |
480 | for (j=0; j<aNbC; ++j) { |
481 | BOPDS_Curve& aNC=aVC.ChangeValue(j); |
482 | PutClosingPaveOnCurve (aNC); |
483 | } |
484 | // |
485 | // 3. Make section edges |
486 | for (j=0; j<aNbC; ++j) { |
487 | BOPDS_Curve& aNC=aVC.ChangeValue(j); |
488 | const IntTools_Curve& aIC=aNC.Curve(); |
489 | // |
490 | BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks(); |
491 | Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1(); |
492 | // |
493 | aLPB.Clear(); |
494 | aPB1->Update(aLPB, Standard_False); |
495 | // |
496 | aItLPB.Initialize(aLPB); |
497 | for (; aItLPB.More(); aItLPB.Next()) { |
498 | Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue(); |
499 | aPB->Indices(nV1, nV2); |
500 | aPB->Range (aT1, aT2); |
501 | // |
502 | if (fabs(aT1 - aT2) < Precision::PConfusion()) { |
503 | continue; |
504 | } |
505 | // |
465d1fba |
506 | bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC, |
507 | aF1, aF2, aTolR3D); |
4e57c75e |
508 | if (!bValid2D) { |
509 | continue; |
510 | } |
511 | // |
512 | bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aLSE); |
513 | if (bExist) { |
514 | continue; |
515 | } |
516 | // |
517 | bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aPBOut); |
518 | if (bExist) { |
519 | if (aMPBAdd.Add(aPBOut)) { |
520 | Standard_Boolean bInBothFaces = Standard_True; |
5a77460e |
521 | if (!myDS->IsCommonBlock(aPBOut)) { |
4e57c75e |
522 | Standard_Integer nE; |
523 | Standard_Real aTolE; |
524 | // |
525 | nE = aPBOut->Edge(); |
526 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE); |
527 | aTolE = BRep_Tool::Tolerance(aE); |
528 | if (aTolR3D > aTolE) { |
529 | myDS->UpdateEdgeTolerance(nE, aTolR3D); |
530 | } |
531 | bInBothFaces = Standard_False; |
532 | } else { |
533 | bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) || |
534 | aFI1.PaveBlocksIn().Contains(aPBOut))&& |
535 | (aFI2.PaveBlocksOn().Contains(aPBOut) || |
536 | aFI2.PaveBlocksIn().Contains(aPBOut)); |
537 | } |
538 | if (!bInBothFaces) { |
539 | PreparePostTreatFF(i, aPBOut, aMSCPB, aMVI, aVC); |
540 | } |
541 | } |
542 | continue; |
543 | } |
544 | // |
545 | // Make Edge |
546 | const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1))); |
547 | const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2))); |
548 | // |
465d1fba |
549 | BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, |
550 | aV2, aT2, aTolR3D, aES); |
4e57c75e |
551 | BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC, |
552 | mySectionAttribute.PCurveOnS1(), |
553 | mySectionAttribute.PCurveOnS2()); |
554 | // |
555 | if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext)) { |
556 | continue; |
557 | } |
558 | // |
559 | // Append the Pave Block to the Curve j |
560 | aLPBC.Append(aPB); |
561 | // |
562 | // Keep info for post treatment |
563 | BOPDS_CoupleOfPaveBlocks aCPB; |
564 | aCPB.SetIndexInterf(i); |
565 | aCPB.SetIndex(j); |
566 | aCPB.SetPaveBlock1(aPB); |
567 | // |
568 | aMSCPB.Add(aES, aCPB); |
569 | aMVI.Bind(aV1, nV1); |
570 | aMVI.Bind(aV2, nV2); |
b4109929 |
571 | // |
572 | aMVTol.UnBind(nV1); |
573 | aMVTol.UnBind(nV2); |
4e57c75e |
574 | } |
575 | // |
576 | aLPBC.RemoveFirst(); |
577 | }//for (j=0; j<aNbC; ++j) { |
b4109929 |
578 | //back to previous tolerance values for unused vertices |
579 | aItMV.Initialize(aMVTol); |
580 | for (; aItMV.More(); aItMV.Next()) { |
581 | nV1 = aItMV.Key(); |
582 | aTol = aItMV.Value(); |
583 | // |
584 | const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1); |
465d1fba |
585 | const Handle(BRep_TVertex)& TV = |
586 | *((Handle(BRep_TVertex)*)&aV.TShape()); |
b4109929 |
587 | TV->Tolerance(aTol); |
588 | } |
589 | // |
4e57c75e |
590 | ProcessExistingPaveBlocks(i, aMPBOnIn, aMSCPB, aMVI, aMVB, aMPBAdd); |
591 | }//for (i=0; i<aNbFF; ++i) { |
592 | // |
593 | // post treatment |
78c66ef1 |
594 | myErrorStatus=PostTreatFF(aMSCPB, aMVI, aDMExEdges, aDMI, aAllocator); |
4e57c75e |
595 | if (myErrorStatus) { |
596 | return; |
597 | } |
598 | // |
599 | // update face info |
1b7ae951 |
600 | UpdateFaceInfo(aDMExEdges, aDMI); |
78c66ef1 |
601 | //Update all pave blocks |
602 | UpdatePaveBlocks(aDMI); |
4e57c75e |
603 | //-----------------------------------------------------scope t |
604 | aMF.Clear(); |
605 | aMVStick.Clear(); |
606 | aMPBOnIn.Clear(); |
607 | aMVOnIn.Clear(); |
608 | aDMExEdges.Clear(); |
78c66ef1 |
609 | aMI.Clear(); |
610 | aDMI.Clear(); |
4e57c75e |
611 | aAllocator.Nullify(); |
612 | } |
613 | |
614 | //======================================================================= |
615 | //function : PostTreatFF |
616 | //purpose : |
617 | //======================================================================= |
a942f2da |
618 | Standard_Integer BOPAlgo_PaveFiller::PostTreatFF |
4e57c75e |
619 | (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB, |
620 | BOPCol_DataMapOfShapeInteger& aMVI, |
621 | BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges, |
78c66ef1 |
622 | BOPCol_DataMapOfIntegerInteger& aDMI, |
4e57c75e |
623 | Handle(NCollection_BaseAllocator)& theAllocator) |
624 | { |
625 | Standard_Integer iRet, aNbS; |
626 | // |
627 | iRet=0; |
628 | aNbS=theMSCPB.Extent(); |
629 | if (!aNbS) { |
630 | return iRet; |
631 | } |
632 | // |
633 | Standard_Boolean bHasPaveBlocks, bOld; |
1d47d8d0 |
634 | Standard_Integer iErr, nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k; |
af4e6dab |
635 | Standard_Integer jx, aNbLPBx; |
4e57c75e |
636 | Standard_Real aT; |
4e57c75e |
637 | TopAbs_ShapeEnum aType; |
638 | TopoDS_Shape aV, aE; |
639 | BOPCol_ListIteratorOfListOfShape aItLS; |
640 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB; |
641 | BOPDS_PDS aPDS; |
642 | Handle(BOPDS_PaveBlock) aPB1; |
643 | BOPDS_Pave aPave[2], aPave1[2]; |
644 | BOPDS_ShapeInfo aSI; |
645 | // |
646 | BOPCol_ListOfShape aLS(theAllocator); |
647 | BOPAlgo_PaveFiller aPF(theAllocator); |
648 | // |
649 | BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
650 | // |
4e57c75e |
651 | // 0 |
652 | if (aNbS==1) { |
653 | const TopoDS_Shape& aS=theMSCPB.FindKey(1); |
654 | const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1); |
655 | |
656 | // |
657 | aType=aS.ShapeType(); |
658 | if (aType==TopAbs_VERTEX) { |
659 | aSI.SetShapeType(aType); |
660 | aSI.SetShape(aS); |
661 | iV=myDS->Append(aSI); |
662 | // |
663 | iX=aCPB.IndexInterf(); |
664 | iP=aCPB.Index(); |
665 | BOPDS_InterfFF& aFF=aFFs(iX); |
666 | BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints(); |
667 | BOPDS_Point& aNP=aVNP(iP); |
668 | aNP.SetIndex(iV); |
669 | } |
670 | else if (aType==TopAbs_EDGE) { |
671 | aPB1=aCPB.PaveBlock1(); |
672 | // |
673 | if (aPB1->HasEdge()) { |
674 | BOPDS_ListOfPaveBlock aLPBx; |
675 | aLPBx.Append(aPB1); |
676 | aDMExEdges.Bind(aPB1, aLPBx); |
677 | } else { |
678 | aSI.SetShapeType(aType); |
679 | aSI.SetShape(aS); |
680 | iE=myDS->Append(aSI); |
681 | // |
682 | aPB1->SetEdge(iE); |
683 | } |
684 | } |
685 | return iRet; |
686 | } |
687 | // |
688 | // 1 prepare arguments |
689 | for (k=1; k<=aNbS; ++k) { |
690 | const TopoDS_Shape& aS=theMSCPB.FindKey(k); |
691 | aLS.Append(aS); |
692 | } |
693 | // |
694 | // 2 Fuse shapes |
36f4947b |
695 | aPF.SetProgressIndicator(myProgressIndicator); |
a942f2da |
696 | aPF.SetRunParallel(myRunParallel); |
4e57c75e |
697 | aPF.SetArguments(aLS); |
698 | aPF.Perform(); |
699 | iErr=aPF.ErrorStatus(); |
700 | if (iErr) { |
4e57c75e |
701 | return iRet; |
702 | } |
703 | aPDS=aPF.PDS(); |
704 | // |
705 | aItLS.Initialize(aLS); |
706 | for (; aItLS.More(); aItLS.Next()) { |
707 | const TopoDS_Shape& aSx=aItLS.Value(); |
708 | nSx=aPDS->Index(aSx); |
709 | const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx); |
710 | // |
711 | aType=aSIx.ShapeType(); |
712 | // |
713 | if (aType==TopAbs_VERTEX) { |
714 | if (aPDS->HasShapeSD(nSx, nVSD)) { |
715 | aV=aPDS->Shape(nVSD); |
716 | } |
717 | else { |
718 | aV=aSx; |
719 | } |
720 | // index of new vertex in theDS -> iV |
721 | if (!aMVI.IsBound(aV)) { |
722 | aSI.SetShapeType(aType); |
723 | aSI.SetShape(aV); |
724 | iV=myDS->Append(aSI); |
725 | // |
726 | aMVI.Bind(aV, iV); |
727 | } |
728 | else { |
729 | iV=aMVI.Find(aV); |
730 | } |
731 | // update FF interference |
732 | const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx); |
733 | iX=aCPB.IndexInterf(); |
734 | iP=aCPB.Index(); |
735 | BOPDS_InterfFF& aFF=aFFs(iX); |
736 | BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints(); |
737 | BOPDS_Point& aNP=aVNP(iP); |
738 | aNP.SetIndex(iV); |
739 | }//if (aType==TopAbs_VERTEX) { |
740 | // |
741 | else if (aType==TopAbs_EDGE) { |
742 | bHasPaveBlocks=aPDS->HasPaveBlocks(nSx); |
743 | const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx); |
744 | iX=aCPB.IndexInterf(); |
745 | iC=aCPB.Index(); |
746 | aPB1=aCPB.PaveBlock1(); |
747 | // |
748 | bOld = aPB1->HasEdge(); |
749 | if (bOld) { |
750 | BOPDS_ListOfPaveBlock aLPBx; |
751 | aDMExEdges.Bind(aPB1, aLPBx); |
752 | } |
753 | // |
754 | if (!bHasPaveBlocks) { |
755 | if (bOld) { |
756 | aDMExEdges.ChangeFind(aPB1).Append(aPB1); |
1b7ae951 |
757 | } |
758 | else { |
4e57c75e |
759 | aSI.SetShapeType(aType); |
760 | aSI.SetShape(aSx); |
761 | iE=myDS->Append(aSI); |
762 | // |
763 | aPB1->SetEdge(iE); |
764 | } |
765 | } |
766 | else { |
767 | BOPDS_InterfFF& aFF=aFFs(iX); |
768 | BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves(); |
769 | BOPDS_Curve& aNC=aVNC(iC); |
770 | BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks(); |
771 | // |
772 | const BOPDS_ListOfPaveBlock& aLPBx=aPDS->PaveBlocks(nSx); |
773 | aNbLPBx=aLPBx.Extent(); |
774 | // |
775 | if (bOld && !aNbLPBx) { |
776 | aDMExEdges.ChangeFind(aPB1).Append(aPB1); |
777 | continue; |
778 | } |
779 | // |
780 | if (!bOld) { |
781 | aItLPB.Initialize(aLPBC); |
782 | for (; aItLPB.More(); aItLPB.Next()) { |
783 | const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value(); |
784 | if (aPBC==aPB1) { |
785 | aLPBC.Remove(aItLPB); |
786 | break; |
787 | } |
788 | } |
789 | } |
790 | // |
791 | if (!aNbLPBx) { |
792 | aE=aSx; |
793 | // |
794 | if (!aMVI.IsBound(aE)) { |
795 | aSI.SetShapeType(aType); |
796 | aSI.SetShape(aE); |
797 | iE=myDS->Append(aSI); |
798 | aMVI.Bind(aE, iE); |
799 | } |
800 | else { |
801 | iE=aMVI.Find(aE); |
802 | } |
803 | // append new PaveBlock to aLPBC |
4e57c75e |
804 | aPB1->SetEdge(iE); |
805 | aLPBC.Append(aPB1); |
806 | } // if (!aNbLPBx) { |
807 | // |
808 | else { |
809 | aItLPB.Initialize(aLPBx); |
810 | if (bOld) { |
811 | aPave1[0] = aPB1->Pave1(); |
812 | aPave1[1] = aPB1->Pave2(); |
813 | } |
814 | for (; aItLPB.More(); aItLPB.Next()) { |
815 | const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value(); |
5a77460e |
816 | const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx); |
4e57c75e |
817 | // |
818 | // update vertices of paves |
819 | aPave[0]=aPBx->Pave1(); |
820 | aPave[1]=aPBx->Pave2(); |
821 | for (j=0; j<2; ++j) { |
822 | jx = 0; |
823 | if (bOld) { |
824 | aT = aPave[j].Parameter(); |
825 | if (aT == aPave1[0].Parameter()) { |
826 | jx = 1; |
827 | } else if (aT == aPave1[1].Parameter()) { |
828 | jx = 2; |
829 | } |
830 | // |
831 | if (jx) { |
832 | iV = aPave1[jx-1].Index(); |
833 | } |
834 | } |
835 | if (!jx) { |
836 | nV=aPave[j].Index(); |
837 | aV=aPDS->Shape(nV); |
838 | // |
465d1fba |
839 | if (!aMVI.IsBound(aV)) { |
840 | // index of new vertex in theDS -> iV |
4e57c75e |
841 | aSI.SetShapeType(TopAbs_VERTEX); |
842 | aSI.SetShape(aV); |
843 | iV=myDS->Append(aSI); |
844 | aMVI.Bind(aV, iV); |
845 | } |
846 | else { |
847 | iV=aMVI.Find(aV); |
848 | } |
849 | } |
78c66ef1 |
850 | const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2(); |
465d1fba |
851 | if (aP1.Parameter() == aPave[j].Parameter() && |
852 | aP1.Index() != iV) { |
78c66ef1 |
853 | aDMI.Bind(aP1.Index(), iV); |
6a43d224 |
854 | myDS->AddShapeSD(aP1.Index(), iV); |
78c66ef1 |
855 | } |
856 | // |
4e57c75e |
857 | aPave[j].SetIndex(iV); |
858 | } |
859 | // |
860 | // add edge |
861 | aE=aPDS->Shape(aPBRx->Edge()); |
862 | // |
863 | if (!aMVI.IsBound(aE)) { |
864 | aSI.SetShapeType(aType); |
865 | aSI.SetShape(aE); |
866 | iE=myDS->Append(aSI); |
867 | aMVI.Bind(aE, iE); |
868 | } |
869 | else { |
870 | iE=aMVI.Find(aE); |
871 | } |
872 | // append new PaveBlock to aLPBC |
873 | Handle(BOPDS_PaveBlock) aPBC=new BOPDS_PaveBlock(); |
874 | // |
875 | aPBC->SetPave1(aPave[0]); |
876 | aPBC->SetPave2(aPave[1]); |
877 | aPBC->SetEdge(iE); |
878 | if (bOld) { |
879 | aPBC->SetOriginalEdge(aPB1->OriginalEdge()); |
880 | aDMExEdges.ChangeFind(aPB1).Append(aPBC); |
881 | } |
882 | else { |
883 | aLPBC.Append(aPBC); |
884 | } |
885 | } |
886 | } |
887 | } |
888 | }//else if (aType==TopAbs_EDGE) |
889 | }//for (; aItLS.More(); aItLS.Next()) { |
890 | return iRet; |
891 | } |
892 | |
893 | //======================================================================= |
894 | //function : UpdateFaceInfo |
895 | //purpose : |
896 | //======================================================================= |
465d1fba |
897 | void BOPAlgo_PaveFiller::UpdateFaceInfo |
1b7ae951 |
898 | (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME, |
899 | const BOPCol_DataMapOfIntegerInteger& theDMV) |
4e57c75e |
900 | { |
901 | Standard_Integer i, j, nV1, nF1, nF2, |
1b7ae951 |
902 | aNbFF, aNbC, aNbP; |
4e57c75e |
903 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB; |
1b7ae951 |
904 | BOPCol_MapOfInteger aMF; |
4e57c75e |
905 | // |
906 | BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
907 | aNbFF=aFFs.Extent(); |
908 | // |
909 | //1. Sections (curves, points); |
910 | for (i=0; i<aNbFF; ++i) { |
911 | BOPDS_InterfFF& aFF=aFFs(i); |
912 | aFF.Indices(nF1, nF2); |
913 | // |
914 | BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1); |
915 | BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2); |
916 | // |
1b7ae951 |
917 | // 1.1. Section edges |
4e57c75e |
918 | BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves(); |
919 | aNbC=aVNC.Extent(); |
920 | for (j=0; j<aNbC; ++j) { |
921 | BOPDS_Curve& aNC=aVNC(j); |
922 | BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks(); |
923 | aItLPB.Initialize(aLPBC); |
924 | // |
1b7ae951 |
925 | // Treat existing pave blocks |
4e57c75e |
926 | if (aItLPB.More() && theDME.IsBound(aLPBC.First())) { |
927 | const Handle(BOPDS_PaveBlock)& aPB=aLPBC.First(); |
1b7ae951 |
928 | BOPDS_ListOfPaveBlock& aLPB=theDME.ChangeFind(aPB); |
4e57c75e |
929 | UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2); |
930 | aLPBC.Clear(); |
931 | continue; |
932 | } |
933 | // |
1b7ae951 |
934 | // Add section edges to face info |
935 | for (; aItLPB.More(); aItLPB.Next()) { |
4e57c75e |
936 | const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value(); |
937 | aFI1.ChangePaveBlocksSc().Add(aPB); |
938 | aFI2.ChangePaveBlocksSc().Add(aPB); |
939 | } |
940 | } |
1b7ae951 |
941 | // |
942 | // 1.2. Section vertices |
4e57c75e |
943 | const BOPDS_VectorOfPoint& aVNP=aFF.Points(); |
944 | aNbP=aVNP.Extent(); |
945 | for (j=0; j<aNbP; ++j) { |
946 | const BOPDS_Point& aNP=aVNP(j); |
947 | nV1=aNP.Index(); |
85915310 |
948 | if (nV1<0) { |
949 | continue; |
950 | } |
4e57c75e |
951 | aFI1.ChangeVerticesSc().Add(nV1); |
952 | aFI2.ChangeVerticesSc().Add(nV1); |
953 | } |
1b7ae951 |
954 | // |
955 | aMF.Add(nF1); |
956 | aMF.Add(nF2); |
4e57c75e |
957 | } |
958 | // |
1b7ae951 |
959 | Standard_Boolean bVerts, bEdges; |
960 | // |
961 | bVerts = theDMV.Extent() > 0; |
962 | bEdges = theDME.Extent() > 0; |
963 | // |
964 | if (!bVerts && !bEdges) { |
4e57c75e |
965 | return; |
966 | } |
967 | // |
1b7ae951 |
968 | // 2. Update Face Info information with new vertices and new |
969 | // pave blocks created in PostTreatFF from existing ones |
970 | Standard_Integer nV2, aNbPB; |
971 | BOPCol_MapIteratorOfMapOfInteger aItMF; |
972 | BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItMV; |
973 | // |
974 | aItMF.Initialize(aMF); |
975 | for (; aItMF.More(); aItMF.Next()) { |
976 | nF1 = aItMF.Value(); |
4e57c75e |
977 | // |
1b7ae951 |
978 | BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF1); |
4e57c75e |
979 | // |
1b7ae951 |
980 | // 2.1. Update information about vertices |
981 | if (bVerts) { |
982 | BOPCol_MapOfInteger& aMVOn = aFI.ChangeVerticesOn(); |
983 | BOPCol_MapOfInteger& aMVIn = aFI.ChangeVerticesIn(); |
984 | // |
985 | aItMV.Initialize(theDMV); |
986 | for (; aItMV.More(); aItMV.Next()) { |
987 | nV1 = aItMV.Key(); |
988 | nV2 = aItMV.Value(); |
989 | // |
990 | if (aMVOn.Remove(nV1)) { |
991 | aMVOn.Add(nV2); |
4e57c75e |
992 | } |
1b7ae951 |
993 | // |
994 | if (aMVIn.Remove(nV1)) { |
995 | aMVIn.Add(nV2); |
996 | } |
997 | } // for (; aItMV.More(); aItMV.Next()) { |
998 | } // if (bVerts) { |
999 | // |
1000 | // 2.2. Update information about pave blocks |
1001 | if (bEdges) { |
1002 | BOPDS_IndexedMapOfPaveBlock& aMPBOn = aFI.ChangePaveBlocksOn(); |
1003 | BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.ChangePaveBlocksIn(); |
1004 | // |
1005 | BOPDS_IndexedMapOfPaveBlock aMPBCopy; |
1006 | for (i = 0; i < 2; ++i) { |
1007 | BOPDS_IndexedMapOfPaveBlock& aMPBOnIn = !i ? aMPBOn : aMPBIn; |
1008 | aMPBCopy = aMPBOnIn; |
1009 | aMPBOnIn.Clear(); |
1010 | // |
1011 | aNbPB = aMPBCopy.Extent(); |
1012 | for (j = 1; j <= aNbPB; ++j) { |
1013 | const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j); |
1014 | if (theDME.IsBound(aPB)) { |
1015 | const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB); |
1016 | aItLPB.Initialize(aLPB); |
1017 | for (; aItLPB.More(); aItLPB.Next()) { |
1018 | const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value(); |
1019 | aMPBOnIn.Add(aPB1); |
1020 | } |
1021 | } |
1022 | else { |
1023 | aMPBOnIn.Add(aPB); |
1024 | } |
1025 | } // for (j = 1; j <= aNbPB; ++j) { |
1026 | } // for (i = 0; i < 2; ++i) { |
1027 | } // if (bEdges) { |
1028 | } |
4e57c75e |
1029 | } |
4e57c75e |
1030 | //======================================================================= |
1031 | //function : IsExistingVertex |
1032 | //purpose : |
1033 | //======================================================================= |
1034 | Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex |
1035 | (const gp_Pnt& aP, |
1036 | const Standard_Real theTolR3D, |
1037 | const BOPCol_MapOfInteger& aMVOnIn)const |
1038 | { |
1039 | Standard_Boolean bRet; |
1040 | Standard_Integer nV, iFlag; |
1041 | Standard_Real aTolV; |
1042 | gp_Pnt aPV; |
1043 | Bnd_Box aBoxP; |
1044 | BOPCol_MapIteratorOfMapOfInteger aIt; |
1045 | // |
1046 | bRet=Standard_True; |
1047 | // |
1048 | aBoxP.Add(aP); |
1049 | aBoxP.Enlarge(theTolR3D); |
1050 | // |
1051 | aIt.Initialize(aMVOnIn); |
1052 | for (; aIt.More(); aIt.Next()) { |
1053 | Bnd_Box aBoxV; |
1054 | // |
1055 | nV=aIt.Value(); |
1056 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV))); |
1057 | aPV=BRep_Tool::Pnt(aV); |
1058 | aTolV=BRep_Tool::Tolerance(aV); |
1059 | aBoxV.Add(aP); |
1060 | aBoxV.Enlarge(aTolV); |
1061 | // |
1062 | if (!aBoxP.IsOut(aBoxV)) { |
1063 | iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, theTolR3D); |
1064 | if (!iFlag) { |
1065 | return bRet; |
1066 | } |
1067 | } |
1068 | } |
1069 | return !bRet; |
1070 | } |
1071 | //======================================================================= |
1072 | //function : IsExistingPaveBlock |
1073 | //purpose : |
1074 | //======================================================================= |
1075 | Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock |
1076 | (const Handle(BOPDS_PaveBlock)& thePB, |
1077 | const BOPDS_Curve& theNC, |
1078 | const Standard_Real theTolR3D, |
1079 | const BOPCol_ListOfInteger& theLSE) |
1080 | { |
1081 | Standard_Boolean bRet=Standard_True; |
1082 | // |
1083 | if (theLSE.IsEmpty()) { |
1084 | return !bRet; |
1085 | } |
1086 | // |
1087 | Standard_Real aT1, aT2, aTm, aTx, aTol; |
1088 | Standard_Integer nE, iFlag; |
1089 | gp_Pnt aPm; |
1090 | Bnd_Box aBoxPm; |
1091 | BOPCol_ListIteratorOfListOfInteger aItLI; |
1092 | // |
1093 | thePB->Range(aT1, aT2); |
1094 | aTm=IntTools_Tools::IntermediatePoint (aT1, aT2); |
1095 | theNC.Curve().D0(aTm, aPm); |
1096 | aBoxPm.Add(aPm); |
1097 | aBoxPm.Enlarge(theTolR3D); |
1098 | // |
1099 | aItLI.Initialize(theLSE); |
1100 | for (; aItLI.More(); aItLI.Next()) { |
1101 | nE=aItLI.Value(); |
1102 | const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE); |
1103 | const Bnd_Box& aBoxE=aSIE.Box(); |
1104 | if (!aBoxE.IsOut(aBoxPm)) { |
1105 | const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape())); |
1106 | aTol = BRep_Tool::Tolerance(aE); |
1107 | aTol = aTol > theTolR3D ? aTol : theTolR3D; |
1108 | iFlag=myContext->ComputePE(aPm, aTol, aE, aTx); |
1109 | if (!iFlag) { |
1110 | return bRet; |
1111 | } |
1112 | } |
1113 | } |
1114 | return !bRet; |
1115 | } |
1116 | |
1117 | //======================================================================= |
1118 | //function : IsExistingPaveBlock |
1119 | //purpose : |
1120 | //======================================================================= |
1121 | Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock |
1122 | (const Handle(BOPDS_PaveBlock)& thePB, |
1123 | const BOPDS_Curve& theNC, |
1124 | const Standard_Real theTolR3D, |
decdfc94 |
1125 | const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn, |
4e57c75e |
1126 | Handle(BOPDS_PaveBlock&) aPBOut) |
1127 | { |
1128 | Standard_Boolean bRet; |
1129 | Standard_Real aT1, aT2, aTm, aTx; |
decdfc94 |
1130 | Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB; |
4e57c75e |
1131 | gp_Pnt aP1, aPm, aP2; |
1132 | Bnd_Box aBoxP1, aBoxPm, aBoxP2; |
4e57c75e |
1133 | // |
78c66ef1 |
1134 | bRet=Standard_False; |
4e57c75e |
1135 | const IntTools_Curve& aIC=theNC.Curve(); |
1136 | // |
1137 | thePB->Range(aT1, aT2); |
1138 | thePB->Indices(nV11, nV12); |
1139 | //first point |
1140 | aIC.D0(aT1, aP1); |
1141 | aBoxP1.Add(aP1); |
1142 | aBoxP1.Enlarge(theTolR3D); |
1143 | //intermediate point |
1144 | aTm=IntTools_Tools::IntermediatePoint (aT1, aT2); |
1145 | aIC.D0(aTm, aPm); |
1146 | aBoxPm.Add(aPm); |
1147 | aBoxPm.Enlarge(theTolR3D); |
1148 | //last point |
1149 | aIC.D0(aT2, aP2); |
1150 | aBoxP2.Add(aP2); |
1151 | aBoxP2.Enlarge(theTolR3D); |
1152 | // |
decdfc94 |
1153 | aNbPB = theMPBOnIn.Extent(); |
1154 | for (i = 1; i <= aNbPB; ++i) { |
1155 | const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i); |
4e57c75e |
1156 | aPB->Indices(nV21, nV22); |
1157 | nSp=aPB->Edge(); |
1158 | const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp); |
78c66ef1 |
1159 | const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape())); |
4e57c75e |
1160 | const Bnd_Box& aBoxSp=aSISp.Box(); |
78c66ef1 |
1161 | // |
465d1fba |
1162 | iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 : |
1163 | (!aBoxSp.IsOut(aBoxP1) ? 1 : 0); |
1164 | iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 : |
1165 | (!aBoxSp.IsOut(aBoxP2) ? 1 : 0); |
78c66ef1 |
1166 | if (iFlag1 && iFlag2) { |
465d1fba |
1167 | if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm, |
1168 | theTolR3D, |
1169 | aSp, |
1170 | aTx)) { |
78c66ef1 |
1171 | continue; |
1172 | } |
1173 | // |
1174 | if (iFlag1 == 1) { |
1175 | iFlag1 = !myContext->ComputePE(aP1, theTolR3D, aSp, aTx); |
1176 | } |
1177 | // |
1178 | if (iFlag2 == 1) { |
1179 | iFlag2 = !myContext->ComputePE(aP2, theTolR3D, aSp, aTx); |
1180 | } |
1181 | // |
1182 | if (iFlag1 && iFlag2) { |
1183 | aPBOut = aPB; |
1184 | bRet=Standard_True; |
1185 | break; |
4e57c75e |
1186 | } |
1187 | } |
1188 | } |
78c66ef1 |
1189 | return bRet; |
4e57c75e |
1190 | } |
4e57c75e |
1191 | //======================================================================= |
1192 | //function : PutBoundPaveOnCurve |
1193 | //purpose : |
1194 | //======================================================================= |
1195 | void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1, |
1196 | const TopoDS_Face& aF2, |
1197 | const Standard_Real aTolR3D, |
1198 | BOPDS_Curve& aNC, |
4e57c75e |
1199 | BOPCol_MapOfInteger& aMVB) |
1200 | { |
1201 | Standard_Boolean bVF; |
1202 | Standard_Integer nV, iFlag, nVn, j, aNbEP; |
1203 | Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew; |
1204 | gp_Pnt aP[2]; |
1205 | TopoDS_Vertex aVn; |
1206 | BOPDS_ListIteratorOfListOfPave aItLP; |
1207 | BOPDS_Pave aPn, aPMM[2]; |
1208 | // |
1209 | aTolVnew = Precision::Confusion(); |
1210 | // |
1211 | const IntTools_Curve& aIC=aNC.Curve(); |
1212 | aIC.Bounds(aT[0], aT[1], aP[0], aP[1]); |
1213 | // |
1214 | Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1(); |
1215 | const BOPDS_ListOfPave& aLP=aPB->ExtPaves(); |
1216 | // |
1217 | aNbEP=aLP.Extent(); |
1218 | if (aNbEP) { |
1219 | aTmin=1.e10; |
1220 | aTmax=-aTmin; |
1221 | // |
1222 | aItLP.Initialize(aLP); |
1223 | for (; aItLP.More(); aItLP.Next()) { |
1224 | const BOPDS_Pave& aPv=aItLP.Value(); |
1225 | aPv.Contents(nV, aTV); |
1226 | if (aTV<aTmin) { |
1227 | aPMM[0]=aPv; |
1228 | aTmin=aTV; |
1229 | } |
1230 | if (aTV>aTmax) { |
1231 | aPMM[1]=aPv; |
1232 | aTmax=aTV; |
1233 | } |
1234 | } |
1235 | } |
1236 | // |
1237 | for (j=0; j<2; ++j) { |
1238 | //if curve is closed, process only one bound |
1239 | if (j && aP[1].IsEqual(aP[0], aTolVnew)) { |
1240 | continue; |
1241 | } |
1242 | // |
1243 | iFlag=1; |
1244 | // |
1245 | if (aNbEP) { |
1246 | Bnd_Box aBoxP; |
1247 | // |
1248 | aBoxP.Set(aP[j]); |
1249 | aTol = aTolR3D+Precision::Confusion(); |
1250 | aBoxP.Enlarge(aTol); |
1251 | const BOPDS_Pave& aPV=aPMM[j]; |
1252 | nV=aPV.Index(); |
1253 | const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV); |
1254 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape())); |
1255 | const Bnd_Box& aBoxV=aSIV.Box(); |
1256 | if (!aBoxP.IsOut(aBoxV)){ |
1257 | iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol); |
1258 | } |
1259 | } |
1260 | if (iFlag) { |
1261 | // 900/L5 |
1262 | bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D); |
1263 | if (!bVF) { |
1264 | continue; |
1265 | } |
1266 | // |
1267 | BOPDS_ShapeInfo aSIVn; |
1268 | // |
1269 | BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn); |
1270 | aSIVn.SetShapeType(TopAbs_VERTEX); |
1271 | aSIVn.SetShape(aVn); |
1272 | // |
1273 | nVn=myDS->Append(aSIVn); |
1274 | // |
1275 | aPn.SetIndex(nVn); |
1276 | aPn.SetParameter(aT[j]); |
1277 | aPB->AppendExtPave(aPn); |
1278 | // |
1279 | aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn))); |
1280 | BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn); |
1281 | // |
1282 | aTolVnew = BRep_Tool::Tolerance(aVn); |
1283 | // |
1284 | BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn); |
1285 | Bnd_Box& aBoxDS=aSIDS.ChangeBox(); |
1286 | BRepBndLib::Add(aVn, aBoxDS); |
4e57c75e |
1287 | aMVB.Add(nVn); |
1288 | } |
1289 | } |
1290 | } |
1291 | |
1292 | //======================================================================= |
78c66ef1 |
1293 | //function : PutPavesOnCurve |
4e57c75e |
1294 | //purpose : |
1295 | //======================================================================= |
465d1fba |
1296 | void BOPAlgo_PaveFiller::PutPavesOnCurve |
1297 | (const BOPCol_MapOfInteger& aMVOnIn, |
1298 | const Standard_Real aTolR3D, |
1299 | BOPDS_Curve& aNC, |
1300 | const Standard_Integer nF1, |
1301 | const Standard_Integer nF2, |
1302 | const BOPCol_MapOfInteger& aMI, |
1303 | const BOPCol_MapOfInteger& aMVEF, |
1304 | BOPCol_DataMapOfIntegerReal& aMVTol) |
4e57c75e |
1305 | { |
78c66ef1 |
1306 | Standard_Boolean bInBothFaces; |
4e57c75e |
1307 | Standard_Integer nV; |
4e57c75e |
1308 | BOPCol_MapIteratorOfMapOfInteger aIt; |
1309 | // |
4e57c75e |
1310 | const Bnd_Box& aBoxC=aNC.Box(); |
1311 | // |
78c66ef1 |
1312 | //Put EF vertices first |
1313 | aIt.Initialize(aMVEF); |
1314 | for (; aIt.More(); aIt.Next()) { |
1315 | nV=aIt.Value(); |
1316 | PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 2); |
1317 | } |
1318 | //Put all other vertices |
4e57c75e |
1319 | aIt.Initialize(aMVOnIn); |
1320 | for (; aIt.More(); aIt.Next()) { |
1321 | nV=aIt.Value(); |
78c66ef1 |
1322 | if (aMVEF.Contains(nV)) { |
1323 | continue; |
4e57c75e |
1324 | } |
1325 | // |
78c66ef1 |
1326 | const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV); |
1327 | const Bnd_Box& aBoxV=aSIV.Box(); |
4e57c75e |
1328 | // |
78c66ef1 |
1329 | if (aBoxC.IsOut(aBoxV)){ |
1330 | continue; |
1331 | } |
1332 | if (!myDS->IsNewShape(nV)) { |
1333 | const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1); |
1334 | const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2); |
b4109929 |
1335 | // |
78c66ef1 |
1336 | bInBothFaces = (aFI1.VerticesOn().Contains(nV) || |
1337 | aFI1.VerticesIn().Contains(nV))&& |
1338 | (aFI2.VerticesOn().Contains(nV) || |
1339 | aFI2.VerticesIn().Contains(nV)); |
1340 | if (!bInBothFaces) { |
1341 | continue; |
b4109929 |
1342 | } |
4e57c75e |
1343 | } |
78c66ef1 |
1344 | // |
1345 | PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 1); |
4e57c75e |
1346 | } |
1347 | } |
1348 | |
1349 | //======================================================================= |
1350 | //function : ExtendedTolerance |
1351 | //purpose : |
1352 | //======================================================================= |
465d1fba |
1353 | Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance |
1354 | (const Standard_Integer nV, |
1355 | const BOPCol_MapOfInteger& aMI, |
1356 | Standard_Real& aTolVExt, |
1357 | const Standard_Integer aType) |
4e57c75e |
1358 | { |
1359 | Standard_Boolean bFound = Standard_False; |
1360 | if (!(myDS->IsNewShape(nV))) { |
1361 | return bFound; |
1362 | } |
78c66ef1 |
1363 | // |
1364 | Standard_Integer i, k, aNbLines, aNbInt; |
4e57c75e |
1365 | Standard_Real aT11, aT12, aD1, aD2, aD; |
1366 | TopoDS_Vertex aV; |
1367 | gp_Pnt aPV, aP11, aP12; |
78c66ef1 |
1368 | // |
1369 | k = 0; |
1370 | aNbInt = 2; |
1371 | if (aType == 1) { |
1372 | aNbInt = 1; |
1373 | } else if (aType == 2) { |
1374 | k = 1; |
1375 | } |
1376 | // |
4e57c75e |
1377 | aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV))); |
1378 | aPV=BRep_Tool::Pnt(aV); |
1379 | // |
1380 | BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE(); |
1381 | BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF(); |
78c66ef1 |
1382 | // |
1383 | for (; k<aNbInt; ++k) { |
4e57c75e |
1384 | aNbLines = !k ? aEEs.Extent() : aEFs.Extent(); |
1385 | for (i = 0; i < aNbLines; ++i) { |
1386 | BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) : |
78c66ef1 |
1387 | (BOPDS_Interf*) (&aEFs(i)); |
4e57c75e |
1388 | if (aInt->IndexNew() == nV) { |
465d1fba |
1389 | if (aMI.Contains(aInt->Index1()) && |
1390 | aMI.Contains(aInt->Index2())) { |
4e57c75e |
1391 | const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() : |
78c66ef1 |
1392 | aEFs(i).CommonPart(); |
4e57c75e |
1393 | // |
1394 | const TopoDS_Edge& aE1=aComPrt.Edge1(); |
1395 | aComPrt.Range1(aT11, aT12); |
1396 | BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11); |
1397 | BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12); |
1398 | aD1=aPV.Distance(aP11); |
1399 | aD2=aPV.Distance(aP12); |
1400 | aD=(aD1>aD2)? aD1 : aD2; |
1401 | if (aD>aTolVExt) { |
1402 | aTolVExt=aD; |
1403 | } |
1404 | return !bFound; |
1405 | }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) { |
1406 | }//if (aInt->IndexNew() == nV) { |
1407 | }//for (i = 0; i < aNbLines; ++i) { |
1408 | }//for (k=0; k<2; ++k) { |
4e57c75e |
1409 | return bFound; |
1410 | } |
1411 | |
1412 | //======================================================================= |
1413 | //function : GetEFPnts |
1414 | //purpose : |
1415 | //======================================================================= |
1416 | void BOPAlgo_PaveFiller::GetEFPnts(const Standard_Integer nF1, |
1417 | const Standard_Integer nF2, |
1418 | IntSurf_ListOfPntOn2S& aListOfPnts) |
1419 | { |
1420 | Standard_Integer nE, nF, nFOpposite, aNbEFs, i; |
1421 | Standard_Real U1, U2, V1, V2, f, l; |
78c66ef1 |
1422 | BOPCol_MapOfInteger aMI; |
4e57c75e |
1423 | // |
1424 | //collect indexes of all shapes from nF1 and nF2. |
78c66ef1 |
1425 | GetFullShapeMap(nF1, aMI); |
1426 | GetFullShapeMap(nF2, aMI); |
4e57c75e |
1427 | // |
1428 | BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF(); |
1429 | aNbEFs = aEFs.Extent(); |
1430 | // |
1431 | for(i = 0; i < aNbEFs; ++i) { |
1432 | const BOPDS_InterfEF& aEF = aEFs(i); |
78c66ef1 |
1433 | if (aEF.HasIndexNew()) { |
1434 | aEF.Indices(nE, nFOpposite); |
1435 | if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) { |
1436 | const IntTools_CommonPrt& aCP = aEF.CommonPart(); |
4e57c75e |
1437 | Standard_Real aPar = aCP.VertexParameter1(); |
1438 | const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE))); |
465d1fba |
1439 | const TopoDS_Face& aFOpposite = |
1440 | (*(TopoDS_Face*)(&myDS->Shape(nFOpposite))); |
4e57c75e |
1441 | // |
1442 | const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l); |
1443 | // |
1444 | nF = (nFOpposite == nF1) ? nF2 : nF1; |
1445 | const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF))); |
465d1fba |
1446 | Handle(Geom2d_Curve) aPCurve = |
1447 | BRep_Tool::CurveOnSurface(aE, aF, f, l); |
4e57c75e |
1448 | // |
465d1fba |
1449 | GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite); |
4e57c75e |
1450 | // |
1451 | gp_Pnt aPoint; |
1452 | aCurve->D0(aPar, aPoint); |
1453 | IntSurf_PntOn2S aPnt; |
1454 | if(!aPCurve.IsNull()) { |
1455 | gp_Pnt2d aP2d = aPCurve->Value(aPar); |
1456 | aProj.Perform(aPoint); |
1457 | if(aProj.IsDone()) { |
1458 | aProj.LowerDistanceParameters(U1,V1); |
1459 | if (nF == nF1) { |
1460 | aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1); |
1461 | } else { |
1462 | aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y()); |
1463 | } |
1464 | aListOfPnts.Append(aPnt); |
1465 | } |
1466 | } |
1467 | else { |
1468 | GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF); |
1469 | aProj1.Perform(aPoint); |
1470 | aProj.Perform(aPoint); |
1471 | if(aProj1.IsDone() && aProj.IsDone()){ |
1472 | aProj1.LowerDistanceParameters(U1,V1); |
1473 | aProj.LowerDistanceParameters(U2,V2); |
1474 | if (nF == nF1) { |
1475 | aPnt.SetValue(U1,V1,U2,V2); |
1476 | } else { |
1477 | aPnt.SetValue(U2,V2,U1,V1); |
1478 | } |
1479 | aListOfPnts.Append(aPnt); |
1480 | } |
1481 | } |
1482 | } |
1483 | } |
1484 | } |
1485 | } |
1486 | |
1487 | //======================================================================= |
1488 | //function : ProcessUnUsedVertices |
1489 | //purpose : |
1490 | //======================================================================= |
465d1fba |
1491 | void BOPAlgo_PaveFiller::PutEFPavesOnCurve |
1492 | (BOPDS_Curve& aNC, |
1493 | const BOPCol_MapOfInteger& aMI, |
1494 | const BOPCol_MapOfInteger& aMVEF, |
1495 | BOPCol_DataMapOfIntegerReal& aMVTol) |
4e57c75e |
1496 | { |
1497 | if (!aMVEF.Extent()) { |
1498 | return; |
1499 | } |
1500 | // |
1501 | const IntTools_Curve& aIC=aNC.Curve(); |
1502 | GeomAbs_CurveType aTypeC; |
1503 | aTypeC=aIC.Type(); |
1504 | if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) { |
1505 | return; |
1506 | } |
1507 | // |
1508 | Standard_Integer nV; |
1509 | BOPCol_MapOfInteger aMV; |
1510 | // |
1511 | aMV.Assign(aMVEF); |
1512 | RemoveUsedVertices(aNC, aMV); |
1513 | if (!aMV.Extent()) { |
1514 | return; |
1515 | } |
1516 | // |
1517 | Standard_Real aDist; |
1518 | BOPDS_Pave aPave; |
1519 | // |
1520 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); |
4e57c75e |
1521 | GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D); |
78c66ef1 |
1522 | // |
4e57c75e |
1523 | BOPCol_MapIteratorOfMapOfInteger aItMI; |
1524 | aItMI.Initialize(aMV); |
1525 | for (; aItMI.More(); aItMI.Next()) { |
1526 | nV = aItMI.Value(); |
1527 | const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV))); |
1528 | gp_Pnt aPV = BRep_Tool::Pnt(aV); |
1529 | aProjPT.Perform(aPV); |
1530 | Standard_Integer aNbPoints = aProjPT.NbPoints(); |
1531 | if (aNbPoints) { |
1532 | aDist = aProjPT.LowerDistance(); |
78c66ef1 |
1533 | PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol); |
4e57c75e |
1534 | } |
1535 | } |
1536 | } |
1537 | |
1538 | //======================================================================= |
1539 | //function : ProcessUnUsedVertices |
1540 | //purpose : |
1541 | //======================================================================= |
465d1fba |
1542 | void BOPAlgo_PaveFiller::PutStickPavesOnCurve |
1543 | (const TopoDS_Face& aF1, |
1544 | const TopoDS_Face& aF2, |
1545 | const BOPCol_MapOfInteger& aMI, |
1546 | BOPDS_Curve& aNC, |
1547 | const BOPCol_MapOfInteger& aMVStick, |
1548 | BOPCol_DataMapOfIntegerReal& aMVTol) |
4e57c75e |
1549 | { |
1550 | BOPCol_MapOfInteger aMV; |
1551 | aMV.Assign(aMVStick); |
1552 | RemoveUsedVertices(aNC, aMV); |
1553 | // |
1554 | if (!aMV.Extent()) { |
1555 | return; |
1556 | } |
1557 | // |
4e57c75e |
1558 | Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1); |
1559 | Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2); |
ec0cdc0e |
1560 | // |
1561 | const IntTools_Curve& aIC=aNC.Curve(); |
ec0cdc0e |
1562 | //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) { |
1563 | Handle(Geom2d_Curve) aC2D[2]; |
1564 | // |
1565 | aC2D[0]=aIC.FirstCurve2d(); |
1566 | aC2D[1]=aIC.SecondCurve2d(); |
1567 | if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) { |
1568 | Standard_Integer nV, m, n; |
1569 | Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr; |
1570 | gp_Pnt aPC[2], aPV; |
1571 | gp_Dir aDN[2]; |
1572 | gp_Pnt2d aP2D; |
1573 | BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1; |
1574 | // |
1575 | aDT2=2e-7; // the rich criteria |
1576 | aDScPr=5.e-9; // the creasing criteria |
1577 | aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]); |
4e57c75e |
1578 | // |
ec0cdc0e |
1579 | aItMI.Initialize(aMV); |
1580 | for (; aItMI.More(); aItMI.Next()) { |
1581 | nV = aItMI.Value(); |
1582 | const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV)); |
1583 | aPV=BRep_Tool::Pnt(aV); |
4e57c75e |
1584 | // |
ec0cdc0e |
1585 | for (m=0; m<2; ++m) { |
1586 | aD2=aPC[m].SquareDistance(aPV); |
1587 | if (aD2>aDT2) {// no rich |
1588 | continue; |
1589 | } |
78c66ef1 |
1590 | // |
ec0cdc0e |
1591 | for (n=0; n<2; ++n) { |
1592 | Handle(Geom_Surface)& aS=(!n)? aS1 : aS2; |
1593 | aC2D[n]->D0(aTC[m], aP2D); |
1594 | aP2D.Coord(u, v); |
1595 | BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]); |
1596 | } |
1597 | // |
1598 | aScPr=aDN[0]*aDN[1]; |
1599 | if (aScPr<0.) { |
1600 | aScPr=-aScPr; |
1601 | } |
1602 | aScPr=1.-aScPr; |
78c66ef1 |
1603 | // |
ec0cdc0e |
1604 | if (aScPr>aDScPr) { |
1605 | continue; |
1606 | } |
1607 | // |
1608 | // The intersection curve aIC is vanishing curve (the crease) |
1609 | aD=sqrt(aD2); |
1610 | // |
1611 | PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol); |
4e57c75e |
1612 | } |
ec0cdc0e |
1613 | }//for (jVU=1; jVU=aNbVU; ++jVU) { |
1614 | } |
1615 | //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) { |
1616 | //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) { |
4e57c75e |
1617 | } |
1618 | |
1619 | //======================================================================= |
1620 | //function : GetStickVertices |
1621 | //purpose : |
1622 | //======================================================================= |
1623 | void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1, |
1624 | const Standard_Integer nF2, |
1625 | BOPCol_MapOfInteger& aMVStick, |
78c66ef1 |
1626 | BOPCol_MapOfInteger& aMVEF, |
1627 | BOPCol_MapOfInteger& aMI) |
4e57c75e |
1628 | { |
78c66ef1 |
1629 | Standard_Integer nS1, nS2, nVNew, aTypeInt, i; |
4e57c75e |
1630 | // |
1631 | BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV(); |
1632 | BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE(); |
1633 | BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE(); |
1634 | BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF(); |
1635 | BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF(); |
1636 | // |
465d1fba |
1637 | Standard_Integer aNbLines[5] = { |
1638 | aVVs.Extent(), aVEs.Extent(), aEEs.Extent(), |
1639 | aVFs.Extent(), aEFs.Extent() |
1640 | }; |
78c66ef1 |
1641 | //collect indices of all shapes from nF1 and nF2. |
1642 | aMI.Clear(); |
1643 | GetFullShapeMap(nF1, aMI); |
1644 | GetFullShapeMap(nF2, aMI); |
1645 | // |
1646 | //collect VV, VE, EE, VF interferences |
1647 | for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) { |
1648 | for (i = 0; i < aNbLines[aTypeInt]; ++i) { |
1649 | BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) : |
1650 | ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) : |
465d1fba |
1651 | ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) : |
1652 | (BOPDS_Interf*)(&aVFs(i)))); |
78c66ef1 |
1653 | if (aInt->HasIndexNew()) { |
1654 | aInt->Indices(nS1, nS2); |
1655 | if(aMI.Contains(nS1) && aMI.Contains(nS2)) { |
1656 | nVNew = aInt->IndexNew(); |
1657 | aMVStick.Add(nVNew); |
1658 | } |
4e57c75e |
1659 | } |
1660 | } |
1661 | } |
4e57c75e |
1662 | //collect EF interferences |
78c66ef1 |
1663 | for (i = 0; i < aNbLines[4]; ++i) { |
1664 | const BOPDS_InterfEF& aInt = aEFs(i); |
1665 | if (aInt.HasIndexNew()) { |
1666 | aInt.Indices(nS1, nS2); |
1667 | if(aMI.Contains(nS1) && aMI.Contains(nS2)) { |
1668 | nVNew = aInt.IndexNew(); |
4e57c75e |
1669 | aMVStick.Add(nVNew); |
1670 | aMVEF.Add(nVNew); |
1671 | } |
1672 | } |
1673 | } |
1674 | } |
1675 | |
1676 | //======================================================================= |
78c66ef1 |
1677 | // function: GetFullShapeMap |
4e57c75e |
1678 | // purpose: |
1679 | //======================================================================= |
78c66ef1 |
1680 | void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF, |
1681 | BOPCol_MapOfInteger& aMI) |
4e57c75e |
1682 | { |
78c66ef1 |
1683 | BOPCol_ListIteratorOfListOfInteger aIt; |
1684 | Standard_Integer nS; |
1685 | // |
1686 | const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF); |
1687 | const BOPCol_ListOfInteger& aLI = aSI.SubShapes(); |
1688 | // |
4e57c75e |
1689 | aMI.Add(nF); |
78c66ef1 |
1690 | aIt.Initialize(aLI); |
1691 | for (; aIt.More(); aIt.Next()) { |
1692 | nS = aIt.Value(); |
1693 | aMI.Add(nS); |
4e57c75e |
1694 | } |
1695 | } |
1696 | |
1697 | //======================================================================= |
1698 | // function: RemoveUsedVertices |
1699 | // purpose: |
1700 | //======================================================================= |
1701 | void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC, |
1702 | BOPCol_MapOfInteger& aMV) |
1703 | { |
1704 | if (!aMV.Extent()) { |
1705 | return; |
1706 | } |
1707 | Standard_Integer nV; |
1708 | BOPDS_Pave aPave; |
1709 | BOPDS_ListIteratorOfListOfPave aItLP; |
1710 | // |
1711 | Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1(); |
1712 | const BOPDS_ListOfPave& aLP = aPB->ExtPaves(); |
1713 | aItLP.Initialize(aLP); |
1714 | for (;aItLP.More();aItLP.Next()) { |
1715 | aPave = aItLP.Value(); |
1716 | nV = aPave.Index(); |
1717 | aMV.Remove(nV); |
1718 | } |
1719 | } |
1720 | |
1721 | //======================================================================= |
1722 | //function : PutPaveOnCurve |
1723 | //purpose : |
1724 | //======================================================================= |
465d1fba |
1725 | void BOPAlgo_PaveFiller::PutPaveOnCurve |
1726 | (const Standard_Integer nV, |
1727 | const Standard_Real aTolR3D, |
1728 | BOPDS_Curve& aNC, |
1729 | const BOPCol_MapOfInteger& aMI, |
1730 | BOPCol_DataMapOfIntegerReal& aMVTol, |
1731 | const Standard_Integer iCheckExtend) |
4e57c75e |
1732 | { |
1733 | Standard_Boolean bIsVertexOnLine; |
b4109929 |
1734 | Standard_Real aT, aTol, aTolNew; |
4e57c75e |
1735 | BOPDS_Pave aPave; |
1736 | // |
1737 | const TopoDS_Vertex aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV))); |
78c66ef1 |
1738 | Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1(); |
4e57c75e |
1739 | const IntTools_Curve& aIC = aNC.Curve(); |
1740 | // |
1741 | bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT); |
78c66ef1 |
1742 | if (!bIsVertexOnLine && iCheckExtend) { |
1743 | aTol = BRep_Tool::Tolerance(aV); |
1744 | // |
1745 | ExtendedTolerance(nV, aMI, aTol, iCheckExtend); |
1746 | bIsVertexOnLine=myContext->IsVertexOnLine(aV, aTol, aIC, aTolR3D, aT); |
1747 | } |
1748 | // |
4e57c75e |
1749 | if (bIsVertexOnLine) { |
1750 | aPave.SetIndex(nV); |
1751 | aPave.SetParameter(aT); |
1752 | // |
1753 | aPB->AppendExtPave(aPave); |
1754 | // |
b4109929 |
1755 | aTol = BRep_Tool::Tolerance(aV); |
1756 | // |
4e57c75e |
1757 | BOPTools_AlgoTools::UpdateVertex (aIC, aT, aV); |
b4109929 |
1758 | // |
1759 | if (!aMVTol.IsBound(nV)) { |
1760 | aTolNew = BRep_Tool::Tolerance(aV); |
1761 | if (aTolNew > aTol) { |
1762 | aMVTol.Bind(nV, aTol); |
1763 | } |
1764 | } |
4e57c75e |
1765 | // |
1766 | BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV); |
1767 | Bnd_Box& aBoxDS=aSIDS.ChangeBox(); |
1768 | BRepBndLib::Add(aV, aBoxDS); |
1769 | } |
1770 | } |
1771 | |
1772 | //======================================================================= |
1773 | //function : ProcessOldPaveBlocks |
1774 | //purpose : |
1775 | //======================================================================= |
1776 | void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks |
1777 | (const Standard_Integer theInt, |
decdfc94 |
1778 | const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn, |
4e57c75e |
1779 | BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB, |
1780 | BOPCol_DataMapOfShapeInteger& aMVI, |
1781 | const BOPCol_MapOfInteger& aMVB, |
1782 | BOPDS_MapOfPaveBlock& aMPB) |
1783 | { |
decdfc94 |
1784 | Standard_Integer nV, nE, iFlag, i, aNbPB; |
4e57c75e |
1785 | Standard_Real aT; |
1786 | BOPCol_MapIteratorOfMapOfInteger aItB; |
4e57c75e |
1787 | // |
1788 | BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
1789 | BOPDS_InterfFF& aFF = aFFs(theInt); |
1790 | BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves(); |
1791 | // |
1792 | aItB.Initialize(aMVB); |
1793 | for (; aItB.More(); aItB.Next()) { |
1794 | nV = aItB.Value(); |
1795 | const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV); |
1796 | const Bnd_Box& aBoxV=aSIV.Box(); |
1797 | const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape(); |
1798 | if (!aMVI.IsBound(aV)) { |
1799 | continue; |
1800 | } |
1801 | // |
decdfc94 |
1802 | aNbPB = aMPBOnIn.Extent(); |
1803 | for (i = 1; i <= aNbPB; ++i) { |
1804 | const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i); |
4e57c75e |
1805 | if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) { |
1806 | continue; |
1807 | } |
1808 | // |
1809 | if (aMPB.Contains(aPB)) { |
1810 | continue; |
1811 | } |
1812 | nE=aPB->Edge(); |
1813 | const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE); |
1814 | const Bnd_Box& aBoxE=aSIE.Box(); |
1815 | // |
1816 | if (!aBoxV.IsOut(aBoxE)) { |
1817 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape(); |
1818 | // |
1819 | iFlag=myContext->ComputeVE (aV, aE, aT); |
1820 | if (!iFlag) { |
1821 | aMPB.Add(aPB); |
1822 | // |
1823 | PreparePostTreatFF(theInt, aPB, aMSCPB, aMVI, aVC); |
1824 | } |
1825 | } |
1826 | } |
1827 | } |
1828 | } |
4e57c75e |
1829 | //======================================================================= |
1830 | //function : UpdateExistingPaveBlocks |
1831 | //purpose : |
1832 | //======================================================================= |
1833 | void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks |
1834 | (const Handle(BOPDS_PaveBlock)& aPBf, |
1835 | BOPDS_ListOfPaveBlock& aLPB, |
1836 | const Standard_Integer nF1, |
1837 | const Standard_Integer nF2) |
1838 | { |
1839 | Standard_Integer nE; |
1840 | Standard_Boolean bCB; |
1841 | Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n; |
1842 | Handle(BOPDS_CommonBlock) aCB; |
1843 | BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2; |
4e57c75e |
1844 | // |
1b7ae951 |
1845 | // 1. Remove micro edges from aLPB |
4e57c75e |
1846 | aIt.Initialize(aLPB); |
1847 | for (; aIt.More();) { |
1848 | aPB = aIt.Value(); |
1849 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge()); |
1850 | if (BOPTools_AlgoTools::IsMicroEdge(aE, myContext)) { |
1851 | aLPB.Remove(aIt); |
1852 | continue; |
1853 | } |
1854 | aIt.Next(); |
1855 | } |
1856 | // |
1857 | if (!aLPB.Extent()) { |
1858 | return; |
1859 | } |
4e57c75e |
1860 | // |
1861 | BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1); |
1862 | BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2); |
1863 | // |
1864 | BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn(); |
1865 | BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn(); |
1866 | BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn(); |
1867 | BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn(); |
1868 | // |
1b7ae951 |
1869 | // 2. Remove old pave blocks |
5a77460e |
1870 | const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf); |
4e57c75e |
1871 | bCB = !aCB1.IsNull(); |
1872 | BOPDS_ListOfPaveBlock aLPB1; |
1873 | // |
1874 | if (bCB) { |
1875 | aLPB1.Assign(aCB1->PaveBlocks()); |
1876 | } else { |
1877 | aLPB1.Append(aPBf); |
1878 | } |
1879 | aIt1.Initialize(aLPB1); |
1880 | for (; aIt1.More(); aIt1.Next()) { |
1881 | aPB1 = aIt1.Value(); |
1882 | nE = aPB1->OriginalEdge(); |
1883 | // |
1884 | BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE); |
1885 | aIt2.Initialize(aLPB2); |
1886 | for (; aIt2.More(); aIt2.Next()) { |
1887 | aPB2 = aIt2.Value(); |
1888 | if (aPB1 == aPB2) { |
1889 | aLPB2.Remove(aIt2); |
1890 | break; |
1891 | } |
1892 | } |
1893 | } |
1894 | // |
1b7ae951 |
1895 | // 3. Update pave blocks |
4e57c75e |
1896 | if (bCB) { |
1b7ae951 |
1897 | //create new common blocks |
4e57c75e |
1898 | const BOPCol_ListOfInteger& aFaces = aCB1->Faces(); |
1899 | aIt.Initialize(aLPB); |
1900 | for (; aIt.More(); aIt.Next()) { |
1901 | Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue(); |
1902 | // |
1903 | aCB = new BOPDS_CommonBlock; |
1904 | aIt1.Initialize(aLPB1); |
1905 | for (; aIt1.More(); aIt1.Next()) { |
1906 | aPB2 = aIt1.Value(); |
1907 | nE = aPB2->OriginalEdge(); |
1908 | // |
1909 | aPB2n = new BOPDS_PaveBlock; |
1910 | aPB2n->SetPave1(aPB->Pave1()); |
1911 | aPB2n->SetPave2(aPB->Pave2()); |
1912 | aPB2n->SetEdge(aPB->Edge()); |
1913 | aPB2n->SetOriginalEdge(nE); |
1914 | aCB->AddPaveBlock(aPB2n); |
5a77460e |
1915 | myDS->SetCommonBlock(aPB2n, aCB); |
4e57c75e |
1916 | myDS->ChangePaveBlocks(nE).Append(aPB2n); |
1917 | } |
1918 | aCB->AddFaces(aFaces); |
1919 | myDS->SortPaveBlocks(aCB); |
1920 | // |
1921 | aPB=aCB->PaveBlocks().First(); |
1922 | } |
1923 | } |
1b7ae951 |
1924 | else { |
1925 | nE = aPBf->OriginalEdge(); |
1926 | BOPDS_ListOfPaveBlock& aLPBE = myDS->ChangePaveBlocks(nE); |
1927 | aIt.Initialize(aLPB); |
1928 | for (; aIt.More(); aIt.Next()) { |
1929 | aPB = aIt.Value(); |
1930 | aLPBE.Append(aPB); |
4e57c75e |
1931 | } |
1932 | } |
1933 | // |
4e57c75e |
1934 | Standard_Boolean bIn1, bIn2; |
1935 | // |
1936 | bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf); |
1937 | bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf); |
1938 | // |
1b7ae951 |
1939 | if (bIn1 && bIn2) { |
1940 | return; |
1941 | } |
1942 | // |
1943 | // 4. Check new pave blocks for coincidence |
1944 | // with the opposite face. |
1945 | // In case of coincidence create common blocks |
1946 | Standard_Integer nF; |
1947 | Standard_Real aTolE, aTolF; |
1948 | // |
1949 | nF = bIn1 ? nF2 : nF1; |
1950 | const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF); |
1951 | BOPDS_IndexedMapOfPaveBlock& aMPBIn = bIn1 ? aMPBIn2 : aMPBIn1; |
1952 | aTolF = BRep_Tool::Tolerance(aF); |
1953 | // |
1954 | aIt.Initialize(aLPB); |
1955 | for (; aIt.More(); aIt.Next()) { |
1956 | Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue(); |
1957 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge()); |
1958 | aTolE = BRep_Tool::Tolerance(aE); |
1959 | // |
1960 | IntTools_EdgeFace anEF; |
1961 | anEF.SetEdge(aE); |
1962 | anEF.SetFace(aF); |
1963 | anEF.SetTolE(aTolE); |
1964 | anEF.SetTolF(aTolF); |
1965 | anEF.SetRange(aPB->Pave1().Parameter(), aPB->Pave2().Parameter()); |
1966 | anEF.SetContext(myContext); |
1967 | anEF.Perform(); |
4e57c75e |
1968 | // |
1b7ae951 |
1969 | const IntTools_SequenceOfCommonPrts& aCPrts=anEF.CommonParts(); |
1970 | if (aCPrts.Length() == 1) { |
1971 | Standard_Boolean bCoinc = (aCPrts(1).Type() == TopAbs_EDGE); |
1972 | if (bCoinc) { |
1973 | if (bCB) { |
1974 | aCB = myDS->CommonBlock(aPB); |
1975 | } else { |
1976 | aCB = new BOPDS_CommonBlock; |
1977 | aCB->AddPaveBlock(aPB); |
1978 | myDS->SetCommonBlock(aPB, aCB); |
1979 | } |
1980 | aCB->AddFace(nF); |
1981 | // |
1982 | aMPBIn.Add(aPB); |
1983 | } |
4e57c75e |
1984 | } |
1985 | } |
1986 | } |
4e57c75e |
1987 | //======================================================================= |
1988 | // function: PutClosingPaveOnCurve |
1989 | // purpose: |
1990 | //======================================================================= |
1991 | void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC) |
1992 | { |
1993 | Standard_Boolean bIsClosed, bHasBounds, bAdded; |
1994 | Standard_Integer nVC, j; |
1995 | Standard_Real aT[2], aTC, dT, aTx; |
1996 | gp_Pnt aP[2] ; |
1997 | BOPDS_Pave aPVx; |
1998 | BOPDS_ListIteratorOfListOfPave aItLP; |
1999 | // |
2000 | const IntTools_Curve& aIC=aNC.Curve(); |
2001 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); |
2002 | if(aC3D.IsNull()) { |
2003 | return; |
2004 | } |
2005 | // |
2006 | bIsClosed=IntTools_Tools::IsClosed(aC3D); |
2007 | if (!bIsClosed) { |
2008 | return; |
2009 | } |
2010 | // |
2011 | bHasBounds=aIC.HasBounds (); |
2012 | if (!bHasBounds){ |
2013 | return; |
2014 | } |
2015 | // |
2016 | bAdded=Standard_False; |
2017 | dT=Precision::PConfusion(); |
2018 | aIC.Bounds (aT[0], aT[1], aP[0], aP[1]); |
2019 | // |
2020 | Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1(); |
2021 | BOPDS_ListOfPave& aLP=aPB->ChangeExtPaves(); |
2022 | // |
2023 | aItLP.Initialize(aLP); |
2024 | for (; aItLP.More() && !bAdded; aItLP.Next()) { |
2025 | const BOPDS_Pave& aPC=aItLP.Value(); |
2026 | nVC=aPC.Index(); |
2027 | aTC=aPC.Parameter(); |
2028 | // |
2029 | for (j=0; j<2; ++j) { |
2030 | if (fabs(aTC-aT[j]) < dT) { |
2031 | aTx=(!j) ? aT[1] : aT[0]; |
2032 | aPVx.SetIndex(nVC); |
2033 | aPVx.SetParameter(aTx); |
2034 | aLP.Append(aPVx); |
2035 | // |
2036 | bAdded=Standard_True; |
2037 | break; |
2038 | } |
2039 | } |
2040 | } |
2041 | } |
4e57c75e |
2042 | //======================================================================= |
2043 | //function : PreparePostTreatFF |
2044 | //purpose : |
2045 | //======================================================================= |
2046 | void BOPAlgo_PaveFiller::PreparePostTreatFF |
2047 | (const Standard_Integer aInt, |
2048 | const Handle(BOPDS_PaveBlock)& aPB, |
2049 | BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB, |
2050 | BOPCol_DataMapOfShapeInteger& aMVI, |
2051 | BOPDS_VectorOfCurve& aVC) |
2052 | { |
2053 | Standard_Integer nV1, nV2; |
2054 | // |
2055 | Standard_Integer iC=aVC.Append()-1; |
2056 | BOPDS_ListOfPaveBlock& aLPBC = aVC(iC).ChangePaveBlocks(); |
2057 | aLPBC.Append(aPB); |
2058 | // |
2059 | aPB->Indices(nV1, nV2); |
2060 | const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1))); |
2061 | const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2))); |
2062 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge()); |
2063 | // Keep info for post treatment |
2064 | BOPDS_CoupleOfPaveBlocks aCPB; |
2065 | aCPB.SetIndexInterf(aInt); |
2066 | aCPB.SetIndex(iC); |
2067 | aCPB.SetPaveBlock1(aPB); |
2068 | // |
2069 | aMSCPB.Add(aE, aCPB); |
2070 | aMVI.Bind(aV1, nV1); |
2071 | aMVI.Bind(aV2, nV2); |
2072 | } |
2073 | |
b4109929 |
2074 | //======================================================================= |
2075 | //function : CheckPlanes |
2076 | //purpose : |
2077 | //======================================================================= |
465d1fba |
2078 | Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes |
2079 | (const Standard_Integer nF1, |
2080 | const Standard_Integer nF2)const |
b4109929 |
2081 | { |
2082 | Standard_Boolean bToIntersect; |
af4e6dab |
2083 | Standard_Integer i, nV2, iCnt; |
b4109929 |
2084 | BOPCol_MapIteratorOfMapOfInteger aIt; |
2085 | // |
af4e6dab |
2086 | bToIntersect=Standard_False; |
b4109929 |
2087 | // |
af4e6dab |
2088 | const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1); |
2089 | const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2); |
b4109929 |
2090 | // |
af4e6dab |
2091 | const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn(); |
2092 | const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn(); |
b4109929 |
2093 | // |
af4e6dab |
2094 | iCnt=0; |
2095 | for (i=0; (i<2 && !bToIntersect); ++i) { |
2096 | const BOPCol_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn() |
2097 | : aFI2.VerticesOn(); |
2098 | // |
2099 | aIt.Initialize(aMV2); |
b4109929 |
2100 | for (; aIt.More(); aIt.Next()) { |
af4e6dab |
2101 | nV2=aIt.Value(); |
2102 | if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) { |
78c66ef1 |
2103 | ++iCnt; |
2104 | if (iCnt>1) { |
2105 | bToIntersect=!bToIntersect; |
2106 | break; |
2107 | } |
b4109929 |
2108 | } |
2109 | } |
2110 | } |
b4109929 |
2111 | // |
2112 | return bToIntersect; |
2113 | } |
4e57c75e |
2114 | //======================================================================= |
78c66ef1 |
2115 | //function : UpdatePaveBlocks |
2116 | //purpose : |
2117 | //======================================================================= |
465d1fba |
2118 | void BOPAlgo_PaveFiller::UpdatePaveBlocks |
2119 | (const BOPCol_DataMapOfIntegerInteger& aDMI) |
78c66ef1 |
2120 | { |
2121 | if (aDMI.IsEmpty()) { |
2122 | return; |
2123 | } |
2124 | // |
2125 | Standard_Integer nSp, aNbPBP, nV[2], i, j; |
2126 | Standard_Real aT[2]; |
2127 | Standard_Boolean bCB, bRebuild; |
2128 | BOPDS_ListIteratorOfListOfPaveBlock aItPB; |
2129 | BOPDS_MapOfPaveBlock aMPB; |
2130 | // |
2131 | BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool(); |
2132 | aNbPBP = aPBP.Extent(); |
2133 | for (i=0; i<aNbPBP; ++i) { |
2134 | BOPDS_ListOfPaveBlock& aLPB=aPBP(i); |
2135 | // |
2136 | aItPB.Initialize(aLPB); |
2137 | for (; aItPB.More(); aItPB.Next()) { |
2138 | Handle(BOPDS_PaveBlock) aPB=aItPB.Value(); |
2139 | const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB); |
2140 | bCB = !aCB.IsNull(); |
2141 | if (bCB) { |
2142 | aPB=aCB->PaveBlock1(); |
2143 | } |
2144 | // |
2145 | if (aMPB.Add(aPB)) { |
2146 | bRebuild = Standard_False; |
2147 | aPB->Indices(nV[0], nV[1]); |
2148 | aPB->Range(aT[0], aT[1]); |
2149 | // |
2150 | for (j = 0; j < 2; ++j) { |
2151 | if (aDMI.IsBound(nV[j])) { |
2152 | BOPDS_Pave aPave; |
2153 | // |
2154 | nV[j] = aDMI.Find(nV[j]); |
2155 | aPave.SetIndex(nV[j]); |
2156 | aPave.SetParameter(aT[j]); |
2157 | // |
2158 | bRebuild = Standard_True; |
2159 | if (!j) { |
2160 | aPB->SetPave1(aPave); |
2161 | } else { |
2162 | aPB->SetPave2(aPave); |
2163 | } |
2164 | } |
2165 | } |
2166 | // |
2167 | if (bRebuild) { |
2168 | nSp = SplitEdge(aPB->Edge(), nV[0], aT[0], nV[1], aT[1]); |
2169 | if (bCB) { |
2170 | aCB->SetEdge(nSp); |
2171 | } |
2172 | else { |
2173 | aPB->SetEdge(nSp); |
2174 | } |
2175 | }// if (bRebuild) { |
2176 | }// if (aMPB.Add(aPB)) { |
2177 | }// for (; aItPB.More(); aItPB.Next()) { |
2178 | }// for (i=0; i<aNbPBP; ++i) { |
2179 | aMPB.Clear(); |
2180 | } |
2181 | //======================================================================= |
4e57c75e |
2182 | //function : ToleranceFF |
2183 | //purpose : Computes the TolFF according to the tolerance value and |
2184 | // types of the faces. |
2185 | //======================================================================= |
b4109929 |
2186 | void ToleranceFF(const BRepAdaptor_Surface& aBAS1, |
2187 | const BRepAdaptor_Surface& aBAS2, |
4e57c75e |
2188 | Standard_Real& aTolFF) |
2189 | { |
2190 | Standard_Real aTol1, aTol2; |
2191 | Standard_Boolean isAna1, isAna2; |
2192 | // |
b4109929 |
2193 | aTol1 = aBAS1.Tolerance(); |
2194 | aTol2 = aBAS2.Tolerance(); |
4e57c75e |
2195 | aTolFF = Max(aTol1, aTol2); |
2196 | // |
b4109929 |
2197 | isAna1 = (aBAS1.GetType() == GeomAbs_Plane || |
2198 | aBAS1.GetType() == GeomAbs_Cylinder || |
2199 | aBAS1.GetType() == GeomAbs_Cone || |
2200 | aBAS1.GetType() == GeomAbs_Sphere || |
2201 | aBAS1.GetType() == GeomAbs_Torus); |
4e57c75e |
2202 | // |
b4109929 |
2203 | isAna2 = (aBAS2.GetType() == GeomAbs_Plane || |
2204 | aBAS2.GetType() == GeomAbs_Cylinder || |
2205 | aBAS2.GetType() == GeomAbs_Cone || |
2206 | aBAS2.GetType() == GeomAbs_Sphere || |
2207 | aBAS2.GetType() == GeomAbs_Torus); |
4e57c75e |
2208 | // |
b4109929 |
2209 | if (!isAna1 || !isAna2) { |
2210 | aTolFF = Max(aTolFF, 5.e-6); |
2211 | } |
4e57c75e |
2212 | } |