ce679ce3a4422be63c8fd12bc36fe241c9e74ad9
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_4.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 <BOPCol_MapOfInteger.hxx>
22 #include <BOPCol_NCVector.hxx>
23 #include <BOPCol_Parallel.hxx>
24 #include <BOPDS_Curve.hxx>
25 #include <BOPDS_DS.hxx>
26 #include <BOPDS_FaceInfo.hxx>
27 #include <BOPDS_Interf.hxx>
28 #include <BOPDS_Iterator.hxx>
29 #include <BOPDS_MapOfPaveBlock.hxx>
30 #include <BOPDS_PaveBlock.hxx>
31 #include <BOPDS_SubIterator.hxx>
32 #include <BOPDS_VectorOfInterfVF.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRepBndLib.hxx>
36 #include <gp_Pnt.hxx>
37 #include <IntTools_Context.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Vertex.hxx>
40
41 //=======================================================================
42 //class    : BOPAlgo_VertexFace
43 //purpose  : 
44 //=======================================================================
45 class BOPAlgo_VertexFace : public BOPAlgo_Algo {
46  public:
47   DEFINE_STANDARD_ALLOC
48
49   BOPAlgo_VertexFace() : 
50     BOPAlgo_Algo(),
51     myIV(-1), myIF(-1),
52     myFlag(-1), myT1(-1.),  myT2(-1.), myTolVNew(-1.) {
53   }
54   //
55   virtual ~BOPAlgo_VertexFace(){
56   }
57   //
58   void SetIndices(const Standard_Integer nV,
59                   const Standard_Integer nF) {
60     myIV=nV;
61     myIF=nF;
62   }
63   //
64   void Indices(Standard_Integer& nV,
65                Standard_Integer& nF) const {
66     nV=myIV;
67     nF=myIF;
68   }
69   //
70   void SetVertex(const TopoDS_Vertex& aV) {
71     myV=aV;
72   }
73   //
74   const TopoDS_Vertex& Vertex()const {
75     return myV;
76   }
77   //
78   void SetFace(const TopoDS_Face& aF) {
79     myF=aF;
80   }
81   //
82   const TopoDS_Face& Face()const {
83     return myF;
84   }
85   //
86   Standard_Integer Flag()const {
87     return myFlag;
88   }
89   //
90   void Parameters(Standard_Real& aT1,
91                   Standard_Real& aT2)const {
92     aT1=myT1;
93     aT2=myT2;
94   }
95   //
96   Standard_Real VertexNewTolerance()const {
97     return myTolVNew;
98   }
99   //
100   void SetContext(const Handle(IntTools_Context)& aContext) {
101     myContext=aContext;
102   }
103   //
104   const Handle(IntTools_Context)& Context()const {
105     return myContext;
106   }
107   //
108   virtual void Perform() {
109     BOPAlgo_Algo::UserBreak();
110     myFlag=myContext->ComputeVF(myV, myF, myT1, myT2, myTolVNew, myFuzzyValue);
111   }
112   //
113  protected:
114   Standard_Integer myIV;
115   Standard_Integer myIF;
116   Standard_Integer myFlag;
117   Standard_Real myT1;
118   Standard_Real myT2;
119   Standard_Real myTolVNew;
120   TopoDS_Vertex myV;
121   TopoDS_Face myF;
122   Handle(IntTools_Context) myContext;
123 };
124 //=======================================================================
125 typedef BOPCol_NCVector<BOPAlgo_VertexFace>
126   BOPAlgo_VectorOfVertexFace; 
127 //
128 typedef BOPCol_ContextFunctor 
129   <BOPAlgo_VertexFace,
130   BOPAlgo_VectorOfVertexFace,
131   Handle(IntTools_Context), 
132   IntTools_Context> BOPAlgo_VertexFaceFunctor;
133 //
134 typedef BOPCol_ContextCnt 
135   <BOPAlgo_VertexFaceFunctor,
136   BOPAlgo_VectorOfVertexFace,
137   Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;
138 //
139 //=======================================================================
140 // function: PerformVF
141 // purpose: 
142 //=======================================================================
143 void BOPAlgo_PaveFiller::PerformVF()
144 {
145   myErrorStatus=0;
146   //
147   myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
148   Standard_Integer iSize = myIterator->ExpectedLength();
149   //
150   Standard_Integer nV, nF;
151   //
152   if (myGlue == BOPAlgo_GlueFull) {
153     // there is no need to intersect vertices with faces in this mode
154     // just initialize FaceInfo for all faces
155     for (; myIterator->More(); myIterator->Next()) {
156       myIterator->Value(nV, nF);
157       if (!myDS->IsSubShape(nV, nF)) {
158         myDS->ChangeFaceInfo(nF);
159       }
160     }
161     return;
162   }
163   //
164   BOPDS_VectorOfInterfVF& aVFs = myDS->InterfVF();
165   if (!iSize) {
166     iSize = 10;
167     aVFs.SetIncrement(iSize);
168     //
169     TreatVerticesEE();
170     return;
171   }
172   //
173   Standard_Integer nVSD, iFlag, nVx, aNbVF, k;
174   Standard_Real aT1, aT2;
175   BOPAlgo_VectorOfVertexFace aVVF; 
176   //
177   aVFs.SetIncrement(iSize);
178   //
179   for (; myIterator->More(); myIterator->Next()) {
180     myIterator->Value(nV, nF);
181     //
182     if (myDS->IsSubShape(nV, nF)) {
183       continue;
184     }
185     //
186     myDS->ChangeFaceInfo(nF);
187     if (myDS->HasInterfShapeSubShapes(nV, nF)) {
188       continue;
189     }
190     //
191     nVx=nV;
192     if (myDS->HasShapeSD(nV, nVSD)) {
193       nVx=nVSD;
194     }
195     //
196     const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
197     const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
198     //
199     BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
200     //
201     aVertexFace.SetIndices(nV, nF);
202     aVertexFace.SetVertex(aV);
203     aVertexFace.SetFace(aF);
204     aVertexFace.SetFuzzyValue(myFuzzyValue);
205     aVertexFace.SetProgressIndicator(myProgressIndicator);
206   }//for (; myIterator->More(); myIterator->Next()) {
207   //
208   aNbVF=aVVF.Extent();
209   //================================================================
210   BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
211   //================================================================
212   //
213   for (k=0; k < aNbVF; ++k) {
214     const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
215     // 
216     iFlag=aVertexFace.Flag();
217     if (iFlag) {
218       continue;
219     }
220     //
221     aVertexFace.Indices(nV, nF);
222     aVertexFace.Parameters(aT1, aT2);
223     // 1
224     BOPDS_InterfVF& aVF=aVFs.Append1();
225     aVF.SetIndices(nV, nF);
226     aVF.SetUV(aT1, aT2);
227     // 2
228     myDS->AddInterf(nV, nF);
229     //
230     // 3 update vertex V/F if necessary
231     Standard_Real aTolVNew = aVertexFace.VertexNewTolerance();
232     nVx=UpdateVertex(nV, aTolVNew);
233     //
234     // 4
235     if (myDS->IsNewShape(nVx)) {
236       aVF.SetIndexNew(nVx);
237     }
238     // 5 update FaceInfo
239     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
240     BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
241     aMVIn.Add(nVx);
242   }//for (k=0; k < aNbVF; ++k) {
243   //
244   TreatVerticesEE();
245 }
246 //=======================================================================
247 //function : TreatVerticesEE
248 //purpose  : 
249 //=======================================================================
250 void BOPAlgo_PaveFiller::TreatVerticesEE()
251 {
252   Standard_Integer i, aNbS,aNbEEs, nF, nV, iFlag;
253   Standard_Real aT1, aT2, dummy;
254   BOPCol_ListIteratorOfListOfInteger aItLI;
255   Handle(NCollection_BaseAllocator) aAllocator;
256   //
257   aAllocator=
258     NCollection_BaseAllocator::CommonBaseAllocator();
259   BOPCol_ListOfInteger aLIV(aAllocator), aLIF(aAllocator);
260   BOPCol_MapOfInteger aMI(100, aAllocator);
261   BOPDS_MapOfPaveBlock aMPBF(100, aAllocator);
262   //
263   myErrorStatus=0;
264   //
265   
266   aNbS=myDS->NbSourceShapes();
267   //
268   BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
269   aNbEEs=aEEs.Extent();
270   for (i=0; i<aNbEEs; ++i) {
271     BOPDS_InterfEE& aEE=aEEs(i);
272     if (aEE.HasIndexNew()) {
273       nV=aEE.IndexNew();
274       if (aMI.Add(nV)) {
275         aLIV.Append(nV);
276       }   
277     }   
278   }
279   if (!aLIV.Extent()) {
280     aAllocator.Nullify();
281     return;
282   }
283   //
284   aNbS=myDS->NbSourceShapes();
285   for (nF=0; nF<aNbS; ++nF) {
286     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(nF);
287     if (aSI.ShapeType()==TopAbs_FACE) {
288       aLIF.Append(nF);
289     }
290   }
291   if (!aLIF.Extent()) {
292     aAllocator.Nullify();
293     return;
294   }
295   //-------------------------------------------------------------
296   BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
297   //
298   BOPDS_SubIterator aIt(aAllocator);
299   //
300   aIt.SetDS(myDS);
301   aIt.SetSubSet1(aLIF);
302   aIt.SetSubSet2(aLIV);
303   aIt.Prepare();
304   aIt.Initialize();
305   for (; aIt.More(); aIt.Next()) {
306     aIt.Value(nV, nF);
307     //
308     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
309     const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn();
310     //
311     if (!aMVOn.Contains(nV)) {
312       const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV))); 
313       const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF))); 
314       iFlag = myContext->ComputeVF(aV, aF, aT1, aT2, dummy, myFuzzyValue);
315       if (!iFlag) {
316         // 1
317         BOPDS_InterfVF& aVF=aVFs.Append1();
318         i=aVFs.Extent()-1;
319         aVF.SetIndices(nV, nF);
320         aVF.SetUV(aT1, aT2);
321         // 2
322         myDS->AddInterf(nV, nF);
323         //
324         BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
325         aMVIn.Add(nV);
326       }
327     }
328   }
329 }