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