Warnings on vc14 were eliminated
[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
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(),
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//
4e57c75e 139//=======================================================================
140// function: PerformVF
141// purpose:
142//=======================================================================
a0a3f6ac 143void BOPAlgo_PaveFiller::PerformVF()
4e57c75e 144{
4e57c75e 145 myErrorStatus=0;
146 //
147 myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
483ce1bd 148 Standard_Integer iSize = myIterator->ExpectedLength();
149 //
483ce1bd 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
4e57c75e 155 for (; myIterator->More(); myIterator->Next()) {
25dfc507 156 myIterator->Value(nV, nF);
157 if (!myDS->IsSubShape(nV, nF)) {
c1746a0a 158 myDS->ChangeFaceInfo(nF);
4e57c75e 159 }
483ce1bd 160 }
161 return;
162 }
163 //
164 BOPDS_VectorOfInterfVF& aVFs = myDS->InterfVF();
165 if (!iSize) {
166 iSize = 10;
4e57c75e 167 aVFs.SetIncrement(iSize);
483ce1bd 168 //
169 TreatVerticesEE();
170 return;
4e57c75e 171 }
c1746a0a 172 //
483ce1bd 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()) {
25dfc507 180 myIterator->Value(nV, nF);
483ce1bd 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 //
4e57c75e 244 TreatVerticesEE();
a0a3f6ac 245}
4e57c75e 246//=======================================================================
247//function : TreatVerticesEE
248//purpose :
249//=======================================================================
a0a3f6ac 250void BOPAlgo_PaveFiller::TreatVerticesEE()
4e57c75e 251{
402bfe81 252 Standard_Integer i, aNbS,aNbEEs, nF, nV, iFlag;
3510db62 253 Standard_Real aT1, aT2, dummy;
4e57c75e 254 BOPCol_ListIteratorOfListOfInteger aItLI;
488e5b9d 255 Handle(NCollection_BaseAllocator) aAllocator;
4e57c75e 256 //
488e5b9d 257 aAllocator=
258 NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 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)));
0d0481c7 314 iFlag = myContext->ComputeVF(aV, aF, aT1, aT2, dummy, myFuzzyValue);
4e57c75e 315 if (!iFlag) {
316 // 1
402bfe81 317 BOPDS_InterfVF& aVF=aVFs.Append1();
318 i=aVFs.Extent()-1;
4e57c75e 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 }
4e57c75e 329}