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