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 | |
4e57c75e |
18 | |
3510db62 |
19 | #include <Precision.hxx> |
20 | |
4e57c75e |
21 | #include <Bnd_Box.hxx> |
42cf5bc1 |
22 | #include <BOPAlgo_PaveFiller.hxx> |
23 | #include <BOPAlgo_SectionAttribute.hxx> |
24 | #include <BOPAlgo_Tools.hxx> |
25 | #include <BOPCol_MapOfInteger.hxx> |
26 | #include <BOPCol_NCVector.hxx> |
27 | #include <BOPCol_Parallel.hxx> |
3510db62 |
28 | #include <BOPCol_DataMapOfShapeReal.hxx> |
42cf5bc1 |
29 | #include <BOPDS_CommonBlock.hxx> |
30 | #include <BOPDS_CoupleOfPaveBlocks.hxx> |
31 | #include <BOPDS_Curve.hxx> |
32 | #include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx> |
33 | #include <BOPDS_DS.hxx> |
34 | #include <BOPDS_Interf.hxx> |
35 | #include <BOPDS_Iterator.hxx> |
36 | #include <BOPDS_MapOfPaveBlock.hxx> |
37 | #include <BOPDS_Pave.hxx> |
38 | #include <BOPDS_PaveBlock.hxx> |
39 | #include <BOPTools_AlgoTools.hxx> |
01b5b3df |
40 | #include <BndLib_Add3dCurve.hxx> |
42cf5bc1 |
41 | #include <BRep_Builder.hxx> |
4e57c75e |
42 | #include <BRep_Tool.hxx> |
e30616a7 |
43 | #include <BRepAdaptor_Curve.hxx> |
42cf5bc1 |
44 | #include <BRepBndLib.hxx> |
45 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
46 | #include <gp_Pnt.hxx> |
47 | #include <IntTools_CommonPrt.hxx> |
48 | #include <IntTools_Context.hxx> |
4e57c75e |
49 | #include <IntTools_EdgeFace.hxx> |
50 | #include <IntTools_Range.hxx> |
51 | #include <IntTools_SequenceOfCommonPrts.hxx> |
42cf5bc1 |
52 | #include <IntTools_Tools.hxx> |
3510db62 |
53 | #include <TopoDS.hxx> |
42cf5bc1 |
54 | #include <TopoDS_Edge.hxx> |
55 | #include <TopoDS_Face.hxx> |
56 | #include <TopoDS_Vertex.hxx> |
57 | |
e30616a7 |
58 | //======================================================================= |
59 | //class : BOPAlgo_EdgeFace |
60 | //purpose : |
61 | //======================================================================= |
36f4947b |
62 | class BOPAlgo_EdgeFace : |
63 | public IntTools_EdgeFace, |
64 | public BOPAlgo_Algo { |
65 | |
e30616a7 |
66 | public: |
36f4947b |
67 | DEFINE_STANDARD_ALLOC |
68 | |
69 | BOPAlgo_EdgeFace() : |
70 | IntTools_EdgeFace(), |
71 | BOPAlgo_Algo(), |
72 | myIE(-1), myIF(-1) { |
e30616a7 |
73 | }; |
74 | // |
36f4947b |
75 | virtual ~BOPAlgo_EdgeFace(){ |
e30616a7 |
76 | }; |
77 | // |
78 | void SetIndices(const Standard_Integer nE, |
79 | const Standard_Integer nF) { |
80 | myIE=nE; |
81 | myIF=nF; |
82 | } |
83 | // |
84 | void Indices(Standard_Integer& nE, |
85 | Standard_Integer& nF) { |
86 | nE=myIE; |
87 | nF=myIF; |
88 | } |
89 | // |
90 | void SetNewSR(const IntTools_Range& aR){ |
91 | myNewSR=aR; |
92 | } |
93 | // |
94 | IntTools_Range& NewSR(){ |
95 | return myNewSR; |
96 | } |
97 | // |
98 | void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) { |
99 | myPB=aPB; |
100 | } |
101 | // |
102 | Handle(BOPDS_PaveBlock)& PaveBlock() { |
103 | return myPB; |
104 | } |
105 | // |
0d0481c7 |
106 | void SetFuzzyValue(const Standard_Real theFuzz) { |
107 | IntTools_EdgeFace::SetFuzzyValue(theFuzz); |
108 | } |
109 | // |
36f4947b |
110 | virtual void Perform() { |
111 | BOPAlgo_Algo::UserBreak(); |
112 | IntTools_EdgeFace::Perform(); |
113 | } |
114 | // |
e30616a7 |
115 | protected: |
116 | Standard_Integer myIE; |
117 | Standard_Integer myIF; |
118 | IntTools_Range myNewSR; |
119 | Handle(BOPDS_PaveBlock) myPB; |
120 | }; |
121 | // |
122 | //======================================================================= |
123 | typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace; |
124 | // |
c7b59798 |
125 | typedef BOPCol_ContextFunctor |
e30616a7 |
126 | <BOPAlgo_EdgeFace, |
127 | BOPAlgo_VectorOfEdgeFace, |
1e143abb |
128 | Handle(IntTools_Context), |
129 | IntTools_Context> BOPAlgo_EdgeFaceFunctor; |
e30616a7 |
130 | // |
c7b59798 |
131 | typedef BOPCol_ContextCnt |
e30616a7 |
132 | <BOPAlgo_EdgeFaceFunctor, |
133 | BOPAlgo_VectorOfEdgeFace, |
1e143abb |
134 | Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt; |
e30616a7 |
135 | // |
4e57c75e |
136 | //======================================================================= |
137 | //function : PerformEF |
138 | //purpose : |
139 | //======================================================================= |
e30616a7 |
140 | void BOPAlgo_PaveFiller::PerformEF() |
4e57c75e |
141 | { |
4e57c75e |
142 | myErrorStatus=0; |
143 | // |
e30616a7 |
144 | FillShrunkData(TopAbs_EDGE, TopAbs_FACE); |
145 | // |
4e57c75e |
146 | myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE); |
483ce1bd |
147 | Standard_Integer iSize = myIterator->ExpectedLength(); |
4e57c75e |
148 | if (!iSize) { |
149 | return; |
150 | } |
e30616a7 |
151 | // |
483ce1bd |
152 | Standard_Integer nE, nF; |
153 | // |
154 | if (myGlue == BOPAlgo_GlueFull) { |
155 | // there is no need to intersect edges with faces in this mode |
156 | // just initialize FaceInfo for faces |
157 | for (; myIterator->More(); myIterator->Next()) { |
25dfc507 |
158 | myIterator->Value(nE, nF); |
159 | if (!myDS->ShapeInfo(nE).HasFlag()) { |
483ce1bd |
160 | myDS->ChangeFaceInfo(nF); |
161 | } |
162 | } |
163 | return; |
164 | } |
165 | // |
166 | Standard_Boolean bV[2], bIsPBSplittable; |
6dc83e21 |
167 | Standard_Boolean bV1, bV2, bExpressCompute; |
168 | Standard_Integer nV1, nV2; |
483ce1bd |
169 | Standard_Integer aDiscretize, i, aNbCPrts, iX, nV[2]; |
e30616a7 |
170 | Standard_Integer aNbEdgeFace, k; |
b4109929 |
171 | Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection; |
488e5b9d |
172 | Handle(NCollection_BaseAllocator) aAllocator; |
4e57c75e |
173 | TopAbs_ShapeEnum aType; |
174 | BOPDS_ListIteratorOfListOfPaveBlock aIt; |
e30616a7 |
175 | BOPAlgo_VectorOfEdgeFace aVEdgeFace; |
e30616a7 |
176 | //-----------------------------------------------------scope f |
4e57c75e |
177 | // |
488e5b9d |
178 | aAllocator=NCollection_BaseAllocator::CommonBaseAllocator(); |
179 | // |
4e57c75e |
180 | BOPCol_MapOfInteger aMIEFC(100, aAllocator); |
181 | BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator); |
182 | BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, aAllocator); |
01b5b3df |
183 | BOPAlgo_DataMapOfPaveBlockBndBox aDMPBBox(100, aAllocator); |
4e57c75e |
184 | // |
185 | aDiscretize=35; |
186 | aDeflection=0.01; |
187 | // |
188 | BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF(); |
4e57c75e |
189 | aEFs.SetIncrement(iSize); |
4e57c75e |
190 | // |
191 | for (; myIterator->More(); myIterator->Next()) { |
25dfc507 |
192 | myIterator->Value(nE, nF); |
4e57c75e |
193 | // |
194 | const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE); |
195 | if (aSIE.HasFlag()){//degenerated |
196 | continue; |
197 | } |
198 | // |
199 | const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape())); |
200 | const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); |
201 | const Bnd_Box& aBBF=myDS->ShapeInfo(nF).Box(); |
202 | // |
203 | BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF); |
204 | const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn(); |
4e57c75e |
205 | // |
6dc83e21 |
206 | const BOPCol_MapOfInteger& aMVIn=aFI.VerticesIn(); |
207 | const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn(); |
208 | // |
4e57c75e |
209 | aTolE=BRep_Tool::Tolerance(aE); |
210 | aTolF=BRep_Tool::Tolerance(aF); |
211 | // |
212 | BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE); |
213 | aIt.Initialize(aLPB); |
214 | for (; aIt.More(); aIt.Next()) { |
215 | Handle(BOPDS_PaveBlock)& aPB=aIt.ChangeValue(); |
216 | // |
5a77460e |
217 | const Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB); |
4e57c75e |
218 | if (aMPBF.Contains(aPBR)) { |
219 | continue; |
220 | } |
221 | // |
01b5b3df |
222 | Bnd_Box aBBE; |
223 | if (!GetPBBox(aE, aPB, aDMPBBox, aT1, aT2, aTS1, aTS2, aBBE)) { |
e30616a7 |
224 | continue; |
4e57c75e |
225 | } |
226 | // |
4e57c75e |
227 | if (aBBF.IsOut (aBBE)) { |
228 | continue; |
229 | } |
230 | // |
6dc83e21 |
231 | aPBR->Indices(nV1, nV2); |
232 | bV1=aMVIn.Contains(nV1) || aMVOn.Contains(nV1); |
233 | bV2=aMVIn.Contains(nV2) || aMVOn.Contains(nV2); |
234 | bExpressCompute=bV1 && bV2; |
235 | // |
e30616a7 |
236 | BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Append1(); |
237 | // |
238 | aEdgeFace.SetIndices(nE, nF); |
239 | aEdgeFace.SetPaveBlock(aPB); |
4e57c75e |
240 | // |
241 | aEdgeFace.SetEdge (aE); |
242 | aEdgeFace.SetFace (aF); |
0d0481c7 |
243 | aEdgeFace.SetFuzzyValue(myFuzzyValue); |
4e57c75e |
244 | aEdgeFace.SetDiscretize (aDiscretize); |
245 | aEdgeFace.SetDeflection (aDeflection); |
6dc83e21 |
246 | aEdgeFace.UseQuickCoincidenceCheck(bExpressCompute); |
4e57c75e |
247 | // |
248 | IntTools_Range aSR(aTS1, aTS2); |
249 | IntTools_Range anewSR=aSR; |
4e57c75e |
250 | BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR); |
e30616a7 |
251 | aEdgeFace.SetNewSR(anewSR); |
b4109929 |
252 | // |
b4109929 |
253 | IntTools_Range aPBRange(aT1, aT2); |
254 | aSR = aPBRange; |
255 | BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange); |
b4109929 |
256 | aEdgeFace.SetRange (aPBRange); |
36f4947b |
257 | aEdgeFace.SetProgressIndicator(myProgressIndicator); |
4e57c75e |
258 | // |
e30616a7 |
259 | }//for (; aIt.More(); aIt.Next()) { |
260 | }//for (; myIterator->More(); myIterator->Next()) { |
261 | // |
262 | aNbEdgeFace=aVEdgeFace.Extent(); |
263 | //================================================================= |
264 | BOPAlgo_EdgeFaceCnt::Perform(myRunParallel, aVEdgeFace, myContext); |
265 | //================================================================= |
266 | // |
267 | for (k=0; k < aNbEdgeFace; ++k) { |
268 | BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace(k); |
269 | if (!aEdgeFace.IsDone()) { |
270 | continue; |
271 | } |
51db0179 |
272 | // |
273 | const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts(); |
274 | aNbCPrts = aCPrts.Length(); |
275 | if (!aNbCPrts) { |
276 | continue; |
277 | } |
278 | // |
e30616a7 |
279 | aEdgeFace.Indices(nE, nF); |
280 | // |
281 | const TopoDS_Edge& aE=aEdgeFace.Edge(); |
282 | const TopoDS_Face& aF=aEdgeFace.Face(); |
283 | // |
0d0481c7 |
284 | aTolE=BRep_Tool::Tolerance(aE); |
285 | aTolF=BRep_Tool::Tolerance(aF); |
e30616a7 |
286 | const IntTools_Range& anewSR=aEdgeFace.NewSR(); |
287 | Handle(BOPDS_PaveBlock)& aPB=aEdgeFace.PaveBlock(); |
288 | // |
289 | aPB->Range(aT1, aT2); |
290 | aPB->Indices(nV[0], nV[1]); |
01b5b3df |
291 | bIsPBSplittable = aPB->IsSplittable(); |
292 | // |
01b5b3df |
293 | anewSR.Range(aTS1, aTS2); |
294 | // |
51db0179 |
295 | if (aCPrts(1).Type() == TopAbs_VERTEX) { |
296 | // for the intersection type VERTEX |
297 | // extend vertices ranges using Edge/Edge intersections |
298 | // between the edge aE and the edges of the face aF. |
299 | // thereby the edge's intersection range is reduced |
300 | ReduceIntersectionRange(nV[0], nV[1], nE, nF, aTS1, aTS2); |
301 | } |
01b5b3df |
302 | // |
303 | IntTools_Range aR1(aT1, aTS1), aR2(aTS2, aT2); |
e30616a7 |
304 | // |
305 | BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF); |
e30616a7 |
306 | const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn(); |
307 | const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn(); |
3510db62 |
308 | // |
309 | Standard_Boolean bLinePlane = Standard_False; |
310 | if (aNbCPrts) { |
311 | BRepAdaptor_Curve aBAC(aE); |
3510db62 |
312 | bLinePlane = (aBAC.GetType() == GeomAbs_Line && |
51db0179 |
313 | myContext->SurfaceAdaptor(aF).GetType() == GeomAbs_Plane); |
3510db62 |
314 | } |
51db0179 |
315 | // |
e30616a7 |
316 | for (i=1; i<=aNbCPrts; ++i) { |
317 | const IntTools_CommonPrt& aCPart=aCPrts(i); |
318 | aType=aCPart.Type(); |
319 | switch (aType) { |
01b5b3df |
320 | case TopAbs_VERTEX: { |
b4109929 |
321 | Standard_Boolean bIsOnPave[2]; |
322 | Standard_Integer j; |
4e57c75e |
323 | Standard_Real aT, aTolToDecide; |
324 | TopoDS_Vertex aVnew; |
e30616a7 |
325 | // |
1e143abb |
326 | IntTools_Tools::VertexParameter(aCPart, aT); |
4e57c75e |
327 | BOPTools_AlgoTools::MakeNewVertex(aE, aT, aF, aVnew); |
328 | // |
329 | const IntTools_Range& aR=aCPart.Range1(); |
330 | aTolToDecide=5.e-8; |
4e57c75e |
331 | // |
1e143abb |
332 | bIsOnPave[0]=IntTools_Tools::IsInRange(aR1, aR, aTolToDecide); |
333 | bIsOnPave[1]=IntTools_Tools::IsInRange(aR2, aR, aTolToDecide); |
b4109929 |
334 | // |
3510db62 |
335 | if ((bIsOnPave[0] && bIsOnPave[1]) || |
336 | (bLinePlane && (bIsOnPave[0] || bIsOnPave[1]))) { |
b4109929 |
337 | bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn); |
338 | bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn); |
339 | if (bV[0] && bV[1]) { |
4e57c75e |
340 | IntTools_CommonPrt aCP = aCPart; |
341 | aCP.SetType(TopAbs_EDGE); |
402bfe81 |
342 | BOPDS_InterfEF& aEF=aEFs.Append1(); |
343 | iX=aEFs.Extent()-1; |
4e57c75e |
344 | aEF.SetIndices(nE, nF); |
345 | aEF.SetCommonPart(aCP); |
346 | myDS->AddInterf(nE, nF); |
ceb31c61 |
347 | // |
348 | aMIEFC.Add(nF); |
349 | // |
4e57c75e |
350 | BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator); |
351 | break; |
352 | } |
353 | } |
01b5b3df |
354 | // |
355 | if (!bIsPBSplittable) { |
356 | continue; |
357 | } |
358 | // |
b4109929 |
359 | for (j=0; j<2; ++j) { |
360 | if (bIsOnPave[j]) { |
361 | bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn); |
362 | if (bV[j]) { |
e30616a7 |
363 | const TopoDS_Vertex& aV= |
364 | (*(TopoDS_Vertex *)(&myDS->Shape(nV[j]))); |
3510db62 |
365 | // |
366 | Standard_Real f, l, aTolVnew, aDistPP, aTolPC, aTolV; |
367 | // |
368 | const Handle(Geom_Curve)& aCur = BRep_Tool::Curve(aE, f, l); |
369 | // |
370 | gp_Pnt aP1 = BRep_Tool::Pnt(aV); |
371 | gp_Pnt aP2 = aCur->Value(aT); |
372 | // |
3510db62 |
373 | aDistPP=aP1.Distance(aP2); |
01b5b3df |
374 | // |
3510db62 |
375 | aTolPC=Precision::PConfusion(); |
376 | aTolV=BRep_Tool::Tolerance(aV); |
377 | if (aDistPP > (aTolV+aTolPC)) { |
378 | aTolVnew=Max(aTolE, aDistPP); |
379 | UpdateVertex(nV[j], aTolVnew); |
01b5b3df |
380 | } |
b4109929 |
381 | } |
382 | else { |
383 | bIsOnPave[j] = ForceInterfVF(nV[j], nF); |
384 | } |
4e57c75e |
385 | } |
4e57c75e |
386 | } |
387 | // |
b4109929 |
388 | if (!bIsOnPave[0] && !bIsOnPave[1]) { |
389 | if (CheckFacePaves(aVnew, aMIFOn)) { |
4e57c75e |
390 | continue; |
391 | } |
b4109929 |
392 | // |
3510db62 |
393 | Standard_Real aTolVnew = BRep_Tool::Tolerance(aVnew); |
394 | aTolVnew = Max(aTolVnew, Max(aTolE, aTolF)); |
395 | BRep_Builder().UpdateVertex(aVnew, aTolVnew); |
396 | if (bLinePlane) { |
397 | // increase tolerance for Line/Plane intersection, but do not update |
398 | // the vertex till its intersection with some other shape |
399 | IntTools_Range aCR = aCPart.Range1(); |
400 | aTolVnew = Max(aTolVnew, (aCR.Last() - aCR.First()) / 2.); |
401 | } |
402 | // |
b4109929 |
403 | const gp_Pnt& aPnew = BRep_Tool::Pnt(aVnew); |
bd28b2af |
404 | // |
3510db62 |
405 | if (!myContext->IsPointInFace(aPnew, aF, aTolVnew)) { |
4e57c75e |
406 | continue; |
407 | } |
b4109929 |
408 | // |
4e57c75e |
409 | aMIEFC.Add(nF); |
410 | // 1 |
402bfe81 |
411 | BOPDS_InterfEF& aEF=aEFs.Append1(); |
412 | iX=aEFs.Extent()-1; |
4e57c75e |
413 | aEF.SetIndices(nE, nF); |
414 | aEF.SetCommonPart(aCPart); |
415 | // 2 |
416 | myDS->AddInterf(nE, nF); |
417 | // 3 |
418 | BOPDS_CoupleOfPaveBlocks aCPB; |
419 | // |
420 | aCPB.SetPaveBlocks(aPB, aPB); |
421 | aCPB.SetIndexInterf(iX); |
3510db62 |
422 | aCPB.SetTolerance(aTolVnew); |
4e57c75e |
423 | aMVCPB.Add(aVnew, aCPB); |
424 | } |
425 | } |
426 | break; |
427 | case TopAbs_EDGE: { |
428 | aMIEFC.Add(nF); |
429 | // |
430 | // 1 |
402bfe81 |
431 | BOPDS_InterfEF& aEF=aEFs.Append1(); |
432 | iX=aEFs.Extent()-1; |
4e57c75e |
433 | aEF.SetIndices(nE, nF); |
434 | // |
b4109929 |
435 | bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn); |
436 | bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn); |
437 | if (!bV[0] || !bV[1]) { |
4e57c75e |
438 | myDS->AddInterf(nE, nF); |
439 | break; |
440 | } |
4e57c75e |
441 | aEF.SetCommonPart(aCPart); |
442 | // 2 |
443 | myDS->AddInterf(nE, nF); |
444 | // 3 |
445 | BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator); |
446 | |
447 | } |
448 | break; |
449 | default: |
450 | break; |
e30616a7 |
451 | }//switch (aType) { |
452 | }//for (i=1; i<=aNbCPrts; ++i) { |
453 | }// for (k=0; k < aNbEdgeEdge; ++k) { |
4e57c75e |
454 | // |
455 | //========================================= |
456 | // post treatment |
457 | //========================================= |
5a77460e |
458 | BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS); |
4e57c75e |
459 | PerformVerticesEF(aMVCPB, aAllocator); |
460 | // |
461 | // Update FaceInfoIn for all faces having EF common parts |
462 | BOPCol_MapIteratorOfMapOfInteger aItMI; |
463 | aItMI.Initialize(aMIEFC); |
464 | for (; aItMI.More(); aItMI.Next()) { |
465 | nF=aItMI.Value(); |
466 | myDS->UpdateFaceInfoIn(nF); |
467 | } |
4e57c75e |
468 | //-----------------------------------------------------scope t |
469 | aMIEFC.Clear(); |
470 | aMVCPB.Clear(); |
471 | aMPBLI.Clear(); |
e30616a7 |
472 | ////aAllocator.Nullify(); |
4e57c75e |
473 | } |
474 | //======================================================================= |
3510db62 |
475 | //function : PerformVerticesEF |
4e57c75e |
476 | //purpose : |
477 | //======================================================================= |
e30616a7 |
478 | Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF |
479 | (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB, |
7f22979e |
480 | const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
481 | { |
482 | Standard_Integer aNbV, iRet; |
483 | // |
484 | iRet=0; |
485 | aNbV=theMVCPB.Extent(); |
486 | if (!aNbV) { |
487 | return iRet; |
488 | } |
489 | // |
490 | Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI; |
3510db62 |
491 | Standard_Real aT, dummy; |
4e57c75e |
492 | BOPCol_ListIteratorOfListOfShape aItLS; |
493 | BOPCol_ListIteratorOfListOfInteger aItLI; |
494 | BOPDS_PDS aPDS; |
495 | BOPDS_ShapeInfo aSI; |
496 | BOPDS_Pave aPave; |
497 | // |
498 | BOPCol_ListOfShape aLS(theAllocator); |
499 | BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator); |
500 | BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator); |
501 | BOPAlgo_PaveFiller aPF(theAllocator); |
3510db62 |
502 | BOPCol_DataMapOfShapeReal aMVIniTol; |
4e57c75e |
503 | // |
504 | aSI.SetShapeType(TopAbs_VERTEX); |
505 | BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF(); |
506 | // |
507 | // 1 prepare arguments |
508 | for (i=1; i<=aNbV; ++i) { |
3510db62 |
509 | const TopoDS_Vertex& aV = TopoDS::Vertex(theMVCPB.FindKey(i)); |
510 | aLS.Append(aV); |
511 | // if an enlarged tolerance is associated with the vertex then update it |
512 | // remembering its initial tolerance |
513 | Standard_Real aTolEnlarged = theMVCPB.FindFromIndex(i).Tolerance(); |
514 | Standard_Real aIniTol = BRep_Tool::Tolerance(aV); |
515 | if (aTolEnlarged > aIniTol) { |
516 | aMVIniTol.Bind(aV, aIniTol); |
517 | BRep_Builder().UpdateVertex(aV, aTolEnlarged); |
518 | } |
4e57c75e |
519 | } |
520 | // |
521 | // 2 Fuse vertices |
3510db62 |
522 | aPF.SetIsPrimary(Standard_False); |
523 | aPF.SetNonDestructive(myNonDestructive); |
4e57c75e |
524 | aPF.SetArguments(aLS); |
525 | aPF.Perform(); |
526 | iErr=aPF.ErrorStatus(); |
527 | if (iErr) { |
528 | iRet=1; |
529 | return iRet; |
530 | } |
531 | aPDS=aPF.PDS(); |
532 | // |
3510db62 |
533 | // Recompute common vertex for each SD group containing enlarged vertex; |
534 | // for that first fill in the map of SD vertex -> its counterparts |
535 | BOPCol_IndexedDataMapOfShapeListOfShape aImages; |
536 | aItLS.Initialize(aLS); |
537 | for (; aItLS.More(); aItLS.Next()) { |
538 | const TopoDS_Shape& aVx = aItLS.Value(); |
539 | nVx = aPDS->Index(aVx); |
540 | // |
8bb8064e |
541 | const TopoDS_Shape& aV = (aPDS->HasShapeSD(nVx, nVSD) ? aPDS->Shape(nVSD) : aVx); |
3510db62 |
542 | BOPCol_ListOfShape* pLst = aImages.ChangeSeek(aV); |
543 | if (!pLst) { |
544 | pLst = &aImages.ChangeFromIndex(aImages.Add(aV, BOPCol_ListOfShape())); |
545 | } |
546 | pLst->Append(aVx); |
547 | } |
4e57c75e |
548 | // 3 Add new vertices to theDS; |
3510db62 |
549 | for (i = 1; i <= aImages.Extent(); i++) { |
550 | TopoDS_Vertex aV = TopoDS::Vertex(aImages.FindKey(i)); |
551 | const BOPCol_ListOfShape& aLVSD = aImages.FindFromIndex(i); |
552 | Standard_Boolean isReset = Standard_False; |
553 | BOPCol_ListIteratorOfListOfShape it(aLVSD); |
554 | for (; it.More(); it.Next()) { |
555 | const TopoDS_Vertex& aVx = TopoDS::Vertex(it.Value()); |
556 | const Standard_Real* pTolIni = aMVIniTol.Seek(aVx); |
557 | if (pTolIni) { |
558 | // reset enlarged vertex tolerance to the initial value |
559 | reinterpret_cast<BRep_TVertex*>(aVx.TShape().operator->())->Tolerance(*pTolIni); |
560 | isReset = Standard_True; |
561 | } |
562 | } |
563 | TopoDS_Vertex aVnew = aV; |
564 | if (isReset && aLVSD.Extent() > 1) { |
565 | // make new vertex again |
566 | BOPTools_AlgoTools::MakeVertex(aLVSD, aVnew); |
567 | } |
568 | // index of new vertex in theDS -> iV |
569 | aSI.SetShape(aVnew); |
570 | iV = myDS->Append(aSI); |
571 | // |
572 | BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(iV); |
573 | Bnd_Box& aBox = aSIDS.ChangeBox(); |
574 | BRepBndLib::Add(aVnew, aBox); |
575 | aBox.SetGap(aBox.GetGap() + Precision::Confusion()); |
576 | // |
577 | aMVI.Bind(aV, iV); |
578 | } |
579 | // |
4e57c75e |
580 | // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI |
581 | aItLS.Initialize(aLS); |
582 | for (; aItLS.More(); aItLS.Next()) { |
583 | const TopoDS_Shape& aVx=aItLS.Value(); |
584 | nVx=aPDS->Index(aVx); |
585 | // |
8bb8064e |
586 | const TopoDS_Shape& aV = (aPDS->HasShapeSD(nVx, nVSD) ? aPDS->Shape(nVSD) : aVx); |
3510db62 |
587 | iV = aMVI.Find(aV); |
4e57c75e |
588 | // |
589 | BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx); |
590 | aCPB.SetIndex(iV); |
591 | // update EF interference |
592 | iX=aCPB.IndexInterf(); |
593 | BOPDS_InterfEF& aEF=aEFs(iX); |
594 | aEF.SetIndexNew(iV); |
595 | // map aMPBLI |
596 | const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1(); |
597 | if (aMPBLI.Contains(aPB)) { |
598 | BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB); |
599 | aLI.Append(iV); |
600 | } |
601 | else { |
602 | BOPCol_ListOfInteger aLI(theAllocator); |
603 | aLI.Append(iV); |
604 | aMPBLI.Add(aPB, aLI); |
605 | } |
606 | } |
607 | // |
608 | // 5 |
609 | // 5.1 Compute Extra Paves and |
610 | // 5.2. Add Extra Paves to the PaveBlocks |
611 | aNbPBLI=aMPBLI.Extent(); |
612 | for (i=1; i<=aNbPBLI; ++i) { |
613 | Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i); |
614 | const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i); |
615 | nE=aPB->OriginalEdge(); |
616 | const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE))); |
617 | // |
618 | aItLI.Initialize(aLI); |
619 | for (; aItLI.More(); aItLI.Next()) { |
620 | nVx=aItLI.Value(); |
621 | const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); |
622 | // |
0d0481c7 |
623 | iFlag=myContext->ComputeVE (aVx, aE, aT, dummy, myFuzzyValue); |
4e57c75e |
624 | if (!iFlag) { |
625 | aPave.SetIndex(nVx); |
626 | aPave.SetParameter(aT); |
627 | aPB->AppendExtPave(aPave); |
628 | } |
629 | } |
630 | } |
3510db62 |
631 | // 6 Split PaveBlocks |
4e57c75e |
632 | for (i=1; i<=aNbPBLI; ++i) { |
633 | Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i); |
634 | nE=aPB->OriginalEdge(); |
635 | // 3 |
5a77460e |
636 | if (!myDS->IsCommonBlock(aPB)) { |
4e57c75e |
637 | myDS->UpdatePaveBlock(aPB); |
638 | } |
639 | else { |
5a77460e |
640 | const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB); |
0d0481c7 |
641 | myDS->UpdateCommonBlock(aCB, myFuzzyValue); |
4e57c75e |
642 | } |
643 | }//for (; aItMPBLI.More(); aItMPBLI.Next()) { |
644 | // |
645 | return iRet; |
646 | } |
647 | //======================================================================= |
648 | // function: CheckFacePaves |
649 | // purpose: |
650 | //======================================================================= |
e30616a7 |
651 | Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves |
652 | (const Standard_Integer nVx, |
653 | const BOPCol_MapOfInteger& aMIFOn, |
654 | const BOPCol_MapOfInteger& aMIFIn) |
4e57c75e |
655 | { |
656 | Standard_Boolean bRet; |
657 | Standard_Integer nV; |
658 | BOPCol_MapIteratorOfMapOfInteger aIt; |
659 | // |
660 | bRet=Standard_False; |
661 | // |
662 | aIt.Initialize(aMIFOn); |
663 | for (; aIt.More(); aIt.Next()) { |
664 | nV=aIt.Value(); |
665 | if (nV==nVx) { |
666 | bRet=!bRet; |
667 | return bRet; |
668 | } |
669 | } |
670 | aIt.Initialize(aMIFIn); |
671 | for (; aIt.More(); aIt.Next()) { |
672 | nV=aIt.Value(); |
673 | if (nV==nVx) { |
674 | bRet=!bRet; |
675 | return bRet; |
676 | } |
677 | } |
678 | // |
679 | return bRet; |
680 | } |
681 | //======================================================================= |
682 | // function: CheckFacePaves |
683 | // purpose: |
684 | //======================================================================= |
e30616a7 |
685 | Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves |
686 | (const TopoDS_Vertex& aVnew, |
687 | const BOPCol_MapOfInteger& aMIF) |
4e57c75e |
688 | { |
689 | Standard_Boolean bRet; |
690 | Standard_Integer nV, iFlag; |
691 | BOPCol_MapIteratorOfMapOfInteger aIt; |
692 | // |
693 | bRet=Standard_True; |
694 | // |
695 | aIt.Initialize(aMIF); |
696 | for (; aIt.More(); aIt.Next()) { |
697 | nV=aIt.Value(); |
698 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV))); |
699 | iFlag=BOPTools_AlgoTools::ComputeVV(aVnew, aV); |
700 | if (!iFlag) { |
701 | return bRet; |
702 | } |
703 | } |
704 | // |
705 | return !bRet; |
706 | } |
b4109929 |
707 | //======================================================================= |
708 | //function : ForceInterfVF |
709 | //purpose : |
710 | //======================================================================= |
e30616a7 |
711 | Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF |
712 | (const Standard_Integer nV, |
713 | const Standard_Integer nF) |
b4109929 |
714 | { |
715 | Standard_Boolean bRet; |
3510db62 |
716 | Standard_Integer iFlag, nVx; |
717 | Standard_Real U, V, aTolVNew; |
b4109929 |
718 | // |
719 | bRet = Standard_False; |
720 | const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV); |
721 | const TopoDS_Face& aF = *(TopoDS_Face*) &myDS->Shape(nF); |
722 | // |
0d0481c7 |
723 | iFlag = myContext->ComputeVF(aV, aF, U, V, aTolVNew, myFuzzyValue); |
3510db62 |
724 | if (iFlag == 0 || iFlag == -2) { |
725 | bRet=!bRet; |
b4109929 |
726 | // |
b4109929 |
727 | BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF(); |
a3476a9f |
728 | aVFs.SetIncrement(10); |
3510db62 |
729 | // 1 |
402bfe81 |
730 | BOPDS_InterfVF& aVF=aVFs.Append1(); |
3510db62 |
731 | // |
b4109929 |
732 | aVF.SetIndices(nV, nF); |
733 | aVF.SetUV(U, V); |
3510db62 |
734 | // 2 |
b4109929 |
735 | myDS->AddInterf(nV, nF); |
736 | // |
3510db62 |
737 | // 3 update vertex V/F if necessary |
738 | nVx=UpdateVertex(nV, aTolVNew); |
739 | // 4 |
740 | if (myDS->IsNewShape(nVx)) { |
741 | aVF.SetIndexNew(nVx); |
742 | } |
b4109929 |
743 | // |
744 | BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF); |
745 | BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn(); |
3510db62 |
746 | aMVIn.Add(nVx); |
b4109929 |
747 | } |
b4109929 |
748 | return bRet; |
749 | } |
01b5b3df |
750 | //======================================================================= |
751 | //function : ReduceIntersectionRange |
752 | //purpose : |
753 | //======================================================================= |
754 | void BOPAlgo_PaveFiller::ReduceIntersectionRange(const Standard_Integer theV1, |
755 | const Standard_Integer theV2, |
756 | const Standard_Integer theE, |
757 | const Standard_Integer theF, |
758 | Standard_Real& theTS1, |
759 | Standard_Real& theTS2) |
760 | { |
761 | if (!myDS->IsNewShape(theV1) && |
762 | !myDS->IsNewShape(theV2)) { |
763 | return; |
764 | } |
765 | // |
51db0179 |
766 | if (!myDS->HasInterfShapeSubShapes(theE, theF)) { |
767 | return; |
768 | } |
769 | // |
01b5b3df |
770 | BOPDS_VectorOfInterfEE& aEEs = myDS->InterfEE(); |
771 | Standard_Integer aNbEEs = aEEs.Extent(); |
772 | if (!aNbEEs) { |
773 | return; |
774 | } |
775 | // |
776 | Standard_Integer i, nV, nE1, nE2; |
777 | Standard_Real aTR1, aTR2; |
778 | // |
779 | // get face's edges to check that E/E contains the edge from the face |
780 | BOPCol_MapOfInteger aMFE; |
781 | const BOPCol_ListOfInteger& aLI = myDS->ShapeInfo(theF).SubShapes(); |
782 | BOPCol_ListIteratorOfListOfInteger aItLI(aLI); |
783 | for (; aItLI.More(); aItLI.Next()) { |
784 | nE1 = aItLI.Value(); |
785 | if (myDS->ShapeInfo(nE1).ShapeType() == TopAbs_EDGE) { |
786 | aMFE.Add(nE1); |
787 | } |
788 | } |
789 | // |
790 | for (i = 0; i < aNbEEs; ++i) { |
791 | BOPDS_InterfEE& aEE = aEEs(i); |
792 | if (!aEE.HasIndexNew()) { |
793 | continue; |
794 | } |
795 | // |
796 | // check the vertex |
797 | nV = aEE.IndexNew(); |
798 | if (nV != theV1 && nV != theV2) { |
799 | continue; |
800 | } |
801 | // |
802 | // check that the intersection is between the edge |
803 | // and one of the face's edge |
804 | aEE.Indices(nE1, nE2); |
805 | if (((theE != nE1) && (theE != nE2)) || |
806 | (!aMFE.Contains(nE1) && !aMFE.Contains(nE2))) { |
807 | continue; |
808 | } |
809 | // |
810 | // update the intersection range |
811 | const IntTools_CommonPrt& aCPart = aEE.CommonPart(); |
812 | const IntTools_Range& aCRange = |
813 | (theE == nE1) ? aCPart.Range1() : aCPart.Ranges2().First(); |
814 | aCRange.Range(aTR1, aTR2); |
815 | // |
816 | if (nV == theV1) { |
817 | if (theTS1 < aTR2) { |
818 | theTS1 = aTR2; |
819 | } |
820 | } |
821 | else { |
822 | if (theTS2 > aTR1) { |
823 | theTS2 = aTR1; |
824 | } |
825 | } |
826 | } |
827 | } |