0024952: Possibility to break Boolean operations algorithm by user request
[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
18#include <BOPAlgo_PaveFiller.ixx>
a0a3f6ac 19//
4e57c75e 20#include <NCollection_IncAllocator.hxx>
a0a3f6ac 21//
4e57c75e 22#include <TopoDS_Vertex.hxx>
23#include <TopoDS_Face.hxx>
24#include <BRep_Tool.hxx>
25#include <BRep_Builder.hxx>
26#include <BRepBndLib.hxx>
a0a3f6ac 27//
4e57c75e 28#include <BOPCol_MapOfInteger.hxx>
a0a3f6ac 29#include <BOPCol_NCVector.hxx>
30#include <BOPCol_TBB.hxx>
31//
1e143abb 32#include <IntTools_Context.hxx>
a0a3f6ac 33//
4e57c75e 34#include <BOPDS_Iterator.hxx>
35#include <BOPDS_VectorOfInterfVF.hxx>
36#include <BOPDS_Interf.hxx>
37#include <BOPDS_SubIterator.hxx>
38#include <BOPDS_MapOfPaveBlock.hxx>
39#include <BOPDS_FaceInfo.hxx>
4e57c75e 40
a0a3f6ac 41//=======================================================================
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(),
51 myIV(-1), myIF(-1), myIVx(-1),
a0a3f6ac 52 myFlag(-1), myT1(-1.), myT2(-1.) {
53 }
54 //
36f4947b 55 virtual ~BOPAlgo_VertexFace(){
a0a3f6ac 56 }
57 //
58 void SetIndices(const Standard_Integer nV,
59 const Standard_Integer nF,
60 const Standard_Integer nVx) {
61 myIV=nV;
62 myIF=nF;
63 myIVx=nVx;
64 }
65 //
66 void Indices(Standard_Integer& nV,
67 Standard_Integer& nF,
68 Standard_Integer& nVx) const {
69 nV=myIV;
70 nF=myIF;
71 nVx=myIVx;
72 }
73 //
74 void SetVertex(const TopoDS_Vertex& aV) {
75 myV=aV;
76 }
77 //
78 const TopoDS_Vertex& Vertex()const {
79 return myV;
80 }
81 //
82 void SetFace(const TopoDS_Face& aF) {
83 myF=aF;
84 }
85 //
86 const TopoDS_Face& Face()const {
87 return myF;
88 }
89 //
90 Standard_Integer Flag()const {
91 return myFlag;
92 }
93 //
94 void Parameters(Standard_Real& aT1,
95 Standard_Real& aT2)const {
96 aT1=myT1;
97 aT2=myT2;
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();
a0a3f6ac 110 myFlag=myContext->ComputeVF(myV, myF, myT1, myT2);
111 }
112 //
113 protected:
114 Standard_Integer myIV;
115 Standard_Integer myIF;
116 Standard_Integer myIVx;
117 Standard_Integer myFlag;
118 Standard_Real myT1;
119 Standard_Real myT2;
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//
128typedef BOPCol_TBBContextFunctor
129 <BOPAlgo_VertexFace,
130 BOPAlgo_VectorOfVertexFace,
1e143abb 131 Handle(IntTools_Context),
132 IntTools_Context> BOPAlgo_VertexFaceFunctor;
a0a3f6ac 133//
134typedef BOPCol_TBBContextCnt
135 <BOPAlgo_VertexFaceFunctor,
136 BOPAlgo_VectorOfVertexFace,
1e143abb 137 Handle(IntTools_Context)> BOPAlgo_VertexFaceCnt;
a0a3f6ac 138//
4e57c75e 139//=======================================================================
140// function: PerformVF
141// purpose:
142//=======================================================================
a0a3f6ac 143void BOPAlgo_PaveFiller::PerformVF()
4e57c75e 144{
145 Standard_Boolean bJustAdd;
a0a3f6ac 146 Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, i, aNbVF, k;
4e57c75e 147 Standard_Real aT1, aT2, aTolF, aTolV;
148 BRep_Builder aBB;
a0a3f6ac 149 BOPAlgo_VectorOfVertexFace aVVF;
4e57c75e 150 //
151 myErrorStatus=0;
152 //
153 myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
154 iSize=myIterator->ExpectedLength();
155 if (iSize) {
156 //
157 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
158 aVFs.SetStartSize(iSize);
159 aVFs.SetIncrement(iSize);
160 aVFs.Init();
161 //
162 for (; myIterator->More(); myIterator->Next()) {
163 myIterator->Value(nV, nF, bJustAdd);
164 if(bJustAdd) {
165 continue;
166 }
167 //
168 if (myDS->IsSubShape(nV, nF)) {
169 continue;
170 }
171 //
172 if (myDS->HasInterfShapeSubShapes(nV, nF)) {
c1746a0a 173 myDS->ChangeFaceInfo(nF);
4e57c75e 174 continue;
175 }
176 //
177 nVx=nV;
178 if (myDS->HasShapeSD(nV, nVSD)) {
179 nVx=nVSD;
180 }
181 //
182 if (myDS->HasInterf(nVx, nF)) {
183 continue;
184 }
185 //
a0a3f6ac 186 myDS->ChangeFaceInfo(nF);// !
187 //
4e57c75e 188 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
189 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
190 //
a0a3f6ac 191 BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
192 //
193 aVertexFace.SetIndices(nV, nF, nVx);
194 aVertexFace.SetVertex(aV);
195 aVertexFace.SetFace(aF);
36f4947b 196 aVertexFace.SetProgressIndicator(myProgressIndicator);
a0a3f6ac 197 }//for (; myIterator->More(); myIterator->Next()) {
198 //
199 aNbVF=aVVF.Extent();
200 //================================================================
201 BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
202 //================================================================
203 //
204 for (k=0; k < aNbVF; ++k) {
205 const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
206 //
207 iFlag=aVertexFace.Flag();
208 if (iFlag) {
209 continue;
210 }
211 //
212 aVertexFace.Indices(nV, nF, nVx);
213 aVertexFace.Parameters(aT1, aT2);
214 const TopoDS_Vertex& aV=aVertexFace.Vertex();
215 const TopoDS_Face& aF=aVertexFace.Face();
216 // 1
217 i=aVFs.Append()-1;
218 BOPDS_InterfVF& aVF=aVFs(i);
219 aVF.SetIndices(nVx, nF);
220 aVF.SetUV(aT1, aT2);
221 // 2
222 myDS->AddInterf(nVx, nF);
223 // 3
224 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
225 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
226 aMVIn.Add(nVx);
227 // 4
4e57c75e 228 aTolV = BRep_Tool::Tolerance(aV);
229 aTolF = BRep_Tool::Tolerance(aF);
a0a3f6ac 230 if (aTolV < aTolF) {
231 aBB.UpdateVertex(aV, aTolF);
232 BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVx);
233 Bnd_Box& aBoxV = aSIV.ChangeBox();
234 BRepBndLib::Add(aV, aBoxV);
4e57c75e 235 }
a0a3f6ac 236 }//for (k=0; k < aNbVF; ++k) {
4e57c75e 237 }// if (iSize) {
238 else {
239 iSize=10;
240 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
241 aVFs.SetStartSize(iSize);
242 aVFs.SetIncrement(iSize);
243 aVFs.Init();
244 }
c1746a0a 245 //
4e57c75e 246 TreatVerticesEE();
a0a3f6ac 247}
4e57c75e 248//=======================================================================
249//function : TreatVerticesEE
250//purpose :
251//=======================================================================
a0a3f6ac 252void BOPAlgo_PaveFiller::TreatVerticesEE()
4e57c75e 253{
254 Standard_Integer i, aNbS, aNbEEs, nF, nV, iFlag;
255 Standard_Real aT1, aT2;
256 BOPCol_ListIteratorOfListOfInteger aItLI;
257 Handle(NCollection_IncAllocator) aAllocator;
258 //
4e57c75e 259 aAllocator=new NCollection_IncAllocator();
260 BOPCol_ListOfInteger aLIV(aAllocator), aLIF(aAllocator);
261 BOPCol_MapOfInteger aMI(100, aAllocator);
262 BOPDS_MapOfPaveBlock aMPBF(100, aAllocator);
263 //
264 myErrorStatus=0;
265 //
266
267 aNbS=myDS->NbSourceShapes();
268 //
269 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
270 aNbEEs=aEEs.Extent();
271 for (i=0; i<aNbEEs; ++i) {
272 BOPDS_InterfEE& aEE=aEEs(i);
273 if (aEE.HasIndexNew()) {
274 nV=aEE.IndexNew();
275 if (aMI.Add(nV)) {
276 aLIV.Append(nV);
277 }
278 }
279 }
280 if (!aLIV.Extent()) {
281 aAllocator.Nullify();
282 return;
283 }
284 //
285 aNbS=myDS->NbSourceShapes();
286 for (nF=0; nF<aNbS; ++nF) {
287 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(nF);
288 if (aSI.ShapeType()==TopAbs_FACE) {
289 aLIF.Append(nF);
290 }
291 }
292 if (!aLIF.Extent()) {
293 aAllocator.Nullify();
294 return;
295 }
296 //-------------------------------------------------------------
297 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
298 //
299 BOPDS_SubIterator aIt(aAllocator);
300 //
301 aIt.SetDS(myDS);
302 aIt.SetSubSet1(aLIF);
303 aIt.SetSubSet2(aLIV);
304 aIt.Prepare();
305 aIt.Initialize();
306 for (; aIt.More(); aIt.Next()) {
307 aIt.Value(nV, nF);
308 //
309 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
310 const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn();
311 //
312 if (!aMVOn.Contains(nV)) {
313 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
314 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
315 iFlag=myContext->ComputeVF(aV, aF, aT1, aT2);
316 if (!iFlag) {
317 // 1
318 i=aVFs.Append()-1;
319 BOPDS_InterfVF& aVF=aVFs(i);
320 aVF.SetIndices(nV, nF);
321 aVF.SetUV(aT1, aT2);
322 // 2
323 myDS->AddInterf(nV, nF);
324 //
325 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
326 aMVIn.Add(nV);
327 }
328 }
329 }
330 //
331 aAllocator.Nullify();
4e57c75e 332}