Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: BRepFill_OffsetWire.cxx |
2 | // Created: Thu Apr 20 10:33:55 1995 | |
3 | // Author: Bruno DUMORTIER | |
4 | // <dub@fuegox> | |
5 | ||
6 | // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 | |
7 | ||
8 | #include <stdio.h> | |
9 | ||
10 | #include <BRepFill_OffsetWire.ixx> | |
11 | ||
12 | #include <BRepAdaptor_Curve.hxx> | |
13 | #include <BRepAdaptor_Surface.hxx> | |
14 | ||
15 | #include <BRepFill_DataMapOfNodeShape.hxx> | |
16 | #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx> | |
17 | #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx> | |
18 | #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx> | |
7fd59977 | 19 | #include <BRepFill_TrimEdgeTool.hxx> |
20 | #include <BRepLib.hxx> | |
21 | #include <BRepLib_MakeVertex.hxx> | |
22 | #include <BRepLib_MakeFace.hxx> | |
23 | #include <BRepLib_MakeWire.hxx> | |
24 | #include <BRepLib_MakeEdge.hxx> | |
25 | #include <BRepTools.hxx> | |
26 | #include <BRep_Builder.hxx> | |
27 | #include <BRep_Tool.hxx> | |
28 | #include <BRep_TEdge.hxx> | |
29 | #include <BRep_CurveRepresentation.hxx> | |
30 | #include <BRep_GCurve.hxx> | |
31 | #include <BRepTools_WireExplorer.hxx> | |
32 | #include <BRepMAT2d_Explorer.hxx> | |
33 | #include <Geom2dAdaptor_Curve.hxx> | |
34 | #include <Geom2dAdaptor_HCurve.hxx> | |
35 | #include <Adaptor3d_OffsetCurve.hxx> | |
36 | #include <Adaptor3d_Curve.hxx> | |
37 | #include <Geom_Surface.hxx> | |
38 | #include <Geom_Plane.hxx> | |
39 | #include <Geom2d_Curve.hxx> | |
40 | #include <Geom2d_Circle.hxx> | |
41 | #include <Geom2d_Line.hxx> | |
42 | #include <Geom2d_TrimmedCurve.hxx> | |
43 | #include <Geom2d_OffsetCurve.hxx> | |
44 | #include <GeomAPI.hxx> | |
45 | #include <Geom_TrimmedCurve.hxx> | |
46 | #include <Geom_Circle.hxx> | |
47 | #include <Geom_OffsetCurve.hxx> | |
48 | #include <MAT_Arc.hxx> | |
49 | #include <MAT_Node.hxx> | |
50 | #include <MAT_Graph.hxx> | |
51 | #include <MAT2d_CutCurve.hxx> | |
52 | #include <Precision.hxx> | |
53 | #include <Standard_NotImplemented.hxx> | |
54 | #include <TColgp_SequenceOfPnt.hxx> | |
55 | #include <TColStd_SequenceOfReal.hxx> | |
56 | #include <TopAbs.hxx> | |
57 | #include <TopExp.hxx> | |
58 | #include <TopExp_Explorer.hxx> | |
59 | #include <TopoDS.hxx> | |
60 | #include <TopoDS_Wire.hxx> | |
61 | #include <TopoDS_Compound.hxx> | |
62 | #include <TopoDS_Iterator.hxx> | |
63 | #include <TopTools_MapOfShape.hxx> | |
64 | #include <TopTools_MapIteratorOfMapOfShape.hxx> | |
65 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
66 | #include <TopTools_DataMapOfShapeListOfShape.hxx> | |
67 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> | |
68 | #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx> | |
69 | #include <TopTools_SequenceOfShape.hxx> | |
70 | #include <TopTools_ListOfShape.hxx> | |
71 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> | |
72 | #include <TopTools_DataMapOfShapeSequenceOfShape.hxx> | |
73 | ||
74 | #include <gp.hxx> | |
75 | #include <gp_Vec.hxx> | |
76 | #include <gp_Ax2.hxx> | |
77 | #include <gp_Pln.hxx> | |
78 | #include <gp_Dir2d.hxx> | |
79 | ||
80 | #include <BRep_TVertex.hxx> | |
81 | #include <TopTools_IndexedMapOfShape.hxx> | |
82 | #include <Geom2d_BSplineCurve.hxx> | |
83 | #include <TColgp_Array1OfPnt2d.hxx> | |
84 | #include <TColStd_Array1OfReal.hxx> | |
85 | #include <TColStd_Array1OfInteger.hxx> | |
86 | #include <BRepTools_Substitution.hxx> | |
87 | #include <BRepLib_MakeVertex.hxx> | |
88 | #include <Geom2dLProp_CLProps2d.hxx> | |
89 | #include <Geom2dConvert_CompCurveToBSplineCurve.hxx> | |
90 | #include <Standard_ErrorHandler.hxx> | |
91 | ||
92 | #ifdef DRAW | |
93 | #include <Draw.hxx> | |
94 | #include <DrawTrSurf.hxx> | |
95 | #include <DrawTrSurf_Curve2d.hxx> | |
96 | #include <DBRep.hxx> | |
97 | #endif | |
98 | ||
99 | #ifdef DEB | |
100 | static Standard_Boolean AffichGeom = Standard_False; | |
101 | static Standard_Boolean Affich2d = Standard_False; | |
102 | static Standard_Boolean AffichEdge = Standard_False; | |
103 | static Standard_Integer NbTRIMEDGES = 0; | |
104 | static Standard_Integer NbOFFSET = 0; | |
105 | static Standard_Integer NbEDGES = 0; | |
106 | static Standard_Integer NbBISSEC = 0; | |
107 | #ifndef WNT | |
108 | static char tname[100]; | |
109 | static Standard_CString name = tname ; | |
110 | #endif | |
111 | #endif | |
112 | ||
113 | // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin | |
114 | ||
115 | static void QuasiFleche(const Adaptor3d_Curve& C, | |
116 | const Standard_Real Deflection2, | |
117 | const Standard_Real Udeb, | |
118 | const gp_Pnt& Pdeb, | |
119 | const gp_Vec& Vdeb, | |
120 | const Standard_Real Ufin, | |
121 | const gp_Pnt& Pfin, | |
122 | const gp_Vec& Vfin, | |
123 | const Standard_Integer Nbmin, | |
124 | const Standard_Real Eps, | |
125 | TColStd_SequenceOfReal& Parameters, | |
126 | TColgp_SequenceOfPnt& Points); | |
127 | ||
128 | static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters, | |
129 | TColgp_SequenceOfPnt& Points, | |
130 | const Adaptor3d_Curve& C, | |
131 | const Standard_Real Deflection, | |
132 | const Standard_Real U1, | |
133 | const Standard_Real U2, | |
134 | const Standard_Real EPSILON, | |
135 | const Standard_Integer Nbmin); | |
136 | ||
137 | static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset, | |
138 | const BRepMAT2d_BisectingLocus& Locus, | |
139 | const BRepMAT2d_LinkTopoBilo& Link, | |
140 | TopTools_ListOfShape& BadEdges); | |
141 | ||
142 | static Standard_Integer CutEdge (const TopoDS_Edge& E, | |
143 | const TopoDS_Face& F, | |
144 | Standard_Integer ForceCut, | |
145 | TopTools_ListOfShape& Cuts); | |
146 | ||
147 | ||
148 | static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C, | |
149 | const Standard_Integer nbParts, | |
150 | TColGeom2d_SequenceOfCurve& theCurves); | |
151 | // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End | |
152 | ||
153 | ||
154 | static void EdgeVertices (const TopoDS_Edge& E, | |
155 | TopoDS_Vertex& V1, | |
156 | TopoDS_Vertex& V2) | |
157 | { | |
158 | if (E.Orientation() == TopAbs_REVERSED) { | |
159 | TopExp::Vertices(E,V2,V1); | |
160 | } | |
161 | else { | |
162 | TopExp::Vertices(E,V1,V2); | |
163 | } | |
164 | } | |
165 | ||
166 | static void UpdateDetromp (TopTools_ListOfShape& Detromp1, | |
167 | TopTools_ListOfShape& Detromp2, | |
168 | const TopTools_SequenceOfShape& Vertices, | |
169 | const TColgp_SequenceOfPnt& Params, | |
170 | const Bisector_Bisec& Bisec, | |
171 | const Standard_Boolean SOnE, | |
172 | const Standard_Boolean EOnE, | |
173 | const BRepFill_TrimEdgeTool& Trim); | |
174 | ||
175 | static Standard_Boolean VertexFromNode | |
176 | (const Handle(MAT_Node)& aNode, | |
177 | const Standard_Real Offset, | |
178 | gp_Pnt2d& PN, | |
179 | BRepFill_DataMapOfNodeShape& MapNodeVertex, | |
180 | TopoDS_Vertex& VN); | |
181 | ||
182 | static void StoreInMap (const TopoDS_Shape& V1, | |
183 | const TopoDS_Shape& V2, | |
184 | TopTools_IndexedDataMapOfShapeShape& MapVV); | |
185 | ||
186 | static void TrimEdge (const TopoDS_Edge& CurrentEdge, | |
187 | const TopTools_ListOfShape& D, | |
188 | TopTools_SequenceOfShape& Sv, | |
189 | TColStd_SequenceOfReal& MapverPar, | |
190 | TopTools_SequenceOfShape& S, | |
191 | TopTools_IndexedDataMapOfShapeShape& MapVV); | |
192 | ||
193 | static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC, | |
194 | const TopoDS_Vertex& V); | |
195 | ||
196 | static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge, | |
197 | const TopoDS_Vertex& aVertex); | |
198 | ||
199 | static void MakeCircle | |
200 | (const TopoDS_Edge& E, | |
201 | const TopoDS_Vertex& V, | |
202 | const TopoDS_Face& F, | |
203 | const Standard_Real Offset, | |
86b3805f | 204 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map, |
7fd59977 | 205 | const Handle(Geom_Plane)& RefPlane); |
206 | ||
207 | static void MakeOffset | |
208 | (const TopoDS_Edge& E, | |
209 | const TopoDS_Face& F, | |
210 | const Standard_Real Offset, | |
86b3805f | 211 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map, |
7fd59977 | 212 | const Handle(Geom_Plane)& RefPlane); |
213 | ||
214 | //======================================================================= | |
215 | //function : KPartCircle | |
216 | //purpose : | |
217 | //======================================================================= | |
218 | ||
219 | static Standard_Boolean KPartCircle | |
220 | (const TopoDS_Face& mySpine, | |
221 | const Standard_Real myOffset, | |
222 | const Standard_Real Alt, | |
223 | TopoDS_Shape& myShape, | |
86b3805f | 224 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap, |
7fd59977 | 225 | Standard_Boolean& myIsDone) |
226 | { | |
227 | // Un seul contour qui est un cercle ferme | |
228 | TopExp_Explorer exp(mySpine,TopAbs_EDGE); | |
229 | Standard_Integer NbEdges = 0; | |
230 | TopoDS_Edge E; | |
231 | ||
232 | for (; exp.More(); exp.Next()) { | |
233 | NbEdges++; | |
234 | E = TopoDS::Edge(exp.Current()); | |
235 | if (NbEdges > 1) return Standard_False; | |
236 | } | |
237 | TopoDS_Vertex V1,V2; | |
238 | TopExp::Vertices(E,V1,V2); | |
239 | if (!V1.IsSame(V2)) return Standard_False; | |
240 | ||
241 | Standard_Real f,l; | |
242 | TopLoc_Location L; | |
243 | Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l); | |
244 | ||
245 | if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { | |
246 | Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C); | |
247 | C = Ct->BasisCurve(); | |
248 | } | |
249 | ||
250 | if (!C->IsKind(STANDARD_TYPE(Geom_Circle))) return Standard_False; | |
251 | Handle(Geom_Circle) CE = Handle(Geom_Circle)::DownCast(C); | |
252 | Standard_Real anOffset = myOffset; | |
253 | if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1; | |
254 | ||
255 | if (anOffset < 0. || Abs(anOffset) < CE->Radius()) { | |
256 | Handle(Geom_Circle) OC = new Geom_Circle (CE->Position(),CE->Radius() - anOffset); | |
257 | myShape = BRepLib_MakeEdge(OC,f,l); | |
258 | ||
259 | myShape.Orientation(E.Orientation()); | |
260 | myShape.Location(L); | |
261 | if (Alt != 0.) { | |
262 | BRepAdaptor_Surface S(mySpine,0); | |
263 | gp_Ax1 Nor = S.Plane().Axis(); | |
264 | gp_Trsf T; | |
265 | gp_Vec Trans(Nor.Direction()); | |
266 | Trans = Alt*Trans; | |
267 | T.SetTranslation(Trans); | |
268 | myShape.Move(TopLoc_Location(T)); | |
269 | } | |
270 | ||
271 | TopTools_ListOfShape LL; | |
272 | LL.Append(myShape); | |
86b3805f | 273 | myMap.Add(E,LL); |
7fd59977 | 274 | } |
275 | myIsDone = Standard_True; | |
276 | return Standard_True; | |
277 | } | |
278 | ||
279 | //======================================================================= | |
280 | //function : BRepFill_OffsetWire | |
281 | //purpose : | |
282 | //======================================================================= | |
283 | ||
284 | BRepFill_OffsetWire::BRepFill_OffsetWire() | |
285 | :myIsDone(Standard_False) | |
286 | { | |
287 | } | |
288 | ||
289 | ||
290 | //======================================================================= | |
291 | //function : BRepFill_OffsetWire | |
292 | //purpose : | |
293 | //======================================================================= | |
294 | ||
295 | BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine, | |
296 | const GeomAbs_JoinType Join ) | |
297 | { | |
298 | Init(Spine,Join); | |
299 | } | |
300 | ||
301 | ||
302 | //======================================================================= | |
303 | //function : Init | |
304 | //purpose : | |
305 | //======================================================================= | |
306 | ||
307 | void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine, | |
308 | const GeomAbs_JoinType Join ) | |
309 | { | |
310 | Standard_NotImplemented_Raise_if(Join > GeomAbs_Arc, | |
311 | "Only GeomAbs_Arc is implemented"); | |
312 | ||
313 | myIsDone = Standard_False; | |
314 | TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD); | |
315 | mySpine = TopoDS::Face(aLocalShape); | |
316 | // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD)); | |
317 | myJoinType = Join; | |
318 | ||
319 | myMap.Clear(); | |
320 | myMapSpine.Clear(); | |
321 | //------------------------------------------------------------------ | |
322 | // decoupe du spine pour les lieux bissecteurs. | |
323 | //------------------------------------------------------------------ | |
324 | // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin | |
325 | static BRepMAT2d_Explorer Exp; | |
326 | ||
327 | Exp.Perform(mySpine); | |
328 | ||
329 | // TopoDS_Face anOldSpine = mySpine; | |
330 | ||
331 | mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine)); | |
332 | PrepareSpine (); | |
333 | ||
334 | // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End | |
335 | TopoDS_Shape aShape; | |
86b3805f | 336 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap; |
7fd59977 | 337 | Standard_Boolean Done; |
338 | if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return; | |
339 | ||
340 | ||
341 | //----------------------------------------------------- | |
342 | // Calcul de la carte des lieux bissecteurs a gauche. | |
343 | // et des Liens Topologie -> elements de base de la carte. | |
344 | //----------------------------------------------------- | |
345 | ||
346 | // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin | |
347 | // static BRepMAT2d_Explorer Exp; | |
348 | // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End | |
349 | Exp.Perform(myWorkSpine); | |
350 | myBilo.Compute(Exp,1,MAT_Left); | |
351 | myLink.Perform(Exp,myBilo); | |
352 | } | |
353 | ||
354 | ||
355 | //======================================================================= | |
356 | //function : IsDone | |
357 | //purpose : | |
358 | //======================================================================= | |
359 | ||
360 | Standard_Boolean BRepFill_OffsetWire::IsDone() const | |
361 | { | |
362 | return myIsDone; | |
363 | } | |
364 | ||
365 | ||
366 | //======================================================================= | |
367 | //function : Spine | |
368 | //purpose : | |
369 | //======================================================================= | |
370 | ||
371 | const TopoDS_Face& BRepFill_OffsetWire::Spine() const | |
372 | { | |
373 | return mySpine; | |
374 | } | |
375 | ||
376 | ||
377 | //======================================================================= | |
378 | //function : Shape | |
379 | //purpose : | |
380 | //======================================================================= | |
381 | ||
382 | const TopoDS_Shape& BRepFill_OffsetWire::Shape() const | |
383 | { | |
384 | return myShape; | |
385 | } | |
386 | ||
387 | ||
388 | //======================================================================= | |
389 | //function : GeneratedShapes | |
390 | //purpose : | |
391 | //======================================================================= | |
392 | ||
393 | const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes | |
394 | (const TopoDS_Shape& SpineShape) | |
395 | { | |
396 | if (!myCallGen) { | |
397 | if (!myMapSpine.IsEmpty()) { | |
398 | // myMapSpine peut etre vide si on est passe par PerformWithBilo. | |
399 | TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine); | |
400 | for (; it.More(); it.Next()) { | |
86b3805f J |
401 | if (myMap.Contains(it.Key())) { |
402 | if (!myMap.Contains(it.Value())) { | |
7fd59977 | 403 | TopTools_ListOfShape L; |
86b3805f | 404 | myMap.Add(it.Value(),L); |
7fd59977 | 405 | } |
406 | if ( !it.Value().IsSame(it.Key())) { | |
86b3805f J |
407 | myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key())); |
408 | //myMap.UnBind(it.Key()); | |
409 | TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent()); | |
410 | TopTools_ListOfShape LastList; | |
411 | LastList.Append(myMap(myMap.Extent())); | |
412 | myMap.RemoveLast(); | |
413 | if (myMap.FindIndex(it.Key()) != 0) | |
414 | myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList); | |
7fd59977 | 415 | } |
416 | } | |
86b3805f J |
417 | if (myMap.Contains(it.Key().Reversed())) { |
418 | if (!myMap.Contains(it.Value().Reversed())) { | |
7fd59977 | 419 | TopTools_ListOfShape L; |
86b3805f | 420 | myMap.Add(it.Value().Reversed(),L); |
7fd59977 | 421 | } |
422 | if ( !it.Value().IsSame(it.Key())) { | |
86b3805f J |
423 | myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed())); |
424 | //myMap.UnBind(it.Key().Reversed()); | |
425 | TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent()); | |
426 | TopTools_ListOfShape LastList; | |
427 | LastList.Append(myMap(myMap.Extent())); | |
428 | myMap.RemoveLast(); | |
429 | if (myMap.FindIndex(it.Key().Reversed()) != 0) | |
430 | myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList); | |
7fd59977 | 431 | } |
432 | } | |
433 | } | |
434 | } | |
435 | myCallGen = Standard_True; | |
436 | } | |
437 | ||
86b3805f J |
438 | if (myMap.Contains(SpineShape)) { |
439 | return myMap.FindFromKey(SpineShape); | |
7fd59977 | 440 | } |
441 | else { | |
442 | static TopTools_ListOfShape Empty; | |
443 | return Empty; | |
444 | } | |
445 | } | |
446 | ||
447 | ||
448 | //======================================================================= | |
449 | //function : JoinType | |
450 | //purpose : | |
451 | //======================================================================= | |
452 | ||
453 | GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const | |
454 | { | |
455 | return myJoinType; | |
456 | } | |
457 | ||
458 | //======================================================================= | |
459 | //function : Perform | |
460 | //purpose : | |
461 | //======================================================================= | |
462 | ||
463 | void BRepFill_OffsetWire::Perform (const Standard_Real Offset, | |
464 | const Standard_Real Alt) | |
465 | { | |
466 | // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin | |
467 | try { | |
468 | OCC_CATCH_SIGNALS | |
469 | myCallGen = Standard_False; | |
470 | if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return; | |
471 | ||
472 | TopoDS_Face oldWorkSpain = myWorkSpine; | |
473 | ||
474 | TopTools_ListOfShape BadEdges; | |
475 | CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges); | |
476 | ||
477 | if(!BadEdges.IsEmpty()) { | |
478 | // Modification of myWorkSpine; | |
479 | //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl; | |
480 | BRepTools_Substitution aSubst; | |
481 | TopTools_ListIteratorOfListOfShape it(BadEdges); | |
482 | TopTools_ListOfShape aL; | |
483 | Standard_Real aDefl = .01 * Abs(Offset); | |
484 | TColStd_SequenceOfReal Parameters; | |
485 | TColgp_SequenceOfPnt Points; | |
486 | ||
487 | for(; it.More(); it.Next()) { | |
488 | aL.Clear(); | |
489 | Parameters.Clear(); | |
490 | Points.Clear(); | |
491 | const TopoDS_Shape& anE = it.Value(); | |
492 | TopoDS_Vertex Vf, Vl; | |
493 | TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl); | |
494 | ||
495 | Standard_Real f, l; | |
496 | Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l); | |
497 | GeomAdaptor_Curve AC(G3d,f,l); | |
498 | ||
499 | Standard_Boolean dummy = PerformCurve(Parameters, Points, | |
500 | AC, aDefl, f, l, Precision::Confusion(), | |
501 | 2); | |
502 | ||
503 | Standard_Integer NPnts = Points.Length(); | |
504 | if(NPnts > 2) { | |
505 | //cout << NPnts << " points " << endl; | |
506 | TopoDS_Vertex FV = Vf; | |
507 | TopoDS_Vertex LV; | |
508 | TopoDS_Edge newE; | |
509 | Standard_Integer np; | |
510 | for(np = 2; np < NPnts; np++) { | |
511 | gp_Pnt LP = Points(np); | |
512 | LV = BRepLib_MakeVertex(LP); | |
513 | newE = BRepLib_MakeEdge(FV, LV); | |
514 | aL.Append(newE); | |
515 | FV = LV; | |
516 | } | |
517 | LV = Vl; | |
518 | newE = BRepLib_MakeEdge(FV, LV); | |
519 | aL.Append(newE); | |
520 | } | |
521 | else { | |
522 | //cout << " 2 points " << endl; | |
523 | TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl); | |
524 | aL.Append(newE); | |
525 | } | |
526 | //Update myMapSpine | |
527 | if (myMapSpine.IsBound( anE )) | |
528 | { | |
529 | TopTools_ListIteratorOfListOfShape newit( aL ); | |
530 | for (; newit.More(); newit.Next()) | |
531 | { | |
532 | TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() ); | |
533 | myMapSpine.Bind( NewEdge, myMapSpine(anE) ); | |
534 | TopoDS_Vertex NewV1, NewV2; | |
535 | EdgeVertices( NewEdge, NewV1, NewV2 ); | |
536 | if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) ); | |
537 | if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) ); | |
538 | } | |
539 | myMapSpine.UnBind( anE ); | |
540 | } | |
541 | /////////////////// | |
542 | aSubst.Substitute(anE, aL); | |
543 | } | |
544 | ||
545 | TopTools_DataMapOfShapeListOfShape wwmap; | |
546 | TopoDS_Iterator itws( myWorkSpine ); | |
547 | for (; itws.More(); itws.Next()) | |
548 | { | |
549 | TopoDS_Shape aWire = itws.Value(); | |
550 | aSubst.Build( aWire ); | |
551 | if (aSubst.IsCopied(aWire)) | |
552 | { | |
553 | TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() ); | |
554 | NewWire.Closed( aWire.Closed() ); | |
555 | TopTools_ListOfShape Lw; | |
556 | Lw.Append( NewWire ); | |
557 | wwmap.Bind( aWire, Lw ); | |
558 | } | |
559 | } | |
560 | aSubst.Clear(); | |
561 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap ); | |
562 | for (; itmap.More(); itmap.Next()) | |
563 | aSubst.Substitute( itmap.Key(), itmap.Value() ); | |
564 | aSubst.Build(myWorkSpine); | |
565 | if(aSubst.IsCopied(myWorkSpine)) { | |
566 | myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First()); | |
567 | //sprintf(name,"WS1"); | |
568 | //DBRep::Set(name,myWorkSpine); | |
569 | ||
570 | BRepMAT2d_Explorer newExp; | |
571 | newExp.Perform(myWorkSpine); | |
572 | BRepMAT2d_BisectingLocus newBilo; | |
573 | BRepMAT2d_LinkTopoBilo newLink; | |
574 | newBilo.Compute(newExp,1,MAT_Left); | |
575 | newLink.Perform(newExp,newBilo); | |
576 | PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt); | |
577 | ||
578 | myWorkSpine = oldWorkSpain; | |
579 | } | |
580 | else { | |
581 | PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt); | |
582 | } | |
583 | ||
584 | } | |
585 | else { | |
586 | PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt); | |
587 | } | |
588 | ||
589 | } catch (Standard_Failure) { | |
590 | myShape.Nullify(); | |
591 | myIsDone = Standard_False; | |
592 | ||
593 | return; | |
594 | } | |
595 | // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End | |
596 | // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin | |
597 | TopExp_Explorer anExp(myShape, TopAbs_WIRE); | |
598 | ||
599 | for (; anExp.More(); anExp.Next()) { | |
600 | const TopoDS_Shape &aWire = anExp.Current(); | |
601 | ||
602 | if (!aWire.Closed()) { | |
603 | myShape.Nullify(); | |
604 | myIsDone = Standard_False; | |
605 | Standard_ConstructionError::Raise("Offset wire is not closed."); | |
606 | } | |
607 | } | |
608 | // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End | |
609 | } | |
610 | ||
611 | //======================================================================= | |
612 | //function : Compute | |
613 | //purpose : | |
614 | //======================================================================= | |
615 | ||
616 | void Compute (const TopoDS_Face& Spine, | |
617 | TopoDS_Shape& aShape, | |
86b3805f | 618 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map, |
7fd59977 | 619 | const Standard_Real Alt) |
620 | { | |
621 | BRep_Builder B; | |
622 | B.MakeCompound(TopoDS::Compound(aShape)); | |
623 | Standard_Real ALT = Alt; | |
624 | if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt; | |
625 | gp_Trsf T; | |
626 | T.SetTranslation(gp_Vec(0.,0.,ALT)); | |
627 | TopLoc_Location L(T); | |
628 | ||
629 | for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) { | |
630 | const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current()); | |
631 | TopoDS_Shape aLocalShape = CurW.Moved(L); | |
632 | TopoDS_Wire NewW = TopoDS::Wire(aLocalShape); | |
633 | // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L)); | |
634 | B.Add(aShape,NewW); | |
635 | // mise a jour de la Map. | |
636 | TopoDS_Iterator it1( CurW); | |
637 | TopoDS_Iterator it2( NewW); | |
638 | for ( ; it1.More(); it1.Next(), it2.Next()) { | |
639 | TopTools_ListOfShape List; | |
640 | List.Append(it2.Value()); | |
86b3805f | 641 | Map.Add(it1.Value(), List); |
7fd59977 | 642 | } |
643 | } | |
644 | } | |
645 | ||
646 | //======================================================================= | |
647 | //function : PerformWithBiLo | |
648 | //purpose : | |
649 | //======================================================================= | |
650 | ||
651 | void BRepFill_OffsetWire::PerformWithBiLo | |
652 | (const TopoDS_Face& Spine, | |
653 | const Standard_Real Offset, | |
654 | const BRepMAT2d_BisectingLocus& Locus, | |
655 | BRepMAT2d_LinkTopoBilo& Link, | |
656 | const GeomAbs_JoinType Join, | |
657 | const Standard_Real Alt) | |
658 | { | |
659 | Standard_NotImplemented_Raise_if (Join > GeomAbs_Arc, | |
660 | "Only GeomAbs_Arc is implemented"); | |
661 | ||
662 | myIsDone = Standard_False; | |
663 | TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD); | |
664 | myWorkSpine = TopoDS::Face(aLocalShape); | |
665 | // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD)); | |
666 | myJoinType = Join; | |
667 | myOffset = Offset ; | |
668 | myShape.Nullify(); | |
669 | ||
670 | ||
671 | if (mySpine.IsNull()) { | |
672 | TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD); | |
673 | mySpine = TopoDS::Face(aLocalShape); | |
674 | // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD)); | |
675 | } | |
676 | myMap.Clear(); | |
677 | ||
678 | //***************************************** | |
679 | // si myOffset = 0, on ne s'emmerde pas !! | |
680 | //***************************************** | |
681 | if ( Abs(myOffset) < Precision::Confusion()) { | |
682 | Compute(mySpine,myShape,myMap,Alt); | |
683 | myIsDone = Standard_True; | |
684 | return; | |
685 | } | |
686 | ||
687 | //****************************** | |
688 | // Calcul pour un offset non nul | |
689 | //****************************** | |
690 | if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return; | |
691 | ||
692 | BRep_Builder myBuilder; | |
693 | myBuilder.MakeCompound(TopoDS::Compound(myShape)); | |
694 | ||
695 | //--------------------------------------------------------------------- | |
696 | // MapNodeVertex : associe a chaque noeud de la carte (key1) et | |
697 | // a chaque element du profil (key2) un vertex (item). | |
698 | // MapBis : ensemble des edges ou vertex (item) generes par | |
699 | // une bisectrice sur une face ou un edge (key)des | |
700 | // tuyaux ou revol. | |
701 | // MapVerPar : Map des parametres des vertex sur les edges paralleles | |
702 | // la liste contenue dans MapVerPar (E) correspond aux | |
703 | // parametres sur E des vertex contenu dans MapBis(E); | |
704 | //--------------------------------------------------------------------- | |
705 | ||
706 | ||
707 | BRepFill_DataMapOfNodeShape MapNodeVertex; | |
708 | TopTools_DataMapOfShapeSequenceOfShape MapBis; | |
709 | BRepFill_DataMapOfShapeSequenceOfReal MapVerPar; | |
710 | ||
711 | TopTools_DataMapOfShapeShape EmptyMap; | |
712 | TopTools_SequenceOfShape EmptySeq; | |
713 | TopTools_ListOfShape EmptyList; | |
714 | TColStd_SequenceOfReal EmptySeqOfReal; | |
715 | ||
716 | Standard_Real ALT = Alt; | |
717 | Handle(Geom_Plane) RefPlane = | |
718 | Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine)); | |
719 | if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt; | |
720 | RefPlane = Handle(Geom_Plane)::DownCast | |
721 | (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() ))); | |
722 | ||
723 | //--------------------------------------------------------------- | |
724 | // Construction des Cercles et des OffsetCurves | |
725 | //--------------------------------------------------------------- | |
726 | ||
727 | for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) { | |
728 | TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic))); | |
729 | TopoDS_Shape& PE = PEE ; | |
730 | for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) { | |
731 | const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie)); | |
732 | if (SE.ShapeType() == TopAbs_VERTEX) { | |
733 | MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE), | |
734 | myWorkSpine,myOffset,myMap,RefPlane); | |
735 | } | |
736 | else { | |
737 | MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane); | |
738 | PE = SE; | |
739 | } | |
740 | } | |
741 | } | |
742 | ||
743 | ||
744 | #ifdef DEB | |
745 | if (AffichEdge) { | |
746 | cout << " Fin Construction des primitives geometriques"<<endl; | |
747 | } | |
748 | #endif | |
749 | ||
750 | ||
751 | //--------------------------------------------------- | |
752 | // Constructions des vertex de l offset. | |
753 | //--------------------------------------------------- | |
754 | BRepFill_DataMapOfOrientedShapeListOfShape Detromp; | |
755 | Handle(MAT_Arc) CurrentArc; | |
756 | Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ; | |
757 | Handle(Geom_Curve) CBis; | |
758 | Standard_Boolean Reverse; | |
759 | TopoDS_Edge CurrentEdge; | |
760 | TopoDS_Shape S [2]; | |
761 | TopoDS_Edge E [2]; | |
762 | TopLoc_Location L; | |
86b3805f | 763 | Standard_Integer j, k; |
7fd59977 | 764 | |
765 | for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) { | |
766 | ||
767 | CurrentArc = Locus.Graph()->Arc(i); | |
768 | Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse); | |
769 | ||
770 | #ifdef DRAW | |
771 | if ( AffichGeom) { | |
772 | sprintf(name,"BISSEC_%d",NbBISSEC++); | |
773 | DrawTrSurf::Set(name,Bisec.Value()); | |
774 | } | |
775 | #endif | |
776 | ||
777 | //----------------------------------------------------------------------- | |
778 | // Recuperation des elements du spine correspondant aux basicElts separes. | |
779 | //----------------------------------------------------------------------- | |
780 | S [0] = Link.GeneratingShape(CurrentArc->FirstElement()); | |
781 | S [1] = Link.GeneratingShape(CurrentArc->SecondElement()); | |
782 | ||
783 | TopTools_SequenceOfShape Vertices; | |
784 | TColgp_SequenceOfPnt Params; | |
785 | ||
786 | TopTools_DataMapOfShapeSequenceOfShape MapSeqVer; | |
787 | BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar; | |
788 | ||
789 | //----------------------------------------------------------- | |
790 | // Recuperation des edges paralleles sur chaque face. | |
791 | // Si pas d offset generees => saut a la bissectrice suivante. | |
792 | //-------------------------------------------------------------- | |
86b3805f J |
793 | if (myMap.Contains(S[0]) && myMap.Contains(S[1])) { |
794 | E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First()); | |
795 | E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First()); | |
7fd59977 | 796 | } |
797 | else continue; | |
798 | ||
799 | //----------------------------------------------------------- | |
800 | // Construction des vertex correspondant au noeud de la carte. | |
801 | // si ils sont sur l offset. | |
802 | //----------------------------------------------------------- | |
803 | TopoDS_Vertex VS,VE; | |
804 | Handle(MAT_Node) Node1, Node2; | |
805 | ||
806 | if (Reverse) { | |
807 | Node1 = CurrentArc->SecondNode(); | |
808 | Node2 = CurrentArc->FirstNode(); | |
809 | } | |
810 | else { | |
811 | Node1 = CurrentArc->FirstNode(); | |
812 | Node2 = CurrentArc->SecondNode(); | |
813 | } | |
814 | ||
815 | Standard_Boolean StartOnEdge = 0, EndOnEdge = 0; | |
816 | ||
817 | if (!Node1->Infinite()) { | |
818 | gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1); | |
819 | StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS); | |
820 | // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1), | |
821 | // MapNodeVertex,VS); | |
822 | } | |
823 | if (!Node2->Infinite()) { | |
824 | gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ; | |
825 | EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE); | |
826 | // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2), | |
827 | // MapNodeVertex,VE); | |
828 | } | |
829 | ||
830 | //--------------------------------------------- | |
831 | // Construction des geometries. | |
832 | //--------------------------------------------- | |
833 | BRepFill_TrimEdgeTool Trim (Bisec, | |
834 | Locus.GeomElt(CurrentArc->FirstElement()), | |
835 | Locus.GeomElt(CurrentArc->SecondElement()), | |
836 | myOffset); | |
837 | ||
838 | //----------------------------------------------------------- | |
839 | // Construction des vertex sur les edges paralleles au spine. | |
840 | //----------------------------------------------------------- | |
841 | ||
842 | Trim.IntersectWith(E [0], E [1], Params); | |
843 | ||
844 | for (Standard_Integer s = 1; s <= Params.Length(); s++) { | |
845 | TopoDS_Vertex VC; | |
846 | myBuilder.MakeVertex (VC); | |
847 | gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X()); | |
848 | gp_Pnt PVC(P2.X(),P2.Y(),0.); | |
849 | ||
850 | myBuilder.UpdateVertex(VC,PVC,Precision::Confusion()); | |
851 | Vertices.Append(VC); | |
852 | } | |
853 | if (StartOnEdge) { | |
854 | Standard_Boolean Start = 1; | |
855 | Trim.AddOrConfuse(Start, E[0], E[1], Params); | |
856 | if (Params.Length() == Vertices.Length()) | |
857 | Vertices.SetValue(1,VS); | |
858 | ||
859 | else | |
860 | // le point n avait pas ete trouve par IntersectWith | |
861 | Vertices.Prepend(VS); | |
862 | } | |
863 | if (EndOnEdge) { | |
864 | Standard_Boolean Start = 0; | |
865 | Trim.AddOrConfuse(Start, E[0], E[1], Params); | |
866 | if (Params.Length() == Vertices.Length()) | |
867 | Vertices.SetValue(Params.Length(),VE); | |
868 | ||
869 | else | |
870 | // le point n avait pas ete trouve par IntersectWith | |
871 | Vertices.Append(VE); | |
872 | } | |
873 | ||
874 | //------------------------------------------------------------ | |
875 | // Mise a jour Detromp. | |
876 | // Detromp permetra de supprimer les vertex sur l offset | |
877 | // correspondant a des zones de tangences | |
878 | // dans Detromp sont ranges les vertex qui limitent | |
879 | // les portions de la bissectrices situes entre le spine et | |
880 | // l offset. | |
881 | //------------------------------------------------------------ | |
882 | if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList); | |
883 | if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList); | |
884 | ||
885 | ||
886 | UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params, | |
887 | Bisec, StartOnEdge, EndOnEdge, Trim); | |
888 | //---------------------------------------------- | |
889 | // Stockage des vertex sur les edges paralleles. | |
890 | // on remplit MapBis et MapVerPar. | |
891 | //---------------------------------------------- | |
892 | if (!Vertices.IsEmpty()) { | |
893 | for (k = 0; k <= 1; k++) { | |
894 | if (!MapBis.IsBound(E[k])) { | |
895 | MapBis .Bind(E[k],EmptySeq); | |
896 | MapVerPar.Bind(E[k],EmptySeqOfReal); | |
897 | } | |
898 | for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) { | |
899 | MapBis (E[k]).Append(Vertices.Value(ii)); | |
900 | if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y()); | |
901 | else MapVerPar (E[k]).Append(Params.Value(ii).Z()); | |
902 | } | |
903 | } | |
904 | } | |
905 | else { | |
906 | //------------------------------------------------------------ | |
907 | //POUR LES CERCLES COMPLETS . la parallele peut etre contenue | |
908 | // dans la zone sans intersection avec la frontiere | |
909 | // pas d intersection | |
910 | // si myoffset est < distance des noeuds la parallele peut etre | |
911 | // valide. | |
912 | //------------------------------------------------------------- | |
913 | for (k = 0; k <= 1; k++) { | |
914 | if (!MapBis.IsBound(E[k])) { | |
915 | if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) { | |
916 | MapBis .Bind(E[k],EmptySeq); | |
917 | MapVerPar.Bind(E[k],EmptySeqOfReal); | |
918 | } | |
919 | } | |
920 | } | |
921 | } | |
922 | } | |
923 | ||
924 | #ifdef DEB | |
925 | if (AffichEdge) { | |
926 | cout << " Fin Construction des vertex sur les offsets"<<endl; | |
927 | } | |
928 | #endif | |
929 | ||
930 | //---------------------------------- | |
931 | // Construction des edges paralleles. | |
932 | //---------------------------------- | |
933 | TopTools_IndexedDataMapOfShapeShape MapVV; | |
934 | ||
935 | TopoDS_Shape CurrentSpine; | |
936 | ||
86b3805f | 937 | //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1; |
7fd59977 | 938 | |
86b3805f J |
939 | for (j = 1; j <= myMap.Extent(); j++) { |
940 | CurrentSpine = myMap.FindKey(j); | |
941 | CurrentEdge = TopoDS::Edge(myMap(j).First()); | |
7fd59977 | 942 | |
86b3805f | 943 | myMap(j).Clear(); |
7fd59977 | 944 | if (MapBis.IsBound(CurrentEdge)) { |
945 | TopTools_SequenceOfShape S; | |
946 | if (!MapBis(CurrentEdge).IsEmpty()) { | |
947 | TrimEdge (CurrentEdge, | |
948 | Detromp (CurrentSpine), | |
949 | MapBis (CurrentEdge) , | |
950 | MapVerPar(CurrentEdge) , | |
951 | S, MapVV); | |
952 | for ( k = 1; k <= S.Length(); k++) { | |
86b3805f | 953 | myMap(j).Append(S.Value(k)); |
7fd59977 | 954 | } |
955 | } | |
956 | else { | |
957 | //----------------- | |
958 | // Cercles complets | |
959 | //----------------- | |
86b3805f | 960 | myMap(j).Append(CurrentEdge); |
7fd59977 | 961 | } |
962 | } | |
963 | } | |
964 | ||
965 | Standard_Integer ind; | |
966 | for (ind = 1; ind <= MapVV.Extent(); ind++) | |
967 | { | |
968 | TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind)); | |
969 | TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind)); | |
970 | gp_Pnt P1 = BRep_Tool::Pnt(OldV); | |
971 | gp_Pnt P2 = BRep_Tool::Pnt(NewV); | |
972 | myBuilder.UpdateVertex(NewV, P1.Distance(P2)); | |
973 | TopTools_ListOfShape LV; | |
974 | LV.Append( NewV.Oriented(TopAbs_FORWARD) ); | |
975 | BRepTools_Substitution aSubst; | |
976 | aSubst.Substitute( OldV, LV ); | |
86b3805f | 977 | for (j = 1; j <= myMap.Extent(); j++) |
7fd59977 | 978 | { |
86b3805f | 979 | TopTools_ListIteratorOfListOfShape itl(myMap(j)); |
7fd59977 | 980 | for (; itl.More(); itl.Next()) |
981 | { | |
982 | aSubst.Build(itl.Value()); | |
983 | if (aSubst.IsCopied(itl.Value())) | |
984 | { | |
985 | const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value()); | |
86b3805f | 986 | TopAbs_Orientation SaveOr = itl.Value().Orientation(); |
7fd59977 | 987 | itl.Value() = listSh.First(); |
86b3805f | 988 | itl.Value().Orientation(SaveOr); |
7fd59977 | 989 | } |
990 | } | |
991 | } | |
992 | } | |
993 | ||
994 | //---------------------------------- | |
995 | // Constructions des wires offset. | |
996 | //---------------------------------- | |
997 | MakeWires (); | |
998 | ||
999 | // Mise a jour des vertex ( Construits dans le plan Z = 0) !!! | |
1000 | TopTools_MapOfShape MapVertex; | |
1001 | for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) { | |
1002 | TopoDS_Vertex V = TopoDS::Vertex(exp.Current()); | |
1003 | if ( MapVertex.Add(V)) { | |
1004 | gp_Pnt P = BRep_Tool::Pnt(V); | |
1005 | P = RefPlane->Value(P.X(),P.Y()); | |
1006 | myBuilder.UpdateVertex(V,P, Precision::Confusion()); | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | // Constructions des courbes 3d. | |
1011 | BRepLib::BuildCurves3d(myShape); | |
1012 | MapVertex.Clear(); | |
1013 | TopExp_Explorer Explo( myShape, TopAbs_EDGE ); | |
1014 | for (; Explo.More(); Explo.Next()) | |
1015 | { | |
1016 | TopoDS_Edge E = TopoDS::Edge( Explo.Current() ); | |
1017 | TopoDS_Vertex V1, V2; | |
1018 | TopExp::Vertices( E, V1, V2 ); | |
1019 | Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape()); | |
1020 | Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape()); | |
1021 | ||
1022 | TopLoc_Location loc; | |
1023 | Standard_Real f, l; | |
1024 | Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l ); | |
1025 | theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() ); | |
1026 | theCurve->Transform( loc.Transformation() ); | |
1027 | gp_Pnt f3d = theCurve->Value( f ); | |
1028 | gp_Pnt l3d = theCurve->Value( l ); | |
1029 | ||
1030 | Standard_Real dist1, dist2; | |
1031 | dist1 = f3d.Distance( TV1->Pnt() ); | |
1032 | dist2 = l3d.Distance( TV2->Pnt() ); | |
1033 | if (! MapVertex.Contains( V1 )) | |
1034 | { | |
1035 | TV1->Pnt( f3d ); | |
1036 | MapVertex.Add( V1 ); | |
1037 | } | |
1038 | else | |
1039 | TV1->UpdateTolerance( 1.5*dist1 ); | |
1040 | if (! MapVertex.Contains( V2 )) | |
1041 | { | |
1042 | TV2->Pnt( l3d ); | |
1043 | MapVertex.Add( V2 ); | |
1044 | } | |
1045 | else | |
1046 | TV2->UpdateTolerance( 1.5*dist2 ); | |
1047 | } | |
1048 | ||
1049 | FixHoles(); | |
1050 | ||
1051 | myIsDone = Standard_True; | |
1052 | } | |
1053 | ||
1054 | ||
1055 | //======================================================================= | |
1056 | //function : Generated | |
1057 | //purpose : | |
1058 | //======================================================================= | |
1059 | ||
86b3805f | 1060 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& |
7fd59977 | 1061 | BRepFill_OffsetWire::Generated() |
1062 | { | |
1063 | return myMap; | |
1064 | } | |
1065 | ||
1066 | ||
1067 | //======================================================================= | |
1068 | //function : PrepareSpine | |
1069 | //purpose : | |
1070 | //======================================================================= | |
1071 | ||
1072 | void BRepFill_OffsetWire::PrepareSpine() | |
1073 | { | |
1074 | BRep_Builder B; | |
1075 | TopTools_ListOfShape Cuts; | |
1076 | TopTools_ListIteratorOfListOfShape IteCuts; | |
1077 | TopoDS_Vertex V1,V2; | |
1078 | ||
1079 | myWorkSpine.Nullify(); | |
1080 | myMapSpine.Clear(); | |
1081 | ||
1082 | TopLoc_Location L; | |
1083 | const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L); | |
1084 | Standard_Real TolF = BRep_Tool::Tolerance(mySpine); | |
1085 | B.MakeFace(myWorkSpine,S,L,TolF); | |
1086 | ||
1087 | for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) { | |
1088 | ||
1089 | TopoDS_Wire NW; | |
1090 | B.MakeWire (NW); | |
1091 | ||
1092 | // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin | |
1093 | Standard_Integer ForcedCut = 0; | |
1094 | Standard_Integer nbResEdges = -1; | |
1095 | TopTools_IndexedMapOfShape EdgeMap; | |
1096 | ||
1097 | TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap); | |
1098 | Standard_Integer nbEdges = EdgeMap.Extent(); | |
1099 | ||
1100 | if (nbEdges == 1) | |
1101 | ForcedCut = 2; | |
1102 | // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End | |
1103 | ||
1104 | for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) { | |
1105 | ||
1106 | const TopoDS_Edge& E = TopoDS::Edge(IteW.Value()); | |
1107 | EdgeVertices(E,V1,V2); | |
1108 | myMapSpine.Bind(V1,V1); | |
1109 | myMapSpine.Bind(V2,V2); | |
1110 | Cuts.Clear(); | |
1111 | ||
1112 | // Decoupe | |
1113 | TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD); | |
1114 | // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin | |
1115 | if (nbEdges == 2 && nbResEdges == 0) | |
1116 | ForcedCut = 1; | |
1117 | // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End | |
1118 | nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts); | |
1119 | ||
1120 | if (Cuts.IsEmpty()) { | |
1121 | B.Add(NW,E); | |
1122 | myMapSpine.Bind(E,E); | |
1123 | } | |
1124 | else { | |
1125 | for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) { | |
1126 | TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value()); | |
1127 | NE.Orientation(E.Orientation()); | |
1128 | B.Add(NW,NE); | |
1129 | myMapSpine.Bind(NE,E); | |
1130 | EdgeVertices(NE,V1,V2); | |
1131 | if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E); | |
1132 | if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E); | |
1133 | } | |
1134 | } | |
1135 | } | |
1136 | // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin | |
1137 | TopoDS_Vertex aV1; | |
1138 | TopoDS_Vertex aV2; | |
1139 | ||
1140 | TopExp::Vertices(NW, aV1, aV2); | |
1141 | ||
1142 | NW.Closed(aV1.IsSame(aV2)); | |
1143 | // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End | |
1144 | B.Add(myWorkSpine, NW); | |
1145 | } | |
1146 | ||
1147 | #ifdef DRAW | |
1148 | if ( AffichEdge) { | |
1149 | sprintf(name,"WS"); | |
1150 | DBRep::Set(name,myWorkSpine); | |
1151 | } | |
1152 | #endif | |
1153 | ||
1154 | } | |
1155 | ||
1156 | //======================================================================= | |
1157 | //function : MakeWires | |
1158 | //purpose : | |
1159 | //======================================================================= | |
1160 | ||
1161 | void BRepFill_OffsetWire::MakeWires() | |
1162 | { | |
1163 | //-------------------------------------------------------- | |
1164 | // creation d une liste unique des edges paralelles crees. | |
1165 | //-------------------------------------------------------- | |
1166 | TopTools_SequenceOfShape TheEdges; | |
1167 | TopTools_ListOfShape TheWires; | |
1168 | TopTools_ListIteratorOfListOfShape itl; | |
86b3805f J |
1169 | //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite; |
1170 | TopTools_IndexedDataMapOfShapeListOfShape MVE; | |
1171 | //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit; | |
7fd59977 | 1172 | TopoDS_Vertex V1,V2,VF,CV; |
86b3805f | 1173 | Standard_Integer i; |
7fd59977 | 1174 | |
86b3805f J |
1175 | for (i = 1; i <= myMap.Extent(); i++) { |
1176 | for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) { | |
7fd59977 | 1177 | const TopoDS_Edge& E = TopoDS::Edge(itl.Value()); |
1178 | TopExp::Vertices (E,V1,V2); | |
1179 | if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1)) | |
1180 | continue; //remove small closed edges | |
86b3805f | 1181 | if (!MVE.Contains(V1)) { |
7fd59977 | 1182 | TopTools_ListOfShape empty; |
86b3805f | 1183 | MVE.Add(V1,empty); |
7fd59977 | 1184 | } |
86b3805f J |
1185 | MVE.ChangeFromKey(V1).Append(E); |
1186 | if (!MVE.Contains(V2)) { | |
7fd59977 | 1187 | TopTools_ListOfShape empty; |
86b3805f | 1188 | MVE.Add(V2,empty); |
7fd59977 | 1189 | } |
86b3805f | 1190 | MVE.ChangeFromKey(V2).Append(E); |
7fd59977 | 1191 | } |
1192 | } | |
1193 | ||
1194 | //-------------------------------------- | |
1195 | // Creation des wires paralleles. | |
1196 | //-------------------------------------- | |
1197 | BRep_Builder B; | |
1198 | ||
1199 | // Standard_Integer NbEdges; | |
1200 | // Standard_Boolean NewWire = Standard_True; | |
1201 | // Standard_Boolean AddEdge = Standard_False; | |
1202 | ||
1203 | TopoDS_Wire NW; | |
1204 | Standard_Boolean End; | |
1205 | TopoDS_Edge CE; | |
1206 | ||
1207 | while (!MVE.IsEmpty()) { | |
1208 | B.MakeWire(NW); | |
1209 | ||
86b3805f J |
1210 | //MVEit.Initialize(MVE); |
1211 | for (i = 1; i <= MVE.Extent(); i++) | |
1212 | if(MVE(i).Extent() == 1) | |
1213 | break; | |
7fd59977 | 1214 | |
86b3805f J |
1215 | //if(!MVEit.More()) MVEit.Initialize(MVE); |
1216 | if (i > MVE.Extent()) | |
1217 | i = 1; | |
7fd59977 | 1218 | |
86b3805f J |
1219 | CV = VF = TopoDS::Vertex(MVE.FindKey(i)); |
1220 | CE = TopoDS::Edge(MVE(i).First()); | |
7fd59977 | 1221 | End = Standard_False; |
86b3805f | 1222 | MVE.ChangeFromKey(CV).RemoveFirst(); |
7fd59977 | 1223 | |
1224 | // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin | |
1225 | Standard_Boolean isClosed = Standard_False; | |
1226 | // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End | |
1227 | ||
1228 | while(!End) { | |
1229 | //------------------------------- | |
1230 | // Construction d un wire. | |
1231 | //------------------------------- | |
1232 | TopExp::Vertices(CE,V1,V2); | |
1233 | if (!CV.IsSame(V1)) CV = V1; else CV = V2; | |
1234 | ||
1235 | B.Add (NW,CE); | |
1236 | ||
86b3805f | 1237 | if (VF.IsSame(CV) || !MVE.Contains(CV)) { |
7fd59977 | 1238 | // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin |
1239 | isClosed = VF.IsSame(CV); | |
1240 | // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End | |
1241 | End = Standard_True; | |
86b3805f J |
1242 | //MVE.UnBind(VF); |
1243 | TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent()); | |
1244 | TopTools_ListOfShape LastList; | |
1245 | LastList.Append(MVE(MVE.Extent())); | |
1246 | MVE.RemoveLast(); | |
1247 | if (MVE.FindIndex(VF) != 0) | |
1248 | MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList); | |
7fd59977 | 1249 | } |
1250 | ||
1251 | if (!End) { | |
86b3805f | 1252 | if (MVE.FindFromKey(CV).Extent() > 2) { |
7fd59977 | 1253 | //cout <<"vertex sur plus de 2 edges dans une face."<<endl; |
1254 | } | |
86b3805f | 1255 | for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) { |
7fd59977 | 1256 | if (itl.Value().IsSame(CE)) { |
86b3805f | 1257 | MVE.ChangeFromKey(CV).Remove(itl); |
7fd59977 | 1258 | break; |
1259 | } | |
1260 | } | |
86b3805f J |
1261 | if (!MVE.FindFromKey(CV).IsEmpty()) { |
1262 | CE = TopoDS::Edge(MVE.FindFromKey(CV).First()); | |
1263 | MVE.ChangeFromKey(CV).RemoveFirst(); | |
7fd59977 | 1264 | } |
86b3805f J |
1265 | if (MVE.FindFromKey(CV).IsEmpty()) |
1266 | { | |
1267 | //MVE.UnBind(CV); | |
1268 | TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent()); | |
1269 | TopTools_ListOfShape LastList; | |
1270 | LastList.Append(MVE(MVE.Extent())); | |
1271 | MVE.RemoveLast(); | |
1272 | if (MVE.FindIndex(CV) != 0) | |
1273 | MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList); | |
1274 | } | |
7fd59977 | 1275 | } |
1276 | } | |
1277 | // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin | |
1278 | // NW.Closed(Standard_True); | |
1279 | NW.Closed(isClosed); | |
1280 | // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End | |
1281 | TheWires.Append(NW); | |
1282 | } | |
1283 | ||
1284 | // mise a jour de myShape : | |
1285 | // -- si un seul wire : myShape est un Wire | |
1286 | // -- si plusieurs wires : myShape est un Compound. | |
1287 | if ( TheWires.Extent() == 1) { | |
1288 | myShape = TheWires.First(); | |
1289 | } | |
1290 | else { | |
1291 | TopoDS_Compound R; | |
1292 | B.MakeCompound(R); | |
1293 | TopTools_ListIteratorOfListOfShape it(TheWires); | |
1294 | for ( ; it.More(); it.Next()) { | |
1295 | B.Add(R, it.Value()); | |
1296 | } | |
1297 | myShape = R; | |
1298 | } | |
1299 | ||
1300 | } | |
1301 | ||
1302 | //======================================================================= | |
1303 | //function : FixHoles | |
1304 | //purpose : | |
1305 | //======================================================================= | |
1306 | ||
1307 | void BRepFill_OffsetWire::FixHoles() | |
1308 | { | |
1309 | TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires; | |
1310 | ||
1311 | Standard_Real MaxTol = 0.; | |
1312 | Standard_Integer i; | |
1313 | BRep_Builder BB; | |
1314 | ||
1315 | TopExp_Explorer Explo( mySpine, TopAbs_VERTEX ); | |
1316 | for (; Explo.More(); Explo.Next()) | |
1317 | { | |
1318 | const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() ); | |
1319 | Standard_Real Tol = BRep_Tool::Tolerance(aVertex); | |
1320 | if (Tol > MaxTol) | |
1321 | MaxTol = Tol; | |
1322 | } | |
1323 | MaxTol *= 100.; | |
1324 | ||
1325 | Explo.Init( myShape, TopAbs_WIRE ); | |
1326 | for (; Explo.More(); Explo.Next()) | |
1327 | { | |
1328 | TopoDS_Shape aWire = Explo.Current(); | |
1329 | // Remove duplicated edges | |
1330 | TopTools_DataMapOfShapeListOfShape EEmap; | |
1331 | TopoDS_Iterator it( aWire ); | |
1332 | for (; it.More(); it.Next()) | |
1333 | { | |
1334 | const TopoDS_Shape& anEdge = it.Value(); | |
1335 | if (! EEmap.IsBound( anEdge )) | |
1336 | { | |
1337 | TopTools_ListOfShape LE; | |
1338 | EEmap.Bind( anEdge, LE ); | |
1339 | } | |
1340 | else | |
1341 | EEmap(anEdge).Append( anEdge ); | |
1342 | } | |
1343 | aWire.Free( Standard_True ); | |
1344 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap ); | |
1345 | for (; mapit.More(); mapit.Next()) | |
1346 | { | |
1347 | const TopTools_ListOfShape& LE = mapit.Value(); | |
1348 | TopTools_ListIteratorOfListOfShape itl( LE ); | |
1349 | for (; itl.More(); itl.Next()) | |
1350 | BB.Remove( aWire, itl.Value() ); | |
1351 | } | |
1352 | // Sorting | |
1353 | if (aWire.Closed()) | |
1354 | ClosedWires.Append( aWire ); | |
1355 | else | |
1356 | UnclosedWires.Append( aWire ); | |
1357 | } | |
1358 | ||
1359 | while (!UnclosedWires.IsEmpty()) | |
1360 | { | |
1361 | TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) ); | |
1362 | TopoDS_Vertex Vf, Vl; | |
1363 | TopExp::Vertices( Base, Vf, Vl ); | |
1364 | gp_Pnt Pf, Pl; | |
1365 | Pf = BRep_Tool::Pnt(Vf); | |
1366 | Pl = BRep_Tool::Pnt(Vl); | |
1367 | Standard_Real DistF = RealLast(), DistL = RealLast(); | |
1368 | Standard_Integer IndexF, IndexL; | |
1369 | Standard_Boolean IsFirstF, IsFirstL; | |
1370 | for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++) | |
1371 | { | |
1372 | TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) ); | |
1373 | TopoDS_Vertex V1, V2; | |
1374 | TopExp::Vertices( aWire, V1, V2 ); | |
1375 | gp_Pnt P1, P2; | |
1376 | P1 = BRep_Tool::Pnt(V1); | |
1377 | P2 = BRep_Tool::Pnt(V2); | |
1378 | Standard_Real dist = Pf.Distance( P1 ); | |
1379 | if (dist < DistF) | |
1380 | { | |
1381 | DistF = dist; | |
1382 | IndexF = i; | |
1383 | IsFirstF = Standard_True; | |
1384 | } | |
1385 | dist = Pf.Distance( P2 ); | |
1386 | if (dist < DistF) | |
1387 | { | |
1388 | DistF = dist; | |
1389 | IndexF = i; | |
1390 | IsFirstF = Standard_False; | |
1391 | } | |
1392 | dist = Pl.Distance( P1 ); | |
1393 | if (dist < DistL) | |
1394 | { | |
1395 | DistL = dist; | |
1396 | IndexL = i; | |
1397 | IsFirstL = Standard_True; | |
1398 | } | |
1399 | dist = Pl.Distance( P2 ); | |
1400 | if (dist < DistL) | |
1401 | { | |
1402 | DistL = dist; | |
1403 | IndexL = i; | |
1404 | IsFirstL = Standard_False; | |
1405 | } | |
1406 | } | |
1407 | TopoDS_Wire theWire; | |
1408 | TopoDS_Edge theEdge; | |
1409 | TopoDS_Vertex theVertex; | |
1410 | Standard_Real CommonTol; | |
1411 | Standard_Boolean TryToClose = Standard_True; | |
1412 | if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL) | |
1413 | { | |
1414 | if (DistF < DistL) | |
1415 | { | |
1416 | DistL = RealLast(); | |
1417 | IndexL++; | |
1418 | } | |
1419 | else | |
1420 | { | |
1421 | DistF = RealLast(); | |
1422 | IndexF++; | |
1423 | } | |
1424 | TryToClose = Standard_False; | |
1425 | } | |
1426 | if (DistF <= MaxTol) | |
1427 | { | |
1428 | theWire = TopoDS::Wire( UnclosedWires(IndexF) ); | |
1429 | TopoDS_Vertex V1, V2; | |
1430 | TopExp::Vertices( theWire, V1, V2 ); | |
1431 | TopTools_IndexedDataMapOfShapeListOfShape VEmap; | |
1432 | TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap ); | |
1433 | theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) : | |
1434 | TopoDS::Edge(VEmap.FindFromKey( V2 ).First()); | |
1435 | TopoDS_Iterator it( theWire ); | |
1436 | for (; it.More(); it.Next()) | |
1437 | { | |
1438 | TopoDS_Edge anEdge = TopoDS::Edge( it.Value() ); | |
1439 | if (IsFirstF) anEdge.Reverse(); | |
1440 | if (!anEdge.IsSame( theEdge )) | |
1441 | BB.Add( Base, anEdge ); | |
1442 | } | |
1443 | theVertex = (IsFirstF)? V1 : V2; | |
1444 | CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) ); | |
1445 | if (DistF <= CommonTol) | |
1446 | { | |
1447 | theEdge.Free( Standard_True ); | |
1448 | Vf.Orientation( theVertex.Orientation() ); | |
1449 | BB.Remove( theEdge, theVertex ); | |
1450 | BB.Add( theEdge, Vf ); | |
1451 | BB.UpdateVertex( Vf, CommonTol ); | |
1452 | if (IsFirstF) theEdge.Reverse(); | |
1453 | BB.Add( Base, theEdge ); | |
1454 | } | |
1455 | else | |
1456 | { | |
1457 | if (IsFirstF) theEdge.Reverse(); | |
1458 | BB.Add( Base, theEdge ); | |
1459 | // Creating new edge from theVertex to Vf | |
1460 | TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf ); | |
1461 | BB.Add( Base, NewEdge ); | |
1462 | } | |
1463 | } | |
1464 | if (DistL <= MaxTol && IndexL != IndexF) | |
1465 | { | |
1466 | theWire = TopoDS::Wire( UnclosedWires(IndexL) ); | |
1467 | TopoDS_Vertex V1, V2; | |
1468 | TopExp::Vertices( theWire, V1, V2 ); | |
1469 | TopTools_IndexedDataMapOfShapeListOfShape VEmap; | |
1470 | TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap ); | |
1471 | theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) : | |
1472 | TopoDS::Edge(VEmap.FindFromKey( V2 ).First()); | |
1473 | TopoDS_Iterator it( theWire ); | |
1474 | for (; it.More(); it.Next()) | |
1475 | { | |
1476 | TopoDS_Edge anEdge = TopoDS::Edge( it.Value() ); | |
1477 | if (!IsFirstL) anEdge.Reverse(); | |
1478 | if (!anEdge.IsSame( theEdge )) | |
1479 | BB.Add( Base, anEdge ); | |
1480 | } | |
1481 | theVertex = (IsFirstL)? V1 : V2; | |
1482 | CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) ); | |
1483 | if (DistL <= CommonTol) | |
1484 | { | |
1485 | theEdge.Free( Standard_True ); | |
1486 | Vl.Orientation( theVertex.Orientation() ); | |
1487 | BB.Remove( theEdge, theVertex ); | |
1488 | BB.Add( theEdge, Vl ); | |
1489 | BB.UpdateVertex( Vl, CommonTol ); | |
1490 | if (!IsFirstL) theEdge.Reverse(); | |
1491 | BB.Add( Base, theEdge ); | |
1492 | } | |
1493 | else | |
1494 | { | |
1495 | if (!IsFirstL) theEdge.Reverse(); | |
1496 | BB.Add( Base, theEdge ); | |
1497 | // Creating new edge from Vl to theVertex | |
1498 | TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex ); | |
1499 | BB.Add( Base, NewEdge ); | |
1500 | } | |
1501 | } | |
1502 | // Check if it is possible to close resulting wire | |
1503 | if (TryToClose) | |
1504 | { | |
1505 | TopExp::Vertices( Base, Vf, Vl ); | |
1506 | CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) ); | |
1507 | TopTools_IndexedDataMapOfShapeListOfShape VEmap; | |
1508 | TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap ); | |
1509 | TopoDS_Edge Efirst, Elast; | |
1510 | Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First()); | |
1511 | Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First()); | |
1512 | Pf = BRep_Tool::Pnt(Vf); | |
1513 | Pl = BRep_Tool::Pnt(Vl); | |
1514 | Standard_Real Dist = Pf.Distance(Pl); | |
1515 | if (Dist <= CommonTol) | |
1516 | { | |
1517 | Elast.Free( Standard_True ); | |
1518 | Vf.Orientation( Vl.Orientation() ); | |
1519 | BB.Remove( Elast, Vl ); | |
1520 | BB.Add( Elast, Vf ); | |
1521 | BB.UpdateVertex( Vf, CommonTol ); | |
1522 | Base.Closed( Standard_True ); | |
1523 | } | |
1524 | else if (Dist <= MaxTol) | |
1525 | { | |
1526 | // Creating new edge from Vl to Vf | |
1527 | TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl ); | |
1528 | BB.Add( Base, NewEdge ); | |
1529 | Base.Closed( Standard_True ); | |
1530 | } | |
1531 | } | |
1532 | // Updating sequences ClosedWires and UnclosedWires | |
1533 | if (DistF <= MaxTol) | |
1534 | UnclosedWires.Remove( IndexF ); | |
1535 | if (DistL <= MaxTol && IndexL != IndexF) | |
1536 | { | |
1537 | if (DistF <= MaxTol && IndexL > IndexF) | |
1538 | IndexL--; | |
1539 | UnclosedWires.Remove( IndexL ); | |
1540 | } | |
1541 | if (Base.Closed()) | |
1542 | { | |
1543 | ClosedWires.Append( Base ); | |
1544 | UnclosedWires.Remove( 1 ); | |
1545 | } | |
1546 | else if (DistF > MaxTol && DistL > MaxTol) | |
1547 | { | |
1548 | IsolatedWires.Append( Base ); | |
1549 | UnclosedWires.Remove( 1 ); | |
1550 | } | |
1551 | } | |
1552 | ||
1553 | // Updating myShape | |
1554 | if (ClosedWires.Length() + IsolatedWires.Length() == 1) | |
1555 | { | |
1556 | if (!ClosedWires.IsEmpty()) | |
1557 | myShape = ClosedWires.First(); | |
1558 | else | |
1559 | myShape = IsolatedWires.First(); | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | TopoDS_Compound R; | |
1564 | BB.MakeCompound( R ); | |
1565 | for (i = 1; i <= ClosedWires.Length(); i++) | |
1566 | BB.Add( R, ClosedWires(i) ); | |
1567 | for (i = 1; i <= IsolatedWires.Length(); i++) | |
1568 | BB.Add( R, IsolatedWires(i) ); | |
1569 | myShape = R; | |
1570 | } | |
1571 | } | |
1572 | ||
1573 | //======================================================================= | |
1574 | //function : CutEdge | |
1575 | //purpose : Decoupe d une edge aux extrema de courbures et aux points | |
1576 | // d inflexion. | |
1577 | // Les cercles fermes sont aussi decoupes en deux. | |
1578 | // Si <Cuts> est vide l edge n est pas modifie. | |
1579 | // Le premier et le dernier vertex de l edge originale | |
1580 | // appartiennent respectivement a la premiere et derniere | |
1581 | // portions. | |
1582 | //======================================================================= | |
1583 | Standard_Integer CutEdge (const TopoDS_Edge& E, | |
1584 | const TopoDS_Face& F, | |
1585 | Standard_Integer ForceCut, | |
1586 | TopTools_ListOfShape& Cuts) | |
1587 | { | |
1588 | Cuts.Clear(); | |
1589 | MAT2d_CutCurve Cuter; | |
1590 | TColGeom2d_SequenceOfCurve theCurves; | |
1591 | Standard_Real f,l; | |
1592 | Handle(Geom2d_Curve) C2d; | |
1593 | Handle(Geom2d_TrimmedCurve) CT2d; | |
1594 | // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin | |
1595 | Standard_Real aTol = BRep_Tool::Tolerance(E); | |
1596 | Handle(Geom_Curve) aC; | |
1597 | // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End | |
1598 | ||
1599 | TopoDS_Vertex V1,V2,VF,VL; | |
1600 | TopExp::Vertices (E,V1,V2); | |
1601 | BRep_Builder B; | |
1602 | ||
1603 | C2d = BRep_Tool::CurveOnSurface (E,F,f,l); | |
1604 | // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin | |
1605 | aC = BRep_Tool::Curve(E,f,l); | |
1606 | // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End | |
1607 | CT2d = new Geom2d_TrimmedCurve(C2d,f,l); | |
1608 | //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse(); | |
1609 | ||
1610 | if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) && | |
1611 | ( Abs(f-l) >= PI) ) { | |
1612 | return 0; | |
1613 | //--------------------------- | |
1614 | // Decoupe cercle ferme. | |
1615 | //--------------------------- | |
1616 | Standard_Real m = (f + l)*0.5; | |
1617 | // Modified by Sergey KHROMOV - Wed Mar 6 17:37:28 2002 Begin | |
1618 | gp_Pnt P = aC->Value(m); | |
1619 | ||
1620 | VL = BRepLib_MakeVertex(P); | |
1621 | B.UpdateVertex(VL, aTol); | |
1622 | // Modified by Sergey KHROMOV - Wed Mar 6 17:37:30 2002 End | |
1623 | TopoDS_Shape aLocalShape = E.EmptyCopied(); | |
1624 | TopoDS_Edge FE = TopoDS::Edge(aLocalShape); | |
1625 | TopoDS_Edge LE = TopoDS::Edge(aLocalShape); | |
1626 | // TopoDS_Edge FE = TopoDS::Edge(E.EmptyCopied()); | |
1627 | // TopoDS_Edge LE = TopoDS::Edge(E.EmptyCopied()); | |
1628 | FE.Orientation(TopAbs_FORWARD); | |
1629 | LE.Orientation(TopAbs_FORWARD); | |
1630 | B.Add (FE,V1); | |
1631 | B.Add (FE,VL.Oriented(TopAbs_REVERSED)); | |
1632 | B.Range(FE, f, m); | |
1633 | B.Add (LE,V2); | |
1634 | B.Add (LE,VL.Oriented(TopAbs_FORWARD)); | |
1635 | B.Range(LE, m, l); | |
1636 | Cuts.Append(FE.Oriented(E.Orientation())); | |
1637 | Cuts.Append(LE.Oriented(E.Orientation())); | |
1638 | //-------- | |
1639 | // Retour. | |
1640 | //-------- | |
1641 | return 2; | |
1642 | } | |
1643 | ||
1644 | //------------------------- | |
1645 | // Decoupe de la courbe. | |
1646 | //------------------------- | |
1647 | Cuter.Perform(CT2d); | |
1648 | ||
1649 | // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin | |
1650 | if (ForceCut == 0) { | |
1651 | if (Cuter.UnModified()) { | |
1652 | //----------------------------- | |
1653 | // edge non modifiee => retour. | |
1654 | //----------------------------- | |
1655 | return 0; | |
1656 | } else { | |
1657 | for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++) | |
1658 | theCurves.Append(Cuter.Value(k)); | |
1659 | } | |
1660 | } else if (ForceCut == 1) { | |
1661 | if (Cuter.UnModified()) { | |
1662 | CutCurve (CT2d, 2, theCurves); | |
1663 | } else { | |
1664 | for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++) | |
1665 | theCurves.Append(Cuter.Value(k)); | |
1666 | } | |
1667 | } else if (ForceCut == 2) { | |
1668 | if (Cuter.UnModified()) { | |
1669 | CutCurve (CT2d, 3, theCurves); | |
1670 | } else { | |
1671 | if (Cuter.NbCurves() == 2) { | |
1672 | Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1); | |
1673 | ||
1674 | if (CC->LastParameter() > (l+f)/2.) { | |
1675 | CutCurve (CC, 2, theCurves); | |
1676 | theCurves.Append(Cuter.Value(2)); | |
1677 | } else { | |
1678 | theCurves.Append(CC); | |
1679 | CutCurve (Cuter.Value(2), 2, theCurves); | |
1680 | } | |
1681 | } else { | |
1682 | for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++) | |
1683 | theCurves.Append(Cuter.Value(k)); | |
1684 | } | |
1685 | } | |
1686 | } | |
1687 | // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End | |
1688 | ||
1689 | //-------------------------------------- | |
1690 | // Creation des edges decoupees. | |
1691 | //-------------------------------------- | |
1692 | VF = V1; | |
1693 | ||
1694 | for (Standard_Integer k = 1; k <= theCurves.Length(); k++) { | |
1695 | ||
1696 | Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k)); | |
1697 | ||
1698 | if (k == theCurves.Length()) {VL = V2;} | |
1699 | else { | |
1700 | // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin | |
1701 | gp_Pnt P = aC->Value(CC->LastParameter()); | |
1702 | ||
1703 | VL = BRepLib_MakeVertex(P); | |
1704 | B.UpdateVertex(VL, aTol); | |
1705 | // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End | |
1706 | } | |
1707 | TopoDS_Shape aLocalShape = E.EmptyCopied(); | |
1708 | TopoDS_Edge NE = TopoDS::Edge(aLocalShape); | |
1709 | // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied()); | |
1710 | NE.Orientation(TopAbs_FORWARD); | |
1711 | B.Add (NE,VF.Oriented(TopAbs_FORWARD)); | |
1712 | B.Add (NE,VL.Oriented(TopAbs_REVERSED)); | |
1713 | B.Range(NE,CC->FirstParameter(),CC->LastParameter()); | |
1714 | Cuts.Append(NE.Oriented(E.Orientation())); | |
1715 | VF = VL; | |
1716 | } | |
1717 | ||
1718 | return theCurves.Length(); | |
1719 | } | |
1720 | ||
1721 | // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin | |
1722 | //======================================================================= | |
1723 | //function : CutCurve | |
1724 | //purpose : | |
1725 | //======================================================================= | |
1726 | ||
1727 | void CutCurve (const Handle(Geom2d_TrimmedCurve)& C, | |
1728 | const Standard_Integer nbParts, | |
1729 | TColGeom2d_SequenceOfCurve& theCurves) | |
1730 | { | |
1731 | Handle(Geom2d_TrimmedCurve) TrimC; | |
1732 | Standard_Real UF,UL,UC; | |
1733 | Standard_Real Step; | |
1734 | gp_Pnt2d PF,PL,PC; | |
1735 | Standard_Real PTol = Precision::PConfusion()*10; | |
1736 | Standard_Real Tol = Precision::Confusion()*10; | |
1737 | Standard_Boolean YaCut = Standard_False; | |
1738 | ||
1739 | UF = C->FirstParameter(); | |
1740 | UL = C->LastParameter (); | |
1741 | PF = C->Value(UF); | |
1742 | PL = C->Value(UL); | |
1743 | ||
1744 | Step = (UL - UF)/nbParts; | |
1745 | ||
1746 | for (Standard_Integer i = 1; i < nbParts; i++) { | |
1747 | ||
1748 | UC = UF + i*Step; | |
1749 | PC = C->Value(UC); | |
1750 | ||
1751 | if (UC - UF > PTol && PC.Distance(PF) > Tol) { | |
1752 | if ( UL - UC < PTol || PL.Distance(PC) < Tol) | |
1753 | continue; | |
1754 | ||
1755 | TrimC = new Geom2d_TrimmedCurve(C,UF,UC); | |
1756 | theCurves.Append(TrimC); | |
1757 | UF = UC; | |
1758 | PF = PC; | |
1759 | YaCut = Standard_True; | |
1760 | } | |
1761 | } | |
1762 | if (YaCut) { | |
1763 | TrimC = new Geom2d_TrimmedCurve(C,UF,UL); | |
1764 | theCurves.Append(TrimC); | |
1765 | } else | |
1766 | theCurves.Append(C); | |
1767 | } | |
1768 | // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End | |
1769 | ||
1770 | //======================================================================= | |
1771 | //function : MakeCircle | |
1772 | //purpose : | |
1773 | //======================================================================= | |
1774 | ||
1775 | void MakeCircle (const TopoDS_Edge& E, | |
1776 | const TopoDS_Vertex& V, | |
1777 | const TopoDS_Face& F, | |
1778 | const Standard_Real Offset, | |
86b3805f | 1779 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map, |
7fd59977 | 1780 | const Handle(Geom_Plane)& RefPlane) |
1781 | { | |
1782 | // eval the Axis of the Circle. | |
1783 | Standard_Real f,l; | |
1784 | Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l); | |
1785 | gp_Vec2d DX; | |
1786 | gp_Pnt2d P; | |
1787 | ||
1788 | if (E.Orientation() == TopAbs_FORWARD) { | |
1789 | GC->D1(l,P,DX); | |
1790 | DX.Reverse(); | |
1791 | } | |
1792 | else GC->D1(f,P,DX); | |
1793 | ||
1794 | gp_Ax2d Axis(P,gp_Dir2d(DX)); | |
1795 | Handle(Geom2d_Circle) Circ | |
1796 | = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.); | |
1797 | ||
1798 | // Bind the edges in my Map. | |
1799 | TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane); | |
1800 | TopTools_ListOfShape LL; | |
1801 | ||
1802 | LL.Append(OE); | |
86b3805f | 1803 | Map.Add(V,LL); |
7fd59977 | 1804 | |
1805 | #ifdef DRAW | |
1806 | if ( AffichGeom && !OE.IsNull()) { | |
1807 | sprintf(name,"OFFSET_%d",++NbOFFSET); | |
1808 | DBRep::Set(name,OE); | |
1809 | } | |
1810 | #endif | |
1811 | } | |
1812 | ||
1813 | //======================================================================= | |
1814 | //function : MakeOffset | |
1815 | //purpose : | |
1816 | //======================================================================= | |
1817 | ||
1818 | void MakeOffset (const TopoDS_Edge& E, | |
1819 | const TopoDS_Face& F, | |
1820 | const Standard_Real Offset, | |
86b3805f | 1821 | BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map, |
7fd59977 | 1822 | const Handle(Geom_Plane)& RefPlane) |
1823 | { | |
1824 | Standard_Real f,l; | |
1825 | Standard_Real anOffset = Offset; | |
1826 | ||
1827 | if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1; | |
1828 | ||
1829 | Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l); | |
1830 | Handle(Geom2d_Curve) G2dOC; | |
1831 | ||
1832 | Geom2dAdaptor_Curve AC(G2d,f,l); | |
1833 | if ( AC.GetType() == GeomAbs_Circle) { | |
1834 | // si l offset est superieur ou egal au rayon et du cote de la | |
1835 | // concavite du cercle => edge null. | |
1836 | gp_Circ2d C1(AC.Circle()); | |
1837 | #ifdef DEB | |
1838 | Standard_Real radius = | |
1839 | #endif | |
1840 | C1.Radius(); | |
1841 | gp_Ax22d axes( C1.Axis()); | |
1842 | gp_Dir2d Xd = axes.XDirection(); | |
1843 | gp_Dir2d Yd = axes.YDirection(); | |
1844 | Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X(); | |
1845 | Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.; | |
1846 | ||
1847 | if (anOffset*Signe < AC.Circle().Radius()) { | |
1848 | // -anOffset vient d une Etrangete adaptoresque! | |
1849 | Handle(Geom2dAdaptor_HCurve) AHC = | |
1850 | new Geom2dAdaptor_HCurve(G2d); | |
1851 | Adaptor3d_OffsetCurve Off(AHC,-anOffset); | |
1852 | Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle()); | |
1853 | ||
1854 | Standard_Real Delta = 2*PI - l + f; | |
1855 | f -= 0.2*Delta; l += 0.2*Delta; | |
1856 | ||
1857 | G2dOC = new Geom2d_TrimmedCurve(CC,f,l); | |
1858 | } | |
1859 | } | |
1860 | else if (AC.GetType() == GeomAbs_Line) { | |
1861 | Handle(Geom2dAdaptor_HCurve) AHC = | |
1862 | new Geom2dAdaptor_HCurve(G2d); | |
1863 | Adaptor3d_OffsetCurve Off(AHC,anOffset); | |
1864 | Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line()); | |
1865 | Standard_Real Delta = (l - f); | |
1866 | f -= Delta; l += Delta; | |
1867 | G2dOC = new Geom2d_TrimmedCurve(CC,f,l); | |
1868 | } | |
1869 | else { | |
1870 | ||
1871 | anOffset = -anOffset; | |
1872 | Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l); | |
1873 | G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset); | |
1874 | ||
1875 | } | |
1876 | ||
1877 | // Bind the edges in my Map. | |
1878 | if (!G2dOC.IsNull()) { | |
1879 | TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane); | |
1880 | OE.Orientation(E.Orientation()); | |
1881 | TopTools_ListOfShape LL; | |
1882 | LL.Append(OE); | |
86b3805f | 1883 | Map.Add(E,LL); |
7fd59977 | 1884 | |
1885 | #ifdef DRAW | |
1886 | if (AffichGeom && !OE.IsNull()) { | |
1887 | sprintf(name,"OFFSET_%d",++NbOFFSET); | |
1888 | DBRep::Set(name,OE); | |
1889 | Standard_Real ii = 0; | |
1890 | } | |
1891 | #endif | |
1892 | ||
1893 | } | |
1894 | } | |
1895 | ||
1896 | //======================================================================= | |
1897 | //function : UpdateDetromp | |
1898 | //purpose : Pour chaque interval sur la bissectrice defini par params | |
1899 | // test si le point milieu est a une distance > offset | |
1900 | // dans ce cas les vertex correspondants aux extremites de l interval | |
1901 | // sont ranges dans le detrompeur. | |
1902 | // => Si un meme vertex apparait deux fois dans le detrompeur la | |
1903 | // frontiere de la zone de proximitee est tangente a l offset . | |
1904 | //======================================================================= | |
1905 | ||
1906 | void UpdateDetromp (TopTools_ListOfShape& Detromp1, | |
1907 | TopTools_ListOfShape& Detromp2, | |
1908 | const TopTools_SequenceOfShape& Vertices, | |
1909 | const TColgp_SequenceOfPnt& Params, | |
1910 | const Bisector_Bisec& Bisec, | |
1911 | const Standard_Boolean SOnE, | |
1912 | const Standard_Boolean EOnE, | |
1913 | const BRepFill_TrimEdgeTool& Trim) | |
1914 | { | |
1915 | Standard_Integer ii = 1; | |
1916 | Standard_Real U1,U2; | |
1917 | TopoDS_Vertex V1,V2; | |
1918 | ||
1919 | Handle(Geom2d_Curve) Bis = Bisec.Value(); | |
1920 | ||
1921 | U1 = Bis->FirstParameter(); | |
1922 | ||
1923 | if (SOnE) { | |
1924 | // le premier point de la bissectrice est sur l offset | |
1925 | V1 = TopoDS::Vertex(Vertices.Value(ii)); | |
1926 | ii++; | |
1927 | } | |
1928 | ||
1929 | while (ii <= Vertices.Length()) { | |
1930 | U2 = Params.Value(ii).X(); | |
1931 | V2 = TopoDS::Vertex(Vertices.Value(ii)); | |
1932 | ||
1933 | gp_Pnt2d P = Bis->Value((U2 + U1)*0.5); | |
1934 | if (!Trim.IsInside(P)) { | |
1935 | if (!V1.IsNull()) { | |
1936 | Detromp1.Append(V1); | |
1937 | Detromp2.Append(V1); | |
1938 | } | |
1939 | Detromp1.Append(V2); | |
1940 | Detromp2.Append(V2); | |
1941 | } | |
1942 | U1 = U2; | |
1943 | V1 = V2; | |
1944 | ii ++; | |
1945 | } | |
1946 | ||
1947 | // test point milieu entre le dernier params et la fin de la bissectrice. | |
1948 | U2 = Bis->LastParameter(); | |
1949 | if (!EOnE) { | |
1950 | if (!Precision::IsInfinite(U2)) { | |
1951 | gp_Pnt2d P = Bis->Value((U2 + U1)*0.5); | |
1952 | if (!Trim.IsInside(P)) { | |
1953 | if (!V1.IsNull()) { | |
1954 | Detromp1.Append(V1); | |
1955 | Detromp2.Append(V1); | |
1956 | } | |
1957 | } | |
1958 | } | |
1959 | else { | |
1960 | if (!V1.IsNull()) { | |
1961 | Detromp1.Append(V1); | |
1962 | Detromp2.Append(V1); | |
1963 | } | |
1964 | } | |
1965 | } | |
1966 | } | |
1967 | ||
1968 | //======================================================================= | |
1969 | //function : VertexFromNode | |
1970 | //purpose : | |
1971 | //======================================================================= | |
1972 | ||
1973 | Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode, | |
1974 | const Standard_Real Offset, | |
1975 | gp_Pnt2d& PN, | |
1976 | BRepFill_DataMapOfNodeShape& MapNodeVertex, | |
1977 | TopoDS_Vertex& VN) | |
1978 | { | |
1979 | Standard_Boolean Status; | |
1980 | Standard_Real Tol = Precision::Confusion(); | |
1981 | BRep_Builder B; | |
1982 | ||
1983 | if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) { | |
1984 | //------------------------------------------------ | |
1985 | // le Noeud donne un vertex sur l offset | |
1986 | //------------------------------------------------ | |
1987 | if (MapNodeVertex.IsBound(aNode)) { | |
1988 | VN = TopoDS::Vertex(MapNodeVertex(aNode)); | |
1989 | } | |
1990 | else { | |
1991 | gp_Pnt P(PN.X(),PN.Y(),0.); | |
1992 | B.MakeVertex (VN); | |
1993 | B.UpdateVertex(VN,P, Precision::Confusion()); | |
1994 | MapNodeVertex.Bind(aNode,VN); | |
1995 | } | |
1996 | Status = Standard_True; | |
1997 | } | |
1998 | else Status = Standard_False; | |
1999 | ||
2000 | return Status; | |
2001 | } | |
2002 | ||
2003 | ||
2004 | //======================================================================= | |
2005 | //function : StoreInMap | |
2006 | //purpose : | |
2007 | //======================================================================= | |
2008 | ||
2009 | void StoreInMap (const TopoDS_Shape& V1, | |
2010 | const TopoDS_Shape& V2, | |
2011 | TopTools_IndexedDataMapOfShapeShape& MapVV) | |
2012 | { | |
2013 | TopoDS_Shape OldV = V1, NewV = V2; | |
2014 | Standard_Integer i; | |
2015 | ||
2016 | if (MapVV.Contains(V2)) | |
2017 | NewV = MapVV.FindFromKey(V2); | |
2018 | ||
2019 | if (MapVV.Contains(V1)) | |
2020 | MapVV.ChangeFromKey(V1) = NewV; | |
2021 | ||
2022 | for (i = 1; i <= MapVV.Extent(); i++) | |
2023 | if (MapVV(i).IsSame(V1)) | |
2024 | MapVV(i) = NewV; | |
2025 | ||
2026 | MapVV.Add(V1, NewV); | |
2027 | } | |
2028 | ||
2029 | //======================================================================= | |
2030 | //function : TrimEdge | |
2031 | //purpose : | |
2032 | //======================================================================= | |
2033 | ||
2034 | void TrimEdge (const TopoDS_Edge& E, | |
2035 | const TopTools_ListOfShape& Detromp, | |
2036 | TopTools_SequenceOfShape& TheVer, | |
2037 | TColStd_SequenceOfReal& ThePar, | |
2038 | TopTools_SequenceOfShape& S, | |
2039 | TopTools_IndexedDataMapOfShapeShape& MapVV) | |
2040 | { | |
2041 | Standard_Boolean Change = Standard_True; | |
2042 | BRep_Builder TheBuilder; | |
2043 | S.Clear(); | |
2044 | ||
2045 | //----------------------------------------------------------- | |
2046 | // Tri des deux sequences en fonction du parametre sur l edge. | |
2047 | //----------------------------------------------------------- | |
2048 | while (Change) { | |
2049 | Change = Standard_False; | |
2050 | for (Standard_Integer i = 1; i < ThePar.Length(); i++) { | |
2051 | if (ThePar.Value(i) > ThePar.Value(i+1)) { | |
2052 | ThePar.Exchange(i,i+1); | |
2053 | TheVer.Exchange(i,i+1); | |
2054 | Change = Standard_True; | |
2055 | } | |
2056 | } | |
2057 | } | |
2058 | ||
2059 | //---------------------------------------------------------- | |
2060 | // Si un vertex n est pas dans le detrompeur il est elimine. | |
2061 | //---------------------------------------------------------- | |
2062 | if (!BRep_Tool::Degenerated(E)) { | |
2063 | for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) { | |
2064 | if ( DoubleOrNotInside (Detromp, | |
2065 | TopoDS::Vertex(TheVer.Value(k)))) { | |
2066 | TheVer.Remove(k); | |
2067 | ThePar.Remove(k); | |
2068 | k--; | |
2069 | } | |
2070 | } | |
2071 | } | |
2072 | ||
2073 | //---------------------------------------------------------- | |
2074 | // Si un vertex_double apparait deux fois dans le detrompeur | |
2075 | // le vertex est elimine . | |
2076 | // sinon on garde une seule de ces representations. | |
2077 | //---------------------------------------------------------- | |
2078 | if (!BRep_Tool::Degenerated(E)) { | |
2079 | for (Standard_Integer k = 1; k < TheVer.Length(); k ++) { | |
2080 | if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) || | |
2081 | Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) { | |
2082 | ||
2083 | if(k+1 == TheVer.Length()) { | |
2084 | StoreInMap(TheVer(k), TheVer(k+1), MapVV); | |
2085 | TheVer.Remove(k); | |
2086 | ThePar.Remove(k); | |
2087 | } | |
2088 | else { | |
2089 | StoreInMap(TheVer(k+1), TheVer(k), MapVV); | |
2090 | TheVer.Remove(k+1); | |
2091 | ThePar.Remove(k+1); | |
2092 | } | |
2093 | /* | |
2094 | if ( DoubleOrNotInside (Detromp, | |
2095 | TopoDS::Vertex(TheVer.Value(k)))) { | |
2096 | TheVer.Remove(k); | |
2097 | ThePar.Remove(k); | |
2098 | k--; | |
2099 | } | |
2100 | */ | |
2101 | k--; | |
2102 | } | |
2103 | } | |
2104 | } | |
2105 | //----------------------------------------------------------- | |
2106 | // Creation des edges. | |
2107 | // le nombre de vertex doit etre pair les edges a creer vont | |
2108 | // d un vertex d indice impair i au vertex i+1; | |
2109 | //----------------------------------------------------------- | |
2110 | for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) { | |
2111 | TopoDS_Shape aLocalShape = E.EmptyCopied(); | |
2112 | TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape); | |
2113 | // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied()); | |
2114 | ||
2115 | if (NewEdge.Orientation() == TopAbs_REVERSED) { | |
2116 | TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED)); | |
2117 | TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD)); | |
2118 | } | |
2119 | else { | |
2120 | TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD)); | |
2121 | TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED)); | |
2122 | } | |
2123 | ||
2124 | ||
2125 | TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1)); | |
2126 | ||
2127 | #ifdef DRAW | |
2128 | if ( AffichEdge) { | |
2129 | sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES); | |
2130 | DBRep::Set(name,NewEdge); | |
2131 | } | |
2132 | if (Affich2d) { | |
2133 | TopLoc_Location L; | |
2134 | Standard_Real f,l; | |
2135 | Handle(Geom_Surface) Surf; | |
2136 | Handle(Geom2d_Curve) C; | |
2137 | BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l); | |
2138 | sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++); | |
2139 | Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l); | |
2140 | Handle(DrawTrSurf_Curve2d) dr = | |
2141 | new DrawTrSurf_Curve2d(C2d,Standard_False); | |
2142 | dr->SetColor(Draw_bleu); | |
2143 | Draw::Set(name,dr); | |
2144 | } | |
2145 | #endif | |
2146 | ||
2147 | S.Append(NewEdge); | |
2148 | } | |
2149 | } | |
2150 | ||
2151 | //======================================================================= | |
2152 | //function : DoubleOrNotInside | |
2153 | //purpose : return True si V apparait 2 fois dans LV ou n est pas dedans. | |
2154 | //======================================================================= | |
2155 | ||
2156 | Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV, | |
2157 | const TopoDS_Vertex& V) | |
2158 | { | |
2159 | Standard_Boolean Vu = Standard_False; | |
2160 | TopTools_ListIteratorOfListOfShape it(LV); | |
2161 | ||
2162 | for ( ; it.More(); it.Next()) { | |
2163 | if (V.IsSame(it.Value())) { | |
2164 | if (Vu) return Standard_True; | |
2165 | else Vu = Standard_True; | |
2166 | } | |
2167 | } | |
2168 | if (Vu) return Standard_False; | |
2169 | else return Standard_True; | |
2170 | } | |
2171 | ||
2172 | Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge, | |
2173 | const TopoDS_Vertex& aVertex) | |
2174 | { | |
2175 | gp_Pnt PV = BRep_Tool::Pnt(aVertex); | |
2176 | gp_Pnt2d PV2d, Pfirst, Plast, Pmid; | |
2177 | PV2d.SetCoord( PV.X(), PV.Y() ); | |
2178 | ||
2179 | Handle(Geom2d_Curve) PCurve; | |
2180 | Handle( BRep_CurveRepresentation ) CurveRep = | |
2181 | ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First(); | |
2182 | PCurve = CurveRep->PCurve(); | |
2183 | ||
2184 | Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First(); | |
2185 | Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last(); | |
2186 | Pfirst = PCurve->Value(fpar); | |
2187 | Plast = PCurve->Value(lpar); | |
2188 | Pmid = PCurve->Value((fpar + lpar)*0.5); | |
2189 | ||
2190 | Standard_Real theTol = BRep_Tool::Tolerance(aVertex); | |
2191 | theTol *= 1.5; | |
2192 | ||
2193 | Standard_Real dist1 = Pfirst.Distance(PV2d); | |
2194 | Standard_Real dist2 = Plast.Distance(PV2d); | |
2195 | Standard_Real dist3 = Pmid.Distance(PV2d); | |
2196 | ||
2197 | if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol) | |
2198 | return Standard_True; | |
2199 | ||
2200 | return Standard_False; | |
2201 | } | |
2202 | ||
2203 | static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset, | |
2204 | const BRepMAT2d_BisectingLocus& Locus, | |
2205 | const BRepMAT2d_LinkTopoBilo& Link, | |
2206 | TopTools_ListOfShape& BadEdges) | |
2207 | { | |
2208 | ||
2209 | TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD)); | |
2210 | Standard_Real eps = Precision::Confusion(); | |
2211 | Standard_Real LimCurv = 1./Offset; | |
2212 | ||
2213 | TopTools_MapOfShape aMap; | |
2214 | ||
2215 | for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) { | |
2216 | for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) { | |
2217 | const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie)); | |
2218 | if (SE.ShapeType() == TopAbs_EDGE) { | |
2219 | ||
2220 | if (aMap.Contains(SE)) { | |
2221 | //cout << "Edge is treated second time" << endl; | |
2222 | continue; | |
2223 | } | |
2224 | ||
2225 | TopoDS_Edge E = TopoDS::Edge(SE); | |
2226 | ||
2227 | Standard_Real f,l; | |
2228 | ||
2229 | Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l); | |
2230 | ||
2231 | Geom2dAdaptor_Curve AC(G2d,f,l); | |
2232 | GeomAbs_CurveType aCType = AC.GetType(); | |
2233 | ||
2234 | if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) { | |
2235 | ||
2236 | Standard_Boolean reverse = Standard_False; | |
2237 | if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True; | |
2238 | ||
2239 | gp_Pnt2d P, Pc; | |
2240 | gp_Dir2d N; | |
2241 | ||
2242 | Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps); | |
2243 | ||
2244 | aCLProps.SetParameter(f); | |
2245 | if(!aCLProps.IsTangentDefined()) { | |
2246 | BadEdges.Append(SE); | |
2247 | aMap.Add(SE); | |
2248 | continue; | |
2249 | } | |
2250 | ||
2251 | P = aCLProps.Value(); | |
2252 | Standard_Real Crv = aCLProps.Curvature(); | |
2253 | ||
2254 | if(Crv >= eps) { | |
2255 | aCLProps.Tangent(N); | |
2256 | Standard_Real x = N.Y(), y = -N.X(); | |
2257 | N.SetCoord(x, y); | |
2258 | if (reverse) N.Reverse(); | |
2259 | aCLProps.CentreOfCurvature(Pc); | |
2260 | gp_Vec2d Dir( P, Pc ); | |
2261 | if (N.Dot(Dir) > 0.) { | |
2262 | if (LimCurv <= Crv + eps) { | |
2263 | BadEdges.Append(SE); | |
2264 | aMap.Add(SE); | |
2265 | continue; | |
2266 | } | |
2267 | } | |
2268 | } | |
2269 | ||
2270 | aCLProps.SetParameter(l); | |
2271 | if(!aCLProps.IsTangentDefined()) { | |
2272 | BadEdges.Append(SE); | |
2273 | aMap.Add(SE); | |
2274 | continue; | |
2275 | } | |
2276 | ||
2277 | P = aCLProps.Value(); | |
2278 | Crv = aCLProps.Curvature(); | |
2279 | ||
2280 | if(Crv >= eps) { | |
2281 | aCLProps.Tangent(N); | |
2282 | Standard_Real x = N.Y(), y = -N.X(); | |
2283 | N.SetCoord(x, y); | |
2284 | if (reverse) N.Reverse(); | |
2285 | aCLProps.CentreOfCurvature(Pc); | |
2286 | gp_Vec2d Dir( P, Pc ); | |
2287 | if (N.Dot(Dir) > 0.) { | |
2288 | if (LimCurv <= Crv + eps) { | |
2289 | BadEdges.Append(SE); | |
2290 | aMap.Add(SE); | |
2291 | continue; | |
2292 | } | |
2293 | } | |
2294 | } | |
2295 | } | |
2296 | } | |
2297 | } | |
2298 | } | |
2299 | } | |
2300 | ||
2301 | ||
2302 | //======================================================================= | |
2303 | //function : PerformCurve | |
2304 | //purpose : | |
2305 | //======================================================================= | |
2306 | ||
2307 | static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters, | |
2308 | TColgp_SequenceOfPnt& Points, | |
2309 | const Adaptor3d_Curve& C, | |
2310 | const Standard_Real Deflection, | |
2311 | const Standard_Real U1, | |
2312 | const Standard_Real U2, | |
2313 | const Standard_Real EPSILON, | |
2314 | const Standard_Integer Nbmin) | |
2315 | { | |
2316 | Standard_Real UU1 = Min(U1, U2); | |
2317 | Standard_Real UU2 = Max(U1, U2); | |
2318 | ||
2319 | gp_Pnt Pdeb, Pfin; | |
2320 | gp_Vec Ddeb,Dfin; | |
2321 | C.D1(UU1,Pdeb,Ddeb); | |
2322 | Parameters.Append(UU1); | |
2323 | Points.Append(Pdeb); | |
2324 | ||
2325 | C.D1(UU2,Pfin,Dfin); | |
2326 | QuasiFleche(C,Deflection*Deflection, | |
2327 | UU1,Pdeb, | |
2328 | Ddeb, | |
2329 | UU2,Pfin, | |
2330 | Dfin, | |
2331 | Nbmin, | |
2332 | EPSILON*EPSILON, | |
2333 | Parameters,Points); | |
2334 | return Standard_True; | |
2335 | } | |
2336 | //======================================================================= | |
2337 | //function : QuasiFleche | |
2338 | //purpose : | |
2339 | //======================================================================= | |
2340 | ||
2341 | static void QuasiFleche(const Adaptor3d_Curve& C, | |
2342 | const Standard_Real Deflection2, | |
2343 | const Standard_Real Udeb, | |
2344 | const gp_Pnt& Pdeb, | |
2345 | const gp_Vec& Vdeb, | |
2346 | const Standard_Real Ufin, | |
2347 | const gp_Pnt& Pfin, | |
2348 | const gp_Vec& Vfin, | |
2349 | const Standard_Integer Nbmin, | |
2350 | const Standard_Real Eps, | |
2351 | TColStd_SequenceOfReal& Parameters, | |
2352 | TColgp_SequenceOfPnt& Points) | |
2353 | { | |
2354 | Standard_Integer Ptslength = Points.Length(); | |
2355 | Standard_Real Udelta = Ufin-Udeb; | |
2356 | gp_Pnt Pdelta; | |
2357 | gp_Vec Vdelta; | |
2358 | if (Nbmin > 2) { | |
2359 | Udelta /=(Nbmin-1); | |
2360 | C.D1(Udeb+Udelta,Pdelta,Vdelta); | |
2361 | } | |
2362 | else { | |
2363 | Pdelta = Pfin; | |
2364 | Vdelta = Vfin; | |
2365 | } | |
2366 | ||
2367 | ||
2368 | Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude(); | |
2369 | Standard_Real theFleche=0; | |
2370 | Standard_Boolean flecheok = Standard_False; | |
2371 | if (Norme > Eps) { | |
2372 | // Evaluation de la fleche par interpolation . Voir IntWalk_IWalking_5.gxx | |
2373 | Standard_Real N1 = Vdeb.SquareMagnitude(); | |
2374 | Standard_Real N2 = Vdelta.SquareMagnitude(); | |
2375 | if (N1 > Eps && N2 > Eps) { | |
2376 | Standard_Real Normediff = | |
2377 | (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus(); | |
2378 | if (Normediff > Eps) { | |
2379 | theFleche = Normediff*Norme/64.; | |
2380 | flecheok = Standard_True; | |
2381 | } | |
2382 | } | |
2383 | } | |
2384 | if (!flecheok) { | |
2385 | gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.); | |
2386 | gp_Pnt Pverif(C.Value(Udeb+Udelta/2.)); | |
2387 | theFleche = Pmid.SquareDistance(Pverif); | |
2388 | } | |
2389 | ||
2390 | if (theFleche < Deflection2) { | |
2391 | Parameters.Append(Udeb+Udelta); | |
2392 | Points.Append(Pdelta); | |
2393 | } | |
2394 | else { | |
2395 | QuasiFleche(C,Deflection2,Udeb,Pdeb, | |
2396 | Vdeb, | |
2397 | Udeb+Udelta,Pdelta, | |
2398 | Vdelta, | |
2399 | 3, | |
2400 | Eps, | |
2401 | Parameters,Points); | |
2402 | ||
2403 | } | |
2404 | ||
2405 | if (Nbmin > 2) { | |
2406 | QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta, | |
2407 | Vdelta, | |
2408 | Ufin,Pfin, | |
2409 | Vfin, | |
2410 | Nbmin-(Points.Length()-Ptslength), | |
2411 | Eps, | |
2412 | Parameters,Points); | |
2413 | } | |
2414 | } | |
2415 |