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>
107 #include <DrawTrSurf.hxx>
108 #include <DrawTrSurf_Curve2d.hxx>
110 static Standard_Boolean AffichGeom = Standard_False;
111 static Standard_Boolean Affich2d = Standard_False;
112 static Standard_Boolean AffichEdge = Standard_False;
113 static Standard_Integer NbTRIMEDGES = 0;
114 static Standard_Integer NbOFFSET = 0;
115 static Standard_Integer NbEDGES = 0;
116 static Standard_Integer NbBISSEC = 0;
120 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
122 static void QuasiFleche(const Adaptor3d_Curve& C,
123 const Standard_Real Deflection2,
124 const Standard_Real Udeb,
127 const Standard_Real Ufin,
130 const Standard_Integer Nbmin,
131 const Standard_Real Eps,
132 TColStd_SequenceOfReal& Parameters,
133 TColgp_SequenceOfPnt& Points);
135 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
136 TColgp_SequenceOfPnt& Points,
137 const Adaptor3d_Curve& C,
138 const Standard_Real Deflection,
139 const Standard_Real U1,
140 const Standard_Real U2,
141 const Standard_Real EPSILON,
142 const Standard_Integer Nbmin);
144 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
145 const BRepMAT2d_BisectingLocus& Locus,
146 const BRepMAT2d_LinkTopoBilo& Link,
147 TopTools_ListOfShape& BadEdges);
149 static Standard_Integer CutEdge (const TopoDS_Edge& E,
150 const TopoDS_Face& F,
151 Standard_Integer ForceCut,
152 TopTools_ListOfShape& Cuts);
155 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
156 const Standard_Integer nbParts,
157 TColGeom2d_SequenceOfCurve& theCurves);
158 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
161 static void EdgeVertices (const TopoDS_Edge& E,
165 if (E.Orientation() == TopAbs_REVERSED) {
166 TopExp::Vertices(E,V2,V1);
169 TopExp::Vertices(E,V1,V2);
172 static Standard_Boolean VertexFromNode
173 (const Handle(MAT_Node)& aNode,
174 const Standard_Real Offset,
176 BRepFill_DataMapOfNodeShape& MapNodeVertex,
179 static void StoreInMap (const TopoDS_Shape& V1,
180 const TopoDS_Shape& V2,
181 TopTools_IndexedDataMapOfShapeShape& MapVV);
183 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
184 const TopoDS_Shape& CurrentSpine,
185 const TopoDS_Face& AllSpine,
186 const TopTools_ListOfShape& D,
187 TopTools_SequenceOfShape& Sv,
188 TColStd_SequenceOfReal& MapverPar,
189 TopTools_SequenceOfShape& S,
190 TopTools_IndexedDataMapOfShapeShape& MapVV,
191 const Standard_Integer IndOfE);
193 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
194 const TopoDS_Face& AllSpine,
195 Standard_Real& TrPar1,
196 Standard_Real& TrPar2);
198 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
199 const TopoDS_Vertex& V);
201 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
202 const TopoDS_Vertex& aVertex);
204 static void MakeCircle
205 (const TopoDS_Edge& E,
206 const TopoDS_Vertex& V,
207 const TopoDS_Face& F,
208 const Standard_Real Offset,
209 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
210 const Handle(Geom_Plane)& RefPlane);
212 static void MakeOffset
213 (const TopoDS_Edge& E,
214 const TopoDS_Face& F,
215 const Standard_Real Offset,
216 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
217 const Handle(Geom_Plane)& RefPlane,
218 const Standard_Boolean IsOpenResult,
219 const GeomAbs_JoinType theJoinType,
220 const TopoDS_Vertex * Ends);
222 //=======================================================================
223 //function : KPartCircle
225 //=======================================================================
227 static Standard_Boolean KPartCircle
228 (const TopoDS_Face& mySpine,
229 const Standard_Real myOffset,
230 const Standard_Boolean IsOpenResult,
231 const Standard_Real Alt,
232 TopoDS_Shape& myShape,
233 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
234 Standard_Boolean& myIsDone)
236 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
237 Standard_Integer NbEdges = 0;
240 for (; exp.More(); exp.Next()) {
242 E = TopoDS::Edge(exp.Current());
243 if (NbEdges > 1) return Standard_False;
248 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
250 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
251 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
252 C = Ct->BasisCurve();
255 if ((C->IsKind(STANDARD_TYPE(Geom_Circle)) && BRep_Tool::IsClosed(E)) || //closed circle
258 Standard_Real anOffset = myOffset;
260 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(E, mySpine, f, l);
261 Handle(Geom2dAdaptor_HCurve) AHC = new Geom2dAdaptor_HCurve(aPCurve, f, l);
262 Handle(Geom2d_Curve) OC;
263 if (AHC->GetType() == GeomAbs_Line)
265 if (E.Orientation() == TopAbs_REVERSED)
267 Adaptor3d_OffsetCurve Off(AHC,anOffset);
268 OC = new Geom2d_Line(Off.Line());
270 else if (AHC->GetType() == GeomAbs_Circle)
272 if (E.Orientation() == TopAbs_FORWARD)
274 gp_Circ2d theCirc = AHC->Circle();
275 if (anOffset > 0. || Abs(anOffset) < theCirc.Radius())
276 OC = new Geom2d_Circle (theCirc.Position(), theCirc.Radius() + anOffset);
279 myIsDone = Standard_False;
280 return Standard_False;
285 if (E.Orientation() == TopAbs_FORWARD)
287 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(aPCurve, f, l);
288 OC = new Geom2d_OffsetCurve( G2dT, anOffset);
290 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(mySpine);
291 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
292 myShape = BRepLib_MakeEdge(OC, 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 return Standard_False;
321 //=======================================================================
322 //function : BRepFill_OffsetWire
324 //=======================================================================
326 BRepFill_OffsetWire::BRepFill_OffsetWire()
327 : myIsOpenResult(Standard_False),
328 myIsDone(Standard_False)
333 //=======================================================================
334 //function : BRepFill_OffsetWire
336 //=======================================================================
338 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
339 const GeomAbs_JoinType Join,
340 const Standard_Boolean IsOpenResult)
342 Init(Spine,Join,IsOpenResult);
345 //=======================================================================
348 //=======================================================================
350 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
351 const GeomAbs_JoinType Join,
352 const Standard_Boolean IsOpenResult)
354 myIsDone = Standard_False;
355 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
356 mySpine = TopoDS::Face(aLocalShape);
357 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
359 myIsOpenResult = IsOpenResult;
363 //------------------------------------------------------------------
364 // cut the spine for bissectors.
365 //------------------------------------------------------------------
366 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
367 static BRepMAT2d_Explorer Exp;
369 Exp.Perform(mySpine);
371 // TopoDS_Face anOldSpine = mySpine;
373 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
376 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
378 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
379 Standard_Boolean Done;
380 if (KPartCircle(myWorkSpine,1.,myIsOpenResult,0.,aShape,aMap,Done)) return;
383 //-----------------------------------------------------
384 // Calculate the map of bissectors to the left.
385 // and Links Topology -> base elements of the map.
386 //-----------------------------------------------------
388 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
389 // static BRepMAT2d_Explorer Exp;
390 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
391 Exp.Perform(myWorkSpine);
392 myBilo.Compute(Exp, 1 ,MAT_Left, myJoinType, myIsOpenResult);
393 myLink.Perform(Exp,myBilo);
397 //=======================================================================
400 //=======================================================================
402 Standard_Boolean BRepFill_OffsetWire::IsDone() const
408 //=======================================================================
411 //=======================================================================
413 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
419 //=======================================================================
422 //=======================================================================
424 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
430 //=======================================================================
431 //function : GeneratedShapes
433 //=======================================================================
435 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
436 (const TopoDS_Shape& SpineShape)
439 if (!myMapSpine.IsEmpty()) {
440 // myMapSpine can be empty if passed by PerformWithBilo.
441 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
442 for (; it.More(); it.Next()) {
443 if (myMap.Contains(it.Key())) {
444 if (!myMap.Contains(it.Value())) {
445 TopTools_ListOfShape L;
446 myMap.Add(it.Value(),L);
448 if ( !it.Value().IsSame(it.Key())) {
449 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
450 //myMap.UnBind(it.Key());
451 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
452 TopTools_ListOfShape LastList;
453 LastList.Append(myMap(myMap.Extent()));
455 if (myMap.FindIndex(it.Key()) != 0)
456 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
459 if (myMap.Contains(it.Key().Reversed())) {
460 if (!myMap.Contains(it.Value().Reversed())) {
461 TopTools_ListOfShape L;
462 myMap.Add(it.Value().Reversed(),L);
464 if ( !it.Value().IsSame(it.Key())) {
465 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
466 //myMap.UnBind(it.Key().Reversed());
467 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
468 TopTools_ListOfShape LastList;
469 LastList.Append(myMap(myMap.Extent()));
471 if (myMap.FindIndex(it.Key().Reversed()) != 0)
472 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
477 myCallGen = Standard_True;
480 if (myMap.Contains(SpineShape)) {
481 return myMap.FindFromKey(SpineShape);
484 static TopTools_ListOfShape Empty;
490 //=======================================================================
491 //function : JoinType
493 //=======================================================================
495 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
500 //=======================================================================
503 //=======================================================================
505 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
506 const Standard_Real Alt)
508 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
512 myCallGen = Standard_False;
513 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone)) return;
515 TopoDS_Face oldWorkSpain = myWorkSpine;
517 TopTools_ListOfShape BadEdges;
518 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
520 if(!BadEdges.IsEmpty())
522 // Modification of myWorkSpine;
523 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
524 BRepTools_Substitution aSubst;
525 TopTools_ListIteratorOfListOfShape it(BadEdges);
526 TopTools_ListOfShape aL;
527 Standard_Real aDefl = .01 * Abs(Offset);
528 TColStd_SequenceOfReal Parameters;
529 TColgp_SequenceOfPnt Points;
531 for(; it.More(); it.Next()) {
535 const TopoDS_Shape& anE = it.Value();
537 TopoDS_Vertex Vf, Vl;
538 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
541 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
542 GeomAdaptor_Curve AC(G3d,f,l);
544 PerformCurve(Parameters, Points, AC, aDefl, f,
545 l, Precision::Confusion(), 2);
547 Standard_Integer NPnts = Points.Length();
550 //cout << NPnts << " points " << endl;
551 TopoDS_Vertex FV = Vf;
555 for(np = 2; np < NPnts; np++) {
556 gp_Pnt LP = Points(np);
557 LV = BRepLib_MakeVertex(LP);
558 newE = BRepLib_MakeEdge(FV, LV);
563 newE = BRepLib_MakeEdge(FV, LV);
568 //cout << " 2 points " << endl;
569 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
573 if (myMapSpine.IsBound( anE ))
575 TopTools_ListIteratorOfListOfShape newit( aL );
576 for (; newit.More(); newit.Next())
578 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
579 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
580 TopoDS_Vertex NewV1, NewV2;
581 EdgeVertices( NewEdge, NewV1, NewV2 );
582 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
583 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
585 myMapSpine.UnBind( anE );
588 aSubst.Substitute(anE, aL);
591 TopTools_DataMapOfShapeListOfShape wwmap;
592 TopoDS_Iterator itws( myWorkSpine );
593 for (; itws.More(); itws.Next())
595 TopoDS_Shape aWire = itws.Value();
596 aSubst.Build( aWire );
597 if (aSubst.IsCopied(aWire))
599 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
600 NewWire.Closed( aWire.Closed() );
601 TopTools_ListOfShape Lw;
602 Lw.Append( NewWire );
603 wwmap.Bind( aWire, Lw );
607 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
608 for (; itmap.More(); itmap.Next())
609 aSubst.Substitute( itmap.Key(), itmap.Value() );
611 aSubst.Build(myWorkSpine);
613 if(aSubst.IsCopied(myWorkSpine)) {
614 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
616 BRepMAT2d_Explorer newExp;
617 newExp.Perform(myWorkSpine);
618 BRepMAT2d_BisectingLocus newBilo;
619 BRepMAT2d_LinkTopoBilo newLink;
620 newBilo.Compute(newExp, 1, MAT_Left, myJoinType, myIsOpenResult);
622 if(!newBilo.IsDone())
625 myIsDone = Standard_False;
629 newLink.Perform(newExp,newBilo);
630 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
631 myWorkSpine = oldWorkSpain;
634 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
639 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
642 catch (Standard_Failure)//Every exception was caught.
645 myIsDone = Standard_False;
647 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
648 Standard_Failure::Caught()->Print(cout);
655 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
656 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
659 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
661 for (; anExp.More(); anExp.Next()) {
662 const TopoDS_Shape &aWire = anExp.Current();
664 if (!aWire.Closed()) {
666 myIsDone = Standard_False;
667 Standard_ConstructionError::Raise("Offset wire is not closed.");
671 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
674 //=======================================================================
677 //=======================================================================
679 void Compute (const TopoDS_Face& Spine,
680 TopoDS_Shape& aShape,
681 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
682 const Standard_Real Alt)
685 B.MakeCompound(TopoDS::Compound(aShape));
686 Standard_Real ALT = Alt;
687 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
689 T.SetTranslation(gp_Vec(0.,0.,ALT));
690 TopLoc_Location L(T);
692 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
693 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
694 TopoDS_Shape aLocalShape = CurW.Moved(L);
695 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
696 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
699 TopoDS_Iterator it1( CurW);
700 TopoDS_Iterator it2( NewW);
701 for ( ; it1.More(); it1.Next(), it2.Next()) {
702 TopTools_ListOfShape List;
703 List.Append(it2.Value());
704 Map.Add(it1.Value(), List);
709 //=======================================================================
710 //function : PerformWithBiLo
712 //=======================================================================
714 void BRepFill_OffsetWire::PerformWithBiLo
715 (const TopoDS_Face& Spine,
716 const Standard_Real Offset,
717 const BRepMAT2d_BisectingLocus& Locus,
718 BRepMAT2d_LinkTopoBilo& Link,
719 const GeomAbs_JoinType Join,
720 const Standard_Real Alt)
722 myIsDone = Standard_False;
723 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
724 myWorkSpine = TopoDS::Face(aLocalShape);
725 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
731 if (mySpine.IsNull()) {
732 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
733 mySpine = TopoDS::Face(aLocalShape);
734 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
738 if ( Abs(myOffset) < Precision::Confusion()) {
739 Compute(mySpine,myShape,myMap,Alt);
740 myIsDone = Standard_True;
744 //********************************
745 // Calculate for a non null offset
746 //********************************
747 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone))
750 BRep_Builder myBuilder;
751 myBuilder.MakeCompound(TopoDS::Compound(myShape));
753 //---------------------------------------------------------------------
754 // MapNodeVertex : associate to each node of the map (key1) and to
755 // each element of the profile (key2) a vertex (item).
756 // MapBis : all edges or vertices (item) generated by
757 // a bisectrice on a face or an edge (key) of revolution tubes.
758 // MapVerPar : Map of parameters of vertices on parallel edges
759 // the list contained in MapVerPar (E) corresponds to
760 // parameters on E of vertices contained in MapBis(E);
761 //---------------------------------------------------------------------
764 BRepFill_DataMapOfNodeShape MapNodeVertex;
765 TopTools_DataMapOfShapeSequenceOfShape MapBis;
766 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
768 TopTools_DataMapOfShapeShape EmptyMap;
769 TopTools_SequenceOfShape EmptySeq;
770 TopTools_ListOfShape EmptyList;
771 TColStd_SequenceOfReal EmptySeqOfReal;
773 Standard_Real ALT = Alt;
774 Handle(Geom_Plane) RefPlane =
775 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
776 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
777 RefPlane = Handle(Geom_Plane)::DownCast
778 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
780 //---------------------------------------------------------------
781 // Construction of Circles and OffsetCurves
782 //---------------------------------------------------------------
784 TopoDS_Vertex Ends [2];
788 TopoDS_Iterator iter(mySpine);
789 theWire = TopoDS::Wire(iter.Value());
790 TopExp::Vertices(theWire, Ends[0], Ends[1]);
793 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
794 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
795 TopoDS_Shape& PE = PEE ;
796 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
797 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
798 if (SE.ShapeType() == TopAbs_VERTEX) {
799 if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
800 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
801 myWorkSpine,myOffset,myMap,RefPlane);
804 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
805 myIsOpenResult, myJoinType, Ends);
815 cout << " End Construction of geometric primitives "<<endl;
821 //---------------------------------------------------
822 // Construction of offset vertices.
823 //---------------------------------------------------
824 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
825 Handle(MAT_Arc) CurrentArc;
826 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
827 Handle(Geom_Curve) CBis;
828 Standard_Boolean Reverse;
829 TopoDS_Edge CurrentEdge;
833 Standard_Integer j, k;
835 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
837 CurrentArc = Locus.Graph()->Arc(i);
838 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
844 sprintf(name,"BISSEC_%d",NbBISSEC++);
845 DrawTrSurf::Set(name,Bisec.Value());
850 //-------------------------------------------------------------------
851 // Return elements of the spine corresponding to separate basicElts.
852 //-------------------------------------------------------------------
853 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
854 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
856 TopTools_SequenceOfShape Vertices;
857 TColgp_SequenceOfPnt Params;
859 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
860 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
862 //-----------------------------------------------------------
863 // Return parallel edges on each face.
864 // If no offset generated => move to the next bissectrice.
865 //--------------------------------------------------------------
866 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
867 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
868 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
872 //-----------------------------------------------------------
873 // Construction of vertices corresponding to the node of the map.
874 // if they are on the offset.
875 //-----------------------------------------------------------
877 Handle(MAT_Node) Node1, Node2;
880 Node1 = CurrentArc->SecondNode();
881 Node2 = CurrentArc->FirstNode();
884 Node1 = CurrentArc->FirstNode();
885 Node2 = CurrentArc->SecondNode();
888 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
890 if (!Node1->Infinite()) {
891 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
892 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
893 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
894 // MapNodeVertex,VS);
896 if (!Node2->Infinite()) {
897 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
898 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
899 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
900 // MapNodeVertex,VE);
903 //---------------------------------------------
904 // Construction of geometries.
905 //---------------------------------------------
906 BRepFill_TrimEdgeTool Trim (Bisec,
907 Locus.GeomElt(CurrentArc->FirstElement()),
908 Locus.GeomElt(CurrentArc->SecondElement()),
911 //-----------------------------------------------------------
912 // Construction of vertices on edges parallel to the spine.
913 //-----------------------------------------------------------
915 Trim.IntersectWith(E [0], E [1], Params);
917 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
919 myBuilder.MakeVertex (VC);
920 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
921 gp_Pnt PVC(P2.X(),P2.Y(),0.);
923 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
927 Standard_Boolean Start = 1;
928 Trim.AddOrConfuse(Start, E[0], E[1], Params);
929 if (Params.Length() == Vertices.Length())
930 Vertices.SetValue(1,VS);
933 // the point was not found by IntersectWith
934 Vertices.Prepend(VS);
937 Standard_Boolean Start = 0;
938 Trim.AddOrConfuse(Start, E[0], E[1], Params);
939 if (Params.Length() == Vertices.Length())
940 Vertices.SetValue(Params.Length(),VE);
943 // the point was not found by IntersectWith
947 //------------------------------------------------------------
949 // Detromp allows to remove vertices on the offset
950 // corresponding to tangency zones
951 // Detromp ranks the vertices that limit
952 // the parts of the bissectrices located between the spine and the
954 //------------------------------------------------------------
955 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
956 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
959 UpdateDetromp (Detromp, S[0], S[1], Vertices, Params,
960 Bisec, StartOnEdge, EndOnEdge, Trim);
961 //----------------------------------------------
962 // Storage of vertices on parallel edges.
963 // fill MapBis and MapVerPar.
964 //----------------------------------------------
965 if (!Vertices.IsEmpty()) {
966 for (k = 0; k <= 1; k++) {
967 if (!MapBis.IsBound(E[k])) {
968 MapBis .Bind(E[k],EmptySeq);
969 MapVerPar.Bind(E[k],EmptySeqOfReal);
971 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
972 MapBis (E[k]).Append(Vertices.Value(ii));
973 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
974 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
979 //------------------------------------------------------------
980 // FOR COMPLETE CIRCLES. the parallel line can be contained
981 // in the zone without intersection with the border
983 // if myoffset is < distance of nodes the parallel can be valid.
984 //-------------------------------------------------------------
985 for (k = 0; k <= 1; k++) {
986 if (!MapBis.IsBound(E[k])) {
987 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
988 MapBis .Bind(E[k],EmptySeq);
989 MapVerPar.Bind(E[k],EmptySeqOfReal);
999 cout << " End Construction of vertices on offsets"<<endl;
1004 //----------------------------------
1005 // Construction of parallel edges.
1006 //----------------------------------
1007 TopTools_IndexedDataMapOfShapeShape MapVV;
1009 TopoDS_Shape CurrentSpine;
1011 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
1013 for (j = 1; j <= myMap.Extent(); j++) {
1014 CurrentSpine = myMap.FindKey(j);
1015 CurrentEdge = TopoDS::Edge(myMap(j).First());
1018 if (MapBis.IsBound(CurrentEdge)) {
1019 TopTools_SequenceOfShape S;
1020 if (!MapBis(CurrentEdge).IsEmpty()) {
1021 Standard_Integer IndOfE = 0;
1026 else if (j == myMap.Extent())
1029 TrimEdge (CurrentEdge,
1032 Detromp (CurrentSpine),
1033 MapBis (CurrentEdge) ,
1034 MapVerPar(CurrentEdge) ,
1036 for ( k = 1; k <= S.Length(); k++) {
1037 myMap(j).Append(S.Value(k));
1044 myMap(j).Append(CurrentEdge);
1049 Standard_Integer ind;
1050 for (ind = 1; ind <= MapVV.Extent(); ind++)
1052 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1053 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1054 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1055 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1056 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1057 TopTools_ListOfShape LV;
1058 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1059 BRepTools_Substitution aSubst;
1060 aSubst.Substitute( OldV, LV );
1061 for (j = 1; j <= myMap.Extent(); j++)
1063 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1064 for (; itl.More(); itl.Next())
1066 aSubst.Build(itl.Value());
1067 if (aSubst.IsCopied(itl.Value()))
1069 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1070 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1071 itl.Value() = listSh.First();
1072 itl.Value().Orientation(SaveOr);
1078 //----------------------------------
1079 // Construction of offset wires.
1080 //----------------------------------
1083 // Update vertices ( Constructed in the plane Z = 0) !!!
1084 TopTools_MapOfShape MapVertex;
1085 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1086 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1087 if ( MapVertex.Add(V)) {
1088 gp_Pnt P = BRep_Tool::Pnt(V);
1089 P = RefPlane->Value(P.X(),P.Y());
1090 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1094 // Construction of curves 3d.
1095 BRepLib::BuildCurves3d(myShape);
1097 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1098 for (; Explo.More(); Explo.Next())
1100 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1101 TopoDS_Vertex V1, V2;
1102 TopExp::Vertices( E, V1, V2 );
1103 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1104 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1106 TopLoc_Location loc;
1108 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1109 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1110 theCurve->Transform( loc.Transformation() );
1111 gp_Pnt f3d = theCurve->Value( f );
1112 gp_Pnt l3d = theCurve->Value( l );
1114 Standard_Real dist1, dist2;
1115 dist1 = f3d.Distance( TV1->Pnt() );
1116 dist2 = l3d.Distance( TV2->Pnt() );
1117 if (! MapVertex.Contains( V1 ))
1121 MapVertex.Add( V1 );
1124 TV1->UpdateTolerance( 1.5*dist1 );
1125 if (! MapVertex.Contains( V2 ))
1128 MapVertex.Add( V2 );
1131 TV2->UpdateTolerance( 1.5*dist2 );
1136 myIsDone = Standard_True;
1140 //=======================================================================
1141 //function : Generated
1143 //=======================================================================
1145 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1146 BRepFill_OffsetWire::Generated()
1152 //=======================================================================
1153 //function : PrepareSpine
1155 //=======================================================================
1157 void BRepFill_OffsetWire::PrepareSpine()
1160 TopTools_ListOfShape Cuts;
1161 TopTools_ListIteratorOfListOfShape IteCuts;
1162 TopoDS_Vertex V1,V2;
1164 myWorkSpine.Nullify();
1168 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1169 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1170 B.MakeFace(myWorkSpine,S,L,TolF);
1172 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1177 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1178 Standard_Integer ForcedCut = 0;
1179 Standard_Integer nbResEdges = -1;
1180 TopTools_IndexedMapOfShape EdgeMap;
1182 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1183 Standard_Integer nbEdges = EdgeMap.Extent();
1185 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
1187 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1189 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1191 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1192 EdgeVertices(E,V1,V2);
1193 myMapSpine.Bind(V1,V1);
1194 myMapSpine.Bind(V2,V2);
1198 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1199 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1200 if (nbEdges == 2 && nbResEdges == 0)
1202 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1203 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1205 if (Cuts.IsEmpty()) {
1207 myMapSpine.Bind(E,E);
1210 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1211 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1212 NE.Orientation(E.Orientation());
1214 myMapSpine.Bind(NE,E);
1215 EdgeVertices(NE,V1,V2);
1216 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1217 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1221 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1225 TopExp::Vertices(NW, aV1, aV2);
1227 NW.Closed(aV1.IsSame(aV2));
1229 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1230 B.Add(myWorkSpine, NW);
1236 DBRep::Set("WS",myWorkSpine);
1237 DBRep::Set("MS",mySpine);
1238 BRepTools::Write(myWorkSpine, "WS");
1239 BRepTools::Write(mySpine, "MS");
1246 //=======================================================================
1247 //function : UpdateDetromp
1248 //purpose : For each interval on bissectrice defined by parameters
1249 // test if the medium point is at a distance > offset
1250 // in this case vertices corresponding to the extremities of the interval
1251 // are ranked in the proofing.
1252 // => If the same vertex appears in the proofing, the
1253 // border of the zone of proximity is tangent to the offset .
1254 //=======================================================================
1256 void BRepFill_OffsetWire::UpdateDetromp (BRepFill_DataMapOfOrientedShapeListOfShape& Detromp,
1257 const TopoDS_Shape& Shape1,
1258 const TopoDS_Shape& Shape2,
1259 const TopTools_SequenceOfShape& Vertices,
1260 const TColgp_SequenceOfPnt& Params,
1261 const Bisector_Bisec& Bisec,
1262 const Standard_Boolean SOnE,
1263 const Standard_Boolean EOnE,
1264 const BRepFill_TrimEdgeTool& Trim) const
1266 Standard_Integer ii = 1;
1267 Standard_Real U1,U2;
1268 TopoDS_Vertex V1,V2;
1270 Handle(Geom2d_Curve) Bis = Bisec.Value();
1272 U1 = Bis->FirstParameter();
1275 // the first point of the bissectrice is on the offset
1276 V1 = TopoDS::Vertex(Vertices.Value(ii));
1280 while (ii <= Vertices.Length()) {
1281 U2 = Params.Value(ii).X();
1282 V2 = TopoDS::Vertex(Vertices.Value(ii));
1284 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1285 Standard_Boolean IsP_inside = Standard_True;
1286 if ((myJoinType != GeomAbs_Intersection) || EOnE)
1287 IsP_inside = Trim.IsInside(P);
1290 Detromp(Shape1).Append(V1);
1291 Detromp(Shape2).Append(V1);
1293 Detromp(Shape1).Append(V2);
1294 Detromp(Shape2).Append(V2);
1301 // test medium point between the last parameter and the end of the bissectrice.
1302 U2 = Bis->LastParameter();
1304 if (!Precision::IsInfinite(U2)) {
1305 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1306 Standard_Boolean IsP_inside = Standard_False;
1307 if (myJoinType == GeomAbs_Arc)
1308 IsP_inside = Trim.IsInside(P);
1311 Detromp(Shape1).Append(V1);
1312 Detromp(Shape2).Append(V1);
1318 Detromp(Shape1).Append(V1);
1319 Detromp(Shape2).Append(V1);
1323 //else if(myJoinType != GeomAbs_Arc)
1325 // if (!V1.IsNull()) {
1326 // Detromp(Shape1).Append(V1);
1327 // Detromp(Shape2).Append(V1);
1332 //=======================================================================
1333 //function : MakeWires
1335 //=======================================================================
1337 void BRepFill_OffsetWire::MakeWires()
1339 //--------------------------------------------------------
1340 // creation of a single list of created parallel edges.
1341 //--------------------------------------------------------
1342 TopTools_SequenceOfShape TheEdges;
1343 TopTools_ListOfShape TheWires;
1344 TopTools_ListIteratorOfListOfShape itl;
1345 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1346 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1347 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1348 TopoDS_Vertex V1,V2,VF,CV;
1351 for (i = 1; i <= myMap.Extent(); i++) {
1352 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1353 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1354 TopExp::Vertices (E,V1,V2);
1355 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1356 continue; //remove small closed edges
1357 if (!MVE.Contains(V1)) {
1358 TopTools_ListOfShape empty;
1361 MVE.ChangeFromKey(V1).Append(E);
1362 if (!MVE.Contains(V2)) {
1363 TopTools_ListOfShape empty;
1366 MVE.ChangeFromKey(V2).Append(E);
1370 //--------------------------------------
1371 // Creation of parallel wires.
1372 //--------------------------------------
1376 // Standard_Integer NbEdges;
1377 // Standard_Boolean NewWire = Standard_True;
1378 // Standard_Boolean AddEdge = Standard_False;
1381 Standard_Boolean End;
1384 while (!MVE.IsEmpty()) {
1387 //MVEit.Initialize(MVE);
1388 for (i = 1; i <= MVE.Extent(); i++)
1389 if(MVE(i).Extent() == 1)
1392 //if(!MVEit.More()) MVEit.Initialize(MVE);
1393 if (i > MVE.Extent())
1396 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1397 CE = TopoDS::Edge(MVE(i).First());
1398 End = Standard_False;
1399 MVE.ChangeFromKey(CV).RemoveFirst();
1401 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1402 Standard_Boolean isClosed = Standard_False;
1404 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1407 //-------------------------------
1408 // Construction of a wire.
1409 //-------------------------------
1410 TopExp::Vertices(CE,V1,V2);
1411 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1415 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1416 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1417 isClosed = VF.IsSame(CV);
1418 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1419 End = Standard_True;
1421 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1422 TopTools_ListOfShape LastList;
1423 LastList.Append(MVE(MVE.Extent()));
1425 if (MVE.FindIndex(VF) != 0)
1426 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1430 if (MVE.FindFromKey(CV).Extent() > 2) {
1431 //cout <<"vertex on more that 2 edges in a face."<<endl;
1433 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1434 if (itl.Value().IsSame(CE)) {
1435 MVE.ChangeFromKey(CV).Remove(itl);
1439 if (!MVE.FindFromKey(CV).IsEmpty()) {
1440 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1441 MVE.ChangeFromKey(CV).RemoveFirst();
1443 if (MVE.FindFromKey(CV).IsEmpty())
1446 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1447 TopTools_ListOfShape LastList;
1448 LastList.Append(MVE(MVE.Extent()));
1450 if (MVE.FindIndex(CV) != 0)
1451 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1455 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1456 // NW.Closed(Standard_True);
1457 NW.Closed(isClosed);
1458 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1459 TheWires.Append(NW);
1463 // -- if only one wire : myShape is a Wire
1464 // -- if several wires : myShape is a Compound.
1465 if ( TheWires.Extent() == 1) {
1466 myShape = TheWires.First();
1471 TopTools_ListIteratorOfListOfShape it(TheWires);
1472 for ( ; it.More(); it.Next()) {
1473 B.Add(R, it.Value());
1480 //=======================================================================
1481 //function : FixHoles
1483 //=======================================================================
1485 void BRepFill_OffsetWire::FixHoles()
1487 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1489 Standard_Real MaxTol = 0.;
1493 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1494 for (; Explo.More(); Explo.Next())
1496 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1497 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1503 Explo.Init( myShape, TopAbs_WIRE );
1504 for (; Explo.More(); Explo.Next())
1506 TopoDS_Shape aWire = Explo.Current();
1507 // Remove duplicated edges
1508 TopTools_DataMapOfShapeListOfShape EEmap;
1509 TopoDS_Iterator it( aWire );
1510 for (; it.More(); it.Next())
1512 const TopoDS_Shape& anEdge = it.Value();
1513 if (! EEmap.IsBound( anEdge ))
1515 TopTools_ListOfShape LE;
1516 EEmap.Bind( anEdge, LE );
1519 EEmap(anEdge).Append( anEdge );
1521 aWire.Free( Standard_True );
1522 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1523 for (; mapit.More(); mapit.Next())
1525 const TopTools_ListOfShape& LE = mapit.Value();
1526 TopTools_ListIteratorOfListOfShape itl( LE );
1527 for (; itl.More(); itl.Next())
1528 BB.Remove( aWire, itl.Value() );
1532 ClosedWires.Append( aWire );
1534 UnclosedWires.Append( aWire );
1537 while (!UnclosedWires.IsEmpty())
1539 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1540 TopoDS_Vertex Vf, Vl;
1541 TopExp::Vertices( Base, Vf, Vl );
1542 if(Vf.IsNull() || Vl.IsNull())
1544 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1546 BRepTools::Write(Base, "Base");
1550 Pf = BRep_Tool::Pnt(Vf);
1551 Pl = BRep_Tool::Pnt(Vl);
1552 Standard_Real DistF = RealLast(), DistL = RealLast();
1553 Standard_Integer IndexF = 1, IndexL = 1;
1554 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1555 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1557 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1558 TopoDS_Vertex V1, V2;
1559 TopExp::Vertices( aWire, V1, V2 );
1561 if(V1.IsNull() || V2.IsNull())
1563 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1565 BRepTools::Write(Base, "Base");
1567 sprintf(name,"Wire_%d",i);
1568 BRepTools::Write(aWire, name);
1573 P1 = BRep_Tool::Pnt(V1);
1574 P2 = BRep_Tool::Pnt(V2);
1575 Standard_Real dist = Pf.Distance( P1 );
1580 IsFirstF = Standard_True;
1582 dist = Pf.Distance( P2 );
1587 IsFirstF = Standard_False;
1589 dist = Pl.Distance( P1 );
1594 IsFirstL = Standard_True;
1596 dist = Pl.Distance( P2 );
1601 IsFirstL = Standard_False;
1604 TopoDS_Wire theWire;
1605 TopoDS_Edge theEdge;
1606 TopoDS_Vertex theVertex;
1607 Standard_Real CommonTol;
1608 Standard_Boolean TryToClose = Standard_True;
1609 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1621 TryToClose = Standard_False;
1623 if (DistF <= MaxTol)
1625 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1626 TopoDS_Vertex V1, V2;
1627 TopExp::Vertices( theWire, V1, V2 );
1628 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1629 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1630 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1631 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1632 TopoDS_Iterator it( theWire );
1633 for (; it.More(); it.Next())
1635 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1636 if (IsFirstF) anEdge.Reverse();
1637 if (!anEdge.IsSame( theEdge ))
1638 BB.Add( Base, anEdge );
1640 theVertex = (IsFirstF)? V1 : V2;
1641 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1642 if (DistF <= CommonTol)
1644 theEdge.Free( Standard_True );
1645 Vf.Orientation( theVertex.Orientation() );
1646 BB.Remove( theEdge, theVertex );
1647 BB.Add( theEdge, Vf );
1648 BB.UpdateVertex( Vf, CommonTol );
1649 if (IsFirstF) theEdge.Reverse();
1650 BB.Add( Base, theEdge );
1654 if (IsFirstF) theEdge.Reverse();
1655 BB.Add( Base, theEdge );
1656 // Creating new edge from theVertex to Vf
1657 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1658 BB.Add( Base, NewEdge );
1661 if (DistL <= MaxTol && IndexL != IndexF)
1663 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1664 TopoDS_Vertex V1, V2;
1665 TopExp::Vertices( theWire, V1, V2 );
1666 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1667 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1668 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1669 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1670 TopoDS_Iterator it( theWire );
1671 for (; it.More(); it.Next())
1673 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1674 if (!IsFirstL) anEdge.Reverse();
1675 if (!anEdge.IsSame( theEdge ))
1676 BB.Add( Base, anEdge );
1678 theVertex = (IsFirstL)? V1 : V2;
1679 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1680 if (DistL <= CommonTol)
1682 theEdge.Free( Standard_True );
1683 Vl.Orientation( theVertex.Orientation() );
1684 BB.Remove( theEdge, theVertex );
1685 BB.Add( theEdge, Vl );
1686 BB.UpdateVertex( Vl, CommonTol );
1687 if (!IsFirstL) theEdge.Reverse();
1688 BB.Add( Base, theEdge );
1692 if (!IsFirstL) theEdge.Reverse();
1693 BB.Add( Base, theEdge );
1694 // Creating new edge from Vl to theVertex
1695 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1696 BB.Add( Base, NewEdge );
1699 // Check if it is possible to close resulting wire
1702 TopExp::Vertices( Base, Vf, Vl );
1703 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1704 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1705 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1706 TopoDS_Edge Efirst, Elast;
1707 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1708 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1709 Pf = BRep_Tool::Pnt(Vf);
1710 Pl = BRep_Tool::Pnt(Vl);
1711 Standard_Real Dist = Pf.Distance(Pl);
1712 if (Dist <= CommonTol)
1714 Elast.Free( Standard_True );
1715 Vf.Orientation( Vl.Orientation() );
1716 BB.Remove( Elast, Vl );
1717 BB.Add( Elast, Vf );
1718 BB.UpdateVertex( Vf, CommonTol );
1719 Base.Closed( Standard_True );
1721 else if (Dist <= MaxTol)
1723 // Creating new edge from Vl to Vf
1724 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1725 BB.Add( Base, NewEdge );
1726 Base.Closed( Standard_True );
1729 // Updating sequences ClosedWires and UnclosedWires
1730 if (DistF <= MaxTol)
1731 UnclosedWires.Remove( IndexF );
1732 if (DistL <= MaxTol && IndexL != IndexF)
1734 if (DistF <= MaxTol && IndexL > IndexF)
1736 UnclosedWires.Remove( IndexL );
1740 ClosedWires.Append( Base );
1741 UnclosedWires.Remove( 1 );
1743 else if (DistF > MaxTol && DistL > MaxTol)
1745 IsolatedWires.Append( Base );
1746 UnclosedWires.Remove( 1 );
1751 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1753 if (!ClosedWires.IsEmpty())
1754 myShape = ClosedWires.First();
1756 myShape = IsolatedWires.First();
1761 BB.MakeCompound( R );
1762 for (i = 1; i <= ClosedWires.Length(); i++)
1763 BB.Add( R, ClosedWires(i) );
1764 for (i = 1; i <= IsolatedWires.Length(); i++)
1765 BB.Add( R, IsolatedWires(i) );
1770 //=======================================================================
1771 //function : CutEdge
1772 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1773 // So, closed circles are cut in two.
1774 // If <Cuts> is empty, the edge is not modified.
1775 // The first and the last vertex of the initial edge
1776 // belong to the first and the last parts respectively.
1777 //=======================================================================
1778 Standard_Integer CutEdge (const TopoDS_Edge& E,
1779 const TopoDS_Face& F,
1780 Standard_Integer ForceCut,
1781 TopTools_ListOfShape& Cuts)
1784 MAT2d_CutCurve Cuter;
1785 TColGeom2d_SequenceOfCurve theCurves;
1787 Handle(Geom2d_Curve) C2d;
1788 Handle(Geom2d_TrimmedCurve) CT2d;
1789 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1790 Standard_Real aTol = BRep_Tool::Tolerance(E);
1791 Handle(Geom_Curve) aC;
1792 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1794 TopoDS_Vertex V1,V2,VF,VL;
1795 TopExp::Vertices (E,V1,V2);
1798 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1799 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1800 aC = BRep_Tool::Curve(E,f,l);
1801 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1802 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1803 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1805 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1806 ( Abs(f-l) >= M_PI) ) {
1810 //-------------------------
1812 //-------------------------
1813 Cuter.Perform(CT2d);
1815 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1816 if (ForceCut == 0) {
1817 if (Cuter.UnModified()) {
1818 //-----------------------------
1819 // edge not modified => return.
1820 //-----------------------------
1823 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1824 theCurves.Append(Cuter.Value(k));
1826 } else if (ForceCut == 1) {
1827 if (Cuter.UnModified()) {
1828 CutCurve (CT2d, 2, theCurves);
1830 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1832 theCurves.Append(Cuter.Value(k));
1834 } else if (ForceCut == 2) {
1835 if (Cuter.UnModified()) {
1836 CutCurve (CT2d, 3, theCurves);
1838 if (Cuter.NbCurves() == 2) {
1840 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1842 if (CC->LastParameter() > (l+f)/2.) {
1843 CutCurve (CC, 2, theCurves);
1844 theCurves.Append(Cuter.Value(2));
1846 theCurves.Append(CC);
1847 CutCurve (Cuter.Value(2), 2, theCurves);
1850 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1851 theCurves.Append(Cuter.Value(k));
1856 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1858 //--------------------------------------
1859 // Creation of cut edges.
1860 //--------------------------------------
1863 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1865 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1867 if (k == theCurves.Length()) {VL = V2;}
1869 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1870 gp_Pnt P = aC->Value(CC->LastParameter());
1872 VL = BRepLib_MakeVertex(P);
1873 B.UpdateVertex(VL, aTol);
1874 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1876 TopoDS_Shape aLocalShape = E.EmptyCopied();
1877 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1878 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1879 NE.Orientation(TopAbs_FORWARD);
1880 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1881 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1882 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1883 Cuts.Append(NE.Oriented(E.Orientation()));
1887 return theCurves.Length();
1890 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1891 //=======================================================================
1892 //function : CutCurve
1894 //=======================================================================
1896 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1897 const Standard_Integer nbParts,
1898 TColGeom2d_SequenceOfCurve& theCurves)
1900 Handle(Geom2d_TrimmedCurve) TrimC;
1901 Standard_Real UF,UL,UC;
1904 Standard_Real PTol = Precision::PConfusion()*10;
1905 Standard_Real Tol = Precision::Confusion()*10;
1906 Standard_Boolean YaCut = Standard_False;
1908 UF = C->FirstParameter();
1909 UL = C->LastParameter ();
1913 Step = (UL - UF)/nbParts;
1915 for (Standard_Integer i = 1; i < nbParts; i++) {
1920 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1921 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1924 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1925 theCurves.Append(TrimC);
1928 YaCut = Standard_True;
1932 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1933 theCurves.Append(TrimC);
1935 theCurves.Append(C);
1937 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1939 //=======================================================================
1940 //function : MakeCircle
1942 //=======================================================================
1944 void MakeCircle (const TopoDS_Edge& E,
1945 const TopoDS_Vertex& V,
1946 const TopoDS_Face& F,
1947 const Standard_Real Offset,
1948 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1949 const Handle(Geom_Plane)& RefPlane)
1951 // evaluate the Axis of the Circle.
1953 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1957 if (E.Orientation() == TopAbs_FORWARD) {
1961 else GC->D1(f,P,DX);
1963 gp_Ax2d Axis(P,gp_Dir2d(DX));
1964 Handle(Geom2d_Circle) Circ
1965 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1967 // Bind the edges in my Map.
1968 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1969 TopTools_ListOfShape LL;
1976 if ( AffichGeom && !OE.IsNull()) {
1978 sprintf(name,"OFFSET_%d",++NbOFFSET);
1979 DBRep::Set(name,OE);
1985 //=======================================================================
1986 //function : MakeOffset
1988 //=======================================================================
1990 void MakeOffset (const TopoDS_Edge& E,
1991 const TopoDS_Face& F,
1992 const Standard_Real Offset,
1993 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1994 const Handle(Geom_Plane)& RefPlane,
1995 const Standard_Boolean IsOpenResult,
1996 const GeomAbs_JoinType theJoinType,
1997 const TopoDS_Vertex * Ends)
2000 Standard_Real anOffset = Offset;
2002 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
2004 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2005 Handle(Geom2d_Curve) G2dOC;
2007 Standard_Boolean ToExtendFirstPar = Standard_True;
2008 Standard_Boolean ToExtendLastPar = Standard_True;
2011 TopoDS_Vertex V1, V2;
2012 TopExp::Vertices(E, V1, V2);
2013 if (V1.IsSame(Ends[0]) ||
2015 ToExtendFirstPar = Standard_False;
2016 if (V2.IsSame(Ends[0]) ||
2018 ToExtendLastPar = Standard_False;
2021 Geom2dAdaptor_Curve AC(G2d,f,l);
2022 if ( AC.GetType() == GeomAbs_Circle) {
2023 // if the offset is greater otr equal to the radius and the side of the
2024 // concavity of the circle => edge null.
2025 gp_Circ2d C1(AC.Circle());
2026 gp_Ax22d axes( C1.Axis());
2027 gp_Dir2d Xd = axes.XDirection();
2028 gp_Dir2d Yd = axes.YDirection();
2029 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
2030 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
2032 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
2034 Handle(Geom2dAdaptor_HCurve) AHC =
2035 new Geom2dAdaptor_HCurve(G2d);
2036 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
2037 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
2039 Standard_Real Delta = 2*M_PI - l + f;
2040 if (theJoinType == GeomAbs_Arc)
2042 if (ToExtendFirstPar)
2044 if (ToExtendLastPar)
2047 else //GeomAbs_Intersection
2049 if (ToExtendFirstPar && ToExtendLastPar)
2051 Standard_Real old_l = l;
2052 f = old_l + Delta/2.;
2055 else if (ToExtendFirstPar)
2060 else if (ToExtendLastPar)
2065 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2068 else if (AC.GetType() == GeomAbs_Line) {
2069 Handle(Geom2dAdaptor_HCurve) AHC =
2070 new Geom2dAdaptor_HCurve(G2d);
2071 Adaptor3d_OffsetCurve Off(AHC,anOffset);
2072 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2073 Standard_Real Delta = (l - f);
2074 if (ToExtendFirstPar)
2076 if (theJoinType == GeomAbs_Arc)
2078 else //GeomAbs_Intersection
2079 f = -Precision::Infinite();
2081 if (ToExtendLastPar)
2083 if (theJoinType == GeomAbs_Arc)
2085 else //GeomAbs_Intersection
2086 l = Precision::Infinite();
2088 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2092 anOffset = -anOffset;
2093 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2094 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2098 // Bind the edges in my Map.
2099 if (!G2dOC.IsNull()) {
2100 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2101 OE.Orientation(E.Orientation());
2102 TopTools_ListOfShape LL;
2108 if (AffichGeom && !OE.IsNull()) {
2110 sprintf(name,"OFFSET_%d",++NbOFFSET);
2111 DBRep::Set(name,OE);
2112 //Standard_Real ii = 0;
2121 //=======================================================================
2122 //function : VertexFromNode
2124 //=======================================================================
2126 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
2127 const Standard_Real Offset,
2129 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2132 Standard_Boolean Status;
2133 Standard_Real Tol = Precision::Confusion();
2136 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2137 //------------------------------------------------
2138 // the Node gives a vertex on the offset
2139 //------------------------------------------------
2140 if (MapNodeVertex.IsBound(aNode)) {
2141 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2144 gp_Pnt P(PN.X(),PN.Y(),0.);
2146 B.UpdateVertex(VN,P, Precision::Confusion());
2147 MapNodeVertex.Bind(aNode,VN);
2149 Status = Standard_True;
2151 else Status = Standard_False;
2157 //=======================================================================
2158 //function : StoreInMap
2160 //=======================================================================
2162 void StoreInMap (const TopoDS_Shape& V1,
2163 const TopoDS_Shape& V2,
2164 TopTools_IndexedDataMapOfShapeShape& MapVV)
2166 TopoDS_Shape OldV = V1, NewV = V2;
2169 if (MapVV.Contains(V2))
2170 NewV = MapVV.FindFromKey(V2);
2172 if (MapVV.Contains(V1))
2173 MapVV.ChangeFromKey(V1) = NewV;
2175 for (i = 1; i <= MapVV.Extent(); i++)
2176 if (MapVV(i).IsSame(V1))
2179 MapVV.Add(V1, NewV);
2182 //=======================================================================
2183 //function : TrimEdge
2185 //=======================================================================
2187 void TrimEdge (const TopoDS_Edge& E,
2188 const TopoDS_Shape& ProE,
2189 const TopoDS_Face& AllSpine,
2190 const TopTools_ListOfShape& Detromp,
2191 TopTools_SequenceOfShape& TheVer,
2192 TColStd_SequenceOfReal& ThePar,
2193 TopTools_SequenceOfShape& S,
2194 TopTools_IndexedDataMapOfShapeShape& MapVV,
2195 const Standard_Integer IndOfE)
2197 Standard_Boolean Change = Standard_True;
2198 BRep_Builder TheBuilder;
2201 //-----------------------------------------------------------
2202 // Parse two sequences depending on the parameter on the edge.
2203 //-----------------------------------------------------------
2205 Change = Standard_False;
2206 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2207 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2208 ThePar.Exchange(i,i+1);
2209 TheVer.Exchange(i,i+1);
2210 Change = Standard_True;
2215 //----------------------------------------------------------
2216 // If a vertex is not in the proofing, it is eliminated.
2217 //----------------------------------------------------------
2218 if (!BRep_Tool::Degenerated(E)) {
2219 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2220 if ( DoubleOrNotInside (Detromp,
2221 TopoDS::Vertex(TheVer.Value(k)))) {
2229 //----------------------------------------------------------
2230 // If a vertex_double appears twice in the proofing
2231 // the vertex is removed.
2232 // otherwise preserve only one of its representations.
2233 //----------------------------------------------------------
2234 if (!BRep_Tool::Degenerated(E)) {
2235 Standard_Real aParTol = 2.0 * Precision::PConfusion();
2236 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2237 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2238 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= aParTol) {
2240 if(k+1 == TheVer.Length()) {
2241 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2246 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2251 if ( DoubleOrNotInside (Detromp,
2252 TopoDS::Vertex(TheVer.Value(k)))) {
2262 //-----------------------------------------------------------
2263 // Creation of edges.
2264 // the number of vertices should be even. The created edges
2265 // go from a vertex with uneven index i to vertex i+1;
2266 //-----------------------------------------------------------
2267 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2269 TopoDS_Shape aLocalShape = E.EmptyCopied();
2270 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2271 TopoDS_Vertex V1, V2;
2272 TopExp::Vertices(E, V1, V2);
2273 Standard_Real fpar, lpar;
2274 Handle(Geom_Surface) aPlane;
2275 TopLoc_Location aLoc;
2276 Handle(Geom2d_Curve) PCurve;
2277 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2278 //BRep_Tool::Range(E, fpar, lpar);
2280 Standard_Real TrPar1, TrPar2;
2281 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2283 if (IndOfE == 1) //first edge of open wire
2285 if (NewEdge.Orientation() == TopAbs_FORWARD)
2290 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2291 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2292 V1 = BRepLib_MakeVertex(TrPnt);
2294 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2295 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2296 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2303 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2304 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2305 V2 = BRepLib_MakeVertex(TrPnt);
2307 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2308 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2309 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2312 else //last edge of open wire
2314 if (NewEdge.Orientation() == TopAbs_FORWARD)
2319 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2320 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2321 V2 = BRepLib_MakeVertex(TrPnt);
2323 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2324 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2325 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2332 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2333 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2334 V1 = BRepLib_MakeVertex(TrPnt);
2336 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2337 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2338 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2345 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2346 TopoDS_Shape aLocalShape = E.EmptyCopied();
2347 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2348 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2350 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2351 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2352 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2355 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2356 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2360 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2366 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2367 DBRep::Set(name,NewEdge);
2372 Handle(Geom_Surface) Surf;
2373 Handle(Geom2d_Curve) C;
2374 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2376 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2377 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2378 Handle(DrawTrSurf_Curve2d) dr =
2379 new DrawTrSurf_Curve2d(C2d,Standard_False);
2380 dr->SetColor(Draw_bleu);
2390 //=======================================================================
2391 //function : IsInnerEdge
2393 //=======================================================================
2395 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2396 const TopoDS_Face& AllSpine,
2397 Standard_Real& TrPar1,
2398 Standard_Real& TrPar2)
2400 if (ProE.ShapeType() != TopAbs_EDGE)
2401 return Standard_False;
2403 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2405 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2406 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2407 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2409 const TopTools_ListOfShape& LE = VEmap(i);
2410 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2411 return Standard_False;
2414 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2415 return Standard_True;
2420 //=======================================================================
2421 //function : DoubleOrNotInside
2422 //purpose : return True if V appears twice in LV or is not inside.
2423 //=======================================================================
2425 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2426 const TopoDS_Vertex& V)
2428 Standard_Boolean Vu = Standard_False;
2429 TopTools_ListIteratorOfListOfShape it(LV);
2431 for ( ; it.More(); it.Next()) {
2432 if (V.IsSame(it.Value())) {
2433 if (Vu) return Standard_True;
2434 else Vu = Standard_True;
2437 if (Vu) return Standard_False;
2438 else return Standard_True;
2441 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2442 const TopoDS_Vertex& aVertex)
2444 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2445 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2446 PV2d.SetCoord( PV.X(), PV.Y() );
2448 Handle(Geom2d_Curve) PCurve;
2449 Handle( BRep_CurveRepresentation ) CurveRep =
2450 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2451 PCurve = CurveRep->PCurve();
2453 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2454 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2455 Pfirst = PCurve->Value(fpar);
2456 Plast = PCurve->Value(lpar);
2457 Pmid = PCurve->Value((fpar + lpar)*0.5);
2459 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2462 Standard_Real dist1 = Pfirst.Distance(PV2d);
2463 Standard_Real dist2 = Plast.Distance(PV2d);
2464 Standard_Real dist3 = Pmid.Distance(PV2d);
2466 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2467 return Standard_True;
2469 return Standard_False;
2472 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2473 const BRepMAT2d_BisectingLocus& Locus,
2474 const BRepMAT2d_LinkTopoBilo& Link,
2475 TopTools_ListOfShape& BadEdges)
2478 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2479 Standard_Real eps = Precision::Confusion();
2480 Standard_Real LimCurv = 1./Offset;
2482 TopTools_MapOfShape aMap;
2484 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2485 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2486 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2487 if (SE.ShapeType() == TopAbs_EDGE) {
2490 if (aMap.Contains(SE)) {
2491 //cout << "Edge is treated second time" << endl;
2496 TopoDS_Edge E = TopoDS::Edge(SE);
2502 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2505 Geom2dAdaptor_Curve AC(G2d,f,l);
2506 GeomAbs_CurveType aCType = AC.GetType();
2509 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2512 Standard_Boolean reverse = Standard_False;
2513 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2520 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2523 aCLProps.SetParameter(f);
2524 if(!aCLProps.IsTangentDefined()) {
2525 BadEdges.Append(SE);
2531 P = aCLProps.Value();
2532 Standard_Real Crv = aCLProps.Curvature();
2536 aCLProps.Tangent(N);
2537 Standard_Real x = N.Y(), y = -N.X();
2539 if (reverse) N.Reverse();
2540 aCLProps.CentreOfCurvature(Pc);
2541 gp_Vec2d Dir( P, Pc );
2542 if (N.Dot(Dir) > 0.) {
2543 if (LimCurv <= Crv + eps) {
2544 BadEdges.Append(SE);
2552 aCLProps.SetParameter(l);
2553 if(!aCLProps.IsTangentDefined()) {
2554 BadEdges.Append(SE);
2560 P = aCLProps.Value();
2561 Crv = aCLProps.Curvature();
2565 aCLProps.Tangent(N);
2566 Standard_Real x = N.Y(), y = -N.X();
2568 if (reverse) N.Reverse();
2569 aCLProps.CentreOfCurvature(Pc);
2570 gp_Vec2d Dir( P, Pc );
2571 if (N.Dot(Dir) > 0.) {
2572 if (LimCurv <= Crv + eps) {
2573 BadEdges.Append(SE);
2586 //=======================================================================
2587 //function : PerformCurve
2589 //=======================================================================
2591 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2593 TColgp_SequenceOfPnt& Points,
2594 const Adaptor3d_Curve& C,
2595 const Standard_Real Deflection,
2596 const Standard_Real U1,
2597 const Standard_Real U2,
2598 const Standard_Real EPSILON,
2599 const Standard_Integer Nbmin)
2601 Standard_Real UU1 = Min(U1, U2);
2602 Standard_Real UU2 = Max(U1, U2);
2606 C.D1(UU1,Pdeb,Ddeb);
2607 Parameters.Append(UU1);
2608 Points.Append(Pdeb);
2610 C.D1(UU2,Pfin,Dfin);
2612 const Standard_Real aDelta = UU2 - UU1;
2613 const Standard_Real aDist = Pdeb.Distance(Pfin);
2615 if((aDelta/aDist) > 5.0e-14)
2617 QuasiFleche(C,Deflection*Deflection,
2628 return Standard_True;
2630 //=======================================================================
2631 //function : QuasiFleche
2633 //=======================================================================
2635 static void QuasiFleche(const Adaptor3d_Curve& C,
2637 const Standard_Real Deflection2,
2638 const Standard_Real Udeb,
2641 const Standard_Real Ufin,
2644 const Standard_Integer Nbmin,
2645 const Standard_Real Eps,
2646 TColStd_SequenceOfReal& Parameters,
2647 TColgp_SequenceOfPnt& Points)
2649 Standard_Integer Ptslength = Points.Length();
2650 Standard_Real Udelta = Ufin-Udeb;
2655 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2663 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2664 Standard_Real theFleche=0;
2665 Standard_Boolean flecheok = Standard_False;
2667 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2668 Standard_Real N1 = Vdeb.SquareMagnitude();
2669 Standard_Real N2 = Vdelta.SquareMagnitude();
2670 if (N1 > Eps && N2 > Eps) {
2671 Standard_Real Normediff =
2673 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2674 if (Normediff > Eps) {
2676 theFleche = Normediff*Norme/64.;
2677 flecheok = Standard_True;
2682 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2683 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2684 theFleche = Pmid.SquareDistance(Pverif);
2687 if (theFleche < Deflection2) {
2688 Parameters.Append(Udeb+Udelta);
2689 Points.Append(Pdelta);
2692 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2704 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2709 Nbmin-(Points.Length()-Ptslength),