1 // Created on: 1994-10-03
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-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
9 // under the terms of the GNU Lesser General Public 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.
18 #include <BRepFill_Evolved.ixx>
21 #include <Bnd_Box2d.hxx>
22 #include <BndLib_Add2dCurve.hxx>
23 #include <BRepFill_OffsetWire.hxx>
24 #include <BRepAdaptor_Curve.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRepClass3d_SolidClassifier.hxx>
27 #include <BRepLib.hxx>
28 #include <BRepMAT2d_Explorer.hxx>
29 #include <BRepFill_Pipe.hxx>
30 #include <BRepFill_OffsetAncestors.hxx>
31 #include <BRepAlgo_FaceRestrictor.hxx>
32 #include <BRepLib_FindSurface.hxx>
33 #include <BRepLib_MakeFace.hxx>
34 #include <BRepLib_MakeWire.hxx>
35 #include <BRepLib_MakeEdge.hxx>
36 #include <BRepLib_MakeVertex.hxx>
37 #include <BRepAlgo_Loop.hxx>
38 #include <BRepSweep_Revol.hxx>
39 #include <BRepSweep_Prism.hxx>
40 #include <BRepTools.hxx>
41 #include <BRepTools_WireExplorer.hxx>
42 #include <BRepTools_TrsfModification.hxx>
43 #include <BRepTools_Modifier.hxx>
44 #include <BRep_Tool.hxx>
45 #include <BRepAdaptor_Curve.hxx>
46 #include <BRepLProp.hxx>
48 #include <BRepMAT2d_LinkTopoBilo.hxx>
49 #include <BRepMAT2d_BisectingLocus.hxx>
50 #include <BRepMAT2d_Explorer.hxx>
52 #include <GeomAPI.hxx>
53 #include <Geom2dAdaptor_Curve.hxx>
54 #include <Geom_Surface.hxx>
55 #include <Geom_Plane.hxx>
56 #include <Geom_Curve.hxx>
57 #include <Geom_Line.hxx>
58 #include <Geom_TrimmedCurve.hxx>
59 #include <Geom2d_CartesianPoint.hxx>
60 #include <Geom2d_Curve.hxx>
61 #include <Geom2d_Line.hxx>
62 #include <Geom2d_Circle.hxx>
63 #include <Geom2d_TrimmedCurve.hxx>
64 #include <Geom2d_Geometry.hxx>
65 #include <GeomProjLib.hxx>
66 #include <Geom_RectangularTrimmedSurface.hxx>
67 #include <Geom2dAdaptor_Curve.hxx>
69 #include <Geom2dAPI_ExtremaCurveCurve.hxx>
70 #include <IntRes2d_IntersectionPoint.hxx>
71 #include <Geom2dInt_GInter.hxx>
73 #include <MAT2d_CutCurve.hxx>
75 #include <MAT_Graph.hxx>
76 #include <MAT_BasicElt.hxx>
77 #include <MAT_Side.hxx>
78 #include <MAT_Arc.hxx>
79 #include <MAT_Node.hxx>
80 #include <Bisector_Bisec.hxx>
81 #include <Bisector_BisecAna.hxx>
84 #include <TopoDS_Wire.hxx>
85 #include <TopoDS_Edge.hxx>
86 #include <TopoDS_Compound.hxx>
87 #include <TopoDS_Solid.hxx>
88 #include <TopoDS_Iterator.hxx>
90 #include <TopExp_Explorer.hxx>
91 #include <TopTools_DataMapOfShapeShape.hxx>
92 #include <TopTools_SequenceOfShape.hxx>
93 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
94 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
95 #include <TopTools_ListIteratorOfListOfShape.hxx>
96 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
97 #include <TopLoc_Location.hxx>
101 #include <gp_Ax1.hxx>
102 #include <gp_Ax3.hxx>
103 #include <gp_Dir.hxx>
104 #include <gp_Pnt.hxx>
105 #include <gp_Pln.hxx>
106 #include <gp_Pnt2d.hxx>
107 #include <gp_Trsf.hxx>
108 #include <gp_Vec.hxx>
109 #include <gp_Vec2d.hxx>
110 #include <gp_Circ2d.hxx>
112 #include <TColgp_SequenceOfPnt.hxx>
113 #include <TColStd_SequenceOfReal.hxx>
114 #include <BRepFill_TrimSurfaceTool.hxx>
115 #include <BRepFill_DataMapOfNodeDataMapOfShapeShape.hxx>
116 #include <BRepFill_DataMapOfShapeDataMapOfShapeListOfShape.hxx>
117 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
118 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
119 #include <BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape.hxx>
120 #include <Precision.hxx>
122 #include <Standard_ConstructionError.hxx>
123 #include <Standard_NotImplemented.hxx>
127 #include <DrawTrSurf.hxx>
132 static Standard_Boolean AffichGeom = Standard_False;
133 static Standard_Boolean AffichEdge = Standard_False;
134 static Standard_Integer NbFACES = 0;
135 static Standard_Integer NbTRIMFACES = 0;
136 static Standard_Integer NbVEVOS = 0;
137 static Standard_Integer NbPROFILS = 0;
138 static Standard_Integer NbEDGES = 0;
141 static char name[100];
145 static const Standard_Real BRepFill_Confusion()
147 Standard_Real Tol = 1.e-6;
151 static const TopoDS_Wire PutProfilAt (const TopoDS_Wire& ProfRef,
152 const gp_Ax3& AxeRef,
153 const TopoDS_Edge& E,
154 const TopoDS_Face& F,
155 const Standard_Boolean AtStart);
157 static void TrimFace(const TopoDS_Face& Face,
158 TopTools_SequenceOfShape& TheEdges,
159 TopTools_SequenceOfShape& S);
161 static void TrimEdge (const TopoDS_Edge& Edge,
162 const TopTools_SequenceOfShape& TheEdgesControle,
163 TopTools_SequenceOfShape& TheVer,
164 TColStd_SequenceOfReal& ThePar,
165 TopTools_SequenceOfShape& S);
167 static TopAbs_Orientation OriEdgeInFace (const TopoDS_Edge& E,
168 const TopoDS_Face& F);
170 static Standard_Integer PosOnFace (Standard_Real d1,
174 static void ComputeIntervals (const TopTools_SequenceOfShape& VonF,
175 const TopTools_SequenceOfShape& VOnL,
176 const TColgp_SequenceOfPnt& ParOnF,
177 const TColgp_SequenceOfPnt& ParOnL,
178 const BRepFill_TrimSurfaceTool& Trim,
179 const Handle(Geom2d_Curve)& Bis,
180 const TopoDS_Vertex& VS,
181 const TopoDS_Vertex& VE,
182 TColStd_SequenceOfReal& FirstPar,
183 TColStd_SequenceOfReal& LastPar,
184 TopTools_SequenceOfShape& FirstV,
185 TopTools_SequenceOfShape& LastV );
187 static Standard_Real DistanceToOZ (const TopoDS_Vertex& V);
189 static Standard_Real Altitud (const TopoDS_Vertex& V);
191 static Standard_Boolean DoubleOrNotInFace (const TopTools_SequenceOfShape& EC,
192 const TopoDS_Vertex& V);
194 static void SimpleExpression (const Bisector_Bisec& B,
195 Handle(Geom2d_Curve)& Bis);
197 static TopAbs_Orientation Relative (const TopoDS_Wire& W1,
198 const TopoDS_Wire& W2,
199 const TopoDS_Vertex& V,
200 Standard_Boolean& Commun);
202 static void CutEdge (const TopoDS_Edge& E,
203 const TopoDS_Face& F,TopTools_ListOfShape& Cuts);
205 static void CutEdgeProf (const TopoDS_Edge& E,
206 const Handle(Geom_Plane)& Plane,
207 const Handle(Geom2d_Line)& Line,
208 TopTools_ListOfShape& Cuts,
209 TopTools_DataMapOfShapeShape& MapVerRefMoved);
211 static Standard_Integer VertexFromNode
212 (const Handle(MAT_Node)& aNode,
213 const TopoDS_Edge& E,
214 const TopoDS_Vertex& VF,
215 const TopoDS_Vertex& VL,
216 BRepFill_DataMapOfNodeDataMapOfShapeShape& MapNodeVertex,
219 //=======================================================================
220 //function : EdgeVertices
222 //=======================================================================
224 static void EdgeVertices (const TopoDS_Edge& E,
228 if (E.Orientation() == TopAbs_REVERSED) {
229 TopExp::Vertices(E,V2,V1);
232 TopExp::Vertices(E,V1,V2);
236 //=======================================================================
237 //function : BRepFill_Evolved
239 //=======================================================================
241 BRepFill_Evolved::BRepFill_Evolved()
243 myIsDone (Standard_False),
244 mySpineType(Standard_True)
249 //=======================================================================
250 //function : BRepFill_Evolved
252 //=======================================================================
254 BRepFill_Evolved::BRepFill_Evolved(const TopoDS_Wire& Spine,
255 const TopoDS_Wire& Profile,
256 const gp_Ax3& AxeProf,
257 const GeomAbs_JoinType Join,
258 const Standard_Boolean Solid)
260 : myIsDone(Standard_False)
262 Perform( Spine, Profile, AxeProf, Join, Solid);
266 //=======================================================================
267 //function : BRepFill_Evolved
269 //=======================================================================
271 BRepFill_Evolved::BRepFill_Evolved(const TopoDS_Face& Spine,
272 const TopoDS_Wire& Profile,
273 const gp_Ax3& AxeProf,
274 const GeomAbs_JoinType Join,
275 const Standard_Boolean Solid)
276 : myIsDone(Standard_False)
278 Perform( Spine, Profile, AxeProf, Join, Solid);
281 //=======================================================================
282 //function : IsVertical
284 //=======================================================================
286 static Standard_Boolean IsVertical(const TopoDS_Edge& E)
289 TopExp::Vertices(E,V1,V2);
290 gp_Pnt P1 = BRep_Tool::Pnt(V1);
291 gp_Pnt P2 = BRep_Tool::Pnt(V2);
293 if ( Abs(P1.Y() - P2.Y()) < BRepFill_Confusion()) {
297 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,Loc,f,l);
298 if ( GC->DynamicType() == STANDARD_TYPE(Geom_Line))
299 return Standard_True;
301 return Standard_False;
304 //=======================================================================
305 //function : IsPlanar
307 //=======================================================================
309 static Standard_Boolean IsPlanar(const TopoDS_Edge& E)
312 TopExp::Vertices(E,V1,V2);
313 gp_Pnt P1 = BRep_Tool::Pnt(V1);
314 gp_Pnt P2 = BRep_Tool::Pnt(V2);
316 if ( Abs(P1.Z() - P2.Z()) < BRepFill_Confusion()) {
320 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,Loc,f,l);
321 if ( GC->DynamicType() == STANDARD_TYPE(Geom_Line))
322 return Standard_True;
324 return Standard_False;
328 //=======================================================================
330 //purpose : determine the position of the profil correspondingly to plane XOZ.
331 // Return 1 : MAT_Left.
332 // Return 2 : MAT_Left and Planar.
333 // Return 3 : MAT_Left and Vertical.
334 // Return 4 : MAT_Right.
335 // Return 5 : MAT_Right and Planar.
336 // Return 6 : MAT_Right and Vertical.
337 //=======================================================================
339 static Standard_Integer Side(const TopoDS_Wire& Profil,
340 const Standard_Real Tol)
343 // Rem : it is enough to test the first edge of the Wire.
344 // ( Correctly cut in PrepareProfil)
345 TopExp_Explorer Explo(Profil,TopAbs_EDGE);
347 Standard_Integer TheSide;
348 const TopoDS_Edge& E = TopoDS::Edge(Explo.Current());
350 TopExp::Vertices(E,V1,V2);
351 gp_Pnt P1 = BRep_Tool::Pnt(V1);
352 gp_Pnt P2 = BRep_Tool::Pnt(V2);
354 if ( P1.Y() < -Tol || P2.Y() < -Tol) TheSide = 4;
356 if (IsVertical(E)) TheSide+=2;
357 else if (IsPlanar(E)) TheSide++;
362 //=======================================================================
365 //=======================================================================
367 void BRepFill_Evolved::Perform(const TopoDS_Wire& Spine,
368 const TopoDS_Wire& Profile,
369 const gp_Ax3& AxeProf,
370 const GeomAbs_JoinType Join,
371 const Standard_Boolean Solid)
373 mySpineType = Standard_False;
374 TopoDS_Face aFace = BRepLib_MakeFace(Spine,Standard_True);
375 PrivatePerform( aFace, Profile, AxeProf, Join, Solid);
378 //=======================================================================
381 //=======================================================================
383 void BRepFill_Evolved::Perform(const TopoDS_Face& Spine,
384 const TopoDS_Wire& Profile,
385 const gp_Ax3& AxeProf,
386 const GeomAbs_JoinType Join,
387 const Standard_Boolean Solid)
389 mySpineType = Standard_True;
390 PrivatePerform( Spine, Profile, AxeProf, Join, Solid);
393 //=======================================================================
394 //function : PrivatePerform
396 //=======================================================================
398 void BRepFill_Evolved::PrivatePerform(const TopoDS_Face& Spine,
399 const TopoDS_Wire& Profile,
400 const gp_Ax3& AxeProf,
401 const GeomAbs_JoinType Join,
402 const Standard_Boolean Solid)
404 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
405 mySpine = TopoDS::Face(aLocalShape);
406 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
407 aLocalShape = Profile.Oriented(TopAbs_FORWARD);
408 myProfile = TopoDS::Wire(aLocalShape);
409 // myProfile = TopoDS::Wire(Profile.Oriented(TopAbs_FORWARD));
413 if (myJoinType > GeomAbs_Arc) {
414 Standard_NotImplemented::Raise();
417 TopTools_ListOfShape WorkProf;
418 TopoDS_Face WorkSpine;
419 TopTools_ListIteratorOfListOfShape WPIte;
421 //-------------------------------------------------------------------
422 // Positioning of mySpine and myProfil in the workspace.
423 //-------------------------------------------------------------------
424 TopLoc_Location LSpine = FindLocation(mySpine);
426 T.SetTransformation(AxeProf);
427 TopLoc_Location LProfile (T);
428 TopLoc_Location InitLS = mySpine .Location();
429 TopLoc_Location InitLP = myProfile.Location();
430 TransformInitWork(LSpine,LProfile);
432 //------------------------------------------------------------------
433 // projection of the profile and cut of the spine.
434 //------------------------------------------------------------------
435 TopTools_DataMapOfShapeShape MapProf, MapSpine;
437 PrepareProfile(WorkProf , MapProf);
438 PrepareSpine (WorkSpine, MapSpine);
440 Standard_Real Tol = BRepFill_Confusion();
441 Standard_Boolean YaLeft = Standard_False;
442 Standard_Boolean YaRight = Standard_False;
445 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
446 SP = TopoDS::Wire(WPIte.Value());
447 if ( Side(SP,Tol) < 4) YaLeft = Standard_True;
448 else YaRight = Standard_True;
449 if (YaLeft && YaRight) break;
453 BRepMAT2d_BisectingLocus Locus;
455 //----------------------------------------------------------
456 // Initialisation of cut volevo.
457 // For each part of the profile create a volevo added to CutVevo
458 //----------------------------------------------------------
459 BRepFill_Evolved CutVevo;
462 BRepTools_WireExplorer WExp;
466 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
467 for (WExp.Init(TopoDS::Wire(WPIte.Value())); WExp.More(); WExp.Next()) {
468 BB.Add(WP,WExp.Current());
471 CutVevo.SetWork(WorkSpine,WP);
473 BRepTools_Quilt Glue;
474 Standard_Integer CSide;
476 //---------------------------------
477 // Construction of vevos to the left.
478 //---------------------------------
480 //-----------------------------------------------------
481 // Calculate the map of bisector locations at the left.
482 // and links Topology -> base elements of the map.
483 //-----------------------------------------------------
484 BRepMAT2d_Explorer Exp(WorkSpine);
485 Locus.Compute(Exp,1,MAT_Left);
486 BRepMAT2d_LinkTopoBilo Link(Exp,Locus);
488 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
489 SP = TopoDS::Wire(WPIte.Value());
490 CSide = Side(SP,Tol);
491 //-----------------------------------------------
492 // Construction and adding of elementary volevo.
493 //-----------------------------------------------
494 BRepFill_Evolved Vevo;
496 Vevo.ElementaryPerform (WorkSpine, SP, Locus, Link, Join);
498 else if (CSide == 2) {
499 Vevo.PlanarPerform (WorkSpine, SP, Locus, Link, Join);
501 else if (CSide == 3) {
502 Vevo.VerticalPerform (WorkSpine, SP, Locus, Link, Join);
504 CutVevo.Add (Vevo, SP, Glue);
508 //---------------------------------
509 // Construction of vevos to the right.
510 //---------------------------------
512 //-----------------------------------
513 // Decomposition of the face into wires.
514 //-----------------------------------
515 TopExp_Explorer SpineExp (WorkSpine, TopAbs_WIRE);
516 for ( ; SpineExp.More(); SpineExp.Next()) {
517 //----------------------------------------------
518 // Calculate the map to the right of the current wire.
519 //----------------------------------------------
520 BRepLib_MakeFace B(gp_Pln(0.,0.,1.,0.));
521 TopoDS_Shape aLocalShape = SpineExp.Current().Reversed();
522 B.Add(TopoDS::Wire(aLocalShape));
523 // B.Add(TopoDS::Wire(SpineExp.Current().Reversed()));
525 BRepMAT2d_Explorer Exp(Face);
526 Locus.Compute(Exp,1,MAT_Left);
527 BRepMAT2d_LinkTopoBilo Link(Exp,Locus);
529 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
530 SP = TopoDS::Wire(WPIte.Value());
531 CSide = Side(SP,Tol);
532 //-----------------------------------------------
533 // Construction and adding of an elementary volevo
534 //-----------------------------------------------
535 BRepFill_Evolved Vevo;
537 Vevo.ElementaryPerform (Face, SP, Locus, Link, Join);
539 else if (CSide == 5) {
540 Vevo.PlanarPerform (Face, SP, Locus, Link, Join);
542 else if (CSide == 6) {
543 Vevo.VerticalPerform (Face, SP, Locus, Link, Join);
545 CutVevo.Add (Vevo, SP, Glue);
550 if (Solid) CutVevo.AddTopAndBottom(Glue);
552 //-------------------------------------------------------------------------
553 // Gluing of regularites on parallel edges generate4d by vertices of the
554 // cut of the profile.
555 //-------------------------------------------------------------------------
556 CutVevo.ContinuityOnOffsetEdge(WorkProf);
558 //-----------------------------------------------------------------
559 // construction of the shape via the quilt, ie:
560 // - sharing of topologies of elementary added volevos.
561 // - Orientation of faces correspondingly to each other.
562 //-----------------------------------------------------------------
563 TopoDS_Shape& SCV = CutVevo.ChangeShape();
565 //------------------------------------------------------------------------
566 // Transfer of the map of generated elements and of the shape of Cutvevo
567 // in myMap and repositioning in the initial space.
568 //------------------------------------------------------------------------
569 Transfert (CutVevo, MapProf, MapSpine, LSpine.Inverted(), InitLS, InitLP);
571 //Orientation of the solid.
572 if (Solid) MakeSolid();
574 // modified by NIZHNY-EAP Mon Jan 24 11:26:48 2000 ___BEGIN___
575 BRepLib::UpdateTolerances(myShape,Standard_False);
576 // modified by NIZHNY-EAP Mon Jan 24 11:26:50 2000 ___END___
577 myIsDone = Standard_True;
582 //=======================================================================
583 //function : IsInversed
585 //=======================================================================
587 static void IsInversed(const TopoDS_Shape& S,
588 const TopoDS_Edge& E1,
589 const TopoDS_Edge& E2,
590 Standard_Boolean* Inverse)
593 Inverse[0] = Inverse[1] = 0;
594 if (S.ShapeType() != TopAbs_EDGE) return;
598 BRepAdaptor_Curve CS(TopoDS::Edge(S));
599 if (S.Orientation() == TopAbs_FORWARD) {
600 CS.D1(CS.FirstParameter(),P,DS);
603 CS.D1(CS.LastParameter(),P,DS);
608 if (!BRep_Tool::Degenerated(E1)) {
609 BRepAdaptor_Curve C1(TopoDS::Edge(E1));
610 if (E1.Orientation() == TopAbs_FORWARD) {
611 C1.D1(C1.FirstParameter(),P,DC1);
614 C1.D1(C1.LastParameter(),P,DC1);
617 Inverse[0] = (DS.Dot(DC1) < 0.);
621 if (!BRep_Tool::Degenerated(E2)) {
622 BRepAdaptor_Curve C2(TopoDS::Edge(E2));
623 if (E2.Orientation() == TopAbs_FORWARD) {
624 C2.D1(C2.FirstParameter(),P,DC2);
627 C2.D1(C2.LastParameter(),P,DC2);
630 Inverse[1] = (DS.Dot(DC2) < 0.);
635 //=======================================================================
638 //=======================================================================
640 void BRepFill_Evolved::SetWork(const TopoDS_Face& Sp,
641 const TopoDS_Wire& Pr)
647 //=======================================================================
648 //function : ConcaveSide
649 //purpose : Determine if the pipes were at the side of the
650 // concavity. In this case they can be closed.
651 // WARNING: Not finished. Done only for circles.
652 //=======================================================================
654 static Standard_Boolean ConcaveSide(const TopoDS_Shape& S,
655 const TopoDS_Face& F)
658 if (S.ShapeType() == TopAbs_VERTEX) return Standard_False;
660 if (S.ShapeType() == TopAbs_EDGE) {
662 Handle(Geom2d_Curve) G2d =
663 BRep_Tool::CurveOnSurface(TopoDS::Edge(S),F,f,l);
664 Handle(Geom2d_Curve) G2dOC;
666 Geom2dAdaptor_Curve AC(G2d,f,l);
667 if ( AC.GetType() == GeomAbs_Circle) {
668 Standard_Boolean Direct = AC.Circle().IsDirect();
669 if (S.Orientation() == TopAbs_REVERSED) Direct = (!Direct);
673 return Standard_False;
676 //=======================================================================
677 //function : ElementaryPerform
679 //=======================================================================
681 void BRepFill_Evolved::ElementaryPerform (const TopoDS_Face& Sp,
682 const TopoDS_Wire& Pr,
683 const BRepMAT2d_BisectingLocus& Locus,
684 BRepMAT2d_LinkTopoBilo& Link,
685 const GeomAbs_JoinType /*Join*/)
690 sprintf(name,"PROFIL_%d",++NbPROFILS);
694 TopoDS_Shape aLocalShape = Sp.Oriented(TopAbs_FORWARD);
695 mySpine = TopoDS::Face(aLocalShape);
696 // mySpine = TopoDS::Face(Sp.Oriented(TopAbs_FORWARD));
700 BRep_Builder myBuilder;
701 myBuilder.MakeCompound(TopoDS::Compound(myShape));
703 //---------------------------------------------------------------------
704 // MapNodeVertex : associate to each node of the map (key1) and
705 // to each element of the profile (key2) a vertex (item).
706 // MapBis : a set of edges or vertexes (item) generated by
707 // a bisectrice on a face or an edge (key) of
708 // tubes or revolutions.
709 // MapVerPar : Map of parameters of vertices on parallel edges
710 // the list contained in MapVerPar (E) corresponds
711 // to parameters on E of vertices contained in MapBis(E);
712 // MapBS : links BasicElt of the map => Topology of the spine.
713 //---------------------------------------------------------------------
716 BRepFill_DataMapOfNodeDataMapOfShapeShape MapNodeVertex;
717 TopTools_DataMapOfShapeSequenceOfShape MapBis;
718 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
720 TopTools_DataMapOfShapeShape EmptyMap;
721 TopTools_SequenceOfShape EmptySeq;
722 TopTools_ListOfShape EmptyList;
723 TColStd_SequenceOfReal EmptySeqOfReal;
725 // mark of the profile.
726 gp_Ax3 AxeRef(gp_Pnt(0.,0.,0.),
730 //---------------------------------------------------------------
731 // Construction of revolutions and tubes.
732 //---------------------------------------------------------------
733 BRepTools_WireExplorer ProfExp;
734 TopExp_Explorer FaceExp;
735 BRepTools_WireExplorer WireExp;
737 for (FaceExp.Init(mySpine,TopAbs_WIRE); FaceExp.More(); FaceExp.Next()){
739 for (WireExp.Init(TopoDS::Wire(FaceExp.Current())); WireExp.More();
742 TopoDS_Edge CurrentEdge = WireExp.Current();
743 TopoDS_Vertex VFirst,VLast;
744 EdgeVertices(CurrentEdge,VFirst,VLast);
746 for (Link.Init(VLast); Link.More(); Link.Next()) {
747 //----------------------------.
748 //Construction of a Revolution
749 //----------------------------.
750 MakeRevol (CurrentEdge, VLast, AxeRef);
753 for (Link.Init(CurrentEdge); Link.More(); Link.Next()) {
754 //------------------------.
755 //Construction of a Tube
756 //-------------------------
757 MakePipe (CurrentEdge, AxeRef);
764 cout << " End Construction of geometric primitives"<<endl;
770 //---------------------------------------------------
771 // Construction of edges associated to bissectrices.
772 //---------------------------------------------------
773 Handle(MAT_Arc) CurrentArc;
774 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
775 Handle(Geom_Curve) CBis;
776 Standard_Boolean Reverse;
777 TopoDS_Edge CurrentEdge;
784 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
785 CurrentArc = Locus.Graph()->Arc(i);
786 SimpleExpression(Locus.GeomBis(CurrentArc,Reverse), Bis);
788 //------------------------------------------------------------------
789 // Return elements of the spine corresponding to separate basicElts.
790 //------------------------------------------------------------------
791 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
792 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
794 Standard_Boolean Concave0 = ConcaveSide(S[0],mySpine);
795 Standard_Boolean Concave1 = ConcaveSide(S[1],mySpine);
797 TopTools_SequenceOfShape VOnF,VOnL;
798 TColgp_SequenceOfPnt ParOnF,ParOnL;
800 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
801 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
803 Standard_Integer vv = 0;
804 for(ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()) {
806 //-----------------------------------------------
807 // Return two faces separated by the bissectrice.
808 //-----------------------------------------------
809 F [0] = TopoDS::Face(myMap(S[0])(ProfExp.Current()).First());
810 F [1] = TopoDS::Face(myMap(S[1])(ProfExp.Current()).First());
812 //------------------------------------
813 // Return parallel edges on each face.
814 //------------------------------------
817 EdgeVertices(ProfExp.Current(),VF,VL);
819 E [0] = TopoDS::Edge(myMap(S[0])(VF).First());
820 E [1] = TopoDS::Edge(myMap(S[0])(VL).First());
821 E [2] = TopoDS::Edge(myMap(S[1])(VF).First());
822 E [3] = TopoDS::Edge(myMap(S[1])(VL).First());
824 Standard_Boolean Inv0[2];
825 Standard_Boolean Inv1[2];
827 Inv0[0] = Inv0[1] = Inv1[0]= Inv1[1] = 0;
828 if (Concave0) IsInversed(S[0],E[0],E[1],Inv0);
829 if (Concave1) IsInversed(S[1],E[2],E[3],Inv1);
831 //---------------------------------------------
832 // Construction of geometries.
833 //---------------------------------------------
834 BRepFill_TrimSurfaceTool Trim (Bis,F[0],F[1],
835 E[0],E[2],Inv0[0],Inv1[0]);
836 //-----------------------------------------------------------
837 //Construction of vertices corresponding to the node of the map
838 //-----------------------------------------------------------
840 Handle(MAT_Node) Node1, Node2;
843 Node1 = CurrentArc->SecondNode();
844 Node2 = CurrentArc->FirstNode();
847 Node1 = CurrentArc->FirstNode();
848 Node2 = CurrentArc->SecondNode();
850 //--------------------------------------------------------
851 // Particular case when the node is on a vertex of the spine.
852 //--------------------------------------------------------
853 if (Node1->OnBasicElt()) {
854 if (S[0].ShapeType() == TopAbs_VERTEX) {
855 Node1 = CurrentArc->FirstElement()->StartArc()->FirstNode();
857 else if (S[1].ShapeType() == TopAbs_VERTEX) {
858 Node1 = CurrentArc->SecondElement()->StartArc()->FirstNode();
861 // End of particular case.
864 StartOnF = VertexFromNode(Node1,
865 TopoDS::Edge(ProfExp.Current()),
870 EndOnF = VertexFromNode(Node2,
871 TopoDS::Edge(ProfExp.Current()),
875 //-----------------------------------------------------------
876 // Construction of vertices on edges parallel to the spine.
877 //-----------------------------------------------------------
878 if (!MapSeqVer.IsBound(VF)) {
879 if (Inv0 [0] || Inv1 [0]) {
884 Trim.IntersectWith(E [0], E [2], ParOnF);
886 for (Standard_Integer s = 1; s <= ParOnF.Length(); s++) {
888 myBuilder.MakeVertex (VC);
892 VOnF .SetValue(1,VS);
895 VOnF .SetValue(ParOnF.Length(),VE);
900 ParOnF = MapSeqPar(VF);
901 VOnF = MapSeqVer(VF);
904 if (!MapSeqVer.IsBound(VL)) {
905 if (Inv0 [1] || Inv1 [1]) {
910 Trim.IntersectWith(E [1], E [3], ParOnL);
912 for (Standard_Integer s = 1; s <= ParOnL.Length(); s++) {
914 myBuilder.MakeVertex (VC);
918 VOnL .SetValue(1,VS);
921 VOnL .SetValue(ParOnL.Length(),VE);
926 ParOnL = MapSeqPar(VL);
927 VOnL = MapSeqVer(VL);
930 //------------------------------------------------------
931 // Test if the Bissectrice is not projected on the face
932 //------------------------------------------------------
933 if ((StartOnF == 0) && (EndOnF == 0) &&
934 VOnL.IsEmpty() && VOnF.IsEmpty())
935 // No trace of the bisectrice on the face.
938 if ((StartOnF == 0) && (EndOnF == 0) &&
939 (VOnL.Length() + VOnF.Length() == 1))
940 // the first or last node of the arc is on the edge
941 // but the arc is not on the face.
944 //---------------------------------------------------------
945 // determine the intervals of the bissectrice that are
946 // projected on F[0] and F[1].
947 //---------------------------------------------------------
948 TColStd_SequenceOfReal LastPar,FirstPar;
949 TopTools_SequenceOfShape FirstV,LastV;
951 ComputeIntervals (VOnF,VOnL,ParOnF,ParOnL,Trim,Bis,
952 VS,VE,FirstPar,LastPar,FirstV,LastV);
954 for (Standard_Integer Ti = 1; Ti <= FirstPar.Length(); Ti++) {
955 TopoDS_Vertex V1 = TopoDS::Vertex(FirstV.Value(Ti));
956 TopoDS_Vertex V2 = TopoDS::Vertex(LastV .Value(Ti));
958 GeomAbs_Shape Continuity;
960 Trim.Project(FirstPar.Value(Ti),LastPar.Value(Ti),
961 CBis,PCurve1,PCurve2,Continuity);
963 //-------------------------------------
964 // Coding of the edge.
965 //-------------------------------------
966 myBuilder.MakeEdge(CurrentEdge, CBis,
967 BRepFill_Confusion());
969 myBuilder.UpdateVertex(V1,CBis->Value(CBis->FirstParameter()),
970 BRepFill_Confusion());
971 myBuilder.UpdateVertex(V2,CBis->Value(CBis->LastParameter()),
972 BRepFill_Confusion());
974 myBuilder.Add(CurrentEdge,V1.Oriented(TopAbs_FORWARD));
975 myBuilder.Add(CurrentEdge,V2.Oriented(TopAbs_REVERSED));
977 myBuilder.Range(CurrentEdge,
978 CBis->FirstParameter(),
979 CBis->LastParameter());
980 myBuilder.UpdateEdge(CurrentEdge,PCurve1,F[0],BRepFill_Confusion());
981 myBuilder.UpdateEdge(CurrentEdge,PCurve2,F[1],BRepFill_Confusion());
983 myBuilder.Continuity(CurrentEdge,F[0],F[1],Continuity);
987 sprintf(name,"ARCEDGE_%d_%d_%d",i,vv,Ti);
988 DBRep::Set(name,CurrentEdge);
991 //-------------------------------------------
992 // Storage of the edge for each of faces.
993 //-------------------------------------------
994 for (k = 0; k <= 1;k++) {
995 if (!MapBis.IsBound(F[k])) {
996 MapBis.Bind(F[k],EmptySeq);
999 //---------------------------------------------------------------
1000 // orientation of the edge depends on the direction of the skin.
1001 // skin => same orientation E[0] , inverted orientation E[2]
1002 // if contreskin it is inverted.
1003 //--------------------------------------------------------------
1004 E[0].Orientation(OriEdgeInFace(E[0],F[0]));
1005 E[2].Orientation(OriEdgeInFace(E[2],F[1]));
1007 if (DistanceToOZ(VF) < DistanceToOZ(VL) ) {
1009 MapBis(F[0]).Append(CurrentEdge.Oriented (E[0].Orientation()));
1010 CurrentEdge.Orientation(TopAbs::Complement(E[2].Orientation()));
1011 MapBis(F[1]).Append(CurrentEdge);
1015 MapBis(F[1]).Append(CurrentEdge.Oriented (E[2].Orientation()));
1016 CurrentEdge.Orientation(TopAbs::Complement(E[0].Orientation()));
1017 MapBis(F[0]).Append(CurrentEdge);
1021 //----------------------------------------------
1022 // Storage of vertices on parallel edges.
1023 // fill MapBis and MapVerPar.
1024 // VOnF for E[0] and E[2].
1025 // VOnL for E[1] and E[3].
1026 //----------------------------------------------
1027 for (k = 0; k <= 2; k = k+2) {
1028 if ( !MapSeqVer.IsBound(VF)) {
1029 if (!VOnF.IsEmpty()) {
1030 if (!MapBis.IsBound(E[k])) {
1031 MapBis .Bind(E[k],EmptySeq);
1032 MapVerPar.Bind(E[k],EmptySeqOfReal);
1034 for (Standard_Integer ii = 1; ii <= VOnF.Length(); ii++) {
1035 MapBis (E[k]).Append(VOnF.Value(ii));
1036 if (k == 0) MapVerPar (E[k]).Append(ParOnF.Value(ii).Y());
1037 else MapVerPar (E[k]).Append(ParOnF.Value(ii).Z());
1043 for (k = 1; k <= 3; k = k+2) {
1044 if ( !MapSeqVer.IsBound(VL)) {
1045 if (!VOnL.IsEmpty()) {
1046 if (!MapBis.IsBound(E[k])) {
1047 MapBis .Bind(E[k],EmptySeq);
1048 MapVerPar.Bind(E[k],EmptySeqOfReal);
1050 for (Standard_Integer ii = 1; ii <= VOnL.Length(); ii++) {
1051 MapBis(E[k]).Append(VOnL.Value(ii));
1052 if (k == 1) MapVerPar (E[k]).Append(ParOnL.Value(ii).Y());
1053 else MapVerPar (E[k]).Append(ParOnL.Value(ii).Z());
1059 //----------------------------------------------------------------
1060 // Edge [1] of the current face will be Edge [0] of the next face.
1061 // => copy of VonL in VonF. To avoid creating the same vertices twice.
1062 //-----------------------------------------------------------------
1064 MapSeqPar.Bind(VF,ParOnF);
1065 MapSeqVer.Bind(VF,VOnF);
1066 MapSeqPar.Bind(VL,ParOnL);
1067 MapSeqVer.Bind(VL,VOnL);
1074 cout << " End of Construction of edges and vertices on bissectrices"<<endl;
1078 //----------------------------------
1079 // Construction of parallel edges.
1080 //----------------------------------
1081 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape ite1;
1082 TopoDS_Shape CurrentProf,PrecProf;
1083 TopoDS_Face CurrentFace;
1084 TopoDS_Shape CurrentSpine;
1085 TopoDS_Vertex VCF,VCL;
1087 for (ite1.Initialize(myMap); ite1.More(); ite1.Next()) {
1088 CurrentSpine = ite1.Key();
1090 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1091 CurrentProf = ProfExp.Current();
1092 EdgeVertices(TopoDS::Edge(CurrentProf),VCF,VCL);
1093 CurrentEdge = TopoDS::Edge(myMap(CurrentSpine)(VCF).First());
1095 //-------------------------------------------------------------
1096 //RQ : Current Edge is oriented relatively to the face (oriented forward)
1097 // generated by edge CurrentProf .
1098 //-------------------------------------------------------------
1099 if (MapBis.IsBound(CurrentEdge)) {
1101 //--------------------------------------------------------
1102 // Find if one of two faces connected to the edge
1103 // belongs to volevo. The edges on this face serve
1104 // to eliminate certain vertices that can appear twice
1105 // on the parallel edge. These Vertices corespond to the
1106 // nodes of the map.
1107 //---------------------------------------------------------
1108 TopoDS_Shape FaceControle;
1109 Standard_Boolean YaFace = Standard_True;
1111 FaceControle = myMap(CurrentSpine)(CurrentProf).First();
1112 if (!MapBis.IsBound(FaceControle)){
1113 YaFace = Standard_False;
1114 if (!PrecProf.IsNull()) {
1115 FaceControle = myMap(CurrentSpine)(PrecProf).First();
1116 if (MapBis.IsBound(FaceControle)){
1117 YaFace = Standard_True;
1123 //------------------------------------------------------------
1124 // No connected face in the volevo => no parallel edge.
1125 //------------------------------------------------------------
1126 TopTools_SequenceOfShape S;
1127 TrimEdge (CurrentEdge,
1128 MapBis (FaceControle),
1129 MapBis (CurrentEdge) ,
1130 MapVerPar(CurrentEdge) , S);
1132 for ( k = 1; k <= S.Length(); k++) {
1133 myMap(CurrentSpine)(VCF).Append(S.Value(k));
1137 sprintf(name,"PAREDGE_%d_%d",++NbEDGES,k);
1138 DBRep::Set(name,S.Value(k));
1144 PrecProf = CurrentProf;
1147 //------------------------------------------------------------
1148 // Construction of the parallel edge from the last vertex of myProfile.
1149 //------------------------------------------------------------
1150 CurrentEdge = TopoDS::Edge(myMap(CurrentSpine)(VCL).First());
1152 if (MapBis.IsBound(CurrentEdge)) {
1153 Standard_Boolean YaFace = Standard_True;
1154 TopoDS_Shape FaceControle;
1156 FaceControle = myMap(CurrentSpine)(CurrentProf).First();
1157 if (!MapBis.IsBound(FaceControle)){
1158 YaFace = Standard_False;
1160 // the number of element of the list allows to know
1161 // if the edges have already been done (closed profile) .
1162 if (YaFace && myMap(CurrentSpine)(VCL).Extent()<= 1) {
1163 TopTools_SequenceOfShape S;
1164 TrimEdge (CurrentEdge,
1165 MapBis (FaceControle),
1166 MapBis (CurrentEdge) ,
1167 MapVerPar(CurrentEdge) , S);
1169 for ( k = 1; k <= S.Length(); k++) {
1170 myMap(CurrentSpine)(VCL).Append(S.Value(k));
1174 sprintf(name,"PAREDGE_%d_%d",++NbEDGES,k);
1175 DBRep::Set(name,S.Value(k));
1185 cout <<" End Construction of parallel edges "<<endl;
1189 //-------------------------------------------------------------------
1190 // Cut faces by edges.
1191 //-------------------------------------------------------------------
1192 for (ite1.Initialize(myMap); ite1.More(); ite1.Next()) {
1193 CurrentSpine = ite1.Key();
1195 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1196 CurrentProf = ProfExp.Current();
1197 CurrentFace = TopoDS::Face(myMap(CurrentSpine)(CurrentProf).First());
1198 myMap(CurrentSpine)(CurrentProf).Clear();
1200 if (MapBis.IsBound(CurrentFace)) {
1201 //----------------------------------------------------------
1202 // If the face does not contain edges that can limit it
1203 // it does not appear in volevo.
1204 // cut of face by edges can generate many faces.
1206 // Add edges generated on the edges parallel to the set
1207 // of edges that limit the face.
1209 //------------------------------------------------------------
1210 EdgeVertices(TopoDS::Edge(CurrentProf),VCF,VCL);
1212 TopTools_ListIteratorOfListOfShape itl;
1213 const TopTools_ListOfShape& LF = myMap(CurrentSpine)(VCF);
1215 TopAbs_Orientation Ori = OriEdgeInFace(TopoDS::Edge(LF.First()),
1217 for (itl.Initialize(LF), itl.Next(); itl.More(); itl.Next()) {
1218 TopoDS_Edge RE = TopoDS::Edge(itl.Value());
1219 MapBis(CurrentFace).Append(RE.Oriented(Ori));
1221 const TopTools_ListOfShape& LL = myMap(CurrentSpine)(VCL);
1222 Ori = OriEdgeInFace(TopoDS::Edge(LL.First()),CurrentFace);
1223 for (itl.Initialize(LL), itl.Next() ; itl.More(); itl.Next()) {
1224 TopoDS_Edge RE = TopoDS::Edge(itl.Value());
1225 MapBis(CurrentFace).Append(RE.Oriented(Ori));
1229 TopTools_SequenceOfShape S;
1231 TrimFace (CurrentFace, MapBis(CurrentFace), S);
1233 for (Standard_Integer ii = 1; ii <= S.Length(); ii++) {
1234 myBuilder.Add (myShape,S.Value(ii));
1235 myMap(CurrentSpine)(CurrentProf).Append(S.Value(ii));
1239 //-----------------------------------------------------------------
1240 // Removal of first edge (edge of origin) from lists of myMap
1241 // corresponding to vertices of the profile.
1242 //-----------------------------------------------------------------
1243 TopExp_Explorer Explo(myProfile,TopAbs_VERTEX);
1244 TopTools_MapOfShape vmap;
1246 for ( ; Explo.More(); Explo.Next()){
1247 if (vmap.Add(Explo.Current())) {
1248 myMap(CurrentSpine)(Explo.Current()).RemoveFirst();
1252 myIsDone = Standard_True;
1256 cout <<" End of construction of an elementary volevo."<<endl;
1257 sprintf(name,"VEVO_%d",++NbVEVOS);
1258 DBRep::Set(name,myShape);
1263 //=======================================================================
1264 //function : PlanarPerform
1266 //=======================================================================
1268 void BRepFill_Evolved::PlanarPerform (const TopoDS_Face& Sp,
1269 const TopoDS_Wire& Pr,
1270 const BRepMAT2d_BisectingLocus& Locus,
1271 BRepMAT2d_LinkTopoBilo& Link,
1272 const GeomAbs_JoinType Join)
1274 TopoDS_Shape aLocalShape = Sp.Oriented(TopAbs_FORWARD);
1275 mySpine = TopoDS::Face(aLocalShape);
1276 // mySpine = TopoDS::Face(Sp.Oriented(TopAbs_FORWARD));
1281 B.MakeCompound(TopoDS::Compound(myShape));
1283 BRepTools_WireExplorer ProfExp;
1284 TopExp_Explorer Exp,exp1,exp2;
1286 TopTools_DataMapOfShapeListOfShape EmptyMap;
1287 TopTools_ListOfShape EmptyList;
1288 TopTools_DataMapOfShapeShape MapVP;
1289 BRepFill_OffsetWire Paral;
1291 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1292 const TopoDS_Edge& E = ProfExp.Current();
1293 BRepAlgo_FaceRestrictor FR;
1294 BRepFill_OffsetAncestors OffAnc;
1297 EdgeVertices(E,V[0],V[1]);
1298 Standard_Real Alt = Altitud(V[0]);
1299 Standard_Real Offset[2];
1300 Offset[0] = DistanceToOZ(V[0]);
1301 Offset[1] = DistanceToOZ(V[1]);
1302 Standard_Boolean IsMinV1 = ( Offset[0] < Offset[1]);
1304 for (Standard_Integer i = 0; i <= 1; i++) {
1305 if (!MapVP.IsBound(V[i])) {
1306 //------------------------------------------------
1307 // Calculate parallel lines corresponding to vertices.
1308 //------------------------------------------------
1309 Paral.PerformWithBiLo(mySpine,Offset[i],Locus,Link,Join,Alt);
1310 OffAnc.Perform(Paral);
1311 MapVP.Bind(V[i],Paral.Shape());
1313 //-----------------------------
1314 // Update myMap (.)(V[i])
1315 //-----------------------------
1316 for (Exp.Init(Paral.Shape(),TopAbs_EDGE);
1319 const TopoDS_Edge& WC = TopoDS::Edge(Exp.Current());
1320 const TopoDS_Shape& GS = OffAnc.Ancestor(WC);
1321 if ( !myMap.IsBound(GS))
1322 myMap.Bind(GS, EmptyMap);
1323 if ( !myMap(GS).IsBound(V[i]))
1324 myMap(GS).Bind(V[i],Paral.GeneratedShapes(GS));
1327 TopoDS_Shape Rest = MapVP(V[i]);
1329 Standard_Boolean ToReverse = Standard_False;
1330 if ( ( IsMinV1 && (i==1)) || (!IsMinV1 && (i==0)) )
1331 ToReverse = Standard_True;
1333 if (!Rest.IsNull()) {
1334 if (Rest.ShapeType() == TopAbs_WIRE) {
1336 TopoDS_Shape aLocalShape = Rest.Reversed();
1337 TopoDS_Wire aWire = TopoDS::Wire(aLocalShape);
1341 FR.Add(TopoDS::Wire(Rest));
1344 for (Exp.Init(Rest,TopAbs_WIRE);Exp.More();Exp.Next()) {
1345 TopoDS_Wire WCop = TopoDS::Wire(Exp.Current());
1347 TopoDS_Shape aLocalShape = WCop.Reversed();
1348 TopoDS_Wire bWire = TopoDS::Wire(aLocalShape);
1349 // TopoDS_Wire bWire = TopoDS::Wire(WCop.Reversed());
1360 TopTools_DataMapIteratorOfDataMapOfShapeShape it(MapVP);
1361 Standard_Integer k = 0;
1362 for (; it.More(); it.Next()) {
1363 sprintf(name,"PARALI_%d",++k);
1364 DBRep::Set(name,it.Value());
1369 //----------------------------------------------------
1370 // Construction of faces limited by parallels.
1371 // - set to the height of the support face.
1372 //----------------------------------------------------
1373 gp_Trsf T; T.SetTranslation(gp_Vec(0,0,Alt));
1374 TopLoc_Location LT(T);
1375 TopoDS_Shape aLocalShape = mySpine.Moved(LT);
1376 FR.Init(TopoDS::Face(aLocalShape));
1377 // FR.Init(TopoDS::Face(mySpine.Moved(LT)));
1380 for ( ;FR.More(); FR.Next()) {
1381 const TopoDS_Face& F = FR.Current();
1383 //---------------------------------------
1384 // Update myMap(.)(E)
1385 //---------------------------------------
1386 for ( Exp.Init(F,TopAbs_EDGE); Exp.More(); Exp.Next()) {
1387 const TopoDS_Edge& CE = TopoDS::Edge(Exp.Current());
1388 if (OffAnc.HasAncestor(CE)) {
1389 const TopoDS_Shape& InitE = OffAnc.Ancestor(CE);
1390 if ( !myMap.IsBound(InitE))
1391 myMap.Bind(InitE, EmptyMap);
1392 if ( !myMap(InitE).IsBound(E))
1393 myMap(InitE).Bind(E,EmptyList);
1394 myMap(InitE)(E).Append(F);
1398 } // End loop on profile.
1402 //=======================================================================
1403 //function : VerticalPerform
1405 //=======================================================================
1407 void BRepFill_Evolved::VerticalPerform (const TopoDS_Face& Sp,
1408 const TopoDS_Wire& Pr,
1409 const BRepMAT2d_BisectingLocus& Locus,
1410 BRepMAT2d_LinkTopoBilo& Link,
1411 const GeomAbs_JoinType Join)
1413 TopoDS_Shape aLocalShape = Sp.Oriented(TopAbs_FORWARD);
1414 mySpine = TopoDS::Face(aLocalShape);
1415 // mySpine = TopoDS::Face(Sp.Oriented(TopAbs_FORWARD));
1420 B.MakeCompound(TopoDS::Compound(myShape));
1422 BRepTools_WireExplorer ProfExp;
1423 TopExp_Explorer Exp;
1424 BRepFill_OffsetWire Paral;
1425 BRepFill_OffsetAncestors OffAnc;
1426 TopoDS_Vertex V1,V2;
1428 Standard_Boolean First = Standard_True;
1430 TopTools_DataMapOfShapeListOfShape EmptyMap;
1432 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1433 const TopoDS_Edge& E = ProfExp.Current();
1434 EdgeVertices(E,V1,V2);
1435 Standard_Real Alt1 = Altitud(V1);
1436 Standard_Real Alt2 = Altitud(V2);
1439 Standard_Real Offset = DistanceToOZ(V1);
1440 if (Abs(Offset) < BRepFill_Confusion()) {
1443 Paral.PerformWithBiLo(mySpine,Offset,Locus,Link,Join,Alt1);
1444 OffAnc.Perform(Paral);
1445 Base = Paral.Shape();
1448 for (Exp.Init(Base,TopAbs_EDGE); Exp.More(); Exp.Next()) {
1449 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1450 const TopoDS_Shape& AE = OffAnc.Ancestor(E);
1451 if (!myMap.IsBound(AE)) {
1452 myMap.Bind(AE,EmptyMap);
1454 if (!myMap(AE).IsBound(V1)) {
1455 TopTools_ListOfShape L;
1456 myMap(AE).Bind(V1,L);
1458 myMap(AE)(V1).Append(E);
1460 First = Standard_False;
1466 sprintf(name,"PARALI_%d",++NbVEVOS);
1467 DBRep::Set(name,Base);
1471 BRepSweep_Prism PS(Base,gp_Vec(0,0,Alt2 - Alt1),Standard_False);
1474 sprintf(name,"PRISM_%d",NbVEVOS);
1475 DBRep::Set(name,PS.Shape());
1479 Base = PS.LastShape();
1481 for (Exp.Init(PS.Shape(),TopAbs_FACE); Exp.More(); Exp.Next()) {
1482 B.Add(myShape,Exp.Current());
1486 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape
1489 for (; it.More(); it.Next()) {
1490 const TopTools_ListOfShape& LOF = it.Value()(V1);
1491 TopTools_ListIteratorOfListOfShape itLOF(LOF);
1492 if (!myMap(it.Key()).IsBound(V2)) {
1493 TopTools_ListOfShape L;
1494 myMap(it.Key()).Bind(V2,L);
1497 if (!myMap(it.Key()).IsBound(E)) {
1498 TopTools_ListOfShape L;
1499 myMap(it.Key()).Bind(E,L);
1502 for (; itLOF.More(); itLOF.Next()) {
1503 const TopoDS_Shape& OS = itLOF.Value();
1504 myMap(it.Key())(V2).Append(PS.LastShape(OS));
1505 myMap(it.Key())(E).Append(PS.Shape(OS));
1511 //=======================================================================
1513 //purpose : Order the sequence of points by growing x.
1514 //=======================================================================
1516 static void Bubble(TColStd_SequenceOfReal& Seq)
1518 Standard_Boolean Invert = Standard_True;
1519 Standard_Integer NbPoints = Seq.Length();
1522 Invert = Standard_False;
1523 for ( Standard_Integer i = 1; i < NbPoints; i++) {
1524 if ( Seq.Value(i+1) < Seq.Value(i)) {
1525 Seq.Exchange(i,i+1);
1526 Invert = Standard_True;
1533 //=======================================================================
1534 //function : PrepareProfile
1535 //purpose : - Projection of the profile on the working plane.
1536 // - Cut of the profile at the extrema of distance from profile to axis Oz.
1537 // - Isolate vertical and horizontal parts.
1538 // - Reconstruction of wires starting from cut edges.
1539 // New wires stored in <WorkProf> are always at the same
1540 // side of axis OZ or mixed with it.
1541 //=======================================================================
1543 void BRepFill_Evolved::PrepareProfile(TopTools_ListOfShape& WorkProf,
1544 TopTools_DataMapOfShapeShape& MapProf )
1547 // Supposedly the profile is located so that the only transformation
1548 // to be carried out is a projection on plane yOz.
1550 // initialise the projection Plane and the Line to evaluate the extrema.
1551 Handle(Geom_Plane) Plane = new Geom_Plane(gp_Ax3(gp::YOZ()));
1552 Handle(Geom2d_Line) Line = new Geom2d_Line(gp::OY2d());
1554 // Map initial vertex -> projected vertex.
1555 TopTools_DataMapOfShapeShape MapVerRefMoved;
1557 TopoDS_Vertex V1,V2,VRef1,VRef2;
1560 TopTools_ListOfShape WP;
1564 BRepTools_WireExplorer Exp(myProfile) ;
1566 while (Exp.More()) {
1567 TopTools_ListOfShape Cuts;
1568 Standard_Boolean NewWire = Standard_False;
1569 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1572 CutEdgeProf (E ,Plane ,Line ,Cuts ,MapVerRefMoved);
1574 EdgeVertices(E,VRef1,VRef2);
1576 if ( Cuts.IsEmpty()) {
1577 // Neither extrema nor intersections nor vertices on the axis.
1582 while (!Cuts.IsEmpty()) {
1583 const TopoDS_Edge& NE = TopoDS::Edge(Cuts.First());
1585 EdgeVertices(NE,V1,V2);
1586 if (!MapProf.IsBound(V1)) MapProf.Bind(V1,E);
1587 if (!MapProf.IsBound(V2)) MapProf.Bind(V2,E);
1592 if (DistanceToOZ(V2) < BRepFill_Confusion() &&
1593 DistanceToOZ(V1) > BRepFill_Confusion()) {
1594 // NE ends on axis OZ => new wire
1595 if (Cuts.IsEmpty()) {
1596 // last part of the current edge
1597 // If it is not the last edge of myProfile
1598 // create a new wire.
1599 NewWire = Standard_True;
1610 if (Exp.More() && NewWire) {
1616 // In the list of Wires, find edges generating plane or vertical vevo.
1617 TopTools_ListIteratorOfListOfShape ite;
1618 TopoDS_Wire CurW,NW;
1622 for (ite.Initialize(WP); ite.More(); ite.Next()) {
1623 CurW = TopoDS::Wire(ite.Value());
1624 Standard_Boolean YaModif = Standard_False;
1625 for (EW.Init(CurW,TopAbs_EDGE); EW.More(); EW.Next()) {
1626 const TopoDS_Edge& EE = TopoDS::Edge(EW.Current());
1627 if (IsVertical(EE) || IsPlanar(EE)) {
1628 YaModif = Standard_True;
1634 //Status = 0 for the begining
1638 Standard_Integer Status = 0;
1640 for (EW.Init(CurW,TopAbs_EDGE); EW.More(); EW.Next()) {
1641 const TopoDS_Edge& EE = TopoDS::Edge(EW.Current());
1642 if (IsVertical(EE)) {
1645 WorkProf.Append(NW);
1649 else if (IsPlanar(EE)) {
1652 WorkProf.Append(NW);
1656 else if ( Status != 1) {
1658 WorkProf.Append(NW);
1665 WorkProf.Append(CurW);
1669 //connect vertices modified in MapProf;
1670 TopTools_DataMapIteratorOfDataMapOfShapeShape gilbert(MapVerRefMoved);
1671 for ( ;gilbert.More() ;gilbert.Next()) {
1672 MapProf.Bind(gilbert.Value(),gilbert.Key());
1677 //=======================================================================
1678 //function : PrepareSpine
1680 //=======================================================================
1682 void BRepFill_Evolved::PrepareSpine(TopoDS_Face& WorkSpine,
1683 TopTools_DataMapOfShapeShape& MapSpine)
1687 TopTools_ListOfShape Cuts;
1688 TopTools_ListIteratorOfListOfShape IteCuts;
1689 TopoDS_Vertex V1,V2;
1692 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1693 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1694 B.MakeFace(WorkSpine,S,L,TolF);
1696 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1701 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1703 TopoDS_Edge E = TopoDS::Edge(IteW.Value());
1704 EdgeVertices(E,V1,V2);
1705 MapSpine.Bind(V1,V1);
1706 MapSpine.Bind(V2,V2);
1710 CutEdge (E, mySpine, Cuts);
1712 if (Cuts.IsEmpty()) {
1717 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1718 const TopoDS_Edge& NE = TopoDS::Edge(IteCuts.Value());
1720 MapSpine.Bind(NE,E);
1721 EdgeVertices(NE,V1,V2);
1722 if (!MapSpine.IsBound(V1)) MapSpine.Bind(V1,E);
1723 if (!MapSpine.IsBound(V2)) MapSpine.Bind(V2,E);
1727 B.Add(WorkSpine, NW);
1730 // Construct curves 3D of the spine
1731 BRepLib::BuildCurves3d(WorkSpine);
1735 sprintf(name,"workspine");
1736 DBRep::Set(name,WorkSpine);
1741 //=======================================================================
1742 //function : GeneratedShapes
1744 //=======================================================================
1746 const TopoDS_Shape& BRepFill_Evolved::Top() const
1751 //=======================================================================
1752 //function : GeneratedShapes
1754 //=======================================================================
1756 const TopoDS_Shape& BRepFill_Evolved::Bottom() const
1761 //=======================================================================
1762 //function : GeneratedShapes
1764 //=======================================================================
1766 const TopTools_ListOfShape& BRepFill_Evolved::GeneratedShapes (
1767 const TopoDS_Shape& SpineShape,
1768 const TopoDS_Shape& ProfShape )
1771 if (myMap .IsBound(SpineShape) &&
1772 myMap(SpineShape).IsBound(ProfShape) ) {
1773 return myMap(SpineShape)(ProfShape);
1776 static TopTools_ListOfShape Empty;
1781 //=======================================================================
1782 //function : Generated
1784 //=================================================================== ====
1786 BRepFill_DataMapOfShapeDataMapOfShapeListOfShape& BRepFill_Evolved::Generated()
1791 //=======================================================================
1792 //function : Compare
1794 //=======================================================================
1796 static TopAbs_Orientation Compare (const TopoDS_Edge& E1,
1797 const TopoDS_Edge& E2)
1799 TopAbs_Orientation OO = TopAbs_FORWARD;
1800 TopoDS_Vertex V1[2],V2[2];
1801 TopExp::Vertices (E1,V1[0],V1[1]);
1802 TopExp::Vertices (E2,V2[0],V2[1]);
1803 gp_Pnt P1 = BRep_Tool::Pnt(V1[0]);
1804 gp_Pnt P2 =BRep_Tool::Pnt(V2[0]);
1805 gp_Pnt P3 =BRep_Tool::Pnt(V2[1]);
1806 if (P1.Distance(P3) < P1.Distance(P2)) OO = TopAbs_REVERSED;
1811 //=======================================================================
1814 //=======================================================================
1816 void BRepFill_Evolved::Add( BRepFill_Evolved& Vevo,
1817 const TopoDS_Wire& Prof,
1818 BRepTools_Quilt& Glue)
1821 BRepFill_DataMapOfShapeDataMapOfShapeListOfShape& MapVevo = Vevo.Generated();
1822 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape iteP;
1823 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape iteS;
1824 TopoDS_Shape CurrentSpine, CurrentProf;
1826 if (Vevo.Shape().IsNull()) return;
1828 //-------------------------------------------------
1829 // Find wires common to <me> and <Vevo>.
1830 //-------------------------------------------------
1832 TopExp_Explorer ExProf;
1833 for (ExProf.Init(Prof,TopAbs_VERTEX); ExProf.More(); ExProf.Next()) {
1834 const TopoDS_Shape& VV = ExProf.Current();
1835 //---------------------------------------------------------------
1836 // Parse edges generated by VV in myMap if they existent
1838 //---------------------------------------------------------------
1840 //------------------------------------------------- -------------
1841 // Note: the curves of of reinforced edges are in the same direction
1842 // if one remains on the same edge.
1843 // if one passes from left to the right they are inverted.
1844 //------------------------------------------------- -------------
1845 Standard_Boolean Commun = Standard_False;
1846 Relative(myProfile,Prof,
1851 for (iteS.Initialize(myMap); iteS.More(); iteS.Next()) {
1852 const TopoDS_Shape& SP = iteS.Key();
1853 if (iteS.Value().IsBound(VV) &&
1854 MapVevo.IsBound(SP) && MapVevo(SP).IsBound(VV)) {
1856 const TopTools_ListOfShape& MyList = myMap(SP)(VV);
1857 const TopTools_ListOfShape& VevoList = Vevo.GeneratedShapes(SP,VV);
1858 TopTools_ListIteratorOfListOfShape MyIte (MyList);
1859 TopTools_ListIteratorOfListOfShape VevoIte(VevoList);
1860 for (; MyIte.More(); MyIte.Next(), VevoIte.Next()) {
1861 const TopoDS_Edge& ME = TopoDS::Edge(MyIte .Value());
1862 const TopoDS_Edge& VE = TopoDS::Edge(VevoIte.Value());
1863 TopAbs_Orientation OG = Compare(ME,VE);
1864 TopoDS_Shape aLocalShape = VE.Oriented (TopAbs_FORWARD);
1865 TopoDS_Shape aLocalShape2 = ME.Oriented (OG);
1866 Glue.Bind(TopoDS::Edge(aLocalShape),TopoDS::Edge(aLocalShape2));
1867 // Glue.Bind(TopoDS::Edge(VE.Oriented (TopAbs_FORWARD)),
1868 // TopoDS::Edge(ME.Oriented (OG)));
1874 Glue.Add(Vevo.Shape());
1876 //----------------------------------------------------------
1877 // Add map of elements generate in Vevo in myMap.
1878 //----------------------------------------------------------
1879 TopTools_DataMapOfShapeListOfShape EmptyMap;
1880 TopTools_ListOfShape EmptyList;
1882 for (iteS.Initialize(MapVevo); iteS.More() ; iteS.Next()) {
1883 CurrentSpine = iteS.Key();
1884 for (iteP.Initialize(MapVevo(CurrentSpine)); iteP.More(); iteP.Next()) {
1885 CurrentProf = iteP.Key();
1886 if (!myMap.IsBound(CurrentSpine)) {
1887 //------------------------------------------------
1888 // The element of spine is not yet present .
1889 // => previous profile not on the border.
1890 //-------------------------------------------------
1891 myMap.Bind(CurrentSpine,EmptyMap);
1893 if (!myMap(CurrentSpine).IsBound(CurrentProf)) {
1894 myMap(CurrentSpine).Bind(CurrentProf,EmptyList);
1895 const TopTools_ListOfShape& GenShapes
1896 = MapVevo (CurrentSpine)(CurrentProf);
1897 TopTools_ListIteratorOfListOfShape itl (GenShapes);
1898 for (; itl.More(); itl.Next()) {
1899 // during Glue.Add the shared shapes are recreated.
1900 if (Glue.IsCopied(itl.Value()))
1901 myMap(CurrentSpine)(CurrentProf).Append(Glue.Copy(itl.Value()));
1903 myMap(CurrentSpine)(CurrentProf).Append(itl.Value());
1910 //=======================================================================
1911 //function : ChangeShape
1913 //=======================================================================
1915 TopoDS_Shape& BRepFill_Evolved::ChangeShape()
1920 //=======================================================================
1921 //function : Transfert
1923 //=======================================================================
1925 void BRepFill_Evolved::Transfert( BRepFill_Evolved& Vevo,
1926 const TopTools_DataMapOfShapeShape& MapProf,
1927 const TopTools_DataMapOfShapeShape& MapSpine,
1928 const TopLoc_Location& LS,
1929 const TopLoc_Location& InitLS,
1930 const TopLoc_Location& InitLP)
1932 //----------------------------------------------------------------
1933 // Transfer the shape from Vevo in myShape and Reposition shapes.
1934 //----------------------------------------------------------------
1935 myShape = Vevo.Shape();
1936 mySpine .Location(InitLS);
1937 myProfile.Location(InitLP);
1941 // Expecting for better, the Same Parameter is forced here
1942 // ( Pb Sameparameter between YaPlanar and Tuyaux
1945 TopExp_Explorer ex(myShape,TopAbs_EDGE);
1947 B.SameRange(TopoDS::Edge(ex.Current()), Standard_False);
1948 B.SameParameter(TopoDS::Edge(ex.Current()), Standard_False);
1949 BRepLib::SameParameter(TopoDS::Edge(ex.Current()));
1954 //--------------------------------------------------------------
1955 // Transfer of myMap of Vevo into myMap.
1956 //--------------------------------------------------------------
1957 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape iteS;
1958 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape iteP;
1959 TopTools_DataMapOfShapeListOfShape EmptyMap;
1960 TopTools_ListOfShape EmptyList;
1961 TopoDS_Shape InitialSpine, InitialProf;
1963 BRepFill_DataMapOfShapeDataMapOfShapeListOfShape& MapVevo
1966 for (iteS.Initialize(MapVevo); iteS.More(); iteS.Next()) {
1967 InitialSpine = MapSpine(iteS.Key());
1968 InitialSpine.Move(LS);
1970 for (iteP.Initialize(MapVevo(iteS.Key())); iteP.More(); iteP.Next()) {
1971 InitialProf = MapProf (iteP.Key());
1972 InitialProf.Location(InitLP);
1974 TopTools_ListOfShape& GenShapes =
1975 MapVevo.ChangeFind(iteS.Key()).ChangeFind(iteP.Key());
1977 TopTools_ListIteratorOfListOfShape itl;
1978 for (itl.Initialize(GenShapes); itl.More(); itl.Next()) {
1979 itl.Value().Move(LS);
1982 if (!myMap.IsBound(InitialSpine)) {
1983 myMap.Bind(InitialSpine,EmptyMap);
1986 if (!myMap(InitialSpine).IsBound(InitialProf)) {
1987 myMap(InitialSpine).Bind(InitialProf,EmptyList);
1989 myMap(InitialSpine)(InitialProf).Append(GenShapes);
1992 //--------------------------------------------------------------
1993 // Transfer of Top and Bottom of Vevo in myTop and myBottom.
1994 //--------------------------------------------------------------
1995 myTop = Vevo.Top() ; myTop.Move(LS);
1996 myBottom = Vevo.Bottom(); myBottom.Move(LS);
1999 //=======================================================================
2002 //=======================================================================
2004 Standard_Boolean BRepFill_Evolved::IsDone() const
2009 //=======================================================================
2012 //=======================================================================
2014 const TopoDS_Shape& BRepFill_Evolved::Shape() const
2019 //=======================================================================
2020 //function : JoinType
2022 //=======================================================================
2024 GeomAbs_JoinType BRepFill_Evolved::JoinType() const
2029 //=======================================================================
2030 //function : AddTopAndBottom
2032 //=======================================================================
2034 void BRepFill_Evolved::AddTopAndBottom(BRepTools_Quilt& Glue)
2036 // return first and last vertex of the profile.
2038 TopExp::Vertices (myProfile,V[0],V[1]);
2039 if (V[0].IsSame(V[1])) return;
2041 TopTools_ListIteratorOfListOfShape itL;
2042 Standard_Boolean ToReverse=Standard_False;
2043 for (Standard_Integer i = 0; i<=1; i++) {
2046 // Construction of supports.
2047 gp_Pln S (0.,0.,1.,- Altitud(V[i]));
2048 TopoDS_Face F = BRepLib_MakeFace(S);
2051 TopExp_Explorer ExpSpine(mySpine,TopAbs_EDGE);
2052 TopTools_MapOfShape View;
2054 for (; ExpSpine.More(); ExpSpine.Next()) {
2055 const TopoDS_Edge& ES = TopoDS::Edge(ExpSpine.Current());
2056 const TopTools_ListOfShape& L = GeneratedShapes(ES,V[i]);
2057 Standard_Boolean ComputeOrientation = 0;
2059 for (itL.Initialize(L); itL.More(); itL.Next()) {
2060 const TopoDS_Edge& E = TopoDS::Edge(itL.Value());
2062 if (!ComputeOrientation) {
2063 BRepAdaptor_Curve C1(ES);
2064 BRepAdaptor_Curve C2(E);
2065 Standard_Real f,l,fs,ls;
2066 BRep_Tool::Range(E ,f ,l);
2067 BRep_Tool::Range(ES,fs,ls);
2068 Standard_Real u = 0.3*f + 0.7*l;
2069 Standard_Real us = 0.3*fs + 0.7*ls;
2072 C1.D1(us,P,V1); C2.D1(u,P,V2);
2073 ToReverse = (V1.Dot(V2) < 0.);
2074 ComputeOrientation = 1;
2077 TopAbs_Orientation Or = ES.Orientation();
2078 if (ToReverse) Or = TopAbs::Reverse(Or);
2079 TopoDS_Shape aLocalShape = E.Oriented(Or);
2080 Loop.AddConstEdge(TopoDS::Edge(aLocalShape));
2081 // Loop.AddConstEdge(TopoDS::Edge(E.Oriented(Or)));
2085 gp_Pnt PV = BRep_Tool::Pnt(V[i]);
2086 Standard_Boolean IsOut = PV.Y() < 0;
2088 for (ExpSpine.Init(mySpine,TopAbs_VERTEX); ExpSpine.More(); ExpSpine.Next()) {
2089 const TopoDS_Vertex& ES = TopoDS::Vertex(ExpSpine.Current());
2091 const TopTools_ListOfShape& L = GeneratedShapes(ES,V[i]);
2092 for (itL.Initialize(L); itL.More(); itL.Next()) {
2093 const TopoDS_Edge& E = TopoDS::Edge(itL.Value());
2094 if (!BRep_Tool::Degenerated(E)){
2095 // the center of circle (ie vertex) is IN the cap if vertex IsOut
2097 BRepAdaptor_Curve C(E);
2099 BRep_Tool::Range(E,f,l);
2100 Standard_Real u = 0.3*f + 0.7*l;
2101 gp_Pnt P = BRep_Tool::Pnt(ES);
2106 gp_Vec Prod = PPC.Crossed(VC);
2108 ToReverse = Prod.Z() < 0.;
2111 ToReverse = Prod.Z() > 0.;
2113 TopAbs_Orientation Or = TopAbs_FORWARD;
2114 if (ToReverse) Or = TopAbs_REVERSED;
2115 TopoDS_Shape aLocalShape = E.Oriented(Or);
2116 Loop.AddConstEdge(TopoDS::Edge(aLocalShape));
2117 // Loop.AddConstEdge(TopoDS::Edge(E.Oriented(Or)));
2124 Loop.WiresToFaces();
2125 const TopTools_ListOfShape& L = Loop.NewFaces();
2126 TopTools_ListIteratorOfListOfShape itL(L);
2128 // Maj of myTop and myBottom for the history
2129 // and addition of constructed faces.
2130 TopoDS_Compound Bouchon;
2132 B.MakeCompound(Bouchon);
2133 Standard_Integer j = 0;
2135 for (itL.Initialize(L); itL.More(); itL.Next()) {
2137 Glue.Add(itL.Value());
2138 if (j ==1 && i == 0) myTop = itL.Value();
2139 if (j ==1 && i == 1) myBottom = itL.Value();
2140 B.Add(Bouchon,itL.Value());
2142 if (i == 0 && j > 1) myTop = Bouchon;
2143 if (i == 1 && j > 1) myBottom = Bouchon;
2147 //================================================================== =====
2148 //function : MakePipe
2150 //=======================================================================
2152 void BRepFill_Evolved::MakeSolid()
2155 TopExp_Explorer exp(myShape,TopAbs_SHELL);
2156 Standard_Integer ish=0;
2157 TopoDS_Compound Res;
2160 B.MakeCompound(Res);
2162 for (; exp.More(); exp.Next()) {
2163 TopoDS_Shape Sh = exp.Current();
2166 BRepClass3d_SolidClassifier SC(Sol);
2167 SC.PerformInfinitePoint(BRepFill_Confusion());
2168 if (SC.State() == TopAbs_IN) {
2170 B.Add(Sol,Sh.Reversed());
2175 if (ish == 1) { myShape = Sol;}
2176 else { myShape = Res;}
2180 //=======================================================================
2181 //function : MakePipe
2183 //=======================================================================
2185 void BRepFill_Evolved::MakePipe(const TopoDS_Edge& SE,
2186 const gp_Ax3& AxeRef)
2188 BRepTools_WireExplorer ProfExp;
2189 TopExp_Explorer FaceExp;
2192 if (Side(myProfile,BRepFill_Confusion()) > 3) { // side right
2193 trsf.SetRotation(gp::OZ(),M_PI);
2195 TopLoc_Location DumLoc (trsf);
2196 TopoDS_Shape aLocalShape = myProfile.Moved(DumLoc);
2197 TopoDS_Wire DummyProf =
2198 PutProfilAt (TopoDS::Wire(aLocalShape),
2200 mySpine,Standard_True);
2201 // TopoDS_Wire DummyProf =
2202 // PutProfilAt (TopoDS::Wire(myProfile.Moved(DumLoc)),
2204 // mySpine,Standard_True);
2206 // Copy of the profile to avoid the accumulation of
2207 // locations on the Edges of myProfile!
2209 Handle(BRepTools_TrsfModification) TrsfMod
2210 = new BRepTools_TrsfModification(gp_Trsf());
2211 BRepTools_Modifier Modif(DummyProf,TrsfMod);
2213 TopoDS_Wire GenProf = TopoDS::Wire(Modif.ModifiedShape(DummyProf));
2217 sprintf(name,"EVOLBASE_%d",++NbFACES);
2218 DBRep::Set(name,SE);
2219 sprintf(name,"EVOLPROF_%d",NbFACES);
2220 DBRep::Set(name,GenProf);
2224 BRepFill_Pipe Pipe(BRepLib_MakeWire(SE), GenProf);
2225 //BRepFill_Pipe Pipe = BRepFill_Pipe(BRepLib_MakeWire(SE),GenProf);
2229 sprintf(name,"EVOL_%d",++NbFACES);
2230 DBRep::Set(name,Pipe.Shape());
2233 //---------------------------------------------
2234 // Arrangement of Tubes in myMap.
2235 //---------------------------------------------
2237 BRepTools_WireExplorer GenProfExp;
2238 TopTools_ListOfShape L;
2239 TopoDS_Vertex VF,VL,VFG,VLG;
2240 Standard_Boolean FirstVertex = Standard_True;
2241 TopTools_DataMapOfShapeListOfShape P;
2245 for (ProfExp.Init(myProfile),GenProfExp.Init(GenProf);
2247 ProfExp.Next(),GenProfExp.Next()) {
2249 EdgeVertices(ProfExp .Current(),VF ,VL);
2250 EdgeVertices(GenProfExp.Current(),VFG,VLG);
2253 myMap(SE).Bind(VF,L);
2254 myMap(SE)(VF).Append(Pipe.Edge(SE,VFG));
2255 FirstVertex = Standard_False;
2257 myMap(SE).Bind(VL,L);
2258 myMap(SE)(VL).Append(Pipe.Edge(SE,VLG));
2259 myMap(SE).Bind(ProfExp.Current(),L);
2260 myMap(SE)(ProfExp.Current()).Append
2261 (Pipe.Face(SE,GenProfExp.Current()));
2266 //=======================================================================
2267 //function : MakeRevol
2269 //=======================================================================
2271 void BRepFill_Evolved::MakeRevol(const TopoDS_Edge& SE,
2272 const TopoDS_Vertex& VLast,
2273 const gp_Ax3& AxeRef)
2275 BRepTools_WireExplorer ProfExp;
2276 TopExp_Explorer FaceExp;
2279 if (Side(myProfile,BRepFill_Confusion()) > 3) { // side right
2280 trsf.SetRotation(gp::OZ(),M_PI);
2282 TopLoc_Location DumLoc (trsf);
2283 TopoDS_Shape aLocalShape = myProfile.Moved(DumLoc);
2284 TopoDS_Wire GenProf =
2285 PutProfilAt (TopoDS::Wire(aLocalShape),
2287 mySpine,Standard_False);
2288 // TopoDS_Wire GenProf =
2289 // PutProfilAt (TopoDS::Wire(myProfile.Moved(DumLoc)),
2291 // mySpine,Standard_False);
2293 gp_Ax1 AxeRev( BRep_Tool::Pnt(VLast), -gp::DZ());
2295 // Position of the sewing on the edge of the spine
2296 // so that the bissectrices didn't cross the sewings.
2298 dummy.SetRotation(AxeRev, 1.5*M_PI);
2299 TopLoc_Location DummyLoc(dummy);
2300 GenProf.Move(DummyLoc);
2302 BRepSweep_Revol Rev(GenProf,AxeRev,Standard_True);
2306 sprintf(name,"EVOLBASE_%d",++NbFACES);
2308 DrawTrSurf::Set(Temp,new Geom_Line(AxeRev));
2309 // DrawTrSurf::Set(name,new Geom_Line(AxeRev));
2310 sprintf(name,"EVOLPROF_%d",NbFACES);
2311 DBRep::Set(name,GenProf);
2313 sprintf(name,"EVOL_%d",NbFACES);
2314 DBRep::Set(name,Rev.Shape());
2317 //--------------------------------------------
2318 // Arrangement of revolutions in myMap.
2319 //---------------------------------------------
2320 BRepTools_WireExplorer GenProfExp;
2321 TopTools_ListOfShape L;
2322 TopoDS_Vertex VF,VL,VFG,VLG;
2323 Standard_Boolean FirstVertex = Standard_True;
2324 TopTools_DataMapOfShapeListOfShape R;
2326 myMap.Bind(VLast,R);
2328 for (ProfExp.Init(myProfile),GenProfExp.Init(GenProf);
2330 ProfExp.Next(),GenProfExp.Next()) {
2332 EdgeVertices(ProfExp .Current(),VF ,VL);
2333 EdgeVertices(GenProfExp.Current(),VFG,VLG);
2335 TopAbs_Orientation Or = GenProfExp.Current().Orientation();
2338 myMap(VLast).Bind(VF,L);
2339 const TopoDS_Shape& RV = Rev.Shape(VFG);
2340 // TopAbs_Orientation OO = TopAbs::Compose(RV.Orientation(),Or);
2341 TopAbs_Orientation OO = RV.Orientation();
2342 myMap(VLast)(VF).Append(RV.Oriented(OO));
2343 FirstVertex = Standard_False;
2345 myMap(VLast).Bind(ProfExp.Current(),L);
2346 const TopoDS_Shape& RF = Rev.Shape(GenProfExp.Current());
2347 TopAbs_Orientation OO = TopAbs::Compose(RF.Orientation(),Or);
2349 myMap(VLast)(ProfExp.Current()).Append(RF.Oriented(OO));
2350 myMap(VLast).Bind(VL,L);
2351 const TopoDS_Shape& RV = Rev.Shape(VLG);
2352 // OO = TopAbs::Compose(RV.Orientation(),Or);
2353 OO = RV.Orientation();
2354 myMap(VLast)(VL).Append(RV.Oriented(OO));
2358 //=======================================================================
2359 //function : FindLocation
2361 //=======================================================================
2363 TopLoc_Location BRepFill_Evolved::FindLocation(const TopoDS_Face& Face)
2367 Handle(Geom_Surface) S;
2368 S = BRep_Tool::Surface(Face, L);
2370 if ( !S->IsKind(STANDARD_TYPE(Geom_Plane))) {
2371 BRepLib_FindSurface FS( Face, -1, Standard_True);
2377 Standard_NoSuchObject::Raise
2378 ("BRepFill_Evolved : The Face is not planar");
2381 if (!L.IsIdentity())
2382 S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
2384 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
2385 gp_Ax3 Axis = P->Position();
2388 gp_Ax3 AxeRef(gp_Pnt(0.,0.,0.),
2391 T.SetTransformation(AxeRef,Axis);
2393 return TopLoc_Location(T);
2397 //=======================================================================
2398 //function : TransformInitWork
2400 //=======================================================================
2402 void BRepFill_Evolved::TransformInitWork(const TopLoc_Location& LS,
2403 const TopLoc_Location& LP)
2410 sprintf(name,"movedspine");
2411 TopoDS_Face SL = mySpine;
2412 DBRep::Set(name,SL);
2413 sprintf(name,"movedprofile");
2414 TopoDS_Wire PL = myProfile;
2415 DBRep::Set(name,PL);
2421 //=======================================================================
2422 //function : ContinuityOnOffsetEdge
2423 //purpose : Coding of regularities on edges parallel to CutVevo
2424 // common to left and right parts of volevo.
2425 //=======================================================================
2426 void BRepFill_Evolved::ContinuityOnOffsetEdge (const TopTools_ListOfShape&)
2428 BRepTools_WireExplorer WExp ;
2429 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape iteS;
2430 TopoDS_Vertex VF,VL,V;
2431 TopoDS_Edge PrecE,CurE,FirstE;
2435 WExp.Init(myProfile);
2436 FirstE = WExp.Current();
2438 EdgeVertices (FirstE, VF, V);
2439 if (WExp.More()) WExp.Next();
2441 for (; WExp.More(); WExp.Next()) {
2442 CurE = WExp.Current();
2443 V = WExp.CurrentVertex();
2445 if (DistanceToOZ(V) <= BRepFill_Confusion()) {
2446 // the regularities are already coded on the edges of elementary volevos
2447 Standard_Real U1 = BRep_Tool::Parameter(V,CurE);
2448 Standard_Real U2 = BRep_Tool::Parameter(V,PrecE);
2449 BRepAdaptor_Curve Curve1(CurE);
2450 BRepAdaptor_Curve Curve2(PrecE);
2451 GeomAbs_Shape Continuity = BRepLProp::Continuity(Curve1,Curve2,U1,U2);
2453 if (Continuity >=1) {
2454 //-----------------------------------------------------
2455 //Code continuity for all edges generated by V.
2456 //-----------------------------------------------------
2457 for (iteS.Initialize(myMap); iteS.More(); iteS.Next()) {
2458 const TopoDS_Shape& SP = iteS.Key();
2459 if (myMap (SP).IsBound(V)
2460 && myMap (SP).IsBound(CurE) && myMap (SP).IsBound(PrecE)){
2461 if (!myMap(SP)(V) .IsEmpty() &&
2462 !myMap(SP)(CurE) .IsEmpty() &&
2463 !myMap(SP)(PrecE).IsEmpty() )
2464 B.Continuity (TopoDS::Edge(myMap(SP)(V) .First()),
2465 TopoDS::Face(myMap(SP)(CurE) .First()),
2466 TopoDS::Face(myMap(SP)(PrecE).First()),
2475 EdgeVertices (PrecE, V, VL);
2477 if (VF.IsSame(VL)) {
2479 Standard_Real U1 = BRep_Tool::Parameter(VF,CurE);
2480 Standard_Real U2 = BRep_Tool::Parameter(VF,FirstE);
2481 BRepAdaptor_Curve Curve1(CurE);
2482 BRepAdaptor_Curve Curve2(FirstE);
2483 GeomAbs_Shape Continuity = BRepLProp::Continuity(Curve1,Curve2,U1,U2);
2485 if (Continuity >=1) {
2486 //---------------------------------------------
2487 //Code continuity for all edges generated by V.
2488 //---------------------------------------------
2489 for (iteS.Initialize(myMap); iteS.More(); iteS.Next()) {
2490 const TopoDS_Shape& SP = iteS.Key();
2491 if (myMap (SP).IsBound(VF)
2492 && myMap (SP).IsBound(CurE) && myMap (SP).IsBound(FirstE)){
2493 if (!myMap(SP)(VF) .IsEmpty() &&
2494 !myMap(SP)(CurE) .IsEmpty() &&
2495 !myMap(SP)(FirstE).IsEmpty() )
2496 B.Continuity (TopoDS::Edge(myMap(SP)(VF) .First()),
2497 TopoDS::Face(myMap(SP)(CurE) .First()),
2498 TopoDS::Face(myMap(SP)(FirstE).First()),
2506 //=======================================================================
2507 //function : AddDegeneratedEdge
2508 //purpose : degenerated edges can be missing in some face
2509 // the missing degenerated edges have vertices corresponding
2510 // to node of the map.
2511 // Now it is enough to compare points UV of vertices
2512 // on edges with a certain tolerance.
2513 //=======================================================================
2515 static void AddDegeneratedEdge(TopoDS_Face& F,
2519 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
2520 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2521 Handle(Geom_Surface) SB = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
2522 if (SB->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2527 if (S->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2533 Standard_Real TolConf = 1.e-4;
2535 Standard_Boolean Change = Standard_True;
2538 Change = Standard_False;
2539 BRepTools_WireExplorer WE(W,F);
2540 gp_Pnt2d PF,PrevP,P1,P2;
2541 TopoDS_Vertex VF,V1,V2;
2543 for (; WE.More(); WE.Next()) {
2544 const TopoDS_Edge& CE = WE.Current();
2545 EdgeVertices (CE,V1,V2);
2546 if (CE.Orientation() == TopAbs_REVERSED)
2547 BRep_Tool::UVPoints(CE, F, P2, P1);
2549 BRep_Tool::UVPoints(CE, F, P1, P2);
2555 if (!P1.IsEqual(PrevP,TolConf)) {
2556 // degenerated edge to be inserted.
2557 Change = Standard_True;
2558 gp_Vec2d V(PrevP,P1);
2559 Handle(Geom2d_Line) C2d = new Geom2d_Line(PrevP,gp_Dir2d(V));
2560 Standard_Real f = 0, l = PrevP.Distance(P1);
2561 Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(C2d,f,l);
2562 TopoDS_Edge NE = BRepLib_MakeEdge(C2d,S);
2563 B.Degenerated(NE,Standard_True);
2564 B.Add(NE,V1.Oriented(TopAbs_FORWARD));
2565 B.Add(NE,V1.Oriented(TopAbs_REVERSED));
2573 if (!Change && VF.IsSame(V2)) { // closed
2574 if (!PF.IsEqual(P2,TolConf)) {
2575 // Degenerated edge to be inserted.
2576 Change = Standard_True;
2578 Handle(Geom2d_Line) C2d = new Geom2d_Line(P2,gp_Dir2d(V));
2579 Standard_Real f = 0, l = P2.Distance(PF);
2580 Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(C2d,f,l);
2581 TopoDS_Edge NE = BRepLib_MakeEdge(C2d,S);
2582 B.Degenerated(NE,Standard_True);
2583 B.Add(NE,VF.Oriented(TopAbs_FORWARD));
2584 B.Add(NE,VF.Oriented(TopAbs_REVERSED));
2592 //=======================================================================
2593 //function : TrimFace
2595 //=======================================================================
2597 void TrimFace(const TopoDS_Face& Face,
2598 TopTools_SequenceOfShape& TheEdges,
2599 TopTools_SequenceOfShape& S)
2603 Standard_Integer NB = TheEdges.Length();
2606 cout << " TrimFace " << ++NbTRIMFACES;
2607 cout << " : " << NB << " edges within the restriction" << endl;
2608 for ( Standard_Integer j = 1; j <= NB; j++) {
2609 sprintf(name,"TRIMEDGE_%d_%d",NbTRIMFACES,j);
2610 DBRep::Set(name,TopoDS::Edge(TheEdges.Value(j)));
2616 //--------------------------------------
2617 // Creation of wires limiting faces.
2618 //--------------------------------------
2619 BRep_Builder TheBuilder;
2621 Standard_Integer NbEdges;
2622 Standard_Boolean NewWire = Standard_True;
2623 Standard_Boolean AddEdge = Standard_False;
2624 TopoDS_Wire GoodWire;
2627 while ( !TheEdges.IsEmpty()) {
2629 BRepLib_MakeWire MWire(TopoDS::Edge(TheEdges.First()));
2630 GoodWire = MWire.Wire();
2632 NbEdges = TheEdges.Length();
2633 NewWire = Standard_False;
2636 AddEdge = Standard_False;
2638 for ( Standard_Integer i = 1; i <= NbEdges && !AddEdge; i++) {
2639 const TopoDS_Edge& E = TopoDS::Edge(TheEdges.Value(i));
2640 if ( BRep_Tool::Degenerated(E)) {
2642 AddEdge = Standard_True;
2643 NbEdges = TheEdges.Length();
2644 GoodWire = MWire.Wire();
2648 if ( MWire.Error() == BRepLib_WireDone) {
2649 // the connection is successful
2650 // it is removed from the sequence and one restarts from the beginning.
2652 AddEdge = Standard_True;
2653 NbEdges = TheEdges.Length();
2654 GoodWire = MWire.Wire();
2658 NewWire = (!AddEdge);
2660 TopoDS_Shape aLocalShape = Face.EmptyCopied();
2661 TopoDS_Face FaceCut = TopoDS::Face(aLocalShape);
2662 // TopoDS_Face FaceCut = TopoDS::Face(Face.EmptyCopied());
2663 FaceCut.Orientation(TopAbs_FORWARD);
2664 BRepTools::Update (FaceCut);
2665 AddDegeneratedEdge (FaceCut,GoodWire);
2666 TheBuilder.Add (FaceCut,GoodWire);
2667 FaceCut.Orientation(Face.Orientation());
2674 //=======================================================================
2675 //function : PutProfilAt
2677 //=======================================================================
2679 const TopoDS_Wire PutProfilAt (const TopoDS_Wire& ProfRef,
2680 const gp_Ax3& AxeRef,
2681 const TopoDS_Edge& E,
2682 const TopoDS_Face& F,
2683 const Standard_Boolean AtStart)
2688 Handle(Geom2d_Curve) C2d;
2689 Standard_Real First,Last;
2691 C2d = BRep_Tool::CurveOnSurface(E,F,First,Last);
2693 Standard_ConstructionError::Raise("ConstructionError in PutProfilAt");
2696 if (E.Orientation() == TopAbs_REVERSED) {
2697 if (!AtStart) C2d->D1(First,P,D1);else C2d->D1(Last,P,D1);
2701 if (!AtStart) C2d->D1(Last,P,D1) ;else C2d->D1(First,P,D1);
2703 gp_Pnt P3d(P.X() ,P.Y() ,0.);
2704 gp_Vec V3d(D1.X(),D1.Y(),0.);
2706 gp_Ax3 Ax( P3d, gp::DZ(), V3d);
2708 Trans.SetTransformation(Ax,AxeRef);
2709 TopoDS_Shape aLocalShape = ProfRef.Moved(TopLoc_Location(Trans));
2710 Prof = TopoDS::Wire(aLocalShape);
2711 // Prof = TopoDS::Wire(ProfRef.Moved(TopLoc_Location(Trans)));
2716 //=======================================================================
2717 //function : TrimEdge
2719 //=======================================================================
2721 void TrimEdge (const TopoDS_Edge& Edge,
2722 const TopTools_SequenceOfShape& TheEdgesControle,
2723 TopTools_SequenceOfShape& TheVer,
2724 TColStd_SequenceOfReal& ThePar,
2725 TopTools_SequenceOfShape& S)
2727 Standard_Boolean Change = Standard_True;
2728 BRep_Builder TheBuilder;
2730 //------------------------------------------------------------
2731 // Parse two sequences depending on the parameter on the edge.
2732 //------------------------------------------------------------
2734 Change = Standard_False;
2735 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2736 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2737 ThePar.Exchange(i,i+1);
2738 TheVer.Exchange(i,i+1);
2739 Change = Standard_True;
2744 //----------------------------------------------------------
2745 // If a vertex is not in the proofing point, it is removed.
2746 //----------------------------------------------------------
2747 if (!BRep_Tool::Degenerated(Edge)) {
2748 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2749 if ( DoubleOrNotInFace (TheEdgesControle,
2750 TopoDS::Vertex(TheVer.Value(k)))) {
2758 //-------------------------------------------------------------------
2759 // Processing of double vertices for non-degenerated edges.
2760 // If a vertex_double appears twice in the edges of control,
2761 // the vertex is eliminated .
2762 // otherwise its only representation is preserved.
2763 //-------------------------------------------------------------------
2764 if (!BRep_Tool::Degenerated(Edge)) {
2765 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2766 if (TheVer.Value(k).IsSame(TheVer.Value(k+1))) {
2769 if ( DoubleOrNotInFace (TheEdgesControle,
2770 TopoDS::Vertex(TheVer.Value(k)))) {
2780 //-----------------------------------------------------------
2781 // Creation of edges.
2782 // the number of vertices should be even. The edges to be created leave
2783 // from a vertex with uneven index i to vertex i+1;
2784 //-----------------------------------------------------------
2785 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2786 TopoDS_Shape aLocalShape = Edge.EmptyCopied();
2787 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2788 // TopoDS_Edge NewEdge = TopoDS::Edge(Edge.EmptyCopied());
2790 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2791 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2792 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2795 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2796 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2798 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2799 // modified by NIZHNY-EAP Wed Dec 22 12:09:48 1999 ___BEGIN___
2800 BRepLib::UpdateTolerances(NewEdge,Standard_False);
2801 // modified by NIZHNY-EAP Wed Dec 22 13:34:19 1999 ___END___
2806 //=======================================================================
2807 //function : ComputeIntervals
2809 //=======================================================================
2811 void ComputeIntervals (const TopTools_SequenceOfShape& VOnF,
2812 const TopTools_SequenceOfShape& VOnL,
2813 const TColgp_SequenceOfPnt& ParOnF,
2814 const TColgp_SequenceOfPnt& ParOnL,
2815 const BRepFill_TrimSurfaceTool& Trim,
2816 const Handle(Geom2d_Curve)& Bis,
2817 const TopoDS_Vertex& VS,
2818 const TopoDS_Vertex& VE,
2819 TColStd_SequenceOfReal& FirstPar,
2820 TColStd_SequenceOfReal& LastPar,
2821 TopTools_SequenceOfShape& FirstV,
2822 TopTools_SequenceOfShape& LastV )
2824 Standard_Integer IOnF = 1,IOnL = 1;
2825 Standard_Real U1 = 0.,U2;
2829 U1 = Bis->FirstParameter();
2832 while ( IOnF <= VOnF.Length() || IOnL <= VOnL.Length()) {
2833 //---------------------------------------------------------
2834 // Return the smallest parameter on the bissectrice
2835 // correponding to the current positions IOnF,IOnL.
2836 //---------------------------------------------------------
2837 if ( IOnL > VOnL.Length() ||
2838 (IOnF <= VOnF.Length() &&
2839 ParOnF.Value(IOnF).X() < ParOnL.Value(IOnL).X())) {
2841 U2 = ParOnF.Value(IOnF).X();
2842 V2 = VOnF .Value(IOnF);
2846 U2 = ParOnL.Value(IOnL).X();
2847 V2 = VOnL .Value(IOnL);
2850 //---------------------------------------------------------------------
2851 // When V2 and V1 are different the medium point P of the
2852 // interval is tested compared to the face. If P is in the face the interval
2854 //---------------------------------------------------------------------
2855 if (!V1.IsNull() && !V2.IsSame(V1)) {
2856 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
2857 if (Trim.IsOnFace(P)) {
2858 FirstPar.Append(U1); LastPar .Append(U2);
2859 FirstV. Append(V1); LastV .Append(V2);
2867 U2 = Bis->LastParameter();
2869 if (!V2.IsSame(V1)) {
2870 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
2871 if (Trim.IsOnFace(P)) {
2872 FirstPar.Append(U1); LastPar .Append(U2);
2873 FirstV.Append (V1); LastV .Append(V2);
2880 //=======================================================================
2881 //function : Relative
2882 //purpose : Commun is true if two wires have V in common
2883 // return FORWARD if the wires near the vertex are at
2884 // the same side. otherwise REVERSED.
2885 //=======================================================================
2886 static TopAbs_Orientation Relative (const TopoDS_Wire& W1,
2887 const TopoDS_Wire& W2,
2888 const TopoDS_Vertex& V,
2889 Standard_Boolean& Commun)
2891 TopExp_Explorer Exp;
2893 TopoDS_Vertex V1,V2;
2895 for (Exp.Init(W1,TopAbs_EDGE); Exp.More(); Exp.Next()) {
2896 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
2897 TopExp::Vertices(E,V1,V2);
2898 if (V1.IsSame(V) || V2.IsSame(V)) {
2903 for (Exp.Init(W2,TopAbs_EDGE); Exp.More(); Exp.Next()) {
2904 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
2905 TopExp::Vertices(E,V1,V2);
2906 if (V1.IsSame(V) || V2.IsSame(V)) {
2912 if (E1.IsNull() || E2.IsNull()) {
2913 Commun = Standard_False;
2914 return TopAbs_FORWARD;
2916 Commun = Standard_True;
2918 TopoDS_Wire WW1 = BRepLib_MakeWire(E1);
2919 TopoDS_Wire WW2 = BRepLib_MakeWire(E2);
2920 Standard_Real Tol = BRepFill_Confusion();
2921 if (Side(WW1,Tol) < 4 && Side(WW2,Tol) < 4) // two to the left
2922 return TopAbs_FORWARD;
2923 if (Side(WW1,Tol) > 4 && Side(WW2,Tol) > 4) // two to the right
2924 return TopAbs_FORWARD;
2926 return TopAbs_REVERSED;
2928 //=======================================================================
2929 //function : OriEdgeInFace
2931 //=======================================================================
2933 TopAbs_Orientation OriEdgeInFace (const TopoDS_Edge& E,
2934 const TopoDS_Face& F )
2937 TopExp_Explorer Exp(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
2939 for (; Exp.More() ;Exp.Next()) {
2940 if (Exp.Current().IsSame(E)) {
2941 return Exp.Current().Orientation();
2944 Standard_ConstructionError::Raise("BRepFill_Evolved::OriEdgeInFace");
2945 return E.Orientation();
2950 //=======================================================================
2951 //function : IsOnFace
2952 //purpose : Return the position of the point defined by d1
2953 // in the face defined by d2 d3.
2955 // 0 : the point is out of the face.
2956 // 1 : the point is on edge corresponding to d2.
2957 // 2 : the point is inside the face.
2958 // 3 : the point is on edge corresponding to d3.
2959 //=======================================================================
2961 Standard_Integer PosOnFace (Standard_Real d1,
2965 if (Abs(d1 - d2) <= BRepFill_Confusion())
2967 if (Abs(d1 - d3) <= BRepFill_Confusion())
2971 if (d1 > (d2 + BRepFill_Confusion()) &&
2972 d1 < (d3 - BRepFill_Confusion()) )
2976 if (d1 > (d3 + BRepFill_Confusion()) &&
2977 d1 < (d2 - BRepFill_Confusion()) )
2983 //=======================================================================
2984 //function : DoubleOrNotInFace
2985 //purpose : Return True if V appears zero or two times in the sequence
2987 //=======================================================================
2989 Standard_Boolean DoubleOrNotInFace(const TopTools_SequenceOfShape& EC,
2990 const TopoDS_Vertex& V)
2992 Standard_Boolean Vu = Standard_False;
2994 for (Standard_Integer i = 1; i <= EC.Length(); i++) {
2995 TopoDS_Vertex V1,V2;
2996 TopExp::Vertices(TopoDS::Edge(EC.Value(i)),V1,V2);
2998 if (Vu) return Standard_True;
2999 else Vu = Standard_True;
3002 if (Vu) return Standard_True;
3003 else Vu = Standard_True;
3006 if (Vu) return Standard_False;
3007 else return Standard_True;
3011 //=======================================================================
3012 //function : DistanceToOZ
3014 //=======================================================================
3016 Standard_Real DistanceToOZ (const TopoDS_Vertex& V)
3018 gp_Pnt PV3d = BRep_Tool::Pnt(V);
3019 return Abs(PV3d.Y());
3022 //=======================================================================
3023 //function : Altitud
3025 //=======================================================================
3027 Standard_Real Altitud (const TopoDS_Vertex& V)
3029 gp_Pnt PV3d = BRep_Tool::Pnt(V);
3033 //=======================================================================
3034 //function : SimpleExpression
3036 //=======================================================================
3038 void SimpleExpression (const Bisector_Bisec& B,
3039 Handle(Geom2d_Curve)& Bis)
3043 Handle(Standard_Type) BT = Bis->DynamicType();
3044 if (BT == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
3045 Handle(Geom2d_TrimmedCurve) TrBis
3046 = Handle(Geom2d_TrimmedCurve)::DownCast(Bis);
3047 Handle(Geom2d_Curve) BasBis = TrBis->BasisCurve();
3048 BT = BasBis->DynamicType();
3049 if (BT == STANDARD_TYPE(Bisector_BisecAna)) {
3050 Bis = Handle(Bisector_BisecAna)::DownCast(BasBis)->Geom2dCurve();
3051 Bis = new Geom2d_TrimmedCurve (Bis,
3052 TrBis->FirstParameter(),
3053 TrBis->LastParameter());
3058 //=======================================================================
3059 //function : CutEdgeProf
3060 //purpose : Projection and Cut of an edge at extrema of distance to axis OZ.
3061 //=======================================================================
3063 void CutEdgeProf (const TopoDS_Edge& E,
3064 const Handle(Geom_Plane)& Plane,
3065 const Handle(Geom2d_Line)& Line,
3066 TopTools_ListOfShape& Cuts,
3067 TopTools_DataMapOfShapeShape& MapVerRefMoved)
3072 Handle(Geom_Curve) C;
3073 Handle(Geom_TrimmedCurve) CT;
3074 Handle(Geom2d_Curve) C2d;
3077 // Return the curve associated to each Edge
3078 C = BRep_Tool::Curve(E,L,f,l);
3079 CT = new Geom_TrimmedCurve(C,f,l);
3080 CT->Transform(L.Transformation());
3082 // project it in the plane and return the associated PCurve
3083 gp_Dir Normal = Plane->Pln().Axis().Direction();
3085 Handle(Geom_Curve)::DownCast(GeomProjLib::ProjectOnPlane(CT,Plane,
3088 C2d = GeomProjLib::Curve2d(C,Plane);
3090 // Calculate the extrema with the straight line
3091 TColStd_SequenceOfReal Seq;
3093 Standard_Real U1 = -Precision::Infinite();
3094 Standard_Real U2 = Precision::Infinite();
3095 f= C2d->FirstParameter();
3096 l= C2d->LastParameter();
3099 Geom2dAdaptor_Curve AC2d(C2d);
3100 BndLib_Add2dCurve::Add(AC2d,BRepFill_Confusion(),B);
3101 Standard_Real xmin,xmax;
3102 B.Get(xmin,U1,xmax,U2);
3104 // modified by NIZHNY-EAP Wed Feb 2 16:32:37 2000 ___BEGIN___
3105 // no sense if C2 is normal to Line or really is a point
3107 Geom2dAPI_ExtremaCurveCurve Extrema(Line,C2d,U1-1.,U2+1.,f,l);
3109 Standard_Integer i, Nb = Extrema.NbExtrema();
3110 for ( i = 1; i <= Nb; i++) {
3111 Extrema.Parameters(i,U1,U2);
3115 // modified by NIZHNY-EAP Wed Feb 2 16:33:05 2000 ___END___
3117 // On calcule les intersection avec Oy.
3118 Geom2dAdaptor_Curve ALine(Line);
3119 Standard_Real Tol = Precision::Intersection();
3120 Standard_Real TolC = 0.;
3122 Geom2dInt_GInter Intersector(ALine,AC2d,TolC,Tol);
3123 Standard_Integer i, Nb = Intersector.NbPoints();
3125 for ( i = 1; i <= Nb; i++) {
3126 Seq.Append(Intersector.Point(i).ParamOnSecond());
3129 // Compute the new edges.
3130 BRep_Builder Builder;
3131 TopoDS_Vertex VV,Vf,Vl,VRf,VRl;
3132 TopExp::Vertices(E,VRf,VRl);
3134 if (!MapVerRefMoved.IsBound(VRf)) {
3135 Builder.MakeVertex(Vf,C->Value(f),BRep_Tool::Tolerance(VRf));
3136 MapVerRefMoved.Bind(VRf,Vf);
3139 Vf = TopoDS::Vertex(MapVerRefMoved(VRf));
3142 if (!MapVerRefMoved.IsBound(VRl)) {
3143 Builder.MakeVertex(Vl,C->Value(l),BRep_Tool::Tolerance(VRl));
3144 MapVerRefMoved.Bind(VRl,Vl);
3147 Vl = TopoDS::Vertex(MapVerRefMoved(VRl));
3150 if ( !Seq.IsEmpty()) {
3154 Standard_Boolean Empty = Standard_False;
3156 Standard_Real CurParam = f;
3157 Standard_Real Param;
3160 Param = Seq.First();
3162 Empty = Seq.IsEmpty();
3163 if (Abs( Param - CurParam) > BRepFill_Confusion() &&
3164 Abs( Param - l) > BRepFill_Confusion() ) {
3166 VV = BRepLib_MakeVertex( C->Value(Param));
3168 TopoDS_Edge EE = BRepLib_MakeEdge(C,Vf,VV);
3169 EE.Orientation(E.Orientation());
3170 if ( EE.Orientation() == TopAbs_FORWARD)
3182 TopoDS_Edge EE = BRepLib_MakeEdge(C,Vf,Vl);
3183 EE.Orientation(E.Orientation());
3184 if ( EE.Orientation() == TopAbs_FORWARD)
3190 //=======================================================================
3191 //function : CutEdge
3192 //purpose : Cut an edge at thw extrema of curves and at points of inflexion.
3193 // Closed circles are also cut in two.
3194 // If <Cuts> are empty the edge is not modified.
3195 // The first and the last vertex of the original edge
3196 // belong to the first and last parts respectively.
3197 //=======================================================================
3198 void CutEdge (const TopoDS_Edge& E,
3199 const TopoDS_Face& F,
3200 TopTools_ListOfShape& Cuts)
3203 MAT2d_CutCurve Cuter;
3205 Handle(Geom2d_Curve) C2d;
3206 Handle(Geom2d_TrimmedCurve) CT2d;
3208 TopoDS_Vertex V1,V2,VF,VL;
3209 TopExp::Vertices (E,V1,V2);
3212 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
3213 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
3215 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
3217 //---------------------------
3218 // Cut closed circle.
3219 //---------------------------
3220 Standard_Real m1 = (2*f + l)/3.;
3221 Standard_Real m2 = ( f + 2*l)/3.;
3222 gp_Pnt2d P1 = CT2d->Value(m1);
3223 gp_Pnt2d P2 = CT2d->Value(m2);
3225 TopoDS_Vertex VL1 = BRepLib_MakeVertex(gp_Pnt(P1.X(), P1.Y(), 0.));
3226 TopoDS_Vertex VL2 = BRepLib_MakeVertex(gp_Pnt(P2.X(), P2.Y(), 0.));
3227 TopoDS_Shape aLocalShape1 = E.EmptyCopied();
3228 TopoDS_Shape aLocalShape2 = E.EmptyCopied();
3229 TopoDS_Shape aLocalShape3 = E.EmptyCopied();
3230 TopoDS_Edge FE = TopoDS::Edge(aLocalShape1);
3231 TopoDS_Edge ME = TopoDS::Edge(aLocalShape2);
3232 TopoDS_Edge LE = TopoDS::Edge(aLocalShape3);
3233 // TopoDS_Edge FE = TopoDS::Edge(E.EmptyCopied());
3234 // TopoDS_Edge ME = TopoDS::Edge(E.EmptyCopied());
3235 // TopoDS_Edge LE = TopoDS::Edge(E.EmptyCopied());
3237 FE.Orientation(TopAbs_FORWARD);
3238 ME.Orientation(TopAbs_FORWARD);
3239 LE.Orientation(TopAbs_FORWARD );
3242 B.Add (FE,VL1.Oriented(TopAbs_REVERSED));
3245 B.Add (ME,VL1.Oriented(TopAbs_FORWARD));
3246 B.Add (ME,VL2.Oriented(TopAbs_REVERSED));
3247 B.Range(ME, m1, m2);
3249 B.Add (LE,VL2.Oriented(TopAbs_FORWARD));
3253 Cuts.Append(FE.Oriented(E.Orientation()));
3254 Cuts.Append(ME.Oriented(E.Orientation()));
3255 Cuts.Append(LE.Oriented(E.Orientation()));
3262 //-------------------------
3263 // Cut of the curve.
3264 //-------------------------
3265 Cuter.Perform(CT2d);
3267 if (Cuter.UnModified()) {
3268 //-----------------------------
3269 // edge not modified => return.
3270 //-----------------------------
3274 //------------------------
3275 // Creation of cut edges.
3276 //------------------------
3279 for ( Standard_Integer k = 1; k <= Cuter.NbCurves(); k++) {
3280 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(k);
3281 if (k == Cuter.NbCurves()) {VL = V2;}
3283 gp_Pnt2d P = CC->Value(CC->LastParameter());
3284 VL = BRepLib_MakeVertex(gp_Pnt(P.X(), P.Y(), 0.));
3286 TopoDS_Shape aLocalShape = E.EmptyCopied();
3287 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
3288 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
3289 NE.Orientation(TopAbs_FORWARD);
3290 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
3291 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
3292 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
3293 Cuts.Append(NE.Oriented(E.Orientation()));
3299 //=======================================================================
3300 //function : VertexFromNode
3301 //purpose : Test if the position of aNode correspondingly to the distance to OZ
3302 // of vertices VF and VL. returns Status.
3303 // if Status is different from 0 Returned
3304 // the vertex corresponding to aNode is created.
3305 //=======================================================================
3307 Standard_Integer VertexFromNode
3308 (const Handle(MAT_Node)& aNode,
3309 const TopoDS_Edge& E,
3310 const TopoDS_Vertex& VF,
3311 const TopoDS_Vertex& VL,
3312 BRepFill_DataMapOfNodeDataMapOfShapeShape& MapNodeVertex,
3315 TopoDS_Shape ShapeOnNode;
3316 TopTools_DataMapOfShapeShape EmptyMap;
3317 Standard_Integer Status = 0;
3320 if (!aNode->Infinite()) {
3321 Status = PosOnFace(aNode->Distance(),
3322 DistanceToOZ(VF) , DistanceToOZ(VL));
3324 if (Status == 2) ShapeOnNode = E;
3325 else if (Status == 1) ShapeOnNode = VF;
3326 else if (Status == 3) ShapeOnNode = VL;
3328 if (!ShapeOnNode.IsNull()) {
3329 //-------------------------------------------------
3330 // the vertex will correspond to a node of the map
3331 //-------------------------------------------------
3332 if (MapNodeVertex.IsBound(aNode) &&
3333 MapNodeVertex(aNode).IsBound(ShapeOnNode)) {
3335 (MapNodeVertex(aNode)(ShapeOnNode));
3339 if (!MapNodeVertex.IsBound(aNode)) {
3340 MapNodeVertex.Bind(aNode,EmptyMap);
3342 MapNodeVertex(aNode).Bind(ShapeOnNode,VN);