1 // Created on: 1995-04-20
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
21 #include <BRepFill_OffsetWire.ixx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRepAdaptor_Surface.hxx>
26 #include <BRepFill_DataMapOfNodeShape.hxx>
27 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
28 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
29 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
30 #include <BRepFill_TrimEdgeTool.hxx>
31 #include <BRepLib.hxx>
32 #include <BRepLib_MakeVertex.hxx>
33 #include <BRepLib_MakeFace.hxx>
34 #include <BRepLib_MakeWire.hxx>
35 #include <BRepLib_MakeEdge.hxx>
36 #include <BRepTools.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRep_TEdge.hxx>
40 #include <BRep_CurveRepresentation.hxx>
41 #include <BRep_GCurve.hxx>
42 #include <BRepTools_WireExplorer.hxx>
43 #include <BRepMAT2d_Explorer.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
45 #include <Geom2dAdaptor_HCurve.hxx>
46 #include <Adaptor3d_OffsetCurve.hxx>
47 #include <Adaptor3d_Curve.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom2d_Curve.hxx>
51 #include <Geom2d_Circle.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <Geom2d_TrimmedCurve.hxx>
54 #include <Geom2d_OffsetCurve.hxx>
55 #include <GeomAPI.hxx>
56 #include <Geom_TrimmedCurve.hxx>
57 #include <Geom_Circle.hxx>
58 #include <Geom_Line.hxx>
59 #include <Geom_OffsetCurve.hxx>
60 #include <MAT_Arc.hxx>
61 #include <MAT_Node.hxx>
62 #include <MAT_Graph.hxx>
63 #include <MAT2d_CutCurve.hxx>
64 #include <Precision.hxx>
65 #include <Standard_NotImplemented.hxx>
66 #include <TColgp_SequenceOfPnt.hxx>
67 #include <TColStd_SequenceOfReal.hxx>
70 #include <TopExp_Explorer.hxx>
72 #include <TopoDS_Wire.hxx>
73 #include <TopoDS_Compound.hxx>
74 #include <TopoDS_Iterator.hxx>
75 #include <TopTools_MapOfShape.hxx>
76 #include <TopTools_MapIteratorOfMapOfShape.hxx>
77 #include <TopTools_ListIteratorOfListOfShape.hxx>
78 #include <TopTools_DataMapOfShapeListOfShape.hxx>
79 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
80 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
81 #include <TopTools_SequenceOfShape.hxx>
82 #include <TopTools_ListOfShape.hxx>
83 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
84 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
90 #include <gp_Dir2d.hxx>
92 #include <BRep_TVertex.hxx>
93 #include <TopTools_IndexedMapOfShape.hxx>
94 #include <Geom2d_BSplineCurve.hxx>
95 #include <TColgp_Array1OfPnt2d.hxx>
96 #include <TColStd_Array1OfReal.hxx>
97 #include <TColStd_Array1OfInteger.hxx>
98 #include <BRepTools_Substitution.hxx>
99 #include <BRepLib_MakeVertex.hxx>
100 #include <Geom2dLProp_CLProps2d.hxx>
101 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
102 #include <Standard_ErrorHandler.hxx>
106 #include <DrawTrSurf.hxx>
107 #include <DrawTrSurf_Curve2d.hxx>
109 static Standard_Boolean AffichGeom = Standard_False;
110 static Standard_Boolean Affich2d = Standard_False;
111 static Standard_Boolean AffichEdge = Standard_False;
112 static Standard_Integer NbTRIMEDGES = 0;
113 static Standard_Integer NbOFFSET = 0;
114 static Standard_Integer NbEDGES = 0;
115 static Standard_Integer NbBISSEC = 0;
118 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
120 static void QuasiFleche(const Adaptor3d_Curve& C,
121 const Standard_Real Deflection2,
122 const Standard_Real Udeb,
125 const Standard_Real Ufin,
128 const Standard_Integer Nbmin,
129 const Standard_Real Eps,
130 TColStd_SequenceOfReal& Parameters,
131 TColgp_SequenceOfPnt& Points);
133 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
134 TColgp_SequenceOfPnt& Points,
135 const Adaptor3d_Curve& C,
136 const Standard_Real Deflection,
137 const Standard_Real U1,
138 const Standard_Real U2,
139 const Standard_Real EPSILON,
140 const Standard_Integer Nbmin);
142 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
143 const BRepMAT2d_BisectingLocus& Locus,
144 const BRepMAT2d_LinkTopoBilo& Link,
145 TopTools_ListOfShape& BadEdges);
147 static Standard_Integer CutEdge (const TopoDS_Edge& E,
148 const TopoDS_Face& F,
149 Standard_Integer ForceCut,
150 TopTools_ListOfShape& Cuts);
153 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
154 const Standard_Integer nbParts,
155 TColGeom2d_SequenceOfCurve& theCurves);
156 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
159 static void EdgeVertices (const TopoDS_Edge& E,
163 if (E.Orientation() == TopAbs_REVERSED) {
164 TopExp::Vertices(E,V2,V1);
167 TopExp::Vertices(E,V1,V2);
171 static Standard_Boolean VertexFromNode
172 (const Handle(MAT_Node)& aNode,
173 const Standard_Real Offset,
175 BRepFill_DataMapOfNodeShape& MapNodeVertex,
178 static void StoreInMap (const TopoDS_Shape& V1,
179 const TopoDS_Shape& V2,
180 TopTools_IndexedDataMapOfShapeShape& MapVV);
182 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
183 const TopoDS_Shape& CurrentSpine,
184 const TopoDS_Face& AllSpine,
185 const TopTools_ListOfShape& D,
186 TopTools_SequenceOfShape& Sv,
187 TColStd_SequenceOfReal& MapverPar,
188 TopTools_SequenceOfShape& S,
189 TopTools_IndexedDataMapOfShapeShape& MapVV,
190 const Standard_Integer IndOfE);
192 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
193 const TopoDS_Face& AllSpine,
194 Standard_Real& TrPar1,
195 Standard_Real& TrPar2);
197 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
198 const TopoDS_Vertex& V);
200 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
201 const TopoDS_Vertex& aVertex);
203 static void MakeCircle
204 (const TopoDS_Edge& E,
205 const TopoDS_Vertex& V,
206 const TopoDS_Face& F,
207 const Standard_Real Offset,
208 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
209 const Handle(Geom_Plane)& RefPlane);
211 static void MakeOffset
212 (const TopoDS_Edge& E,
213 const TopoDS_Face& F,
214 const Standard_Real Offset,
215 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
216 const Handle(Geom_Plane)& RefPlane,
217 const Standard_Boolean IsOpenResult,
218 const GeomAbs_JoinType theJoinType,
219 const TopoDS_Vertex * Ends);
221 //=======================================================================
222 //function : KPartCircle
224 //=======================================================================
226 static Standard_Boolean KPartCircle
227 (const TopoDS_Face& mySpine,
228 const Standard_Real myOffset,
229 const Standard_Boolean IsOpenResult,
230 const Standard_Real Alt,
231 TopoDS_Shape& myShape,
232 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
233 Standard_Boolean& myIsDone)
235 // The only contour which is a closed circle
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) anOffset *= -1;
266 Adaptor3d_OffsetCurve Off(AHC,anOffset);
267 OC = new Geom2d_Line(Off.Line());
269 else if (AHC->GetType() == GeomAbs_Circle)
271 if (E.Orientation() == TopAbs_FORWARD) anOffset *= -1;
272 gp_Circ2d theCirc = AHC->Circle();
273 if (anOffset > 0. || Abs(anOffset) < theCirc.Radius())
274 OC = new Geom2d_Circle (theCirc.Position(), theCirc.Radius() + anOffset);
277 myIsDone = Standard_False;
278 return Standard_False;
283 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
284 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(aPCurve, f, l);
285 OC = new Geom2d_OffsetCurve( G2dT, anOffset);
287 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(mySpine);
288 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
289 myShape = BRepLib_MakeEdge(OC, aPlane, f, l);
290 BRepLib::BuildCurve3d(TopoDS::Edge(myShape));
292 myShape.Orientation(E.Orientation());
295 BRepAdaptor_Surface S(mySpine,0);
296 gp_Ax1 Nor = S.Plane().Axis();
298 gp_Vec Trans(Nor.Direction());
300 T.SetTranslation(Trans);
301 myShape.Move(TopLoc_Location(T));
304 TopTools_ListOfShape LL;
308 TopoDS_Edge myEdge = TopoDS::Edge(myShape);
309 myShape = BRepLib_MakeWire(myEdge);
311 myIsDone = Standard_True;
312 return Standard_True;
315 return Standard_False;
318 //=======================================================================
319 //function : BRepFill_OffsetWire
321 //=======================================================================
323 BRepFill_OffsetWire::BRepFill_OffsetWire()
324 : myIsOpenResult(Standard_False),
325 myIsDone(Standard_False)
330 //=======================================================================
331 //function : BRepFill_OffsetWire
333 //=======================================================================
335 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
336 const GeomAbs_JoinType Join,
337 const Standard_Boolean IsOpenResult)
339 Init(Spine,Join,IsOpenResult);
342 //=======================================================================
345 //=======================================================================
347 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
348 const GeomAbs_JoinType Join,
349 const Standard_Boolean IsOpenResult)
351 myIsDone = Standard_False;
352 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
353 mySpine = TopoDS::Face(aLocalShape);
354 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
356 myIsOpenResult = IsOpenResult;
359 //------------------------------------------------------------------
360 // cut the spine for bissectors.
361 //------------------------------------------------------------------
362 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
363 static BRepMAT2d_Explorer Exp;
365 Exp.Perform(mySpine);
367 // TopoDS_Face anOldSpine = mySpine;
369 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
372 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
374 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
375 Standard_Boolean Done;
376 if (KPartCircle(myWorkSpine,1.,myIsOpenResult,0.,aShape,aMap,Done)) return;
379 //-----------------------------------------------------
380 // Calculate the map of bissectors to the left.
381 // and Links Topology -> base elements of the map.
382 //-----------------------------------------------------
384 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
385 // static BRepMAT2d_Explorer Exp;
386 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
387 Exp.Perform(myWorkSpine);
388 myBilo.Compute(Exp, 1 ,MAT_Left, myJoinType, myIsOpenResult);
389 myLink.Perform(Exp, myBilo);
393 //=======================================================================
396 //=======================================================================
398 Standard_Boolean BRepFill_OffsetWire::IsDone() const
404 //=======================================================================
407 //=======================================================================
409 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
415 //=======================================================================
418 //=======================================================================
420 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
426 //=======================================================================
427 //function : GeneratedShapes
429 //=======================================================================
431 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
432 (const TopoDS_Shape& SpineShape)
435 if (!myMapSpine.IsEmpty()) {
436 // myMapSpine can be empty if passed by PerformWithBilo.
437 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
438 for (; it.More(); it.Next()) {
439 if (myMap.Contains(it.Key())) {
440 if (!myMap.Contains(it.Value())) {
441 TopTools_ListOfShape L;
442 myMap.Add(it.Value(),L);
444 if ( !it.Value().IsSame(it.Key())) {
445 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
446 //myMap.UnBind(it.Key());
447 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
448 TopTools_ListOfShape LastList;
449 LastList.Append(myMap(myMap.Extent()));
451 if (myMap.FindIndex(it.Key()) != 0)
452 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
455 if (myMap.Contains(it.Key().Reversed())) {
456 if (!myMap.Contains(it.Value().Reversed())) {
457 TopTools_ListOfShape L;
458 myMap.Add(it.Value().Reversed(),L);
460 if ( !it.Value().IsSame(it.Key())) {
461 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
462 //myMap.UnBind(it.Key().Reversed());
463 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
464 TopTools_ListOfShape LastList;
465 LastList.Append(myMap(myMap.Extent()));
467 if (myMap.FindIndex(it.Key().Reversed()) != 0)
468 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
473 myCallGen = Standard_True;
476 if (myMap.Contains(SpineShape)) {
477 return myMap.FindFromKey(SpineShape);
480 static TopTools_ListOfShape Empty;
486 //=======================================================================
487 //function : JoinType
489 //=======================================================================
491 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
496 //=======================================================================
499 //=======================================================================
501 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
502 const Standard_Real Alt)
504 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
508 myCallGen = Standard_False;
509 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone)) return;
511 TopoDS_Face oldWorkSpain = myWorkSpine;
513 TopTools_ListOfShape BadEdges;
514 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
516 if(!BadEdges.IsEmpty())
518 // Modification of myWorkSpine;
519 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
520 BRepTools_Substitution aSubst;
521 TopTools_ListIteratorOfListOfShape it(BadEdges);
522 TopTools_ListOfShape aL;
523 Standard_Real aDefl = .01 * Abs(Offset);
524 TColStd_SequenceOfReal Parameters;
525 TColgp_SequenceOfPnt Points;
527 for(; it.More(); it.Next()) {
531 const TopoDS_Shape& anE = it.Value();
533 TopoDS_Vertex Vf, Vl;
534 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
537 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
538 GeomAdaptor_Curve AC(G3d,f,l);
540 PerformCurve(Parameters, Points, AC, aDefl, f,
541 l, Precision::Confusion(), 2);
543 Standard_Integer NPnts = Points.Length();
546 //cout << NPnts << " points " << endl;
547 TopoDS_Vertex FV = Vf;
551 for(np = 2; np < NPnts; np++) {
552 gp_Pnt LP = Points(np);
553 LV = BRepLib_MakeVertex(LP);
554 newE = BRepLib_MakeEdge(FV, LV);
559 newE = BRepLib_MakeEdge(FV, LV);
564 //cout << " 2 points " << endl;
565 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
569 if (myMapSpine.IsBound( anE ))
571 TopTools_ListIteratorOfListOfShape newit( aL );
572 for (; newit.More(); newit.Next())
574 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
575 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
576 TopoDS_Vertex NewV1, NewV2;
577 EdgeVertices( NewEdge, NewV1, NewV2 );
578 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
579 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
581 myMapSpine.UnBind( anE );
584 aSubst.Substitute(anE, aL);
587 TopTools_DataMapOfShapeListOfShape wwmap;
588 TopoDS_Iterator itws( myWorkSpine );
589 for (; itws.More(); itws.Next())
591 TopoDS_Shape aWire = itws.Value();
592 aSubst.Build( aWire );
593 if (aSubst.IsCopied(aWire))
595 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
596 NewWire.Closed( aWire.Closed() );
597 TopTools_ListOfShape Lw;
598 Lw.Append( NewWire );
599 wwmap.Bind( aWire, Lw );
603 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
604 for (; itmap.More(); itmap.Next())
605 aSubst.Substitute( itmap.Key(), itmap.Value() );
607 aSubst.Build(myWorkSpine);
609 if(aSubst.IsCopied(myWorkSpine)) {
610 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
612 BRepMAT2d_Explorer newExp;
613 newExp.Perform(myWorkSpine);
614 BRepMAT2d_BisectingLocus newBilo;
615 BRepMAT2d_LinkTopoBilo newLink;
616 newBilo.Compute(newExp, 1, MAT_Left, myJoinType, myIsOpenResult);
618 if(!newBilo.IsDone())
621 myIsDone = Standard_False;
625 newLink.Perform(newExp,newBilo);
626 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
627 myWorkSpine = oldWorkSpain;
630 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
635 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
638 catch (Standard_Failure)//Every exception was caught.
641 myIsDone = Standard_False;
643 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
644 Standard_Failure::Caught()->Print(cout);
651 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
652 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
655 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
657 for (; anExp.More(); anExp.Next()) {
658 const TopoDS_Shape &aWire = anExp.Current();
660 if (!aWire.Closed()) {
662 myIsDone = Standard_False;
663 Standard_ConstructionError::Raise("Offset wire is not closed.");
667 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
670 //=======================================================================
673 //=======================================================================
675 void Compute (const TopoDS_Face& Spine,
676 TopoDS_Shape& aShape,
677 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
678 const Standard_Real Alt)
681 B.MakeCompound(TopoDS::Compound(aShape));
682 Standard_Real ALT = Alt;
683 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
685 T.SetTranslation(gp_Vec(0.,0.,ALT));
686 TopLoc_Location L(T);
688 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
689 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
690 TopoDS_Shape aLocalShape = CurW.Moved(L);
691 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
692 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
695 TopoDS_Iterator it1( CurW);
696 TopoDS_Iterator it2( NewW);
697 for ( ; it1.More(); it1.Next(), it2.Next()) {
698 TopTools_ListOfShape List;
699 List.Append(it2.Value());
700 Map.Add(it1.Value(), List);
705 //=======================================================================
706 //function : PerformWithBiLo
708 //=======================================================================
710 void BRepFill_OffsetWire::PerformWithBiLo
711 (const TopoDS_Face& Spine,
712 const Standard_Real Offset,
713 const BRepMAT2d_BisectingLocus& Locus,
714 BRepMAT2d_LinkTopoBilo& Link,
715 const GeomAbs_JoinType Join,
716 const Standard_Real Alt)
718 myIsDone = Standard_False;
719 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
720 myWorkSpine = TopoDS::Face(aLocalShape);
721 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
727 if (mySpine.IsNull()) {
728 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
729 mySpine = TopoDS::Face(aLocalShape);
730 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
734 if ( Abs(myOffset) < Precision::Confusion()) {
735 Compute(mySpine,myShape,myMap,Alt);
736 myIsDone = Standard_True;
740 //********************************
741 // Calculate for a non null offset
742 //********************************
743 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone))
746 BRep_Builder myBuilder;
747 myBuilder.MakeCompound(TopoDS::Compound(myShape));
749 //---------------------------------------------------------------------
750 // MapNodeVertex : associate to each node of the map (key1) and to
751 // each element of the profile (key2) a vertex (item).
752 // MapBis : all edges or vertices (item) generated by
753 // a bisectrice on a face or an edge (key) of revolution tubes.
754 // MapVerPar : Map of parameters of vertices on parallel edges
755 // the list contained in MapVerPar (E) corresponds to
756 // parameters on E of vertices contained in MapBis(E);
757 //---------------------------------------------------------------------
760 BRepFill_DataMapOfNodeShape MapNodeVertex;
761 TopTools_DataMapOfShapeSequenceOfShape MapBis;
762 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
764 TopTools_DataMapOfShapeShape EmptyMap;
765 TopTools_SequenceOfShape EmptySeq;
766 TopTools_ListOfShape EmptyList;
767 TColStd_SequenceOfReal EmptySeqOfReal;
769 Standard_Real ALT = Alt;
770 Handle(Geom_Plane) RefPlane =
771 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
772 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
773 RefPlane = Handle(Geom_Plane)::DownCast
774 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
776 //---------------------------------------------------------------
777 // Construction of Circles and OffsetCurves
778 //---------------------------------------------------------------
780 TopoDS_Vertex Ends [2];
784 TopoDS_Iterator iter(mySpine);
785 theWire = TopoDS::Wire(iter.Value());
786 TopExp::Vertices(theWire, Ends[0], Ends[1]);
789 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
790 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
791 TopoDS_Shape& PE = PEE ;
792 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
793 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
794 if (SE.ShapeType() == TopAbs_VERTEX) {
795 if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
796 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
797 myWorkSpine,myOffset,myMap,RefPlane);
800 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
801 myIsOpenResult, myJoinType, Ends);
810 cout << " End Construction of geometric primitives "<<endl;
815 //---------------------------------------------------
816 // Construction of offset vertices.
817 //---------------------------------------------------
818 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
819 Handle(MAT_Arc) CurrentArc;
820 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
821 Handle(Geom_Curve) CBis;
822 Standard_Boolean Reverse;
823 TopoDS_Edge CurrentEdge;
827 Standard_Integer j, k;
829 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
831 CurrentArc = Locus.Graph()->Arc(i);
832 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
837 sprintf(name,"BISSEC_%d",NbBISSEC++);
838 DrawTrSurf::Set(name,Bisec.Value());
842 //-------------------------------------------------------------------
843 // Return elements of the spine corresponding to separate basicElts.
844 //-------------------------------------------------------------------
845 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
846 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
848 TopTools_SequenceOfShape Vertices;
849 TColgp_SequenceOfPnt Params;
851 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
852 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
854 //-----------------------------------------------------------
855 // Return parallel edges on each face.
856 // If no offset generated => move to the next bissectrice.
857 //--------------------------------------------------------------
858 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
859 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
860 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
864 //-----------------------------------------------------------
865 // Construction of vertices corresponding to the node of the map.
866 // if they are on the offset.
867 //-----------------------------------------------------------
869 Handle(MAT_Node) Node1, Node2;
872 Node1 = CurrentArc->SecondNode();
873 Node2 = CurrentArc->FirstNode();
876 Node1 = CurrentArc->FirstNode();
877 Node2 = CurrentArc->SecondNode();
880 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
882 if (!Node1->Infinite()) {
883 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
884 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
885 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
886 // MapNodeVertex,VS);
888 if (!Node2->Infinite()) {
889 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
890 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
891 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
892 // MapNodeVertex,VE);
895 //---------------------------------------------
896 // Construction of geometries.
897 //---------------------------------------------
898 BRepFill_TrimEdgeTool Trim (Bisec,
899 Locus.GeomElt(CurrentArc->FirstElement()),
900 Locus.GeomElt(CurrentArc->SecondElement()),
903 //-----------------------------------------------------------
904 // Construction of vertices on edges parallel to the spine.
905 //-----------------------------------------------------------
907 Trim.IntersectWith(E [0], E [1], Params);
909 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
911 myBuilder.MakeVertex (VC);
912 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
913 gp_Pnt PVC(P2.X(),P2.Y(),0.);
915 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
919 Standard_Boolean Start = 1;
920 Trim.AddOrConfuse(Start, E[0], E[1], Params);
921 if (Params.Length() == Vertices.Length())
922 Vertices.SetValue(1,VS);
925 // the point was not found by IntersectWith
926 Vertices.Prepend(VS);
929 Standard_Boolean Start = 0;
930 Trim.AddOrConfuse(Start, E[0], E[1], Params);
931 if (Params.Length() == Vertices.Length())
932 Vertices.SetValue(Params.Length(),VE);
935 // the point was not found by IntersectWith
939 //------------------------------------------------------------
941 // Detromp allows to remove vertices on the offset
942 // corresponding to tangency zones
943 // Detromp ranks the vertices that limit
944 // the parts of the bissectrices located between the spine and the
946 //------------------------------------------------------------
947 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
948 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
951 UpdateDetromp (Detromp, S[0], S[1], Vertices, Params,
952 Bisec, StartOnEdge, EndOnEdge, Trim);
953 //----------------------------------------------
954 // Storage of vertices on parallel edges.
955 // fill MapBis and MapVerPar.
956 //----------------------------------------------
957 if (!Vertices.IsEmpty()) {
958 for (k = 0; k <= 1; k++) {
959 if (!MapBis.IsBound(E[k])) {
960 MapBis .Bind(E[k],EmptySeq);
961 MapVerPar.Bind(E[k],EmptySeqOfReal);
963 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
964 MapBis (E[k]).Append(Vertices.Value(ii));
965 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
966 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
971 //------------------------------------------------------------
972 // FOR COMPLETE CIRCLES. the parallel line can be contained
973 // in the zone without intersection with the border
975 // if myoffset is < distance of nodes the parallel can be valid.
976 //-------------------------------------------------------------
977 for (k = 0; k <= 1; k++) {
978 if (!MapBis.IsBound(E[k])) {
979 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
980 MapBis .Bind(E[k],EmptySeq);
981 MapVerPar.Bind(E[k],EmptySeqOfReal);
990 cout << " End Construction of vertices on offsets"<<endl;
994 //----------------------------------
995 // Construction of parallel edges.
996 //----------------------------------
997 TopTools_IndexedDataMapOfShapeShape MapVV;
999 TopoDS_Shape CurrentSpine;
1001 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
1003 for (j = 1; j <= myMap.Extent(); j++) {
1004 CurrentSpine = myMap.FindKey(j);
1005 CurrentEdge = TopoDS::Edge(myMap(j).First());
1008 if (MapBis.IsBound(CurrentEdge)) {
1009 TopTools_SequenceOfShape S;
1010 if (!MapBis(CurrentEdge).IsEmpty()) {
1011 Standard_Integer IndOfE = 0;
1016 else if (j == myMap.Extent())
1019 TrimEdge (CurrentEdge,
1022 Detromp (CurrentSpine),
1023 MapBis (CurrentEdge) ,
1024 MapVerPar(CurrentEdge) ,
1026 for ( k = 1; k <= S.Length(); k++) {
1027 myMap(j).Append(S.Value(k));
1034 myMap(j).Append(CurrentEdge);
1039 Standard_Integer ind;
1040 for (ind = 1; ind <= MapVV.Extent(); ind++)
1042 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1043 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1044 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1045 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1046 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1047 TopTools_ListOfShape LV;
1048 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1049 BRepTools_Substitution aSubst;
1050 aSubst.Substitute( OldV, LV );
1051 for (j = 1; j <= myMap.Extent(); j++)
1053 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1054 for (; itl.More(); itl.Next())
1056 aSubst.Build(itl.Value());
1057 if (aSubst.IsCopied(itl.Value()))
1059 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1060 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1061 itl.Value() = listSh.First();
1062 itl.Value().Orientation(SaveOr);
1068 //----------------------------------
1069 // Construction of offset wires.
1070 //----------------------------------
1073 // Update vertices ( Constructed in the plane Z = 0) !!!
1074 TopTools_MapOfShape MapVertex;
1075 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1076 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1077 if ( MapVertex.Add(V)) {
1078 gp_Pnt P = BRep_Tool::Pnt(V);
1079 P = RefPlane->Value(P.X(),P.Y());
1080 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1084 // Construction of curves 3d.
1085 BRepLib::BuildCurves3d(myShape);
1087 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1088 for (; Explo.More(); Explo.Next())
1090 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1091 TopoDS_Vertex V1, V2;
1092 TopExp::Vertices( E, V1, V2 );
1093 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1094 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1096 TopLoc_Location loc;
1098 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1099 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1100 theCurve->Transform( loc.Transformation() );
1101 gp_Pnt f3d = theCurve->Value( f );
1102 gp_Pnt l3d = theCurve->Value( l );
1104 Standard_Real dist1, dist2;
1105 dist1 = f3d.Distance( TV1->Pnt() );
1106 dist2 = l3d.Distance( TV2->Pnt() );
1107 if (! MapVertex.Contains( V1 ))
1110 MapVertex.Add( V1 );
1113 TV1->UpdateTolerance( 1.5*dist1 );
1114 if (! MapVertex.Contains( V2 ))
1117 MapVertex.Add( V2 );
1120 TV2->UpdateTolerance( 1.5*dist2 );
1125 myIsDone = Standard_True;
1129 //=======================================================================
1130 //function : Generated
1132 //=======================================================================
1134 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1135 BRepFill_OffsetWire::Generated()
1141 //=======================================================================
1142 //function : PrepareSpine
1144 //=======================================================================
1146 void BRepFill_OffsetWire::PrepareSpine()
1149 TopTools_ListOfShape Cuts;
1150 TopTools_ListIteratorOfListOfShape IteCuts;
1151 TopoDS_Vertex V1,V2;
1153 myWorkSpine.Nullify();
1157 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1158 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1159 B.MakeFace(myWorkSpine,S,L,TolF);
1161 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1166 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1167 Standard_Integer ForcedCut = 0;
1168 Standard_Integer nbResEdges = -1;
1169 TopTools_IndexedMapOfShape EdgeMap;
1171 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1172 Standard_Integer nbEdges = EdgeMap.Extent();
1174 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
1176 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1178 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1180 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1181 EdgeVertices(E,V1,V2);
1182 myMapSpine.Bind(V1,V1);
1183 myMapSpine.Bind(V2,V2);
1187 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1188 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1189 if (nbEdges == 2 && nbResEdges == 0)
1191 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1192 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1194 if (Cuts.IsEmpty()) {
1196 myMapSpine.Bind(E,E);
1199 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1200 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1201 NE.Orientation(E.Orientation());
1203 myMapSpine.Bind(NE,E);
1204 EdgeVertices(NE,V1,V2);
1205 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1206 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1210 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1214 TopExp::Vertices(NW, aV1, aV2);
1216 NW.Closed(aV1.IsSame(aV2));
1217 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1218 B.Add(myWorkSpine, NW);
1223 DBRep::Set("WS",myWorkSpine);
1229 //=======================================================================
1230 //function : UpdateDetromp
1231 //purpose : For each interval on bissectrice defined by parameters
1232 // test if the medium point is at a distance > offset
1233 // in this case vertices corresponding to the extremities of the interval
1234 // are ranked in the proofing.
1235 // => If the same vertex appears in the proofing, the
1236 // border of the zone of proximity is tangent to the offset .
1237 //=======================================================================
1239 void BRepFill_OffsetWire::UpdateDetromp (BRepFill_DataMapOfOrientedShapeListOfShape& Detromp,
1240 const TopoDS_Shape& Shape1,
1241 const TopoDS_Shape& Shape2,
1242 const TopTools_SequenceOfShape& Vertices,
1243 const TColgp_SequenceOfPnt& Params,
1244 const Bisector_Bisec& Bisec,
1245 const Standard_Boolean SOnE,
1246 const Standard_Boolean EOnE,
1247 const BRepFill_TrimEdgeTool& Trim) const
1249 Standard_Integer ii = 1;
1250 Standard_Real U1,U2;
1251 TopoDS_Vertex V1,V2;
1253 Handle(Geom2d_Curve) Bis = Bisec.Value();
1255 U1 = Bis->FirstParameter();
1258 // the first point of the bissectrice is on the offset
1259 V1 = TopoDS::Vertex(Vertices.Value(ii));
1263 while (ii <= Vertices.Length()) {
1264 U2 = Params.Value(ii).X();
1265 V2 = TopoDS::Vertex(Vertices.Value(ii));
1267 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1268 Standard_Boolean IsP_inside = Standard_True;
1269 if (myJoinType == GeomAbs_Arc)
1270 IsP_inside = Trim.IsInside(P);
1273 Detromp(Shape1).Append(V1);
1274 Detromp(Shape2).Append(V1);
1276 Detromp(Shape1).Append(V2);
1277 Detromp(Shape2).Append(V2);
1284 // test medium point between the last parameter and the end of the bissectrice.
1285 U2 = Bis->LastParameter();
1287 if (!Precision::IsInfinite(U2)) {
1288 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1289 Standard_Boolean IsP_inside = Standard_False;
1290 if (myJoinType == GeomAbs_Arc)
1291 IsP_inside = Trim.IsInside(P);
1294 Detromp(Shape1).Append(V1);
1295 Detromp(Shape2).Append(V1);
1301 Detromp(Shape1).Append(V1);
1302 Detromp(Shape2).Append(V1);
1308 //=======================================================================
1309 //function : MakeWires
1311 //=======================================================================
1313 void BRepFill_OffsetWire::MakeWires()
1315 //--------------------------------------------------------
1316 // creation of a single list of created parallel edges.
1317 //--------------------------------------------------------
1318 TopTools_SequenceOfShape TheEdges;
1319 TopTools_ListOfShape TheWires;
1320 TopTools_ListIteratorOfListOfShape itl;
1321 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1322 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1323 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1324 TopoDS_Vertex V1,V2,VF,CV;
1327 for (i = 1; i <= myMap.Extent(); i++) {
1328 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1329 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1330 TopExp::Vertices (E,V1,V2);
1331 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1332 continue; //remove small closed edges
1333 if (!MVE.Contains(V1)) {
1334 TopTools_ListOfShape empty;
1337 MVE.ChangeFromKey(V1).Append(E);
1338 if (!MVE.Contains(V2)) {
1339 TopTools_ListOfShape empty;
1342 MVE.ChangeFromKey(V2).Append(E);
1346 //--------------------------------------
1347 // Creation of parallel wires.
1348 //--------------------------------------
1351 // Standard_Integer NbEdges;
1352 // Standard_Boolean NewWire = Standard_True;
1353 // Standard_Boolean AddEdge = Standard_False;
1356 Standard_Boolean End;
1359 while (!MVE.IsEmpty()) {
1362 //MVEit.Initialize(MVE);
1363 for (i = 1; i <= MVE.Extent(); i++)
1364 if(MVE(i).Extent() == 1)
1367 //if(!MVEit.More()) MVEit.Initialize(MVE);
1368 if (i > MVE.Extent())
1371 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1372 CE = TopoDS::Edge(MVE(i).First());
1373 End = Standard_False;
1374 MVE.ChangeFromKey(CV).RemoveFirst();
1376 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1377 Standard_Boolean isClosed = Standard_False;
1378 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1381 //-------------------------------
1382 // Construction of a wire.
1383 //-------------------------------
1384 TopExp::Vertices(CE,V1,V2);
1385 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1389 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1390 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1391 isClosed = VF.IsSame(CV);
1392 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1393 End = Standard_True;
1395 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1396 TopTools_ListOfShape LastList;
1397 LastList.Append(MVE(MVE.Extent()));
1399 if (MVE.FindIndex(VF) != 0)
1400 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1404 if (MVE.FindFromKey(CV).Extent() > 2) {
1405 //cout <<"vertex on more that 2 edges in a face."<<endl;
1407 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1408 if (itl.Value().IsSame(CE)) {
1409 MVE.ChangeFromKey(CV).Remove(itl);
1413 if (!MVE.FindFromKey(CV).IsEmpty()) {
1414 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1415 MVE.ChangeFromKey(CV).RemoveFirst();
1417 if (MVE.FindFromKey(CV).IsEmpty())
1420 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1421 TopTools_ListOfShape LastList;
1422 LastList.Append(MVE(MVE.Extent()));
1424 if (MVE.FindIndex(CV) != 0)
1425 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1429 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1430 // NW.Closed(Standard_True);
1431 NW.Closed(isClosed);
1432 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1433 TheWires.Append(NW);
1437 // -- if only one wire : myShape is a Wire
1438 // -- if several wires : myShape is a Compound.
1439 if ( TheWires.Extent() == 1) {
1440 myShape = TheWires.First();
1445 TopTools_ListIteratorOfListOfShape it(TheWires);
1446 for ( ; it.More(); it.Next()) {
1447 B.Add(R, it.Value());
1454 //=======================================================================
1455 //function : FixHoles
1457 //=======================================================================
1459 void BRepFill_OffsetWire::FixHoles()
1461 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1463 Standard_Real MaxTol = 0.;
1467 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1468 for (; Explo.More(); Explo.Next())
1470 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1471 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1477 Explo.Init( myShape, TopAbs_WIRE );
1478 for (; Explo.More(); Explo.Next())
1480 TopoDS_Shape aWire = Explo.Current();
1481 // Remove duplicated edges
1482 TopTools_DataMapOfShapeListOfShape EEmap;
1483 TopoDS_Iterator it( aWire );
1484 for (; it.More(); it.Next())
1486 const TopoDS_Shape& anEdge = it.Value();
1487 if (! EEmap.IsBound( anEdge ))
1489 TopTools_ListOfShape LE;
1490 EEmap.Bind( anEdge, LE );
1493 EEmap(anEdge).Append( anEdge );
1495 aWire.Free( Standard_True );
1496 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1497 for (; mapit.More(); mapit.Next())
1499 const TopTools_ListOfShape& LE = mapit.Value();
1500 TopTools_ListIteratorOfListOfShape itl( LE );
1501 for (; itl.More(); itl.Next())
1502 BB.Remove( aWire, itl.Value() );
1506 ClosedWires.Append( aWire );
1508 UnclosedWires.Append( aWire );
1511 while (!UnclosedWires.IsEmpty())
1513 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1514 TopoDS_Vertex Vf, Vl;
1515 TopExp::Vertices( Base, Vf, Vl );
1516 if(Vf.IsNull() || Vl.IsNull())
1517 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1519 Pf = BRep_Tool::Pnt(Vf);
1520 Pl = BRep_Tool::Pnt(Vl);
1521 Standard_Real DistF = RealLast(), DistL = RealLast();
1522 Standard_Integer IndexF = 1, IndexL = 1;
1523 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1524 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1526 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1527 TopoDS_Vertex V1, V2;
1528 TopExp::Vertices( aWire, V1, V2 );
1530 if(V1.IsNull() || V2.IsNull())
1531 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1534 P1 = BRep_Tool::Pnt(V1);
1535 P2 = BRep_Tool::Pnt(V2);
1536 Standard_Real dist = Pf.Distance( P1 );
1541 IsFirstF = Standard_True;
1543 dist = Pf.Distance( P2 );
1548 IsFirstF = Standard_False;
1550 dist = Pl.Distance( P1 );
1555 IsFirstL = Standard_True;
1557 dist = Pl.Distance( P2 );
1562 IsFirstL = Standard_False;
1565 TopoDS_Wire theWire;
1566 TopoDS_Edge theEdge;
1567 TopoDS_Vertex theVertex;
1568 Standard_Real CommonTol;
1569 Standard_Boolean TryToClose = Standard_True;
1570 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1582 TryToClose = Standard_False;
1584 if (DistF <= MaxTol)
1586 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1587 TopoDS_Vertex V1, V2;
1588 TopExp::Vertices( theWire, V1, V2 );
1589 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1590 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1591 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1592 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1593 TopoDS_Iterator it( theWire );
1594 for (; it.More(); it.Next())
1596 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1597 if (IsFirstF) anEdge.Reverse();
1598 if (!anEdge.IsSame( theEdge ))
1599 BB.Add( Base, anEdge );
1601 theVertex = (IsFirstF)? V1 : V2;
1602 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1603 if (DistF <= CommonTol)
1605 theEdge.Free( Standard_True );
1606 Vf.Orientation( theVertex.Orientation() );
1607 BB.Remove( theEdge, theVertex );
1608 BB.Add( theEdge, Vf );
1609 BB.UpdateVertex( Vf, CommonTol );
1610 if (IsFirstF) theEdge.Reverse();
1611 BB.Add( Base, theEdge );
1615 if (IsFirstF) theEdge.Reverse();
1616 BB.Add( Base, theEdge );
1617 // Creating new edge from theVertex to Vf
1618 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1619 BB.Add( Base, NewEdge );
1622 if (DistL <= MaxTol && IndexL != IndexF)
1624 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1625 TopoDS_Vertex V1, V2;
1626 TopExp::Vertices( theWire, V1, V2 );
1627 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1628 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1629 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1630 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1631 TopoDS_Iterator it( theWire );
1632 for (; it.More(); it.Next())
1634 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1635 if (!IsFirstL) anEdge.Reverse();
1636 if (!anEdge.IsSame( theEdge ))
1637 BB.Add( Base, anEdge );
1639 theVertex = (IsFirstL)? V1 : V2;
1640 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1641 if (DistL <= CommonTol)
1643 theEdge.Free( Standard_True );
1644 Vl.Orientation( theVertex.Orientation() );
1645 BB.Remove( theEdge, theVertex );
1646 BB.Add( theEdge, Vl );
1647 BB.UpdateVertex( Vl, CommonTol );
1648 if (!IsFirstL) theEdge.Reverse();
1649 BB.Add( Base, theEdge );
1653 if (!IsFirstL) theEdge.Reverse();
1654 BB.Add( Base, theEdge );
1655 // Creating new edge from Vl to theVertex
1656 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1657 BB.Add( Base, NewEdge );
1660 // Check if it is possible to close resulting wire
1663 TopExp::Vertices( Base, Vf, Vl );
1664 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1665 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1666 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1667 TopoDS_Edge Efirst, Elast;
1668 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1669 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1670 Pf = BRep_Tool::Pnt(Vf);
1671 Pl = BRep_Tool::Pnt(Vl);
1672 Standard_Real Dist = Pf.Distance(Pl);
1673 if (Dist <= CommonTol)
1675 Elast.Free( Standard_True );
1676 Vf.Orientation( Vl.Orientation() );
1677 BB.Remove( Elast, Vl );
1678 BB.Add( Elast, Vf );
1679 BB.UpdateVertex( Vf, CommonTol );
1680 Base.Closed( Standard_True );
1682 else if (Dist <= MaxTol)
1684 // Creating new edge from Vl to Vf
1685 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1686 BB.Add( Base, NewEdge );
1687 Base.Closed( Standard_True );
1690 // Updating sequences ClosedWires and UnclosedWires
1691 if (DistF <= MaxTol)
1692 UnclosedWires.Remove( IndexF );
1693 if (DistL <= MaxTol && IndexL != IndexF)
1695 if (DistF <= MaxTol && IndexL > IndexF)
1697 UnclosedWires.Remove( IndexL );
1701 ClosedWires.Append( Base );
1702 UnclosedWires.Remove( 1 );
1704 else if (DistF > MaxTol && DistL > MaxTol)
1706 IsolatedWires.Append( Base );
1707 UnclosedWires.Remove( 1 );
1712 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1714 if (!ClosedWires.IsEmpty())
1715 myShape = ClosedWires.First();
1717 myShape = IsolatedWires.First();
1722 BB.MakeCompound( R );
1723 for (i = 1; i <= ClosedWires.Length(); i++)
1724 BB.Add( R, ClosedWires(i) );
1725 for (i = 1; i <= IsolatedWires.Length(); i++)
1726 BB.Add( R, IsolatedWires(i) );
1731 //=======================================================================
1732 //function : CutEdge
1733 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1734 // So, closed circles are cut in two.
1735 // If <Cuts> is empty, the edge is not modified.
1736 // The first and the last vertex of the initial edge
1737 // belong to the first and the last parts respectively.
1738 //=======================================================================
1739 Standard_Integer CutEdge (const TopoDS_Edge& E,
1740 const TopoDS_Face& F,
1741 Standard_Integer ForceCut,
1742 TopTools_ListOfShape& Cuts)
1745 MAT2d_CutCurve Cuter;
1746 TColGeom2d_SequenceOfCurve theCurves;
1748 Handle(Geom2d_Curve) C2d;
1749 Handle(Geom2d_TrimmedCurve) CT2d;
1750 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1751 Standard_Real aTol = BRep_Tool::Tolerance(E);
1752 Handle(Geom_Curve) aC;
1753 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1755 TopoDS_Vertex V1,V2,VF,VL;
1756 TopExp::Vertices (E,V1,V2);
1759 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1760 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1761 aC = BRep_Tool::Curve(E,f,l);
1762 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1763 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1764 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1766 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1767 ( Abs(f-l) >= M_PI) ) {
1771 //-------------------------
1773 //-------------------------
1774 Cuter.Perform(CT2d);
1776 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1777 if (ForceCut == 0) {
1778 if (Cuter.UnModified()) {
1779 //-----------------------------
1780 // edge not modified => return.
1781 //-----------------------------
1784 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1785 theCurves.Append(Cuter.Value(k));
1787 } else if (ForceCut == 1) {
1788 if (Cuter.UnModified()) {
1789 CutCurve (CT2d, 2, theCurves);
1791 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1792 theCurves.Append(Cuter.Value(k));
1794 } else if (ForceCut == 2) {
1795 if (Cuter.UnModified()) {
1796 CutCurve (CT2d, 3, theCurves);
1798 if (Cuter.NbCurves() == 2) {
1799 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1801 if (CC->LastParameter() > (l+f)/2.) {
1802 CutCurve (CC, 2, theCurves);
1803 theCurves.Append(Cuter.Value(2));
1805 theCurves.Append(CC);
1806 CutCurve (Cuter.Value(2), 2, theCurves);
1809 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1810 theCurves.Append(Cuter.Value(k));
1814 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1816 //--------------------------------------
1817 // Creation of cut edges.
1818 //--------------------------------------
1821 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1823 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1825 if (k == theCurves.Length()) {VL = V2;}
1827 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1828 gp_Pnt P = aC->Value(CC->LastParameter());
1830 VL = BRepLib_MakeVertex(P);
1831 B.UpdateVertex(VL, aTol);
1832 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1834 TopoDS_Shape aLocalShape = E.EmptyCopied();
1835 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1836 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1837 NE.Orientation(TopAbs_FORWARD);
1838 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1839 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1840 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1841 Cuts.Append(NE.Oriented(E.Orientation()));
1845 return theCurves.Length();
1848 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1849 //=======================================================================
1850 //function : CutCurve
1852 //=======================================================================
1854 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1855 const Standard_Integer nbParts,
1856 TColGeom2d_SequenceOfCurve& theCurves)
1858 Handle(Geom2d_TrimmedCurve) TrimC;
1859 Standard_Real UF,UL,UC;
1862 Standard_Real PTol = Precision::PConfusion()*10;
1863 Standard_Real Tol = Precision::Confusion()*10;
1864 Standard_Boolean YaCut = Standard_False;
1866 UF = C->FirstParameter();
1867 UL = C->LastParameter ();
1871 Step = (UL - UF)/nbParts;
1873 for (Standard_Integer i = 1; i < nbParts; i++) {
1878 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1879 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1882 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1883 theCurves.Append(TrimC);
1886 YaCut = Standard_True;
1890 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1891 theCurves.Append(TrimC);
1893 theCurves.Append(C);
1895 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1897 //=======================================================================
1898 //function : MakeCircle
1900 //=======================================================================
1902 void MakeCircle (const TopoDS_Edge& E,
1903 const TopoDS_Vertex& V,
1904 const TopoDS_Face& F,
1905 const Standard_Real Offset,
1906 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1907 const Handle(Geom_Plane)& RefPlane)
1909 // evaluate the Axis of the Circle.
1911 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1915 if (E.Orientation() == TopAbs_FORWARD) {
1919 else GC->D1(f,P,DX);
1921 gp_Ax2d Axis(P,gp_Dir2d(DX));
1922 Handle(Geom2d_Circle) Circ
1923 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1925 // Bind the edges in my Map.
1926 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1927 TopTools_ListOfShape LL;
1933 if ( AffichGeom && !OE.IsNull()) {
1935 sprintf(name,"OFFSET_%d",++NbOFFSET);
1936 DBRep::Set(name,OE);
1941 //=======================================================================
1942 //function : MakeOffset
1944 //=======================================================================
1946 void MakeOffset (const TopoDS_Edge& E,
1947 const TopoDS_Face& F,
1948 const Standard_Real Offset,
1949 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1950 const Handle(Geom_Plane)& RefPlane,
1951 const Standard_Boolean IsOpenResult,
1952 const GeomAbs_JoinType theJoinType,
1953 const TopoDS_Vertex * Ends)
1956 Standard_Real anOffset = Offset;
1958 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1960 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1961 Handle(Geom2d_Curve) G2dOC;
1963 Standard_Boolean ToExtendFirstPar = Standard_True;
1964 Standard_Boolean ToExtendLastPar = Standard_True;
1967 TopoDS_Vertex V1, V2;
1968 TopExp::Vertices(E, V1, V2);
1969 if (V1.IsSame(Ends[0]) ||
1971 ToExtendFirstPar = Standard_False;
1972 if (V2.IsSame(Ends[0]) ||
1974 ToExtendLastPar = Standard_False;
1977 Geom2dAdaptor_Curve AC(G2d,f,l);
1978 if ( AC.GetType() == GeomAbs_Circle) {
1979 // if the offset is greater otr equal to the radius and the side of the
1980 // concavity of the circle => edge null.
1981 gp_Circ2d C1(AC.Circle());
1982 gp_Ax22d axes( C1.Axis());
1983 gp_Dir2d Xd = axes.XDirection();
1984 gp_Dir2d Yd = axes.YDirection();
1985 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1986 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1988 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
1990 Handle(Geom2dAdaptor_HCurve) AHC =
1991 new Geom2dAdaptor_HCurve(G2d);
1992 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1993 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1995 Standard_Real Delta = 2*M_PI - l + f;
1996 if (theJoinType == GeomAbs_Arc)
1998 if (ToExtendFirstPar)
2000 if (ToExtendLastPar)
2003 else //GeomAbs_Intersection
2005 if (ToExtendFirstPar && ToExtendLastPar)
2007 Standard_Real old_l = l;
2008 f = old_l + Delta/2.;
2011 else if (ToExtendFirstPar)
2016 else if (ToExtendLastPar)
2021 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2024 else if (AC.GetType() == GeomAbs_Line) {
2025 Handle(Geom2dAdaptor_HCurve) AHC =
2026 new Geom2dAdaptor_HCurve(G2d);
2027 Adaptor3d_OffsetCurve Off(AHC,anOffset);
2028 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2029 Standard_Real Delta = (l - f);
2030 if (ToExtendFirstPar)
2032 if (theJoinType == GeomAbs_Arc)
2034 else //GeomAbs_Intersection
2035 f = -Precision::Infinite();
2037 if (ToExtendLastPar)
2039 if (theJoinType == GeomAbs_Arc)
2041 else //GeomAbs_Intersection
2042 l = Precision::Infinite();
2044 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2048 anOffset = -anOffset;
2049 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2050 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2054 // Bind the edges in my Map.
2055 if (!G2dOC.IsNull()) {
2056 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2057 OE.Orientation(E.Orientation());
2058 TopTools_ListOfShape LL;
2063 if (AffichGeom && !OE.IsNull()) {
2065 sprintf(name,"OFFSET_%d",++NbOFFSET);
2066 DBRep::Set(name,OE);
2067 Standard_Real ii = 0;
2075 //=======================================================================
2076 //function : VertexFromNode
2078 //=======================================================================
2080 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
2081 const Standard_Real Offset,
2083 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2086 Standard_Boolean Status;
2087 Standard_Real Tol = Precision::Confusion();
2090 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2091 //------------------------------------------------
2092 // the Node gives a vertex on the offset
2093 //------------------------------------------------
2094 if (MapNodeVertex.IsBound(aNode)) {
2095 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2098 gp_Pnt P(PN.X(),PN.Y(),0.);
2100 B.UpdateVertex(VN,P, Precision::Confusion());
2101 MapNodeVertex.Bind(aNode,VN);
2103 Status = Standard_True;
2105 else Status = Standard_False;
2111 //=======================================================================
2112 //function : StoreInMap
2114 //=======================================================================
2116 void StoreInMap (const TopoDS_Shape& V1,
2117 const TopoDS_Shape& V2,
2118 TopTools_IndexedDataMapOfShapeShape& MapVV)
2120 TopoDS_Shape OldV = V1, NewV = V2;
2123 if (MapVV.Contains(V2))
2124 NewV = MapVV.FindFromKey(V2);
2126 if (MapVV.Contains(V1))
2127 MapVV.ChangeFromKey(V1) = NewV;
2129 for (i = 1; i <= MapVV.Extent(); i++)
2130 if (MapVV(i).IsSame(V1))
2133 MapVV.Add(V1, NewV);
2136 //=======================================================================
2137 //function : TrimEdge
2139 //=======================================================================
2141 void TrimEdge (const TopoDS_Edge& E,
2142 const TopoDS_Shape& ProE,
2143 const TopoDS_Face& AllSpine,
2144 const TopTools_ListOfShape& Detromp,
2145 TopTools_SequenceOfShape& TheVer,
2146 TColStd_SequenceOfReal& ThePar,
2147 TopTools_SequenceOfShape& S,
2148 TopTools_IndexedDataMapOfShapeShape& MapVV,
2149 const Standard_Integer IndOfE)
2151 Standard_Boolean Change = Standard_True;
2152 BRep_Builder TheBuilder;
2155 //-----------------------------------------------------------
2156 // Parse two sequences depending on the parameter on the edge.
2157 //-----------------------------------------------------------
2159 Change = Standard_False;
2160 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2161 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2162 ThePar.Exchange(i,i+1);
2163 TheVer.Exchange(i,i+1);
2164 Change = Standard_True;
2169 //----------------------------------------------------------
2170 // If a vertex is not in the proofing, it is eliminated.
2171 //----------------------------------------------------------
2172 if (!BRep_Tool::Degenerated(E)) {
2173 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2174 if ( DoubleOrNotInside (Detromp,
2175 TopoDS::Vertex(TheVer.Value(k)))) {
2183 //----------------------------------------------------------
2184 // If a vertex_double appears twice in the proofing
2185 // the vertex is removed.
2186 // otherwise preserve only one of its representations.
2187 //----------------------------------------------------------
2188 if (!BRep_Tool::Degenerated(E)) {
2189 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2190 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2191 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2193 if(k+1 == TheVer.Length()) {
2194 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2199 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2204 if ( DoubleOrNotInside (Detromp,
2205 TopoDS::Vertex(TheVer.Value(k)))) {
2215 //-----------------------------------------------------------
2216 // Creation of edges.
2217 // the number of vertices should be even. The created edges
2218 // go from a vertex with uneven index i to vertex i+1;
2219 //-----------------------------------------------------------
2220 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2222 TopoDS_Shape aLocalShape = E.EmptyCopied();
2223 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2224 TopoDS_Vertex V1, V2;
2225 TopExp::Vertices(E, V1, V2);
2226 Standard_Real fpar, lpar;
2227 Handle(Geom_Surface) aPlane;
2228 TopLoc_Location aLoc;
2229 Handle(Geom2d_Curve) PCurve;
2230 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2231 //BRep_Tool::Range(E, fpar, lpar);
2233 Standard_Real TrPar1, TrPar2;
2234 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2236 if (IndOfE == 1) //first edge of open wire
2238 if (NewEdge.Orientation() == TopAbs_FORWARD)
2243 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2244 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2245 V1 = BRepLib_MakeVertex(TrPnt);
2247 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2248 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2249 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2256 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2257 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2258 V2 = BRepLib_MakeVertex(TrPnt);
2260 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2261 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2262 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2265 else //last edge of open wire
2267 if (NewEdge.Orientation() == TopAbs_FORWARD)
2272 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2273 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2274 V2 = BRepLib_MakeVertex(TrPnt);
2276 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2277 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2278 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2285 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2286 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2287 V1 = BRepLib_MakeVertex(TrPnt);
2289 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2290 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2291 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2298 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2299 TopoDS_Shape aLocalShape = E.EmptyCopied();
2300 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2301 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2303 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2304 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2305 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2308 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2309 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2313 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2318 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2319 DBRep::Set(name,NewEdge);
2324 Handle(Geom_Surface) Surf;
2325 Handle(Geom2d_Curve) C;
2326 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2328 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2329 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2330 Handle(DrawTrSurf_Curve2d) dr =
2331 new DrawTrSurf_Curve2d(C2d,Standard_False);
2332 dr->SetColor(Draw_bleu);
2342 //=======================================================================
2343 //function : IsInnerEdge
2345 //=======================================================================
2347 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2348 const TopoDS_Face& AllSpine,
2349 Standard_Real& TrPar1,
2350 Standard_Real& TrPar2)
2352 if (ProE.ShapeType() != TopAbs_EDGE)
2353 return Standard_False;
2355 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2357 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2358 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2359 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2361 const TopTools_ListOfShape& LE = VEmap(i);
2362 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2363 return Standard_False;
2366 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2367 return Standard_True;
2372 //=======================================================================
2373 //function : DoubleOrNotInside
2374 //purpose : return True if V appears twice in LV or is not inside.
2375 //=======================================================================
2377 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2378 const TopoDS_Vertex& V)
2380 Standard_Boolean Vu = Standard_False;
2381 TopTools_ListIteratorOfListOfShape it(LV);
2383 for ( ; it.More(); it.Next()) {
2384 if (V.IsSame(it.Value())) {
2385 if (Vu) return Standard_True;
2386 else Vu = Standard_True;
2389 if (Vu) return Standard_False;
2390 else return Standard_True;
2393 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2394 const TopoDS_Vertex& aVertex)
2396 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2397 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2398 PV2d.SetCoord( PV.X(), PV.Y() );
2400 Handle(Geom2d_Curve) PCurve;
2401 Handle( BRep_CurveRepresentation ) CurveRep =
2402 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2403 PCurve = CurveRep->PCurve();
2405 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2406 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2407 Pfirst = PCurve->Value(fpar);
2408 Plast = PCurve->Value(lpar);
2409 Pmid = PCurve->Value((fpar + lpar)*0.5);
2411 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2414 Standard_Real dist1 = Pfirst.Distance(PV2d);
2415 Standard_Real dist2 = Plast.Distance(PV2d);
2416 Standard_Real dist3 = Pmid.Distance(PV2d);
2418 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2419 return Standard_True;
2421 return Standard_False;
2424 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2425 const BRepMAT2d_BisectingLocus& Locus,
2426 const BRepMAT2d_LinkTopoBilo& Link,
2427 TopTools_ListOfShape& BadEdges)
2430 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2431 Standard_Real eps = Precision::Confusion();
2432 Standard_Real LimCurv = 1./Offset;
2434 TopTools_MapOfShape aMap;
2436 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2437 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2438 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2439 if (SE.ShapeType() == TopAbs_EDGE) {
2441 if (aMap.Contains(SE)) {
2442 //cout << "Edge is treated second time" << endl;
2446 TopoDS_Edge E = TopoDS::Edge(SE);
2450 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2452 Geom2dAdaptor_Curve AC(G2d,f,l);
2453 GeomAbs_CurveType aCType = AC.GetType();
2455 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2457 Standard_Boolean reverse = Standard_False;
2458 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2463 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2465 aCLProps.SetParameter(f);
2466 if(!aCLProps.IsTangentDefined()) {
2467 BadEdges.Append(SE);
2472 P = aCLProps.Value();
2473 Standard_Real Crv = aCLProps.Curvature();
2476 aCLProps.Tangent(N);
2477 Standard_Real x = N.Y(), y = -N.X();
2479 if (reverse) N.Reverse();
2480 aCLProps.CentreOfCurvature(Pc);
2481 gp_Vec2d Dir( P, Pc );
2482 if (N.Dot(Dir) > 0.) {
2483 if (LimCurv <= Crv + eps) {
2484 BadEdges.Append(SE);
2491 aCLProps.SetParameter(l);
2492 if(!aCLProps.IsTangentDefined()) {
2493 BadEdges.Append(SE);
2498 P = aCLProps.Value();
2499 Crv = aCLProps.Curvature();
2502 aCLProps.Tangent(N);
2503 Standard_Real x = N.Y(), y = -N.X();
2505 if (reverse) N.Reverse();
2506 aCLProps.CentreOfCurvature(Pc);
2507 gp_Vec2d Dir( P, Pc );
2508 if (N.Dot(Dir) > 0.) {
2509 if (LimCurv <= Crv + eps) {
2510 BadEdges.Append(SE);
2523 //=======================================================================
2524 //function : PerformCurve
2526 //=======================================================================
2528 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2529 TColgp_SequenceOfPnt& Points,
2530 const Adaptor3d_Curve& C,
2531 const Standard_Real Deflection,
2532 const Standard_Real U1,
2533 const Standard_Real U2,
2534 const Standard_Real EPSILON,
2535 const Standard_Integer Nbmin)
2537 Standard_Real UU1 = Min(U1, U2);
2538 Standard_Real UU2 = Max(U1, U2);
2542 C.D1(UU1,Pdeb,Ddeb);
2543 Parameters.Append(UU1);
2544 Points.Append(Pdeb);
2546 C.D1(UU2,Pfin,Dfin);
2548 const Standard_Real aDelta = UU2 - UU1;
2549 const Standard_Real aDist = Pdeb.Distance(Pfin);
2551 if((aDelta/aDist) > 5.0e-14)
2553 QuasiFleche(C,Deflection*Deflection,
2563 return Standard_True;
2565 //=======================================================================
2566 //function : QuasiFleche
2568 //=======================================================================
2570 static void QuasiFleche(const Adaptor3d_Curve& C,
2571 const Standard_Real Deflection2,
2572 const Standard_Real Udeb,
2575 const Standard_Real Ufin,
2578 const Standard_Integer Nbmin,
2579 const Standard_Real Eps,
2580 TColStd_SequenceOfReal& Parameters,
2581 TColgp_SequenceOfPnt& Points)
2583 Standard_Integer Ptslength = Points.Length();
2584 Standard_Real Udelta = Ufin-Udeb;
2589 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2597 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2598 Standard_Real theFleche=0;
2599 Standard_Boolean flecheok = Standard_False;
2601 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2602 Standard_Real N1 = Vdeb.SquareMagnitude();
2603 Standard_Real N2 = Vdelta.SquareMagnitude();
2604 if (N1 > Eps && N2 > Eps) {
2605 Standard_Real Normediff =
2606 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2607 if (Normediff > Eps) {
2608 theFleche = Normediff*Norme/64.;
2609 flecheok = Standard_True;
2614 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2615 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2616 theFleche = Pmid.SquareDistance(Pverif);
2619 if (theFleche < Deflection2) {
2620 Parameters.Append(Udeb+Udelta);
2621 Points.Append(Pdelta);
2624 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2635 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2639 Nbmin-(Points.Length()-Ptslength),