f4eb89a2da2b6cb86af71d9f583c9447dbd65fc4
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_SectionAttribute.hxx>
21 #include <BOPAlgo_Alerts.hxx>
22 #include <BOPDS_Curve.hxx>
23 #include <BOPDS_DS.hxx>
24 #include <BOPDS_Iterator.hxx>
25 #include <BOPDS_PaveBlock.hxx>
26 #include <gp_Pnt.hxx>
27 #include <IntTools_Context.hxx>
28 #include <NCollection_BaseAllocator.hxx>
29 #include <Standard_ErrorHandler.hxx>
30 #include <Standard_Failure.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34
35 //=======================================================================
36 //function : 
37 //purpose  : 
38 //=======================================================================
39 BOPAlgo_PaveFiller::BOPAlgo_PaveFiller()
40 :
41   BOPAlgo_Algo()
42 {
43   myDS = NULL;
44   myIterator = NULL;
45   myNonDestructive = Standard_False;
46   myIsPrimary = Standard_True;
47   myAvoidBuildPCurve = Standard_False;
48   myGlue = BOPAlgo_GlueOff;
49 }
50 //=======================================================================
51 //function : 
52 //purpose  : 
53 //=======================================================================
54 BOPAlgo_PaveFiller::BOPAlgo_PaveFiller
55   (const Handle(NCollection_BaseAllocator)& theAllocator)
56 :
57   BOPAlgo_Algo(theAllocator),
58   myFPBDone(1, theAllocator),
59   myIncreasedSS(1, theAllocator),
60   myVertsToAvoidExtension(1, theAllocator)
61 {
62   myDS = NULL;
63   myIterator = NULL;
64   myNonDestructive = Standard_False;
65   myIsPrimary = Standard_True;
66   myAvoidBuildPCurve = Standard_False;
67   myGlue = BOPAlgo_GlueOff;
68 }
69 //=======================================================================
70 //function : ~
71 //purpose  : 
72 //=======================================================================
73 BOPAlgo_PaveFiller::~BOPAlgo_PaveFiller()
74 {
75   Clear();
76 }
77 //=======================================================================
78 //function : SetNonDestructive
79 //purpose  : 
80 //=======================================================================
81 void BOPAlgo_PaveFiller::SetNonDestructive(const Standard_Boolean bFlag)
82 {
83   myNonDestructive=bFlag;
84 }
85 //=======================================================================
86 //function : NonDestructive
87 //purpose  : 
88 //=======================================================================
89 Standard_Boolean BOPAlgo_PaveFiller::NonDestructive()const 
90 {
91   return myNonDestructive;
92 }
93 //=======================================================================
94 //function : SetGlue
95 //purpose  : 
96 //=======================================================================
97 void BOPAlgo_PaveFiller::SetGlue(const BOPAlgo_GlueEnum theGlue)
98 {
99   myGlue=theGlue;
100 }
101 //=======================================================================
102 //function : Glue
103 //purpose  : 
104 //=======================================================================
105 BOPAlgo_GlueEnum BOPAlgo_PaveFiller::Glue() const 
106 {
107   return myGlue;
108 }
109 //=======================================================================
110 //function : SetIsPrimary
111 //purpose  : 
112 //=======================================================================
113 void BOPAlgo_PaveFiller::SetIsPrimary(const Standard_Boolean bFlag)
114 {
115   myIsPrimary=bFlag;
116 }
117 //=======================================================================
118 //function : IsPrimary
119 //purpose  : 
120 //=======================================================================
121 Standard_Boolean BOPAlgo_PaveFiller::IsPrimary()const 
122 {
123   return myIsPrimary;
124 }
125 //=======================================================================
126 //function : Clear
127 //purpose  : 
128 //=======================================================================
129 void BOPAlgo_PaveFiller::Clear()
130 {
131   BOPAlgo_Algo::Clear();
132   if (myIterator) {
133     delete myIterator;
134     myIterator=NULL;
135   }
136   if (myDS) {
137     delete myDS;
138     myDS=NULL;
139   }
140   myIncreasedSS.Clear();
141 }
142 //=======================================================================
143 //function : DS
144 //purpose  : 
145 //=======================================================================
146 const BOPDS_DS& BOPAlgo_PaveFiller::DS()
147 {
148   return *myDS;
149 }
150 //=======================================================================
151 //function : PDS
152 //purpose  : 
153 //=======================================================================
154 BOPDS_PDS BOPAlgo_PaveFiller::PDS()
155 {
156   return myDS;
157 }
158 //=======================================================================
159 //function : Context
160 //purpose  : 
161 //=======================================================================
162 const Handle(IntTools_Context)& BOPAlgo_PaveFiller::Context()
163 {
164   return myContext;
165 }
166 //=======================================================================
167 //function : SectionAttribute
168 //purpose  : 
169 //=======================================================================
170 void BOPAlgo_PaveFiller::SetSectionAttribute
171   (const BOPAlgo_SectionAttribute& theSecAttr)
172 {
173   mySectionAttribute = theSecAttr;
174 }
175 //=======================================================================
176 // function: Init
177 // purpose: 
178 //=======================================================================
179 void BOPAlgo_PaveFiller::Init()
180 {
181   if (!myArguments.Extent()) {
182     AddError (new BOPAlgo_AlertTooFewArguments);
183     return;
184   }
185   //
186   TopTools_ListIteratorOfListOfShape aIt(myArguments);
187   for (; aIt.More(); aIt.Next()) {
188     if (aIt.Value().IsNull()) {
189       AddError (new BOPAlgo_AlertNullInputShapes);
190       return;
191     }
192   }
193   //
194   // 0 Clear
195   Clear();
196   //
197   // 1.myDS 
198   myDS=new BOPDS_DS(myAllocator);
199   myDS->SetArguments(myArguments);
200   myDS->Init(myFuzzyValue);
201   //
202   // 2 myContext
203   myContext=new IntTools_Context;
204   //
205   // 3.myIterator 
206   myIterator=new BOPDS_Iterator(myAllocator);
207   myIterator->SetRunParallel(myRunParallel);
208   myIterator->SetDS(myDS);
209   myIterator->Prepare(myContext, myUseOBB, myFuzzyValue);
210   //
211   // 4 NonDestructive flag
212   SetNonDestructive();
213 }
214 //=======================================================================
215 // function: Perform
216 // purpose: 
217 //=======================================================================
218 void BOPAlgo_PaveFiller::Perform()
219 {
220   try {
221     OCC_CATCH_SIGNALS
222     //
223     PerformInternal();
224   }
225   //
226   catch (Standard_Failure const&) {
227     AddError (new BOPAlgo_AlertIntersectionFailed);
228   } 
229 }
230 //=======================================================================
231 // function: PerformInternal
232 // purpose: 
233 //=======================================================================
234 void BOPAlgo_PaveFiller::PerformInternal()
235 {
236   Init();
237   if (HasErrors()) {
238     return; 
239   }
240   //
241   Prepare();
242   if (HasErrors()) {
243     return; 
244   }
245   // 00
246   PerformVV();
247   if (HasErrors()) {
248     return; 
249   }
250   // 01
251   PerformVE();
252   if (HasErrors()) {
253     return; 
254   }
255   //
256   UpdatePaveBlocksWithSDVertices();
257   // 11
258   PerformEE();
259   if (HasErrors()) {
260     return; 
261   }
262   UpdatePaveBlocksWithSDVertices();
263   // 02
264   PerformVF();
265   if (HasErrors()) {
266     return; 
267   }
268   UpdatePaveBlocksWithSDVertices();
269   // 12
270   PerformEF();
271   if (HasErrors()) {
272     return; 
273   }
274   UpdatePaveBlocksWithSDVertices();
275   UpdateInterfsWithSDVertices();
276
277   // Repeat Intersection with increased vertices
278   RepeatIntersection();
279   if (HasErrors())
280     return;
281
282   // Force intersection of edges after increase
283   // of the tolerance values of their vertices
284   ForceInterfEE();
285   // Force Edge/Face intersection after increase
286   // of the tolerance values of their vertices
287   ForceInterfEF();
288   //
289   // 22
290   PerformFF();
291   if (HasErrors()) {
292     return; 
293   }
294   //
295   UpdateBlocksWithSharedVertices();
296   //
297   MakeSplitEdges();
298   if (HasErrors()) {
299     return; 
300   }
301   //
302   UpdatePaveBlocksWithSDVertices();
303   //
304   MakeBlocks();
305   if (HasErrors()) {
306     return; 
307   }
308   //
309   CheckSelfInterference();
310   //
311   UpdateInterfsWithSDVertices();
312   myDS->ReleasePaveBlocks();
313   myDS->RefineFaceInfoOn();
314   //
315   RemoveMicroEdges();
316   //
317   MakePCurves();
318   if (HasErrors()) {
319     return; 
320   }
321   //
322   ProcessDE();
323   if (HasErrors()) {
324     return; 
325   }
326 }
327
328 //=======================================================================
329 // function: RepeatIntersection
330 // purpose: 
331 //=======================================================================
332 void BOPAlgo_PaveFiller::RepeatIntersection()
333 {
334   // Find all vertices with increased tolerance
335   TColStd_MapOfInteger anExtraInterfMap;
336   const Standard_Integer aNbS = myDS->NbSourceShapes();
337   for (Standard_Integer i = 0; i < aNbS; ++i)
338   {
339     const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
340     if (aSI.ShapeType() != TopAbs_VERTEX)
341       continue;
342     // Check if the tolerance of the original vertex has been increased
343     if (myIncreasedSS.Contains(i))
344     {
345       anExtraInterfMap.Add(i);
346       continue;
347     }
348
349     // Check if the vertex created a new vertex with greater tolerance
350     Standard_Integer nVSD;
351     if (!myDS->HasShapeSD(i, nVSD))
352       continue;
353
354     if (myIncreasedSS.Contains(nVSD))
355       anExtraInterfMap.Add(i);
356   }
357
358   if (anExtraInterfMap.IsEmpty())
359     return;
360
361   // Update iterator of pairs of shapes with interfering boxes
362   myIterator->PrepareExt(anExtraInterfMap);
363
364   // Perform intersections with vertices
365   PerformVV();
366   if (HasErrors())
367     return;
368   UpdatePaveBlocksWithSDVertices();
369
370   PerformVE();
371   if (HasErrors())
372     return;
373   UpdatePaveBlocksWithSDVertices();
374
375   PerformVF();
376   if (HasErrors())
377     return;
378
379   UpdatePaveBlocksWithSDVertices();
380   UpdateInterfsWithSDVertices();
381 }