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