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 // The only contour which is a closed circle
237 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
238 Standard_Integer NbEdges = 0;
241 for (; exp.More(); exp.Next()) {
243 E = TopoDS::Edge(exp.Current());
244 if (NbEdges > 1) return Standard_False;
249 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
251 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
252 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
253 C = Ct->BasisCurve();
256 if ((C->IsKind(STANDARD_TYPE(Geom_Circle)) && BRep_Tool::IsClosed(E)) || //closed circle
259 Standard_Real anOffset = myOffset;
261 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(E, mySpine, f, l);
262 Handle(Geom2dAdaptor_HCurve) AHC = new Geom2dAdaptor_HCurve(aPCurve, f, l);
263 Handle(Geom2d_Curve) OC;
264 if (AHC->GetType() == GeomAbs_Line)
266 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
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) anOffset *= -1;
273 gp_Circ2d theCirc = AHC->Circle();
274 if (anOffset > 0. || Abs(anOffset) < theCirc.Radius())
275 OC = new Geom2d_Circle (theCirc.Position(), theCirc.Radius() + anOffset);
278 myIsDone = Standard_False;
279 return Standard_False;
284 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
285 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(aPCurve, f, l);
286 OC = new Geom2d_OffsetCurve( G2dT, anOffset);
288 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(mySpine);
289 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
290 myShape = BRepLib_MakeEdge(OC, aPlane, f, l);
291 BRepLib::BuildCurve3d(TopoDS::Edge(myShape));
293 myShape.Orientation(E.Orientation());
296 BRepAdaptor_Surface S(mySpine,0);
297 gp_Ax1 Nor = S.Plane().Axis();
299 gp_Vec Trans(Nor.Direction());
301 T.SetTranslation(Trans);
302 myShape.Move(TopLoc_Location(T));
305 TopTools_ListOfShape LL;
309 TopoDS_Edge myEdge = TopoDS::Edge(myShape);
310 myShape = BRepLib_MakeWire(myEdge);
312 myIsDone = Standard_True;
313 return Standard_True;
316 return Standard_False;
319 //=======================================================================
320 //function : BRepFill_OffsetWire
322 //=======================================================================
324 BRepFill_OffsetWire::BRepFill_OffsetWire()
325 : myIsOpenResult(Standard_False),
326 myIsDone(Standard_False)
331 //=======================================================================
332 //function : BRepFill_OffsetWire
334 //=======================================================================
336 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
337 const GeomAbs_JoinType Join,
338 const Standard_Boolean IsOpenResult)
340 Init(Spine,Join,IsOpenResult);
343 //=======================================================================
346 //=======================================================================
348 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
349 const GeomAbs_JoinType Join,
350 const Standard_Boolean IsOpenResult)
352 myIsDone = Standard_False;
353 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
354 mySpine = TopoDS::Face(aLocalShape);
355 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
357 myIsOpenResult = IsOpenResult;
361 //------------------------------------------------------------------
362 // cut the spine for bissectors.
363 //------------------------------------------------------------------
364 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
365 static BRepMAT2d_Explorer Exp;
367 Exp.Perform(mySpine);
369 // TopoDS_Face anOldSpine = mySpine;
371 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
374 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
376 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
377 Standard_Boolean Done;
378 if (KPartCircle(myWorkSpine,1.,myIsOpenResult,0.,aShape,aMap,Done)) return;
381 //-----------------------------------------------------
382 // Calculate the map of bissectors to the left.
383 // and Links Topology -> base elements of the map.
384 //-----------------------------------------------------
386 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
387 // static BRepMAT2d_Explorer Exp;
388 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
389 Exp.Perform(myWorkSpine);
390 myBilo.Compute(Exp, 1 ,MAT_Left, myJoinType, myIsOpenResult);
391 myLink.Perform(Exp,myBilo);
395 //=======================================================================
398 //=======================================================================
400 Standard_Boolean BRepFill_OffsetWire::IsDone() const
406 //=======================================================================
409 //=======================================================================
411 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
417 //=======================================================================
420 //=======================================================================
422 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
428 //=======================================================================
429 //function : GeneratedShapes
431 //=======================================================================
433 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
434 (const TopoDS_Shape& SpineShape)
437 if (!myMapSpine.IsEmpty()) {
438 // myMapSpine can be empty if passed by PerformWithBilo.
439 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
440 for (; it.More(); it.Next()) {
441 if (myMap.Contains(it.Key())) {
442 if (!myMap.Contains(it.Value())) {
443 TopTools_ListOfShape L;
444 myMap.Add(it.Value(),L);
446 if ( !it.Value().IsSame(it.Key())) {
447 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
448 //myMap.UnBind(it.Key());
449 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
450 TopTools_ListOfShape LastList;
451 LastList.Append(myMap(myMap.Extent()));
453 if (myMap.FindIndex(it.Key()) != 0)
454 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
457 if (myMap.Contains(it.Key().Reversed())) {
458 if (!myMap.Contains(it.Value().Reversed())) {
459 TopTools_ListOfShape L;
460 myMap.Add(it.Value().Reversed(),L);
462 if ( !it.Value().IsSame(it.Key())) {
463 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
464 //myMap.UnBind(it.Key().Reversed());
465 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
466 TopTools_ListOfShape LastList;
467 LastList.Append(myMap(myMap.Extent()));
469 if (myMap.FindIndex(it.Key().Reversed()) != 0)
470 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
475 myCallGen = Standard_True;
478 if (myMap.Contains(SpineShape)) {
479 return myMap.FindFromKey(SpineShape);
482 static TopTools_ListOfShape Empty;
488 //=======================================================================
489 //function : JoinType
491 //=======================================================================
493 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
498 //=======================================================================
501 //=======================================================================
503 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
504 const Standard_Real Alt)
506 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
510 myCallGen = Standard_False;
511 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone)) return;
513 TopoDS_Face oldWorkSpain = myWorkSpine;
515 TopTools_ListOfShape BadEdges;
516 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
518 if(!BadEdges.IsEmpty())
520 // Modification of myWorkSpine;
521 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
522 BRepTools_Substitution aSubst;
523 TopTools_ListIteratorOfListOfShape it(BadEdges);
524 TopTools_ListOfShape aL;
525 Standard_Real aDefl = .01 * Abs(Offset);
526 TColStd_SequenceOfReal Parameters;
527 TColgp_SequenceOfPnt Points;
529 for(; it.More(); it.Next()) {
533 const TopoDS_Shape& anE = it.Value();
535 TopoDS_Vertex Vf, Vl;
536 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
539 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
540 GeomAdaptor_Curve AC(G3d,f,l);
542 PerformCurve(Parameters, Points, AC, aDefl, f,
543 l, Precision::Confusion(), 2);
545 Standard_Integer NPnts = Points.Length();
548 //cout << NPnts << " points " << endl;
549 TopoDS_Vertex FV = Vf;
553 for(np = 2; np < NPnts; np++) {
554 gp_Pnt LP = Points(np);
555 LV = BRepLib_MakeVertex(LP);
556 newE = BRepLib_MakeEdge(FV, LV);
561 newE = BRepLib_MakeEdge(FV, LV);
566 //cout << " 2 points " << endl;
567 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
571 if (myMapSpine.IsBound( anE ))
573 TopTools_ListIteratorOfListOfShape newit( aL );
574 for (; newit.More(); newit.Next())
576 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
577 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
578 TopoDS_Vertex NewV1, NewV2;
579 EdgeVertices( NewEdge, NewV1, NewV2 );
580 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
581 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
583 myMapSpine.UnBind( anE );
586 aSubst.Substitute(anE, aL);
589 TopTools_DataMapOfShapeListOfShape wwmap;
590 TopoDS_Iterator itws( myWorkSpine );
591 for (; itws.More(); itws.Next())
593 TopoDS_Shape aWire = itws.Value();
594 aSubst.Build( aWire );
595 if (aSubst.IsCopied(aWire))
597 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
598 NewWire.Closed( aWire.Closed() );
599 TopTools_ListOfShape Lw;
600 Lw.Append( NewWire );
601 wwmap.Bind( aWire, Lw );
605 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
606 for (; itmap.More(); itmap.Next())
607 aSubst.Substitute( itmap.Key(), itmap.Value() );
609 aSubst.Build(myWorkSpine);
611 if(aSubst.IsCopied(myWorkSpine)) {
612 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
614 BRepMAT2d_Explorer newExp;
615 newExp.Perform(myWorkSpine);
616 BRepMAT2d_BisectingLocus newBilo;
617 BRepMAT2d_LinkTopoBilo newLink;
618 newBilo.Compute(newExp, 1, MAT_Left, myJoinType, myIsOpenResult);
620 if(!newBilo.IsDone())
623 myIsDone = Standard_False;
627 newLink.Perform(newExp,newBilo);
628 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
629 myWorkSpine = oldWorkSpain;
632 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
637 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
640 catch (Standard_Failure)//Every exception was caught.
643 myIsDone = Standard_False;
645 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
646 Standard_Failure::Caught()->Print(cout);
653 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
654 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
657 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
659 for (; anExp.More(); anExp.Next()) {
660 const TopoDS_Shape &aWire = anExp.Current();
662 if (!aWire.Closed()) {
664 myIsDone = Standard_False;
665 Standard_ConstructionError::Raise("Offset wire is not closed.");
669 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
672 //=======================================================================
675 //=======================================================================
677 void Compute (const TopoDS_Face& Spine,
678 TopoDS_Shape& aShape,
679 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
680 const Standard_Real Alt)
683 B.MakeCompound(TopoDS::Compound(aShape));
684 Standard_Real ALT = Alt;
685 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
687 T.SetTranslation(gp_Vec(0.,0.,ALT));
688 TopLoc_Location L(T);
690 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
691 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
692 TopoDS_Shape aLocalShape = CurW.Moved(L);
693 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
694 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
697 TopoDS_Iterator it1( CurW);
698 TopoDS_Iterator it2( NewW);
699 for ( ; it1.More(); it1.Next(), it2.Next()) {
700 TopTools_ListOfShape List;
701 List.Append(it2.Value());
702 Map.Add(it1.Value(), List);
707 //=======================================================================
708 //function : PerformWithBiLo
710 //=======================================================================
712 void BRepFill_OffsetWire::PerformWithBiLo
713 (const TopoDS_Face& Spine,
714 const Standard_Real Offset,
715 const BRepMAT2d_BisectingLocus& Locus,
716 BRepMAT2d_LinkTopoBilo& Link,
717 const GeomAbs_JoinType Join,
718 const Standard_Real Alt)
720 myIsDone = Standard_False;
721 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
722 myWorkSpine = TopoDS::Face(aLocalShape);
723 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
729 if (mySpine.IsNull()) {
730 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
731 mySpine = TopoDS::Face(aLocalShape);
732 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
736 if ( Abs(myOffset) < Precision::Confusion()) {
737 Compute(mySpine,myShape,myMap,Alt);
738 myIsDone = Standard_True;
742 //********************************
743 // Calculate for a non null offset
744 //********************************
745 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone))
748 BRep_Builder myBuilder;
749 myBuilder.MakeCompound(TopoDS::Compound(myShape));
751 //---------------------------------------------------------------------
752 // MapNodeVertex : associate to each node of the map (key1) and to
753 // each element of the profile (key2) a vertex (item).
754 // MapBis : all edges or vertices (item) generated by
755 // a bisectrice on a face or an edge (key) of revolution tubes.
756 // MapVerPar : Map of parameters of vertices on parallel edges
757 // the list contained in MapVerPar (E) corresponds to
758 // parameters on E of vertices contained in MapBis(E);
759 //---------------------------------------------------------------------
762 BRepFill_DataMapOfNodeShape MapNodeVertex;
763 TopTools_DataMapOfShapeSequenceOfShape MapBis;
764 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
766 TopTools_DataMapOfShapeShape EmptyMap;
767 TopTools_SequenceOfShape EmptySeq;
768 TopTools_ListOfShape EmptyList;
769 TColStd_SequenceOfReal EmptySeqOfReal;
771 Standard_Real ALT = Alt;
772 Handle(Geom_Plane) RefPlane =
773 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
774 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
775 RefPlane = Handle(Geom_Plane)::DownCast
776 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
778 //---------------------------------------------------------------
779 // Construction of Circles and OffsetCurves
780 //---------------------------------------------------------------
782 TopoDS_Vertex Ends [2];
786 TopoDS_Iterator iter(mySpine);
787 theWire = TopoDS::Wire(iter.Value());
788 TopExp::Vertices(theWire, Ends[0], Ends[1]);
791 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
792 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
793 TopoDS_Shape& PE = PEE ;
794 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
795 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
796 if (SE.ShapeType() == TopAbs_VERTEX) {
797 if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
798 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
799 myWorkSpine,myOffset,myMap,RefPlane);
802 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
803 myIsOpenResult, myJoinType, Ends);
813 cout << " End Construction of geometric primitives "<<endl;
819 //---------------------------------------------------
820 // Construction of offset vertices.
821 //---------------------------------------------------
822 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
823 Handle(MAT_Arc) CurrentArc;
824 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
825 Handle(Geom_Curve) CBis;
826 Standard_Boolean Reverse;
827 TopoDS_Edge CurrentEdge;
831 Standard_Integer j, k;
833 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
835 CurrentArc = Locus.Graph()->Arc(i);
836 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
842 sprintf(name,"BISSEC_%d",NbBISSEC++);
843 DrawTrSurf::Set(name,Bisec.Value());
848 //-------------------------------------------------------------------
849 // Return elements of the spine corresponding to separate basicElts.
850 //-------------------------------------------------------------------
851 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
852 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
854 TopTools_SequenceOfShape Vertices;
855 TColgp_SequenceOfPnt Params;
857 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
858 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
860 //-----------------------------------------------------------
861 // Return parallel edges on each face.
862 // If no offset generated => move to the next bissectrice.
863 //--------------------------------------------------------------
864 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
865 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
866 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
870 //-----------------------------------------------------------
871 // Construction of vertices corresponding to the node of the map.
872 // if they are on the offset.
873 //-----------------------------------------------------------
875 Handle(MAT_Node) Node1, Node2;
878 Node1 = CurrentArc->SecondNode();
879 Node2 = CurrentArc->FirstNode();
882 Node1 = CurrentArc->FirstNode();
883 Node2 = CurrentArc->SecondNode();
886 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
888 if (!Node1->Infinite()) {
889 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
890 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
891 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
892 // MapNodeVertex,VS);
894 if (!Node2->Infinite()) {
895 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
896 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
897 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
898 // MapNodeVertex,VE);
901 //---------------------------------------------
902 // Construction of geometries.
903 //---------------------------------------------
904 BRepFill_TrimEdgeTool Trim (Bisec,
905 Locus.GeomElt(CurrentArc->FirstElement()),
906 Locus.GeomElt(CurrentArc->SecondElement()),
909 //-----------------------------------------------------------
910 // Construction of vertices on edges parallel to the spine.
911 //-----------------------------------------------------------
913 Trim.IntersectWith(E [0], E [1], Params);
915 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
917 myBuilder.MakeVertex (VC);
918 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
919 gp_Pnt PVC(P2.X(),P2.Y(),0.);
921 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
925 Standard_Boolean Start = 1;
926 Trim.AddOrConfuse(Start, E[0], E[1], Params);
927 if (Params.Length() == Vertices.Length())
928 Vertices.SetValue(1,VS);
931 // the point was not found by IntersectWith
932 Vertices.Prepend(VS);
935 Standard_Boolean Start = 0;
936 Trim.AddOrConfuse(Start, E[0], E[1], Params);
937 if (Params.Length() == Vertices.Length())
938 Vertices.SetValue(Params.Length(),VE);
941 // the point was not found by IntersectWith
945 //------------------------------------------------------------
947 // Detromp allows to remove vertices on the offset
948 // corresponding to tangency zones
949 // Detromp ranks the vertices that limit
950 // the parts of the bissectrices located between the spine and the
952 //------------------------------------------------------------
953 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
954 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
957 UpdateDetromp (Detromp, S[0], S[1], Vertices, Params,
958 Bisec, StartOnEdge, EndOnEdge, Trim);
959 //----------------------------------------------
960 // Storage of vertices on parallel edges.
961 // fill MapBis and MapVerPar.
962 //----------------------------------------------
963 if (!Vertices.IsEmpty()) {
964 for (k = 0; k <= 1; k++) {
965 if (!MapBis.IsBound(E[k])) {
966 MapBis .Bind(E[k],EmptySeq);
967 MapVerPar.Bind(E[k],EmptySeqOfReal);
969 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
970 MapBis (E[k]).Append(Vertices.Value(ii));
971 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
972 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
977 //------------------------------------------------------------
978 // FOR COMPLETE CIRCLES. the parallel line can be contained
979 // in the zone without intersection with the border
981 // if myoffset is < distance of nodes the parallel can be valid.
982 //-------------------------------------------------------------
983 for (k = 0; k <= 1; k++) {
984 if (!MapBis.IsBound(E[k])) {
985 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
986 MapBis .Bind(E[k],EmptySeq);
987 MapVerPar.Bind(E[k],EmptySeqOfReal);
997 cout << " End Construction of vertices on offsets"<<endl;
1002 //----------------------------------
1003 // Construction of parallel edges.
1004 //----------------------------------
1005 TopTools_IndexedDataMapOfShapeShape MapVV;
1007 TopoDS_Shape CurrentSpine;
1009 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
1011 for (j = 1; j <= myMap.Extent(); j++) {
1012 CurrentSpine = myMap.FindKey(j);
1013 CurrentEdge = TopoDS::Edge(myMap(j).First());
1016 if (MapBis.IsBound(CurrentEdge)) {
1017 TopTools_SequenceOfShape S;
1018 if (!MapBis(CurrentEdge).IsEmpty()) {
1019 Standard_Integer IndOfE = 0;
1024 else if (j == myMap.Extent())
1027 TrimEdge (CurrentEdge,
1030 Detromp (CurrentSpine),
1031 MapBis (CurrentEdge) ,
1032 MapVerPar(CurrentEdge) ,
1034 for ( k = 1; k <= S.Length(); k++) {
1035 myMap(j).Append(S.Value(k));
1042 myMap(j).Append(CurrentEdge);
1047 Standard_Integer ind;
1048 for (ind = 1; ind <= MapVV.Extent(); ind++)
1050 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1051 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1052 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1053 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1054 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1055 TopTools_ListOfShape LV;
1056 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1057 BRepTools_Substitution aSubst;
1058 aSubst.Substitute( OldV, LV );
1059 for (j = 1; j <= myMap.Extent(); j++)
1061 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1062 for (; itl.More(); itl.Next())
1064 aSubst.Build(itl.Value());
1065 if (aSubst.IsCopied(itl.Value()))
1067 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1068 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1069 itl.Value() = listSh.First();
1070 itl.Value().Orientation(SaveOr);
1076 //----------------------------------
1077 // Construction of offset wires.
1078 //----------------------------------
1081 // Update vertices ( Constructed in the plane Z = 0) !!!
1082 TopTools_MapOfShape MapVertex;
1083 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1084 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1085 if ( MapVertex.Add(V)) {
1086 gp_Pnt P = BRep_Tool::Pnt(V);
1087 P = RefPlane->Value(P.X(),P.Y());
1088 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1092 // Construction of curves 3d.
1093 BRepLib::BuildCurves3d(myShape);
1095 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1096 for (; Explo.More(); Explo.Next())
1098 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1099 TopoDS_Vertex V1, V2;
1100 TopExp::Vertices( E, V1, V2 );
1101 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1102 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1104 TopLoc_Location loc;
1106 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1107 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1108 theCurve->Transform( loc.Transformation() );
1109 gp_Pnt f3d = theCurve->Value( f );
1110 gp_Pnt l3d = theCurve->Value( l );
1112 Standard_Real dist1, dist2;
1113 dist1 = f3d.Distance( TV1->Pnt() );
1114 dist2 = l3d.Distance( TV2->Pnt() );
1115 if (! MapVertex.Contains( V1 ))
1119 MapVertex.Add( V1 );
1122 TV1->UpdateTolerance( 1.5*dist1 );
1123 if (! MapVertex.Contains( V2 ))
1126 MapVertex.Add( V2 );
1129 TV2->UpdateTolerance( 1.5*dist2 );
1134 myIsDone = Standard_True;
1138 //=======================================================================
1139 //function : Generated
1141 //=======================================================================
1143 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1144 BRepFill_OffsetWire::Generated()
1150 //=======================================================================
1151 //function : PrepareSpine
1153 //=======================================================================
1155 void BRepFill_OffsetWire::PrepareSpine()
1158 TopTools_ListOfShape Cuts;
1159 TopTools_ListIteratorOfListOfShape IteCuts;
1160 TopoDS_Vertex V1,V2;
1162 myWorkSpine.Nullify();
1166 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1167 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1168 B.MakeFace(myWorkSpine,S,L,TolF);
1170 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1175 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1176 Standard_Integer ForcedCut = 0;
1177 Standard_Integer nbResEdges = -1;
1178 TopTools_IndexedMapOfShape EdgeMap;
1180 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1181 Standard_Integer nbEdges = EdgeMap.Extent();
1183 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
1185 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1187 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1189 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1190 EdgeVertices(E,V1,V2);
1191 myMapSpine.Bind(V1,V1);
1192 myMapSpine.Bind(V2,V2);
1196 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1197 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1198 if (nbEdges == 2 && nbResEdges == 0)
1200 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1201 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1203 if (Cuts.IsEmpty()) {
1205 myMapSpine.Bind(E,E);
1208 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1209 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1210 NE.Orientation(E.Orientation());
1212 myMapSpine.Bind(NE,E);
1213 EdgeVertices(NE,V1,V2);
1214 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1215 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1219 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1223 TopExp::Vertices(NW, aV1, aV2);
1225 NW.Closed(aV1.IsSame(aV2));
1227 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1228 B.Add(myWorkSpine, NW);
1234 DBRep::Set("WS",myWorkSpine);
1235 DBRep::Set("MS",mySpine);
1236 BRepTools::Write(myWorkSpine, "WS");
1237 BRepTools::Write(mySpine, "MS");
1244 //=======================================================================
1245 //function : UpdateDetromp
1246 //purpose : For each interval on bissectrice defined by parameters
1247 // test if the medium point is at a distance > offset
1248 // in this case vertices corresponding to the extremities of the interval
1249 // are ranked in the proofing.
1250 // => If the same vertex appears in the proofing, the
1251 // border of the zone of proximity is tangent to the offset .
1252 //=======================================================================
1254 void BRepFill_OffsetWire::UpdateDetromp (BRepFill_DataMapOfOrientedShapeListOfShape& Detromp,
1255 const TopoDS_Shape& Shape1,
1256 const TopoDS_Shape& Shape2,
1257 const TopTools_SequenceOfShape& Vertices,
1258 const TColgp_SequenceOfPnt& Params,
1259 const Bisector_Bisec& Bisec,
1260 const Standard_Boolean SOnE,
1261 const Standard_Boolean EOnE,
1262 const BRepFill_TrimEdgeTool& Trim) const
1264 Standard_Integer ii = 1;
1265 Standard_Real U1,U2;
1266 TopoDS_Vertex V1,V2;
1268 Handle(Geom2d_Curve) Bis = Bisec.Value();
1270 U1 = Bis->FirstParameter();
1273 // the first point of the bissectrice is on the offset
1274 V1 = TopoDS::Vertex(Vertices.Value(ii));
1278 while (ii <= Vertices.Length()) {
1279 U2 = Params.Value(ii).X();
1280 V2 = TopoDS::Vertex(Vertices.Value(ii));
1282 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1283 Standard_Boolean IsP_inside = Standard_True;
1284 if ((myJoinType != GeomAbs_Intersection) || EOnE)
1285 IsP_inside = Trim.IsInside(P);
1288 Detromp(Shape1).Append(V1);
1289 Detromp(Shape2).Append(V1);
1291 Detromp(Shape1).Append(V2);
1292 Detromp(Shape2).Append(V2);
1299 // test medium point between the last parameter and the end of the bissectrice.
1300 U2 = Bis->LastParameter();
1302 if (!Precision::IsInfinite(U2)) {
1303 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1304 Standard_Boolean IsP_inside = Standard_False;
1305 if (myJoinType == GeomAbs_Arc)
1306 IsP_inside = Trim.IsInside(P);
1309 Detromp(Shape1).Append(V1);
1310 Detromp(Shape2).Append(V1);
1316 Detromp(Shape1).Append(V1);
1317 Detromp(Shape2).Append(V1);
1321 //else if(myJoinType != GeomAbs_Arc)
1323 // if (!V1.IsNull()) {
1324 // Detromp(Shape1).Append(V1);
1325 // Detromp(Shape2).Append(V1);
1330 //=======================================================================
1331 //function : MakeWires
1333 //=======================================================================
1335 void BRepFill_OffsetWire::MakeWires()
1337 //--------------------------------------------------------
1338 // creation of a single list of created parallel edges.
1339 //--------------------------------------------------------
1340 TopTools_SequenceOfShape TheEdges;
1341 TopTools_ListOfShape TheWires;
1342 TopTools_ListIteratorOfListOfShape itl;
1343 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1344 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1345 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1346 TopoDS_Vertex V1,V2,VF,CV;
1349 for (i = 1; i <= myMap.Extent(); i++) {
1350 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1351 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1352 TopExp::Vertices (E,V1,V2);
1353 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1354 continue; //remove small closed edges
1355 if (!MVE.Contains(V1)) {
1356 TopTools_ListOfShape empty;
1359 MVE.ChangeFromKey(V1).Append(E);
1360 if (!MVE.Contains(V2)) {
1361 TopTools_ListOfShape empty;
1364 MVE.ChangeFromKey(V2).Append(E);
1368 //--------------------------------------
1369 // Creation of parallel wires.
1370 //--------------------------------------
1374 // Standard_Integer NbEdges;
1375 // Standard_Boolean NewWire = Standard_True;
1376 // Standard_Boolean AddEdge = Standard_False;
1379 Standard_Boolean End;
1382 while (!MVE.IsEmpty()) {
1385 //MVEit.Initialize(MVE);
1386 for (i = 1; i <= MVE.Extent(); i++)
1387 if(MVE(i).Extent() == 1)
1390 //if(!MVEit.More()) MVEit.Initialize(MVE);
1391 if (i > MVE.Extent())
1394 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1395 CE = TopoDS::Edge(MVE(i).First());
1396 End = Standard_False;
1397 MVE.ChangeFromKey(CV).RemoveFirst();
1399 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1400 Standard_Boolean isClosed = Standard_False;
1402 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1405 //-------------------------------
1406 // Construction of a wire.
1407 //-------------------------------
1408 TopExp::Vertices(CE,V1,V2);
1409 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1413 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1414 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1415 isClosed = VF.IsSame(CV);
1416 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1417 End = Standard_True;
1419 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1420 TopTools_ListOfShape LastList;
1421 LastList.Append(MVE(MVE.Extent()));
1423 if (MVE.FindIndex(VF) != 0)
1424 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1428 if (MVE.FindFromKey(CV).Extent() > 2) {
1429 //cout <<"vertex on more that 2 edges in a face."<<endl;
1431 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1432 if (itl.Value().IsSame(CE)) {
1433 MVE.ChangeFromKey(CV).Remove(itl);
1437 if (!MVE.FindFromKey(CV).IsEmpty()) {
1438 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1439 MVE.ChangeFromKey(CV).RemoveFirst();
1441 if (MVE.FindFromKey(CV).IsEmpty())
1444 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1445 TopTools_ListOfShape LastList;
1446 LastList.Append(MVE(MVE.Extent()));
1448 if (MVE.FindIndex(CV) != 0)
1449 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1453 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1454 // NW.Closed(Standard_True);
1455 NW.Closed(isClosed);
1456 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1457 TheWires.Append(NW);
1461 // -- if only one wire : myShape is a Wire
1462 // -- if several wires : myShape is a Compound.
1463 if ( TheWires.Extent() == 1) {
1464 myShape = TheWires.First();
1469 TopTools_ListIteratorOfListOfShape it(TheWires);
1470 for ( ; it.More(); it.Next()) {
1471 B.Add(R, it.Value());
1478 //=======================================================================
1479 //function : FixHoles
1481 //=======================================================================
1483 void BRepFill_OffsetWire::FixHoles()
1485 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1487 Standard_Real MaxTol = 0.;
1491 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1492 for (; Explo.More(); Explo.Next())
1494 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1495 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1501 Explo.Init( myShape, TopAbs_WIRE );
1502 for (; Explo.More(); Explo.Next())
1504 TopoDS_Shape aWire = Explo.Current();
1505 // Remove duplicated edges
1506 TopTools_DataMapOfShapeListOfShape EEmap;
1507 TopoDS_Iterator it( aWire );
1508 for (; it.More(); it.Next())
1510 const TopoDS_Shape& anEdge = it.Value();
1511 if (! EEmap.IsBound( anEdge ))
1513 TopTools_ListOfShape LE;
1514 EEmap.Bind( anEdge, LE );
1517 EEmap(anEdge).Append( anEdge );
1519 aWire.Free( Standard_True );
1520 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1521 for (; mapit.More(); mapit.Next())
1523 const TopTools_ListOfShape& LE = mapit.Value();
1524 TopTools_ListIteratorOfListOfShape itl( LE );
1525 for (; itl.More(); itl.Next())
1526 BB.Remove( aWire, itl.Value() );
1530 ClosedWires.Append( aWire );
1532 UnclosedWires.Append( aWire );
1535 while (!UnclosedWires.IsEmpty())
1537 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1538 TopoDS_Vertex Vf, Vl;
1539 TopExp::Vertices( Base, Vf, Vl );
1540 if(Vf.IsNull() || Vl.IsNull())
1542 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1544 BRepTools::Write(Base, "Base");
1548 Pf = BRep_Tool::Pnt(Vf);
1549 Pl = BRep_Tool::Pnt(Vl);
1550 Standard_Real DistF = RealLast(), DistL = RealLast();
1551 Standard_Integer IndexF = 1, IndexL = 1;
1552 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1553 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1555 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1556 TopoDS_Vertex V1, V2;
1557 TopExp::Vertices( aWire, V1, V2 );
1559 if(V1.IsNull() || V2.IsNull())
1561 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1563 BRepTools::Write(Base, "Base");
1565 sprintf(name,"Wire_%d",i);
1566 BRepTools::Write(aWire, name);
1571 P1 = BRep_Tool::Pnt(V1);
1572 P2 = BRep_Tool::Pnt(V2);
1573 Standard_Real dist = Pf.Distance( P1 );
1578 IsFirstF = Standard_True;
1580 dist = Pf.Distance( P2 );
1585 IsFirstF = Standard_False;
1587 dist = Pl.Distance( P1 );
1592 IsFirstL = Standard_True;
1594 dist = Pl.Distance( P2 );
1599 IsFirstL = Standard_False;
1602 TopoDS_Wire theWire;
1603 TopoDS_Edge theEdge;
1604 TopoDS_Vertex theVertex;
1605 Standard_Real CommonTol;
1606 Standard_Boolean TryToClose = Standard_True;
1607 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1619 TryToClose = Standard_False;
1621 if (DistF <= MaxTol)
1623 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1624 TopoDS_Vertex V1, V2;
1625 TopExp::Vertices( theWire, V1, V2 );
1626 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1627 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1628 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1629 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1630 TopoDS_Iterator it( theWire );
1631 for (; it.More(); it.Next())
1633 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1634 if (IsFirstF) anEdge.Reverse();
1635 if (!anEdge.IsSame( theEdge ))
1636 BB.Add( Base, anEdge );
1638 theVertex = (IsFirstF)? V1 : V2;
1639 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1640 if (DistF <= CommonTol)
1642 theEdge.Free( Standard_True );
1643 Vf.Orientation( theVertex.Orientation() );
1644 BB.Remove( theEdge, theVertex );
1645 BB.Add( theEdge, Vf );
1646 BB.UpdateVertex( Vf, CommonTol );
1647 if (IsFirstF) theEdge.Reverse();
1648 BB.Add( Base, theEdge );
1652 if (IsFirstF) theEdge.Reverse();
1653 BB.Add( Base, theEdge );
1654 // Creating new edge from theVertex to Vf
1655 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1656 BB.Add( Base, NewEdge );
1659 if (DistL <= MaxTol && IndexL != IndexF)
1661 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1662 TopoDS_Vertex V1, V2;
1663 TopExp::Vertices( theWire, V1, V2 );
1664 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1665 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1666 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1667 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1668 TopoDS_Iterator it( theWire );
1669 for (; it.More(); it.Next())
1671 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1672 if (!IsFirstL) anEdge.Reverse();
1673 if (!anEdge.IsSame( theEdge ))
1674 BB.Add( Base, anEdge );
1676 theVertex = (IsFirstL)? V1 : V2;
1677 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1678 if (DistL <= CommonTol)
1680 theEdge.Free( Standard_True );
1681 Vl.Orientation( theVertex.Orientation() );
1682 BB.Remove( theEdge, theVertex );
1683 BB.Add( theEdge, Vl );
1684 BB.UpdateVertex( Vl, CommonTol );
1685 if (!IsFirstL) theEdge.Reverse();
1686 BB.Add( Base, theEdge );
1690 if (!IsFirstL) theEdge.Reverse();
1691 BB.Add( Base, theEdge );
1692 // Creating new edge from Vl to theVertex
1693 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1694 BB.Add( Base, NewEdge );
1697 // Check if it is possible to close resulting wire
1700 TopExp::Vertices( Base, Vf, Vl );
1701 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1702 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1703 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1704 TopoDS_Edge Efirst, Elast;
1705 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1706 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1707 Pf = BRep_Tool::Pnt(Vf);
1708 Pl = BRep_Tool::Pnt(Vl);
1709 Standard_Real Dist = Pf.Distance(Pl);
1710 if (Dist <= CommonTol)
1712 Elast.Free( Standard_True );
1713 Vf.Orientation( Vl.Orientation() );
1714 BB.Remove( Elast, Vl );
1715 BB.Add( Elast, Vf );
1716 BB.UpdateVertex( Vf, CommonTol );
1717 Base.Closed( Standard_True );
1719 else if (Dist <= MaxTol)
1721 // Creating new edge from Vl to Vf
1722 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1723 BB.Add( Base, NewEdge );
1724 Base.Closed( Standard_True );
1727 // Updating sequences ClosedWires and UnclosedWires
1728 if (DistF <= MaxTol)
1729 UnclosedWires.Remove( IndexF );
1730 if (DistL <= MaxTol && IndexL != IndexF)
1732 if (DistF <= MaxTol && IndexL > IndexF)
1734 UnclosedWires.Remove( IndexL );
1738 ClosedWires.Append( Base );
1739 UnclosedWires.Remove( 1 );
1741 else if (DistF > MaxTol && DistL > MaxTol)
1743 IsolatedWires.Append( Base );
1744 UnclosedWires.Remove( 1 );
1749 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1751 if (!ClosedWires.IsEmpty())
1752 myShape = ClosedWires.First();
1754 myShape = IsolatedWires.First();
1759 BB.MakeCompound( R );
1760 for (i = 1; i <= ClosedWires.Length(); i++)
1761 BB.Add( R, ClosedWires(i) );
1762 for (i = 1; i <= IsolatedWires.Length(); i++)
1763 BB.Add( R, IsolatedWires(i) );
1768 //=======================================================================
1769 //function : CutEdge
1770 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1771 // So, closed circles are cut in two.
1772 // If <Cuts> is empty, the edge is not modified.
1773 // The first and the last vertex of the initial edge
1774 // belong to the first and the last parts respectively.
1775 //=======================================================================
1776 Standard_Integer CutEdge (const TopoDS_Edge& E,
1777 const TopoDS_Face& F,
1778 Standard_Integer ForceCut,
1779 TopTools_ListOfShape& Cuts)
1782 MAT2d_CutCurve Cuter;
1783 TColGeom2d_SequenceOfCurve theCurves;
1785 Handle(Geom2d_Curve) C2d;
1786 Handle(Geom2d_TrimmedCurve) CT2d;
1787 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1788 Standard_Real aTol = BRep_Tool::Tolerance(E);
1789 Handle(Geom_Curve) aC;
1790 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1792 TopoDS_Vertex V1,V2,VF,VL;
1793 TopExp::Vertices (E,V1,V2);
1796 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1797 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1798 aC = BRep_Tool::Curve(E,f,l);
1799 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1800 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1801 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1803 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1804 ( Abs(f-l) >= M_PI) ) {
1808 //-------------------------
1810 //-------------------------
1811 Cuter.Perform(CT2d);
1813 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1814 if (ForceCut == 0) {
1815 if (Cuter.UnModified()) {
1816 //-----------------------------
1817 // edge not modified => return.
1818 //-----------------------------
1821 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1822 theCurves.Append(Cuter.Value(k));
1824 } else if (ForceCut == 1) {
1825 if (Cuter.UnModified()) {
1826 CutCurve (CT2d, 2, theCurves);
1828 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1830 theCurves.Append(Cuter.Value(k));
1832 } else if (ForceCut == 2) {
1833 if (Cuter.UnModified()) {
1834 CutCurve (CT2d, 3, theCurves);
1836 if (Cuter.NbCurves() == 2) {
1838 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1840 if (CC->LastParameter() > (l+f)/2.) {
1841 CutCurve (CC, 2, theCurves);
1842 theCurves.Append(Cuter.Value(2));
1844 theCurves.Append(CC);
1845 CutCurve (Cuter.Value(2), 2, theCurves);
1848 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1849 theCurves.Append(Cuter.Value(k));
1854 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1856 //--------------------------------------
1857 // Creation of cut edges.
1858 //--------------------------------------
1861 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1863 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1865 if (k == theCurves.Length()) {VL = V2;}
1867 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1868 gp_Pnt P = aC->Value(CC->LastParameter());
1870 VL = BRepLib_MakeVertex(P);
1871 B.UpdateVertex(VL, aTol);
1872 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1874 TopoDS_Shape aLocalShape = E.EmptyCopied();
1875 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1876 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1877 NE.Orientation(TopAbs_FORWARD);
1878 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1879 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1880 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1881 Cuts.Append(NE.Oriented(E.Orientation()));
1885 return theCurves.Length();
1888 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1889 //=======================================================================
1890 //function : CutCurve
1892 //=======================================================================
1894 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1895 const Standard_Integer nbParts,
1896 TColGeom2d_SequenceOfCurve& theCurves)
1898 Handle(Geom2d_TrimmedCurve) TrimC;
1899 Standard_Real UF,UL,UC;
1902 Standard_Real PTol = Precision::PConfusion()*10;
1903 Standard_Real Tol = Precision::Confusion()*10;
1904 Standard_Boolean YaCut = Standard_False;
1906 UF = C->FirstParameter();
1907 UL = C->LastParameter ();
1911 Step = (UL - UF)/nbParts;
1913 for (Standard_Integer i = 1; i < nbParts; i++) {
1918 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1919 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1922 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1923 theCurves.Append(TrimC);
1926 YaCut = Standard_True;
1930 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1931 theCurves.Append(TrimC);
1933 theCurves.Append(C);
1935 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1937 //=======================================================================
1938 //function : MakeCircle
1940 //=======================================================================
1942 void MakeCircle (const TopoDS_Edge& E,
1943 const TopoDS_Vertex& V,
1944 const TopoDS_Face& F,
1945 const Standard_Real Offset,
1946 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1947 const Handle(Geom_Plane)& RefPlane)
1949 // evaluate the Axis of the Circle.
1951 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1955 if (E.Orientation() == TopAbs_FORWARD) {
1959 else GC->D1(f,P,DX);
1961 gp_Ax2d Axis(P,gp_Dir2d(DX));
1962 Handle(Geom2d_Circle) Circ
1963 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1965 // Bind the edges in my Map.
1966 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1967 TopTools_ListOfShape LL;
1974 if ( AffichGeom && !OE.IsNull()) {
1976 sprintf(name,"OFFSET_%d",++NbOFFSET);
1977 DBRep::Set(name,OE);
1983 //=======================================================================
1984 //function : MakeOffset
1986 //=======================================================================
1988 void MakeOffset (const TopoDS_Edge& E,
1989 const TopoDS_Face& F,
1990 const Standard_Real Offset,
1991 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1992 const Handle(Geom_Plane)& RefPlane,
1993 const Standard_Boolean IsOpenResult,
1994 const GeomAbs_JoinType theJoinType,
1995 const TopoDS_Vertex * Ends)
1998 Standard_Real anOffset = Offset;
2000 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
2002 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2003 Handle(Geom2d_Curve) G2dOC;
2005 Standard_Boolean ToExtendFirstPar = Standard_True;
2006 Standard_Boolean ToExtendLastPar = Standard_True;
2009 TopoDS_Vertex V1, V2;
2010 TopExp::Vertices(E, V1, V2);
2011 if (V1.IsSame(Ends[0]) ||
2013 ToExtendFirstPar = Standard_False;
2014 if (V2.IsSame(Ends[0]) ||
2016 ToExtendLastPar = Standard_False;
2019 Geom2dAdaptor_Curve AC(G2d,f,l);
2020 if ( AC.GetType() == GeomAbs_Circle) {
2021 // if the offset is greater otr equal to the radius and the side of the
2022 // concavity of the circle => edge null.
2023 gp_Circ2d C1(AC.Circle());
2024 gp_Ax22d axes( C1.Axis());
2025 gp_Dir2d Xd = axes.XDirection();
2026 gp_Dir2d Yd = axes.YDirection();
2027 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
2028 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
2030 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
2032 Handle(Geom2dAdaptor_HCurve) AHC =
2033 new Geom2dAdaptor_HCurve(G2d);
2034 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
2035 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
2037 Standard_Real Delta = 2*M_PI - l + f;
2038 if (theJoinType == GeomAbs_Arc)
2040 if (ToExtendFirstPar)
2042 if (ToExtendLastPar)
2045 else //GeomAbs_Intersection
2047 if (ToExtendFirstPar && ToExtendLastPar)
2049 Standard_Real old_l = l;
2050 f = old_l + Delta/2.;
2053 else if (ToExtendFirstPar)
2058 else if (ToExtendLastPar)
2063 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2066 else if (AC.GetType() == GeomAbs_Line) {
2067 Handle(Geom2dAdaptor_HCurve) AHC =
2068 new Geom2dAdaptor_HCurve(G2d);
2069 Adaptor3d_OffsetCurve Off(AHC,anOffset);
2070 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2071 Standard_Real Delta = (l - f);
2072 if (ToExtendFirstPar)
2074 if (theJoinType == GeomAbs_Arc)
2076 else //GeomAbs_Intersection
2077 f = -Precision::Infinite();
2079 if (ToExtendLastPar)
2081 if (theJoinType == GeomAbs_Arc)
2083 else //GeomAbs_Intersection
2084 l = Precision::Infinite();
2086 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2090 anOffset = -anOffset;
2091 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2092 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2096 // Bind the edges in my Map.
2097 if (!G2dOC.IsNull()) {
2098 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2099 OE.Orientation(E.Orientation());
2100 TopTools_ListOfShape LL;
2106 if (AffichGeom && !OE.IsNull()) {
2108 sprintf(name,"OFFSET_%d",++NbOFFSET);
2109 DBRep::Set(name,OE);
2110 //Standard_Real ii = 0;
2119 //=======================================================================
2120 //function : VertexFromNode
2122 //=======================================================================
2124 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
2125 const Standard_Real Offset,
2127 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2130 Standard_Boolean Status;
2131 Standard_Real Tol = Precision::Confusion();
2134 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2135 //------------------------------------------------
2136 // the Node gives a vertex on the offset
2137 //------------------------------------------------
2138 if (MapNodeVertex.IsBound(aNode)) {
2139 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2142 gp_Pnt P(PN.X(),PN.Y(),0.);
2144 B.UpdateVertex(VN,P, Precision::Confusion());
2145 MapNodeVertex.Bind(aNode,VN);
2147 Status = Standard_True;
2149 else Status = Standard_False;
2155 //=======================================================================
2156 //function : StoreInMap
2158 //=======================================================================
2160 void StoreInMap (const TopoDS_Shape& V1,
2161 const TopoDS_Shape& V2,
2162 TopTools_IndexedDataMapOfShapeShape& MapVV)
2164 TopoDS_Shape OldV = V1, NewV = V2;
2167 if (MapVV.Contains(V2))
2168 NewV = MapVV.FindFromKey(V2);
2170 if (MapVV.Contains(V1))
2171 MapVV.ChangeFromKey(V1) = NewV;
2173 for (i = 1; i <= MapVV.Extent(); i++)
2174 if (MapVV(i).IsSame(V1))
2177 MapVV.Add(V1, NewV);
2180 //=======================================================================
2181 //function : TrimEdge
2183 //=======================================================================
2185 void TrimEdge (const TopoDS_Edge& E,
2186 const TopoDS_Shape& ProE,
2187 const TopoDS_Face& AllSpine,
2188 const TopTools_ListOfShape& Detromp,
2189 TopTools_SequenceOfShape& TheVer,
2190 TColStd_SequenceOfReal& ThePar,
2191 TopTools_SequenceOfShape& S,
2192 TopTools_IndexedDataMapOfShapeShape& MapVV,
2193 const Standard_Integer IndOfE)
2195 Standard_Boolean Change = Standard_True;
2196 BRep_Builder TheBuilder;
2199 //-----------------------------------------------------------
2200 // Parse two sequences depending on the parameter on the edge.
2201 //-----------------------------------------------------------
2203 Change = Standard_False;
2204 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2205 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2206 ThePar.Exchange(i,i+1);
2207 TheVer.Exchange(i,i+1);
2208 Change = Standard_True;
2213 //----------------------------------------------------------
2214 // If a vertex is not in the proofing, it is eliminated.
2215 //----------------------------------------------------------
2216 if (!BRep_Tool::Degenerated(E)) {
2217 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2218 if ( DoubleOrNotInside (Detromp,
2219 TopoDS::Vertex(TheVer.Value(k)))) {
2227 //----------------------------------------------------------
2228 // If a vertex_double appears twice in the proofing
2229 // the vertex is removed.
2230 // otherwise preserve only one of its representations.
2231 //----------------------------------------------------------
2232 if (!BRep_Tool::Degenerated(E)) {
2233 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2234 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2236 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2238 if(k+1 == TheVer.Length()) {
2239 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2244 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2249 if ( DoubleOrNotInside (Detromp,
2250 TopoDS::Vertex(TheVer.Value(k)))) {
2260 //-----------------------------------------------------------
2261 // Creation of edges.
2262 // the number of vertices should be even. The created edges
2263 // go from a vertex with uneven index i to vertex i+1;
2264 //-----------------------------------------------------------
2265 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2267 TopoDS_Shape aLocalShape = E.EmptyCopied();
2268 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2269 TopoDS_Vertex V1, V2;
2270 TopExp::Vertices(E, V1, V2);
2271 Standard_Real fpar, lpar;
2272 Handle(Geom_Surface) aPlane;
2273 TopLoc_Location aLoc;
2274 Handle(Geom2d_Curve) PCurve;
2275 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2276 //BRep_Tool::Range(E, fpar, lpar);
2278 Standard_Real TrPar1, TrPar2;
2279 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2281 if (IndOfE == 1) //first edge of open wire
2283 if (NewEdge.Orientation() == TopAbs_FORWARD)
2288 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2289 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2290 V1 = BRepLib_MakeVertex(TrPnt);
2292 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2293 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2294 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2301 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2302 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2303 V2 = BRepLib_MakeVertex(TrPnt);
2305 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2306 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2307 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2310 else //last edge of open wire
2312 if (NewEdge.Orientation() == TopAbs_FORWARD)
2317 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2318 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2319 V2 = BRepLib_MakeVertex(TrPnt);
2321 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2322 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2323 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2330 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2331 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2332 V1 = BRepLib_MakeVertex(TrPnt);
2334 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2335 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2336 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2343 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2344 TopoDS_Shape aLocalShape = E.EmptyCopied();
2345 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2346 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2348 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2349 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2350 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2353 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2354 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2358 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2364 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2365 DBRep::Set(name,NewEdge);
2370 Handle(Geom_Surface) Surf;
2371 Handle(Geom2d_Curve) C;
2372 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2374 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2375 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2376 Handle(DrawTrSurf_Curve2d) dr =
2377 new DrawTrSurf_Curve2d(C2d,Standard_False);
2378 dr->SetColor(Draw_bleu);
2388 //=======================================================================
2389 //function : IsInnerEdge
2391 //=======================================================================
2393 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2394 const TopoDS_Face& AllSpine,
2395 Standard_Real& TrPar1,
2396 Standard_Real& TrPar2)
2398 if (ProE.ShapeType() != TopAbs_EDGE)
2399 return Standard_False;
2401 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2403 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2404 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2405 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2407 const TopTools_ListOfShape& LE = VEmap(i);
2408 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2409 return Standard_False;
2412 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2413 return Standard_True;
2418 //=======================================================================
2419 //function : DoubleOrNotInside
2420 //purpose : return True if V appears twice in LV or is not inside.
2421 //=======================================================================
2423 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2424 const TopoDS_Vertex& V)
2426 Standard_Boolean Vu = Standard_False;
2427 TopTools_ListIteratorOfListOfShape it(LV);
2429 for ( ; it.More(); it.Next()) {
2430 if (V.IsSame(it.Value())) {
2431 if (Vu) return Standard_True;
2432 else Vu = Standard_True;
2435 if (Vu) return Standard_False;
2436 else return Standard_True;
2439 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2440 const TopoDS_Vertex& aVertex)
2442 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2443 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2444 PV2d.SetCoord( PV.X(), PV.Y() );
2446 Handle(Geom2d_Curve) PCurve;
2447 Handle( BRep_CurveRepresentation ) CurveRep =
2448 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2449 PCurve = CurveRep->PCurve();
2451 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2452 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2453 Pfirst = PCurve->Value(fpar);
2454 Plast = PCurve->Value(lpar);
2455 Pmid = PCurve->Value((fpar + lpar)*0.5);
2457 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2460 Standard_Real dist1 = Pfirst.Distance(PV2d);
2461 Standard_Real dist2 = Plast.Distance(PV2d);
2462 Standard_Real dist3 = Pmid.Distance(PV2d);
2464 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2465 return Standard_True;
2467 return Standard_False;
2470 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2471 const BRepMAT2d_BisectingLocus& Locus,
2472 const BRepMAT2d_LinkTopoBilo& Link,
2473 TopTools_ListOfShape& BadEdges)
2476 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2477 Standard_Real eps = Precision::Confusion();
2478 Standard_Real LimCurv = 1./Offset;
2480 TopTools_MapOfShape aMap;
2482 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2483 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2484 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2485 if (SE.ShapeType() == TopAbs_EDGE) {
2488 if (aMap.Contains(SE)) {
2489 //cout << "Edge is treated second time" << endl;
2494 TopoDS_Edge E = TopoDS::Edge(SE);
2500 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2503 Geom2dAdaptor_Curve AC(G2d,f,l);
2504 GeomAbs_CurveType aCType = AC.GetType();
2507 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2510 Standard_Boolean reverse = Standard_False;
2511 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2518 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2521 aCLProps.SetParameter(f);
2522 if(!aCLProps.IsTangentDefined()) {
2523 BadEdges.Append(SE);
2529 P = aCLProps.Value();
2530 Standard_Real Crv = aCLProps.Curvature();
2534 aCLProps.Tangent(N);
2535 Standard_Real x = N.Y(), y = -N.X();
2537 if (reverse) N.Reverse();
2538 aCLProps.CentreOfCurvature(Pc);
2539 gp_Vec2d Dir( P, Pc );
2540 if (N.Dot(Dir) > 0.) {
2541 if (LimCurv <= Crv + eps) {
2542 BadEdges.Append(SE);
2550 aCLProps.SetParameter(l);
2551 if(!aCLProps.IsTangentDefined()) {
2552 BadEdges.Append(SE);
2558 P = aCLProps.Value();
2559 Crv = aCLProps.Curvature();
2563 aCLProps.Tangent(N);
2564 Standard_Real x = N.Y(), y = -N.X();
2566 if (reverse) N.Reverse();
2567 aCLProps.CentreOfCurvature(Pc);
2568 gp_Vec2d Dir( P, Pc );
2569 if (N.Dot(Dir) > 0.) {
2570 if (LimCurv <= Crv + eps) {
2571 BadEdges.Append(SE);
2584 //=======================================================================
2585 //function : PerformCurve
2587 //=======================================================================
2589 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2591 TColgp_SequenceOfPnt& Points,
2592 const Adaptor3d_Curve& C,
2593 const Standard_Real Deflection,
2594 const Standard_Real U1,
2595 const Standard_Real U2,
2596 const Standard_Real EPSILON,
2597 const Standard_Integer Nbmin)
2599 Standard_Real UU1 = Min(U1, U2);
2600 Standard_Real UU2 = Max(U1, U2);
2604 C.D1(UU1,Pdeb,Ddeb);
2605 Parameters.Append(UU1);
2606 Points.Append(Pdeb);
2608 C.D1(UU2,Pfin,Dfin);
2610 const Standard_Real aDelta = UU2 - UU1;
2611 const Standard_Real aDist = Pdeb.Distance(Pfin);
2613 if((aDelta/aDist) > 5.0e-14)
2615 QuasiFleche(C,Deflection*Deflection,
2626 return Standard_True;
2628 //=======================================================================
2629 //function : QuasiFleche
2631 //=======================================================================
2633 static void QuasiFleche(const Adaptor3d_Curve& C,
2635 const Standard_Real Deflection2,
2636 const Standard_Real Udeb,
2639 const Standard_Real Ufin,
2642 const Standard_Integer Nbmin,
2643 const Standard_Real Eps,
2644 TColStd_SequenceOfReal& Parameters,
2645 TColgp_SequenceOfPnt& Points)
2647 Standard_Integer Ptslength = Points.Length();
2648 Standard_Real Udelta = Ufin-Udeb;
2653 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2661 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2662 Standard_Real theFleche=0;
2663 Standard_Boolean flecheok = Standard_False;
2665 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2666 Standard_Real N1 = Vdeb.SquareMagnitude();
2667 Standard_Real N2 = Vdelta.SquareMagnitude();
2668 if (N1 > Eps && N2 > Eps) {
2669 Standard_Real Normediff =
2671 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2672 if (Normediff > Eps) {
2674 theFleche = Normediff*Norme/64.;
2675 flecheok = Standard_True;
2680 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2681 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2682 theFleche = Pmid.SquareDistance(Pverif);
2685 if (theFleche < Deflection2) {
2686 Parameters.Append(Udeb+Udelta);
2687 Points.Append(Pdelta);
2690 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2702 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2707 Nbmin-(Points.Length()-Ptslength),