b311480e |
1 | // Created on: 1996-01-05 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <TopOpeBRepBuild_FaceBuilder.ixx> |
18 | |
19 | #include <gp_Pnt.hxx> |
20 | #include <gp_Pnt2d.hxx> |
21 | #include <TopAbs_Orientation.hxx> |
22 | #include <TopoDS.hxx> |
23 | #include <TopoDS_Compound.hxx> |
24 | #include <TopoDS_Face.hxx> |
25 | #include <TopoDS_Edge.hxx> |
26 | #include <TopoDS_Vertex.hxx> |
27 | #include <TopOpeBRepDS_BuildTool.hxx> |
28 | #include <BRep_Tool.hxx> |
29 | #include <BRep_Builder.hxx> |
30 | //#include <BRepAdaptor_Curve2d.hxx> |
31 | #include <TopExp.hxx> |
32 | #include <TopTools_Array1OfShape.hxx> |
33 | #include <TopTools_ListOfShape.hxx> |
34 | #include <TopTools_IndexedMapOfOrientedShape.hxx> |
35 | #include <TopTools_IndexedDataMapOfShapeShape.hxx> |
36 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
37 | #include <TopTools_DataMapOfShapeListOfShape.hxx> |
38 | #include <TopTools_DataMapOfShapeListOfShape.hxx> |
39 | #include <TopOpeBRepBuild_WireEdgeClassifier.hxx> |
40 | #include <TopOpeBRepBuild_Loop.hxx> |
41 | #include <TopOpeBRepBuild_BlockBuilder.hxx> |
42 | #include <TopOpeBRepBuild_LoopSet.hxx> |
43 | #include <Standard_ProgramError.hxx> |
44 | #include <Precision.hxx> |
45 | #include <TopTools_IndexedMapOfShape.hxx> |
46 | #include <TopTools_DataMapOfShapeInteger.hxx> |
47 | #include <TopOpeBRepBuild_define.hxx> |
48 | |
49 | #undef RM_HANGING |
50 | // MSV: RM_HANGING behaviour: when state of wire is UNCLOSEDW we do not |
51 | // remove the whole wire but remove the chains of hanging edges. This would |
52 | // produce a good result in some cases. But :-( it gives regressions on grid |
53 | // tests (1cto 021 W4,X4). Therefore I leaved this code not active. |
54 | #ifdef RM_HANGING |
55 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
56 | #endif |
57 | |
0797d9d3 |
58 | #ifdef OCCT_DEBUG |
1d0a9d4d |
59 | extern Standard_Boolean TopOpeBRepBuild_GettracePURGE(); |
60 | extern Standard_Boolean TopOpeBRepDS_GettraceSTRANGE(); |
7fd59977 |
61 | #include <TopOpeBRepDS_DSX.hxx> |
62 | void debifb() {} |
63 | #endif |
64 | |
65 | #ifdef DRAW |
66 | #include <TopOpeBRepTool_DRAW.hxx> |
67 | #endif |
68 | |
69 | //======================================================================= |
70 | //function : TopOpeBRepBuild_FaceBuilder |
71 | //purpose : |
72 | //======================================================================= |
73 | TopOpeBRepBuild_FaceBuilder::TopOpeBRepBuild_FaceBuilder() |
74 | { |
75 | } |
76 | |
77 | //======================================================================= |
78 | //function : TopOpeBRepBuild_FaceBuilder |
79 | //purpose : |
80 | //======================================================================= |
81 | TopOpeBRepBuild_FaceBuilder::TopOpeBRepBuild_FaceBuilder(TopOpeBRepBuild_WireEdgeSet& WES,const TopoDS_Shape& F,const Standard_Boolean ForceClass) |
82 | { |
83 | InitFaceBuilder(WES,F,ForceClass); |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : InitFaceBuilder |
88 | //purpose : |
89 | //======================================================================= |
90 | void TopOpeBRepBuild_FaceBuilder::InitFaceBuilder(TopOpeBRepBuild_WireEdgeSet& WES,const TopoDS_Shape& F,const Standard_Boolean ForceClass) |
91 | { |
92 | myFace = TopoDS::Face(F); |
0797d9d3 |
93 | #ifdef OCCT_DEBUG |
7fd59977 |
94 | Standard_Boolean deb = TopOpeBRepDS_GettraceSPSX(myFace); |
95 | if (deb) debifb(); |
96 | #endif |
97 | MakeLoops(WES); |
98 | TopOpeBRepBuild_BlockBuilder& BB = myBlockBuilder; |
99 | TopOpeBRepBuild_WireEdgeClassifier WEC(F,BB); |
100 | TopOpeBRepBuild_LoopSet& LS = myLoopSet; |
101 | myFaceAreaBuilder.InitFaceAreaBuilder(LS,WEC,ForceClass); |
7fd59977 |
102 | } |
103 | |
104 | //--------------------------------------------------------------- |
105 | void FUN_DetectVerticesOn1Edge(const TopoDS_Shape& W,TopTools_IndexedDataMapOfShapeShape& mapVon1E) |
106 | { |
107 | // Fills the map <mapVon1edge>,with vertices of <W> of 3d connexity 1. |
108 | TopTools_IndexedDataMapOfShapeListOfShape mapVedges; |
109 | TopExp::MapShapesAndAncestors(W,TopAbs_VERTEX,TopAbs_EDGE,mapVedges); |
110 | Standard_Integer nV = mapVedges.Extent(); |
111 | |
112 | for (Standard_Integer i = 1;i <= nV;i++) { |
113 | const TopoDS_Shape& V = mapVedges.FindKey(i); |
114 | if (V.Orientation() == TopAbs_INTERNAL) continue; |
115 | |
116 | const TopTools_ListOfShape& loE = mapVedges.FindFromIndex(i); |
117 | if (loE.Extent() < 2) { |
118 | // Keeping INTERNAL or EXTERNAL edges |
119 | const TopoDS_Shape& E = loE.First(); |
120 | TopAbs_Orientation oriE = E.Orientation(); |
121 | if ((oriE == TopAbs_INTERNAL) || (oriE == TopAbs_EXTERNAL)) continue; |
122 | mapVon1E.Add(V,E); |
123 | } |
124 | } |
125 | } |
126 | |
127 | #define ISUNKNOWN -1 |
128 | #define ISVERTEX 0 |
129 | #define GCLOSEDW 1 |
130 | #define UNCLOSEDW 2 |
131 | #define CLOSEDW 10 |
132 | Standard_Integer FUN_AnalyzemapVon1E(const TopTools_IndexedDataMapOfShapeShape& mapVon1E, |
133 | TopTools_IndexedDataMapOfShapeShape& mapVV) |
134 | { |
135 | #ifdef DRAW |
136 | Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE(); |
137 | if (trc) cout<<endl<<"* DetectUnclosedWire :"<<endl; |
138 | #endif |
139 | |
140 | Standard_Integer res = ISUNKNOWN; |
141 | |
142 | Standard_Integer nV = mapVon1E.Extent(); |
143 | if (nV == 0) { |
144 | res = CLOSEDW; |
145 | } |
146 | else if (nV == 1) { |
147 | const TopoDS_Shape& E = mapVon1E.FindFromIndex(1); |
148 | Standard_Boolean Eclosed = E.Closed(); |
149 | Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(E)); |
150 | if (dgE) res = ISVERTEX; |
151 | else if (Eclosed) res = CLOSEDW; |
152 | else res = UNCLOSEDW; |
153 | } |
154 | else { |
155 | // Finding among all vertices,couple of vertices falling on same |
156 | // geometry. |
157 | // Filling up map <mapVV>,with (vi,vj),vi and vj are on same point. |
158 | Standard_Real tol = Precision::Confusion(); |
159 | for (Standard_Integer i = 1;i <= nV;i++) { |
160 | const TopoDS_Vertex& vi = TopoDS::Vertex(mapVon1E.FindKey(i)); |
161 | gp_Pnt pi = BRep_Tool::Pnt(vi); |
162 | for (Standard_Integer j = i+1;j <= nV;j++) { |
163 | const TopoDS_Vertex& vj = TopoDS::Vertex(mapVon1E.FindKey(j)); |
164 | gp_Pnt pj = BRep_Tool::Pnt(vj); |
165 | Standard_Boolean same = pi.IsEqual(pj,tol); |
166 | if (same) { |
167 | mapVV.Add(vi,vj); |
168 | mapVV.Add(vj,vi); |
169 | break; |
170 | } |
171 | } // j |
172 | } // i |
173 | Standard_Integer nVV = mapVV.Extent(); |
174 | #ifdef RM_HANGING |
175 | // MSV Oct 4, 2001: consider GCLOSEDW even if not all vertices from mapVon1E |
176 | // hit into mapVV; reason is the left vertices may start |
177 | // useless chains of hanging edges that can be removed to |
178 | // achieve a closed wire. |
179 | if (nVV > 0) res = GCLOSEDW; |
180 | #else |
181 | if (nVV == nV) res = GCLOSEDW; |
182 | #endif |
183 | else res = UNCLOSEDW; |
184 | } |
185 | return res; |
186 | } // FUN_AnalyzemapVon1E |
187 | |
188 | #ifdef DRAW |
189 | void FUN_AnalyzemapVon1EDRAW(const Standard_Integer res, |
190 | const TopTools_IndexedDataMapOfShapeShape& mapVon1E, |
191 | const TopTools_IndexedDataMapOfShapeShape& mapVV, |
192 | const TopoDS_Shape& W,const Standard_Integer iiwi, |
193 | TopTools_IndexedDataMapOfShapeShape& mapVon1EdgeDRAW, |
194 | TopTools_IndexedDataMapOfShapeShape& mapVVsameGDRAW) |
195 | { |
196 | Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE(); |
197 | if (!trc) return; |
198 | cout<<"wire "<<iiwi; |
199 | if (res == ISVERTEX) { |
200 | cout<<" is vertex"<<endl; |
201 | } |
202 | else if (res == CLOSEDW) { |
203 | cout<<" is closed"<<endl; |
204 | } |
205 | else if (res == GCLOSEDW) { |
206 | cout<<" is Gclosed :"<<endl; |
207 | TCollection_AsciiString aa("w_");FUN_tool_draw(aa,W,iiwi); |
208 | Standard_Integer i ; |
209 | for ( i = 1;i <= mapVV.Extent();i++) { |
210 | Standard_Integer iV = mapVVsameGDRAW.Add(mapVV.FindKey(i),mapVV.FindFromIndex(i)); |
211 | cout<<" on vve_"<<iV; aa = "vve_"; |
212 | FUN_tool_draw(aa,mapVVsameGDRAW.FindKey(iV),iV); |
213 | } |
214 | for (i = 1;i <= mapVon1E.Extent();i++) { |
215 | Standard_Integer iE = mapVon1EdgeDRAW.Add(mapVon1E.FindKey(i),mapVon1E.FindFromIndex(i)); |
216 | cout<<" on eed_"<<iE; aa = "eed_"; |
217 | FUN_tool_draw(aa,mapVon1EdgeDRAW.FindFromIndex(iE),iE); |
218 | } |
219 | cout<<endl; |
220 | } |
221 | else if (res == UNCLOSEDW) { |
222 | cout<<" is unclosed "<<endl; |
223 | TCollection_AsciiString aa("w_");FUN_tool_draw(aa,W,iiwi); |
224 | } |
225 | cout<<endl; |
226 | } // FUN_AnalyzemapVon1EDRAW |
227 | #endif |
228 | |
229 | //======================================================================= |
230 | //function : DetectUnclosedWire |
231 | //purpose : |
232 | //======================================================================= |
233 | void TopOpeBRepBuild_FaceBuilder::DetectUnclosedWire(TopTools_IndexedDataMapOfShapeShape& mapVVsameG, |
234 | TopTools_IndexedDataMapOfShapeShape& mapVon1Edge) |
235 | { |
236 | // wire unclosed : has vertices of connexity == 1 |
237 | // exception : a wire of one closed edge with only one vertex describing |
238 | // a face or a degenerated edge. |
239 | |
240 | mapVVsameG.Clear(); |
241 | mapVon1Edge.Clear(); |
242 | |
243 | // During the wire processing, |
244 | // * IF THE WIRE IS G-CLOSED,we fill up the maps : |
245 | // - <mapVVsameG> with vertices falling on same geometry |
246 | // - <mapVon1Edge> with (key = vertex,item = edge), |
247 | // the vertex is connected to only one unclosed,undegenerated edge. |
248 | // * Else,if it is unclosed,we delete it (or it`s hanging edges). |
249 | |
250 | #ifdef DRAW |
251 | TopTools_IndexedDataMapOfShapeShape mapVon1EdgeDRAW,mapVVsameGDRAW; |
252 | Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE(); |
253 | if (trc) cout<<endl<<"* DetectUnclosedWire :"<<endl<<endl; |
254 | #endif |
255 | |
256 | Standard_Integer iiwi = 0; // DEB |
257 | |
258 | InitFace(); |
259 | for (;MoreFace();NextFace()) { |
260 | InitWire(); |
261 | for (;MoreWire();NextWire()) { |
262 | iiwi++; |
263 | Standard_Boolean isold = IsOldWire(); |
264 | #ifdef DRAW |
265 | if ( trc && isold ) cout<<"wire "<<iiwi<<" is old wire => closed"<<endl; |
266 | #endif |
267 | if (isold) continue; |
268 | |
269 | TopoDS_Compound cmp;BRep_Builder BB;BB.MakeCompound(cmp); |
270 | InitEdge(); |
271 | for(;MoreEdge();NextEdge()) AddEdgeWire(Edge(),cmp); |
272 | TopoDS_Shape W = cmp; |
273 | |
274 | // <mapVon1E> binds vertices of connexity 1 attached to one non-closed,non-degenerated edge. |
275 | TopTools_IndexedDataMapOfShapeShape mapVon1E; |
276 | FUN_DetectVerticesOn1Edge(W,mapVon1E); |
277 | |
278 | TopTools_IndexedDataMapOfShapeShape mapVV; |
279 | Standard_Integer res = FUN_AnalyzemapVon1E(mapVon1E,mapVV); |
280 | #ifdef DRAW |
281 | FUN_AnalyzemapVon1EDRAW(res,mapVon1E,mapVV,W,iiwi,mapVon1EdgeDRAW,mapVVsameGDRAW); |
282 | #endif |
283 | |
284 | if (res == ISVERTEX) { |
285 | continue; |
286 | } |
287 | else if (res == CLOSEDW) { |
288 | continue; |
289 | } |
290 | else if (res == GCLOSEDW) { |
291 | Standard_Integer i; |
292 | for (i = 1;i <= mapVV.Extent();i++) { |
293 | mapVVsameG.Add(mapVV.FindKey(i),mapVV.FindFromIndex(i)); |
294 | } |
295 | for (i = 1;i <= mapVon1E.Extent();i++) { |
296 | mapVon1Edge.Add(mapVon1E.FindKey(i),mapVon1E.FindFromIndex(i)); |
297 | } |
298 | } |
299 | else if (res == UNCLOSEDW) { |
300 | #ifdef RM_HANGING |
301 | // MSV Oct 4, 2001: remove hanging edges |
302 | TopTools_IndexedDataMapOfShapeListOfShape mapVE; |
303 | TopExp::MapShapesAndAncestors (W, TopAbs_VERTEX, TopAbs_EDGE, mapVE); |
304 | Standard_Integer nV = mapVon1E.Extent(); |
305 | for (Standard_Integer i = 1; i <= nV; i++) |
306 | { |
307 | TopoDS_Vertex V = TopoDS::Vertex (mapVon1E.FindKey(i)); |
308 | if (mapVV.Contains(V)) continue; // V is in same geometry pair |
309 | while (1) |
310 | { |
311 | const TopTools_ListOfShape &LE = mapVE.FindFromKey(V); |
312 | |
313 | // get not yet processed edge, count the number of such edges |
314 | Standard_Integer nEdges = 0; |
315 | TopoDS_Edge Edge; |
316 | TColStd_ListOfInteger LOI; |
317 | TopTools_ListIteratorOfListOfShape itE (LE); |
318 | for (; itE.More() && nEdges <= 1; itE.Next()) |
319 | { |
320 | const TopoDS_Edge &E = TopoDS::Edge (itE.Value()); |
321 | Standard_Integer I = myBlockBuilder.Element(E); |
322 | if (!E.Closed() && myBlockBuilder.ElementIsValid(I)) |
323 | { |
324 | TopoDS_Vertex Vf,Vl; |
325 | TopExp::Vertices (E, Vf, Vl); |
326 | LOI.Append(I); |
327 | // consider not small edges only |
328 | if (!Vf.IsSame(Vl)) |
329 | { |
330 | Edge = E; |
331 | nEdges++; |
332 | } |
333 | } |
334 | } |
335 | if (nEdges != 1) break; // stop this chain |
336 | |
337 | // remove edges from Block Builder |
338 | TColStd_ListIteratorOfListOfInteger itLOI (LOI); |
339 | for (; itLOI.More(); itLOI.Next()) |
340 | myBlockBuilder.SetValid (itLOI.Value(), Standard_False); |
341 | |
342 | // get other vertex |
343 | TopoDS_Vertex aV1, aV2, otherV; |
344 | TopExp::Vertices (Edge, aV1, aV2); |
345 | if (aV1.IsSame (V)) |
346 | otherV = aV2; |
347 | else if (aV2.IsSame (V)) |
348 | otherV = aV1; |
349 | if (otherV.IsNull()) break; |
350 | V = otherV; |
351 | } |
352 | } |
353 | #else |
354 | TopExp_Explorer ex; |
355 | for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) { |
356 | // for (TopExp_Explorer ex(W,TopAbs_EDGE);ex.More();ex.Next()) { |
357 | Standard_Integer I = myBlockBuilder.Element(ex.Current()); |
358 | myBlockBuilder.SetValid(I,Standard_False); |
359 | } |
360 | #endif |
361 | } |
362 | } // MoreWire |
363 | } // MoreFace |
364 | } // DetectUnclosedWire |
365 | |
366 | //======================================================================= |
367 | //function : CorrectGclosedWire |
368 | //purpose : |
369 | //======================================================================= |
370 | void TopOpeBRepBuild_FaceBuilder::CorrectGclosedWire(const TopTools_IndexedDataMapOfShapeShape& mapVVref, |
371 | const TopTools_IndexedDataMapOfShapeShape& mapVon1Edge) |
372 | { |
373 | // prequesitory : edges described by <mapVon1Edge> are not closed,not degenerated |
0797d9d3 |
374 | #ifdef OCCT_DEBUG |
7fd59977 |
375 | Standard_Boolean trc = TopOpeBRepDS_GettraceSTRANGE(); |
376 | if (TopOpeBRepBuild_GettracePURGE()) { |
377 | cout<<endl<<"* CorrectGclosedWire :"<<endl<<endl; |
378 | trc = Standard_True; |
379 | } |
380 | #endif |
381 | |
382 | Standard_Integer nVV = mapVVref.Extent(); |
383 | for (Standard_Integer i = 1;i <= nVV;i++) { |
384 | const TopoDS_Vertex& V = TopoDS::Vertex(mapVVref.FindKey(i)); |
385 | const TopoDS_Vertex& Vref = TopoDS::Vertex(mapVVref.FindFromIndex(i)); |
386 | |
387 | if (V.IsSame(Vref)) continue; |
388 | |
389 | TopoDS_Edge E = TopoDS::Edge(mapVon1Edge.FindFromKey(V)); |
390 | Standard_Real paronE = BRep_Tool::Parameter(V,E); |
391 | |
392 | BRep_Builder BB;E.Free(Standard_True); |
393 | BB.Remove(E,V); |
394 | TopoDS_Shape aLocalShape = Vref.Oriented(V.Orientation()); |
395 | TopoDS_Vertex newVref = TopoDS::Vertex(aLocalShape); |
396 | // TopoDS_Vertex newVref = TopoDS::Vertex(Vref.Oriented(V.Orientation())); |
397 | BB.Add(E,newVref); |
0797d9d3 |
398 | #ifdef OCCT_DEBUG |
7fd59977 |
399 | Standard_Integer iV = i,iVref = mapVVref.FindIndex(Vref),iE = mapVon1Edge.FindIndex(V); |
400 | if (trc) cout << " replacing V "<<iV<<" with V "<<iVref<<" on edge "<<iE<<endl; |
401 | #endif |
402 | TopOpeBRepDS_BuildTool BT; |
403 | BT.Parameter(E,newVref,paronE); |
404 | } |
405 | } |
406 | |
407 | //======================================================================= |
408 | //function : DetectPseudoInternalEdge |
409 | //purpose : |
410 | //======================================================================= |
411 | void TopOpeBRepBuild_FaceBuilder::DetectPseudoInternalEdge(TopTools_IndexedMapOfShape& MapE) |
412 | { |
413 | TopoDS_Compound cmp;BRep_Builder BB;BB.MakeCompound(cmp); |
414 | InitFace(); |
415 | for (;MoreFace();NextFace()) { |
416 | InitWire(); |
417 | for (;MoreWire();NextWire()) { |
418 | Standard_Boolean isold = IsOldWire(); if (isold) continue; |
419 | InitEdge(); |
420 | for(;MoreEdge();NextEdge()) AddEdgeWire(Edge(),cmp); |
421 | } // MoreWire |
422 | } // MoreFace |
423 | |
424 | TopTools_IndexedDataMapOfShapeListOfShape mapVOE; |
425 | TopExp::MapShapesAndAncestors(cmp,TopAbs_VERTEX,TopAbs_EDGE,mapVOE); |
426 | Standard_Integer nv = mapVOE.Extent(); |
427 | |
428 | MapE.Clear(); |
429 | for (Standard_Integer i = 1; i <= nv; i++) { |
430 | const TopTools_ListOfShape& le = mapVOE.FindFromIndex(i); |
431 | Standard_Integer ne = le.Extent(); |
432 | if (ne == 2) { |
433 | TopTools_ListIteratorOfListOfShape ile(le); const TopoDS_Shape& e1 = ile.Value(); |
434 | ile.Next(); const TopoDS_Shape& e2 = ile.Value(); |
435 | Standard_Boolean same = e1.IsSame(e2); |
436 | TopAbs_Orientation o1 = e1.Orientation(); |
437 | TopAbs_Orientation o2 = e2.Orientation(); |
438 | Standard_Boolean o1co2 = (o1 == TopAbs::Complement(o2)); |
439 | |
440 | if ( same && o1co2 ) { |
441 | MapE.Add(e1); |
442 | |
443 | Standard_Integer ie1 = myBlockBuilder.Element(e1); |
444 | myBlockBuilder.SetValid(ie1,Standard_False); |
445 | |
446 | Standard_Integer ie2 = myBlockBuilder.Element(e2); |
447 | myBlockBuilder.SetValid(ie2,Standard_False); |
448 | } |
449 | } |
450 | } |
451 | |
452 | } |
453 | |
454 | //======================================================================= |
455 | //function : Face |
456 | //purpose : |
457 | //======================================================================= |
458 | const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::Face() const |
459 | { |
460 | return myFace; |
461 | } |
462 | |
463 | //======================================================================= |
464 | //function : InitFace |
465 | //purpose : |
466 | //======================================================================= |
467 | Standard_Integer TopOpeBRepBuild_FaceBuilder::InitFace() |
468 | { |
469 | Standard_Integer n = myFaceAreaBuilder.InitArea(); |
470 | return n; |
471 | } |
472 | |
473 | //======================================================================= |
474 | //function : MoreFace |
475 | //purpose : |
476 | //======================================================================= |
477 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreFace() const |
478 | { |
479 | Standard_Boolean b = myFaceAreaBuilder.MoreArea(); |
480 | return b; |
481 | } |
482 | |
483 | //======================================================================= |
484 | //function : NextFace |
485 | //purpose : |
486 | //======================================================================= |
487 | void TopOpeBRepBuild_FaceBuilder::NextFace() |
488 | { |
489 | myFaceAreaBuilder.NextArea(); |
490 | } |
491 | |
492 | //======================================================================= |
493 | //function : InitWire |
494 | //purpose : |
495 | //======================================================================= |
496 | Standard_Integer TopOpeBRepBuild_FaceBuilder::InitWire() |
497 | { |
498 | Standard_Integer n = myFaceAreaBuilder.InitLoop(); |
499 | return n; |
500 | } |
501 | |
502 | //======================================================================= |
503 | //function : MoreWire |
504 | //purpose : |
505 | //======================================================================= |
506 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreWire() const |
507 | { |
508 | Standard_Boolean b = myFaceAreaBuilder.MoreLoop(); |
509 | return b; |
510 | } |
511 | |
512 | //======================================================================= |
513 | //function : NextWire |
514 | //purpose : |
515 | //======================================================================= |
516 | void TopOpeBRepBuild_FaceBuilder::NextWire() |
517 | { |
518 | myFaceAreaBuilder.NextLoop(); |
519 | } |
520 | |
521 | //======================================================================= |
522 | //function : IsOldWire |
523 | //purpose : |
524 | //======================================================================= |
525 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::IsOldWire() const |
526 | { |
527 | const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop(); |
528 | Standard_Boolean b = L->IsShape(); |
529 | return b; |
530 | } |
531 | |
532 | //======================================================================= |
533 | //function : OldWire |
534 | //purpose : |
535 | //======================================================================= |
536 | const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::OldWire() const |
537 | { |
538 | const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop(); |
539 | const TopoDS_Shape& B = L->Shape(); |
540 | return B; |
541 | } |
542 | |
543 | //======================================================================= |
544 | //function : FindNextValidElement |
545 | //purpose : |
546 | //======================================================================= |
547 | void TopOpeBRepBuild_FaceBuilder::FindNextValidElement() |
548 | { |
549 | // prerequisites : myBlockIterator.Initialize |
550 | myFaceAreaBuilder.Loop(); |
551 | Standard_Boolean found = Standard_False; |
552 | |
553 | while ( myBlockIterator.More()) { |
554 | const Standard_Integer i = myBlockIterator.Value(); |
555 | found = myBlockBuilder.ElementIsValid(i); |
556 | if (found) break; |
557 | else myBlockIterator.Next(); |
558 | } |
559 | } |
560 | |
561 | //======================================================================= |
562 | //function : InitEdge |
563 | //purpose : |
564 | //======================================================================= |
565 | Standard_Integer TopOpeBRepBuild_FaceBuilder::InitEdge() |
566 | { |
567 | const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop(); |
568 | if ( L->IsShape() ) |
569 | Standard_DomainError::Raise("TopOpeBRepBuild_FaceBuilder:InitEdge"); |
570 | else { |
571 | myBlockIterator = L->BlockIterator(); |
572 | myBlockIterator.Initialize(); |
573 | FindNextValidElement(); |
574 | } |
575 | Standard_Integer n = myBlockIterator.Extent(); |
576 | return n; |
577 | } |
578 | |
579 | //======================================================================= |
580 | //function : MoreEdge |
581 | //purpose : |
582 | //======================================================================= |
583 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreEdge() const |
584 | { |
585 | Standard_Boolean b = myBlockIterator.More(); |
586 | return b; |
587 | } |
588 | |
589 | //======================================================================= |
590 | //function : NextEdge |
591 | //purpose : |
592 | //======================================================================= |
593 | void TopOpeBRepBuild_FaceBuilder::NextEdge() |
594 | { |
595 | myBlockIterator.Next(); |
596 | FindNextValidElement(); |
597 | } |
598 | |
599 | //======================================================================= |
600 | //function : Edge |
601 | //purpose : |
602 | //======================================================================= |
603 | const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::Edge() const |
604 | { |
605 | if (!myBlockIterator.More()) Standard_Failure::Raise("OutOfRange"); |
606 | |
607 | const Standard_Integer i = myBlockIterator.Value(); |
608 | Standard_Boolean isvalid = myBlockBuilder.ElementIsValid(i); |
609 | if (!isvalid) Standard_Failure::Raise("Edge not Valid"); |
610 | |
611 | const TopoDS_Shape& E = myBlockBuilder.Element(i); |
612 | return E; |
613 | } |
614 | |
615 | //======================================================================= |
616 | //function : EdgeConnexity |
617 | //purpose : |
618 | //======================================================================= |
619 | Standard_Integer TopOpeBRepBuild_FaceBuilder::EdgeConnexity(const TopoDS_Shape& /*E*/) const |
620 | { |
0797d9d3 |
621 | #ifdef OCCT_DEBUG |
7fd59977 |
622 | Standard_ProgramError::Raise("FaceBuilder::EdgeConnexity management disactivated"); |
623 | #endif |
624 | return 0; |
625 | // Standard_Boolean inmosi = myMOSI.IsBound(E); |
626 | // Standard_Integer nmosi = (inmosi) ? myMOSI.Find(E) : 0; |
627 | // return nmosi; |
628 | } |
629 | |
630 | //======================================================================= |
631 | //function : AddEdgeWire |
632 | //purpose : |
633 | //======================================================================= |
634 | Standard_Integer TopOpeBRepBuild_FaceBuilder::AddEdgeWire(const TopoDS_Shape& E,TopoDS_Shape& W) const |
635 | { |
636 | Standard_Integer nadd = 0; |
637 | BRep_Builder BB; |
638 | BB.Add(W,E);nadd++; |
639 | // Standard_Integer nmosi = EdgeConnexity(E); |
640 | // Standard_Boolean addEC = (nmosi == 1); |
641 | // if (addEC) { |
642 | // TopAbs_Orientation oe = E.Orientation(); |
643 | // TopAbs_Orientation oc = TopAbs::Complement(oe); |
644 | // TopoDS_Shape EC = E.Oriented(oc); |
645 | // BB.Add(W,EC);nadd++; |
646 | // } |
647 | return nadd; |
648 | } |
649 | |
650 | //======================================================================= |
651 | //function : MakeLoops |
652 | //purpose : |
653 | //======================================================================= |
654 | void TopOpeBRepBuild_FaceBuilder::MakeLoops(TopOpeBRepBuild_ShapeSet& SS) |
655 | { |
656 | TopOpeBRepBuild_BlockBuilder& BB = myBlockBuilder; |
657 | TopOpeBRepBuild_ListOfLoop& LL = myLoopSet.ChangeListOfLoop(); |
658 | |
659 | // Build blocks on elements of SS |
660 | BB.MakeBlock(SS); |
661 | |
662 | // make list of loop (LL) of the LoopSet |
663 | // - on shapes of the ShapeSet (SS) |
664 | // - on blocks of the BlockBuilder (BB) |
665 | |
666 | // Add shapes of SS as shape loops |
667 | LL.Clear(); |
668 | for(SS.InitShapes();SS.MoreShapes();SS.NextShape()) { |
669 | const TopoDS_Shape& S = SS.Shape(); |
670 | Handle(TopOpeBRepBuild_Loop) ShapeLoop = new TopOpeBRepBuild_Loop(S); |
671 | LL.Append(ShapeLoop); |
672 | } |
673 | |
674 | // Add blocks of BB as block loops |
675 | for (BB.InitBlock();BB.MoreBlock();BB.NextBlock()) { |
676 | TopOpeBRepBuild_BlockIterator BI = BB.BlockIterator(); |
677 | Handle(TopOpeBRepBuild_Loop) BlockLoop = new TopOpeBRepBuild_Loop(BI); |
678 | LL.Append(BlockLoop); |
679 | } |
680 | |
681 | } |