1 // Created on: 1995-07-18
2 // Created by: Joelle CHAUVET
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified: Mon Jan 12 10:50:10 1998
18 // gestion automatique de l'origine et de l'orientation
19 // avec la methode ArrangeWires
20 // Modified: Mon Jan 19 10:11:56 1998
21 // traitement des cas particuliers cylindre, cone, plan
22 // (methodes DetectKPart et CreateKPart)
23 // Modified: Mon Feb 23 09:28:46 1998
24 // traitement des sections avec nombre d'elements different
25 // + quelques ameliorations pour les cas particuliers
26 // + cas de la derniere section ponctuelle
27 // Modified: Mon Apr 6 15:47:44 1998
28 // traitement des cas particuliers deplace dans BRepFill
29 // Modified: Thu Apr 30 15:24:17 1998
30 // separation sections fermees / sections ouvertes + debug
31 // Modified: Fri Jul 10 11:23:35 1998
32 // surface de CreateSmoothed par concatenation,approximation
33 // et segmentation (PRO13924, CTS21295)
34 // Modified: Tue Jul 21 16:48:35 1998
35 // pb de ratio (BUC60281)
36 // Modified: Thu Jul 23 11:38:36 1998
37 // sections bouclantes
38 // Modified: Fri Aug 28 10:13:44 1998
39 // traitement des sections ponctuelles
40 // dans l'historique (cf. loft06 et loft09)
41 // et dans le cas des solides
42 // Modified: Tue Nov 3 10:06:15 1998
43 // utilisation de BRepFill_CompatibleWires
46 #include <BRepOffsetAPI_ThruSections.ixx>
48 #include <Precision.hxx>
49 #include <Standard_DomainError.hxx>
52 #include <gp_Pnt2d.hxx>
53 #include <gp_Dir2d.hxx>
54 #include <TColgp_Array1OfPnt.hxx>
56 #include <GeomAbs_Shape.hxx>
57 #include <Geom_Curve.hxx>
58 #include <Geom_BSplineSurface.hxx>
59 #include <Geom_TrimmedCurve.hxx>
60 #include <Geom_BezierCurve.hxx>
61 #include <Geom_Conic.hxx>
62 #include <Geom2d_Line.hxx>
63 #include <GeomFill_Line.hxx>
64 #include <GeomFill_AppSurf.hxx>
65 #include <GeomFill_SectionGenerator.hxx>
66 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
67 #include <GeomConvert.hxx>
68 #include <GeomConvert_ApproxCurve.hxx>
69 #include <Geom_BSplineCurve.hxx>
70 #include <BSplCLib.hxx>
74 #include <TopoDS_Solid.hxx>
75 #include <TopoDS_Face.hxx>
76 #include <TopoDS_Edge.hxx>
77 #include <TopoDS_Vertex.hxx>
78 #include <TopoDS_Wire.hxx>
79 #include <TopLoc_Location.hxx>
80 #include <TopTools_Array1OfShape.hxx>
81 #include <TopTools_ListIteratorOfListOfShape.hxx>
82 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
84 #include <TopoDS_Iterator.hxx>
87 #include <BRep_Builder.hxx>
88 #include <BRep_Tool.hxx>
89 #include <BRepTools_WireExplorer.hxx>
91 #include <BRepLib.hxx>
92 #include <BRepClass3d_SolidClassifier.hxx>
94 #include <BRepFill_Generator.hxx>
95 #include <BRepFill_CompatibleWires.hxx>
97 #include <BRepBuilderAPI_MakeFace.hxx>
98 #include <BRepBuilderAPI_FindPlane.hxx>
101 //=======================================================================
102 //function : PreciseUpar
103 //purpose : pins the u-parameter of surface close to U-knot
105 //=======================================================================
107 static Standard_Real PreciseUpar(const Standard_Real anUpar,
108 const Handle(Geom_BSplineSurface)& aSurface)
110 Standard_Real Tol = Precision::PConfusion();
111 Standard_Integer i1, i2;
113 aSurface->LocateU(anUpar, Tol, i1, i2);
114 Standard_Real U1 = aSurface->UKnot(i1);
115 Standard_Real U2 = aSurface->UKnot(i2);
117 Standard_Real NewU = anUpar;
119 NewU = (anUpar - U1 < U2 - anUpar)? U1 : U2;
123 //=======================================================================
124 //function : PerformPlan
125 //purpose : Construct a plane of filling if exists
126 //=======================================================================
128 static Standard_Boolean PerformPlan(const TopoDS_Wire& W,
129 const Standard_Real presPln,
130 TopoDS_Face& theFace)
132 Standard_Boolean isDegen = Standard_True;
133 TopoDS_Iterator iter(W);
134 for (; iter.More(); iter.Next())
136 const TopoDS_Edge& anEdge = TopoDS::Edge(iter.Value());
137 if (!BRep_Tool::Degenerated(anEdge))
138 isDegen = Standard_False;
141 return Standard_True;
143 Standard_Boolean Ok = Standard_False;
145 BRepBuilderAPI_FindPlane Searcher( W, presPln );
146 if (Searcher.Found())
148 theFace = BRepBuilderAPI_MakeFace(Searcher.Plane(), W);
151 else // try to find another surface
153 BRepBuilderAPI_MakeFace MF( W );
165 //=============================================================================
166 //function : IsSameOriented
167 //purpose : Checks whether aFace is oriented to the same side as aShell or not
168 //=============================================================================
170 static Standard_Boolean IsSameOriented(const TopoDS_Shape& aFace,
171 const TopoDS_Shape& aShell)
173 TopExp_Explorer Explo(aFace, TopAbs_EDGE);
174 TopoDS_Shape anEdge = Explo.Current();
175 TopAbs_Orientation Or1 = anEdge.Orientation();
177 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
178 TopExp::MapShapesAndAncestors( aShell, TopAbs_EDGE, TopAbs_FACE, EFmap );
180 const TopoDS_Shape& AdjacentFace = EFmap.FindFromKey(anEdge).First();
181 TopoDS_Shape theEdge;
182 for (Explo.Init(AdjacentFace, TopAbs_EDGE); Explo.More(); Explo.Next())
184 theEdge = Explo.Current();
185 if (theEdge.IsSame(anEdge))
189 TopAbs_Orientation Or2 = theEdge.Orientation();
191 return Standard_False;
192 return Standard_True;
195 //=======================================================================
196 //function : MakeSolid
198 //=======================================================================
200 static TopoDS_Solid MakeSolid(TopoDS_Shell& shell, const TopoDS_Wire& wire1,
201 const TopoDS_Wire& wire2, const Standard_Real presPln,
202 TopoDS_Face& face1, TopoDS_Face& face2)
205 StdFail_NotDone::Raise("Thrusections is not build");
206 Standard_Boolean B = shell.Closed();
211 // It is necessary to close the extremities
212 B = PerformPlan(wire1, presPln, face1);
214 B = PerformPlan(wire2, presPln, face2);
216 if (!face1.IsNull() && !IsSameOriented( face1, shell ))
218 if (!face2.IsNull() && !IsSameOriented( face2, shell ))
222 BB.Add(shell, face1);
224 BB.Add(shell, face2);
226 shell.Closed(Standard_True);
233 BB.Add(solid, shell);
235 // verify the orientation the solid
236 BRepClass3d_SolidClassifier clas3d(solid);
237 clas3d.PerformInfinitePoint(Precision::Confusion());
238 if (clas3d.State() == TopAbs_IN) {
240 TopoDS_Shape aLocalShape = shell.Reversed();
241 BB.Add(solid, TopoDS::Shell(aLocalShape));
242 // B.Add(solid, TopoDS::Shell(newShell.Reversed()));
245 solid.Closed(Standard_True);
250 //=======================================================================
251 //function : BRepOffsetAPI_ThruSections
253 //=======================================================================
255 BRepOffsetAPI_ThruSections::BRepOffsetAPI_ThruSections(const Standard_Boolean isSolid, const Standard_Boolean ruled,
256 const Standard_Real pres3d):
257 myIsSolid(isSolid), myIsRuled(ruled), myPres3d(pres3d)
259 myWCheck = Standard_True;
260 //----------------------------
261 myParamType = Approx_ChordLength;
263 myContinuity = GeomAbs_C2;
264 myCritWeights[0] = .4;
265 myCritWeights[1] = .2;
266 myCritWeights[2] = .4;
267 myUseSmoothing = Standard_False;
271 //=======================================================================
274 //=======================================================================
276 void BRepOffsetAPI_ThruSections::Init(const Standard_Boolean isSolid, const Standard_Boolean ruled,
277 const Standard_Real pres3d)
282 myWCheck = Standard_True;
283 //----------------------------
284 myParamType = Approx_ChordLength;
286 myContinuity = GeomAbs_C2;
287 myCritWeights[0] = .4;
288 myCritWeights[1] = .2;
289 myCritWeights[2] = .4;
290 myUseSmoothing = Standard_False;
295 //=======================================================================
298 //=======================================================================
300 void BRepOffsetAPI_ThruSections::AddWire(const TopoDS_Wire& wire)
302 myWires.Append(wire);
305 //=======================================================================
306 //function : AddVertex
308 //=======================================================================
310 void BRepOffsetAPI_ThruSections::AddVertex(const TopoDS_Vertex& aVertex)
315 BB.MakeEdge( DegEdge );
316 BB.Add( DegEdge, aVertex.Oriented(TopAbs_FORWARD) );
317 BB.Add( DegEdge, aVertex.Oriented(TopAbs_REVERSED) );
318 BB.Degenerated( DegEdge, Standard_True );
319 DegEdge.Closed( Standard_True );
322 BB.MakeWire( DegWire );
323 BB.Add( DegWire, DegEdge );
324 DegWire.Closed( Standard_True );
326 myWires.Append( DegWire );
329 //=======================================================================
330 //function : CheckCompatibility
332 //=======================================================================
334 void BRepOffsetAPI_ThruSections::CheckCompatibility(const Standard_Boolean check)
340 //=======================================================================
343 //=======================================================================
345 void BRepOffsetAPI_ThruSections::Build()
347 //Check set of section for right configuration of punctual sections
349 TopExp_Explorer explo;
350 for (i = 2; i <= myWires.Length()-1; i++)
352 Standard_Boolean wdeg = Standard_True;
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");
361 if (myWires.Length() <= 2)
363 Standard_Boolean wdeg = Standard_True;
364 for (i = 1; i <= myWires.Length(); i++)
365 for (explo.Init(myWires(i), TopAbs_EDGE); explo.More(); explo.Next())
367 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
368 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
371 Standard_Failure::Raise("Wrong usage of punctual sections");
375 // compute origin and orientation on wires to avoid twisted results
376 // and update wires to have same number of edges
378 // use BRepFill_CompatibleWires
379 TopTools_SequenceOfShape WorkingSections;
380 WorkingSections.Clear();
381 TopTools_DataMapOfShapeListOfShape WorkingMap;
384 // Calculate the working sections
385 BRepFill_CompatibleWires Georges(myWires);
387 if (Georges.IsDone()) {
388 WorkingSections = Georges.Shape();
389 WorkingMap = Georges.Generated();
391 myWires = WorkingSections;
394 // Calculate the resulting shape
395 if (myWires.Length() == 2 || myIsRuled) {
396 // create a ruled shell
400 // create a smoothed shell
403 // Encode the Regularities
404 BRepLib::EncodeRegularity(myShape);
409 //=======================================================================
410 //function : CreateRuled
412 //=======================================================================
414 void BRepOffsetAPI_ThruSections::CreateRuled()
416 Standard_Integer nbSects = myWires.Length();
417 BRepFill_Generator aGene;
418 // for (Standard_Integer i=1; i<=nbSects; i++) {
420 for (i=1; i<=nbSects; i++) {
421 aGene.AddWire(TopoDS::Wire(myWires(i)));
424 TopoDS_Shell shell = aGene.Shell();
428 // check if the first wire is the same as the last
429 Standard_Boolean vClosed = (myWires(1).IsSame(myWires(nbSects))) ;
438 // verify the orientation of the solid
439 BRepClass3d_SolidClassifier clas3d(solid);
440 clas3d.PerformInfinitePoint(Precision::Confusion());
441 if (clas3d.State() == TopAbs_IN) {
443 TopoDS_Shape aLocalShape = shell.Reversed();
444 B.Add(solid, TopoDS::Shell(aLocalShape));
445 // B.Add(solid, TopoDS::Shell(shell.Reversed()));
453 TopoDS_Wire wire1 = TopoDS::Wire(myWires.First());
454 TopoDS_Wire wire2 = TopoDS::Wire(myWires.Last());
455 myShape = MakeSolid(shell, wire1, wire2, myPres3d, myFirst, myLast);
468 BRepTools_WireExplorer anExp1, anExp2;
469 TopTools_IndexedDataMapOfShapeListOfShape M;
470 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE, TopAbs_FACE, M);
471 TopTools_ListIteratorOfListOfShape it;
473 TopTools_IndexedDataMapOfShapeListOfShape MV;
474 TopExp::MapShapesAndAncestors(shell, TopAbs_VERTEX, TopAbs_FACE, MV);
476 for (i=1; i<=nbSects-1; i++) {
478 const TopoDS_Wire& wire1 = TopoDS::Wire(myWires(i));
479 const TopoDS_Wire& wire2 = TopoDS::Wire(myWires(i+1));
484 Standard_Boolean tantque = anExp1.More() && anExp2.More();
488 const TopoDS_Shape& edge1 = anExp1.Current();
489 const TopoDS_Shape& edge2 = anExp2.Current();
490 Standard_Boolean degen1 = BRep_Tool::Degenerated(anExp1.Current());
491 Standard_Boolean degen2 = BRep_Tool::Degenerated(anExp2.Current());
493 TopTools_MapOfShape MapFaces;
495 TopoDS_Vertex Vdegen = TopExp::FirstVertex(TopoDS::Edge(edge2));
496 for (it.Initialize(MV.FindFromKey(Vdegen)); it.More(); it.Next()) {
497 MapFaces.Add(it.Value());
501 for (it.Initialize(M.FindFromKey(edge2)); it.More(); it.Next()) {
502 MapFaces.Add(it.Value());
507 TopoDS_Vertex Vdegen = TopExp::FirstVertex(TopoDS::Edge(edge1));
508 for (it.Initialize(MV.FindFromKey(Vdegen)); it.More(); it.Next()) {
509 const TopoDS_Shape& Face = it.Value();
510 if (MapFaces.Contains(Face)) {
511 myGenerated.Bind(edge1, Face);
517 for (it.Initialize(M.FindFromKey(edge1)); it.More(); it.Next()) {
518 const TopoDS_Shape& Face = it.Value();
519 if (MapFaces.Contains(Face)) {
520 myGenerated.Bind(edge1, Face);
526 if (!degen1) anExp1.Next();
527 if (!degen2) anExp2.Next();
529 tantque = anExp1.More() && anExp2.More();
530 if (degen1) tantque = anExp2.More();
531 if (degen2) tantque = anExp1.More();
539 //=======================================================================
540 //function : CreateSmoothed
542 //=======================================================================
544 void BRepOffsetAPI_ThruSections::CreateSmoothed()
547 Standard_Integer nbSects = myWires.Length();
548 BRepTools_WireExplorer anExp;
550 Standard_Boolean w1Point = Standard_True;
551 // check if the first wire is punctual
552 for(anExp.Init(TopoDS::Wire(myWires(1))); anExp.More(); anExp.Next()) {
553 w1Point = w1Point && (BRep_Tool::Degenerated(anExp.Current()));
556 Standard_Boolean w2Point = Standard_True;
557 // check if the last wire is punctual
558 for(anExp.Init(TopoDS::Wire(myWires(nbSects))); anExp.More(); anExp.Next()) {
559 w2Point = w2Point && (BRep_Tool::Degenerated(anExp.Current()));
562 Standard_Boolean vClosed = Standard_False;
563 // check if the first wire is the same as last
564 if (myWires(1).IsSame(myWires(myWires.Length()))) vClosed = Standard_True;
566 // find the dimension
567 Standard_Integer nbEdges=0;
569 for(anExp.Init(TopoDS::Wire(myWires(1))); anExp.More(); anExp.Next()) {
574 for(anExp.Init(TopoDS::Wire(myWires(2))); anExp.More(); anExp.Next()) {
579 // recover the shapes
580 Standard_Boolean uClosed = Standard_True;
581 TopTools_Array1OfShape shapes(1, nbSects*nbEdges);
582 Standard_Integer nb=0, i, j;
584 for (i=1; i<=nbSects; i++) {
585 const TopoDS_Wire& wire = TopoDS::Wire(myWires(i));
586 if (!wire.Closed()) {
587 // check if the vertices are the same
588 TopoDS_Vertex V1, V2;
589 TopExp::Vertices(wire,V1,V2);
590 if ( !V1.IsSame(V2)) uClosed = Standard_False;
592 if ( (i==1 && w1Point) || (i==nbSects && w2Point) ) {
593 // if the wire is punctual
594 anExp.Init(TopoDS::Wire(wire));
595 for(j=1; j<=nbEdges; j++) {
597 shapes(nb) = anExp.Current();
602 for(anExp.Init(TopoDS::Wire(wire)); anExp.More(); anExp.Next()) {
604 shapes(nb) = anExp.Current();
609 // create the new surface
613 TopoDS_Edge edge, edge1, edge2, edge3, edge4, couture;
614 TopTools_Array1OfShape vcouture(1, nbEdges);
619 TopoDS_Wire newW1, newW2;
620 BRep_Builder BW1, BW2;
625 TopoDS_Vertex v1f,v1l,v2f,v2l;
627 Standard_Integer nbPnts = 21;
628 TColgp_Array2OfPnt points(1, nbPnts, 1, nbSects);
630 // concatenate each section to get a total surface that will be segmented
631 Handle(Geom_BSplineSurface) TS;
632 TS = TotalSurf(shapes,nbSects,nbEdges,w1Point,w2Point,vClosed);
638 TopoDS_Shape firstEdge;
639 for (i=1; i<=nbEdges; i++) {
641 // segmentation of TS
642 Handle(Geom_BSplineSurface) surface;
643 surface = Handle(Geom_BSplineSurface)::DownCast(TS->Copy());
644 Standard_Real Ui1,Ui2,V0,V1;
647 Ui1 = PreciseUpar(Ui1, surface);
648 Ui2 = PreciseUpar(Ui2, surface);
649 V0 = surface->VKnot(surface->FirstVKnotIndex());
650 V1 = surface->VKnot(surface->LastVKnotIndex());
651 surface->Segment(Ui1,Ui2,V0,V1);
654 edge = TopoDS::Edge(shapes(i));
655 TopExp::Vertices(edge,v1f,v1l);
656 if (edge.Orientation() == TopAbs_REVERSED)
657 TopExp::Vertices(edge,v1l,v1f);
660 edge = TopoDS::Edge(shapes((nbSects-1)*nbEdges+i));
661 TopExp::Vertices(edge,v2f,v2l);
662 if (edge.Orientation() == TopAbs_REVERSED)
663 TopExp::Vertices(edge,v2l,v2f);
666 B.MakeFace(face, surface, Precision::Confusion());
671 // make the missing edges
672 Standard_Real f1, f2, l1, l2;
673 surface->Bounds(f1,l1,f2,l2);
677 // copy the degenerated edge
678 TopoDS_Shape aLocalShape = shapes(1).EmptyCopied();
679 edge1 = TopoDS::Edge(aLocalShape);
680 // edge1 = TopoDS::Edge(shapes(1).EmptyCopied());
681 edge1.Orientation(TopAbs_FORWARD);
684 B.MakeEdge(edge1, surface->VIso(f2), Precision::Confusion());
686 v1f.Orientation(TopAbs_FORWARD);
688 v1l.Orientation(TopAbs_REVERSED);
690 B.Range(edge1, f1, l1);
691 // processing of looping sections
692 // store edges of the 1st section
699 edge2 = TopoDS::Edge(vcouture(i));
702 // copy of the degenerated edge
703 TopoDS_Shape aLocalShape = shapes(nbSects*nbEdges).EmptyCopied();
704 edge2 = TopoDS::Edge(aLocalShape);
705 // edge2 = TopoDS::Edge(shapes(nbSects*nbEdges).EmptyCopied());
706 edge2.Orientation(TopAbs_FORWARD);
709 B.MakeEdge(edge2, surface->VIso(l2), Precision::Confusion());
711 v2f.Orientation(TopAbs_FORWARD);
713 v2l.Orientation(TopAbs_REVERSED);
715 B.Range(edge2, f1, l1);
722 B.MakeEdge(edge3, surface->UIso(f1), Precision::Confusion());
723 v1f.Orientation(TopAbs_FORWARD);
725 v2f.Orientation(TopAbs_REVERSED);
727 B.Range(edge3, f2, l2);
738 if ( uClosed && i==nbEdges) {
742 B.MakeEdge(edge4, surface->UIso(l1), Precision::Confusion());
743 v1l.Orientation(TopAbs_FORWARD);
745 v2l.Orientation(TopAbs_REVERSED);
747 B.Range(edge4, f2, l2);
758 new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)),
759 new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)),face,
760 Precision::Confusion());
761 B.Range(edge1,face,f1,l1);
764 B.UpdateEdge(edge1,new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)),face,
765 Precision::Confusion());
766 B.Range(edge1,face,f1,l1);
767 B.UpdateEdge(edge2,new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)),face,
768 Precision::Confusion());
769 B.Range(edge2,face,f1,l1);
772 if ( uClosed && nbEdges ==1 ) {
774 new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),
775 new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),face,
776 Precision::Confusion());
777 B.Range(edge3,face,f2,l2);
781 B.UpdateEdge(edge3,new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),face,
782 Precision::Confusion());
783 B.Range(edge3,face,f2,l2);
784 B.UpdateEdge(edge4,new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),face,
785 Precision::Confusion());
786 B.Range(edge4,face,f2,l2);
791 // complete newW1 newW2
792 TopoDS_Edge edge12 = edge1;
793 TopoDS_Edge edge22 = edge2;
796 BW1.Add(newW1, edge12);
797 BW2.Add(newW2, edge22);
800 myGenerated.Bind(firstEdge, face);
803 if (uClosed && w1Point && w2Point)
804 shell.Closed(Standard_True);
815 // verify the orientation the solid
816 BRepClass3d_SolidClassifier clas3d(solid);
817 clas3d.PerformInfinitePoint(Precision::Confusion());
818 if (clas3d.State() == TopAbs_IN) {
820 TopoDS_Shape aLocalShape = shell.Reversed();
821 B.Add(solid, TopoDS::Shell(aLocalShape));
822 // B.Add(solid, TopoDS::Shell(shell.Reversed()));
829 myShape = MakeSolid(shell, newW1, newW2, myPres3d, myFirst, myLast);
840 TopExp_Explorer ex(myShape,TopAbs_EDGE);
842 const TopoDS_Edge& CurE = TopoDS::Edge(ex.Current());
843 B.SameRange(CurE, Standard_False);
844 B.SameParameter(CurE, Standard_False);
845 Standard_Real tol = BRep_Tool::Tolerance(CurE);
846 BRepLib::SameParameter(CurE,tol);
851 //=======================================================================
852 //function : EdgeToBSpline
853 //purpose : auxiliary -- get curve from edge and convert it to bspline
854 // parameterized from 0 to 1
855 //=======================================================================
857 // NOTE: this code duplicates the same function in BRepFill_NSections.cxx
858 static Handle(Geom_BSplineCurve) EdgeToBSpline (const TopoDS_Edge& theEdge)
860 Handle(Geom_BSplineCurve) aBSCurve;
861 if (BRep_Tool::Degenerated(theEdge)) {
862 // degenerated edge : construction of a point curve
863 TColStd_Array1OfReal aKnots (1,2);
867 TColStd_Array1OfInteger aMults (1,2);
871 TColgp_Array1OfPnt aPoles(1,2);
872 TopoDS_Vertex vf, vl;
873 TopExp::Vertices(theEdge,vl,vf);
874 aPoles(1) = BRep_Tool::Pnt(vf);
875 aPoles(2) = BRep_Tool::Pnt(vl);
877 aBSCurve = new Geom_BSplineCurve (aPoles, aKnots, aMults, 1);
881 // get the curve of the edge
882 TopLoc_Location aLoc;
883 Standard_Real aFirst, aLast;
884 Handle(Geom_Curve) aCurve = BRep_Tool::Curve (theEdge, aLoc, aFirst, aLast);
886 // convert its part used by edge to bspline; note that if edge curve is bspline,
887 // conversion made via trimmed curve is still needed -- it will copy it, segment
888 // as appropriate, and remove periodicity if it is periodic (deadly for approximator)
889 Handle(Geom_TrimmedCurve) aTrimCurve = new Geom_TrimmedCurve (aCurve, aFirst, aLast);
891 // special treatment of conic curve
892 if (aTrimCurve->BasisCurve()->IsKind(STANDARD_TYPE(Geom_Conic)))
894 GeomConvert_ApproxCurve anAppr (aTrimCurve, Precision::Confusion(), GeomAbs_C1, 16, 14);
895 if (anAppr.HasResult())
896 aBSCurve = anAppr.Curve();
900 if (aBSCurve.IsNull())
901 aBSCurve = GeomConvert::CurveToBSplineCurve (aTrimCurve);
903 // apply transformation if needed
904 if (! aLoc.IsIdentity())
905 aBSCurve->Transform (aLoc.Transformation());
907 // reparameterize to [0,1]
908 TColStd_Array1OfReal aKnots (1, aBSCurve->NbKnots());
909 aBSCurve->Knots (aKnots);
910 BSplCLib::Reparametrize (0., 1., aKnots);
911 aBSCurve->SetKnots (aKnots);
914 // reverse curve if edge is reversed
915 if (theEdge.Orientation() == TopAbs_REVERSED)
921 //=======================================================================
922 //function : TotalSurf
924 //=======================================================================
926 Handle(Geom_BSplineSurface) BRepOffsetAPI_ThruSections::
927 TotalSurf(const TopTools_Array1OfShape& shapes,
928 const Standard_Integer NbSects,
929 const Standard_Integer NbEdges,
930 const Standard_Boolean w1Point,
931 const Standard_Boolean w2Point,
932 const Standard_Boolean vClosed) const
934 Standard_Integer i,j,jdeb=1,jfin=NbSects;
938 GeomFill_SectionGenerator section;
939 Handle(Geom_BSplineSurface) surface;
940 Handle(Geom_BSplineCurve) BS, BS1;
941 Handle(Geom_TrimmedCurve) curvTrim;
942 Handle(Geom_BSplineCurve) curvBS;
946 edge = TopoDS::Edge(shapes(1));
947 TopExp::Vertices(edge,vl,vf);
948 TColgp_Array1OfPnt Extremities(1,2);
949 Extremities(1) = BRep_Tool::Pnt(vf);
950 Extremities(2) = BRep_Tool::Pnt(vl);
951 TColStd_Array1OfReal Bounds(1,2);
954 TColStd_Array1OfInteger Mult(1,2);
957 Handle(Geom_BSplineCurve) BSPoint
958 = new Geom_BSplineCurve(Extremities,Bounds,Mult,1);
959 section.AddCurve(BSPoint);
966 for (j=jdeb; j<=jfin; j++) {
968 // case of looping sections
969 if (j==jfin && vClosed) {
970 section.AddCurve(BS1);
974 // read the first edge to initialise CompBS;
975 TopoDS_Edge aPrevEdge = TopoDS::Edge (shapes((j-1)*NbEdges+1));
976 Handle(Geom_BSplineCurve) curvBS = EdgeToBSpline (aPrevEdge);
979 GeomConvert_CompCurveToBSplineCurve CompBS(curvBS);
981 for (i=2; i<=NbEdges; i++) {
983 TopoDS_Edge aNextEdge = TopoDS::Edge (shapes((j-1)*NbEdges+i));
984 curvBS = EdgeToBSpline (aNextEdge);
987 CompBS.Add(curvBS, Precision::Confusion(), Standard_True, Standard_False, 1);
990 // return the final section
991 BS = CompBS.BSplineCurve();
992 section.AddCurve(BS);
994 // case of looping sections
995 if (j==jdeb && vClosed) {
1003 edge = TopoDS::Edge(shapes(NbSects*NbEdges));
1004 TopExp::Vertices(edge,vl,vf);
1005 TColgp_Array1OfPnt Extremities(1,2);
1006 Extremities(1) = BRep_Tool::Pnt(vf);
1007 Extremities(2) = BRep_Tool::Pnt(vl);
1008 TColStd_Array1OfReal Bounds(1,2);
1011 TColStd_Array1OfInteger Mult(1,2);
1014 Handle(Geom_BSplineCurve) BSPoint
1015 = new Geom_BSplineCurve(Extremities,Bounds,Mult,1);
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 associated 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;