0026619: Tolerances of operands are modified using bop
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_2.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
4e57c75e 18
42cf5bc1 19#include <BOPAlgo_PaveFiller.hxx>
20#include <BOPAlgo_SectionAttribute.hxx>
505abfb8 21#include <BOPCol_NCVector.hxx>
c7b59798 22#include <BOPCol_Parallel.hxx>
42cf5bc1 23#include <BOPDS_Curve.hxx>
24#include <BOPDS_DS.hxx>
4e57c75e 25#include <BOPDS_Interf.hxx>
42cf5bc1 26#include <BOPDS_Iterator.hxx>
4e57c75e 27#include <BOPDS_MapOfPassKey.hxx>
42cf5bc1 28#include <BOPDS_PassKey.hxx>
29#include <BOPDS_PaveBlock.hxx>
30#include <BOPDS_VectorOfInterfVE.hxx>
3510db62 31#include <BOPTools_AlgoTools.hxx>
4e57c75e 32#include <BRep_Builder.hxx>
42cf5bc1 33#include <BRep_Tool.hxx>
34#include <BRepBndLib.hxx>
35#include <gp_Pnt.hxx>
36#include <IntTools_Context.hxx>
3510db62 37#include <IntTools_Tools.hxx>
42cf5bc1 38#include <TopoDS_Edge.hxx>
39#include <TopoDS_Face.hxx>
40#include <TopoDS_Vertex.hxx>
3510db62 41#include <Precision.hxx>
4e57c75e 42
505abfb8 43//=======================================================================
44//class : BOPAlgo_VertexEdgeEdge
45//purpose :
46//=======================================================================
36f4947b 47class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
48
505abfb8 49 public:
36f4947b 50 DEFINE_STANDARD_ALLOC
51
52 BOPAlgo_VertexEdge() :
53 BOPAlgo_Algo(),
3510db62 54 myIV(-1), myIE(-1), myIVx(-1), myFlag(-1), myT(-1.), myTolVNew(-1.) {
505abfb8 55 };
56 //
36f4947b 57 virtual ~BOPAlgo_VertexEdge(){
505abfb8 58 };
59 //
60 void SetIndices(const Standard_Integer nV,
61 const Standard_Integer nE,
62 const Standard_Integer nVx) {
63 myIV=nV;
64 myIE=nE;
65 myIVx=nVx;
66 }
67 //
68 void Indices(Standard_Integer& nV,
69 Standard_Integer& nE,
70 Standard_Integer& nVx) const {
71 nV=myIV;
72 nE=myIE;
73 nVx=myIVx;
74 }
75 //
76 void SetVertex(const TopoDS_Vertex& aV) {
77 myV=aV;
78 }
79 //
505abfb8 80 void SetEdge(const TopoDS_Edge& aE) {
81 myE=aE;
82 }
83 //
3510db62 84 const TopoDS_Vertex& Vertex() const {
85 return myV;
86 }
87 //
88 const TopoDS_Edge& Edge() const {
505abfb8 89 return myE;
90 }
91 //
92 Standard_Integer Flag()const {
93 return myFlag;
94 }
95 //
96 Standard_Real Parameter()const {
97 return myT;
98 }
99 //
3510db62 100 Standard_Real VertexNewTolerance()const {
101 return myTolVNew;
102 }
103 //
1e143abb 104 void SetContext(const Handle(IntTools_Context)& aContext) {
505abfb8 105 myContext=aContext;
106 }
107 //
1e143abb 108 const Handle(IntTools_Context)& Context()const {
505abfb8 109 return myContext;
110 }
111 //
36f4947b 112 virtual void Perform() {
113 BOPAlgo_Algo::UserBreak();
3510db62 114 myFlag=myContext->ComputeVE (myV, myE, myT, myTolVNew);
505abfb8 115 };
116 //
117 protected:
118 Standard_Integer myIV;
119 Standard_Integer myIE;
120 Standard_Integer myIVx;
121 Standard_Integer myFlag;
122 Standard_Real myT;
3510db62 123 Standard_Real myTolVNew;
505abfb8 124 TopoDS_Vertex myV;
125 TopoDS_Edge myE;
1e143abb 126 Handle(IntTools_Context) myContext;
505abfb8 127};
128//=======================================================================
129typedef BOPCol_NCVector
130 <BOPAlgo_VertexEdge> BOPAlgo_VectorOfVertexEdge;
131//
c7b59798 132typedef BOPCol_ContextFunctor
505abfb8 133 <BOPAlgo_VertexEdge,
134 BOPAlgo_VectorOfVertexEdge,
1e143abb 135 Handle(IntTools_Context),
136 IntTools_Context> BOPAlgo_VertexEdgeFunctor;
505abfb8 137//
c7b59798 138typedef BOPCol_ContextCnt
505abfb8 139 <BOPAlgo_VertexEdgeFunctor,
140 BOPAlgo_VectorOfVertexEdge,
1e143abb 141 Handle(IntTools_Context)> BOPAlgo_VertexEdgeCnt;
505abfb8 142//
4e57c75e 143//=======================================================================
144// function: PerformVE
145// purpose:
146//=======================================================================
505abfb8 147void BOPAlgo_PaveFiller::PerformVE()
4e57c75e 148{
149 Standard_Boolean bJustAdd;
402bfe81 150 Standard_Integer iSize, nV, nE, nVSD, iFlag, nVx, k, aNbVE;
3510db62 151 Standard_Real aT, aT1, aT2, aTS1, aTS2;
4e57c75e 152 BOPDS_Pave aPave;
153 BOPDS_PassKey aPK;
154 BOPDS_MapOfPassKey aMPK;
505abfb8 155 BOPAlgo_VectorOfVertexEdge aVVE;
4e57c75e 156 //
157 myErrorStatus=0;
158 //
3510db62 159 FillShrunkData(TopAbs_VERTEX, TopAbs_EDGE);
160 //
4e57c75e 161 myIterator->Initialize(TopAbs_VERTEX, TopAbs_EDGE);
162 iSize=myIterator->ExpectedLength();
163 if (!iSize) {
164 return;
165 }
166 //
167 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
4e57c75e 168 aVEs.SetIncrement(iSize);
4e57c75e 169 //
170 for (; myIterator->More(); myIterator->Next()) {
171 myIterator->Value(nV, nE, bJustAdd);
172 if(bJustAdd) {
173 continue;
174 }
175 //
176 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
177 if (aSIE.HasSubShape(nV)) {
178 continue;
179 }
180 //
181 if (aSIE.HasFlag()){
182 continue;
183 }
184 //
185 if (myDS->HasInterfShapeSubShapes(nV, nE)) {
c1746a0a 186 myDS->ChangePaveBlocks(nE);
4e57c75e 187 continue;
188 }
189 //
190 nVx=nV;
191 if (myDS->HasShapeSD(nV, nVSD)) {
192 nVx=nVSD;
193 }
194 //
195 aPK.SetIds(nVx, nE);
196 if (!aMPK.Add(aPK)) {
197 continue;
198 }
199 //
3510db62 200 const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(nE);
201 if (aLPB.IsEmpty() || !aLPB.First()->HasShrunkData()) {
202 // this is a micro edge, ignore it
203 continue;
204 }
205 //
4e57c75e 206 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
207 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
208 //
505abfb8 209 BOPAlgo_VertexEdge& aVESolver=aVVE.Append1();
210 //
211 aVESolver.SetIndices(nV, nE, nVx);
212 aVESolver.SetVertex(aV);
213 aVESolver.SetEdge(aE);
36f4947b 214 aVESolver.SetProgressIndicator(myProgressIndicator);
505abfb8 215 //
36f4947b 216 }// for (; myIterator->More(); myIterator->Next()) {
505abfb8 217 //
218 aNbVE=aVVE.Extent();
219 //=============================================================
220 BOPAlgo_VertexEdgeCnt::Perform(myRunParallel, aVVE, myContext);
221 //=============================================================
222 //
223 for (k=0; k < aNbVE; ++k) {
224 const BOPAlgo_VertexEdge& aVESolver=aVVE(k);
225 iFlag=aVESolver.Flag();
4e57c75e 226 if (!iFlag) {
505abfb8 227 aVESolver.Indices(nV, nE, nVx);
228 aT=aVESolver.Parameter();
3510db62 229 //
230 // check if vertex hits beyond shrunk range, in such case create V-V interf
231 const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(nE);
232 const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
233 Bnd_Box aBox;
234 aPB->Range(aT1, aT2);
235 aPB->ShrunkData(aTS1, aTS2, aBox);
236 IntTools_Range aPaveR[2] = { IntTools_Range(aT1, aTS1), IntTools_Range(aTS2, aT2) };
237 Standard_Real aTol = Precision::Confusion();
238 Standard_Boolean isOnPave = Standard_False;
239 for (Standard_Integer i = 0; i < 2; i++) {
240 if (IntTools_Tools::IsOnPave1(aT, aPaveR[i], aTol)) {
241 Standard_Integer nV1 = (i == 0 ? aPB->Pave1().Index() : aPB->Pave2().Index());
242 if (!myDS->HasInterf(nV, nV1)) {
243 BOPCol_ListOfInteger aLI;
244 aLI.Append(nV);
245 aLI.Append(nV1);
246 MakeSDVertices(aLI);
247 }
248 isOnPave = Standard_True;
249 break;
250 }
251 }
252 if (isOnPave)
253 continue;
254 //
4e57c75e 255 // 1
402bfe81 256 BOPDS_InterfVE& aVE=aVEs.Append1();
4e57c75e 257 aVE.SetIndices(nV, nE);
258 aVE.SetParameter(aT);
259 // 2
260 myDS->AddInterf(nV, nE);
3510db62 261 //
262 // 3 update vertex V/E if necessary
263 Standard_Real aTolVNew = aVESolver.VertexNewTolerance();
264 nVx=UpdateVertex(nV, aTolVNew);
265 //4
266 if (myDS->IsNewShape(nVx)) {
267 aVE.SetIndexNew(nVx);
268 }
269 //5 append ext pave to pave block
4e57c75e 270 aPave.SetIndex(nVx);
271 aPave.SetParameter(aT);
272 aPB->AppendExtPave(aPave);
4e57c75e 273 }
505abfb8 274 }//for (k=0; k < aNbVE; ++k) {
4e57c75e 275}