1 // Created on: 1995-04-20
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
21 #include <BRepFill_OffsetWire.ixx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRepAdaptor_Surface.hxx>
26 #include <BRepFill_DataMapOfNodeShape.hxx>
27 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
28 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
29 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
30 #include <BRepFill_TrimEdgeTool.hxx>
31 #include <BRepLib.hxx>
32 #include <BRepLib_MakeVertex.hxx>
33 #include <BRepLib_MakeFace.hxx>
34 #include <BRepLib_MakeWire.hxx>
35 #include <BRepLib_MakeEdge.hxx>
36 #include <BRepTools.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRep_TEdge.hxx>
40 #include <BRep_CurveRepresentation.hxx>
41 #include <BRep_GCurve.hxx>
42 #include <BRepTools_WireExplorer.hxx>
43 #include <BRepMAT2d_Explorer.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
45 #include <Geom2dAdaptor_HCurve.hxx>
46 #include <Adaptor3d_OffsetCurve.hxx>
47 #include <Adaptor3d_Curve.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom2d_Curve.hxx>
51 #include <Geom2d_Circle.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <Geom2d_TrimmedCurve.hxx>
54 #include <Geom2d_OffsetCurve.hxx>
55 #include <GeomAPI.hxx>
56 #include <Geom_TrimmedCurve.hxx>
57 #include <Geom_Circle.hxx>
58 #include <Geom_Line.hxx>
59 #include <Geom_OffsetCurve.hxx>
60 #include <MAT_Arc.hxx>
61 #include <MAT_Node.hxx>
62 #include <MAT_Graph.hxx>
63 #include <MAT2d_CutCurve.hxx>
64 #include <Precision.hxx>
65 #include <Standard_NotImplemented.hxx>
66 #include <TColgp_SequenceOfPnt.hxx>
67 #include <TColStd_SequenceOfReal.hxx>
70 #include <TopExp_Explorer.hxx>
72 #include <TopoDS_Wire.hxx>
73 #include <TopoDS_Compound.hxx>
74 #include <TopoDS_Iterator.hxx>
75 #include <TopTools_MapOfShape.hxx>
76 #include <TopTools_MapIteratorOfMapOfShape.hxx>
77 #include <TopTools_ListIteratorOfListOfShape.hxx>
78 #include <TopTools_DataMapOfShapeListOfShape.hxx>
79 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
80 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
81 #include <TopTools_SequenceOfShape.hxx>
82 #include <TopTools_ListOfShape.hxx>
83 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
84 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
90 #include <gp_Dir2d.hxx>
92 #include <BRep_TVertex.hxx>
93 #include <TopTools_IndexedMapOfShape.hxx>
94 #include <Geom2d_BSplineCurve.hxx>
95 #include <TColgp_Array1OfPnt2d.hxx>
96 #include <TColStd_Array1OfReal.hxx>
97 #include <TColStd_Array1OfInteger.hxx>
98 #include <BRepTools_Substitution.hxx>
99 #include <BRepLib_MakeVertex.hxx>
100 #include <Geom2dLProp_CLProps2d.hxx>
101 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
102 #include <Standard_ErrorHandler.hxx>
106 #include <DrawTrSurf.hxx>
107 #include <DrawTrSurf_Curve2d.hxx>
109 static Standard_Boolean AffichGeom = Standard_False;
110 static Standard_Boolean Affich2d = Standard_False;
111 static Standard_Boolean AffichEdge = Standard_False;
112 static Standard_Integer NbTRIMEDGES = 0;
113 static Standard_Integer NbOFFSET = 0;
114 static Standard_Integer NbEDGES = 0;
115 static Standard_Integer NbBISSEC = 0;
118 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
120 static void QuasiFleche(const Adaptor3d_Curve& C,
121 const Standard_Real Deflection2,
122 const Standard_Real Udeb,
125 const Standard_Real Ufin,
128 const Standard_Integer Nbmin,
129 const Standard_Real Eps,
130 TColStd_SequenceOfReal& Parameters,
131 TColgp_SequenceOfPnt& Points);
133 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
134 TColgp_SequenceOfPnt& Points,
135 const Adaptor3d_Curve& C,
136 const Standard_Real Deflection,
137 const Standard_Real U1,
138 const Standard_Real U2,
139 const Standard_Real EPSILON,
140 const Standard_Integer Nbmin);
142 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
143 const BRepMAT2d_BisectingLocus& Locus,
144 const BRepMAT2d_LinkTopoBilo& Link,
145 TopTools_ListOfShape& BadEdges);
147 static Standard_Integer CutEdge (const TopoDS_Edge& E,
148 const TopoDS_Face& F,
149 Standard_Integer ForceCut,
150 TopTools_ListOfShape& Cuts);
153 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
154 const Standard_Integer nbParts,
155 TColGeom2d_SequenceOfCurve& theCurves);
156 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
159 static void EdgeVertices (const TopoDS_Edge& E,
163 if (E.Orientation() == TopAbs_REVERSED) {
164 TopExp::Vertices(E,V2,V1);
167 TopExp::Vertices(E,V1,V2);
171 static void UpdateDetromp (TopTools_ListOfShape& Detromp1,
172 TopTools_ListOfShape& Detromp2,
173 const TopTools_SequenceOfShape& Vertices,
174 const TColgp_SequenceOfPnt& Params,
175 const Bisector_Bisec& Bisec,
176 const Standard_Boolean SOnE,
177 const Standard_Boolean EOnE,
178 const BRepFill_TrimEdgeTool& Trim);
180 static Standard_Boolean VertexFromNode
181 (const Handle(MAT_Node)& aNode,
182 const Standard_Real Offset,
184 BRepFill_DataMapOfNodeShape& MapNodeVertex,
187 static void StoreInMap (const TopoDS_Shape& V1,
188 const TopoDS_Shape& V2,
189 TopTools_IndexedDataMapOfShapeShape& MapVV);
191 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
192 const TopTools_ListOfShape& D,
193 TopTools_SequenceOfShape& Sv,
194 TColStd_SequenceOfReal& MapverPar,
195 TopTools_SequenceOfShape& S,
196 TopTools_IndexedDataMapOfShapeShape& MapVV,
197 const Standard_Integer IndOfE);
199 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
200 const TopoDS_Vertex& V);
202 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
203 const TopoDS_Vertex& aVertex);
205 static void MakeCircle
206 (const TopoDS_Edge& E,
207 const TopoDS_Vertex& V,
208 const TopoDS_Face& F,
209 const Standard_Real Offset,
210 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
211 const Handle(Geom_Plane)& RefPlane);
213 static void MakeOffset
214 (const TopoDS_Edge& E,
215 const TopoDS_Face& F,
216 const Standard_Real Offset,
217 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
218 const Handle(Geom_Plane)& RefPlane,
219 const Standard_Boolean IsOpenResult,
220 const TopoDS_Vertex * Ends);
224 //=======================================================================
225 //function : CheckFace
226 //purpose : Check if face contains an edge with C0 continuity
227 //=======================================================================
229 static void CheckFace(const TopoDS_Face& theFace)
231 TopExp_Explorer ex(theFace,TopAbs_EDGE);
232 for(; ex.More(); ex.Next())
234 TopoDS_Edge anEdge=TopoDS::Edge(ex.Current());
236 const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(anEdge,theFace,f,l);
237 if (C->Continuity() == GeomAbs_C0)
238 Standard_ConstructionError::Raise("Initial shape contains an edge with C0 continuity");
242 //=======================================================================
243 //function : KPartCircle
245 //=======================================================================
247 static Standard_Boolean KPartCircle
248 (const TopoDS_Face& mySpine,
249 const Standard_Real myOffset,
250 const Standard_Real Alt,
251 TopoDS_Shape& myShape,
252 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
253 Standard_Boolean& myIsDone)
255 // The only contour which is a closed circle
256 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
257 Standard_Integer NbEdges = 0;
260 for (; exp.More(); exp.Next()) {
262 E = TopoDS::Edge(exp.Current());
263 if (NbEdges > 1) return Standard_False;
268 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
270 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
271 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
272 C = Ct->BasisCurve();
276 TopExp::Vertices(E,V1,V2);
277 if (!V1.IsSame(V2)) //may be case of line
279 if (!C->IsKind(STANDARD_TYPE(Geom_Line))) return Standard_False;
280 Handle(Geom_Line) LE = Handle(Geom_Line)::DownCast(C);
281 Standard_Real anOffset = myOffset;
282 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
284 Handle(Geom2d_Curve) aPCurve;
285 Handle(Geom_Surface) aSurf;
286 TopLoc_Location aLoc;
287 BRep_Tool::CurveOnSurface(E, aPCurve, aSurf, aLoc, f, l);
288 Handle(Geom2dAdaptor_HCurve) AHC = new Geom2dAdaptor_HCurve(aPCurve, f, l);
289 Adaptor3d_OffsetCurve Off(AHC,anOffset);
290 Handle(Geom2d_Line) OLC = new Geom2d_Line(Off.Line());
291 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
292 myShape = BRepLib_MakeEdge(OLC, aPlane, f, l);
293 BRepLib::BuildCurve3d(TopoDS::Edge(myShape));
295 myShape.Orientation(E.Orientation());
298 BRepAdaptor_Surface S(mySpine,0);
299 gp_Ax1 Nor = S.Plane().Axis();
301 gp_Vec Trans(Nor.Direction());
303 T.SetTranslation(Trans);
304 myShape.Move(TopLoc_Location(T));
307 TopTools_ListOfShape LL;
311 TopoDS_Edge myEdge = TopoDS::Edge(myShape);
312 myShape = BRepLib_MakeWire(myEdge);
314 myIsDone = Standard_True;
315 return Standard_True;
318 if (!C->IsKind(STANDARD_TYPE(Geom_Circle))) return Standard_False;
319 Handle(Geom_Circle) CE = Handle(Geom_Circle)::DownCast(C);
320 Standard_Real anOffset = myOffset;
321 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
323 if (anOffset < 0. || Abs(anOffset) < CE->Radius()) {
324 Handle(Geom_Circle) OC = new Geom_Circle (CE->Position(),CE->Radius() - anOffset);
325 myShape = BRepLib_MakeEdge(OC,f,l);
327 myShape.Orientation(E.Orientation());
330 BRepAdaptor_Surface S(mySpine,0);
331 gp_Ax1 Nor = S.Plane().Axis();
333 gp_Vec Trans(Nor.Direction());
335 T.SetTranslation(Trans);
336 myShape.Move(TopLoc_Location(T));
339 TopTools_ListOfShape LL;
343 myIsDone = Standard_True;
344 return Standard_True;
347 //=======================================================================
348 //function : BRepFill_OffsetWire
350 //=======================================================================
352 BRepFill_OffsetWire::BRepFill_OffsetWire()
353 : myIsOpenResult(Standard_False),
354 myIsDone(Standard_False)
359 //=======================================================================
360 //function : BRepFill_OffsetWire
362 //=======================================================================
364 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
365 const GeomAbs_JoinType Join,
366 const Standard_Boolean IsOpenResult)
368 Init(Spine,Join,IsOpenResult);
371 //=======================================================================
374 //=======================================================================
376 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
377 const GeomAbs_JoinType Join,
378 const Standard_Boolean IsOpenResult)
380 Standard_NotImplemented_Raise_if(Join > GeomAbs_Arc,
381 "Only GeomAbs_Arc is implemented");
383 myIsDone = Standard_False;
384 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
385 mySpine = TopoDS::Face(aLocalShape);
386 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
388 myIsOpenResult = IsOpenResult;
394 //------------------------------------------------------------------
395 // cut the spine for bissectors.
396 //------------------------------------------------------------------
397 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
398 static BRepMAT2d_Explorer Exp;
400 Exp.Perform(mySpine);
402 // TopoDS_Face anOldSpine = mySpine;
404 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
407 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
409 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
410 Standard_Boolean Done;
411 if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return;
414 //-----------------------------------------------------
415 // Calculate the map of bissectors to the left.
416 // and Links Topology -> base elements of the map.
417 //-----------------------------------------------------
419 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
420 // static BRepMAT2d_Explorer Exp;
421 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
422 Exp.Perform(myWorkSpine);
423 myBilo.Compute(Exp,1,MAT_Left,myIsOpenResult);
424 myLink.Perform(Exp,myBilo);
428 //=======================================================================
431 //=======================================================================
433 Standard_Boolean BRepFill_OffsetWire::IsDone() const
439 //=======================================================================
442 //=======================================================================
444 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
450 //=======================================================================
453 //=======================================================================
455 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
461 //=======================================================================
462 //function : GeneratedShapes
464 //=======================================================================
466 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
467 (const TopoDS_Shape& SpineShape)
470 if (!myMapSpine.IsEmpty()) {
471 // myMapSpine can be empty if passed by PerformWithBilo.
472 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
473 for (; it.More(); it.Next()) {
474 if (myMap.Contains(it.Key())) {
475 if (!myMap.Contains(it.Value())) {
476 TopTools_ListOfShape L;
477 myMap.Add(it.Value(),L);
479 if ( !it.Value().IsSame(it.Key())) {
480 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
481 //myMap.UnBind(it.Key());
482 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
483 TopTools_ListOfShape LastList;
484 LastList.Append(myMap(myMap.Extent()));
486 if (myMap.FindIndex(it.Key()) != 0)
487 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
490 if (myMap.Contains(it.Key().Reversed())) {
491 if (!myMap.Contains(it.Value().Reversed())) {
492 TopTools_ListOfShape L;
493 myMap.Add(it.Value().Reversed(),L);
495 if ( !it.Value().IsSame(it.Key())) {
496 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
497 //myMap.UnBind(it.Key().Reversed());
498 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
499 TopTools_ListOfShape LastList;
500 LastList.Append(myMap(myMap.Extent()));
502 if (myMap.FindIndex(it.Key().Reversed()) != 0)
503 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
508 myCallGen = Standard_True;
511 if (myMap.Contains(SpineShape)) {
512 return myMap.FindFromKey(SpineShape);
515 static TopTools_ListOfShape Empty;
521 //=======================================================================
522 //function : JoinType
524 //=======================================================================
526 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
531 //=======================================================================
534 //=======================================================================
536 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
537 const Standard_Real Alt)
539 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
543 myCallGen = Standard_False;
544 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
546 TopoDS_Face oldWorkSpain = myWorkSpine;
548 TopTools_ListOfShape BadEdges;
549 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
551 if(!BadEdges.IsEmpty())
553 // Modification of myWorkSpine;
554 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
555 BRepTools_Substitution aSubst;
556 TopTools_ListIteratorOfListOfShape it(BadEdges);
557 TopTools_ListOfShape aL;
558 Standard_Real aDefl = .01 * Abs(Offset);
559 TColStd_SequenceOfReal Parameters;
560 TColgp_SequenceOfPnt Points;
562 for(; it.More(); it.Next()) {
566 const TopoDS_Shape& anE = it.Value();
568 TopoDS_Vertex Vf, Vl;
569 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
572 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
573 GeomAdaptor_Curve AC(G3d,f,l);
575 PerformCurve(Parameters, Points, AC, aDefl, f,
576 l, Precision::Confusion(), 2);
578 Standard_Integer NPnts = Points.Length();
581 //cout << NPnts << " points " << endl;
582 TopoDS_Vertex FV = Vf;
586 for(np = 2; np < NPnts; np++) {
587 gp_Pnt LP = Points(np);
588 LV = BRepLib_MakeVertex(LP);
589 newE = BRepLib_MakeEdge(FV, LV);
594 newE = BRepLib_MakeEdge(FV, LV);
599 //cout << " 2 points " << endl;
600 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
604 if (myMapSpine.IsBound( anE ))
606 TopTools_ListIteratorOfListOfShape newit( aL );
607 for (; newit.More(); newit.Next())
609 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
610 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
611 TopoDS_Vertex NewV1, NewV2;
612 EdgeVertices( NewEdge, NewV1, NewV2 );
613 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
614 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
616 myMapSpine.UnBind( anE );
619 aSubst.Substitute(anE, aL);
622 TopTools_DataMapOfShapeListOfShape wwmap;
623 TopoDS_Iterator itws( myWorkSpine );
624 for (; itws.More(); itws.Next())
626 TopoDS_Shape aWire = itws.Value();
627 aSubst.Build( aWire );
628 if (aSubst.IsCopied(aWire))
630 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
631 NewWire.Closed( aWire.Closed() );
632 TopTools_ListOfShape Lw;
633 Lw.Append( NewWire );
634 wwmap.Bind( aWire, Lw );
638 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
639 for (; itmap.More(); itmap.Next())
640 aSubst.Substitute( itmap.Key(), itmap.Value() );
642 aSubst.Build(myWorkSpine);
644 if(aSubst.IsCopied(myWorkSpine)) {
645 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
647 BRepMAT2d_Explorer newExp;
648 newExp.Perform(myWorkSpine);
649 BRepMAT2d_BisectingLocus newBilo;
650 BRepMAT2d_LinkTopoBilo newLink;
651 newBilo.Compute(newExp,1,MAT_Left,myIsOpenResult);
653 if(!newBilo.IsDone())
656 myIsDone = Standard_False;
660 newLink.Perform(newExp,newBilo);
661 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
662 myWorkSpine = oldWorkSpain;
665 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
670 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
673 catch (...)//Every exception was caught.
676 myIsDone = Standard_False;
677 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
678 Standard_Failure::Caught()->Print(cout);
684 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
685 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
688 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
690 for (; anExp.More(); anExp.Next()) {
691 const TopoDS_Shape &aWire = anExp.Current();
693 if (!aWire.Closed()) {
695 myIsDone = Standard_False;
696 Standard_ConstructionError::Raise("Offset wire is not closed.");
700 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
703 //=======================================================================
706 //=======================================================================
708 void Compute (const TopoDS_Face& Spine,
709 TopoDS_Shape& aShape,
710 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
711 const Standard_Real Alt)
714 B.MakeCompound(TopoDS::Compound(aShape));
715 Standard_Real ALT = Alt;
716 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
718 T.SetTranslation(gp_Vec(0.,0.,ALT));
719 TopLoc_Location L(T);
721 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
722 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
723 TopoDS_Shape aLocalShape = CurW.Moved(L);
724 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
725 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
728 TopoDS_Iterator it1( CurW);
729 TopoDS_Iterator it2( NewW);
730 for ( ; it1.More(); it1.Next(), it2.Next()) {
731 TopTools_ListOfShape List;
732 List.Append(it2.Value());
733 Map.Add(it1.Value(), List);
738 //=======================================================================
739 //function : PerformWithBiLo
741 //=======================================================================
743 void BRepFill_OffsetWire::PerformWithBiLo
744 (const TopoDS_Face& Spine,
745 const Standard_Real Offset,
746 const BRepMAT2d_BisectingLocus& Locus,
747 BRepMAT2d_LinkTopoBilo& Link,
748 const GeomAbs_JoinType Join,
749 const Standard_Real Alt)
751 Standard_NotImplemented_Raise_if (Join > GeomAbs_Arc,
752 "Only GeomAbs_Arc is implemented");
754 myIsDone = Standard_False;
755 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
756 myWorkSpine = TopoDS::Face(aLocalShape);
757 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
763 if (mySpine.IsNull()) {
764 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
765 mySpine = TopoDS::Face(aLocalShape);
766 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
770 if ( Abs(myOffset) < Precision::Confusion()) {
771 Compute(mySpine,myShape,myMap,Alt);
772 myIsDone = Standard_True;
776 //********************************
777 // Calculate for a non null offset
778 //********************************
779 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone))
782 BRep_Builder myBuilder;
783 myBuilder.MakeCompound(TopoDS::Compound(myShape));
785 //---------------------------------------------------------------------
786 // MapNodeVertex : associate to each node of the map (key1) and to
787 // each element of the profile (key2) a vertex (item).
788 // MapBis : all edges or vertices (item) generated by
789 // a bisectrice on a face or an edge (key) of revolution tubes.
790 // MapVerPar : Map of parameters of vertices on parallel edges
791 // the list contained in MapVerPar (E) corresponds to
792 // parameters on E of vertices contained in MapBis(E);
793 //---------------------------------------------------------------------
796 BRepFill_DataMapOfNodeShape MapNodeVertex;
797 TopTools_DataMapOfShapeSequenceOfShape MapBis;
798 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
800 TopTools_DataMapOfShapeShape EmptyMap;
801 TopTools_SequenceOfShape EmptySeq;
802 TopTools_ListOfShape EmptyList;
803 TColStd_SequenceOfReal EmptySeqOfReal;
805 Standard_Real ALT = Alt;
806 Handle(Geom_Plane) RefPlane =
807 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
808 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
809 RefPlane = Handle(Geom_Plane)::DownCast
810 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
812 //---------------------------------------------------------------
813 // Construction of Circles and OffsetCurves
814 //---------------------------------------------------------------
816 TopoDS_Vertex Ends [2];
820 TopoDS_Iterator iter(mySpine);
821 theWire = TopoDS::Wire(iter.Value());
822 TopExp::Vertices(theWire, Ends[0], Ends[1]);
825 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
826 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
827 TopoDS_Shape& PE = PEE ;
828 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
829 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
830 if (SE.ShapeType() == TopAbs_VERTEX) {
831 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
832 myWorkSpine,myOffset,myMap,RefPlane);
835 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
836 myIsOpenResult, Ends);
845 cout << " End Construction of geometric primitives "<<endl;
850 //---------------------------------------------------
851 // Construction of offset vertices.
852 //---------------------------------------------------
853 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
854 Handle(MAT_Arc) CurrentArc;
855 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
856 Handle(Geom_Curve) CBis;
857 Standard_Boolean Reverse;
858 TopoDS_Edge CurrentEdge;
862 Standard_Integer j, k;
864 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
866 CurrentArc = Locus.Graph()->Arc(i);
867 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
872 sprintf(name,"BISSEC_%d",NbBISSEC++);
873 DrawTrSurf::Set(name,Bisec.Value());
877 //-------------------------------------------------------------------
878 // Return elements of the spine corresponding to separate basicElts.
879 //-------------------------------------------------------------------
880 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
881 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
883 TopTools_SequenceOfShape Vertices;
884 TColgp_SequenceOfPnt Params;
886 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
887 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
889 //-----------------------------------------------------------
890 // Return parallel edges on each face.
891 // If no offset generated => move to the next bissectrice.
892 //--------------------------------------------------------------
893 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
894 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
895 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
899 //-----------------------------------------------------------
900 // Construction of vertices corresponding to the node of the map.
901 // if they are on the offset.
902 //-----------------------------------------------------------
904 Handle(MAT_Node) Node1, Node2;
907 Node1 = CurrentArc->SecondNode();
908 Node2 = CurrentArc->FirstNode();
911 Node1 = CurrentArc->FirstNode();
912 Node2 = CurrentArc->SecondNode();
915 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
917 if (!Node1->Infinite()) {
918 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
919 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
920 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
921 // MapNodeVertex,VS);
923 if (!Node2->Infinite()) {
924 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
925 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
926 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
927 // MapNodeVertex,VE);
930 //---------------------------------------------
931 // Construction of geometries.
932 //---------------------------------------------
933 BRepFill_TrimEdgeTool Trim (Bisec,
934 Locus.GeomElt(CurrentArc->FirstElement()),
935 Locus.GeomElt(CurrentArc->SecondElement()),
938 //-----------------------------------------------------------
939 // Construction of vertices on edges parallel to the spine.
940 //-----------------------------------------------------------
942 Trim.IntersectWith(E [0], E [1], Params);
944 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
946 myBuilder.MakeVertex (VC);
947 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
948 gp_Pnt PVC(P2.X(),P2.Y(),0.);
950 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
954 Standard_Boolean Start = 1;
955 Trim.AddOrConfuse(Start, E[0], E[1], Params);
956 if (Params.Length() == Vertices.Length())
957 Vertices.SetValue(1,VS);
960 // the point was not found by IntersectWith
961 Vertices.Prepend(VS);
964 Standard_Boolean Start = 0;
965 Trim.AddOrConfuse(Start, E[0], E[1], Params);
966 if (Params.Length() == Vertices.Length())
967 Vertices.SetValue(Params.Length(),VE);
970 // the point was not found by IntersectWith
974 //------------------------------------------------------------
976 // Detromp allows to remove vertices on the offset
977 // corresponding to tangency zones
978 // Detromp ranks the vertices that limit
979 // the parts of the bissectrices located between the spine and the
981 //------------------------------------------------------------
982 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
983 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
986 UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params,
987 Bisec, StartOnEdge, EndOnEdge, Trim);
988 //----------------------------------------------
989 // Storage of vertices on parallel edges.
990 // fill MapBis and MapVerPar.
991 //----------------------------------------------
992 if (!Vertices.IsEmpty()) {
993 for (k = 0; k <= 1; k++) {
994 if (!MapBis.IsBound(E[k])) {
995 MapBis .Bind(E[k],EmptySeq);
996 MapVerPar.Bind(E[k],EmptySeqOfReal);
998 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
999 MapBis (E[k]).Append(Vertices.Value(ii));
1000 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
1001 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
1006 //------------------------------------------------------------
1007 // FOR COMPLETE CIRCLES. the parallel line can be contained
1008 // in the zone without intersection with the border
1010 // if myoffset is < distance of nodes the parallel can be valid.
1011 //-------------------------------------------------------------
1012 for (k = 0; k <= 1; k++) {
1013 if (!MapBis.IsBound(E[k])) {
1014 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
1015 MapBis .Bind(E[k],EmptySeq);
1016 MapVerPar.Bind(E[k],EmptySeqOfReal);
1025 cout << " End Construction of vertices on offsets"<<endl;
1029 //----------------------------------
1030 // Construction of parallel edges.
1031 //----------------------------------
1032 TopTools_IndexedDataMapOfShapeShape MapVV;
1034 TopoDS_Shape CurrentSpine;
1036 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
1038 for (j = 1; j <= myMap.Extent(); j++) {
1039 CurrentSpine = myMap.FindKey(j);
1040 CurrentEdge = TopoDS::Edge(myMap(j).First());
1043 if (MapBis.IsBound(CurrentEdge)) {
1044 TopTools_SequenceOfShape S;
1045 if (!MapBis(CurrentEdge).IsEmpty()) {
1046 Standard_Integer IndOfE = 0;
1051 else if (j == myMap.Extent())
1054 TrimEdge (CurrentEdge,
1055 Detromp (CurrentSpine),
1056 MapBis (CurrentEdge) ,
1057 MapVerPar(CurrentEdge) ,
1059 for ( k = 1; k <= S.Length(); k++) {
1060 myMap(j).Append(S.Value(k));
1067 myMap(j).Append(CurrentEdge);
1072 Standard_Integer ind;
1073 for (ind = 1; ind <= MapVV.Extent(); ind++)
1075 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1076 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1077 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1078 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1079 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1080 TopTools_ListOfShape LV;
1081 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1082 BRepTools_Substitution aSubst;
1083 aSubst.Substitute( OldV, LV );
1084 for (j = 1; j <= myMap.Extent(); j++)
1086 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1087 for (; itl.More(); itl.Next())
1089 aSubst.Build(itl.Value());
1090 if (aSubst.IsCopied(itl.Value()))
1092 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1093 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1094 itl.Value() = listSh.First();
1095 itl.Value().Orientation(SaveOr);
1101 //----------------------------------
1102 // Construction of offset wires.
1103 //----------------------------------
1106 // Update vertices ( Constructed in the plane Z = 0) !!!
1107 TopTools_MapOfShape MapVertex;
1108 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1109 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1110 if ( MapVertex.Add(V)) {
1111 gp_Pnt P = BRep_Tool::Pnt(V);
1112 P = RefPlane->Value(P.X(),P.Y());
1113 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1117 // Construction of curves 3d.
1118 BRepLib::BuildCurves3d(myShape);
1120 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1121 for (; Explo.More(); Explo.Next())
1123 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1124 TopoDS_Vertex V1, V2;
1125 TopExp::Vertices( E, V1, V2 );
1126 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1127 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1129 TopLoc_Location loc;
1131 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1132 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1133 theCurve->Transform( loc.Transformation() );
1134 gp_Pnt f3d = theCurve->Value( f );
1135 gp_Pnt l3d = theCurve->Value( l );
1137 Standard_Real dist1, dist2;
1138 dist1 = f3d.Distance( TV1->Pnt() );
1139 dist2 = l3d.Distance( TV2->Pnt() );
1140 if (! MapVertex.Contains( V1 ))
1143 MapVertex.Add( V1 );
1146 TV1->UpdateTolerance( 1.5*dist1 );
1147 if (! MapVertex.Contains( V2 ))
1150 MapVertex.Add( V2 );
1153 TV2->UpdateTolerance( 1.5*dist2 );
1158 myIsDone = Standard_True;
1162 //=======================================================================
1163 //function : Generated
1165 //=======================================================================
1167 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1168 BRepFill_OffsetWire::Generated()
1174 //=======================================================================
1175 //function : PrepareSpine
1177 //=======================================================================
1179 void BRepFill_OffsetWire::PrepareSpine()
1182 TopTools_ListOfShape Cuts;
1183 TopTools_ListIteratorOfListOfShape IteCuts;
1184 TopoDS_Vertex V1,V2;
1186 myWorkSpine.Nullify();
1190 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1191 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1192 B.MakeFace(myWorkSpine,S,L,TolF);
1194 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1199 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1200 Standard_Integer ForcedCut = 0;
1201 Standard_Integer nbResEdges = -1;
1202 TopTools_IndexedMapOfShape EdgeMap;
1204 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1205 Standard_Integer nbEdges = EdgeMap.Extent();
1207 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
1209 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1211 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1213 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1214 EdgeVertices(E,V1,V2);
1215 myMapSpine.Bind(V1,V1);
1216 myMapSpine.Bind(V2,V2);
1220 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1221 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1222 if (nbEdges == 2 && nbResEdges == 0)
1224 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1225 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1227 if (Cuts.IsEmpty()) {
1229 myMapSpine.Bind(E,E);
1232 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1233 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1234 NE.Orientation(E.Orientation());
1236 myMapSpine.Bind(NE,E);
1237 EdgeVertices(NE,V1,V2);
1238 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1239 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1243 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1247 TopExp::Vertices(NW, aV1, aV2);
1249 NW.Closed(aV1.IsSame(aV2));
1250 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1251 B.Add(myWorkSpine, NW);
1256 DBRep::Set("WS",myWorkSpine);
1262 //=======================================================================
1263 //function : MakeWires
1265 //=======================================================================
1267 void BRepFill_OffsetWire::MakeWires()
1269 //--------------------------------------------------------
1270 // creation of a single list of created parallel edges.
1271 //--------------------------------------------------------
1272 TopTools_SequenceOfShape TheEdges;
1273 TopTools_ListOfShape TheWires;
1274 TopTools_ListIteratorOfListOfShape itl;
1275 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1276 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1277 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1278 TopoDS_Vertex V1,V2,VF,CV;
1281 for (i = 1; i <= myMap.Extent(); i++) {
1282 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1283 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1284 TopExp::Vertices (E,V1,V2);
1285 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1286 continue; //remove small closed edges
1287 if (!MVE.Contains(V1)) {
1288 TopTools_ListOfShape empty;
1291 MVE.ChangeFromKey(V1).Append(E);
1292 if (!MVE.Contains(V2)) {
1293 TopTools_ListOfShape empty;
1296 MVE.ChangeFromKey(V2).Append(E);
1300 //--------------------------------------
1301 // Creation of parallel wires.
1302 //--------------------------------------
1305 // Standard_Integer NbEdges;
1306 // Standard_Boolean NewWire = Standard_True;
1307 // Standard_Boolean AddEdge = Standard_False;
1310 Standard_Boolean End;
1313 while (!MVE.IsEmpty()) {
1316 //MVEit.Initialize(MVE);
1317 for (i = 1; i <= MVE.Extent(); i++)
1318 if(MVE(i).Extent() == 1)
1321 //if(!MVEit.More()) MVEit.Initialize(MVE);
1322 if (i > MVE.Extent())
1325 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1326 CE = TopoDS::Edge(MVE(i).First());
1327 End = Standard_False;
1328 MVE.ChangeFromKey(CV).RemoveFirst();
1330 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1331 Standard_Boolean isClosed = Standard_False;
1332 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1335 //-------------------------------
1336 // Construction of a wire.
1337 //-------------------------------
1338 TopExp::Vertices(CE,V1,V2);
1339 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1343 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1344 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1345 isClosed = VF.IsSame(CV);
1346 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1347 End = Standard_True;
1349 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1350 TopTools_ListOfShape LastList;
1351 LastList.Append(MVE(MVE.Extent()));
1353 if (MVE.FindIndex(VF) != 0)
1354 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1358 if (MVE.FindFromKey(CV).Extent() > 2) {
1359 //cout <<"vertex on more that 2 edges in a face."<<endl;
1361 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1362 if (itl.Value().IsSame(CE)) {
1363 MVE.ChangeFromKey(CV).Remove(itl);
1367 if (!MVE.FindFromKey(CV).IsEmpty()) {
1368 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1369 MVE.ChangeFromKey(CV).RemoveFirst();
1371 if (MVE.FindFromKey(CV).IsEmpty())
1374 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1375 TopTools_ListOfShape LastList;
1376 LastList.Append(MVE(MVE.Extent()));
1378 if (MVE.FindIndex(CV) != 0)
1379 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1383 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1384 // NW.Closed(Standard_True);
1385 NW.Closed(isClosed);
1386 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1387 TheWires.Append(NW);
1391 // -- if only one wire : myShape is a Wire
1392 // -- if several wires : myShape is a Compound.
1393 if ( TheWires.Extent() == 1) {
1394 myShape = TheWires.First();
1399 TopTools_ListIteratorOfListOfShape it(TheWires);
1400 for ( ; it.More(); it.Next()) {
1401 B.Add(R, it.Value());
1408 //=======================================================================
1409 //function : FixHoles
1411 //=======================================================================
1413 void BRepFill_OffsetWire::FixHoles()
1415 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1417 Standard_Real MaxTol = 0.;
1421 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1422 for (; Explo.More(); Explo.Next())
1424 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1425 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1431 Explo.Init( myShape, TopAbs_WIRE );
1432 for (; Explo.More(); Explo.Next())
1434 TopoDS_Shape aWire = Explo.Current();
1435 // Remove duplicated edges
1436 TopTools_DataMapOfShapeListOfShape EEmap;
1437 TopoDS_Iterator it( aWire );
1438 for (; it.More(); it.Next())
1440 const TopoDS_Shape& anEdge = it.Value();
1441 if (! EEmap.IsBound( anEdge ))
1443 TopTools_ListOfShape LE;
1444 EEmap.Bind( anEdge, LE );
1447 EEmap(anEdge).Append( anEdge );
1449 aWire.Free( Standard_True );
1450 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1451 for (; mapit.More(); mapit.Next())
1453 const TopTools_ListOfShape& LE = mapit.Value();
1454 TopTools_ListIteratorOfListOfShape itl( LE );
1455 for (; itl.More(); itl.Next())
1456 BB.Remove( aWire, itl.Value() );
1460 ClosedWires.Append( aWire );
1462 UnclosedWires.Append( aWire );
1465 while (!UnclosedWires.IsEmpty())
1467 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1468 TopoDS_Vertex Vf, Vl;
1469 TopExp::Vertices( Base, Vf, Vl );
1470 if(Vf.IsNull() || Vl.IsNull())
1471 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1473 Pf = BRep_Tool::Pnt(Vf);
1474 Pl = BRep_Tool::Pnt(Vl);
1475 Standard_Real DistF = RealLast(), DistL = RealLast();
1476 Standard_Integer IndexF = 1, IndexL = 1;
1477 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1478 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1480 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1481 TopoDS_Vertex V1, V2;
1482 TopExp::Vertices( aWire, V1, V2 );
1484 if(V1.IsNull() || V2.IsNull())
1485 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1488 P1 = BRep_Tool::Pnt(V1);
1489 P2 = BRep_Tool::Pnt(V2);
1490 Standard_Real dist = Pf.Distance( P1 );
1495 IsFirstF = Standard_True;
1497 dist = Pf.Distance( P2 );
1502 IsFirstF = Standard_False;
1504 dist = Pl.Distance( P1 );
1509 IsFirstL = Standard_True;
1511 dist = Pl.Distance( P2 );
1516 IsFirstL = Standard_False;
1519 TopoDS_Wire theWire;
1520 TopoDS_Edge theEdge;
1521 TopoDS_Vertex theVertex;
1522 Standard_Real CommonTol;
1523 Standard_Boolean TryToClose = Standard_True;
1524 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1536 TryToClose = Standard_False;
1538 if (DistF <= MaxTol)
1540 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1541 TopoDS_Vertex V1, V2;
1542 TopExp::Vertices( theWire, V1, V2 );
1543 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1544 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1545 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1546 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1547 TopoDS_Iterator it( theWire );
1548 for (; it.More(); it.Next())
1550 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1551 if (IsFirstF) anEdge.Reverse();
1552 if (!anEdge.IsSame( theEdge ))
1553 BB.Add( Base, anEdge );
1555 theVertex = (IsFirstF)? V1 : V2;
1556 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1557 if (DistF <= CommonTol)
1559 theEdge.Free( Standard_True );
1560 Vf.Orientation( theVertex.Orientation() );
1561 BB.Remove( theEdge, theVertex );
1562 BB.Add( theEdge, Vf );
1563 BB.UpdateVertex( Vf, CommonTol );
1564 if (IsFirstF) theEdge.Reverse();
1565 BB.Add( Base, theEdge );
1569 if (IsFirstF) theEdge.Reverse();
1570 BB.Add( Base, theEdge );
1571 // Creating new edge from theVertex to Vf
1572 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1573 BB.Add( Base, NewEdge );
1576 if (DistL <= MaxTol && IndexL != IndexF)
1578 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1579 TopoDS_Vertex V1, V2;
1580 TopExp::Vertices( theWire, V1, V2 );
1581 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1582 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1583 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1584 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1585 TopoDS_Iterator it( theWire );
1586 for (; it.More(); it.Next())
1588 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1589 if (!IsFirstL) anEdge.Reverse();
1590 if (!anEdge.IsSame( theEdge ))
1591 BB.Add( Base, anEdge );
1593 theVertex = (IsFirstL)? V1 : V2;
1594 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1595 if (DistL <= CommonTol)
1597 theEdge.Free( Standard_True );
1598 Vl.Orientation( theVertex.Orientation() );
1599 BB.Remove( theEdge, theVertex );
1600 BB.Add( theEdge, Vl );
1601 BB.UpdateVertex( Vl, CommonTol );
1602 if (!IsFirstL) theEdge.Reverse();
1603 BB.Add( Base, theEdge );
1607 if (!IsFirstL) theEdge.Reverse();
1608 BB.Add( Base, theEdge );
1609 // Creating new edge from Vl to theVertex
1610 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1611 BB.Add( Base, NewEdge );
1614 // Check if it is possible to close resulting wire
1617 TopExp::Vertices( Base, Vf, Vl );
1618 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1619 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1620 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1621 TopoDS_Edge Efirst, Elast;
1622 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1623 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1624 Pf = BRep_Tool::Pnt(Vf);
1625 Pl = BRep_Tool::Pnt(Vl);
1626 Standard_Real Dist = Pf.Distance(Pl);
1627 if (Dist <= CommonTol)
1629 Elast.Free( Standard_True );
1630 Vf.Orientation( Vl.Orientation() );
1631 BB.Remove( Elast, Vl );
1632 BB.Add( Elast, Vf );
1633 BB.UpdateVertex( Vf, CommonTol );
1634 Base.Closed( Standard_True );
1636 else if (Dist <= MaxTol)
1638 // Creating new edge from Vl to Vf
1639 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1640 BB.Add( Base, NewEdge );
1641 Base.Closed( Standard_True );
1644 // Updating sequences ClosedWires and UnclosedWires
1645 if (DistF <= MaxTol)
1646 UnclosedWires.Remove( IndexF );
1647 if (DistL <= MaxTol && IndexL != IndexF)
1649 if (DistF <= MaxTol && IndexL > IndexF)
1651 UnclosedWires.Remove( IndexL );
1655 ClosedWires.Append( Base );
1656 UnclosedWires.Remove( 1 );
1658 else if (DistF > MaxTol && DistL > MaxTol)
1660 IsolatedWires.Append( Base );
1661 UnclosedWires.Remove( 1 );
1666 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1668 if (!ClosedWires.IsEmpty())
1669 myShape = ClosedWires.First();
1671 myShape = IsolatedWires.First();
1676 BB.MakeCompound( R );
1677 for (i = 1; i <= ClosedWires.Length(); i++)
1678 BB.Add( R, ClosedWires(i) );
1679 for (i = 1; i <= IsolatedWires.Length(); i++)
1680 BB.Add( R, IsolatedWires(i) );
1685 //=======================================================================
1686 //function : CutEdge
1687 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1688 // So, closed circles are cut in two.
1689 // If <Cuts> is empty, the edge is not modified.
1690 // The first and the last vertex of the initial edge
1691 // belong to the first and the last parts respectively.
1692 //=======================================================================
1693 Standard_Integer CutEdge (const TopoDS_Edge& E,
1694 const TopoDS_Face& F,
1695 Standard_Integer ForceCut,
1696 TopTools_ListOfShape& Cuts)
1699 MAT2d_CutCurve Cuter;
1700 TColGeom2d_SequenceOfCurve theCurves;
1702 Handle(Geom2d_Curve) C2d;
1703 Handle(Geom2d_TrimmedCurve) CT2d;
1704 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1705 Standard_Real aTol = BRep_Tool::Tolerance(E);
1706 Handle(Geom_Curve) aC;
1707 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1709 TopoDS_Vertex V1,V2,VF,VL;
1710 TopExp::Vertices (E,V1,V2);
1713 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1714 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1715 aC = BRep_Tool::Curve(E,f,l);
1716 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1717 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1718 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1720 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1721 ( Abs(f-l) >= M_PI) ) {
1725 //-------------------------
1727 //-------------------------
1728 Cuter.Perform(CT2d);
1730 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1731 if (ForceCut == 0) {
1732 if (Cuter.UnModified()) {
1733 //-----------------------------
1734 // edge not modified => return.
1735 //-----------------------------
1738 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1739 theCurves.Append(Cuter.Value(k));
1741 } else if (ForceCut == 1) {
1742 if (Cuter.UnModified()) {
1743 CutCurve (CT2d, 2, theCurves);
1745 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1746 theCurves.Append(Cuter.Value(k));
1748 } else if (ForceCut == 2) {
1749 if (Cuter.UnModified()) {
1750 CutCurve (CT2d, 3, theCurves);
1752 if (Cuter.NbCurves() == 2) {
1753 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1755 if (CC->LastParameter() > (l+f)/2.) {
1756 CutCurve (CC, 2, theCurves);
1757 theCurves.Append(Cuter.Value(2));
1759 theCurves.Append(CC);
1760 CutCurve (Cuter.Value(2), 2, theCurves);
1763 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1764 theCurves.Append(Cuter.Value(k));
1768 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1770 //--------------------------------------
1771 // Creation of cut edges.
1772 //--------------------------------------
1775 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1777 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1779 if (k == theCurves.Length()) {VL = V2;}
1781 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1782 gp_Pnt P = aC->Value(CC->LastParameter());
1784 VL = BRepLib_MakeVertex(P);
1785 B.UpdateVertex(VL, aTol);
1786 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1788 TopoDS_Shape aLocalShape = E.EmptyCopied();
1789 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1790 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1791 NE.Orientation(TopAbs_FORWARD);
1792 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1793 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1794 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1795 Cuts.Append(NE.Oriented(E.Orientation()));
1799 return theCurves.Length();
1802 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1803 //=======================================================================
1804 //function : CutCurve
1806 //=======================================================================
1808 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1809 const Standard_Integer nbParts,
1810 TColGeom2d_SequenceOfCurve& theCurves)
1812 Handle(Geom2d_TrimmedCurve) TrimC;
1813 Standard_Real UF,UL,UC;
1816 Standard_Real PTol = Precision::PConfusion()*10;
1817 Standard_Real Tol = Precision::Confusion()*10;
1818 Standard_Boolean YaCut = Standard_False;
1820 UF = C->FirstParameter();
1821 UL = C->LastParameter ();
1825 Step = (UL - UF)/nbParts;
1827 for (Standard_Integer i = 1; i < nbParts; i++) {
1832 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1833 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1836 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1837 theCurves.Append(TrimC);
1840 YaCut = Standard_True;
1844 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1845 theCurves.Append(TrimC);
1847 theCurves.Append(C);
1849 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1851 //=======================================================================
1852 //function : MakeCircle
1854 //=======================================================================
1856 void MakeCircle (const TopoDS_Edge& E,
1857 const TopoDS_Vertex& V,
1858 const TopoDS_Face& F,
1859 const Standard_Real Offset,
1860 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1861 const Handle(Geom_Plane)& RefPlane)
1863 // evaluate the Axis of the Circle.
1865 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1869 if (E.Orientation() == TopAbs_FORWARD) {
1873 else GC->D1(f,P,DX);
1875 gp_Ax2d Axis(P,gp_Dir2d(DX));
1876 Handle(Geom2d_Circle) Circ
1877 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1879 // Bind the edges in my Map.
1880 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1881 TopTools_ListOfShape LL;
1887 if ( AffichGeom && !OE.IsNull()) {
1889 sprintf(name,"OFFSET_%d",++NbOFFSET);
1890 DBRep::Set(name,OE);
1895 //=======================================================================
1896 //function : MakeOffset
1898 //=======================================================================
1900 void MakeOffset (const TopoDS_Edge& E,
1901 const TopoDS_Face& F,
1902 const Standard_Real Offset,
1903 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1904 const Handle(Geom_Plane)& RefPlane,
1905 const Standard_Boolean IsOpenResult,
1906 const TopoDS_Vertex * Ends)
1909 Standard_Real anOffset = Offset;
1911 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1913 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1914 Handle(Geom2d_Curve) G2dOC;
1916 Standard_Boolean ToExtendFirstPar = Standard_True;
1917 Standard_Boolean ToExtendLastPar = Standard_True;
1920 TopoDS_Vertex V1, V2;
1921 TopExp::Vertices(E, V1, V2);
1922 if (V1.IsSame(Ends[0]) ||
1924 ToExtendFirstPar = Standard_False;
1925 if (V2.IsSame(Ends[0]) ||
1927 ToExtendLastPar = Standard_False;
1930 Geom2dAdaptor_Curve AC(G2d,f,l);
1931 if ( AC.GetType() == GeomAbs_Circle) {
1932 // if the offset is greater otr equal to the radius and the side of the
1933 // concavity of the circle => edge null.
1934 gp_Circ2d C1(AC.Circle());
1935 gp_Ax22d axes( C1.Axis());
1936 gp_Dir2d Xd = axes.XDirection();
1937 gp_Dir2d Yd = axes.YDirection();
1938 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1939 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1941 if (anOffset*Signe < AC.Circle().Radius()) {
1943 Handle(Geom2dAdaptor_HCurve) AHC =
1944 new Geom2dAdaptor_HCurve(G2d);
1945 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1946 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1948 Standard_Real Delta = 2*M_PI - l + f;
1949 if (ToExtendFirstPar)
1951 if (ToExtendLastPar)
1954 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1957 else if (AC.GetType() == GeomAbs_Line) {
1958 Handle(Geom2dAdaptor_HCurve) AHC =
1959 new Geom2dAdaptor_HCurve(G2d);
1960 Adaptor3d_OffsetCurve Off(AHC,anOffset);
1961 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
1962 Standard_Real Delta = (l - f);
1963 if (ToExtendFirstPar)
1965 if (ToExtendLastPar)
1967 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1971 anOffset = -anOffset;
1972 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
1973 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
1977 // Bind the edges in my Map.
1978 if (!G2dOC.IsNull()) {
1979 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
1980 OE.Orientation(E.Orientation());
1981 TopTools_ListOfShape LL;
1986 if (AffichGeom && !OE.IsNull()) {
1988 sprintf(name,"OFFSET_%d",++NbOFFSET);
1989 DBRep::Set(name,OE);
1990 Standard_Real ii = 0;
1997 //=======================================================================
1998 //function : UpdateDetromp
1999 //purpose : For each interval on bissectrice defined by parameters
2000 // test if the medium point is at a distance > offset
2001 // in this case vertices corresponding to the extremities of the interval
2002 // are ranked in the proofing.
2003 // => If the same vertex appears in the proofing, the
2004 // border of the zone of proximity is tangent to the offset .
2005 //=======================================================================
2007 void UpdateDetromp (TopTools_ListOfShape& Detromp1,
2008 TopTools_ListOfShape& Detromp2,
2009 const TopTools_SequenceOfShape& Vertices,
2010 const TColgp_SequenceOfPnt& Params,
2011 const Bisector_Bisec& Bisec,
2012 const Standard_Boolean SOnE,
2013 const Standard_Boolean EOnE,
2014 const BRepFill_TrimEdgeTool& Trim)
2016 Standard_Integer ii = 1;
2017 Standard_Real U1,U2;
2018 TopoDS_Vertex V1,V2;
2020 Handle(Geom2d_Curve) Bis = Bisec.Value();
2022 U1 = Bis->FirstParameter();
2025 // the first point of the bissectrice is on the offset
2026 V1 = TopoDS::Vertex(Vertices.Value(ii));
2030 while (ii <= Vertices.Length()) {
2031 U2 = Params.Value(ii).X();
2032 V2 = TopoDS::Vertex(Vertices.Value(ii));
2034 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
2035 if (!Trim.IsInside(P)) {
2037 Detromp1.Append(V1);
2038 Detromp2.Append(V1);
2040 Detromp1.Append(V2);
2041 Detromp2.Append(V2);
2048 // test medium point between the last parameter and the end of the bissectrice.
2049 U2 = Bis->LastParameter();
2051 if (!Precision::IsInfinite(U2)) {
2052 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
2053 if (!Trim.IsInside(P)) {
2055 Detromp1.Append(V1);
2056 Detromp2.Append(V1);
2062 Detromp1.Append(V1);
2063 Detromp2.Append(V1);
2069 //=======================================================================
2070 //function : VertexFromNode
2072 //=======================================================================
2074 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
2075 const Standard_Real Offset,
2077 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2080 Standard_Boolean Status;
2081 Standard_Real Tol = Precision::Confusion();
2084 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2085 //------------------------------------------------
2086 // the Node gives a vertex on the offset
2087 //------------------------------------------------
2088 if (MapNodeVertex.IsBound(aNode)) {
2089 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2092 gp_Pnt P(PN.X(),PN.Y(),0.);
2094 B.UpdateVertex(VN,P, Precision::Confusion());
2095 MapNodeVertex.Bind(aNode,VN);
2097 Status = Standard_True;
2099 else Status = Standard_False;
2105 //=======================================================================
2106 //function : StoreInMap
2108 //=======================================================================
2110 void StoreInMap (const TopoDS_Shape& V1,
2111 const TopoDS_Shape& V2,
2112 TopTools_IndexedDataMapOfShapeShape& MapVV)
2114 TopoDS_Shape OldV = V1, NewV = V2;
2117 if (MapVV.Contains(V2))
2118 NewV = MapVV.FindFromKey(V2);
2120 if (MapVV.Contains(V1))
2121 MapVV.ChangeFromKey(V1) = NewV;
2123 for (i = 1; i <= MapVV.Extent(); i++)
2124 if (MapVV(i).IsSame(V1))
2127 MapVV.Add(V1, NewV);
2130 //=======================================================================
2131 //function : TrimEdge
2133 //=======================================================================
2135 void TrimEdge (const TopoDS_Edge& E,
2136 const TopTools_ListOfShape& Detromp,
2137 TopTools_SequenceOfShape& TheVer,
2138 TColStd_SequenceOfReal& ThePar,
2139 TopTools_SequenceOfShape& S,
2140 TopTools_IndexedDataMapOfShapeShape& MapVV,
2141 const Standard_Integer IndOfE)
2143 Standard_Boolean Change = Standard_True;
2144 BRep_Builder TheBuilder;
2147 //-----------------------------------------------------------
2148 // Parse two sequences depending on the parameter on the edge.
2149 //-----------------------------------------------------------
2151 Change = Standard_False;
2152 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2153 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2154 ThePar.Exchange(i,i+1);
2155 TheVer.Exchange(i,i+1);
2156 Change = Standard_True;
2161 //----------------------------------------------------------
2162 // If a vertex is not in the proofing, it is eliminated.
2163 //----------------------------------------------------------
2164 if (!BRep_Tool::Degenerated(E)) {
2165 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2166 if ( DoubleOrNotInside (Detromp,
2167 TopoDS::Vertex(TheVer.Value(k)))) {
2175 //----------------------------------------------------------
2176 // If a vertex_double appears twice in the proofing
2177 // the vertex is removed.
2178 // otherwise preserve only one of its representations.
2179 //----------------------------------------------------------
2180 if (!BRep_Tool::Degenerated(E)) {
2181 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2182 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2183 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2185 if(k+1 == TheVer.Length()) {
2186 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2191 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2196 if ( DoubleOrNotInside (Detromp,
2197 TopoDS::Vertex(TheVer.Value(k)))) {
2207 //-----------------------------------------------------------
2208 // Creation of edges.
2209 // the number of vertices should be even. The created edges
2210 // go from a vertex with uneven index i to vertex i+1;
2211 //-----------------------------------------------------------
2212 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2214 TopoDS_Shape aLocalShape = E.EmptyCopied();
2215 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2216 TopoDS_Vertex V1, V2;
2217 TopExp::Vertices(E, V1, V2);
2218 Standard_Real fpar, lpar;
2219 BRep_Tool::Range(E, fpar, lpar);
2220 if (IndOfE == 1) //first edge of open wire
2222 if (NewEdge.Orientation() == TopAbs_FORWARD)
2224 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2225 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2226 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2230 //TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2231 //TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2232 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2233 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2234 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2237 else //last edge of open wire
2239 if (NewEdge.Orientation() == TopAbs_FORWARD)
2241 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2242 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2243 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2247 //TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2248 //TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2249 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2250 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2251 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2258 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2259 TopoDS_Shape aLocalShape = E.EmptyCopied();
2260 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2261 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2263 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2264 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2265 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2268 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2269 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2273 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2278 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2279 DBRep::Set(name,NewEdge);
2284 Handle(Geom_Surface) Surf;
2285 Handle(Geom2d_Curve) C;
2286 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2288 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2289 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2290 Handle(DrawTrSurf_Curve2d) dr =
2291 new DrawTrSurf_Curve2d(C2d,Standard_False);
2292 dr->SetColor(Draw_bleu);
2302 //=======================================================================
2303 //function : DoubleOrNotInside
2304 //purpose : return True if V appears twice in LV or is not inside.
2305 //=======================================================================
2307 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2308 const TopoDS_Vertex& V)
2310 Standard_Boolean Vu = Standard_False;
2311 TopTools_ListIteratorOfListOfShape it(LV);
2313 for ( ; it.More(); it.Next()) {
2314 if (V.IsSame(it.Value())) {
2315 if (Vu) return Standard_True;
2316 else Vu = Standard_True;
2319 if (Vu) return Standard_False;
2320 else return Standard_True;
2323 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2324 const TopoDS_Vertex& aVertex)
2326 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2327 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2328 PV2d.SetCoord( PV.X(), PV.Y() );
2330 Handle(Geom2d_Curve) PCurve;
2331 Handle( BRep_CurveRepresentation ) CurveRep =
2332 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2333 PCurve = CurveRep->PCurve();
2335 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2336 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2337 Pfirst = PCurve->Value(fpar);
2338 Plast = PCurve->Value(lpar);
2339 Pmid = PCurve->Value((fpar + lpar)*0.5);
2341 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2344 Standard_Real dist1 = Pfirst.Distance(PV2d);
2345 Standard_Real dist2 = Plast.Distance(PV2d);
2346 Standard_Real dist3 = Pmid.Distance(PV2d);
2348 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2349 return Standard_True;
2351 return Standard_False;
2354 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2355 const BRepMAT2d_BisectingLocus& Locus,
2356 const BRepMAT2d_LinkTopoBilo& Link,
2357 TopTools_ListOfShape& BadEdges)
2360 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2361 Standard_Real eps = Precision::Confusion();
2362 Standard_Real LimCurv = 1./Offset;
2364 TopTools_MapOfShape aMap;
2366 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2367 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2368 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2369 if (SE.ShapeType() == TopAbs_EDGE) {
2371 if (aMap.Contains(SE)) {
2372 //cout << "Edge is treated second time" << endl;
2376 TopoDS_Edge E = TopoDS::Edge(SE);
2380 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2382 Geom2dAdaptor_Curve AC(G2d,f,l);
2383 GeomAbs_CurveType aCType = AC.GetType();
2385 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2387 Standard_Boolean reverse = Standard_False;
2388 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2393 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2395 aCLProps.SetParameter(f);
2396 if(!aCLProps.IsTangentDefined()) {
2397 BadEdges.Append(SE);
2402 P = aCLProps.Value();
2403 Standard_Real Crv = aCLProps.Curvature();
2406 aCLProps.Tangent(N);
2407 Standard_Real x = N.Y(), y = -N.X();
2409 if (reverse) N.Reverse();
2410 aCLProps.CentreOfCurvature(Pc);
2411 gp_Vec2d Dir( P, Pc );
2412 if (N.Dot(Dir) > 0.) {
2413 if (LimCurv <= Crv + eps) {
2414 BadEdges.Append(SE);
2421 aCLProps.SetParameter(l);
2422 if(!aCLProps.IsTangentDefined()) {
2423 BadEdges.Append(SE);
2428 P = aCLProps.Value();
2429 Crv = aCLProps.Curvature();
2432 aCLProps.Tangent(N);
2433 Standard_Real x = N.Y(), y = -N.X();
2435 if (reverse) N.Reverse();
2436 aCLProps.CentreOfCurvature(Pc);
2437 gp_Vec2d Dir( P, Pc );
2438 if (N.Dot(Dir) > 0.) {
2439 if (LimCurv <= Crv + eps) {
2440 BadEdges.Append(SE);
2453 //=======================================================================
2454 //function : PerformCurve
2456 //=======================================================================
2458 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2459 TColgp_SequenceOfPnt& Points,
2460 const Adaptor3d_Curve& C,
2461 const Standard_Real Deflection,
2462 const Standard_Real U1,
2463 const Standard_Real U2,
2464 const Standard_Real EPSILON,
2465 const Standard_Integer Nbmin)
2467 Standard_Real UU1 = Min(U1, U2);
2468 Standard_Real UU2 = Max(U1, U2);
2472 C.D1(UU1,Pdeb,Ddeb);
2473 Parameters.Append(UU1);
2474 Points.Append(Pdeb);
2476 C.D1(UU2,Pfin,Dfin);
2478 const Standard_Real aDelta = UU2 - UU1;
2479 const Standard_Real aDist = Pdeb.Distance(Pfin);
2481 if((aDelta/aDist) > 5.0e-14)
2483 QuasiFleche(C,Deflection*Deflection,
2493 return Standard_True;
2495 //=======================================================================
2496 //function : QuasiFleche
2498 //=======================================================================
2500 static void QuasiFleche(const Adaptor3d_Curve& C,
2501 const Standard_Real Deflection2,
2502 const Standard_Real Udeb,
2505 const Standard_Real Ufin,
2508 const Standard_Integer Nbmin,
2509 const Standard_Real Eps,
2510 TColStd_SequenceOfReal& Parameters,
2511 TColgp_SequenceOfPnt& Points)
2513 Standard_Integer Ptslength = Points.Length();
2514 Standard_Real Udelta = Ufin-Udeb;
2519 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2527 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2528 Standard_Real theFleche=0;
2529 Standard_Boolean flecheok = Standard_False;
2531 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2532 Standard_Real N1 = Vdeb.SquareMagnitude();
2533 Standard_Real N2 = Vdelta.SquareMagnitude();
2534 if (N1 > Eps && N2 > Eps) {
2535 Standard_Real Normediff =
2536 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2537 if (Normediff > Eps) {
2538 theFleche = Normediff*Norme/64.;
2539 flecheok = Standard_True;
2544 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2545 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2546 theFleche = Pmid.SquareDistance(Pverif);
2549 if (theFleche < Deflection2) {
2550 Parameters.Append(Udeb+Udelta);
2551 Points.Append(Pdelta);
2554 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2565 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2569 Nbmin-(Points.Length()-Ptslength),