1 // Created on: 1998-01-07
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-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.
19 #include <BRepFill_Sweep.ixx>
21 #include <BRepFill_SectionLaw.hxx>
22 //#include <BRepFill_TrimCorner.hxx>
23 #include <BRepFill_CurveConstraint.hxx>
25 #include <GeomFill_SectionLaw.hxx>
26 #include <GeomFill_LocationLaw.hxx>
27 #include <GeomFill_Sweep.hxx>
29 // modified by NIZHNY-MKK Wed Oct 22 12:25:45 2003
30 #include <BRepFill_TrimShellCorner.hxx>
32 //#include <GeomPlate_BuildPlateSurface.hxx>
33 //#include <GeomPlate_Surface.hxx>
34 //#include <GeomPlate_PointConstraint.hxx>
36 #include <gp_Pnt2d.hxx>
37 #include <gp_Vec2d.hxx>
38 #include <Bnd_Box.hxx>
40 #include <Geom_Surface.hxx>
41 #include <Geom_SurfaceOfRevolution.hxx>
42 #include <Geom_RectangularTrimmedSurface.hxx>
43 #include <Geom_Plane.hxx>
44 #include <Geom_Curve.hxx>
45 #include <Geom_BezierCurve.hxx>
46 #include <Geom_BSplineCurve.hxx>
47 #include <Geom2d_Line.hxx>
48 #include <Geom2d_Curve.hxx>
49 #include <Geom2d_TrimmedCurve.hxx>
50 #include <GeomLib.hxx>
51 #include <GeomLib_IsPlanarSurface.hxx>
52 #include <BRepLib_FindSurface.hxx>
53 #include <GeomConvert_ApproxSurface.hxx>
55 #include <BRepAdaptor_HCurve.hxx>
56 #include <BRepAdaptor_HCurve2d.hxx>
57 #include <BRepAdaptor_HSurface.hxx>
58 #include <Adaptor3d_HCurveOnSurface.hxx>
59 #include <GeomAdaptor_HSurface.hxx>
60 #include <GeomAdaptor_HCurve.hxx>
61 #include <Geom2dAdaptor_HCurve.hxx>
62 #include <Approx_CurveOnSurface.hxx>
63 #include <Approx_SameParameter.hxx>
64 #include <GCPnts_AbscissaPoint.hxx>
66 #include <BRep_Builder.hxx>
67 #include <BRep_Tool.hxx>
68 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
69 #include <BRep_TEdge.hxx>
70 #include <BRep_TVertex.hxx>
71 #include <BRep_CurveRepresentation.hxx>
72 #include <BRep_GCurve.hxx>
74 #include <BRepLib.hxx>
75 #include <BRepLib_MakeEdge.hxx>
76 #include <BRepLib_MakeFace.hxx>
77 #include <BRepLib_FaceError.hxx>
80 #include <TopoDS_Edge.hxx>
81 #include <TopoDS_Face.hxx>
82 #include <TopoDS_Compound.hxx>
83 #include <TopoDS_Shell.hxx>
85 #include <TopExp_Explorer.hxx>
86 #include <TopAbs_Orientation.hxx>
88 #include <TColStd_HArray1OfInteger.hxx>
89 #include <TColStd_Array2OfInteger.hxx>
90 #include <TColStd_Array1OfReal.hxx>
91 #include <TColStd_Array2OfReal.hxx>
92 #include <TColGeom_Array2OfSurface.hxx>
93 #include <TColgp_Array1OfPnt.hxx>
94 #include <TColStd_Array1OfBoolean.hxx>
96 #include <TopTools_Array1OfShape.hxx>
97 #include <TopTools_Array2OfShape.hxx>
98 #include <TopTools_HArray2OfShape.hxx>
99 #include <TopTools_HArray1OfShape.hxx>
100 #include <TopTools_ListIteratorOfListOfShape.hxx>
101 #include <TopTools_ListOfShape.hxx>
102 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
103 #include <TopTools_SequenceOfShape.hxx>
104 #include <BRepTools_WireExplorer.hxx>
106 #include <Standard_ConstructionError.hxx>
107 #include <Precision.hxx>
108 #include <BRepBuilderAPI_MakeWire.hxx>
110 #include <BRepTools_Substitution.hxx>
111 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
112 #include <TopoDS_Iterator.hxx>
115 #include <BRepCheck_Edge.hxx>
119 #include <DrawTrSurf.hxx>
121 static Standard_Boolean Affich = 0;
124 //=======================================================================
125 //function : NumberOfPoles
127 //=======================================================================
128 static Standard_Integer NumberOfPoles(const TopoDS_Wire& W)
130 Standard_Integer NbPoints = 0;
132 TopoDS_Iterator iter(W);
133 for (; iter.More(); iter.Next())
135 BRepAdaptor_Curve c(TopoDS::Edge(iter.Value()));
137 Standard_Real dfUf = c.FirstParameter();
138 Standard_Real dfUl = c.LastParameter();
139 if (IsEqual(dfUf,dfUl))
145 case GeomAbs_BezierCurve:
147 // Put all poles for bezier
148 Handle(Geom_BezierCurve) GC = c.Bezier();
149 Standard_Integer iNbPol = GC->NbPoles();
154 case GeomAbs_BSplineCurve:
156 // Put all poles for bspline
157 Handle(Geom_BSplineCurve) GC = c.BSpline();
158 Standard_Integer iNbPol = GC->NbPoles();
169 case GeomAbs_Ellipse:
170 case GeomAbs_Hyperbola:
171 case GeomAbs_Parabola:
177 NbPoints += 15 + c.NbIntervals(GeomAbs_C3);
178 } // switch (c.GetType()) ...
179 } // for (; iter.More(); iter.Next())
184 //=======================================================================
185 //function : HasPCurves
187 //=======================================================================
188 static Standard_Boolean HasPCurves(const TopoDS_Edge& E)
190 Standard_Boolean haspcurves = Standard_False;
192 BRep_ListIteratorOfListOfCurveRepresentation itcr
193 ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves());
194 for (; itcr.More(); itcr.Next())
196 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
197 if (cr->IsCurveOnSurface())
199 haspcurves = Standard_True;
206 //=======================================================================
207 //function : Translate
208 //purpose : Copy a column from one table to another.
209 //=======================================================================
210 static void Translate(const Handle(TopTools_HArray2OfShape)& ArrayIn,
211 const Standard_Integer In,
212 Handle(TopTools_HArray2OfShape)& ArrayOut,
213 const Standard_Integer Out)
215 Standard_Integer ii, Nb;
216 Nb = ArrayOut->ColLength();
217 for (ii=1; ii<=Nb; ii++) {
218 ArrayOut->SetValue(ii, Out, ArrayIn->Value(ii, In));
223 //=======================================================================
225 //purpose : Bounding box of a section.
226 //=======================================================================
227 static void Box(Handle(GeomFill_SectionLaw)& Sec,
228 const Standard_Real U,
232 Standard_Integer NbPoles, bid;
234 Sec->SectionShape(NbPoles, bid, bid);
235 TColgp_Array1OfPnt Poles(1, NbPoles);
236 TColStd_Array1OfReal W(1, NbPoles);
237 Sec->D0(U, Poles, W);
238 for (Standard_Integer ii=1; ii<=NbPoles; ii++) {
243 //=======================================================================
245 //purpose : Check if E is an edge of sewing on S
246 // and make the representation HadHoc
247 //=======================================================================
248 static Handle(Geom2d_Curve) Couture(const TopoDS_Edge& E,
249 const Handle(Geom_Surface)& S,
250 const TopLoc_Location& L)
252 TopLoc_Location l = L.Predivided(E.Location());
253 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
255 // find the representation
256 BRep_ListIteratorOfListOfCurveRepresentation itcr
257 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
259 while (itcr.More()) {
260 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
261 if (cr->IsCurveOnSurface(S,l)) {
262 Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
263 if (GC->IsCurveOnClosedSurface() && Eisreversed)
264 return GC->PCurve2();
270 Handle(Geom2d_Curve) pc;
275 //=======================================================================
276 //function : CheckSameParameter
277 //purpose : Check a posteriori that sameparameter has worked correctly
278 //=======================================================================
280 static Standard_Boolean CheckSameParameter
281 (const Handle(Adaptor3d_HCurve)& C3d,
282 const Handle(Geom2d_Curve)& Pcurv,
283 const Handle(Adaptor3d_HSurface)& S,
284 const Standard_Real tol3d,
285 Standard_Real& tolreached)
288 Standard_Real f = C3d->FirstParameter();
289 Standard_Real l = C3d->LastParameter();
290 Standard_Integer nbp = 45;
291 Standard_Real step = 1./(nbp -1);
292 for(Standard_Integer i = 0; i < nbp; i++){
295 t = (1-t) * f + t * l;
296 Pcurv->Value(t).Coord(u,v);
297 gp_Pnt pS = S->Value(u,v);
298 gp_Pnt pC = C3d->Value(t);
299 Standard_Real d2 = pS.SquareDistance(pC);
300 tolreached = Max(tolreached,d2);
302 tolreached = sqrt(tolreached);
303 if(tolreached > tol3d){
305 return Standard_False;
308 tolreached = Max(tolreached,Precision::Confusion());
309 return Standard_True;
312 //=======================================================================
313 //function : SameParameter
314 //purpose : Encapsulation of Sameparameter
315 // Boolean informs if the pcurve was computed or not...
316 // The tolerance is always OK.
317 //=======================================================================
319 static Standard_Boolean SameParameter(TopoDS_Edge& E,
320 Handle(Geom2d_Curve)& Pcurv,
321 const Handle(Geom_Surface)& Surf,
322 const Standard_Real tol3d,
323 Standard_Real& tolreached)
325 //Handle(BRepAdaptor_HCurve) C3d = new (BRepAdaptor_HCurve)(E);
327 Handle(Geom_Curve) C3d = BRep_Tool::Curve( E, f, l );
328 GeomAdaptor_Curve GAC3d( C3d, f, l );
329 Handle(GeomAdaptor_HCurve) HC3d = new GeomAdaptor_HCurve( GAC3d );
331 Handle(GeomAdaptor_HSurface) S = new (GeomAdaptor_HSurface)(Surf);
332 Standard_Real ResTol;
334 if(CheckSameParameter( HC3d, Pcurv, S, tol3d, tolreached ))
335 return Standard_True;
339 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( Pcurv );
340 Approx_CurveOnSurface AppCurve(HC2d, S, HC2d->FirstParameter(), HC2d->LastParameter(),
341 Precision::Confusion(), GeomAbs_C1, 10, 10, Standard_True);
342 if (AppCurve.IsDone() && AppCurve.HasResult())
344 C3d = AppCurve.Curve3d();
345 tolreached = AppCurve.MaxError3d();
347 B.UpdateEdge( E, C3d, tolreached );
348 return Standard_True;
352 Approx_SameParameter sp( HC3d, Pcurv, S, tol3d );
353 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
354 else if(!sp.IsDone() && !sp.IsSameParameter()){
356 cout<<"echec SameParameter"<<endl;
358 return Standard_False;
361 ResTol = sp.TolReached();
362 if(ResTol > tolreached ){
364 cout<<"SameParameter : Tolerance not reached!"<<endl;
365 cout<<"tol visee : "<<tol3d<<" tol obtained : "<<ResTol<<endl;
367 return Standard_False;
370 tolreached = 1.1*ResTol;
371 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
373 return Standard_True;
376 //=======================================================================
377 //Objet : Orientate an edge of natural restriction
379 //=======================================================================
380 static void Oriente(const Handle(Geom_Surface)& S,
384 gp_Vec2d D, URef(1, 0), VRef(0, 1);
385 Standard_Boolean isuiso, isfirst, isopposite;
386 Standard_Real UFirst, ULast, VFirst, VLast, f, l;
387 S->Bounds(UFirst, ULast, VFirst, VLast);
388 Handle(Geom2d_Curve) C;
391 C = BRep_Tool::CurveOnSurface(E, S, bid, f, l);
392 C->D1((f+l)/2, P, D);
394 isuiso = D.IsParallel(VRef, 0.1);
397 isfirst = (Abs (P.X()-UFirst) < Precision::Confusion());
398 isopposite = D.IsOpposite(VRef, 0.1);
399 E.Orientation(TopAbs_REVERSED);
402 isfirst = (Abs (P.Y()-VFirst) < Precision::Confusion());
403 isopposite = D.IsOpposite(URef, 0.1);
404 E.Orientation(TopAbs_FORWARD);
407 if (!isfirst) E.Reverse();
408 if (isopposite) E.Reverse();
411 static void UpdateEdgeOnPlane(const TopoDS_Face& F, const TopoDS_Edge& E,
412 const BRep_Builder& BB)
415 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
416 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
418 Standard_Real Tol = BRep_Tool::Tolerance(E);
419 BB.UpdateEdge(E, C2d, S, Loc, Tol);
420 BRepCheck_Edge Check(E);
421 Tol = Max(Tol,Check.Tolerance());
422 BB.UpdateEdge(E, Tol);
425 V = TopExp::FirstVertex(E);
426 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
427 V = TopExp::LastVertex(E);
428 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
431 //=======================================================================
432 //Function : BuildFace
433 //Objet : Construct a Face via a surface and 4 Edges (natural borders)
434 // : Only one Hypothesis : isos u and v are switched :
435 // Edge1/3 are iso u (recp v)
436 // Edge2/4 are iso v (recp u)
437 //=======================================================================
438 static void BuildFace(const Handle(Geom_Surface)& S,
439 const TopoDS_Edge& E1,
440 const TopoDS_Edge& E2,
441 const TopoDS_Edge& E3,
442 const TopoDS_Edge& E4,
443 TopTools_DataMapOfShapeShape& EEmap,
444 const Standard_Boolean ExchUV,
445 const Standard_Boolean UReverse,
449 // Class BRep_Tool without fields and without Constructor :
451 TopoDS_Edge e1, e2, E;
454 BRepBuilderAPI_MakeWire B;
455 TopoDS_Iterator Iter;
458 //Is the surface planar ?
459 Standard_Real Tol1, Tol2, Tol3, Tol4;
460 Tol1 = BRep_Tool::Tolerance( E1 );
461 Tol2 = BRep_Tool::Tolerance( E2 );
462 Tol3 = BRep_Tool::Tolerance( E3 );
463 Tol4 = BRep_Tool::Tolerance( E4 );
464 // Tol = Min( BT.Tolerance(E1), BT.Tolerance(E2));
465 Tol = Min( Tol1, Tol2 );
466 // Tol = Min(Tol, Min(BT.Tolerance(E3),BT.Tolerance(E4)));
467 Tol = Min( Tol, Min( Tol3, Tol4 ) );
468 Standard_Boolean IsPlan = Standard_False;
469 Handle(Geom_Plane) thePlane;
471 if (!E1.IsSame(E3) && !E2.IsSame(E4)) //exclude cases with seam edges: they are not planar
473 GeomLib_IsPlanarSurface IsP(S, Tol);
476 IsPlan = Standard_True;
477 thePlane = new Geom_Plane( IsP.Plan() );
481 Handle(BRep_TEdge)& TE1 = *((Handle(BRep_TEdge)*)&E1.TShape());
482 Handle(BRep_TEdge)& TE2 = *((Handle(BRep_TEdge)*)&E2.TShape());
483 Handle(BRep_TEdge)& TE3 = *((Handle(BRep_TEdge)*)&E3.TShape());
484 Handle(BRep_TEdge)& TE4 = *((Handle(BRep_TEdge)*)&E4.TShape());
485 TE1->Tolerance( Precision::Confusion() );
486 TE2->Tolerance( Precision::Confusion() );
487 TE3->Tolerance( Precision::Confusion() );
488 TE4->Tolerance( Precision::Confusion() );
490 TopoDS_Wire theWire = BRepLib_MakeWire( E1, E2, E3, E4 );
491 Standard_Integer NbPoints = NumberOfPoles( theWire );
492 if (NbPoints <= 100) //limitation for CPU
494 BRepLib_FindSurface FS( theWire, -1, Standard_True );
497 IsPlan = Standard_True;
498 thePlane = Handle(Geom_Plane)::DownCast(FS.Surface());
501 BB.UpdateEdge( E1, Tol1 );
502 BB.UpdateEdge( E2, Tol2 );
503 BB.UpdateEdge( E3, Tol3 );
504 BB.UpdateEdge( E4, Tol4 );
508 // Construction of the wire
512 // if (!IsPlan || !BT.Degenerated(e1))
513 if (!IsPlan || !BRep_Tool::Degenerated(e1))
518 // if (!IsPlan || !BT.Degenerated(e2))
519 if (!IsPlan || !BRep_Tool::Degenerated(e2))
522 if (!BRep_Tool::Degenerated(e2))
525 TopoDS_Shape NewEdge;
526 //take the last edge added to WW
527 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
528 NewEdge = Iter.Value();
529 if (! e2.IsSame(NewEdge))
530 EEmap.Bind( e2, NewEdge );
542 // if (!IsPlan || !BT.Degenerated(E))
543 if (!IsPlan || !BRep_Tool::Degenerated(E))
546 if (!BRep_Tool::Degenerated(E))
549 TopoDS_Shape NewEdge;
550 //take the last edge added to WW
551 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
552 NewEdge = Iter.Value();
553 if (! E.IsSame(NewEdge))
554 EEmap.Bind( E, NewEdge );
566 // if (!IsPlan || !BT.Degenerated(E))
567 if (!IsPlan || !BRep_Tool::Degenerated(E))
570 if (!BRep_Tool::Degenerated(E))
573 TopoDS_Shape NewEdge;
574 //take the last edge added to WW
575 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
576 NewEdge = Iter.Value();
577 if (! E.IsSame(NewEdge))
578 EEmap.Bind( E, NewEdge );
585 DBRep::Set("wire-on-face", WW);
588 // Construction of the face.
589 if (IsPlan) { // Suspend representation 2d
590 // and construct face Plane
592 //BRepLib_MakeFace MkF(IsP.Plan(), WW);
594 gp_Vec DU, DV, NS, NP;
595 Standard_Real Ufirst, Ulast, Vfirst, Vlast;
596 S->Bounds( Ufirst, Ulast, Vfirst, Vlast );
597 S->D1( (Ufirst+Ulast)/2., (Vfirst+Vlast)/2., aPnt, DU, DV );
599 NP = thePlane->Pln().Axis().Direction();
601 thePlane->UReverse();
602 BRepLib_MakeFace MkF( thePlane, WW );
603 if (MkF.Error() != BRepLib_FaceDone) {
605 BRepLib_FaceError Err = MkF.Error();
606 cout << "Planar Face Error :" << Err << endl;
610 Handle(Geom2d_Curve) NullC2d;
612 BB.UpdateEdge( E1, NullC2d, S, Loc, Tol1 );
613 BB.UpdateEdge( E2, NullC2d, S, Loc, Tol2 );
614 BB.UpdateEdge( E3, NullC2d, S, Loc, Tol3 );
615 BB.UpdateEdge( E4, NullC2d, S, Loc, Tol4 );
618 UpdateEdgeOnPlane(F,E1,BB);
619 UpdateEdgeOnPlane(F,E2,BB);
620 UpdateEdgeOnPlane(F,E3,BB);
621 UpdateEdgeOnPlane(F,E4,BB);
624 Handle(Geom2d_Curve) NC;
626 // B.UpdateEdge(E1, NC, S, Loc, BT.Tolerance(E1));
627 BB.UpdateEdge(E1, NC, S, Loc, BRep_Tool::Tolerance(E1));
628 // B.UpdateEdge(E2, NC, S, Loc, BT.Tolerance(E2));
629 BB.UpdateEdge(E2, NC, S, Loc, BRep_Tool::Tolerance(E2));
630 // B.UpdateEdge(E3, NC, S, Loc, BT.Tolerance(E3));
631 BB.UpdateEdge(E3, NC, S, Loc, BRep_Tool::Tolerance(E3));
632 // B.UpdateEdge(E4, NC, S, Loc, BT.Tolerance(E4));
633 BB.UpdateEdge(E4, NC, S, Loc, BRep_Tool::Tolerance(E4));
638 if (!IsPlan) {// Cas Standard : Ajout
639 BB.MakeFace(F, S, Precision::Confusion());
644 if (ExchUV) F.Reverse();
645 if (UReverse) F.Reverse();
649 //=======================================================================
650 //Fonction : BuildEdge
651 //Objet : Construct non-closed Edge
652 //=======================================================================
653 static TopoDS_Edge BuildEdge(Handle(Geom_Curve)& C3d,
654 Handle(Geom2d_Curve)& C2d,
655 Handle(Geom_Surface)& S,
656 const TopoDS_Vertex& VF,
657 const TopoDS_Vertex& VL,
658 const Standard_Real f,
659 const Standard_Real l,
660 const Standard_Real Tol3d)
663 Standard_Real Tol1, Tol2, Tol, d;
664 // Class BRep_Tool without fields and without Constructor :
670 P1 = BRep_Tool::Pnt(VF);
671 // Tol1 = BT.Tolerance(VF);
672 Tol1 = BRep_Tool::Tolerance(VF);
674 P2 = BRep_Tool::Pnt(VL);
675 // Tol2 = BT.Tolerance(VF);
676 Tol2 = BRep_Tool::Tolerance(VF);
677 Tol = Max(Tol1, Tol2);
680 (P1.Distance(P2) < Tol ) ) {
684 S->D0(P2d.X(), P2d.Y(), P);
686 if (d > Tol) Tol = d;
688 S->D0(P2d.X(), P2d.Y(), P);
690 if (d > Tol) Tol = d;
692 B.UpdateVertex(VF, Tol);
693 B.UpdateVertex(VL, Tol);
696 B.UpdateEdge(E,C2d,S,TopLoc_Location(), Tol);
700 B.Degenerated(E, Standard_True);
708 B.UpdateVertex(VF, d);
711 P1 = BRep_Tool::Pnt(VL);
715 B.UpdateVertex(VL, d);
717 BRepLib_MakeEdge MkE (C3d, VF, VL, f, l);
718 if (!MkE.IsDone()) { // Error of construction !!
721 sprintf(name,"firstvertex_error");
722 DBRep::Set(name, VF);
723 sprintf(name,"lastvertex_error");
724 DBRep::Set(name, VL);
725 sprintf(name,"curve3d_error");
727 DrawTrSurf::Set(Temp, C3d);
728 // DrawTrSurf::Set(name, C3d);
729 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
735 B.UpdateEdge(E, C2d, S, Loc, Tol3d);
741 //=======================================================================
743 //Objet : Construct the faces of filling
744 //=======================================================================
745 static Standard_Boolean Filling(const TopoDS_Shape& EF,
746 const TopoDS_Shape& F1,
747 const TopoDS_Shape& EL,
748 const TopoDS_Shape& F2,
749 TopTools_DataMapOfShapeShape& EEmap,
750 const Standard_Real Tol,
752 const gp_Vec& TangentOnPart1,
758 // Class BRep_Tool without fields and without Constructor :
760 // Standard_Integer NbInt =0;
761 // Standard_Real Tol3d = Tol;
762 Standard_Boolean WithE3, WithE4;
764 // Return constraints
765 TopoDS_Vertex V1, V2, Vf, Vl;
766 TopoDS_Edge E1, E2, E3, E4;
767 E1 = TopoDS::Edge(EF);
768 E2 = TopoDS::Edge(EL);
770 TopExp::Vertices(E1, Vf, Vl);
771 Vf.Orientation(TopAbs_FORWARD);
772 Vl.Orientation(TopAbs_FORWARD);
774 TopExp::Vertices(E2, V1, V2);
775 V1.Orientation(TopAbs_REVERSED);
776 V2.Orientation(TopAbs_REVERSED);
781 WithE3 = WithE4 = Standard_False;
783 if ((!Aux1.IsNull()) && (!Vf.IsSame(V1))) {
785 // E3 = TopoDS::Edge(Aux1);
786 WithE3 = Standard_True;
794 else if (!Aux2.IsNull() && (!Vl.IsSame(V2))) {
796 // E4 = TopoDS::Edge(Aux2);
797 WithE4 = Standard_True;
802 DBRep::Set("Fill_Edge1", E1);
803 DBRep::Set("Fill_Edge2", E2);
805 DBRep::Set("Fill_Edge3", E3);
807 DBRep::Set("Fill_Edge4", E4);
811 // Construction of a surface of revolution
812 Handle(Geom_Curve) Prof1, Prof2;
813 //Standard_Integer ii, jj;//, Nb;
814 Standard_Real f1, f2, l1, l2,/*d1, d2,*/ Angle;//, Eps = 1.e-9;
815 // Prof1 = BT.Curve(E1, f1, l1);
816 Prof1 = BRep_Tool::Curve(E1, f1, l1);
817 // Prof2 = BT.Curve(E2, f2, l2);
818 Prof2 = BRep_Tool::Curve(E2, f2, l2);
822 Tf.SetTransformation(Axe);
824 // Choose the angle of opening
825 P1 = Prof1->Value((f1+l1)/2);
826 P2 = Prof2->Value((f2+l2)/2);
829 p1.SetCoord(P1.Z(), P1.X());
830 p2.SetCoord(P2.Z(), P2.X());
831 gp_Vec2d v1(gp::Origin2d(), p1);
832 gp_Vec2d v2(gp::Origin2d(), p2);
833 if (v1.Magnitude() <= gp::Resolution() ||
834 v2.Magnitude() <= gp::Resolution())
835 return Standard_False;
836 Angle = v1.Angle(v2);
838 gp_Ax1 axe(Axe.Location(), Axe.YDirection());
845 Handle(Geom_SurfaceOfRevolution) Rev =
846 new (Geom_SurfaceOfRevolution) (Prof1, axe);
848 Handle(Geom_Surface) Surf =
849 new (Geom_RectangularTrimmedSurface) (Rev, 0, Angle, f1, l1);
851 // Control the direction of the rotation
852 Standard_Boolean ToReverseResult = Standard_False;
854 d1u = Surf->DN(0, (f1+l1)/2, 1, 0);
855 if (d1u.Angle(TangentOnPart1) > M_PI/2) { //Invert everything
856 ToReverseResult = Standard_True;
859 Angle = 2*M_PI - Angle;
860 Rev = new (Geom_SurfaceOfRevolution) (Prof1, axe);
861 Surf = new (Geom_RectangularTrimmedSurface)
862 (Rev, 0, Angle, f1, l1);
868 char* Temp = "Surf_Init" ;
869 DrawTrSurf::Set(Temp, Surf);
873 Handle(Geom2d_Curve) C1, C2, C3, C4;
875 // Deform the surface of revolution.
876 GeomPlate_BuildPlateSurface BPS;
878 Handle(BRepAdaptor_HSurface) AS;
879 Handle(BRepAdaptor_HCurve2d) AC2d;
880 Handle(Adaptor3d_HCurveOnSurface) HConS;
882 Handle(Geom2d_Line) L;
885 L = new (Geom2d_Line) (P2d, gp::DY2d());
886 C1 = new (Geom2d_TrimmedCurve) (L, f1, l1);
888 P2d.SetCoord(Angle,0.);
889 L = new (Geom2d_Line) (P2d, gp::DY2d());
890 C2 = new (Geom2d_TrimmedCurve) (L, f1, l1);
892 // It is required to control the direction and the range.
894 Surf->D0(P2d.X(), P2d.Y(), P1);
896 Surf->D0(P2d.X(), P2d.Y(), P2);
898 P = BRep_Tool::Pnt(V1);
899 if (P.Distance(P2)+Tol < P.Distance(P1)) {
900 // E2 is parsed in the direction opposite to E1
907 GeomLib::SameRange(Precision::PConfusion(), C2,
908 C2->FirstParameter(),
914 P1 = BRep_Tool::Pnt(Vf);
916 P2 = BRep_Tool::Pnt(V1);
917 // pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BT.Tolerance(Vf));
919 P1 = BRep_Tool::Pnt(Vl);
921 P2 = BRep_Tool::Pnt(V2);
922 // pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BT.Tolerance(Vl));
925 L = new (Geom2d_Line) (P2d, gp::DX2d());
926 C3 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
930 L = new (Geom2d_Line) (P2d, gp::DX2d());
931 C4 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
933 // Determine the constraints and
934 // their parametric localisation.
936 AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
937 AC2d = new BRepAdaptor_HCurve2d();
938 AC2d->ChangeCurve2d().Initialize(E1,TopoDS::Face(F1));
939 HConS = new (Adaptor3d_HCurveOnSurface)();
940 HConS->ChangeCurve().Load(AC2d);
941 HConS->ChangeCurve().Load(AS);
943 Handle(BRepFill_CurveConstraint) Cont
944 = new BRepFill_CurveConstraint(HConS, 1, 15);
945 Cont->SetCurve2dOnSurf(C1);
948 NbInt = HConS->NbIntervals(GeomAbs_CN);
952 AS = new BRepAdaptor_HSurface(TopoDS::Face(F2));
953 AC2d = new BRepAdaptor_HCurve2d();
954 AC2d->ChangeCurve2d().Initialize(E2,TopoDS::Face(F2));
955 HConS = new (Adaptor3d_HCurveOnSurface);
957 HConS->ChangeCurve().Load(AC2d);
958 HConS->ChangeCurve().Load(AS);
960 Handle(BRepFill_CurveConstraint) Cont
961 = new BRepFill_CurveConstraint(HConS, 1, 15);
962 Cont->SetCurve2dOnSurf(C2);
967 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E3);
968 Handle(BRepFill_CurveConstraint) Cont
969 = new BRepFill_CurveConstraint(AC, 0);
970 Cont->SetCurve2dOnSurf(C3);
974 Standard_Real delta = Angle / 11;
976 P = BRep_Tool::Pnt(Vf);
977 Handle(GeomPlate_PointConstraint) PC;
978 for (ii=1; ii<=10; ii++) {
979 C3->D0(ii*delta, P2d);
980 PC = new (GeomPlate_PointConstraint) (P, 0);
981 PC->SetPnt2dOnSurf(P2d);
988 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E4);
989 Handle(BRepFill_CurveConstraint) Cont
990 = new BRepFill_CurveConstraint(AC, 0);
991 Cont->SetCurve2dOnSurf(C4);
995 Standard_Real delta = Angle / 11;
997 P = BRep_Tool::Pnt(Vl);
998 Handle(GeomPlate_PointConstraint) PC;
999 for (ii=1; ii<=10; ii++) {
1000 C4->D0(ii*delta, P2d);
1001 PC = new (GeomPlate_PointConstraint) (P, 0);
1002 PC->SetPnt2dOnSurf(P2d);
1007 BPS.LoadInitSurface(Surf);
1010 // Controle s'il y a une deformation effective
1011 Handle(GeomPlate_Surface) plate;
1012 plate = BPS.Surface();
1013 plate->SetBounds(0, Angle, f1, l1);
1014 Standard_Boolean Ok=Standard_True;
1018 for (ii=0; ii<=5 && Ok; ii++) {
1020 for (jj=0; jj<=5 && Ok; jj++) {
1022 plate->D0(u, v, P1);
1024 Ok = (P2.IsEqual(P1, Tol));
1030 // Approx de la plate surface
1031 // Bords naturelles => pas besoin de criteres.
1032 GeomConvert_ApproxSurface App(BPS.Surface(),
1034 GeomAbs_C1, GeomAbs_C1,
1036 if (!App.HasResult()) {
1038 cout << "Filling_Approx : Pas de resultat" << endl;
1040 return Standard_False;
1043 cout << "Filling_Approx Error 3d = " <<
1044 App.MaxError() << endl;
1046 Surf = App.Surface();
1047 Tol3d = App.MaxError();
1052 TopLoc_Location Loc;
1053 Handle(Geom_Curve) C3d;
1054 B.UpdateEdge(E1, C1, Surf, Loc, /*Tol3d*/Precision::Confusion());
1055 B.UpdateEdge(E2, C2, Surf, Loc, /*Tol3d*/Precision::Confusion());
1057 if (E3.IsSame(E4)) {
1060 C3d = Surf->VIso(f1);
1061 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1065 BRepAdaptor_Curve aCurve(E3);
1066 Standard_Real AngleOld = aCurve.LastParameter();
1067 if (Angle > AngleOld)
1069 B.Range( E3, 0, Angle );
1070 TopoDS_Vertex V (TopExp::LastVertex(E3));
1071 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1072 TVlast->Tolerance( Precision::Confusion() );
1076 B.UpdateEdge(E3, C3, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1083 C3d = Surf->VIso(f1);
1084 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1088 BRepAdaptor_Curve aCurve(E3);
1089 Standard_Real AngleOld = aCurve.LastParameter();
1090 if (Angle > AngleOld)
1092 B.Range( E3, 0, Angle );
1093 TopoDS_Vertex V(TopExp::LastVertex(E3));
1094 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1095 TVlast->Tolerance( Precision::Confusion() );
1098 B.UpdateEdge(E3, C3, Surf, Loc, /*Tol3d*/Precision::Confusion());
1103 C3d = Surf->VIso(l1);
1104 E4 = BuildEdge(C3d, C4, Surf, Vl, V2, 0, Angle, /*Tol3d*/Precision::Confusion());
1108 BRepAdaptor_Curve aCurve(E4);
1109 Standard_Real AngleOld = aCurve.LastParameter();
1110 if (Angle > AngleOld)
1112 B.Range( E4, 0, Angle );
1113 TopoDS_Vertex V (TopExp::LastVertex(E4));
1114 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*)&V.TShape());
1115 TVlast->Tolerance( Precision::Confusion() );
1118 B.UpdateEdge(E4, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1123 BuildFace(Surf,E1, E3, E2, E4, EEmap,
1124 Standard_False, Standard_False,
1127 // Set the continuities.
1128 B.Continuity(E1, TopoDS::Face(F1), Result, GeomAbs_G1);
1129 B.Continuity(E2, TopoDS::Face(F2), Result, GeomAbs_G1);
1131 // Render the calculated borders.
1132 // if (!BT.Degenerated(E3))
1133 if (!BRep_Tool::Degenerated(E3))
1136 B.MakeEdge(Aux1); //Nullify
1138 // if (!BT.Degenerated(E4))
1139 if (!BRep_Tool::Degenerated(E4))
1144 // Set the orientation
1145 gp_Vec D1U, D1V, N1, N2;
1146 C1->D0( (f1+l1)/2, P2d);
1147 Surf->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1150 // C1 = BT.CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1151 C1 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1152 C1->D0( (f1+l1)/2, P2d);
1153 Handle(BRepAdaptor_HSurface) AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
1154 AS->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1157 if ( (F1.Orientation() == TopAbs_REVERSED) ^ (N1.Angle(N2)>M_PI/2) )
1158 Result.Orientation(TopAbs_REVERSED);
1159 else Result.Orientation(TopAbs_FORWARD);
1161 if (ToReverseResult)
1165 if (Affich) DBRep::Set("BoucheTrou", Result);
1168 return Standard_True;
1171 //=======================================================================
1172 //function : Substitute
1174 //=======================================================================
1175 static void Substitute(BRepTools_Substitution& aSubstitute,
1176 const TopoDS_Edge& Old,
1177 const TopoDS_Edge& New)
1179 TopTools_ListOfShape listShape;
1181 TopoDS_Vertex OldV1, OldV2, NewV1, NewV2;
1182 TopExp::Vertices( Old, OldV1, OldV2 );
1183 TopExp::Vertices( New, NewV1, NewV2 );
1185 if (!aSubstitute.IsCopied( OldV1 ))
1187 listShape.Append( NewV1.Oriented(TopAbs_FORWARD) );
1188 aSubstitute.Substitute( OldV1, listShape );
1191 if (!aSubstitute.IsCopied( OldV2 ))
1193 listShape.Append( NewV2.Oriented(TopAbs_FORWARD) );
1194 aSubstitute.Substitute( OldV2, listShape );
1197 if (!aSubstitute.IsCopied( Old ))
1199 listShape.Append( New.Oriented(TopAbs_FORWARD) );
1200 aSubstitute.Substitute( Old, listShape );
1204 //=======================================================================
1205 //Function : SetCommonEdgeInFace
1206 //Purpose : Replace an edge of the face by the corresponding edge from
1208 //=======================================================================
1210 static void SetCommonEdgeInFace(BRepTools_Substitution& aSubstitute,
1211 const TopoDS_Shape& Face,
1212 const TopoDS_Shape& Edge)
1217 Standard_Boolean done = Standard_False;
1218 // Class BRep_Tool without fields and without Constructor :
1221 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1222 Handle(Geom_Curve) Cref, C;
1223 TopLoc_Location Lref, L;
1224 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1225 const TopoDS_Edge& NewEdge = TopoDS::Edge(Edge);
1226 Cref = BRep_Tool::Curve( NewEdge, Lref, f, l );
1228 for ( ; Exp.More() && !done; Exp.Next()) {
1229 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1230 const TopoDS_Edge& OldEdge = TopoDS::Edge(Exp.Current());
1231 C = BRep_Tool::Curve(OldEdge, L, f, l);
1232 if ((Cref==C) && (Lref == L)) {
1233 done = Standard_True;
1234 Substitute( aSubstitute, OldEdge, NewEdge );
1238 if (!done) cout << "Substitution of Edge failed" << endl;
1243 //=======================================================================
1244 //Fonction : KeepEdge
1245 //Objet : Find edges of the face supported by the same Curve.
1246 //=======================================================================
1247 static void KeepEdge(const TopoDS_Shape& Face,
1248 const TopoDS_Shape& Edge,
1249 TopTools_ListOfShape& List)
1252 // Class BRep_Tool without fields and without Constructor :
1255 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1256 Handle(Geom_Curve) Cref, C;
1257 TopLoc_Location Lref, L;
1258 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1259 Cref = BRep_Tool::Curve(TopoDS::Edge(Edge), Lref, f, l);
1261 for ( ; Exp.More(); Exp.Next()) {
1262 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1263 C = BRep_Tool::Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1264 if ((Cref==C) && (Lref == L)) {
1265 List.Append(Exp.Current());
1270 //=======================================================================
1272 //Objet : Construct a vertex via an iso
1273 //=======================================================================
1274 static void BuildVertex(const Handle(Geom_Curve)& Iso,
1275 const Standard_Boolean isfirst,
1276 const Standard_Real First,
1277 const Standard_Real Last,
1278 TopoDS_Shape& Vertex)
1283 if (isfirst) val = First;
1285 B.MakeVertex(TopoDS::Vertex(Vertex),
1287 Precision::Confusion());
1290 //=======================================================================
1292 //Objet : Construct an empty edge
1293 //=======================================================================
1294 static TopoDS_Edge NullEdge(TopoDS_Shape& Vertex)
1299 Vertex.Orientation(TopAbs_FORWARD);
1301 B.Add(E, Vertex.Reversed());
1302 B.Degenerated(E, Standard_True);
1307 //=======================================================================
1309 //Objet : Construct an edge via an iso
1310 //=======================================================================
1311 static TopoDS_Edge BuildEdge(const Handle(Geom_Surface)& S,
1312 const Standard_Boolean isUiso,
1313 const Standard_Real ValIso,
1314 const TopoDS_Shape& VFirst,
1315 const TopoDS_Shape& VLast,
1316 const Standard_Real Tol)
1320 Handle(Geom_Curve) Iso;
1321 Standard_Boolean sing = Standard_False;
1323 Iso = S->UIso(ValIso);
1326 Iso = S->VIso(ValIso);
1329 if (VFirst.IsSame(VLast)) { // Singular case ?
1331 // Class BRep_Tool without fields and without Constructor :
1333 const TopoDS_Vertex& V = TopoDS::Vertex(VFirst);
1334 // Standard_Real tol = BT.Tolerance(V);
1335 Standard_Real tol = BRep_Tool::Tolerance(V);
1336 if (Tol > tol) tol = Tol;
1337 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, P);
1338 // if (P.Distance(BT.Pnt(V)) < tol) {
1339 if (P.Distance(BRep_Tool::Pnt(V)) < tol) {
1340 GeomAdaptor_Curve AC(Iso);
1341 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1346 if (sing) { // Singular case
1351 // B.UpdateEdge(E, Iso, Precision::Confusion());
1352 B.Degenerated(E, Standard_True);
1356 // Construction Via 3d
1358 // Iso = S->UIso(ValIso);
1360 Standard_Real p1, p2, p11, p12, p21, p22;
1361 Standard_Boolean fwd = Standard_False;
1362 p1 = Iso->FirstParameter();
1363 p2 = Iso->LastParameter();
1364 P1 = Iso->Value(p1);
1365 P2 = Iso->Value(p2);
1367 Standard_Real t1 = BRep_Tool::Tolerance(TopoDS::Vertex(VFirst));
1368 Standard_Real t2 = BRep_Tool::Tolerance(TopoDS::Vertex(VLast));
1372 p11 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1373 p22 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1374 p12 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1375 p21 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1377 if(p11 < p12 && p22 < p21) fwd = Standard_True;
1379 if(fwd) { //OCC500(apo)
1380 if (p11 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p11);
1381 if (p22 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p22);
1384 // Iso = S->VIso(ValIso);
1385 if (p12 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p12);
1386 if (p21 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p21);
1389 BRepLib_MakeEdge MkE;
1392 // TopoDS::Vertex(VFirst),
1393 // TopoDS::Vertex(VLast),
1394 // Iso->FirstParameter(),
1395 // Iso->LastParameter());
1398 TopoDS::Vertex(VFirst),
1399 TopoDS::Vertex(VLast),
1400 Iso->FirstParameter(),
1401 Iso->LastParameter());
1404 TopoDS::Vertex(VLast),
1405 TopoDS::Vertex(VFirst),
1406 Iso->FirstParameter(),
1407 Iso->LastParameter());
1409 // if (!MkE.IsDone()) { // Il faut peut etre permuter les Vertex
1411 // TopoDS::Vertex(VLast),
1412 // TopoDS::Vertex(VFirst),
1413 // Iso->FirstParameter(),
1414 // Iso->LastParameter());
1417 if (!MkE.IsDone()) { // Erreur de construction !!
1420 sprintf(name,"firstvertex_error");
1421 DBRep::Set(name, VFirst);
1422 sprintf(name,"lastvertex_error");
1423 DBRep::Set(name, VLast);
1424 sprintf(name,"curve3d_error");
1426 DrawTrSurf::Set(Temp,Iso);
1427 // DrawTrSurf::Set(name,Iso);
1429 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1436 Handle(Geom2d_Line) L;
1437 TopLoc_Location Loc;
1438 Standard_Real Umin, Umax, Vmin, Vmax;
1439 S->Bounds(Umin, Umax, Vmin, Vmax);
1441 //gp_Pnt2d P(ValIso, 0);
1442 gp_Pnt2d P( ValIso, Vmin - Iso->FirstParameter() );
1444 L = new (Geom2d_Line) (P, V);
1447 //gp_Pnt2d P(0., ValIso);
1448 gp_Pnt2d P( Umin -Iso->FirstParameter() , ValIso );
1450 L = new (Geom2d_Line) (P, V);
1453 B.UpdateEdge(E, L, S, Loc, Precision::Confusion());
1454 if (sing) B.Range(E, S, Loc,
1455 Iso->FirstParameter(),
1456 Iso->LastParameter());
1458 Standard_Real MaxTol = 1.e-4;
1459 Standard_Real theTol;
1460 GeomAdaptor_Curve GAiso(Iso);
1461 Handle(GeomAdaptor_HCurve) GAHiso = new GeomAdaptor_HCurve(GAiso);
1462 GeomAdaptor_Surface GAsurf(S);
1463 Handle(GeomAdaptor_HSurface) GAHsurf = new GeomAdaptor_HSurface(GAsurf);
1464 CheckSameParameter( GAHiso, L, GAHsurf, MaxTol, theTol);
1465 B.UpdateEdge(E, theTol);
1470 //=======================================================================
1472 //Objet : Complete an edge via an iso
1473 //=======================================================================
1474 static void UpdateEdge(TopoDS_Edge& E,
1475 const Handle(Geom_Surface)& S,
1476 const Standard_Boolean isUiso,
1477 const Standard_Real ValIso)
1480 Handle(Geom2d_Line) L;
1481 Handle(Geom2d_Curve) PCurve, CL;
1482 TopLoc_Location Loc;
1483 Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d;
1484 S->Bounds( UFirst, ULast, VFirst, VLast);
1486 Standard_Boolean sing = Standard_False;
1487 Handle(Geom_Curve) Iso;
1489 Iso = S->UIso(ValIso);
1492 Iso = S->VIso(ValIso);
1495 TopoDS_Vertex Vf, Vl;
1496 TopExp::Vertices(E, Vf, Vl);
1497 if (Vf.IsSame(Vl)) { // Singular case ?
1499 Standard_Real tol = BRep_Tool::Tolerance(Vf);
1500 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid);
1501 if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) {
1502 GeomAdaptor_Curve AC(Iso);
1503 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1508 gp_Pnt2d P(ValIso, 0);
1510 L = new (Geom2d_Line) (P, V);
1515 gp_Pnt2d P(0., ValIso);
1517 L = new (Geom2d_Line) (P, V);
1521 CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d);
1523 // Control direction & Range
1524 Standard_Real R, First, Last, Tol=1.e-4;
1525 Standard_Boolean reverse = Standard_False;;
1528 // Class BRep_Tool without fields and without Constructor :
1532 // BT.Range(E, First, Last);
1533 BRep_Tool::Range(E, First, Last);
1535 if (!Vf.IsSame(Vl)) {
1536 // Test distances between "FirstPoint" and "Vertex"
1537 P2d = CL->Value(F2d);
1538 POnS = S->Value(P2d.X(), P2d.Y());
1539 // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf));
1540 reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf));
1543 // Test angle between "First Tangente"
1545 gp_Vec V3d, du, dv, dC3d;
1546 BRepAdaptor_Curve C3d(E);
1548 C3d.D1(First, POnS, dC3d);
1549 CL->D1(F2d, P2d, V2d);
1550 S->D1(P2d.X(), P2d.Y(), POnS, du, dv);
1551 V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv);
1552 reverse = ( dC3d.Angle(V3d) > Tol);
1554 if (reverse ) { // Return curve 2d
1555 CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d);
1557 F2d = CL->FirstParameter();
1558 L2d = CL->LastParameter();
1563 Handle(Geom_Curve) NullCurve;
1564 B.UpdateEdge(E, NullCurve, 0.);
1565 B.Degenerated(E, Standard_True);
1566 B.Range(E, F2d, L2d);
1571 if (First != F2d || Last != L2d) {
1572 Handle(Geom2d_Curve) C2d;
1573 GeomLib::SameRange(Precision::PConfusion(), CL,
1574 F2d, L2d, First, Last,
1576 CL = new (Geom2d_TrimmedCurve)(C2d, First, Last);
1579 // Update des Vertex
1583 P2d = CL->Value(First);
1584 POnS = S->Value(P2d.X(), P2d.Y());
1585 V = TopExp::FirstVertex(E);
1586 // R = POnS.Distance(BT.Pnt(V));
1587 R = POnS.Distance(BRep_Tool::Pnt(V));
1588 B.UpdateVertex(V, R);
1590 P2d = CL->Value(Last);
1591 POnS = S->Value(P2d.X(), P2d.Y());
1592 V = TopExp::LastVertex(E);
1593 // R = POnS.Distance(BT.Pnt(V));
1594 R = POnS.Distance(BRep_Tool::Pnt(V));
1595 B.UpdateVertex(V, R);
1598 if (!sing && SameParameter(E, CL, S, Tol, R)) {
1602 PCurve = Couture(E, S, Loc);
1603 if (PCurve.IsNull())
1604 B.UpdateEdge(E, CL, S, Loc, Precision::Confusion());
1605 else { // Sewing edge
1608 if (e.Orientation() == TopAbs_REVERSED)
1609 B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion());
1611 B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion());
1614 // Attention to case not SameRange on its shapes (PRO13551)
1615 // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last);
1616 if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last);
1619 //=======================================================================
1620 // Object : Check if a surface is degenerated
1621 //=======================================================================
1622 static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S,
1623 const Standard_Real Tol)
1625 Standard_Integer Nb = 5;
1626 Standard_Boolean B = Standard_True;
1627 Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l;
1628 Standard_Integer ii;
1629 Handle(Geom_Curve) Iso;
1631 GCPnts_AbscissaPoint GC;
1633 S->Bounds(Umin, Umax, Vmin, Vmax);
1635 // Check the length of Iso-U
1636 t = (Umin + Umax)/2;
1638 S->D0(t, (Vmin+Vmax)/2, P2);
1640 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1642 for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) {
1645 GeomAdaptor_Curve AC(Iso);
1646 l = GC.Length(AC, Tol/4);
1650 if (B) return Standard_True;
1652 // Check the length of Iso-V
1653 t = (Vmin + Vmax)/2;
1655 S->D0((Umin+Umax)/2, t, P2);
1657 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1660 for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) {
1663 GeomAdaptor_Curve AC(Iso);
1664 l = GC.Length(AC, Tol/4);
1671 //=======================================================================
1672 //function : Constructeur
1674 //======================================================================
1675 BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section,
1676 const Handle(BRepFill_LocationLaw)& Location,
1677 const Standard_Boolean WithKPart) :
1678 isDone(Standard_False),
1686 SetTolerance(1.e-4);
1687 SetAngularControl();
1690 myApproxStyle = GeomFill_Location;
1691 myContinuity = GeomAbs_C2;
1694 myForceApproxC1 = Standard_False;
1697 //=======================================================================
1698 //function : SetBounds
1699 //purpose : Define start and end shapes
1700 //======================================================================
1701 void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First,
1702 const TopoDS_Wire& Last)
1707 // It is necessary to check the SameRange on its (PRO13551)
1709 Standard_Boolean issame = Standard_True;
1712 BRepTools_WireExplorer wexp;
1713 if (!FirstShape.IsNull()) {
1714 for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) {
1715 if (!BRepLib::CheckSameRange(wexp.Current())) {
1716 B.SameRange(wexp.Current(), Standard_False);
1717 B.SameParameter(wexp.Current(), Standard_False);
1719 issame = Standard_False;
1725 if (!LastShape.IsNull()) {
1726 for (wexp.Init(LastShape); wexp.More(); wexp.Next()) {
1727 if (!BRepLib::CheckSameRange(wexp.Current())) {
1728 B.SameRange(wexp.Current(), Standard_False);
1729 B.SameParameter(wexp.Current(), Standard_False);
1731 issame = Standard_False;
1739 cout<<"Sweep Warning : Edge not SameRange in the limits"<<endl;
1743 //=======================================================================
1744 //function : SetTolerance
1746 //======================================================================
1747 void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d,
1748 const Standard_Real BoundTol,
1749 const Standard_Real Tol2d,
1750 const Standard_Real TolAngular)
1753 myBoundTol = BoundTol;
1755 myTolAngular = TolAngular;
1757 //=======================================================================
1758 //function : SetAngularControl
1760 //======================================================================
1761 void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle,
1762 const Standard_Real MaxAngle)
1764 myAngMin = Max (MinAngle, Precision::Angular());
1765 myAngMax = Min (MaxAngle, 6.28);
1768 //=======================================================================
1769 //function : SetForceApproxC1
1770 //purpose : Set the flag that indicates attempt to approximate
1771 // a C1-continuous surface if a swept surface proved
1773 //=======================================================================
1774 void BRepFill_Sweep::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
1776 myForceApproxC1 = ForceApproxC1;
1779 ///=======================================================================
1780 //function : CorrectApproxParameters
1782 //=======================================================================
1783 Standard_Boolean BRepFill_Sweep::CorrectApproxParameters()
1785 TopoDS_Wire thePath = myLoc->Wire();
1786 GeomAbs_Shape NewCont = myContinuity;
1787 Standard_Integer NewSegmax = mySegmax;
1789 TopoDS_Iterator iter(thePath);
1790 for (; iter.More(); iter.Next())
1792 TopoDS_Edge anEdge = TopoDS::Edge(iter.Value());
1793 BRepAdaptor_Curve aBAcurve(anEdge);
1794 GeomAbs_Shape aContinuity = aBAcurve.Continuity();
1795 Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN);
1796 if (aContinuity < NewCont)
1797 NewCont = aContinuity;
1798 if (aNbInterv > NewSegmax)
1799 NewSegmax = aNbInterv;
1802 Standard_Boolean Corrected = Standard_False;
1803 if (NewCont != myContinuity || NewSegmax != mySegmax)
1804 Corrected = Standard_True;
1805 myContinuity = NewCont;
1806 mySegmax = NewSegmax;
1810 //=======================================================================
1811 //function : BuildWire
1812 //purpose : Construit a wire by sweeping
1813 //======================================================================
1814 Standard_Boolean BRepFill_Sweep::
1815 BuildWire(const BRepFill_TransitionStyle /*Transition*/)
1817 Standard_Integer ipath, isec = 1;
1821 // Class BRep_Tool without fields and without Constructor :
1823 Standard_Integer NbPath = myLoc->NbLaw();
1824 Standard_Boolean vclose;
1825 vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0));
1827 Handle(Geom_Surface) S;
1828 Handle(Geom_Curve) Iso;
1829 Standard_Real val, bid, First, Last, Tol;
1835 // (1) Construction of all curves
1837 // (1.1) Construction of Tables
1838 myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath);
1839 myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath);
1840 myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1);
1842 // (1.2) Calculate curves / vertex / edge
1843 for (ipath=1; ipath <=NbPath; ipath++) {
1844 // Curve by iso value
1845 GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart);
1846 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1847 Sweep.SetForceApproxC1(myForceApproxC1);
1848 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1849 if (!Sweep.IsDone())
1850 return Standard_False;
1851 S = Sweep.Surface();
1852 if (Sweep.ExchangeUV()) {
1853 if (Sweep.UReversed()) S->Bounds(First, Last, bid, val);
1854 else S->Bounds(First, Last, val, bid);
1858 if (Sweep.UReversed()) S->Bounds(bid, val, First, Last);
1859 else S->Bounds(val, bid, First, Last);
1862 // Vertex by position
1864 BuildVertex(Iso, Standard_False, First, Last,
1865 myVEdges->ChangeValue(1, ipath+1));
1868 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1));
1869 myVEdges->SetValue(1, ipath+1, V);
1871 // Tol = P1.Distance(BT.Pnt(V));
1872 Tol = P1.Distance(BRep_Tool::Pnt(V));
1873 B.UpdateVertex(V, Tol);
1876 if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape);
1877 else BuildVertex(Iso, Standard_False, First, Last,
1878 myVEdges->ChangeValue(1, NbPath+1));
1884 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath));
1885 // Tol = P1.Distance(BT.Pnt(V));
1886 Tol = P1.Distance(BRep_Tool::Pnt(V));
1887 B.UpdateVertex(V, Tol);
1890 if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape);
1891 else BuildVertex(Iso, Standard_True, First, Last,
1892 myVEdges->ChangeValue(1, 1));
1895 // Construction of the edge
1896 BRepLib_MakeEdge MkE;
1898 TopoDS::Vertex(myVEdges->Value(1, ipath)),
1899 TopoDS::Vertex(myVEdges->Value(1, ipath+1)),
1900 Iso->FirstParameter(),
1901 Iso->LastParameter());
1902 if (!MkE.IsDone()) { // Error of construction !!
1905 sprintf(name,"firstvertex_error");
1906 DBRep::Set(name, myVEdges->Value(1, ipath));
1907 sprintf(name,"lastvertex_error");
1908 DBRep::Set(name, myVEdges->Value(1, ipath+1));
1909 sprintf(name,"curve3d_error");
1911 DrawTrSurf::Set(Temp,Iso);
1912 // DrawTrSurf::Set(name,Iso);
1913 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1915 return Standard_False;
1920 sprintf(name,"Surf_%d", ipath);
1922 DrawTrSurf::Set(Temp, S);
1923 // DrawTrSurf::Set(name, S);
1924 sprintf(name,"Edge_%d", ipath);
1925 DBRep::Set(name, E);
1928 B.UpdateEdge(E, Sweep.ErrorOnSurface());
1930 myFaces->SetValue(1, ipath, E);
1933 return Standard_True;
1936 //=======================================================================
1937 //function : BuildShell
1938 //purpose : Construct a Shell by sweeping
1939 //======================================================================
1940 Standard_Boolean BRepFill_Sweep::
1941 BuildShell(const BRepFill_TransitionStyle /*Transition*/,
1942 const Standard_Integer IFirst,
1943 const Standard_Integer ILast,
1944 TopTools_MapOfShape& ReversedEdges,
1945 BRepFill_DataMapOfShapeHArray2OfShape& Tapes,
1946 const Standard_Real ExtendFirst,
1947 const Standard_Real ExtendLast)
1949 Standard_Integer ipath, isec, IPath;
1954 Standard_Integer NbPath = ILast - IFirst;
1955 Standard_Integer NbLaw = mySec->NbLaw();
1956 Standard_Boolean uclose, vclose, constSection, hasdegen = Standard_False;
1957 constSection = mySec->IsConstant();
1958 uclose = mySec->IsUClosed();
1959 vclose = (mySec->IsVClosed() && myLoc->IsClosed()) &&
1960 (NbPath == myLoc->NbLaw()) && (myLoc->IsG1(0, myTol3d)>= 0);
1963 // (1) Construction of all surfaces
1965 // (1.1) Construction of Tables
1967 TColStd_Array2OfInteger ExchUV(1, NbLaw, 1, NbPath);
1968 TColStd_Array2OfInteger UReverse(1, NbLaw, 1, NbPath);
1969 TColStd_Array2OfInteger Degenerated(1, NbLaw, 1, NbPath);
1970 Degenerated.Init(0);
1971 // No VReverse for the moment...
1972 TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath);
1973 TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath);
1975 TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath);
1976 TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1);
1977 TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1);
1979 TopoDS_Vertex VNULL;
1983 TopTools_Array1OfShape SecVertex(1, NbLaw+1);
1984 TColStd_Array1OfReal VError(1, NbLaw+1);
1985 TColStd_Array1OfReal Vi(1, NbPath+1);
1987 //Initialization of management of parametric intervals
1988 //(Case of evolutionary sections)
1989 Standard_Real Length, SecDom, SecDeb;
1990 myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length);
1991 mySec->Law(1)->GetDomain(SecDeb, SecDom);
1994 Standard_Real Lf, Ll;
1995 myLoc->CurvilinearBounds(IFirst-1, Lf, Ll);
1996 Vi(1) = SecDeb + (Ll/Length)*SecDom;
2001 // Error a priori on vertices
2003 for (isec=1; isec<=NbLaw+1; isec++) {
2004 VError(isec) = mySec->VertexTol(isec-1, 0.);
2005 SecVertex(isec) = mySec->Vertex(isec, 0.);
2010 // (1.2) Calculate surfaces
2011 for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) {
2013 GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart);
2014 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
2015 Sweep.SetForceApproxC1(myForceApproxC1);
2017 // Case of evolutionary section, definition of parametric correspondence
2018 if (!constSection) {
2019 Standard_Real lf, ll, Lf, Ll;
2020 myLoc->Law(IPath)->GetDomain(lf, ll);
2021 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2022 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2023 Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1));
2025 else //section is constant
2027 Standard_Real lf, ll, Lf, Ll;
2028 myLoc->Law(IPath)->GetDomain(lf, ll);
2029 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2030 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2033 for(isec=1; isec<=NbLaw; isec++) {
2034 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
2035 if (!Sweep.IsDone())
2036 return Standard_False;
2037 TabS(isec,ipath) = Sweep.Surface();
2038 TabErr(isec,ipath) = Sweep.ErrorOnSurface();
2039 ExchUV(isec, ipath) = Sweep.ExchangeUV();
2040 UReverse(isec, ipath) = Sweep.UReversed();
2041 if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface();
2043 if ((ipath==1)&&(ExtendFirst>0)) {
2044 Handle(Geom_BoundedSurface) BndS;
2045 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2046 GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1,
2047 Sweep.ExchangeUV(), Standard_False);
2048 TabS(isec,ipath) = BndS;
2050 if ((ipath==NbPath)&&(ExtendLast>0)){
2051 Handle(Geom_BoundedSurface) BndS;
2052 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2053 GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1,
2054 Sweep.ExchangeUV(), Standard_True);
2055 TabS(isec,ipath) = BndS;
2060 sprintf(name,"Surf_%d_%d", isec, IPath);
2062 DrawTrSurf::Set(Temp, TabS(isec,ipath));
2068 // (2) Construction of Edges
2069 Standard_Real UFirst, ULast, VFirst, VLast;
2070 Standard_Boolean exuv, singu, singv;
2071 Handle(Geom_Surface) S;
2073 // (2.0) return preexisting Edges and vertices
2075 TColStd_Array1OfBoolean IsBuilt(1, NbLaw);
2076 IsBuilt.Init(Standard_False);
2077 TopTools_Array1OfShape StartEdges(1, NbLaw);
2078 if (! FirstShape.IsNull() && (IFirst==1)) {
2079 mySec->Init(FirstShape);
2080 for (isec=1; isec<=NbLaw; isec++) {
2081 E = mySec->CurrentEdge();
2083 if (E.Orientation() == TopAbs_REVERSED)
2084 Vertex(isec+1, 1) = TopExp::FirstVertex(E);
2086 Vertex(isec+1, 1) = TopExp::LastVertex(E);
2087 UpdateVertex(IFirst-1, isec+1,
2088 TabErr(isec, 1), Vi(1), Vertex(isec+1, 1));
2090 StartEdges(isec) = E;
2091 if (Tapes.IsBound(E))
2093 IsBuilt(isec) = Standard_True;
2095 //Initialize VEdge, UEdge, Vertex and myFaces
2097 for (j = 1; j <= NbPath+1; j++)
2099 VEdge(isec, j) = Tapes(E)->Value(1, j);
2100 VEdge(isec, j).Reverse(); //direction of round is reversed
2102 Standard_Integer ifirst = isec+1, ilast = isec; //direction of round is reversed
2103 for (j = 1; j <= NbPath; j++)
2104 UEdge(ifirst, j) = Tapes(E)->Value(2, j);
2105 for (j = 1; j <= NbPath; j++)
2106 UEdge(ilast, j) = Tapes(E)->Value(3, j);
2107 for (j = 1; j <= NbPath+1; j++)
2108 Vertex(ifirst, j) = Tapes(E)->Value(4, j);
2109 for (j = 1; j <= NbPath+1; j++)
2110 Vertex(ilast, j) = Tapes(E)->Value(5, j);
2111 for (j = 1; j <= NbPath; j++)
2112 myFaces->SetValue(isec, j, Tapes(E)->Value(6, j));
2114 if (uclose && isec == 1)
2116 for (j = 1; j <= NbPath; j++)
2117 UEdge(NbLaw+1, j) = UEdge(1, j);
2118 for (j = 1; j <= NbPath+1; j++)
2119 Vertex(NbLaw+1, j) = Vertex(1, j);
2121 if (uclose && isec == NbLaw)
2123 for (j = 1; j <= NbPath; j++)
2124 UEdge(1, j) = UEdge(NbLaw+1, j);
2125 for (j = 1; j <= NbPath+1; j++)
2126 Vertex(1, j) = Vertex(NbLaw+1, j);
2131 Handle(TopTools_HArray2OfShape) EmptyArray = new TopTools_HArray2OfShape(1, 6, 1, NbPath+1);
2132 Tapes.Bind(E, EmptyArray);
2136 if (VEdge(1, 1).Orientation() == TopAbs_REVERSED)
2137 Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1)));
2139 Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1)));
2140 UpdateVertex(IFirst-1, 1,
2141 TabErr(1, 1), Vi(1), Vertex(1, 1));
2144 Standard_Real u, v, aux;
2145 Standard_Boolean ureverse;
2146 for (isec=1; isec<=NbLaw+1; isec++) {
2150 ureverse = UReverse(NbLaw, 1);
2151 exuv = ExchUV(NbLaw, 1);
2155 ureverse = UReverse(isec, 1);
2156 exuv = ExchUV(isec, 1);
2158 S->Bounds(UFirst, ULast, VFirst, VLast);
2160 // Choice of parameters
2163 aux = VFirst; VFirst = VLast; VLast = aux;
2166 aux = UFirst; UFirst = ULast; ULast = aux;
2169 if (isec!= NbLaw+1) {
2184 // construction of vertices
2185 if (Vertex(isec, 1).IsNull())
2186 B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)),
2188 mySec->VertexTol(isec-1,Vi(1)));
2191 TopLoc_Location Identity;
2192 Vertex(isec, 1).Location(Identity);
2193 B.UpdateVertex(TopoDS::Vertex(Vertex(isec, 1)),
2195 mySec->VertexTol(isec-1,Vi(1)));
2197 } //end of for (isec=1; isec<=NbLaw+1; isec++)
2199 if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) {
2200 mySec->Init(LastShape);
2201 for (isec=1; isec<=NbLaw; isec++) {
2202 E = mySec->CurrentEdge();
2203 if (VEdge(isec, NbPath+1).IsNull())
2204 VEdge(isec, NbPath+1) = E;
2206 if (Vertex(isec+1, NbPath+1).IsNull())
2208 if (VEdge(isec, NbPath+1).Orientation() == TopAbs_REVERSED)
2209 Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(isec, NbPath+1)));
2211 Vertex(isec+1, NbPath+1) = TopExp::LastVertex(TopoDS::Edge(VEdge(isec, NbPath+1)));
2213 UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath),
2214 Vi(NbPath+1), Vertex(isec+1, NbPath+1));
2217 if (Vertex(1, NbPath+1).IsNull())
2219 if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED)
2220 Vertex(1, NbPath+1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2222 Vertex(1, NbPath+1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2224 UpdateVertex(ILast-1, 1,
2225 TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 ));
2228 for (isec=1; isec<=NbLaw+1; isec++) {
2231 S = TabS(NbLaw, NbPath);
2232 ureverse = UReverse(NbLaw, NbPath);
2233 exuv = ExchUV(NbLaw, NbPath);
2236 S = TabS(isec, NbPath);
2237 ureverse = UReverse(isec, NbPath);
2238 exuv = ExchUV(isec, NbPath);
2240 S->Bounds(UFirst, ULast, VFirst, VLast);
2242 // Choice of parametres
2245 aux = VFirst; VFirst = VLast; VLast = aux;
2248 aux = UFirst; UFirst = ULast; ULast = aux;
2251 if (isec == NbLaw+1) {
2266 // construction of vertex
2267 if (Vertex(isec, NbPath+1).IsNull())
2268 B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2270 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2273 TopLoc_Location Identity;
2274 Vertex(isec, NbPath+1).Location(Identity);
2275 B.UpdateVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2277 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2279 } //end of for (isec=1; isec<=NbLaw+1; isec++)
2282 // ---------- Creation of Vertex and edge ------------
2283 ReversedEdges.Clear();
2284 for (ipath=1, IPath=IFirst; ipath<=NbPath;
2286 for (isec=1; isec <=NbLaw; isec++) {
2290 S = TabS(isec, ipath);
2291 exuv = ExchUV(isec, ipath);
2292 S->Bounds(UFirst, ULast, VFirst, VLast);
2293 if (UReverse(isec, ipath)) {
2296 aux = VFirst; VFirst = VLast; VLast = aux;
2299 aux = UFirst; UFirst = ULast; ULast = aux;
2303 // (2.1) Construction of new vertices
2305 if (ipath == 1 && Vertex(1, 1).IsNull()) {
2308 myLoc->PerformVertex(IPath-1,
2309 TopoDS::Vertex(SecVertex(1)),
2311 TopoDS::Vertex(Vertex(1, 1)));
2313 myLoc->PerformVertex(IPath-1,
2314 mySec->Vertex(1,Vi(1)),
2315 mySec->VertexTol(0,Vi(1)),
2316 TopoDS::Vertex(Vertex(1, 1)));
2318 // the first and the next column
2319 if (vclose &&(ipath == NbPath) ) {
2320 Vertex(1, ipath+1) = Vertex(1, 1);
2322 else if (Vertex(1, ipath+1).IsNull()) {
2324 myLoc->PerformVertex(IPath,
2325 TopoDS::Vertex(SecVertex(1)),
2326 TabErr(1,ipath)+VError(1),
2327 TopoDS::Vertex(Vertex(1, ipath+1)) );
2329 myLoc->PerformVertex(IPath,
2330 mySec->Vertex(1,Vi(ipath+1)),
2332 mySec->VertexTol(0,Vi(ipath+1)),
2333 TopoDS::Vertex(Vertex(1, ipath+1)));
2335 if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) {
2336 UEdge(1, ipath) = NullEdge(Vertex(1,ipath));
2342 if (uclose && (isec == NbLaw)) {
2343 Vertex(isec+1, 1) = Vertex(1, 1);
2345 else if (Vertex(isec+1, 1).IsNull()) {
2347 myLoc->PerformVertex(IPath-1,
2348 TopoDS::Vertex(SecVertex(isec+1)),
2349 TabErr(isec,1)+VError(isec+1),
2350 TopoDS::Vertex(Vertex(isec+1, 1)) );
2352 myLoc->PerformVertex(IPath-1,
2353 mySec->Vertex(isec+1,Vi(1)),
2355 mySec->VertexTol(isec,Vi(1)),
2356 TopoDS::Vertex(Vertex(isec+1, 1)) );
2358 if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) {
2359 VEdge(isec, 1) = NullEdge(Vertex(isec, 1));
2364 if (uclose && (isec == NbLaw)) {
2365 Vertex(isec+1, ipath+1) = Vertex(1, ipath+1);
2367 else if (vclose && (ipath == NbPath)) {
2368 Vertex(isec+1, ipath+1) = Vertex(isec+1, 1);
2370 else if (Vertex(isec+1, ipath+1).IsNull()) {
2372 myLoc->PerformVertex(IPath,
2373 TopoDS::Vertex(SecVertex(isec+1)),
2374 TabErr(isec, ipath)+ VError(isec+1),
2375 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2377 myLoc->PerformVertex(IPath,
2378 mySec->Vertex(isec+1,Vi(ipath+1)),
2379 TabErr(isec, ipath) +
2380 mySec->VertexTol(isec, Vi(ipath+1)),
2381 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2385 singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1));
2386 singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1));
2390 if (singu || singv) {
2391 Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath),
2392 Max(myTol3d, TabErr(isec,ipath)));
2394 if (Degenerated(isec, ipath)) {
2396 cout << "Sweep : Degenerated case" << endl;
2398 hasdegen = Standard_True;
2399 // Particular construction of edges
2400 if (UEdge(isec+1, ipath).IsNull()) {
2403 UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath));
2405 else { // Copy the previous edge
2406 UEdge(isec+1, ipath) = UEdge(isec, ipath);
2409 if (VEdge(isec, ipath+1).IsNull()) {
2412 VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1));
2414 else { // Copy the previous edge
2415 VEdge(isec, ipath+1) = VEdge(isec, ipath);
2419 else { // Construction of edges by isos
2422 UV = UFirst; UFirst = VFirst; VFirst = UV;
2423 UV = ULast ; ULast = VLast ; VLast = UV;
2427 if (isec == 1 && UEdge(1, ipath).IsNull()) {
2428 if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) {
2429 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath)));
2430 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1)));
2431 if (P1.Distance(P2) <= myTol3d)
2432 Vertex(1,ipath+1) = Vertex(1,ipath);
2434 UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst,
2439 else UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)),
2442 if (uclose && (isec==NbLaw)) {
2443 UpdateEdge(TopoDS::Edge(UEdge(1, ipath)),
2445 UEdge(isec+1, ipath) = UEdge(1, ipath);
2448 if (UEdge(isec+1, ipath).IsNull())
2449 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2450 Vertex(isec+1, ipath),
2451 Vertex(isec+1, ipath+1),
2454 UpdateEdge(TopoDS::Edge(UEdge(isec+1, ipath)), S, !exuv, ULast);
2460 TopoDS_Edge aNewFirstEdge = BuildEdge(S, exuv, VFirst,
2464 if (VEdge(isec, ipath).IsNull())
2465 VEdge(isec, ipath) = aNewFirstEdge;
2466 else //rebuild first edge
2467 RebuildTopOrBottomEdge(aNewFirstEdge,
2468 TopoDS::Edge(VEdge(isec, ipath)),
2472 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)),
2475 if (vclose && (ipath == NbPath)) {
2476 UpdateEdge(TopoDS::Edge(VEdge(isec, 1)),
2478 VEdge(isec, ipath+1) = VEdge(isec, 1);
2480 else if (VEdge(isec, ipath+1).IsNull())
2481 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2482 Vertex(isec , ipath+1),
2483 Vertex(isec+1, ipath+1),
2487 if (ipath != NbPath || vclose)
2488 UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)),
2490 else //ipath == NbPath && !vclose => rebuild last edge
2492 TopoDS_Edge aNewLastEdge = BuildEdge(S, exuv, VLast,
2493 Vertex(isec , ipath+1),
2494 Vertex(isec+1, ipath+1),
2496 RebuildTopOrBottomEdge(aNewLastEdge,
2497 TopoDS::Edge(VEdge(isec, ipath+1)),
2502 }// End of construction of edges
2505 // (3) Construction of Faces
2510 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2511 for (isec=1; isec <=NbLaw+1; isec++){
2512 sprintf(name,"uedge_%d_%d", isec, IPath);
2513 DBRep::Set(name,UEdge(isec, ipath));
2517 for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) {
2518 for (isec=1; isec <=NbLaw; isec++){
2519 sprintf(name,"vedge_%d_%d", isec, IPath);
2520 DBRep::Set(name,VEdge(isec, ipath));
2523 for (isec=1; isec <=NbLaw+1; isec++){
2524 sprintf(name,"vertex_%d_%d", isec, IPath);
2525 DBRep::Set(name,Vertex(isec, ipath));
2531 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2532 for (isec=1; isec <=NbLaw; isec++) {
2533 if (Degenerated(isec, ipath)) {
2534 if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath)))
2535 myFaces->SetValue(isec, IPath, UEdge(isec, ipath));
2537 myFaces->SetValue(isec, IPath, VEdge(isec, ipath));
2539 else if (myFaces->Value(isec, IPath).IsNull()) {
2540 BuildFace(TabS(isec,ipath),
2541 TopoDS::Edge(UEdge(isec, ipath)),
2542 TopoDS::Edge(VEdge(isec, ipath)),
2543 TopoDS::Edge(UEdge(isec+1, ipath)),
2544 TopoDS::Edge(VEdge(isec, ipath+1)),
2546 ExchUV(isec, ipath),
2547 UReverse(isec, ipath),
2549 myFaces->SetValue(isec, IPath, face);
2554 // (3.1) Reverse the faces that have been built ealier
2555 for (ipath = 1; ipath <= NbPath; ipath++)
2556 for (isec = 1; isec <= NbLaw; isec++)
2558 myFaces->ChangeValue(isec, ipath).Reverse();
2561 // (4) History and Continuity
2564 //(4.1) // Degenerated case => Sledgehammer
2565 TopoDS_Compound Comp;
2566 B.MakeCompound(Comp);
2567 for (isec=1; isec <= NbLaw+1; isec++)
2568 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2569 if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2570 if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2571 if ((ipath <= NbPath) && (isec <= NbLaw) &&
2572 (myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE))
2573 B.Add(Comp, myFaces->Value(isec, IPath));
2575 BRepLib::EncodeRegularity(Comp, myTolAngular);
2578 //(4.2) // General case => Tweezers
2579 Standard_Boolean isG1;
2583 for (isec=1; isec <= NbLaw+1; isec++) {
2585 (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1);
2586 else isG1 = Standard_False;
2587 for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) {
2588 myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2590 if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath));
2591 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2592 B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)),
2593 TopoDS::Face(myFaces->Value(isec-1, IPath)),
2599 Standard_Integer nbpath = NbPath;
2600 if (vclose) nbpath++; //Another test G1
2601 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2602 if ((ipath > 1) && (ipath <=nbpath))
2603 isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0);
2604 else isG1 = Standard_False;
2605 for (isec=1; isec <= NbLaw; isec++) {
2606 myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2608 if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1));
2609 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2610 E = TopoDS::Edge(myVEdges->Value(isec, IPath));
2611 BRepLib::EncodeRegularity(E, FF,
2612 TopoDS::Face(myFaces->Value(isec, IPath-1)),
2621 if (IFirst == 1 && !Tapes.IsEmpty()) //works only in case of single shell
2623 for (isec = 1; isec <= NbLaw; isec++)
2625 for (j = 1; j <= NbPath+1; j++)
2626 Tapes(StartEdges(isec))->SetValue(1, j, myVEdges->Value(isec, j));
2627 for (j = 1; j <= NbPath; j++)
2628 Tapes(StartEdges(isec))->SetValue(2, j, myUEdges->Value(isec, j));
2629 for (j = 1; j <= NbPath; j++)
2630 Tapes(StartEdges(isec))->SetValue(3, j, myUEdges->Value(isec+1, j));
2631 for (j = 1; j <= NbPath+1; j++)
2632 Tapes(StartEdges(isec))->SetValue(4, j, Vertex(isec, j));
2633 for (j = 1; j <= NbPath+1; j++)
2634 Tapes(StartEdges(isec))->SetValue(5, j, Vertex(isec+1, j));
2635 for (j = 1; j <= NbPath; j++)
2636 Tapes(StartEdges(isec))->SetValue(6, j, myFaces->Value(isec, j));
2640 return Standard_True;
2643 //=======================================================================
2645 //purpose : Construt the result of sweeping
2646 //======================================================================
2647 void BRepFill_Sweep::Build(TopTools_MapOfShape& ReversedEdges,
2648 BRepFill_DataMapOfShapeHArray2OfShape& Tapes,
2649 const BRepFill_TransitionStyle Transition,
2650 const GeomAbs_Shape Continuity,
2651 const GeomFill_ApproxStyle Approx,
2652 const Standard_Integer Degmax,
2653 const Standard_Integer Segmax)
2655 myContinuity = Continuity;
2656 myApproxStyle = Approx;
2660 CorrectApproxParameters();
2663 if (mySec->IsVertex()) isDone = BuildWire(Transition);
2666 Standard_Integer NbTrous = myLoc->NbHoles(myTol3d),
2667 NbPath = myLoc->NbLaw(),
2668 NbLaw = mySec->NbLaw(), ii, jj, NbPart=1;
2669 Standard_Integer ipath, isec;
2671 myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath);
2672 myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1);
2673 myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath);
2674 Handle (TopTools_HArray2OfShape) Bounds =
2675 new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2);
2677 Handle(TColStd_HArray1OfInteger) Trous;
2679 if (NbTrous>0) { // How many sub-parts ?
2680 Trous = new (TColStd_HArray1OfInteger) (1, NbTrous);
2681 myLoc->Holes(Trous->ChangeArray1());
2683 if (Trous->Value(NbTrous) == NbPath+1) NbPart--;
2685 if (NbPart == 1) { // This is done at once
2686 Standard_Real Extend = 0.0;
2687 if (NbTrous==1) Extend = EvalExtrapol(1, Transition);
2688 isDone = BuildShell(Transition,
2694 else { // This is done piece by piece
2695 Standard_Integer IFirst = 1, ILast;
2696 for (ii=1, isDone=Standard_True;
2697 ii<=NbPart && isDone; ii++) {
2698 if (ii > NbTrous) ILast = NbPath+1;
2699 else ILast = Trous->Value(ii);
2700 isDone = BuildShell(Transition,
2704 EvalExtrapol(IFirst, Transition),
2705 EvalExtrapol(ILast, Transition));
2707 Translate(myVEdges, IFirst, Bounds, 2);
2708 PerformCorner(IFirst,
2709 Transition, Bounds);
2712 Translate(myVEdges, IFirst, Bounds, 1);
2715 // Management of looping ends
2716 if ( (NbTrous>0) && (myLoc->IsClosed()) &&
2717 (Trous->Value(NbTrous) == NbPath+1) ) {
2718 Translate(myVEdges, NbPath+1, Bounds, 1);
2719 Translate(myVEdges, 1, Bounds, 2);
2720 PerformCorner(1, Transition, Bounds);
2723 // Construction of the shell
2726 for (ipath=1; ipath<=NbPath; ipath++)
2727 for (isec=1; isec <=NbLaw; isec++) {
2728 const TopoDS_Shape& face = myFaces->Value(isec, ipath);
2729 if (!face.IsNull() &&
2730 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2733 TopTools_ListIteratorOfListOfShape It(myAuxShape);
2734 for (; It.More(); It.Next()) {
2735 const TopoDS_Shape& face = It.Value();
2736 if (!face.IsNull() &&
2737 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2739 //Set common Uedges to faces
2740 BRepTools_Substitution aSubstitute;
2742 for (ii = 1; ii <= NbLaw; ii++)
2743 for (jj = 1; jj <= NbPath; jj++)
2745 SetCommonEdgeInFace(aSubstitute,
2746 myFaces->Value(ii, jj),
2747 myUEdges->Value(ii, jj));
2748 SetCommonEdgeInFace(aSubstitute,
2749 myFaces->Value(ii, jj),
2750 myUEdges->Value(ii+1, jj));
2752 if (mySec->IsUClosed())
2753 for (jj = 1; jj <= NbPath; jj++)
2754 SetCommonEdgeInFace(aSubstitute,
2755 myFaces->Value( 1, jj ),
2756 myUEdges->Value( NbLaw+1, jj));
2758 TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified );
2759 for (; mapit.More(); mapit.Next())
2761 const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key());
2762 const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value());
2763 Substitute( aSubstitute, OldEdge, NewEdge );
2765 aSubstitute.Build( shell );
2766 if (aSubstitute.IsCopied( shell )) {
2767 const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell );
2768 shell = TopoDS::Shell( listSh.First() );
2771 for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
2772 for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
2773 const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj);
2775 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2776 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2778 if(!aList.IsEmpty())
2779 myFaces->ChangeValue(ii, jj) = aList.First();
2784 for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) {
2785 for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) {
2786 const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj);
2788 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2789 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2791 if(!aList.IsEmpty())
2792 myVEdges->ChangeValue(ii, jj) = aList.First();
2797 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2798 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) {
2799 const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj);
2801 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2802 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2804 if(!aList.IsEmpty())
2805 myUEdges->ChangeValue(ii, jj) = aList.First();
2811 if (myLoc->IsClosed() && mySec->IsUClosed()) {
2813 Standard_Boolean closed = Standard_True;
2814 Standard_Integer iedge;
2815 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
2816 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE,
2817 TopAbs_FACE, EFmap);
2819 for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) {
2820 const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge));
2821 if (BRep_Tool::Degenerated(theEdge)) continue;
2822 closed = ( EFmap(iedge).Extent() > 1);
2824 shell.Closed(closed);
2831 //=======================================================================
2834 //=======================================================================
2835 Standard_Boolean BRepFill_Sweep::IsDone() const
2840 //=======================================================================
2843 //=======================================================================
2844 TopoDS_Shape BRepFill_Sweep::Shape() const
2849 //=======================================================================
2850 //function : ErrorOnSurface
2852 //=======================================================================
2853 Standard_Real BRepFill_Sweep::ErrorOnSurface() const
2858 //=======================================================================
2859 //function : SubShape
2860 //purpose : Faces obtained by sweeping
2861 //=======================================================================
2862 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const
2867 //=======================================================================
2868 //function : InterFaces
2869 //purpose : Edges obtained by sweeping
2870 //=======================================================================
2871 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const
2876 //=======================================================================
2877 //function : Sections
2878 //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings
2879 //=======================================================================
2880 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const
2885 //=======================================================================
2886 //function : PerformCorner
2887 //purpose : Trim and/or loop a corner
2888 //======================================================================
2889 void BRepFill_Sweep::PerformCorner(const Standard_Integer Index,
2890 const BRepFill_TransitionStyle Transition,
2891 const Handle(TopTools_HArray2OfShape)& Bounds)
2894 if (Transition == BRepFill_Modified) return; // Do nothing.
2896 BRepFill_TransitionStyle TheTransition = Transition;
2897 Standard_Boolean isTangent=Standard_False;
2899 Standard_Integer I1, I2, ii; //, jj;
2901 gp_Vec T1, T2, Tang, Sortant;
2903 //Handle(TopTools_HArray1OfShape) TheShape =
2904 //new TopTools_HArray1OfShape( 1, mySec->NbLaw() );
2905 // TopTools_ListIteratorOfListOfShape Iterator;
2912 I1 = myLoc->NbLaw();
2916 // Construct an axis supported by the bissectrice
2917 myLoc->Law(I1)->GetDomain(F, L);
2918 myLoc->Law(I1)->GetCurve()->D1(L, P1, T1);
2921 myLoc->Law(I2)->GetDomain(F, L);
2922 myLoc->Law(I2)->GetCurve()->D1(F, P2, T2);
2925 if (T1.Angle(T2) < myAngMin) {
2926 isTangent = Standard_True;
2929 myLoc->Law(I1)->GetDomain(F, L);
2930 myLoc->Law(I1)->D0(L, M, V);
2932 myLoc->Law(I2)->GetDomain(F, L);
2933 myLoc->Law(I2)->D0(L, M, V);
2936 if (t1.Angle(t2) < myAngMin) {
2938 cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << endl;
2945 if ((TheTransition == BRepFill_Right)
2946 && (T1.Angle(T2) > myAngMax) ) {
2947 TheTransition = BRepFill_Round;
2950 Tang = T1 + T2; //Average direction
2951 gp_Dir NormalOfBisPlane = Tang;
2954 Sortant -= Tang.Dot(Tang)*Tang;
2957 Sortant = T2-T1; //Direction input
2958 Sortant *= -1; // " " output
2959 Tang -= (Tang.Dot(T2))*T2;
2962 P1.BaryCenter(0.5, P2, 0.5);
2966 gp_Ax2 Axe (P1, N, Dx);
2967 gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane );
2969 // Construct 2 intersecting Shells
2970 Handle (TopTools_HArray2OfShape) UEdges =
2971 new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() );
2972 UEdges->ChangeArray2() = myUEdges->Array2();
2974 // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN
2975 Handle (TopTools_HArray2OfShape) aFaces =
2976 new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2);
2977 Translate(myFaces, I1, aFaces, 1);
2978 Translate(myFaces, I2, aFaces, 2);
2980 Handle (TopTools_HArray2OfShape) aUEdges =
2981 new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2);
2982 Translate(myUEdges, I1, aUEdges, 1);
2983 Translate(myUEdges, I2, aUEdges, 2);
2985 gp_Vec aNormal = T2 + T1;
2986 TopoDS_Face aPlaneF;
2988 if(aNormal.Magnitude() > gp::Resolution()) {
2989 gp_Pln pl(P1, gp_Dir(aNormal));
2990 BRepLib_MakeFace aFMaker(pl);
2992 if(aFMaker.Error() == BRepLib_FaceDone) {
2993 aPlaneF = aFMaker.Face();
2995 aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.);
2999 BRepFill_TrimShellCorner aTrim(aFaces, AxeOfBisPlane, aPlaneF);
3000 aTrim.AddBounds(Bounds);
3001 aTrim.AddUEdges(aUEdges);
3004 if (aTrim.IsDone()) {
3005 TopTools_ListOfShape listmodif;
3006 Standard_Integer iit = 0;
3008 for(iit = 0; iit < 2; iit++) {
3009 Standard_Integer II = (iit == 0) ? I1 : I2;
3011 for (ii = 1; ii <= mySec->NbLaw(); ii++) {
3012 aTrim.Modified(myFaces->Value(ii, II), listmodif);
3014 if(!listmodif.IsEmpty()) {
3015 myFaces->SetValue(ii, II, listmodif.First());
3019 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
3020 aTrim.Modified(myUEdges->Value(ii, II), listmodif);
3022 if(!listmodif.IsEmpty()) {
3023 myUEdges->SetValue(ii, II, listmodif.First());
3028 else if ((TheTransition == BRepFill_Right) ||
3029 aTrim.HasSection() ) {
3031 cout << "Fail of TrimCorner" << endl;
3033 return; // Nothing is touched
3036 if (mySec->IsUClosed())
3038 myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) );
3039 myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) );
3042 if (TheTransition == BRepFill_Round) {
3044 TopTools_ListOfShape list1, list2;
3045 TopoDS_Edge Bord1, Bord2, BordFirst;
3046 BordFirst.Nullify();
3049 Standard_Boolean HasFilling = Standard_False;
3051 for (ii=1; ii<=mySec->NbLaw(); ii++) {
3052 KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1);
3053 KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2);
3054 if (list1.Extent() == list2.Extent()) {
3055 TopTools_ListIteratorOfListOfShape It1(list1);
3056 TopTools_ListIteratorOfListOfShape It2(list2);
3058 for (; It1.More(); It1.Next(), It2.Next()) {
3059 if (HasFilling) { // Transversal choice of constraints
3060 TopoDS_Vertex VF, VL, VC;
3061 TopoDS_Edge E = TopoDS::Edge(It1.Value());
3065 TopExp::Vertices(E, VF, VL);
3066 if (!Bord1.IsNull() &&
3067 TopExp::CommonVertex(E, Bord1, VC)) {
3068 if (VC.IsSame(VF)) E1 = Bord1;
3071 if (!Bord2.IsNull() &&
3072 TopExp::CommonVertex(E, Bord2, VC)) {
3073 if (VC.IsSame(VF)) E1 = Bord2;
3076 if (!BordFirst.IsNull() &&
3077 TopExp::CommonVertex(E, BordFirst, VC)) {
3078 if (VC.IsSame(VF)) E1 = BordFirst;
3079 else E2 = BordFirst;
3086 B = Filling(It1.Value(), myFaces->Value(ii, I1),
3087 It2.Value(), myFaces->Value(ii, I2),
3088 myVEdgesModified, myTol3d, Axe, T1, Bord1, Bord2, FF);
3091 myAuxShape.Append(FF);
3092 myVEdges->ChangeValue(ii, I2) = FF;
3093 HasFilling = Standard_True;
3095 if (ii==1) BordFirst = Bord1;
3099 else cout << "PerformCorner : Unsymmetry of free border" << endl;
3107 Standard_Integer jj;
3109 DBRep::Set("TrimmedShell", TheShape);
3110 for (jj=1; jj <=myFaces->ColLength(); jj++){
3111 sprintf(name,"Tfaces_%d_%d", jj, I1);
3112 DBRep::Set(name, myFaces->Value(jj, I1));
3113 sprintf(name,"Tfaces_%d_%d", jj, I2);
3114 DBRep::Set(name, myFaces->Value(jj, I2));
3121 //=======================================================================
3122 //function : EvalExtrapol
3124 //======================================================================
3125 Standard_Real BRepFill_Sweep::
3126 EvalExtrapol(const Standard_Integer Index,
3127 const BRepFill_TransitionStyle Transition) const
3129 Standard_Real Extrap = 0.0;
3130 if (Transition == BRepFill_Right) {
3131 Standard_Integer I1, I2;
3132 if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) {
3133 if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap;
3134 I1 = myLoc->NbLaw();
3142 gp_Vec V1, V2, T1, T2;
3144 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l;
3146 myLoc->Law(I1)->GetDomain(f, l);
3147 myLoc->Law(I1)->D0(l, M1, V1);
3148 T1.SetXYZ(M1.Column(3));
3149 myLoc->Law(I2)->GetDomain(f, l);
3150 myLoc->Law(I2)->D0(f, M2, V2);
3151 T2.SetXYZ(M2.Column(3));
3153 Standard_Real alpha = T1.Angle(T2);
3154 if ((alpha > myAngMax) || (alpha < myAngMin)) {
3155 //Angle too great => No "straight" connection
3156 //Angle too small => No connection
3157 return Extrap; // = 0.0
3160 Handle(GeomFill_SectionLaw) Sec;
3161 Sec = mySec->ConcatenedLaw();
3163 //Calculating parameter U
3164 Standard_Real U, Length, SecFirst, SecLen, Lf, Ll;
3165 myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length );
3166 mySec->Law(1)->GetDomain( SecFirst, SecLen );
3168 myLoc->CurvilinearBounds( I1, Lf, Ll );
3169 U = SecFirst + (Ll/Length)*SecLen;
3172 //Box(Sec, 0., box);
3174 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3176 R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax)));
3178 // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003
3179 // Standard_Real coef = 1.2;
3180 Standard_Real coef = 2.;
3182 Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d;
3183 Extrap += R*Tan(alpha/2);
3188 //=======================================================================
3189 //function : MergeVertex
3190 //purpose : Make V2 = V1 if V2 is too close to V1
3191 //======================================================================
3192 Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1,
3193 TopoDS_Shape& V2) const
3195 // Class BRep_Tool without fields and without Constructor :
3197 const TopoDS_Vertex& v1 = TopoDS::Vertex(V1);
3198 const TopoDS_Vertex& v2 = TopoDS::Vertex(V2);
3200 // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2));
3201 tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2));
3202 if (tol < myTol3d) tol = myTol3d;
3203 // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){
3204 if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){
3206 return Standard_True;
3208 return Standard_False;
3212 //=======================================================================
3213 //function : UpdateVertex
3214 //purpose : Update the Tolerance of Vertices depending on Laws.
3215 //======================================================================
3216 void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath,
3217 const Standard_Integer isec,
3218 const Standard_Real ErrApp,
3219 const Standard_Real Param,
3220 TopoDS_Shape& V) const
3222 TopoDS_Vertex vv, TheV;
3223 TheV = TopoDS::Vertex(V);
3224 myLoc->PerformVertex(ipath,
3225 mySec->Vertex(isec, Param),
3226 ErrApp+mySec->VertexTol(isec-1, Param),
3228 // Class BRep_Tool without fields and without Constructor :
3232 P1 = BRep_Tool::Pnt(vv);
3233 // P2 = BT.Pnt(TheV);
3234 P2 = BRep_Tool::Pnt(TheV);
3236 // Standard_Real Tol = BT.Tolerance(vv);
3237 Standard_Real Tol = BRep_Tool::Tolerance(vv);
3238 Tol += P1.Distance(P2);
3240 // if (Tol > BT.Tolerance(TheV)) {
3241 if (Tol > BRep_Tool::Tolerance(TheV)) {
3243 B.UpdateVertex(TheV, Tol);
3247 //=======================================================================
3248 //function : RebuildTopOrBottomEdge
3249 //purpose : Rebuild v-iso edge of top or bottom section
3250 // inserting new 3d and 2d curves taken from swept surfaces
3251 //======================================================================
3252 void BRepFill_Sweep::RebuildTopOrBottomEdge(const TopoDS_Edge& aNewEdge,
3253 TopoDS_Edge& anEdge,
3254 TopTools_MapOfShape& ReversedEdges) const
3256 Standard_Real fpar, lpar;
3257 Handle(Geom_Curve) aNewCurve = BRep_Tool::Curve(aNewEdge, fpar, lpar);
3258 TopLoc_Location Identity;
3260 Standard_Boolean ToReverse = Standard_False;
3261 Standard_Boolean IsDegen = BRep_Tool::Degenerated(aNewEdge);
3263 BRep_Tool::Range(aNewEdge, fpar, lpar);
3266 TopoDS_Vertex V1, V2, NewV1, NewV2;
3267 TopExp::Vertices(anEdge, V1, V2);
3270 TopExp::Vertices(aNewEdge, NewV1, NewV2);
3271 V1.Location(Identity);
3272 if (!V1.IsSame(NewV1))
3274 if (V1.IsSame(NewV2))
3275 ToReverse = Standard_True;
3278 gp_Pnt Pnt1 = BRep_Tool::Pnt(V1);
3279 gp_Pnt NewPnt1 = BRep_Tool::Pnt(NewV1);
3280 Standard_Real TolSum = BRep_Tool::Tolerance(V1) + BRep_Tool::Tolerance(NewV1);
3281 if (!Pnt1.IsEqual(NewPnt1, TolSum))
3282 ToReverse = Standard_True;
3288 Standard_Real OldFirst, OldLast;
3289 Handle(Geom_Curve) OldCurve = BRep_Tool::Curve(anEdge, OldFirst, OldLast);
3290 gp_Vec OldD1, NewD1;
3292 OldCurve->D1(0.5*(OldFirst + OldLast), MidPnt, OldD1);
3293 aNewCurve->D1(0.5*(fpar + lpar), MidPnt, NewD1);
3294 if (OldD1 * NewD1 < 0.)
3295 ToReverse = Standard_True;
3299 anEdge.Location(Identity);
3300 const Handle(BRep_TEdge)& TEdge = *((Handle(BRep_TEdge)*) &anEdge.TShape());
3301 TEdge->Tolerance(BRep_Tool::Tolerance(aNewEdge));
3303 BB.Range(anEdge, fpar, lpar);
3304 BB.UpdateEdge(anEdge, aNewCurve, Precision::Confusion());
3305 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &aNewEdge.TShape());
3306 const BRep_ListOfCurveRepresentation& lcr = TE->Curves();
3307 BRep_ListIteratorOfListOfCurveRepresentation itrep(lcr);
3308 for (; itrep.More(); itrep.Next())
3310 const Handle(BRep_CurveRepresentation)& CurveRep = itrep.Value();
3311 if (CurveRep->IsCurveOnSurface())
3313 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&CurveRep);
3314 Handle(Geom2d_Curve) aPCurve = GC->PCurve();
3315 Handle(Geom_Surface) aSurf = GC->Surface();
3316 TopLoc_Location aLoc = aNewEdge.Location() * GC->Location();
3317 BB.UpdateEdge(anEdge, aPCurve, aSurf, aLoc, Precision::Confusion());
3321 anEdge.Free(Standard_True);
3322 TopoDS_Vertex V1, V2;
3323 TopExp::Vertices(anEdge, V1, V2);
3325 TopoDS_Shape anEdgeFORWARD = anEdge.Oriented(TopAbs_FORWARD);
3327 BB.Remove(anEdgeFORWARD, V1);
3328 BB.Remove(anEdgeFORWARD, V2);
3330 V1.Location(Identity);
3331 V2.Location(Identity);
3334 V2.Orientation(TopAbs_FORWARD);
3335 V1.Orientation(TopAbs_REVERSED);
3337 BB.Add(anEdgeFORWARD, V1);
3338 BB.Add(anEdgeFORWARD, V2);
3343 ReversedEdges.Add(anEdge);
3346 BB.Degenerated(anEdge, IsDegen);