1 // File: BRepOffsetAPI_ThruSections.cxx
2 // Created: Tue Jul 18 16:18:09 1995
3 // Author: Jing Cheng MEI
5 // Modified: Mon Jan 12 10:50:10 1998
6 // Author: Joelle CHAUVET
8 // gestion automatique de l'origine et de l'orientation
9 // avec la methode ArrangeWires
10 // Modified: Mon Jan 19 10:11:56 1998
11 // Author: Joelle CHAUVET
13 // traitement des cas particuliers cylindre, cone, plan
14 // (methodes DetectKPart et CreateKPart)
15 // Modified: Mon Feb 23 09:28:46 1998
16 // Author: Joelle CHAUVET
18 // traitement des sections avec nombre d'elements different
19 // + quelques ameliorations pour les cas particuliers
20 // + cas de la derniere section ponctuelle
21 // Modified: Mon Apr 6 15:47:44 1998
22 // Author: Joelle CHAUVET
24 // traitement des cas particuliers deplace dans BRepFill
25 // Modified: Thu Apr 30 15:24:17 1998
26 // Author: Joelle CHAUVET
28 // separation sections fermees / sections ouvertes + debug
29 // Modified: Fri Jul 10 11:23:35 1998
30 // Author: Joelle CHAUVET
32 // surface de CreateSmoothed par concatenation,approximation
33 // et segmentation (PRO13924, CTS21295)
34 // Modified: Tue Jul 21 16:48:35 1998
35 // Author: Joelle CHAUVET
37 // pb de ratio (BUC60281)
38 // Modified: Thu Jul 23 11:38:36 1998
39 // Author: Joelle CHAUVET
41 // sections bouclantes
42 // Modified: Fri Aug 28 10:13:44 1998
43 // Author: Joelle CHAUVET
45 // traitement des sections ponctuelles
46 // dans l'historique (cf. loft06 et loft09)
47 // et dans le cas des solides
48 // Modified: Tue Nov 3 10:06:15 1998
49 // Author: Joelle CHAUVET
51 // utilisation de BRepFill_CompatibleWires
54 #include <BRepOffsetAPI_ThruSections.ixx>
56 #include <Precision.hxx>
57 #include <Standard_DomainError.hxx>
60 #include <gp_Pnt2d.hxx>
61 #include <gp_Dir2d.hxx>
62 #include <TColgp_Array1OfPnt.hxx>
64 #include <GeomAbs_Shape.hxx>
65 #include <Geom_Curve.hxx>
66 #include <Geom_BSplineSurface.hxx>
67 #include <Geom_TrimmedCurve.hxx>
68 #include <Geom_BezierCurve.hxx>
69 #include <Geom_Conic.hxx>
70 #include <Geom2d_Line.hxx>
71 #include <GeomFill_Line.hxx>
72 #include <GeomFill_AppSurf.hxx>
73 #include <GeomFill_SectionGenerator.hxx>
74 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
75 #include <GeomConvert.hxx>
76 #include <GeomConvert_ApproxCurve.hxx>
77 #include <Geom_BSplineCurve.hxx>
78 #include <BSplCLib.hxx>
82 #include <TopoDS_Solid.hxx>
83 #include <TopoDS_Face.hxx>
84 #include <TopoDS_Edge.hxx>
85 #include <TopoDS_Vertex.hxx>
86 #include <TopoDS_Wire.hxx>
87 #include <TopLoc_Location.hxx>
88 #include <TopTools_Array1OfShape.hxx>
89 #include <TopTools_ListIteratorOfListOfShape.hxx>
90 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
92 #include <TopoDS_Iterator.hxx>
95 #include <BRep_Builder.hxx>
96 #include <BRep_Tool.hxx>
97 #include <BRepTools_WireExplorer.hxx>
99 #include <BRepLib.hxx>
100 #include <BRepClass3d_SolidClassifier.hxx>
102 #include <BRepFill_Generator.hxx>
103 #include <BRepFill_CompatibleWires.hxx>
105 #include <BRepBuilderAPI_MakeFace.hxx>
106 #include <BRepBuilderAPI_FindPlane.hxx>
111 //=======================================================================
112 //function : PerformPlan
113 //purpose : Construit s'il existe un plan de remplissage
114 //=======================================================================
116 static Standard_Boolean PerformPlan(const TopoDS_Wire& W,
117 const Standard_Real presPln,
118 TopoDS_Face& theFace)
120 Standard_Boolean isDegen = Standard_True;
121 TopoDS_Iterator iter(W);
122 for (; iter.More(); iter.Next())
124 const TopoDS_Edge& anEdge = TopoDS::Edge(iter.Value());
125 if (!BRep_Tool::Degenerated(anEdge))
126 isDegen = Standard_False;
129 return Standard_True;
131 Standard_Boolean Ok = Standard_False;
133 BRepBuilderAPI_FindPlane Searcher( W, presPln );
134 if (Searcher.Found())
136 theFace = BRepBuilderAPI_MakeFace(Searcher.Plane(), W);
139 else // try to find another surface
141 BRepBuilderAPI_MakeFace MF( W );
153 //=============================================================================
154 //function : IsSameOriented
155 //purpose : Checks whether aFace is oriented to the same side as aShell or not
156 //=============================================================================
158 static Standard_Boolean IsSameOriented(const TopoDS_Shape& aFace,
159 const TopoDS_Shape& aShell)
161 TopExp_Explorer Explo(aFace, TopAbs_EDGE);
162 TopoDS_Shape anEdge = Explo.Current();
163 TopAbs_Orientation Or1 = anEdge.Orientation();
165 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
166 TopExp::MapShapesAndAncestors( aShell, TopAbs_EDGE, TopAbs_FACE, EFmap );
168 const TopoDS_Shape& AdjacentFace = EFmap.FindFromKey(anEdge).First();
169 TopoDS_Shape theEdge;
170 for (Explo.Init(AdjacentFace, TopAbs_EDGE); Explo.More(); Explo.Next())
172 theEdge = Explo.Current();
173 if (theEdge.IsSame(anEdge))
177 TopAbs_Orientation Or2 = theEdge.Orientation();
179 return Standard_False;
180 return Standard_True;
183 //=======================================================================
184 //function : MakeSolid
186 //=======================================================================
188 static TopoDS_Solid MakeSolid(TopoDS_Shell& shell, const TopoDS_Wire& wire1,
189 const TopoDS_Wire& wire2, const Standard_Real presPln,
190 TopoDS_Face& face1, TopoDS_Face& face2)
193 StdFail_NotDone::Raise("Thrusections is not build");
194 Standard_Boolean B = shell.Closed();
199 // Il faut boucher les extremites
200 B = PerformPlan(wire1, presPln, face1);
202 B = PerformPlan(wire2, presPln, face2);
204 if (!face1.IsNull() && !IsSameOriented( face1, shell ))
206 if (!face2.IsNull() && !IsSameOriented( face2, shell ))
210 BB.Add(shell, face1);
212 BB.Add(shell, face2);
214 shell.Closed(Standard_True);
221 BB.Add(solid, shell);
223 // verify the orientation the solid
224 BRepClass3d_SolidClassifier clas3d(solid);
225 clas3d.PerformInfinitePoint(Precision::Confusion());
226 if (clas3d.State() == TopAbs_IN) {
228 TopoDS_Shape aLocalShape = shell.Reversed();
229 BB.Add(solid, TopoDS::Shell(aLocalShape));
230 // B.Add(solid, TopoDS::Shell(newShell.Reversed()));
233 solid.Closed(Standard_True);
238 //=======================================================================
239 //function : BRepOffsetAPI_ThruSections
241 //=======================================================================
243 BRepOffsetAPI_ThruSections::BRepOffsetAPI_ThruSections(const Standard_Boolean isSolid, const Standard_Boolean ruled,
244 const Standard_Real pres3d):
245 myIsSolid(isSolid), myIsRuled(ruled), myPres3d(pres3d)
247 myWCheck = Standard_True;
248 //----------------------------
249 myParamType = Approx_ChordLength;
251 myContinuity = GeomAbs_C2;
252 myCritWeights[0] = .4;
253 myCritWeights[1] = .2;
254 myCritWeights[2] = .4;
255 myUseSmoothing = Standard_False;
259 //=======================================================================
262 //=======================================================================
264 void BRepOffsetAPI_ThruSections::Init(const Standard_Boolean isSolid, const Standard_Boolean ruled,
265 const Standard_Real pres3d)
270 myWCheck = Standard_True;
271 //----------------------------
272 myParamType = Approx_ChordLength;
274 myContinuity = GeomAbs_C2;
275 myCritWeights[0] = .4;
276 myCritWeights[1] = .2;
277 myCritWeights[2] = .4;
278 myUseSmoothing = Standard_False;
283 //=======================================================================
286 //=======================================================================
288 void BRepOffsetAPI_ThruSections::AddWire(const TopoDS_Wire& wire)
290 myWires.Append(wire);
293 //=======================================================================
294 //function : AddVertex
296 //=======================================================================
298 void BRepOffsetAPI_ThruSections::AddVertex(const TopoDS_Vertex& aVertex)
303 BB.MakeEdge( DegEdge );
304 BB.Add( DegEdge, aVertex.Oriented(TopAbs_FORWARD) );
305 BB.Add( DegEdge, aVertex.Oriented(TopAbs_REVERSED) );
306 BB.Degenerated( DegEdge, Standard_True );
307 DegEdge.Closed( Standard_True );
310 BB.MakeWire( DegWire );
311 BB.Add( DegWire, DegEdge );
312 DegWire.Closed( Standard_True );
314 myWires.Append( DegWire );
317 //=======================================================================
318 //function : CheckCompatibility
320 //=======================================================================
322 void BRepOffsetAPI_ThruSections::CheckCompatibility(const Standard_Boolean check)
328 //=======================================================================
331 //=======================================================================
333 void BRepOffsetAPI_ThruSections::Build()
335 //Check set of section for right configuration of punctual sections
337 TopExp_Explorer explo;
338 for (i = 2; i <= myWires.Length()-1; i++)
340 Standard_Boolean wdeg = Standard_True;
341 for (explo.Init(myWires(i), TopAbs_EDGE); explo.More(); explo.Next())
343 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
344 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
347 Standard_Failure::Raise("Wrong usage of punctual sections");
349 if (myWires.Length() <= 2)
351 Standard_Boolean wdeg = Standard_True;
352 for (i = 1; i <= myWires.Length(); i++)
353 for (explo.Init(myWires(i), TopAbs_EDGE); explo.More(); explo.Next())
355 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
356 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
359 Standard_Failure::Raise("Wrong usage of punctual sections");
363 // compute origin and orientation on wires to avoid twisted results
364 // and update wires to have same number of edges
366 // on utilise BRepFill_CompatibleWires
367 TopTools_SequenceOfShape WorkingSections;
368 WorkingSections.Clear();
369 TopTools_DataMapOfShapeListOfShape WorkingMap;
372 // Calcul des sections de travail
373 BRepFill_CompatibleWires Georges(myWires);
375 if (Georges.IsDone()) {
376 WorkingSections = Georges.Shape();
377 WorkingMap = Georges.Generated();
379 myWires = WorkingSections;
382 // Calcul de la shape resultat
383 if (myWires.Length() == 2 || myIsRuled) {
384 // create a ruled shell
388 // create a smoothed shell
391 // Encode the Regularities
392 BRepLib::EncodeRegularity(myShape);
397 //=======================================================================
398 //function : CreateRuled
400 //=======================================================================
402 void BRepOffsetAPI_ThruSections::CreateRuled()
404 Standard_Integer nbSects = myWires.Length();
405 BRepFill_Generator aGene;
406 // for (Standard_Integer i=1; i<=nbSects; i++) {
408 for (i=1; i<=nbSects; i++) {
409 aGene.AddWire(TopoDS::Wire(myWires(i)));
412 TopoDS_Shell shell = aGene.Shell();
416 // on regarde si le premier wire est identique au dernier
417 Standard_Boolean vClosed = (myWires(1).IsSame(myWires(nbSects))) ;
426 // verify the orientation the solid
427 BRepClass3d_SolidClassifier clas3d(solid);
428 clas3d.PerformInfinitePoint(Precision::Confusion());
429 if (clas3d.State() == TopAbs_IN) {
431 TopoDS_Shape aLocalShape = shell.Reversed();
432 B.Add(solid, TopoDS::Shell(aLocalShape));
433 // B.Add(solid, TopoDS::Shell(shell.Reversed()));
441 TopoDS_Wire wire1 = TopoDS::Wire(myWires.First());
442 TopoDS_Wire wire2 = TopoDS::Wire(myWires.Last());
443 myShape = MakeSolid(shell, wire1, wire2, myPres3d, myFirst, myLast);
456 BRepTools_WireExplorer anExp1, anExp2;
457 TopTools_IndexedDataMapOfShapeListOfShape M;
458 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE, TopAbs_FACE, M);
459 TopTools_ListIteratorOfListOfShape it;
461 TopTools_IndexedDataMapOfShapeListOfShape MV;
462 TopExp::MapShapesAndAncestors(shell, TopAbs_VERTEX, TopAbs_FACE, MV);
464 for (i=1; i<=nbSects-1; i++) {
466 const TopoDS_Wire& wire1 = TopoDS::Wire(myWires(i));
467 const TopoDS_Wire& wire2 = TopoDS::Wire(myWires(i+1));
472 Standard_Boolean tantque = anExp1.More() && anExp2.More();
476 const TopoDS_Shape& edge1 = anExp1.Current();
477 const TopoDS_Shape& edge2 = anExp2.Current();
478 Standard_Boolean degen1 = BRep_Tool::Degenerated(anExp1.Current());
479 Standard_Boolean degen2 = BRep_Tool::Degenerated(anExp2.Current());
481 TopTools_MapOfShape MapFaces;
483 TopoDS_Vertex Vdegen = TopExp::FirstVertex(TopoDS::Edge(edge2));
484 for (it.Initialize(MV.FindFromKey(Vdegen)); it.More(); it.Next()) {
485 MapFaces.Add(it.Value());
489 for (it.Initialize(M.FindFromKey(edge2)); it.More(); it.Next()) {
490 MapFaces.Add(it.Value());
495 TopoDS_Vertex Vdegen = TopExp::FirstVertex(TopoDS::Edge(edge1));
496 for (it.Initialize(MV.FindFromKey(Vdegen)); it.More(); it.Next()) {
497 const TopoDS_Shape& Face = it.Value();
498 if (MapFaces.Contains(Face)) {
499 myGenerated.Bind(edge1, Face);
505 for (it.Initialize(M.FindFromKey(edge1)); it.More(); it.Next()) {
506 const TopoDS_Shape& Face = it.Value();
507 if (MapFaces.Contains(Face)) {
508 myGenerated.Bind(edge1, Face);
514 if (!degen1) anExp1.Next();
515 if (!degen2) anExp2.Next();
517 tantque = anExp1.More() && anExp2.More();
518 if (degen1) tantque = anExp2.More();
519 if (degen2) tantque = anExp1.More();
527 //=======================================================================
528 //function : CreateSmoothed
530 //=======================================================================
532 void BRepOffsetAPI_ThruSections::CreateSmoothed()
535 Standard_Integer nbSects = myWires.Length();
536 BRepTools_WireExplorer anExp;
538 Standard_Boolean w1Point = Standard_True;
539 // on regarde si le premier wire est ponctuel
540 for(anExp.Init(TopoDS::Wire(myWires(1))); anExp.More(); anExp.Next()) {
541 w1Point = w1Point && (BRep_Tool::Degenerated(anExp.Current()));
544 Standard_Boolean w2Point = Standard_True;
545 // on regarde si le dernier wire est ponctuel
546 for(anExp.Init(TopoDS::Wire(myWires(nbSects))); anExp.More(); anExp.Next()) {
547 w2Point = w2Point && (BRep_Tool::Degenerated(anExp.Current()));
550 Standard_Boolean vClosed = Standard_False;
551 // on regarde si le premier wire est identique au dernier
552 if (myWires(1).IsSame(myWires(myWires.Length()))) vClosed = Standard_True;
554 // find the dimension
555 Standard_Integer nbEdges=0;
557 for(anExp.Init(TopoDS::Wire(myWires(1))); anExp.More(); anExp.Next()) {
562 for(anExp.Init(TopoDS::Wire(myWires(2))); anExp.More(); anExp.Next()) {
567 // recover the shapes
568 Standard_Boolean uClosed = Standard_True;
569 TopTools_Array1OfShape shapes(1, nbSects*nbEdges);
570 Standard_Integer nb=0, i, j;
572 for (i=1; i<=nbSects; i++) {
573 const TopoDS_Wire& wire = TopoDS::Wire(myWires(i));
574 if (!wire.Closed()) {
575 // on regarde quand meme si les vertex sont les memes.
576 TopoDS_Vertex V1, V2;
577 TopExp::Vertices(wire,V1,V2);
578 if ( !V1.IsSame(V2)) uClosed = Standard_False;
580 if ( (i==1 && w1Point) || (i==nbSects && w2Point) ) {
581 // si le wire est ponctuel
582 anExp.Init(TopoDS::Wire(wire));
583 for(j=1; j<=nbEdges; j++) {
585 shapes(nb) = anExp.Current();
590 for(anExp.Init(TopoDS::Wire(wire)); anExp.More(); anExp.Next()) {
592 shapes(nb) = anExp.Current();
597 // create the new surface
601 TopoDS_Edge edge, edge1, edge2, edge3, edge4, couture;
602 TopTools_Array1OfShape vcouture(1, nbEdges);
607 TopoDS_Wire newW1, newW2;
608 BRep_Builder BW1, BW2;
613 TopoDS_Vertex v1f,v1l,v2f,v2l;
615 GeomFill_SectionGenerator section;
616 Standard_Integer nbPnts = 21;
617 TColgp_Array2OfPnt points(1, nbPnts, 1, nbSects);
619 // on concatene chaque section pour obtenir une surface totale que
621 Handle(Geom_BSplineSurface) TS;
622 TS = TotalSurf(shapes,nbSects,nbEdges,w1Point,w2Point,vClosed);
628 TopoDS_Shape firstEdge;
629 for (i=1; i<=nbEdges; i++) {
631 // segmentation de TS
632 Handle(Geom_BSplineSurface) surface;
633 surface = Handle(Geom_BSplineSurface)::DownCast(TS->Copy());
634 Standard_Real Ui1,Ui2,V0,V1;
637 V0 = surface->VKnot(surface->FirstVKnotIndex());
638 V1 = surface->VKnot(surface->LastVKnotIndex());
639 surface->Segment(Ui1,Ui2,V0,V1);
641 // recuperation des vertices
642 edge = TopoDS::Edge(shapes(i));
643 TopExp::Vertices(edge,v1f,v1l);
644 if (edge.Orientation() == TopAbs_REVERSED)
645 TopExp::Vertices(edge,v1l,v1f);
648 edge = TopoDS::Edge(shapes((nbSects-1)*nbEdges+i));
649 TopExp::Vertices(edge,v2f,v2l);
650 if (edge.Orientation() == TopAbs_REVERSED)
651 TopExp::Vertices(edge,v2l,v2f);
654 B.MakeFace(face, surface, Precision::Confusion());
659 // make the missing edges
660 Standard_Real f1, f2, l1, l2;
661 surface->Bounds(f1,l1,f2,l2);
665 // copie de l'edge degeneree
666 TopoDS_Shape aLocalShape = shapes(1).EmptyCopied();
667 edge1 = TopoDS::Edge(aLocalShape);
668 // edge1 = TopoDS::Edge(shapes(1).EmptyCopied());
669 edge1.Orientation(TopAbs_FORWARD);
672 B.MakeEdge(edge1, surface->VIso(f2), Precision::Confusion());
674 v1f.Orientation(TopAbs_FORWARD);
676 v1l.Orientation(TopAbs_REVERSED);
678 B.Range(edge1, f1, l1);
679 // traitement des sections bouclantes
680 // on stocke les edges de la 1ere section
687 edge2 = TopoDS::Edge(vcouture(i));
690 // copie de l'edge degeneree
691 TopoDS_Shape aLocalShape = shapes(nbSects*nbEdges).EmptyCopied();
692 edge2 = TopoDS::Edge(aLocalShape);
693 // edge2 = TopoDS::Edge(shapes(nbSects*nbEdges).EmptyCopied());
694 edge2.Orientation(TopAbs_FORWARD);
697 B.MakeEdge(edge2, surface->VIso(l2), Precision::Confusion());
699 v2f.Orientation(TopAbs_FORWARD);
701 v2l.Orientation(TopAbs_REVERSED);
703 B.Range(edge2, f1, l1);
710 B.MakeEdge(edge3, surface->UIso(f1), Precision::Confusion());
711 v1f.Orientation(TopAbs_FORWARD);
713 v2f.Orientation(TopAbs_REVERSED);
715 B.Range(edge3, f2, l2);
726 if ( uClosed && i==nbEdges) {
730 B.MakeEdge(edge4, surface->UIso(l1), Precision::Confusion());
731 v1l.Orientation(TopAbs_FORWARD);
733 v2l.Orientation(TopAbs_REVERSED);
735 B.Range(edge4, f2, l2);
746 new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)),
747 new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)),face,
748 Precision::Confusion());
749 B.Range(edge1,face,f1,l1);
752 B.UpdateEdge(edge1,new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)),face,
753 Precision::Confusion());
754 B.Range(edge1,face,f1,l1);
755 B.UpdateEdge(edge2,new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)),face,
756 Precision::Confusion());
757 B.Range(edge2,face,f1,l1);
760 if ( uClosed && nbEdges ==1 ) {
762 new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),
763 new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),face,
764 Precision::Confusion());
765 B.Range(edge3,face,f2,l2);
769 B.UpdateEdge(edge3,new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),face,
770 Precision::Confusion());
771 B.Range(edge3,face,f2,l2);
772 B.UpdateEdge(edge4,new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),face,
773 Precision::Confusion());
774 B.Range(edge4,face,f2,l2);
779 // complete newW1 newW2
780 TopoDS_Edge edge12 = edge1;
781 TopoDS_Edge edge22 = edge2;
784 BW1.Add(newW1, edge12);
785 BW2.Add(newW2, edge22);
788 myGenerated.Bind(firstEdge, face);
791 if (uClosed && w1Point && w2Point)
792 shell.Closed(Standard_True);
803 // verify the orientation the solid
804 BRepClass3d_SolidClassifier clas3d(solid);
805 clas3d.PerformInfinitePoint(Precision::Confusion());
806 if (clas3d.State() == TopAbs_IN) {
808 TopoDS_Shape aLocalShape = shell.Reversed();
809 B.Add(solid, TopoDS::Shell(aLocalShape));
810 // B.Add(solid, TopoDS::Shell(shell.Reversed()));
817 myShape = MakeSolid(shell, newW1, newW2, myPres3d, myFirst, myLast);
828 TopExp_Explorer ex(myShape,TopAbs_EDGE);
830 const TopoDS_Edge& CurE = TopoDS::Edge(ex.Current());
831 B.SameRange(CurE, Standard_False);
832 B.SameParameter(CurE, Standard_False);
833 Standard_Real tol = BRep_Tool::Tolerance(CurE);
834 BRepLib::SameParameter(CurE,tol);
839 //=======================================================================
840 //function : TotalSurf
842 //=======================================================================
844 Handle(Geom_BSplineSurface) BRepOffsetAPI_ThruSections::
845 TotalSurf(const TopTools_Array1OfShape& shapes,
846 const Standard_Integer NbSects,
847 const Standard_Integer NbEdges,
848 const Standard_Boolean w1Point,
849 const Standard_Boolean w2Point,
850 const Standard_Boolean vClosed) const
852 Standard_Integer i,j,jdeb=1,jfin=NbSects;
855 Standard_Real first, last;
858 GeomFill_SectionGenerator section;
859 Handle(Geom_BSplineSurface) surface;
860 Handle(Geom_BSplineCurve) BS, BS1;
861 Handle(Geom_TrimmedCurve) curvTrim;
862 Handle(Geom_BSplineCurve) curvBS;
866 edge = TopoDS::Edge(shapes(1));
867 TopExp::Vertices(edge,vl,vf);
868 TColgp_Array1OfPnt Extremities(1,2);
869 Extremities(1) = BRep_Tool::Pnt(vf);
870 Extremities(2) = BRep_Tool::Pnt(vl);
871 TColStd_Array1OfReal Bounds(1,2);
874 Standard_Integer Deg = 1;
875 TColStd_Array1OfInteger Mult(1,2);
878 Handle(Geom_BSplineCurve) BSPoint
879 = new Geom_BSplineCurve(Extremities,Bounds,Mult,Deg);
880 section.AddCurve(BSPoint);
887 for (j=jdeb; j<=jfin; j++) {
889 // cas des sections bouclantes
890 if (j==jfin && vClosed) {
891 section.AddCurve(BS1);
895 // read the first edge to initialise CompBS;
896 edge = TopoDS::Edge(shapes((j-1)*NbEdges+1));
897 if (BRep_Tool::Degenerated(edge)) {
898 // edge degeneree : construction d'une courbe ponctuelle
899 TopExp::Vertices(edge,vl,vf);
900 TColgp_Array1OfPnt Extremities(1,2);
901 Extremities(1) = BRep_Tool::Pnt(vf);
902 Extremities(2) = BRep_Tool::Pnt(vl);
903 Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities);
904 curvTrim = new Geom_TrimmedCurve(curv,
905 curv->FirstParameter(),
906 curv->LastParameter());
909 // recuperation de la courbe sur l'edge
910 Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last);
911 curvTrim = new Geom_TrimmedCurve(curv, first, last);
912 curvTrim->Transform(loc.Transformation());
914 if (edge.Orientation() == TopAbs_REVERSED) {
918 // transformation en BSpline reparametree sur [i-1,i]
919 curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim);
920 if (curvBS.IsNull()) {
921 Handle(Geom_Curve) theCurve = curvTrim->BasisCurve();
922 if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
924 GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14);
925 if (appr.HasResult())
926 curvBS = appr.Curve();
929 curvBS = GeomConvert::CurveToBSplineCurve(curvTrim);
931 TColStd_Array1OfReal BSK(1,curvBS->NbKnots());
933 BSplCLib::Reparametrize(0.,1.,BSK);
934 curvBS->SetKnots(BSK);
937 GeomConvert_CompCurveToBSplineCurve CompBS(curvBS);
939 for (i=2; i<=NbEdges; i++) {
941 edge = TopoDS::Edge(shapes((j-1)*NbEdges+i));
942 if (BRep_Tool::Degenerated(edge)) {
943 // edge degeneree : construction d'une courbe ponctuelle
944 TopExp::Vertices(edge,vl,vf);
945 TColgp_Array1OfPnt Extremities(1,2);
946 Extremities(1) = BRep_Tool::Pnt(vf);
947 Extremities(2) = BRep_Tool::Pnt(vl);
948 Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities);
949 curvTrim = new Geom_TrimmedCurve(curv,
950 curv->FirstParameter(),
951 curv->LastParameter());
954 // recuperation de la courbe sur l'edge
955 Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last);
956 curvTrim = new Geom_TrimmedCurve(curv, first, last);
957 curvTrim->Transform(loc.Transformation());
959 if (edge.Orientation() == TopAbs_REVERSED) {
963 // transformation en BSpline reparametree sur [i-1,i]
964 curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim);
965 if (curvBS.IsNull()) {
966 Handle(Geom_Curve) theCurve = curvTrim->BasisCurve();
967 if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
969 GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14);
970 if (appr.HasResult())
971 curvBS = appr.Curve();
974 curvBS = GeomConvert::CurveToBSplineCurve(curvTrim);
976 TColStd_Array1OfReal BSK(1,curvBS->NbKnots());
978 BSplCLib::Reparametrize(i-1,i,BSK);
979 curvBS->SetKnots(BSK);
983 Precision::Confusion(),
989 // recuperation de la section finale
990 BS = CompBS.BSplineCurve();
991 section.AddCurve(BS);
993 // cas des sections bouclantes
994 if (j==jdeb && vClosed) {
1002 edge = TopoDS::Edge(shapes(NbSects*NbEdges));
1003 TopExp::Vertices(edge,vl,vf);
1004 TColgp_Array1OfPnt Extremities(1,2);
1005 Extremities(1) = BRep_Tool::Pnt(vf);
1006 Extremities(2) = BRep_Tool::Pnt(vl);
1007 TColStd_Array1OfReal Bounds(1,2);
1010 Standard_Integer Deg = 1;
1011 TColStd_Array1OfInteger Mult(1,2);
1014 Handle(Geom_BSplineCurve) BSPoint
1015 = new Geom_BSplineCurve(Extremities,Bounds,Mult,Deg);
1016 section.AddCurve(BSPoint);
1019 section.Perform(Precision::PConfusion());
1020 Handle(GeomFill_Line) line = new GeomFill_Line(NbSects);
1022 Standard_Integer nbIt = 3;
1023 if(myPres3d <= 1.e-3) nbIt = 0;
1025 Standard_Integer degmin = 2, degmax = Max(myDegMax, degmin);
1026 Standard_Boolean SpApprox = Standard_True;
1028 GeomFill_AppSurf anApprox(degmin, degmax, myPres3d, myPres3d, nbIt);
1029 anApprox.SetContinuity(myContinuity);
1031 if(myUseSmoothing) {
1032 anApprox.SetCriteriumWeight(myCritWeights[0], myCritWeights[1], myCritWeights[2]);
1033 anApprox.PerformSmoothing(line, section);
1036 anApprox.SetParType(myParamType);
1037 anApprox.Perform(line, section, SpApprox);
1040 if(anApprox.IsDone()) {
1042 new Geom_BSplineSurface(anApprox.SurfPoles(), anApprox.SurfWeights(),
1043 anApprox.SurfUKnots(), anApprox.SurfVKnots(),
1044 anApprox.SurfUMults(), anApprox.SurfVMults(),
1045 anApprox.UDegree(), anApprox.VDegree());
1052 //=======================================================================
1053 //function : FirstShape
1055 //=======================================================================
1057 const TopoDS_Shape& BRepOffsetAPI_ThruSections::FirstShape() const
1062 //=======================================================================
1063 //function : LastShape
1065 //=======================================================================
1067 const TopoDS_Shape& BRepOffsetAPI_ThruSections::LastShape() const
1072 //=======================================================================
1073 //function : GeneratedFace
1075 //=======================================================================
1077 TopoDS_Shape BRepOffsetAPI_ThruSections::GeneratedFace(const TopoDS_Shape& edge) const
1080 if (myGenerated.IsBound(edge)) {
1081 return myGenerated(edge);
1089 //=======================================================================
1090 //function : CriteriumWeight
1091 //purpose : returns the Weights associed to the criterium used in
1092 // the optimization.
1093 //=======================================================================
1095 void BRepOffsetAPI_ThruSections::CriteriumWeight(Standard_Real& W1, Standard_Real& W2, Standard_Real& W3) const
1097 W1 = myCritWeights[0];
1098 W2 = myCritWeights[1];
1099 W3 = myCritWeights[2];
1101 //=======================================================================
1102 //function : SetCriteriumWeight
1104 //=======================================================================
1106 void BRepOffsetAPI_ThruSections::SetCriteriumWeight(const Standard_Real W1, const Standard_Real W2, const Standard_Real W3)
1108 if (W1 < 0 || W2 < 0 || W3 < 0 ) Standard_DomainError::Raise();
1109 myCritWeights[0] = W1;
1110 myCritWeights[1] = W2;
1111 myCritWeights[2] = W3;
1113 //=======================================================================
1114 //function : SetContinuity
1116 //=======================================================================
1118 void BRepOffsetAPI_ThruSections::SetContinuity (const GeomAbs_Shape TheCont)
1120 myContinuity = TheCont;
1123 //=======================================================================
1124 //function : Continuity
1126 //=======================================================================
1128 GeomAbs_Shape BRepOffsetAPI_ThruSections::Continuity () const
1130 return myContinuity;
1133 //=======================================================================
1134 //function : SetParType
1136 //=======================================================================
1138 void BRepOffsetAPI_ThruSections::SetParType (const Approx_ParametrizationType ParType)
1140 myParamType = ParType;
1143 //=======================================================================
1144 //function : ParType
1146 //=======================================================================
1148 Approx_ParametrizationType BRepOffsetAPI_ThruSections::ParType () const
1153 //=======================================================================
1154 //function : SetMaxDegree
1156 //=======================================================================
1158 void BRepOffsetAPI_ThruSections:: SetMaxDegree(const Standard_Integer MaxDeg)
1163 //=======================================================================
1164 //function : MaxDegree
1166 //=======================================================================
1168 Standard_Integer BRepOffsetAPI_ThruSections::MaxDegree () const
1173 //=======================================================================
1174 //function : SetSmoothing
1176 //=======================================================================
1178 void BRepOffsetAPI_ThruSections::SetSmoothing(const Standard_Boolean UseVar)
1180 myUseSmoothing = UseVar;
1183 //=======================================================================
1184 //function : UseSmoothing
1186 //=======================================================================
1188 Standard_Boolean BRepOffsetAPI_ThruSections::UseSmoothing () const
1190 return myUseSmoothing;