1 // Created on: 1995-10-23
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <BRepOffset_Tool.ixx>
26 #include <BRepAlgo_Tool.hxx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <BRepAdaptor_Surface.hxx>
30 #include <BRepAdaptor_HCurve.hxx>
31 #include <BRepAdaptor_HSurface.hxx>
33 #include <BRepBndLib.hxx>
35 #include <Bnd_Box2d.hxx>
36 #include <BndLib_Add3dCurve.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRepLib.hxx>
39 #include <BRepLib_MakeEdge.hxx>
40 #include <BRepLib_MakeVertex.hxx>
41 #include <BRepLib_MakePolygon.hxx>
42 #include <BRepLib_MakeFace.hxx>
43 #include <BRepLib_MakeWire.hxx>
44 #include <BRepTools.hxx>
45 #include <BRepTools_WireExplorer.hxx>
47 #include <BRepTools_Modifier.hxx>
48 #include <BRepTools_TrsfModification.hxx>
49 #include <BRepTopAdaptor_FClass2d.hxx>
50 #include <BRepAdaptor_Curve.hxx>
51 #include <BRepAdaptor_Curve2d.hxx>
53 #include <IntRes2d_IntersectionPoint.hxx>
54 #include <IntRes2d_IntersectionSegment.hxx>
55 #include <Extrema_ExtPC.hxx>
58 #include <TopExp_Explorer.hxx>
60 #include <Standard_ConstructionError.hxx>
62 #include <TopOpeBRepBuild_Builder.hxx>
63 #include <TopOpeBRepDS_HDataStructure.hxx>
64 #include <TopOpeBRepDS_CurveExplorer.hxx>
65 #include <TopOpeBRep_DSFiller.hxx>
66 #include <TopOpeBRepTool_GeomTool.hxx>
67 #include <TopOpeBRep_ShapeIntersector.hxx>
68 #include <TopOpeBRep_FacesFiller.hxx>
69 #include <TopOpeBRep_GeomTool.hxx>
71 #include <TopoDS_Iterator.hxx>
72 #include <TopTools_ListIteratorOfListOfShape.hxx>
73 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
75 #include <Geom_Surface.hxx>
76 #include <Geom_RectangularTrimmedSurface.hxx>
77 #include <Geom_OffsetSurface.hxx>
78 #include <Geom_BezierSurface.hxx>
79 #include <Geom_BSplineSurface.hxx>
80 #include <Geom_ConicalSurface.hxx>
81 #include <Geom_Curve.hxx>
82 #include <Geom_Line.hxx>
83 #include <Geom_Conic.hxx>
84 #include <Geom_TrimmedCurve.hxx>
85 #include <GCPnts_QuasiUniformDeflection.hxx>
87 #include <GeomLib.hxx>
88 #include <GeomAPI.hxx>
89 #include <GeomAPI_ProjectPointOnCurve.hxx>
90 #include <Geom2d_TrimmedCurve.hxx>
91 #include <Geom2d_Line.hxx>
92 #include <Geom2d_Curve.hxx>
93 #include <Geom2d_Circle.hxx>
94 #include <Geom2d_Ellipse.hxx>
95 #include <Geom2d_Parabola.hxx>
96 #include <Geom2d_Hyperbola.hxx>
97 #include <Geom2d_BezierCurve.hxx>
98 #include <Geom2d_BSplineCurve.hxx>
100 #include <Geom2dAdaptor_Curve.hxx>
101 #include <Geom2dInt_GInter.hxx>
103 #include <GeomAdaptor_Surface.hxx>
104 #include <GeomProjLib.hxx>
105 #include <GeomInt_IntSS.hxx>
106 #include <ProjLib_ProjectedCurve.hxx>
107 #include <ProjLib_HProjectedCurve.hxx>
109 #include <ElSLib.hxx>
110 #include <ElCLib.hxx>
113 #include <gp_Pnt.hxx>
114 #include <gp_Vec.hxx>
117 #include <Precision.hxx>
118 #include <Standard_ConstructionError.hxx>
120 #include <BRep_TEdge.hxx>
121 #include <Extrema_ExtPC2d.hxx>
123 #include <Geom_SurfaceOfLinearExtrusion.hxx>
124 #include <Geom_SurfaceOfRevolution.hxx>
125 #include <GCPnts_AbscissaPoint.hxx>
127 //tma: for new boolean operation
128 #include <TopTools_SequenceOfShape.hxx>
129 #include <Geom_BSplineCurve.hxx>
130 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
131 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
132 #include <GeomConvert_ApproxCurve.hxx>
133 #include <Geom2dConvert_ApproxCurve.hxx>
134 #include <TopoDS_Compound.hxx>
135 #include <GCPnts_UniformAbscissa.hxx>
136 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
137 #include <BRep_CurveRepresentation.hxx>
139 #include <BRepOffset_ListOfInterval.hxx>
140 #include <BRepOffset_Interval.hxx>
141 #include <TColgp_Array1OfPnt2d.hxx>
142 #include <ShapeCustom_Curve2d.hxx>
143 #include <GeomAPI_ExtremaCurveCurve.hxx>
145 #include <BOPDS_DS.hxx>
146 #include <BOPAlgo_PaveFiller.hxx>
147 #include <BOPTools_AlgoTools2D.hxx>
154 Standard_Boolean AffichInter = Standard_False;
155 static Standard_Boolean AffichExtent = Standard_False;
156 static Standard_Integer NbNewEdges = 1;
157 static Standard_Integer NbFaces = 1;
158 static Standard_Integer NbFOB = 1;
159 static Standard_Integer NbFTE = 1;
160 static Standard_Integer NbExtE = 1;
162 //char* name = new char[100];
166 //=======================================================================
167 //function : EdgeVertices
169 //=======================================================================
171 void BRepOffset_Tool::EdgeVertices (const TopoDS_Edge& E,
175 if (E.Orientation() == TopAbs_REVERSED) {
176 TopExp::Vertices(E,V2,V1);
179 TopExp::Vertices(E,V1,V2);
183 //=======================================================================
184 //function : OriEdgeInFace
186 //=======================================================================
188 TopAbs_Orientation BRepOffset_Tool::OriEdgeInFace (const TopoDS_Edge& E,
189 const TopoDS_Face& F )
193 Exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
195 for (; Exp.More() ;Exp.Next()) {
196 if (Exp.Current().IsSame(E)) {
197 return Exp.Current().Orientation();
200 Standard_ConstructionError::Raise("BRepOffset_Tool::OriEdgeInFace");
201 return E.Orientation();
205 //=======================================================================
206 //function : FindPeriod
208 //=======================================================================
210 static void FindPeriod (const TopoDS_Face& F,
219 for (exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next()) {
220 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
223 const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl);
224 if (C.IsNull()) return;
225 Geom2dAdaptor_Curve PC(C,pf,pl);
226 Standard_Real i, nbp = 20;
227 if (PC.GetType() == GeomAbs_Line) nbp = 2;
228 Standard_Real step = (pl - pf) / nbp;
232 for (i = 2; i < nbp; i++) {
239 B.Get(umin,vmin,umax,vmax);
243 //=======================================================================
244 //function : PutInBounds
245 //purpose : Recadre la courbe 2d dans les bounds de la face
246 //=======================================================================
248 static void PutInBounds (const TopoDS_Face& F,
249 const TopoDS_Edge& E,
250 Handle(Geom2d_Curve)& C2d)
252 Standard_Real umin,umax,vmin,vmax;
254 BRep_Tool::Range(E,f,l);
256 TopLoc_Location L; // Recup S avec la location pour eviter la copie.
257 Handle (Geom_Surface) S = BRep_Tool::Surface(F,L);
259 if (S->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
260 S = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
265 if (!S->IsUPeriodic() && !S->IsVPeriodic()) return;
267 FindPeriod (F,umin,umax,vmin,vmax);
269 if (S->IsUPeriodic()) {
270 Standard_Real period = S->UPeriod();
271 Standard_Real eps = period*1.e-6;
272 gp_Pnt2d Pf = C2d->Value(f);
273 gp_Pnt2d Pl = C2d->Value(l);
274 gp_Pnt2d Pm = C2d->Value(0.34*f + 0.66*l);
275 Standard_Real minC = Min(Pf.X(),Pl.X()); minC = Min(minC,Pm.X());
276 Standard_Real maxC = Max(Pf.X(),Pl.X()); maxC = Max(maxC,Pm.X());
277 Standard_Real du = 0.;
278 if (minC< umin - eps) {
279 du = (int((umin - minC)/period) + 1)*period;
281 if (minC > umax + eps) {
282 du = -(int((minC - umax)/period) + 1)*period;
287 minC += du; maxC += du;
289 // Ajuste au mieux la courbe dans le domaine.
290 if (maxC > umax +100*eps) {
291 Standard_Real d1 = maxC - umax;
292 Standard_Real d2 = umin - minC + period;
293 if (d2 < d1) du =-period;
303 if (S->IsVPeriodic()) {
304 Standard_Real period = S->VPeriod();
305 Standard_Real eps = period*1.e-6;
306 gp_Pnt2d Pf = C2d->Value(f);
307 gp_Pnt2d Pl = C2d->Value(l);
308 gp_Pnt2d Pm = C2d->Value(0.34*f + 0.66*l);
309 Standard_Real minC = Min(Pf.Y(),Pl.Y()); minC = Min(minC,Pm.Y());
310 Standard_Real maxC = Max(Pf.Y(),Pl.Y()); maxC = Max(maxC,Pm.Y());
311 Standard_Real dv = 0.;
312 if (minC< vmin - eps) {
313 dv = (int((vmin - minC)/period) + 1)*period;
315 if (minC > vmax + eps) {
316 dv = -(int((minC - vmax)/period) + 1)*period;
321 minC += dv; maxC += dv;
323 // Ajuste au mieux la courbe dans le domaine.
324 if (maxC > vmax +100*eps) {
325 Standard_Real d1 = maxC - vmax;
326 Standard_Real d2 = vmin - minC + period;
327 if (d2 < d1) dv =-period;
336 //=======================================================================
339 //=======================================================================
341 Standard_Real BRepOffset_Tool::Gabarit(const Handle(Geom_Curve)& aCurve)
343 GeomAdaptor_Curve GC( aCurve );
345 BndLib_Add3dCurve::Add( GC, Precision::Confusion(), aBox );
346 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dist;
347 aBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
348 dist = Max( (aXmax-aXmin), (aYmax-aYmin) );
349 dist = Max( dist, (aZmax-aZmin) );
353 //=======================================================================
354 //function : BuildPCurves
356 //=======================================================================
358 static void BuildPCurves (const TopoDS_Edge& E,
359 const TopoDS_Face& F)
362 Handle (Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface (E,F,ff,ll);
363 if (!C2d.IsNull()) return;
365 //Standard_Real Tolerance = Max(Precision::Confusion(),BRep_Tool::Tolerance(E));
366 Standard_Real Tolerance = Precision::Confusion();
368 BRepAdaptor_Surface AS(F,0);
369 BRepAdaptor_Curve AC(E);
371 //Try to find pcurve on a bound of BSpline or Bezier surface
372 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( F );
373 Handle( Standard_Type ) typS = theSurf->DynamicType();
374 if (typS == STANDARD_TYPE(Geom_OffsetSurface))
375 typS = (*((Handle(Geom_OffsetSurface)*)&theSurf))->BasisSurface()->DynamicType();
376 if (typS == STANDARD_TYPE(Geom_BezierSurface) || typS == STANDARD_TYPE(Geom_BSplineSurface))
378 gp_Pnt fpoint = AC.Value( AC.FirstParameter() );
379 gp_Pnt lpoint = AC.Value( AC.LastParameter() );
380 TopoDS_Face theFace = BRepLib_MakeFace( theSurf, Precision::Confusion() );
381 Standard_Real U1 = 0., U2 = 0., TolProj = 1.e-4; //1.e-5;
383 TopExp_Explorer Explo;
384 Explo.Init( theFace, TopAbs_EDGE );
385 for (; Explo.More(); Explo.Next())
387 TopoDS_Edge anEdge = TopoDS::Edge( Explo.Current() );
388 BRepAdaptor_Curve aCurve( anEdge );
389 Extrema_ExtPC fextr( fpoint, aCurve );
390 if (!fextr.IsDone() || fextr.NbExt() < 1)
392 Standard_Real dist2, dist2min = RealLast();
394 for (i = 1; i <= fextr.NbExt(); i++)
396 dist2 = fextr.SquareDistance(i);
397 if (dist2 < dist2min)
400 U1 = fextr.Point(i).Parameter();
403 if (dist2min > TolProj * TolProj)
405 Extrema_ExtPC lextr( lpoint, aCurve );
406 if (!lextr.IsDone() || lextr.NbExt() <1)
408 dist2min = RealLast();
409 for (i = 1; i <= lextr.NbExt(); i++)
411 dist2 = lextr.SquareDistance(i);
412 if (dist2 < dist2min)
415 U2 = lextr.Point(i).Parameter();
418 if (dist2min <= TolProj * TolProj)
423 } // for (; Explo.More(); Explo.Current())
425 if (! theEdge.IsNull())
427 //Construction of pcurve
430 Standard_Real temp = U1;
435 C2d = BRep_Tool::CurveOnSurface( theEdge, theFace, f, l );
436 C2d = new Geom2d_TrimmedCurve( C2d, U1, U2 );
438 if (theSurf->IsUPeriodic() || theSurf->IsVPeriodic())
439 PutInBounds( F, E, C2d );
442 B.UpdateEdge( E, C2d, F, BRep_Tool::Tolerance(E) );
443 BRepLib::SameRange( E );
449 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(AS);
450 Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(AC);
452 ProjLib_ProjectedCurve Proj(HS,HC,Tolerance);
454 switch ( Proj.GetType()) {
457 C2d = new Geom2d_Line(Proj.Line());
461 C2d = new Geom2d_Circle(Proj.Circle());
464 case GeomAbs_Ellipse:
465 C2d = new Geom2d_Ellipse(Proj.Ellipse());
468 case GeomAbs_Parabola:
469 C2d = new Geom2d_Parabola(Proj.Parabola());
472 case GeomAbs_Hyperbola:
473 C2d = new Geom2d_Hyperbola(Proj.Hyperbola());
476 case GeomAbs_BezierCurve:
480 case GeomAbs_BSplineCurve:
481 C2d = Proj.BSpline();
487 if (AS.IsUPeriodic() || AS.IsVPeriodic()) {
488 PutInBounds(F,E,C2d);
492 B.UpdateEdge (E,C2d,F,BRep_Tool::Tolerance(E));
495 Standard_ConstructionError::Raise("BRepOffset_Tool::BuildPCurves");
496 cout <<"Echec ProjLib"<<endl;
500 //=======================================================================
503 //=======================================================================
505 void BRepOffset_Tool::OrientSection (const TopoDS_Edge& E,
506 const TopoDS_Face& F1,
507 const TopoDS_Face& F2,
508 TopAbs_Orientation& O1,
509 TopAbs_Orientation& O2)
515 Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1);
516 Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2);
517 Handle (Geom2d_Curve) C1 = BRep_Tool::CurveOnSurface(E,F1,f,l);
518 Handle (Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(E,F2,f,l);
519 Handle (Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
521 BRepAdaptor_Curve BAcurve( E );
523 GCPnts_AbscissaPoint AP(BAcurve,GCPnts_AbscissaPoint::Length(BAcurve)/2.0,f);
524 Standard_Real ParOnC;
527 ParOnC = AP.Parameter();
529 ParOnC = BOPTools_AlgoTools2D::IntermediatePoint(f, l);
531 gp_Vec T1 = C->DN(ParOnC,1).Transformed(L.Transformation());
532 if (T1.SquareMagnitude() > gp::Resolution()) {
536 gp_Pnt2d P = C1->Value(ParOnC);
540 S1->D1(P.X(),P.Y(),P3,D1U,D1V);
542 if (F1.Orientation() == TopAbs_REVERSED) DN1.Reverse();
544 P = C2->Value(ParOnC);
545 S2->D1(P.X(),P.Y(),P3,D1U,D1V);
547 if (F2.Orientation() == TopAbs_REVERSED) DN2.Reverse();
549 gp_Vec ProVec = DN2^T1;
550 Standard_Real Prod = DN1.Dot(ProVec);
555 O1 = TopAbs_REVERSED;
558 Prod = DN2.Dot(ProVec);
563 O2 = TopAbs_REVERSED;
565 if (F1.Orientation() == TopAbs_REVERSED) O1 = TopAbs::Reverse(O1);
566 if (F2.Orientation() == TopAbs_REVERSED) O2 = TopAbs::Reverse(O2);
569 //=======================================================================
570 //function : HasCommonShape
572 //=======================================================================
574 Standard_Boolean BRepOffset_Tool::HasCommonShapes (const TopoDS_Face& F1,
575 const TopoDS_Face& F2,
576 TopTools_ListOfShape& LE,
577 TopTools_ListOfShape& LV)
579 Standard_Boolean Common = Standard_False;
580 LE.Clear(); LV.Clear();
582 TopExp_Explorer exp1;
583 exp1.Init(F1,TopAbs_EDGE);
585 for (; exp1.More(); exp1.Next()) {
586 TopExp_Explorer exp2;
587 exp2.Init(F2,TopAbs_EDGE);
588 for (; exp2.More(); exp2.Next()) {
589 if (exp1.Current().IsSame(exp2.Current())) {
590 Common = Standard_True;
591 LE.Append(exp1.Current());
595 for (exp1.Init(F1,TopAbs_VERTEX); exp1.More(); exp1.Next()) {
596 TopExp_Explorer exp2;
597 exp2.Init(F2,TopAbs_EDGE);
598 for (exp2.Init(F2,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
599 if (exp1.Current().IsSame(exp2.Current())) {
600 Common = Standard_True;
601 LV.Append(exp1.Current());
608 //=======================================================================
611 //=======================================================================
613 static Standard_Boolean ToSmall (const Handle(Geom_Curve)& C)
615 Standard_Real Tol = 10*Precision::Confusion();
616 Standard_Real m = (C->FirstParameter()*0.668 + C->LastParameter()*0.332);
617 gp_Pnt P1 = C->Value(C->FirstParameter());
618 gp_Pnt P2 = C->Value(C->LastParameter());
619 gp_Pnt P3 = C->Value(m);
620 if (P1.Distance(P2) > Tol) return Standard_False;
621 if (P2.Distance(P3) > Tol) return Standard_False;
622 return Standard_True;
626 //=======================================================================
627 //function : IsOnSurface
629 //=======================================================================
631 static Standard_Boolean IsOnSurface(const Handle(Geom_Curve)& C,
632 const Handle(Geom_Surface)& S,
633 Standard_Real TolConf,
634 Standard_Real& TolReached)
636 Standard_Real f = C->FirstParameter();
637 Standard_Real l = C->LastParameter();
638 Standard_Integer n = 5;
639 Standard_Real du = (f-l)/(n-1);
645 GeomAdaptor_Surface AS(S);
647 switch ( AS.GetType()) {
650 gp_Ax3 Ax = AS.Plane().Position();
651 for ( Standard_Integer i = 0; i < n; i++) {
652 P = C->Value(f+i*du);
653 ElSLib::PlaneParameters(Ax,P,U,V);
654 TolReached = P.Distance(ElSLib::PlaneValue(U,V,Ax));
655 if ( TolReached > TolConf)
656 return Standard_False;
660 case GeomAbs_Cylinder:
662 gp_Ax3 Ax = AS.Cylinder().Position();
663 Standard_Real Rad = AS.Cylinder().Radius();
664 for ( Standard_Integer i = 0; i < n; i++) {
665 P = C->Value(f+i*du);
666 ElSLib::CylinderParameters(Ax,Rad,P,U,V);
667 TolReached = P.Distance(ElSLib::CylinderValue(U,V,Ax,Rad));
668 if ( TolReached > TolConf)
669 return Standard_False;
675 gp_Ax3 Ax = AS.Cone().Position();
676 Standard_Real Rad = AS.Cone().RefRadius();
677 Standard_Real Alp = AS.Cone().SemiAngle();
678 for ( Standard_Integer i = 0; i < n; i++) {
679 P = C->Value(f+i*du);
680 ElSLib::ConeParameters(Ax,Rad,Alp,P,U,V);
681 TolReached = P.Distance(ElSLib::ConeValue(U,V,Ax,Rad,Alp));
682 if ( TolReached > TolConf)
683 return Standard_False;
689 gp_Ax3 Ax = AS.Sphere().Position();
690 Standard_Real Rad = AS.Sphere().Radius();
691 for ( Standard_Integer i = 0; i < n; i++) {
692 P = C->Value(f+i*du);
693 ElSLib::SphereParameters(Ax,Rad,P,U,V);
694 TolReached = P.Distance(ElSLib::SphereValue(U,V,Ax,Rad));
695 if ( TolReached > TolConf)
696 return Standard_False;
702 gp_Ax3 Ax = AS.Torus().Position();
703 Standard_Real R1 = AS.Torus().MajorRadius();
704 Standard_Real R2 = AS.Torus().MinorRadius();
705 for ( Standard_Integer i = 0; i < n; i++) {
706 P = C->Value(f+i*du);
707 ElSLib::TorusParameters(Ax,R1,R2,P,U,V);
708 TolReached = P.Distance(ElSLib::TorusValue(U,V,Ax,R1,R2));
709 if ( TolReached > TolConf)
710 return Standard_False;
717 return Standard_False;
721 return Standard_True;
725 //=======================================================================
726 //function : PipeInter
728 //=======================================================================
730 void BRepOffset_Tool::PipeInter(const TopoDS_Face& F1,
731 const TopoDS_Face& F2,
732 TopTools_ListOfShape& L1,
733 TopTools_ListOfShape& L2,
734 const TopAbs_State Side)
739 char* name = new char[100];
740 sprintf(name,"FF_%d",NbFaces++);
742 sprintf(name,"FF_%d",NbFaces++);
747 Handle (Geom_Curve) CI;
749 TopAbs_Orientation O1,O2;
750 L1.Clear(); L2.Clear();
752 Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1);
753 Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2);
755 GeomInt_IntSS Inter (S1,S2, Precision::Confusion(),1,1,1);
757 if (Inter.IsDone()) {
758 for (Standard_Integer i = 1; i <= Inter.NbLines(); i++) {
760 if (ToSmall(CI)) continue;
761 TopoDS_Edge E = BRepLib_MakeEdge(CI);
762 if (Inter.HasLineOnS1(i)) {
763 Handle(Geom2d_Curve) C2 = Inter.LineOnS1(i);
764 PutInBounds (F1,E,C2);
765 B.UpdateEdge (E,C2,F1,BRep_Tool::Tolerance(E));
770 if (Inter.HasLineOnS2(i)) {
771 Handle(Geom2d_Curve) C2 = Inter.LineOnS2(i);
772 PutInBounds (F2,E,C2);
773 B.UpdateEdge (E,C2,F2,BRep_Tool::Tolerance(E));
778 OrientSection (E,F1,F2,O1,O2);
779 if (Side == TopAbs_OUT) {
780 O1 = TopAbs::Reverse(O1);
781 O2 = TopAbs::Reverse(O2);
783 L1.Append (E.Oriented(O1));
784 L2.Append (E.Oriented(O2));
788 char* name = new char[100];
789 sprintf(name,"EI_%d",NbNewEdges++);
790 DBRep::Set(name,E.Oriented(O1));
798 //=======================================================================
799 //function : IsAutonomVertex
800 //purpose : Checks wether a vertex is "autonom" or not
801 //=======================================================================
803 static Standard_Boolean IsAutonomVertex(const TopoDS_Shape& aVertex,
804 const TopoDS_Shape& F1,
805 const TopoDS_Shape& F2,
806 const BOPDS_PDS& pDS)
808 Standard_Integer index, indF1, indF2;
809 Standard_Integer aNbVVs, aNbEEs, aNbEFs, aInt;
811 index = pDS->Index(aVertex);
813 Standard_Integer i, i1, i2;
814 i1=pDS->NbSourceShapes();
816 for (i=i1; i<i2; ++i) {
817 const TopoDS_Shape& aSx=pDS->Shape(i);
818 if(aSx.IsSame(aVertex)) {
825 indF1 = pDS->Index(F1);
826 indF2 = pDS->Index(F2);
828 if (!pDS->IsNewShape(index)) {
829 return Standard_False;
831 //check if vertex with index "index" is not created in VV or EE or EF interference
833 BOPDS_VectorOfInterfVV& aVVs=pDS->InterfVV();
834 aNbVVs = aVVs.Extent();
835 for(aInt = 0; aInt < aNbVVs; aInt++) {
836 const BOPDS_InterfVV& aVV = aVVs(aInt);
837 if (aVV.HasIndexNew()) {
838 if (aVV.IndexNew() == index) {
839 return Standard_False;
844 BOPDS_VectorOfInterfEE& aEEs=pDS->InterfEE();
845 aNbEEs = aEEs.Extent();
846 for(aInt = 0; aInt < aNbEEs; aInt++) {
847 const BOPDS_InterfEE& aEE = aEEs(aInt);
848 IntTools_CommonPrt aCP = aEE.CommonPart();
849 if(aCP.Type() == TopAbs_VERTEX) {
850 if (aEE.IndexNew() == index) {
851 return Standard_False;
856 BOPDS_VectorOfInterfEF& aEFs=pDS->InterfEF();
857 aNbEFs = aEFs.Extent();
858 for(aInt = 0; aInt < aNbEFs; aInt++) {
859 const BOPDS_InterfEF& aEF = aEFs(aInt);
860 IntTools_CommonPrt aCP = aEF.CommonPart();
861 if(aCP.Type() == TopAbs_VERTEX) {
862 if (aEF.IndexNew() == index) {
863 return Standard_False;
867 return Standard_True;
871 //=======================================================================
872 //function : AreConnex
873 //purpose : define if two shapes are connex by a vertex (vertices)
874 //=======================================================================
876 static Standard_Boolean AreConnex(const TopoDS_Wire& W1,
877 const TopoDS_Wire& W2,
878 const TopoDS_Shape& F1,
879 const TopoDS_Shape& F2,
880 const BOPDS_PDS& pDS)
882 TopoDS_Vertex V11, V12, V21, V22;
883 TopExp::Vertices( W1, V11, V12 );
884 TopExp::Vertices( W2, V21, V22 );
886 if (V11.IsSame(V21) || V11.IsSame(V22) ||
887 V12.IsSame(V21) || V12.IsSame(V22))
889 Standard_Boolean isCV1 = V11.IsSame(V21) || V11.IsSame(V22);
890 Standard_Boolean isCV2 = V12.IsSame(V21) || V12.IsSame(V22);
891 if (isCV1 && !IsAutonomVertex(V11, F1, F2, pDS))
894 return Standard_False;
895 if (!IsAutonomVertex(V12, F1, F2, pDS))
896 return Standard_False;
898 if (!isCV1 && !IsAutonomVertex(V12, F1, F2, pDS))
899 return Standard_False;
901 TopoDS_Vertex CV = (V11.IsSame(V21) || V11.IsSame(V22))? V11 : V12;
903 TopoDS_Iterator itw( W1 );
904 for (; itw.More(); itw.Next())
906 E1 = TopoDS::Edge(itw.Value());
907 TopoDS_Vertex V1, V2;
908 TopExp::Vertices( E1, V1, V2 );
909 if (V1.IsSame(CV) || V2.IsSame(CV))
912 itw.Initialize( W2 );
913 E2 = TopoDS::Edge(itw.Value());
916 Handle(Geom_Curve) C1 = BRep_Tool::Curve( E1, f, l );
917 if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
918 C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve();
920 Handle(Geom_Curve) C2 = BRep_Tool::Curve( E2, f, l );
921 if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
922 C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve();
924 if (C1->IsInstance(STANDARD_TYPE(Geom_Line)) &&
925 C2->IsInstance(STANDARD_TYPE(Geom_Line)))
927 Handle(Geom_Line) L1 = *((Handle(Geom_Line)*) &C1);
928 gp_Ax1 Axis1 = L1->Position();
929 Handle(Geom_Line) L2 = *((Handle(Geom_Line)*) &C2);
930 gp_Ax1 Axis2 = L2->Position();
931 if (! Axis1.IsParallel( Axis2, Precision::Angular() ))
932 return Standard_False;
935 return Standard_True;
938 return Standard_False;
941 //=======================================================================
942 //function : AreClosed
943 //purpose : define if two edges are connex by two vertices
944 //=======================================================================
946 static Standard_Boolean AreClosed(const TopoDS_Edge& E1,
947 const TopoDS_Edge& E2)
949 TopoDS_Vertex V11, V12, V21, V22;
950 TopExp::Vertices( E1, V11, V12 );
951 TopExp::Vertices( E2, V21, V22 );
953 if (V11.IsSame(V21) && V12.IsSame(V22) ||
954 V11.IsSame(V22) && V12.IsSame(V21))
955 return Standard_True;
957 return Standard_False;
960 //=======================================================================
961 //function : BSplineEdges
963 //=======================================================================
965 static Standard_Boolean BSplineEdges(const TopoDS_Edge& E1,
966 const TopoDS_Edge& E2,
967 const Standard_Integer par1,
968 const Standard_Integer par2,
969 Standard_Real& angle)
971 Standard_Real first1, last1, first2, last2, Param1, Param2;
973 Handle(Geom_Curve) C1 = BRep_Tool::Curve( E1, first1, last1 );
974 if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
975 C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve();
977 Handle(Geom_Curve) C2 = BRep_Tool::Curve( E2, first2, last2 );
978 if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
979 C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve();
981 if (!C1->IsInstance(STANDARD_TYPE(Geom_BSplineCurve)) ||
982 !C2->IsInstance(STANDARD_TYPE(Geom_BSplineCurve)))
983 return Standard_False;
985 Param1 = (par1 == 0)? first1 : last1;
986 Param2 = (par2 == 0)? first2 : last2;
990 C1->D1( Param1, Pnt1, Der1 );
991 C2->D1( Param2, Pnt2, Der2 );
993 if (Der1.Magnitude() <= gp::Resolution() ||
994 Der2.Magnitude() <= gp::Resolution())
997 angle = Der1.Angle(Der2);
999 return Standard_True;
1002 //=======================================================================
1003 //function : AngleWireEdge
1005 //=======================================================================
1007 static Standard_Real AngleWireEdge(const TopoDS_Wire& aWire,
1008 const TopoDS_Edge& anEdge)
1010 TopoDS_Vertex V11, V12, V21, V22, CV;
1011 TopExp::Vertices( aWire, V11, V12 );
1012 TopExp::Vertices( anEdge, V21, V22 );
1013 CV = (V11.IsSame(V21) || V11.IsSame(V22))? V11 : V12;
1014 TopoDS_Edge FirstEdge;
1015 TopoDS_Iterator itw(aWire);
1016 for (; itw.More(); itw.Next())
1018 FirstEdge = TopoDS::Edge(itw.Value());
1019 TopoDS_Vertex v1, v2;
1020 TopExp::Vertices( FirstEdge, v1, v2 );
1021 if (v1.IsSame(CV) || v2.IsSame(CV))
1028 Standard_Real Angle;
1029 if (V11.IsSame(CV) && V21.IsSame(CV))
1031 BSplineEdges( FirstEdge, anEdge, 0, 0, Angle );
1032 Angle = M_PI - Angle;
1034 else if (V11.IsSame(CV) && V22.IsSame(CV))
1035 BSplineEdges( FirstEdge, anEdge, 0, 1, Angle );
1036 else if (V12.IsSame(CV) && V21.IsSame(CV))
1037 BSplineEdges( FirstEdge, anEdge, 1, 0, Angle );
1040 BSplineEdges( FirstEdge, anEdge, 1, 1, Angle );
1041 Angle = M_PI - Angle;
1047 //=======================================================================
1048 //function : ReconstructPCurves
1050 //=======================================================================
1052 static void ReconstructPCurves(const TopoDS_Edge& anEdge)
1055 Handle(Geom_Curve) C3d = BRep_Tool::Curve(anEdge, f, l);
1057 BRep_ListIteratorOfListOfCurveRepresentation
1058 itcr( (Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->ChangeCurves() );
1059 for (; itcr.More(); itcr.Next())
1061 Handle( BRep_CurveRepresentation ) CurveRep = itcr.Value();
1062 if (CurveRep->IsCurveOnSurface())
1064 Handle(Geom_Surface) theSurf = CurveRep->Surface();
1065 TopLoc_Location theLoc = CurveRep->Location();
1066 theLoc = anEdge.Location() * theLoc;
1067 theSurf = Handle(Geom_Surface)::DownCast
1068 (theSurf->Transformed(theLoc.Transformation()));
1069 Handle(Geom2d_Curve) ProjPCurve =
1070 GeomProjLib::Curve2d( C3d, f, l, theSurf );
1071 CurveRep->PCurve( ProjPCurve );
1076 //=======================================================================
1077 //function : ConcatPCurves
1079 //=======================================================================
1081 static Handle(Geom2d_Curve) ConcatPCurves(const TopoDS_Edge& E1,
1082 const TopoDS_Edge& E2,
1083 const TopoDS_Face& F,
1084 const Standard_Boolean After,
1085 Standard_Real& newFirst,
1086 Standard_Real& newLast)
1088 Standard_Real Tol = 1.e-7;
1089 GeomAbs_Shape Continuity = GeomAbs_C1;
1090 Standard_Integer MaxDeg = 14;
1091 Standard_Integer MaxSeg = 16;
1093 Standard_Real first1, last1, first2, last2;
1094 Handle(Geom2d_Curve) PCurve1, PCurve2, newPCurve;
1096 PCurve1 = BRep_Tool::CurveOnSurface( E1, F, first1, last1 );
1097 if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve)))
1098 PCurve1 = (*((Handle(Geom2d_TrimmedCurve)*)&PCurve1))->BasisCurve();
1100 PCurve2 = BRep_Tool::CurveOnSurface( E2, F, first2, last2 );
1101 if (PCurve2->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve)))
1102 PCurve2 = (*((Handle(Geom2d_TrimmedCurve)*)&PCurve2))->BasisCurve();
1104 if (PCurve1 == PCurve2)
1106 newPCurve = PCurve1;
1107 newFirst = Min( first1, first2 );
1108 newLast = Max( last1, last2 );
1110 else if (PCurve1->DynamicType() == PCurve2->DynamicType() &&
1111 (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Line)) ||
1112 PCurve1->IsKind(STANDARD_TYPE(Geom2d_Conic))))
1114 newPCurve = PCurve1;
1116 P1 = PCurve2->Value( first2 );
1117 P2 = PCurve2->Value( last2 );
1118 if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Line)))
1120 Handle(Geom2d_Line) Lin1 = *((Handle(Geom2d_Line)*) &PCurve1);
1121 gp_Lin2d theLin = Lin1->Lin2d();
1122 first2 = ElCLib::Parameter( theLin, P1 );
1123 last2 = ElCLib::Parameter( theLin, P2 );
1125 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Circle)))
1127 Handle(Geom2d_Circle) Circ1 = *((Handle(Geom2d_Circle)*) &PCurve1);
1128 gp_Circ2d theCirc = Circ1->Circ2d();
1129 first2 = ElCLib::Parameter( theCirc, P1 );
1130 last2 = ElCLib::Parameter( theCirc, P2 );
1132 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Ellipse)))
1134 Handle(Geom2d_Ellipse) Ell1 = *((Handle(Geom2d_Ellipse)*) &PCurve1);
1135 gp_Elips2d theElips = Ell1->Elips2d();
1136 first2 = ElCLib::Parameter( theElips, P1 );
1137 last2 = ElCLib::Parameter( theElips, P2 );
1139 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Parabola)))
1141 Handle(Geom2d_Parabola) Parab1 = *((Handle(Geom2d_Parabola)*) &PCurve1);
1142 gp_Parab2d theParab = Parab1->Parab2d();
1143 first2 = ElCLib::Parameter( theParab, P1 );
1144 last2 = ElCLib::Parameter( theParab, P2 );
1146 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Hyperbola)))
1148 Handle(Geom2d_Hyperbola) Hypr1 = *((Handle(Geom2d_Hyperbola)*) &PCurve1);
1149 gp_Hypr2d theHypr = Hypr1->Hypr2d();
1150 first2 = ElCLib::Parameter( theHypr, P1 );
1151 last2 = ElCLib::Parameter( theHypr, P2 );
1153 newFirst = Min( first1, first2 );
1154 newLast = Max( last1, last2 );
1158 Handle(Geom2d_TrimmedCurve) TC1 = new Geom2d_TrimmedCurve( PCurve1, first1, last1 );
1159 Handle(Geom2d_TrimmedCurve) TC2 = new Geom2d_TrimmedCurve( PCurve2, first2, last2 );
1160 Geom2dConvert_CompCurveToBSplineCurve Concat2d( TC1 );
1161 Concat2d.Add( TC2, Precision::Confusion(), After );
1162 newPCurve = Concat2d.BSplineCurve();
1163 if (newPCurve->Continuity() < GeomAbs_C1)
1165 Geom2dConvert_ApproxCurve Approx2d( newPCurve, Tol, Continuity, MaxSeg, MaxDeg );
1166 if (Approx2d.HasResult())
1167 newPCurve = Approx2d.Curve();
1169 newFirst = newPCurve->FirstParameter();
1170 newLast = newPCurve->LastParameter();
1176 //=======================================================================
1178 //purpose : glue two edges.
1179 //=======================================================================
1181 static TopoDS_Edge Glue(const TopoDS_Edge& E1,
1182 const TopoDS_Edge& E2,
1183 const TopoDS_Vertex& Vfirst,
1184 const TopoDS_Vertex& Vlast,
1185 const Standard_Boolean After,
1186 const TopoDS_Face& F1,
1187 const Standard_Boolean addPCurve1,
1188 const TopoDS_Face& F2,
1189 const Standard_Boolean addPCurve2)
1191 Standard_Real Tol = 1.e-7;
1192 GeomAbs_Shape Continuity = GeomAbs_C1;
1193 Standard_Integer MaxDeg = 14;
1194 Standard_Integer MaxSeg = 16;
1196 Handle(Geom_Curve) C1, C2, newCurve;
1197 Handle(Geom2d_Curve) PCurve1, PCurve2, newPCurve;
1198 Standard_Real first1, last1, first2, last2, fparam=0., lparam=0.;
1199 Standard_Boolean IsCanonic = Standard_False;
1201 C1 = BRep_Tool::Curve( E1, first1, last1 );
1202 if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1203 C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve();
1205 C2 = BRep_Tool::Curve( E2, first2, last2 );
1206 if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1207 C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve();
1212 fparam = Min( first1, first2 );
1213 lparam = Max( last1, last2 );
1215 else if (C1->DynamicType() == C2->DynamicType() &&
1216 (C1->IsInstance(STANDARD_TYPE(Geom_Line)) ||
1217 C1->IsKind(STANDARD_TYPE(Geom_Conic))))
1219 IsCanonic = Standard_True;
1224 Handle(Geom_TrimmedCurve) TC1 = new Geom_TrimmedCurve( C1, first1, last1 );
1225 Handle(Geom_TrimmedCurve) TC2 = new Geom_TrimmedCurve( C2, first2, last2 );
1226 GeomConvert_CompCurveToBSplineCurve Concat( TC1 );
1227 Concat.Add( TC2, Precision::Confusion(), After );
1228 newCurve = Concat.BSplineCurve();
1229 if (newCurve->Continuity() < GeomAbs_C1)
1231 GeomConvert_ApproxCurve Approx3d( newCurve, Tol, Continuity, MaxSeg, MaxDeg );
1232 if (Approx3d.HasResult())
1233 newCurve = Approx3d.Curve();
1235 fparam = newCurve->FirstParameter();
1236 lparam = newCurve->LastParameter();
1239 TopoDS_Edge newEdge;
1243 newEdge = BRepLib_MakeEdge( newCurve, Vfirst, Vlast );
1245 newEdge = BRepLib_MakeEdge( newCurve, Vfirst, Vlast, fparam, lparam );
1247 Standard_Real newFirst, newLast;
1250 newPCurve = ConcatPCurves( E1, E2, F1, After, newFirst, newLast );
1251 BB.UpdateEdge( newEdge, newPCurve, F1, 0. );
1252 BB.Range( newEdge, F1, newFirst, newLast );
1256 newPCurve = ConcatPCurves( E1, E2, F2, After, newFirst, newLast );
1257 BB.UpdateEdge( newEdge, newPCurve, F2, 0. );
1258 BB.Range( newEdge, F2, newFirst, newLast );
1265 //=======================================================================
1266 //function : FindNewVerticesOnBoundsOfFace
1268 //=======================================================================
1270 static void FindNewVerticesOnBoundsOfFace(const BOPDS_PDS& pDS,
1271 const TopoDS_Face& aFace,
1272 TopTools_DataMapOfShapeShape& VEmap)
1274 TopTools_IndexedMapOfShape OldVertices;
1275 TopExp::MapShapes( aFace, TopAbs_VERTEX, OldVertices );
1276 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1277 TopoDS_Vertex V1, V2;
1279 TopExp_Explorer Explo( aFace, TopAbs_EDGE );
1280 for (; Explo.More(); Explo.Next()) {
1281 const TopoDS_Shape& aE = Explo.Current();
1282 Standard_Integer nE = pDS->Index(aE);
1284 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(nE);
1285 aItLPB.Initialize(aLPB);
1286 for (; aItLPB.More(); aItLPB.Next()) {
1287 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
1288 const TopoDS_Edge& aESp = *(TopoDS_Edge*)&pDS->Shape(aPB->Edge());
1290 TopExp::Vertices( aESp, V1, V2 );
1291 if (!OldVertices.Contains( V1 )) {
1292 VEmap.Bind( V1, aE );
1295 if (!OldVertices.Contains( V2 )) {
1296 VEmap.Bind( V2, aE );
1302 //=======================================================================
1303 //function : CheckIntersFF
1305 //=======================================================================
1307 static Standard_Boolean CheckIntersFF(const BOPDS_PDS& pDS,
1308 const TopoDS_Edge& RefEdge,
1309 const TopoDS_Face& F1,
1310 const TopoDS_Face& F2,
1311 TopTools_IndexedMapOfShape& TrueEdges)
1313 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
1314 Standard_Boolean isPlane1 = Standard_False, isPlane2 = Standard_False;
1316 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F1);
1317 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1318 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1319 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1320 isPlane1 = Standard_True;
1321 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1322 isEl1 = Standard_True;
1324 aSurf = BRep_Tool::Surface(F2);
1325 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1326 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1327 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1328 isPlane2 = Standard_True;
1329 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1330 isEl2 = Standard_True;
1332 if (isPlane1 || isPlane2)
1333 return Standard_True;
1336 return Standard_True;
1338 BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF();
1339 Standard_Integer aNb = aFFs.Extent();
1340 Standard_Integer i, j, nbe = 0;
1342 TopTools_SequenceOfShape Edges;
1344 for (i = 0; i < aNb; ++i)
1346 BOPDS_InterfFF& aFFi=aFFs(i);
1347 const BOPDS_VectorOfCurve& aBCurves=aFFi.Curves();
1348 Standard_Integer aNbCurves = aBCurves.Extent();
1350 for (j = 0; j < aNbCurves; ++j)
1352 const BOPDS_Curve& aBC=aBCurves(j);
1353 const BOPDS_ListOfPaveBlock& aSectEdges = aBC.PaveBlocks();
1355 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1356 aPBIt.Initialize(aSectEdges);
1358 for (; aPBIt.More(); aPBIt.Next())
1360 const Handle(BOPDS_PaveBlock)& aPB = aPBIt.Value();
1361 Standard_Integer nSect = aPB->Edge();
1362 const TopoDS_Edge& anEdge = *(TopoDS_Edge*)&pDS->Shape(nSect);
1363 Edges.Append( anEdge );
1370 return Standard_True;
1372 //define tangents of RefEdge on start and on end
1373 BRepAdaptor_Curve cref(RefEdge);
1374 gp_Vec RefTangFirst = cref.DN(cref.FirstParameter(), 1);
1375 gp_Vec RefTangLast = cref.DN(cref.LastParameter(), 1);
1377 //find the start edge and take it from Edges
1378 TopoDS_Edge StartEdge; //, StartEonF1, StartEonF2, EndEonF1, EndEonF2;
1380 TopTools_DataMapOfShapeShape VEmapF1, VEmapF2;
1381 FindNewVerticesOnBoundsOfFace( pDS, F1, VEmapF1 );
1382 FindNewVerticesOnBoundsOfFace( pDS, F2, VEmapF2 );
1384 Standard_Real AngTol = 0.1;
1385 Standard_Boolean V1onBound = Standard_False;
1386 Standard_Boolean V2onBound = Standard_False;
1387 TopoDS_Vertex V1, V2, Vcur;
1388 gp_Vec TangFirst, TangLast, TangCur;
1389 for (i = 1; i <= Edges.Length(); i++)
1391 StartEdge = TopoDS::Edge(Edges(i));
1392 TopExp::Vertices( StartEdge, V1, V2 );
1393 V1onBound = VEmapF1.IsBound(V1) || VEmapF2.IsBound(V1); // && ?
1394 V2onBound = VEmapF1.IsBound(V2) || VEmapF2.IsBound(V2); // && ?
1395 if (V1onBound || V2onBound)
1397 BRepAdaptor_Curve CE(StartEdge);
1398 TangFirst = CE.DN( CE.FirstParameter(), 1 );
1399 TangLast = CE.DN( CE.LastParameter(), 1 );
1402 if (TangFirst.IsParallel( RefTangFirst, AngTol ) ||
1403 TangFirst.IsParallel( RefTangLast, AngTol ))
1404 break; //start edged found
1408 if (TangLast.IsParallel( RefTangLast, AngTol ) ||
1409 TangLast.IsParallel( RefTangFirst, AngTol ))
1410 break; //start edged found
1415 if (i > Edges.Length()) //start edged not found
1416 return Standard_False;
1418 if (V1onBound && V2onBound)
1420 if (TangFirst.IsParallel(RefTangFirst,AngTol) && TangLast.IsParallel(RefTangLast,AngTol) ||
1421 TangFirst.IsParallel(RefTangLast,AngTol) && TangLast.IsParallel(RefTangFirst,AngTol))
1423 TrueEdges.Add( Edges(i) );
1424 return Standard_True;
1427 return Standard_False;
1430 //StartEonF1 = (V1onBound)? VEmapF1( V1 ) : VEmapF1( V2 );
1431 //StartEonF2 = (V1onBound)? VEmapF2( V1 ) : VEmapF2( V2 );
1433 TrueEdges.Add( Edges(i) );
1435 Vcur = (V1onBound)? V2 : V1;
1436 TangCur = (V1onBound)? TangLast : TangFirst;
1440 //build the chain from StartEdge till the opposite bound of face
1443 TColStd_SequenceOfInteger Candidates;
1444 for (i = 1; i <= Edges.Length(); i++)
1446 TopoDS_Edge anEdge = TopoDS::Edge(Edges(i));
1447 TopExp::Vertices( anEdge, V1, V2 );
1448 if (V1.IsSame(Vcur) || V2.IsSame(Vcur))
1449 Candidates.Append(i);
1451 if (Candidates.IsEmpty())
1454 return Standard_False;
1457 Standard_Integer minind = 1;
1458 if (Candidates.Length() > 1)
1460 Standard_Real MinAngle = RealLast();
1461 for (i = 1; i <= Candidates.Length(); i++)
1463 TopoDS_Edge anEdge = TopoDS::Edge(Edges(Candidates(i)));
1464 TopExp::Vertices( anEdge, V1, V2 );
1465 Standard_Boolean ConnectByFirst = (Vcur.IsSame(V1))? Standard_True : Standard_False;
1466 BRepAdaptor_Curve CE(anEdge);
1467 gp_Vec aTang = (ConnectByFirst)?
1468 CE.DN( CE.FirstParameter(), 1 ) : CE.DN( CE.LastParameter(), 1 );
1469 if (!ConnectByFirst)
1471 Standard_Real anAngle = TangCur.Angle(aTang);
1472 if (anAngle < MinAngle)
1479 TopoDS_Edge CurEdge = TopoDS::Edge(Edges(Candidates(minind)));
1480 TrueEdges.Add( CurEdge );
1481 Edges.Remove(Candidates(minind));
1482 TopExp::Vertices( CurEdge, V1, V2 );
1483 Standard_Boolean ConnectByFirst = (Vcur.IsSame(V1))? Standard_True : Standard_False;
1484 Vcur = (ConnectByFirst)? V2 : V1;
1485 BRepAdaptor_Curve CE(CurEdge);
1486 TangCur = (ConnectByFirst)? CE.DN( CE.LastParameter(), 1 ) : CE.DN( CE.FirstParameter(), 1 );
1487 if (!ConnectByFirst)
1489 //check if Vcur is on bounds of faces
1490 if (VEmapF1.IsBound(Vcur) || VEmapF2.IsBound(Vcur))
1494 if (TangCur.IsParallel( RefTangFirst, AngTol ) ||
1495 TangCur.IsParallel( RefTangLast, AngTol ))
1496 return Standard_True;
1499 return Standard_False;
1502 //=======================================================================
1503 //function : AssembleEdge
1505 //=======================================================================
1507 static TopoDS_Edge AssembleEdge(const BOPDS_PDS& pDS,
1508 const TopoDS_Face& F1,
1509 const TopoDS_Face& F2,
1510 const Standard_Boolean addPCurve1,
1511 const Standard_Boolean addPCurve2,
1512 const TopTools_SequenceOfShape& EdgesForConcat)
1514 TopoDS_Edge CurEdge = TopoDS::Edge( EdgesForConcat(1) );
1515 for (Standard_Integer j = 2; j <= EdgesForConcat.Length(); j++)
1517 TopoDS_Edge anEdge = TopoDS::Edge( EdgesForConcat(j) );
1518 Standard_Boolean After = Standard_False;
1519 TopoDS_Vertex Vfirst, Vlast;
1520 if (AreClosed( CurEdge, anEdge ))
1522 TopoDS_Vertex V1, V2;
1523 TopExp::Vertices( CurEdge, V1, V2 );
1524 if (IsAutonomVertex( V1, F1, F2, pDS ))
1526 After = Standard_False;
1527 Vfirst = Vlast = V2;
1531 After = Standard_True;
1532 Vfirst = Vlast = V1;
1537 TopoDS_Vertex CV, V11, V12, V21, V22;
1538 TopExp::CommonVertex( CurEdge, anEdge, CV );
1539 TopExp::Vertices( CurEdge, V11, V12 );
1540 TopExp::Vertices( anEdge, V21, V22 );
1541 if (V11.IsSame(CV) && V21.IsSame(CV))
1546 else if (V11.IsSame(CV) && V22.IsSame(CV))
1551 else if (V12.IsSame(CV) && V21.IsSame(CV))
1561 } //end of else (open wire)
1563 TopoDS_Edge NewEdge = Glue(CurEdge, anEdge,
1564 Vfirst, Vlast, After,
1565 F1, addPCurve1, F2, addPCurve2);
1567 } //end of for (Standard_Integer j = 2; j <= EdgesForConcat.Length(); j++)
1572 //=======================================================================
1573 //function : Inter3D
1575 //=======================================================================
1577 void BRepOffset_Tool::Inter3D(const TopoDS_Face& F1,
1578 const TopoDS_Face& F2,
1579 TopTools_ListOfShape& L1,
1580 TopTools_ListOfShape& L2,
1581 const TopAbs_State Side,
1582 const TopoDS_Edge& RefEdge,
1583 const Standard_Boolean IsRefEdgeDefined)
1588 char* name = new char[100];
1589 sprintf(name,"FF_%d",NbFaces++);
1590 DBRep::Set(name,F1);
1591 sprintf(name,"FF_%d",NbFaces++);
1592 DBRep::Set(name,F2);
1596 TopoDS_Face cpF1=F1;
1597 TopoDS_Face cpF2=F2;
1598 // create 3D curves on faces
1599 BRepLib::BuildCurves3d(cpF1);
1600 BRepLib::BuildCurves3d(cpF2);
1602 BOPAlgo_PaveFiller aPF1, aPF2;
1603 BOPCol_ListOfShape aLS;
1606 aPF1.SetArguments(aLS);
1610 BOPAlgo_PaveFiller *pPF = &aPF1;
1613 TopTools_IndexedMapOfShape TrueEdges;
1614 if (IsRefEdgeDefined && !CheckIntersFF( pPF->PDS(), RefEdge, cpF1, cpF2, TrueEdges ))
1620 aPF2.SetArguments(aLS);
1623 CheckIntersFF( pPF->PDS(), RefEdge, cpF1, cpF2, TrueEdges );
1626 Standard_Boolean addPCurve1 = 1;
1627 Standard_Boolean addPCurve2 = 1;
1629 const BOPDS_PDS& pDS = pPF->PDS();
1630 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
1631 Standard_Integer aNb = aFFs.Extent();
1632 Standard_Integer i = 0, j = 0, k;
1634 L1.Clear(); L2.Clear();
1635 TopAbs_Orientation O1,O2;
1637 for (i = 0; i < aNb; i++) {
1638 BOPDS_InterfFF& aFFi=aFFs(i);
1639 const BOPDS_VectorOfCurve& aBCurves=aFFi.Curves();
1641 Standard_Integer aNbCurves = aBCurves.Extent();
1643 for (j = 0; j < aNbCurves; j++) {
1644 const BOPDS_Curve& aBC=aBCurves(j);
1645 const BOPDS_ListOfPaveBlock& aSectEdges = aBC.PaveBlocks();
1647 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1648 aPBIt.Initialize(aSectEdges);
1650 for (; aPBIt.More(); aPBIt.Next()) {
1651 const Handle(BOPDS_PaveBlock)& aPB = aPBIt.Value();
1652 Standard_Integer nSect = aPB->Edge();
1653 const TopoDS_Edge& anEdge = *(TopoDS_Edge*)&pDS->Shape(nSect);
1654 if (!TrueEdges.IsEmpty() && !TrueEdges.Contains(anEdge))
1658 const Handle(Geom_Curve)& aC3DE = BRep_Tool::Curve(anEdge, f, l);
1659 Handle(Geom_TrimmedCurve) aC3DETrim;
1662 aC3DETrim = new Geom_TrimmedCurve(aC3DE, f, l);
1665 Standard_Real aTolEdge = BRep_Tool::Tolerance(anEdge);
1667 if (!BOPTools_AlgoTools2D::HasCurveOnSurface(anEdge, cpF1)) {
1668 Handle(Geom2d_Curve) aC2d = aBC.Curve().FirstCurve2d();
1669 if(!aC3DETrim.IsNull()) {
1670 Handle(Geom2d_Curve) aC2dNew;
1672 if(aC3DE->IsPeriodic()) {
1673 BOPTools_AlgoTools2D::AdjustPCurveOnFace(cpF1, f, l, aC2d, aC2dNew);
1676 BOPTools_AlgoTools2D::AdjustPCurveOnFace(cpF1, aC3DETrim, aC2d, aC2dNew);
1680 aBB.UpdateEdge(anEdge, aC2d, cpF1, aTolEdge);
1683 if (!BOPTools_AlgoTools2D::HasCurveOnSurface(anEdge, cpF2)) {
1684 Handle(Geom2d_Curve) aC2d = aBC.Curve().SecondCurve2d();
1685 if(!aC3DETrim.IsNull()) {
1686 Handle(Geom2d_Curve) aC2dNew;
1688 if(aC3DE->IsPeriodic()) {
1689 BOPTools_AlgoTools2D::AdjustPCurveOnFace(cpF2, f, l, aC2d, aC2dNew);
1692 BOPTools_AlgoTools2D::AdjustPCurveOnFace(cpF2, aC3DETrim, aC2d, aC2dNew);
1696 aBB.UpdateEdge(anEdge, aC2d, cpF2, aTolEdge);
1699 OrientSection (anEdge, F1, F2, O1, O2);
1700 if (Side == TopAbs_OUT) {
1701 O1 = TopAbs::Reverse(O1);
1702 O2 = TopAbs::Reverse(O2);
1705 L1.Append (anEdge.Oriented(O1));
1706 L2.Append (anEdge.Oriented(O2));
1710 char* name = new char[100];
1711 sprintf(name,"EI_%d",NbNewEdges++);
1712 DBRep::Set(name,anEdge.Oriented(O1));
1720 Standard_Real aSameParTol = Precision::Confusion();
1721 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
1723 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(cpF1);
1724 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1725 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1726 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1727 addPCurve1 = Standard_False;
1728 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1729 isEl1 = Standard_True;
1731 aSurf = BRep_Tool::Surface(cpF2);
1732 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1733 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1734 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1735 addPCurve2 = Standard_False;
1736 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1737 isEl2 = Standard_True;
1739 if (L1.Extent() > 1 && (!isEl1 || !isEl2)) {
1740 TopTools_SequenceOfShape eseq;
1741 TopTools_SequenceOfShape EdgesForConcat;
1743 if (!TrueEdges.IsEmpty())
1745 for (i = TrueEdges.Extent(); i >= 1; i--)
1746 EdgesForConcat.Append( TrueEdges(i) );
1747 TopoDS_Edge theEdge =
1748 AssembleEdge( pDS, cpF1, cpF2, addPCurve1, addPCurve2, EdgesForConcat );
1749 eseq.Append(theEdge);
1754 TopTools_SequenceOfShape wseq;
1755 TopTools_SequenceOfShape edges;
1756 TopTools_ListIteratorOfListOfShape itl(L1);
1757 for (; itl.More(); itl.Next())
1758 edges.Append( itl.Value() );
1759 while (!edges.IsEmpty())
1761 TopoDS_Edge anEdge = TopoDS::Edge( edges.First() );
1762 TopoDS_Wire aWire = BRepLib_MakeWire( anEdge ), resWire;
1763 TColStd_SequenceOfInteger Candidates;
1764 for (k = 1; k <= wseq.Length(); k++)
1766 resWire = TopoDS::Wire(wseq(k));
1767 if (AreConnex( resWire, aWire, cpF1, cpF2, pDS ))
1769 Candidates.Append( 1 );
1773 if (Candidates.IsEmpty())
1775 wseq.Append( aWire );
1780 for (j = 2; j <= edges.Length(); j++)
1782 anEdge = TopoDS::Edge( edges(j) );
1783 //if (anEdge.IsSame(edges(Candidates.First())))
1785 aWire = BRepLib_MakeWire( anEdge );
1786 if (AreConnex( resWire, aWire, cpF1, cpF2, pDS ))
1787 Candidates.Append( j );
1789 Standard_Integer minind = 1;
1790 if (Candidates.Length() > 1)
1792 Standard_Real MinAngle = RealLast();
1793 for (j = 1; j <= Candidates.Length(); j++)
1795 anEdge = TopoDS::Edge( edges(Candidates(j)) );
1796 Standard_Real anAngle = AngleWireEdge( resWire, anEdge );
1797 if (anAngle < MinAngle)
1804 TopoDS_Wire NewWire = BRepLib_MakeWire( resWire, TopoDS::Edge(edges(Candidates(minind))) );
1806 edges.Remove(Candidates(minind));
1808 } //end of while (!edges.IsEmpty())
1810 for (i = 1; i <= wseq.Length(); i++)
1812 TopoDS_Wire aWire = TopoDS::Wire(wseq(i));
1813 TopTools_SequenceOfShape EdgesForConcat;
1816 TopoDS_Vertex StartVertex;
1817 TopoDS_Edge StartEdge;
1818 Standard_Boolean StartFound = Standard_False;
1819 TopTools_ListOfShape Elist;
1821 TopoDS_Iterator itw(aWire);
1822 for (; itw.More(); itw.Next())
1824 TopoDS_Edge anEdge = TopoDS::Edge(itw.Value());
1826 Elist.Append(anEdge);
1829 TopoDS_Vertex V1, V2;
1830 TopExp::Vertices( anEdge, V1, V2 );
1831 if (!IsAutonomVertex( V1, cpF1, cpF2, pDS ))
1835 StartFound = Standard_True;
1837 else if (!IsAutonomVertex( V2, cpF1, cpF2, pDS ))
1841 StartFound = Standard_True;
1844 Elist.Append(anEdge);
1846 } //end of for (; itw.More(); itw.Next())
1849 itl.Initialize(Elist);
1850 StartEdge = TopoDS::Edge(itl.Value());
1852 TopoDS_Vertex V1, V2;
1853 TopExp::Vertices( StartEdge, V1, V2 );
1856 EdgesForConcat.Append( StartEdge );
1857 while (!Elist.IsEmpty())
1859 for (itl.Initialize(Elist); itl.More(); itl.Next())
1861 TopoDS_Edge anEdge = TopoDS::Edge(itl.Value());
1862 TopoDS_Vertex V1, V2;
1863 TopExp::Vertices( anEdge, V1, V2 );
1864 if (V1.IsSame(StartVertex))
1867 EdgesForConcat.Append( anEdge );
1871 else if (V2.IsSame(StartVertex))
1874 EdgesForConcat.Append( anEdge );
1879 } //end of while (!Elist.IsEmpty())
1880 } //end of if (aWire.Closed())
1883 BRepTools_WireExplorer Wexp( aWire );
1884 for (; Wexp.More(); Wexp.Next())
1885 EdgesForConcat.Append( Wexp.Current() );
1888 TopoDS_Edge theEdge =
1889 AssembleEdge( pDS, cpF1, cpF2, addPCurve1, addPCurve2, EdgesForConcat );
1890 eseq.Append( theEdge );
1892 } //end of else (when TrueEdges is empty)
1894 if (eseq.Length() < L1.Extent())
1898 for (i = 1; i <= eseq.Length(); i++)
1900 TopoDS_Edge anEdge = TopoDS::Edge(eseq(i));
1901 BRepLib::SameParameter(anEdge, aSameParTol, Standard_True);
1902 Standard_Real EdgeTol = BRep_Tool::Tolerance(anEdge);
1904 cout<<"Tolerance of glued E = "<<EdgeTol<<endl;
1906 if (EdgeTol > 1.e-2)
1909 if (EdgeTol >= 1.e-4)
1911 ReconstructPCurves(anEdge);
1912 BRepLib::SameParameter(anEdge, aSameParTol, Standard_True);
1914 cout<<"After projection tol of E = "<<BRep_Tool::Tolerance(anEdge)<<endl;
1918 OrientSection( anEdge, F1, F2, O1, O2 );
1919 if (Side == TopAbs_OUT)
1921 O1 = TopAbs::Reverse(O1);
1922 O2 = TopAbs::Reverse(O2);
1925 L1.Append( anEdge.Oriented(O1) );
1926 L2.Append( anEdge.Oriented(O2) );
1929 } //end of if (L1.Extent() > 1)
1933 TopTools_ListIteratorOfListOfShape itl(L1);
1934 for (; itl.More(); itl.Next())
1936 const TopoDS_Edge& anEdge = TopoDS::Edge( itl.Value() );
1937 BRepLib::SameParameter(anEdge, aSameParTol, Standard_True);
1942 //=======================================================================
1943 //function : TryProject
1945 //=======================================================================
1947 Standard_Boolean BRepOffset_Tool::TryProject
1948 (const TopoDS_Face& F1,
1949 const TopoDS_Face& F2,
1950 const TopTools_ListOfShape& Edges,
1951 TopTools_ListOfShape& LInt1,
1952 TopTools_ListOfShape& LInt2,
1953 const TopAbs_State Side,
1954 const Standard_Real TolConf)
1959 char* name = new char[100];
1960 sprintf(name,"FF_%d",NbFaces++);
1961 DBRep::Set(name,F1);
1962 sprintf(name,"FF_%d",NbFaces++);
1963 DBRep::Set(name,F2);
1967 // try to find if the edges <Edges> are laying on the face F1.
1968 LInt1.Clear(); LInt2.Clear();
1969 TopTools_ListIteratorOfListOfShape it(Edges);
1970 Standard_Boolean isOk = Standard_True;
1971 Standard_Boolean Ok = Standard_True;
1972 TopAbs_Orientation O1,O2;
1973 Handle(Geom_Surface) Bouchon = BRep_Tool::Surface(F1);
1976 for ( ; it.More(); it.Next()) {
1979 TopoDS_Edge CurE = TopoDS::Edge(it.Value());
1980 Handle(Geom_Curve) C = BRep_Tool::Curve(CurE,L,f,l);
1982 BRepLib::BuildCurve3d(CurE,BRep_Tool::Tolerance(CurE));
1983 C = BRep_Tool::Curve(CurE,L,f,l);
1985 C = new Geom_TrimmedCurve(C,f,l);
1986 if ( !L.IsIdentity()) C->Transform(L);
1987 Standard_Real TolReached;
1988 isOk = IsOnSurface(C,Bouchon,TolConf,TolReached);
1991 B.UpdateEdge(CurE,TolReached);
1992 BuildPCurves(CurE,F1);
1993 OrientSection (CurE,F1,F2,O1,O2);
1994 if (Side == TopAbs_OUT) {
1995 O1 = TopAbs::Reverse(O1);
1996 O2 = TopAbs::Reverse(O2);
1998 LInt1.Append (CurE.Oriented(O1));
1999 LInt2.Append (CurE.Oriented(O2));
2003 char* name = new char[100];
2004 sprintf(name,"EI_%d",NbNewEdges++);
2005 DBRep::Set(name,CurE.Oriented(O1));
2010 Ok = Standard_False;
2016 //=======================================================================
2017 //function : InterOrExtent
2019 //=======================================================================
2021 void BRepOffset_Tool::InterOrExtent(const TopoDS_Face& F1,
2022 const TopoDS_Face& F2,
2023 TopTools_ListOfShape& L1,
2024 TopTools_ListOfShape& L2,
2025 const TopAbs_State Side)
2030 char* name = new char[100];
2031 sprintf(name,"FF_%d",NbFaces++);
2032 DBRep::Set(name,F1);
2033 sprintf(name,"FF_%d",NbFaces++);
2034 DBRep::Set(name,F2);
2038 Handle (Geom_Curve) CI;
2040 TopAbs_Orientation O1,O2;
2041 L1.Clear(); L2.Clear();
2042 Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1);
2043 Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2);
2045 if (S1->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2046 Handle(Geom_RectangularTrimmedSurface) RTS ;
2047 RTS = *((Handle(Geom_RectangularTrimmedSurface)*) &S1);
2048 if (RTS->BasisSurface()->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2049 S1 = RTS->BasisSurface();
2052 if (S2->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2053 Handle(Geom_RectangularTrimmedSurface) RTS ;
2054 RTS = *((Handle(Geom_RectangularTrimmedSurface)*) &S2);
2055 if (RTS->BasisSurface()->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2056 S2 = RTS->BasisSurface();
2060 GeomInt_IntSS Inter (S1,S2, Precision::Confusion());
2062 if (Inter.IsDone()) {
2063 for (Standard_Integer i = 1; i <= Inter.NbLines(); i++) {
2066 if (ToSmall(CI)) continue;
2067 TopoDS_Edge E = BRepLib_MakeEdge(CI);
2068 BuildPCurves (E,F1);
2069 BuildPCurves (E,F2);
2070 OrientSection (E,F1,F2,O1,O2);
2071 if (Side == TopAbs_OUT) {
2072 O1 = TopAbs::Reverse(O1);
2073 O2 = TopAbs::Reverse(O2);
2075 L1.Append (E.Oriented(O1));
2076 L2.Append (E.Oriented(O2));
2080 char* name = new char[100];
2081 sprintf(name,"EI_%d",NbNewEdges++);
2082 DBRep::Set(name,E.Oriented(O1));
2089 //=======================================================================
2090 //function : ExtentEdge
2092 //=======================================================================
2094 static void ExtentEdge(const TopoDS_Face& F,
2095 const TopoDS_Face& EF,
2096 const TopoDS_Edge& E,
2099 BRepAdaptor_Curve CE(E);
2100 GeomAbs_CurveType Type = CE.GetType();
2101 TopoDS_Shape aLocalEdge = E.EmptyCopied();
2102 NE = TopoDS::Edge(aLocalEdge);
2103 // NE = TopoDS::Edge(E.EmptyCopied());
2105 if (Type == GeomAbs_Line || Type == GeomAbs_Circle || Type == GeomAbs_Ellipse ||
2106 Type == GeomAbs_Hyperbola || Type == GeomAbs_Parabola) {
2109 // Extension en tangence jusqu'au bord de la surface.
2110 Standard_Real PMax = 1.e2;
2112 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
2113 Standard_Real umin,umax,vmin,vmax;
2115 S->Bounds(umin,umax,vmin,vmax);
2116 umin = Max(umin,-PMax);vmin = Max(vmin,-PMax);
2117 umax = Min(umax, PMax);vmax = Min(vmax, PMax);
2121 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2123 //calcul point cible . ie point d'intersection du prolongement tangent et des bords.
2126 C2d->D1(CE.FirstParameter(),P,Tang);
2127 Standard_Real tx,ty,tmin;
2128 tx = ty = Precision::Infinite();
2129 if (Abs(Tang.X()) > Precision::Confusion())
2130 tx = Min (Abs((umax - P.X())/Tang.X()), Abs((umin - P.X())/Tang.X()));
2131 if (Abs(Tang.Y()) > Precision::Confusion())
2132 ty = Min (Abs((vmax - P.Y())/Tang.Y()), Abs((vmin - P.Y())/Tang.Y()));
2135 gp_Pnt2d PF2d (P.X() - Tang.X(),P.Y() - Tang.Y());
2137 C2d->D1(CE.LastParameter(),P,Tang);
2138 tx = ty = Precision::Infinite();
2139 if (Abs(Tang.X()) > Precision::Confusion())
2140 tx = Min (Abs((umax - P.X())/Tang.X()), Abs((umin - P.X())/Tang.X()));
2141 if (Abs(Tang.Y()) > Precision::Confusion())
2142 ty = Min (Abs((vmax - P.Y())/Tang.Y()), Abs((vmin - P.Y())/Tang.Y()));
2145 gp_Pnt2d PL2d (P.X() + Tang.X(),P.Y() + Tang.Y());
2147 Handle(Geom_Curve) CC = GeomAPI::To3d(C2d,gp_Pln(gp::XOY()));
2148 gp_Pnt PF(PF2d.X(),PF2d.Y(),0.);
2149 gp_Pnt PL(PL2d.X(),PL2d.Y(),0.);
2151 Handle(Geom_BoundedCurve) ExtC = Handle(Geom_BoundedCurve)::DownCast(CC);
2152 if (ExtC.IsNull()) return;
2154 GeomLib::ExtendCurveToPoint(ExtC,PF,1,0);
2155 GeomLib::ExtendCurveToPoint(ExtC,PL,1,1);
2157 Handle(Geom2d_Curve) CNE2d = GeomAPI::To2d(ExtC,gp_Pln(gp::XOY()));
2159 //Construction de la nouvelle arrete;
2162 // B.UpdateEdge (NE,CNE2d,F,BRep_Tool::Tolerance(E));
2163 B.UpdateEdge (NE,CNE2d,EF,BRep_Tool::Tolerance(E));
2164 B.Range (NE,CNE2d->FirstParameter(), CNE2d->LastParameter());
2165 NE.Orientation(E.Orientation());
2168 char* name = new char[100];
2169 sprintf (name,"F_%d",NbExtE);
2170 DBRep::Set(name,EF);
2171 sprintf (name,"OE_%d",NbExtE);
2172 DBRep::Set (name,E);
2173 sprintf (name,"ExtE_%d",NbExtE++);
2174 DBRep::Set(name,NE);
2179 //=======================================================================
2180 //function : ProjectVertexOnEdge
2182 //=======================================================================
2184 static Standard_Boolean ProjectVertexOnEdge(TopoDS_Vertex& V,
2185 const TopoDS_Edge& E,
2186 Standard_Real TolConf)
2196 Standard_Real U = 0.;
2198 Standard_Boolean found = Standard_False;
2200 gp_Pnt P = BRep_Tool::Pnt (V);
2201 BRepAdaptor_Curve C = BRepAdaptor_Curve(E);
2202 f = C.FirstParameter(); l = C.LastParameter();
2204 if (V.Orientation() == TopAbs_FORWARD) {
2205 if (Abs(f) < Precision::Infinite()) {
2206 gp_Pnt PF = C.Value (f);
2207 if (PF.IsEqual(P,TolConf)) {
2209 found = Standard_True;
2213 if (V.Orientation() == TopAbs_REVERSED) {
2214 if (!found && Abs(l) < Precision::Infinite()) {
2215 gp_Pnt PL = C.Value (l);
2216 if (PL.IsEqual(P,TolConf)) {
2218 found = Standard_True;
2223 Extrema_ExtPC Proj(P,C);
2224 if (Proj.IsDone() && Proj.NbExt() > 0) {
2225 Standard_Real Dist2,Dist2Min = Proj.SquareDistance(1);
2226 U = Proj.Point(1).Parameter();
2227 for (Standard_Integer i = 2; i <= Proj.NbExt(); i++) {
2228 Dist2 = Proj.SquareDistance(i);
2229 if (Dist2 < Dist2Min) {
2231 U = Proj.Point(i).Parameter();
2234 found = Standard_True;
2240 Standard_Real Dist = P.Distance(C.Value(U));
2241 if (Dist > TolConf) {
2242 cout << " ProjectVertexOnEdge :distance vertex edge :"<<Dist<<endl;
2244 if (U < f - Precision::Confusion() ||
2245 U > l + Precision::Confusion()) {
2246 cout << " ProjectVertexOnEdge : hors borne :"<<endl;
2247 cout << " f = "<<f<<" l ="<<l<< " U ="<<U<<endl;
2251 cout <<"BRepOffset_Tool::ProjectVertexOnEdge Parameter no found"<<endl;
2252 if (Abs(f) < Precision::Infinite() &&
2253 Abs(l) < Precision::Infinite()) {
2261 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
2262 TopoDS_Edge EE = TopoDS::Edge(aLocalShape);
2263 aLocalShape = V.Oriented(TopAbs_INTERNAL);
2264 // TopoDS_Edge EE = TopoDS::Edge(E.Oriented(TopAbs_FORWARD));
2265 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
2266 U,EE,BRep_Tool::Tolerance(E));
2272 //=======================================================================
2273 //function : Inter2d
2275 //=======================================================================
2277 void BRepOffset_Tool::Inter2d (const TopoDS_Face& F,
2278 const TopoDS_Edge& E1,
2279 const TopoDS_Edge& E2,
2280 TopTools_ListOfShape& LV,
2281 const Standard_Real TolConf)
2285 DBRep::Set("E1",E1);
2286 DBRep::Set("E2",E2);
2291 Standard_Real fl1[2],fl2[2];
2294 // Si l edge a ete etendu les pcurves ne sont pas forcement
2300 // Construction des curves 3d si elles n existent pas
2301 // utile pour coder correctement les parametres des vertex
2302 // d intersection sur les edges.
2303 //TopLoc_Location L;
2304 //Standard_Real f,l;
2305 //Handle(Geom_Curve) C3d1 = BRep_Tool::Curve(E1,L,f,l);
2306 //if (C3d1.IsNull()) {
2307 // BRepLib::BuildCurve3d(E1,BRep_Tool::Tolerance(E1));
2309 //Handle(Geom_Curve) C3d2 = BRep_Tool::Curve(E2,L,f,l);
2310 //if (C3d2.IsNull()) {
2311 // BRepLib::BuildCurve3d(E2,BRep_Tool::Tolerance(E2));
2314 Standard_Integer NbPC1 = 1, NbPC2 = 1;
2315 if (BRep_Tool::IsClosed(E1,F)) NbPC1++;
2316 if (BRep_Tool::IsClosed(E2,F)) NbPC2++;
2318 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2319 Handle(Geom2d_Curve) C1, C2;
2320 Standard_Boolean YaSol = Standard_False;
2321 Standard_Integer itry = 0;
2323 while (!YaSol && itry < 2) {
2324 for ( Standard_Integer i = 1; i <= NbPC1 ; i++) {
2325 TopoDS_Shape aLocalEdge = E1.Reversed();
2326 if (i == 1) C1 = BRep_Tool::CurveOnSurface(E1,F,fl1[0],fl1[1]);
2327 else C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalEdge),
2329 // if (i == 1) C1 = BRep_Tool::CurveOnSurface(E1,F,fl1[0],fl1[1]);
2330 // else C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(E1.Reversed()),
2331 // F,fl1[0],fl1[1]);
2332 for ( Standard_Integer j = 1; j <= NbPC2; j++ ) {
2333 TopoDS_Shape aLocalEdge = E2.Reversed();
2334 if (j == 1) C2 = BRep_Tool::CurveOnSurface(E2,F,fl2[0],fl2[1]);
2335 else C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalEdge),
2337 // if (j == 1) C2 = BRep_Tool::CurveOnSurface(E2,F,fl2[0],fl2[1]);
2338 // else C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(E2.Reversed()),
2339 // F,fl2[0],fl2[1]);
2341 if (C1.IsNull() || C2.IsNull()) {
2342 cout <<"Inter2d : Pas de pcurve"<<endl;
2344 DBRep::Set("E1",E1);
2345 DBRep::Set("E2",E2);
2351 Standard_Real U1 = 0.,U2 = 0.;
2354 fl1[0] = C1->FirstParameter(); fl1[1] = C1->LastParameter();
2355 fl2[0] = C2->FirstParameter(); fl2[1] = C2->LastParameter();
2357 Geom2dAdaptor_Curve AC1(C1,fl1[0],fl1[1]);
2358 Geom2dAdaptor_Curve AC2(C2,fl2[0],fl2[1]);
2361 gp_Pnt2d P1[2],P2[2];
2362 P1[0] = C1->Value(fl1[0]); P1[1] = C1->Value(fl1[1]);
2363 P2[0] = C2->Value(fl2[0]); P2[1] = C2->Value(fl2[1]);
2365 Standard_Integer i1 ;
2366 for ( i1 = 0; i1 < 2; i1++) {
2367 for (Standard_Integer i2 = 0; i2 < 2; i2++) {
2368 if (Abs(fl1[i1]) < Precision::Infinite() &&
2369 Abs(fl2[i2]) < Precision::Infinite() ) {
2370 if (P1[i1].IsEqual(P2[i2],TolConf)) {
2371 YaSol = Standard_True;
2372 U1 = fl1[i1]; U2 = fl2[i2];
2373 P2d = C1->Value(U1);
2379 for (i1 = 0; i1 < 2; i1++)
2381 Extrema_ExtPC2d extr( P1[i1], AC2 );
2382 if (extr.IsDone() && extr.NbExt() > 0)
2384 Standard_Real Dist2, Dist2Min = extr.SquareDistance(1);
2385 Standard_Integer IndexMin = 1;
2386 for (Standard_Integer ind = 2; ind <= extr.NbExt(); ind++)
2388 Dist2 = extr.SquareDistance(ind);
2389 if (Dist2 < Dist2Min)
2395 if (Dist2Min <= Precision::SquareConfusion())
2397 YaSol = Standard_True;
2400 U2 = (extr.Point(IndexMin)).Parameter();
2406 for (Standard_Integer i2 = 0; i2 < 2; i2++)
2408 Extrema_ExtPC2d extr( P2[i2], AC1 );
2409 if (extr.IsDone() && extr.NbExt() > 0)
2411 Standard_Real Dist2, Dist2Min = extr.SquareDistance(1);
2412 Standard_Integer IndexMin = 1;
2413 for (Standard_Integer ind = 2; ind <= extr.NbExt(); ind++)
2415 Dist2 = extr.SquareDistance(ind);
2416 if (Dist2 < Dist2Min)
2422 if (Dist2Min <= Precision::SquareConfusion())
2424 YaSol = Standard_True;
2427 U1 = (extr.Point(IndexMin)).Parameter();
2435 Geom2dInt_GInter Inter (AC1,AC2,TolConf,TolConf);
2437 if (!Inter.IsEmpty() && Inter.NbPoints() > 0) {
2438 YaSol = Standard_True;
2439 U1 = Inter.Point(1).ParamOnFirst();
2440 U2 = Inter.Point(1).ParamOnSecond();
2441 P2d = Inter.Point(1).Value();
2443 else if (!Inter.IsEmpty() && Inter.NbSegments() > 0) {
2444 YaSol = Standard_True;
2445 IntRes2d_IntersectionSegment Seg = Inter.Segment(1);
2446 IntRes2d_IntersectionPoint IntP1 = Seg.FirstPoint();
2447 IntRes2d_IntersectionPoint IntP2 = Seg.LastPoint();
2448 Standard_Real U1on1 = IntP1.ParamOnFirst();
2449 Standard_Real U1on2 = IntP2.ParamOnFirst();
2450 Standard_Real U2on1 = IntP1.ParamOnSecond();
2451 Standard_Real U2on2 = IntP2.ParamOnSecond();
2453 cout << " BRepOffset_Tool::Inter2d SEGMENT d intersection" << endl;
2454 cout << " ===> Parametres sur Curve1 : ";
2455 cout << U1on1 << " " << U1on2 << endl;
2456 cout << " ===> Parametres sur Curve2 : ";
2457 cout << U2on1 << " " << U2on2 << endl;
2459 U1 = (U1on1 + U1on2)/2.;
2460 U2 = (U2on1 + U2on2)/2.;
2461 gp_Pnt2d P2d1 = C1->Value(U1);
2462 gp_Pnt2d P2d2 = C2->Value(U2);
2463 P2d.SetX( (P2d1.X() + P2d2.X()) / 2.);
2464 P2d.SetY( (P2d1.Y() + P2d2.Y()) / 2.);
2468 gp_Pnt P = S->Value(P2d.X(),P2d.Y());
2469 TopoDS_Vertex V = BRepLib_MakeVertex(P);
2470 V.Orientation(TopAbs_INTERNAL);
2471 TopoDS_Shape aLocalEdge = E1.Oriented(TopAbs_FORWARD);
2472 B.UpdateVertex(V,U1,TopoDS::Edge(aLocalEdge),TolConf);
2473 aLocalEdge = E2.Oriented(TopAbs_FORWARD);
2474 B.UpdateVertex(V,U2,TopoDS::Edge(aLocalEdge),TolConf);
2475 // B.UpdateVertex(V,U1,TopoDS::Edge(E1.Oriented(TopAbs_FORWARD)),TolConf);
2476 // B.UpdateVertex(V,U2,TopoDS::Edge(E2.Oriented(TopAbs_FORWARD)),TolConf);
2484 if (LV.Extent() > 1) {
2485 //------------------------------------------------
2486 // garde seulement les vertex les plus proches du
2487 //debut et de la fin.
2488 //------------------------------------------------
2489 TopTools_ListIteratorOfListOfShape it(LV);
2490 TopoDS_Vertex VF,VL;
2491 Standard_Real UMin = Precision::Infinite();
2492 Standard_Real UMax = -Precision::Infinite();
2495 for ( ; it.More(); it.Next()) {
2496 TopoDS_Vertex CV = TopoDS::Vertex(it.Value());
2497 TopoDS_Shape aLocalEdge = E1.Oriented(TopAbs_FORWARD);
2498 U = BRep_Tool::Parameter(CV,TopoDS::Edge(aLocalEdge));
2499 // U = BRep_Tool::Parameter(CV,TopoDS::Edge(E1.Oriented(TopAbs_FORWARD)));
2507 LV.Clear();LV.Append(VF); LV.Append(VL);
2512 cout <<"Inter2d : Pas de solution"<<endl;
2514 DBRep::Set("E1",E1);
2515 DBRep::Set("E2",E2);
2522 //=======================================================================
2523 //function : SelectEdge
2525 //=======================================================================
2527 static void SelectEdge (const TopoDS_Face& /*F*/,
2528 const TopoDS_Face& /*EF*/,
2529 const TopoDS_Edge& E,
2530 TopTools_ListOfShape& LInt)
2532 //------------------------------------------------------------
2533 // detrompeur sur les intersections sur les faces periodiques
2534 //------------------------------------------------------------
2535 TopTools_ListIteratorOfListOfShape it(LInt);
2536 Standard_Real dU = 1.0e100;
2539 Standard_Real Fst, Lst, tmp;
2540 BRep_Tool::Range(E, Fst, Lst);
2541 BRepAdaptor_Curve Ad1(E);
2543 gp_Pnt PFirst = Ad1.Value( Fst );
2544 gp_Pnt PLast = Ad1.Value( Lst );
2546 //----------------------------------------------------------------------
2547 // Selection de l edge qui couvre le plus le domaine de l edge initiale.
2548 //----------------------------------------------------------------------
2549 for (; it.More(); it.Next()) {
2550 const TopoDS_Edge& EI = TopoDS::Edge(it.Value());
2552 BRep_Tool::Range(EI, Fst, Lst);
2553 BRepAdaptor_Curve Ad2(EI);
2554 gp_Pnt P1 = Ad2.Value(Fst);
2555 gp_Pnt P2 = Ad2.Value(Lst);
2557 tmp = P1.Distance(PFirst) + P2.Distance(PLast);
2569 //=======================================================================
2572 //=======================================================================
2574 static void MakeFace(const Handle(Geom_Surface)& S,
2575 const Standard_Real Um,
2576 const Standard_Real UM,
2577 const Standard_Real Vm,
2578 const Standard_Real VM,
2579 const Standard_Boolean isVminDegen,
2580 const Standard_Boolean isVmaxDegen,
2583 Standard_Real UMin = Um;
2584 Standard_Real UMax = UM;
2585 Standard_Real VMin = Vm;
2586 Standard_Real VMax = VM;
2587 Standard_Real epsilon = Precision::Confusion();
2589 Standard_Real umin,umax,vmin,vmax;
2590 S->Bounds(umin,umax,vmin,vmax);
2593 // compute infinite flags
2594 Standard_Boolean umininf = Precision::IsNegativeInfinite(UMin);
2595 Standard_Boolean umaxinf = Precision::IsPositiveInfinite(UMax);
2596 Standard_Boolean vmininf = Precision::IsNegativeInfinite(VMin);
2597 Standard_Boolean vmaxinf = Precision::IsPositiveInfinite(VMax);
2600 Standard_Boolean IsSuclosed = S->IsUClosed(), IsSvclosed = S->IsVClosed();
2601 if (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
2603 Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&S))->BasisSurface();
2604 IsSuclosed = BasisSurf->IsUClosed();
2605 IsSvclosed = BasisSurf->IsVClosed();
2608 Standard_Boolean uclosed =
2610 Abs(UMin - umin) < epsilon &&
2611 Abs(UMax - umax) < epsilon;
2613 Standard_Boolean vclosed =
2615 Abs(VMin - vmin) < epsilon &&
2616 Abs(VMax - vmax) < epsilon;
2618 // degenerated flags (for cones)
2619 Standard_Boolean vmindegen = isVminDegen, vmaxdegen = isVmaxDegen;
2620 Handle(Geom_Surface) theSurf = S;
2621 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
2622 theSurf = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
2623 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
2625 Handle(Geom_ConicalSurface) ConicalS = *((Handle(Geom_ConicalSurface)*) &theSurf);
2626 gp_Cone theCone = ConicalS->Cone();
2627 gp_Pnt theApex = theCone.Apex();
2628 Standard_Real Uapex, Vapex;
2629 ElSLib::Parameters( theCone, theApex, Uapex, Vapex );
2630 if (Abs(VMin - Vapex) <= Precision::Confusion())
2631 vmindegen = Standard_True;
2632 if (Abs(VMax - Vapex) <= Precision::Confusion())
2633 vmaxdegen = Standard_True;
2638 Standard_Real tol = Precision::Confusion();
2640 TopoDS_Vertex V00,V10,V11,V01;
2643 if (!vmininf) B.MakeVertex(V00,S->Value(UMin,VMin),tol);
2644 if (!vmaxinf) B.MakeVertex(V01,S->Value(UMin,VMax),tol);
2647 if (!vmininf) B.MakeVertex(V10,S->Value(UMax,VMin),tol);
2648 if (!vmaxinf) B.MakeVertex(V11,S->Value(UMax,VMax),tol);
2667 Handle(Geom2d_Line) Lumin,Lumax,Lvmin,Lvmax;
2669 Lumin = new Geom2d_Line(gp_Pnt2d(UMin,0),gp_Dir2d(0,1));
2671 Lumax = new Geom2d_Line(gp_Pnt2d(UMax,0),gp_Dir2d(0,1));
2673 Lvmin = new Geom2d_Line(gp_Pnt2d(0,VMin),gp_Dir2d(1,0));
2675 Lvmax = new Geom2d_Line(gp_Pnt2d(0,VMax),gp_Dir2d(1,0));
2677 Handle(Geom_Curve) Cumin,Cumax,Cvmin,Cvmax;
2678 Standard_Real TolApex = 1.e-5;
2679 //Standard_Boolean hasiso = ! S->IsKind(STANDARD_TYPE(Geom_OffsetSurface));
2680 Standard_Boolean hasiso = S->IsKind(STANDARD_TYPE(Geom_ElementarySurface));
2683 Cumin = S->UIso(UMin);
2685 Cumax = S->UIso(UMax);
2688 Cvmin = S->VIso(VMin);
2689 if (BRepOffset_Tool::Gabarit( Cvmin ) <= TolApex)
2690 vmindegen = Standard_True;
2694 Cvmax = S->VIso(VMax);
2695 if (BRepOffset_Tool::Gabarit( Cvmax ) <= TolApex)
2696 vmaxdegen = Standard_True;
2701 B.MakeFace(F,S,tol);
2704 TopoDS_Edge eumin,eumax,evmin,evmax;
2708 B.MakeEdge(eumin,Cumin,tol);
2712 B.UpdateEdge(eumin,Lumax,Lumin,F,tol);
2714 B.UpdateEdge(eumin,Lumin,F,tol);
2716 V00.Orientation(TopAbs_FORWARD);
2720 V01.Orientation(TopAbs_REVERSED);
2723 B.Range(eumin,VMin,VMax);
2731 B.MakeEdge(eumax,Cumax,tol);
2734 B.UpdateEdge(eumax,Lumax,F,tol);
2736 V10.Orientation(TopAbs_FORWARD);
2740 V11.Orientation(TopAbs_REVERSED);
2743 B.Range(eumax,VMin,VMax);
2748 if (hasiso && !vmindegen)
2749 B.MakeEdge(evmin,Cvmin,tol);
2753 B.UpdateEdge(evmin,Lvmin,Lvmax,F,tol);
2755 B.UpdateEdge(evmin,Lvmin,F,tol);
2757 V00.Orientation(TopAbs_FORWARD);
2761 V10.Orientation(TopAbs_REVERSED);
2764 B.Range(evmin,UMin,UMax);
2766 B.Degenerated(evmin, Standard_True);
2773 if (hasiso && !vmaxdegen)
2774 B.MakeEdge(evmax,Cvmax,tol);
2777 B.UpdateEdge(evmax,Lvmax,F,tol);
2779 V01.Orientation(TopAbs_FORWARD);
2783 V11.Orientation(TopAbs_REVERSED);
2786 B.Range(evmax,UMin,UMax);
2788 B.Degenerated(evmax, Standard_True);
2792 // make the wires and add them to the face
2793 eumin.Orientation(TopAbs_REVERSED);
2794 evmax.Orientation(TopAbs_REVERSED);
2798 if (!umininf && !umaxinf && vmininf && vmaxinf) {
2809 else if (umininf && umaxinf && !vmininf && !vmaxinf) {
2820 else if (!umininf || !umaxinf || !vmininf || !vmaxinf) {
2823 if (!umininf) B.Add(W,eumin);
2824 if (!vmininf) B.Add(W,evmin);
2825 if (!umaxinf) B.Add(W,eumax);
2826 if (!vmaxinf) B.Add(W,evmax);
2828 W.Closed(!umininf && !umaxinf && !vmininf && !vmaxinf);
2829 F.Closed(uclosed && vclosed);
2833 //=======================================================================
2834 //function : EnLargeGeometry
2836 //=======================================================================
2838 static Standard_Boolean EnlargeGeometry(Handle(Geom_Surface)& S,
2843 Standard_Boolean& IsV1degen,
2844 Standard_Boolean& IsV2degen,
2845 const Standard_Real uf1,
2846 const Standard_Real uf2,
2847 const Standard_Real vf1,
2848 const Standard_Real vf2,
2849 const Standard_Boolean GlobalEnlargeU,
2850 const Standard_Boolean GlobalEnlargeVfirst,
2851 const Standard_Boolean GlobalEnlargeVlast)
2853 const Standard_Real coeff = 4.;
2854 const Standard_Real TolApex = 1.e-5;
2856 Standard_Boolean SurfaceChange = Standard_False;
2857 if ( S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2858 Handle(Geom_Surface) BS = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface();
2859 EnlargeGeometry(BS,U1,U2,V1,V2,IsV1degen,IsV2degen,
2860 uf1,uf2,vf1,vf2,GlobalEnlargeU,GlobalEnlargeVfirst,GlobalEnlargeVlast);
2861 if (!GlobalEnlargeVfirst)
2863 if (!GlobalEnlargeVlast)
2865 if (!GlobalEnlargeVfirst || !GlobalEnlargeVlast)
2866 //(*((Handle(Geom_RectangularTrimmedSurface)*)&S))->SetTrim( U1, U2, V1, V2 );
2867 S = new Geom_RectangularTrimmedSurface( BS, U1, U2, V1, V2 );
2870 SurfaceChange = Standard_True;
2872 else if (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)) {
2873 Handle(Geom_Surface) Surf = (*((Handle(Geom_OffsetSurface)*)&S))->BasisSurface();
2874 SurfaceChange = EnlargeGeometry(Surf,U1,U2,V1,V2,IsV1degen,IsV2degen,
2875 uf1,uf2,vf1,vf2,GlobalEnlargeU,GlobalEnlargeVfirst,GlobalEnlargeVlast);
2876 Handle(Geom_OffsetSurface)::DownCast(S)->SetBasisSurface(Surf);
2878 else if (S->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) ||
2879 S->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution))
2881 Standard_Real du=0., dv=0.;
2882 Handle( Geom_Curve ) uiso, viso, uiso1, uiso2, viso1, viso2;
2883 Standard_Real u1, u2, v1, v2;
2884 Standard_Boolean enlargeU = GlobalEnlargeU, enlargeV = Standard_True;
2885 Standard_Boolean enlargeUfirst = enlargeU, enlargeUlast = enlargeU;
2886 Standard_Boolean enlargeVfirst = GlobalEnlargeVfirst, enlargeVlast = GlobalEnlargeVlast;
2887 S->Bounds( u1, u2, v1, v2 );
2888 if (Precision::IsInfinite(u1) || Precision::IsInfinite(u2))
2893 enlargeU = Standard_False;
2895 else if (S->IsUClosed())
2896 enlargeU = Standard_False;
2899 viso = S->VIso( vf1 );
2900 GeomAdaptor_Curve gac( viso );
2901 du = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2902 uiso1 = S->UIso( uf1 );
2903 uiso2 = S->UIso( uf2 );
2904 if (BRepOffset_Tool::Gabarit( uiso1 ) <= TolApex)
2905 enlargeUfirst = Standard_False;
2906 if (BRepOffset_Tool::Gabarit( uiso2 ) <= TolApex)
2907 enlargeUlast = Standard_False;
2909 if (Precision::IsInfinite(v1) || Precision::IsInfinite(v2))
2914 enlargeV = Standard_False;
2916 else if (S->IsVClosed())
2917 enlargeV = Standard_False;
2920 uiso = S->UIso( uf1 );
2921 GeomAdaptor_Curve gac( uiso );
2922 dv = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2923 viso1 = S->VIso( vf1 );
2924 viso2 = S->VIso( vf2 );
2925 if (BRepOffset_Tool::Gabarit( viso1 ) <= TolApex)
2927 enlargeVfirst = Standard_False;
2928 IsV1degen = Standard_True;
2930 if (BRepOffset_Tool::Gabarit( viso2 ) <= TolApex)
2932 enlargeVlast = Standard_False;
2933 IsV2degen = Standard_True;
2936 S = new Geom_RectangularTrimmedSurface( S, u1, u2, v1, v2 );
2940 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_False );
2942 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_True );
2947 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_False );
2949 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_True );
2951 S->Bounds( U1, U2, V1, V2 );
2952 SurfaceChange = Standard_True;
2954 else if (S->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) ||
2955 S->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface))
2957 Standard_Boolean enlargeU = GlobalEnlargeU, enlargeV = Standard_True;
2958 Standard_Boolean enlargeUfirst = enlargeU, enlargeUlast = enlargeU;
2959 Standard_Boolean enlargeVfirst = GlobalEnlargeVfirst, enlargeVlast = GlobalEnlargeVlast;
2961 enlargeU = Standard_False;
2963 enlargeV = Standard_False;
2965 Standard_Real duf = uf2-uf1, dvf = vf2-vf1;
2966 Standard_Real u1, u2, v1, v2;
2967 S->Bounds( u1, u2, v1, v2 );
2969 Standard_Real du=0., dv=0.;
2970 Handle( Geom_Curve ) uiso, viso, uiso1, uiso2, viso1, viso2;
2971 GeomAdaptor_Curve gac;
2974 viso = S->VIso( v1 );
2976 du = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2977 uiso1 = S->UIso( u1 );
2978 uiso2 = S->UIso( u2 );
2979 if (BRepOffset_Tool::Gabarit( uiso1 ) <= TolApex)
2980 enlargeUfirst = Standard_False;
2981 if (BRepOffset_Tool::Gabarit( uiso2 ) <= TolApex)
2982 enlargeUlast = Standard_False;
2986 uiso = S->UIso( u1 );
2988 dv = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2989 viso1 = S->VIso( v1 );
2990 viso2 = S->VIso( v2 );
2991 if (BRepOffset_Tool::Gabarit( viso1 ) <= TolApex)
2993 enlargeVfirst = Standard_False;
2994 IsV1degen = Standard_True;
2996 if (BRepOffset_Tool::Gabarit( viso2 ) <= TolApex)
2998 enlargeVlast = Standard_False;
2999 IsV2degen = Standard_True;
3005 if (enlargeUfirst && uf1-u1 < duf)
3006 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_False );
3007 if (enlargeUlast && u2-uf2 < duf)
3008 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_True );
3012 if (enlargeVfirst && vf1-v1 < dvf)
3013 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_False );
3014 if (enlargeVlast && v2-vf2 < dvf)
3015 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_True );
3018 S->Bounds( U1, U2, V1, V2 );
3019 SurfaceChange = Standard_True;
3021 // else if (S->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) ||
3022 // S->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) {
3023 // S->Bounds(U1,U2,V1,V2);
3026 Standard_Real UU1,UU2,VV1,VV2;
3027 S->Bounds(UU1,UU2,VV1,VV2);
3028 // Pas d extension au dela des bornes de la surface.
3034 return SurfaceChange;
3037 //=======================================================================
3038 //function : UpDatePCurve
3039 //purpose : Mise a jour des pcurves de F sur la surface de de BF.
3040 // F and BF has to be FORWARD,
3041 //=======================================================================
3043 static void UpdatePCurves (const TopoDS_Face& F,
3049 TopTools_IndexedMapOfShape Emap;
3050 Handle(Geom2d_Curve) NullPCurve;
3052 TopExp::MapShapes( F, TopAbs_EDGE, Emap );
3054 for (i = 1; i <= Emap.Extent(); i++)
3056 TopoDS_Edge CE = TopoDS::Edge( Emap(i) );
3057 CE.Orientation( TopAbs_FORWARD );
3058 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface( CE, F, f, l );
3061 if (BRep_Tool::IsClosed( CE, F ))
3064 Handle(Geom2d_Curve) C2R = BRep_Tool::CurveOnSurface( CE, F, f, l );
3065 B.UpdateEdge( CE, NullPCurve, NullPCurve, F, BRep_Tool::Tolerance(CE) );
3066 B.UpdateEdge( CE, C2, C2R, BF, BRep_Tool::Tolerance(CE) );
3070 B.UpdateEdge( CE, NullPCurve, F, BRep_Tool::Tolerance(CE) );
3071 B.UpdateEdge( CE, C2, BF, BRep_Tool::Tolerance(CE) );
3079 //=======================================================================
3080 //function :CompactUVBounds
3082 //=======================================================================
3084 static void CompactUVBounds (const TopoDS_Face& F,
3085 Standard_Real& UMin,
3086 Standard_Real& UMax,
3087 Standard_Real& VMin,
3088 Standard_Real& VMax)
3090 // Calcul serre pour que les bornes ne couvrent pas plus d une periode
3091 Standard_Real U1,U2;
3092 Standard_Real N = 33;
3095 TopExp_Explorer exp;
3096 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
3097 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
3098 BRepAdaptor_Curve2d C(E,F);
3099 BRep_Tool::Range(E,U1,U2);
3101 Standard_Real U = U1;
3102 Standard_Real DU = (U2-U1)/(N-1);
3103 for (Standard_Integer j=1;j<N;j++) {
3111 B.Get(UMin,VMin,UMax,VMax);
3114 //=======================================================================
3115 //function : CheckBounds
3117 //=======================================================================
3119 void BRepOffset_Tool::CheckBounds(const TopoDS_Face& F,
3120 const BRepOffset_Analyse& Analyse,
3121 Standard_Boolean& enlargeU,
3122 Standard_Boolean& enlargeVfirst,
3123 Standard_Boolean& enlargeVlast)
3125 enlargeU = Standard_True;
3126 enlargeVfirst = Standard_True; enlargeVlast = Standard_True;
3128 Standard_Integer Ubound = 0, Vbound = 0;
3129 Standard_Real Ufirst = RealLast(), Ulast = RealFirst();
3130 Standard_Real Vfirst = RealLast(), Vlast = RealFirst();
3132 Standard_Real UF1,UF2,VF1,VF2;
3133 CompactUVBounds(F,UF1,UF2,VF1,VF2);
3135 Handle(Geom_Surface) theSurf = BRep_Tool::Surface(F);
3136 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
3137 theSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&theSurf))->BasisSurface();
3139 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) ||
3140 theSurf->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution) ||
3141 theSurf->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) ||
3142 theSurf->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface))
3144 TopExp_Explorer Explo(F, TopAbs_EDGE);
3145 for (; Explo.More(); Explo.Next())
3147 const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
3148 const BRepOffset_ListOfInterval& L = Analyse.Type(anEdge);
3149 if (!L.IsEmpty() || BRep_Tool::Degenerated(anEdge))
3151 BRepOffset_Type OT = L.First().Type();
3152 if (OT == BRepOffset_Tangent || BRep_Tool::Degenerated(anEdge))
3154 Standard_Real fpar, lpar;
3155 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, F, fpar, lpar);
3156 if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve))
3157 aCurve = (*((Handle(Geom2d_TrimmedCurve)*)&aCurve))->BasisCurve();
3159 Handle(Geom2d_Line) theLine;
3160 if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_Line))
3161 theLine = *((Handle(Geom2d_Line)*)&aCurve);
3162 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_BezierCurve) ||
3163 aCurve->DynamicType() == STANDARD_TYPE(Geom2d_BSplineCurve))
3165 Standard_Real newFpar, newLpar, deviation;
3166 theLine = ShapeCustom_Curve2d::ConvertToLine2d(aCurve, fpar, lpar, Precision::Confusion(),
3167 newFpar, newLpar, deviation);
3170 if (!theLine.IsNull())
3172 gp_Dir2d theDir = theLine->Direction();
3173 if (theDir.IsParallel( gp::DX2d(), Precision::Angular() ))
3176 if (BRep_Tool::Degenerated(anEdge))
3178 if (Abs(theLine->Location().Y() - VF1) <= Precision::Confusion())
3179 enlargeVfirst = Standard_False;
3180 else //theLine->Location().Y() is near VF2
3181 enlargeVlast = Standard_False;
3185 if (theLine->Location().Y() < Vfirst)
3186 Vfirst = theLine->Location().Y();
3187 if (theLine->Location().Y() > Vlast)
3188 Vlast = theLine->Location().Y();
3191 else if (theDir.IsParallel( gp::DY2d(), Precision::Angular() ))
3194 if (theLine->Location().X() < Ufirst)
3195 Ufirst = theLine->Location().X();
3196 if (theLine->Location().X() > Ulast)
3197 Ulast = theLine->Location().X();
3205 if (Ubound >= 2 || Vbound >= 2)
3208 Abs(UF1-Ufirst) <= Precision::Confusion() &&
3209 Abs(UF2-Ulast) <= Precision::Confusion())
3210 enlargeU = Standard_False;
3212 Abs(VF1-Vfirst) <= Precision::Confusion() &&
3213 Abs(VF2-Vlast) <= Precision::Confusion())
3215 enlargeVfirst = Standard_False;
3216 enlargeVlast = Standard_False;
3221 //=======================================================================
3222 //function : EnLargeFace
3224 //=======================================================================
3226 Standard_Boolean BRepOffset_Tool::EnLargeFace
3227 (const TopoDS_Face& F,
3229 const Standard_Boolean CanExtentSurface,
3230 const Standard_Boolean UpdatePCurve,
3231 const Standard_Boolean enlargeU,
3232 const Standard_Boolean enlargeVfirst,
3233 const Standard_Boolean enlargeVlast)
3235 //---------------------------
3236 // extension de la geometrie.
3237 //---------------------------
3239 Handle (Geom_Surface) S = BRep_Tool::Surface(F,L);
3240 Standard_Real UU1,VV1,UU2,VV2;
3241 Standard_Boolean isVV1degen = Standard_False, isVV2degen = Standard_False;
3242 Standard_Real US1,VS1,US2,VS2;
3243 Standard_Real UF1,VF1,UF2,VF2;
3244 Standard_Real infini = 1.e8;
3245 Standard_Boolean SurfaceChange = Standard_False;
3247 if (S->IsUPeriodic() || S->IsVPeriodic()) {
3248 // Calcul serre pour que les bornes ne couvre pas plus d une periode
3249 CompactUVBounds(F,UF1,UF2,VF1,VF2);
3252 BRepTools::UVBounds(F,UF1,UF2,VF1,VF2);
3255 S->Bounds (US1,US2,VS1,VS2);
3256 UU1 = VV1 = - infini;
3259 if (CanExtentSurface) {
3260 SurfaceChange = EnlargeGeometry( S, UU1, UU2, VV1, VV2, isVV1degen, isVV2degen, UF1, UF2, VF1, VF2,
3261 enlargeU, enlargeVfirst, enlargeVlast );
3264 UU1 = Max(US1,UU1); UU2 = Min(UU2,US2);
3265 VV1 = Max(VS1,VV1); VV2 = Min(VS2,VV2);
3268 if (S->IsUPeriodic()) {
3269 Standard_Real Period = S->UPeriod();
3270 Standard_Real Delta = Period - (UF2 - UF1);
3271 Standard_Real alpha = 0.1;
3272 UU1 = UF1 - alpha*Delta; UU2 = UF2 + alpha*Delta;
3273 if ((UU2 - UU1) > Period) {
3277 if (S->IsVPeriodic()) {
3278 Standard_Real Period = S->VPeriod();
3279 Standard_Real Delta = Period - (VF2 - VF1);
3280 Standard_Real alpha = 0.1;
3281 VV1 = VF1 - alpha*Delta; VV2 = VF2 + alpha*Delta;
3282 if ((VV2 - VV1) > Period) {
3287 //Special treatment for conical surfaces
3288 Handle(Geom_Surface) theSurf = S;
3289 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
3290 theSurf = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
3291 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
3293 Handle(Geom_ConicalSurface) ConicalS = *((Handle(Geom_ConicalSurface)*) &theSurf);
3294 gp_Cone theCone = ConicalS->Cone();
3295 gp_Pnt theApex = theCone.Apex();
3296 Standard_Real Uapex, Vapex;
3297 ElSLib::Parameters( theCone, theApex, Uapex, Vapex );
3298 if (VV1 < Vapex && Vapex < VV2)
3300 //consider that VF1 and VF2 are on the same side from apex
3301 Standard_Real TolApex = 1.e-5;
3302 if (Vapex - VF1 >= TolApex ||
3303 Vapex - VF2 >= TolApex) //if (VF1 < Vapex || VF2 < Vapex)
3312 UU1 = UF1; UU2 = UF2;
3319 MakeFace(S,UU1,UU2,VV1,VV2,isVV1degen,isVV2degen,BF);
3322 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
3324 //----------------------------------------------------------------
3325 // utile pour les bouchons on ne doit pas changer leur geometrie.
3326 // (Ce que fait BRepLib_MakeFace si S est restreinte).
3327 // On remet S et on update les pcurves.
3328 //----------------------------------------------------------------
3329 TopExp_Explorer exp;
3330 exp.Init(BF,TopAbs_EDGE);
3331 Standard_Real f=0.,l=0.;
3332 for (; exp.More(); exp.Next()) {
3333 TopoDS_Edge CE = TopoDS::Edge(exp.Current());
3334 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(CE,BF,f,l);
3335 B.UpdateEdge (CE,C2,S,L,BRep_Tool::Tolerance(CE));
3337 B.UpdateFace(BF,S,L,BRep_Tool::Tolerance(F));
3340 if (SurfaceChange && UpdatePCurve) {
3341 TopoDS_Shape aLocalFace = F.Oriented(TopAbs_FORWARD);
3342 UpdatePCurves(TopoDS::Face(aLocalFace),BF);
3343 //UpdatePCurves(TopoDS::Face(F.Oriented(TopAbs_FORWARD)),BF);
3345 BB.UpdateFace( F, S, L, BRep_Tool::Tolerance(F) );
3348 BF.Orientation(F.Orientation());
3349 return SurfaceChange;
3352 //=======================================================================
3353 //function : TryParameter
3355 //=======================================================================
3357 static Standard_Boolean TryParameter (const TopoDS_Edge& OE,
3359 const TopoDS_Edge& NE,
3360 Standard_Real TolConf)
3362 BRepAdaptor_Curve OC(OE);
3363 BRepAdaptor_Curve NC(NE);
3364 Standard_Real Of = OC.FirstParameter(); Standard_Real Ol = OC.LastParameter();
3365 Standard_Real Nf = NC.FirstParameter(); Standard_Real Nl = NC.LastParameter();
3366 Standard_Real U = 0.;
3367 gp_Pnt P = BRep_Tool::Pnt(V);
3368 Standard_Boolean OK = Standard_False;
3370 if (P.Distance(OC.Value(Of)) < TolConf) {
3371 if (Of > Nf && Of < Nl && P.Distance(NC.Value(Of)) < TolConf) {
3376 if (P.Distance(OC.Value(Ol)) < TolConf) {
3377 if (Ol > Nf && Ol < Nl && P.Distance(NC.Value(Ol)) < TolConf) {
3384 TopoDS_Shape aLocalShape = NE.Oriented(TopAbs_FORWARD);
3385 TopoDS_Edge EE = TopoDS::Edge(aLocalShape);
3386 // TopoDS_Edge EE = TopoDS::Edge(NE.Oriented(TopAbs_FORWARD));
3387 aLocalShape = V.Oriented(TopAbs_INTERNAL);
3388 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
3389 U,NE,BRep_Tool::Tolerance(NE));
3390 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
3391 // U,NE,BRep_Tool::Tolerance(NE));
3396 //=======================================================================
3399 //=======================================================================
3401 void BRepOffset_Tool::MapVertexEdges (const TopoDS_Shape& S,
3402 TopTools_DataMapOfShapeListOfShape& MEV)
3404 TopExp_Explorer exp;
3405 exp.Init(S.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3406 TopTools_MapOfShape DejaVu;
3407 for ( ; exp.More(); exp.Next()) {
3408 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
3409 if (DejaVu.Add(E)) {
3410 TopoDS_Vertex V1,V2;
3411 TopExp::Vertices (E,V1,V2);
3412 if (!MEV.IsBound(V1)) {
3413 TopTools_ListOfShape empty;
3417 if (!V1.IsSame(V2)) {
3418 if (!MEV.IsBound(V2)) {
3419 TopTools_ListOfShape empty;
3428 //=======================================================================
3431 //=======================================================================
3433 void BRepOffset_Tool::BuildNeighbour (const TopoDS_Wire& W,
3434 const TopoDS_Face& F,
3435 TopTools_DataMapOfShapeShape& NOnV1,
3436 TopTools_DataMapOfShapeShape& NOnV2)
3438 TopoDS_Vertex V1,V2,VP1,VP2,FV1,FV2;
3439 TopoDS_Edge CurE,FirstE,PrecE;
3440 BRepTools_WireExplorer wexp;
3442 TopoDS_Shape aLocalFace = F.Oriented(TopAbs_FORWARD);
3443 TopoDS_Shape aLocalWire = W.Oriented(TopAbs_FORWARD);
3444 wexp.Init(TopoDS::Wire(aLocalWire),TopoDS::Face(aLocalFace));
3445 // wexp.Init(TopoDS::Wire(W.Oriented(TopAbs_FORWARD)),
3446 // TopoDS::Face(F.Oriented(TopAbs_FORWARD)));
3447 CurE = FirstE = PrecE = wexp.Current();
3448 TopExp::Vertices(CurE,V1,V2);
3449 FV1 = VP1 = V1; FV2 = VP2 = V2;
3451 while (wexp.More()) {
3452 CurE = wexp.Current();
3453 TopExp::Vertices(CurE,V1,V2);
3454 if (V1.IsSame(VP1)) { NOnV1.Bind(PrecE,CurE); NOnV1.Bind(CurE,PrecE);}
3455 if (V1.IsSame(VP2)) { NOnV2.Bind(PrecE,CurE); NOnV1.Bind(CurE,PrecE);}
3456 if (V2.IsSame(VP1)) { NOnV1.Bind(PrecE,CurE); NOnV2.Bind(CurE,PrecE);}
3457 if (V2.IsSame(VP2)) { NOnV2.Bind(PrecE,CurE); NOnV2.Bind(CurE,PrecE);}
3462 if (V1.IsSame(FV1)) { NOnV1.Bind(FirstE,CurE); NOnV1.Bind(CurE,FirstE);}
3463 if (V1.IsSame(FV2)) { NOnV2.Bind(FirstE,CurE); NOnV1.Bind(CurE,FirstE);}
3464 if (V2.IsSame(FV1)) { NOnV1.Bind(FirstE,CurE); NOnV2.Bind(CurE,FirstE);}
3465 if (V2.IsSame(FV2)) { NOnV2.Bind(FirstE,CurE); NOnV2.Bind(CurE,FirstE);}
3468 //=======================================================================
3469 //function : ExtentFace
3471 //=======================================================================
3473 void BRepOffset_Tool::ExtentFace (const TopoDS_Face& F,
3474 TopTools_DataMapOfShapeShape& ConstShapes,
3475 TopTools_DataMapOfShapeShape& ToBuild,
3476 const TopAbs_State Side,
3477 const Standard_Real TolConf,
3483 char* name = new char[100];
3484 sprintf(name,"FTE_%d",NbFTE++);
3489 TopExp_Explorer exp,exp2;
3490 TopTools_DataMapOfShapeShape Build;
3491 TopTools_DataMapOfShapeShape Extent;
3492 TopoDS_Edge FirstE,PrecE,CurE,NE;
3496 // Construction de la boite englobante de la face a etendre et des bouchons pour
3497 // limiter les extensions.
3498 //Bnd_Box ContextBox;
3499 //BRepBndLib::Add(F,B);
3500 //TopTools_DataMapIteratorOfDataMapOfShape itTB(ToBuild);
3501 //for (; itTB.More(); itTB.Next()) {
3502 //BRepBndLib::Add(TopBuild.Value(), ContextBox);
3506 Standard_Boolean SurfaceChange;
3507 SurfaceChange = EnLargeFace (F,EF,Standard_True);
3509 TopoDS_Shape aLocalShape = EF.EmptyCopied();
3510 NF = TopoDS::Face(aLocalShape);
3511 // NF = TopoDS::Face(EF.EmptyCopied());
3512 NF.Orientation(TopAbs_FORWARD);
3514 if (SurfaceChange) {
3515 //------------------------------------------------
3516 // Mise a jour des pcurves sur la surface de base.
3517 //------------------------------------------------
3518 TopoDS_Face Fforward = F;
3519 Fforward.Orientation(TopAbs_FORWARD);
3520 TopTools_IndexedMapOfShape Emap;
3521 TopExp::MapShapes( Fforward, TopAbs_EDGE, Emap );
3523 for (Standard_Integer i = 1; i <= Emap.Extent(); i++) {
3524 TopoDS_Edge CE = TopoDS::Edge( Emap(i) );
3525 CE.Orientation(TopAbs_FORWARD);
3526 TopoDS_Edge Ecs; //patch
3527 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(CE,Fforward,f,l);
3529 if (ConstShapes.IsBound(CE)) {
3530 Ecs = TopoDS::Edge(ConstShapes(CE));
3531 BRep_Tool::Range(Ecs,f,l);
3533 if (BRep_Tool::IsClosed(CE,Fforward)) {
3534 TopoDS_Shape aLocalShape = CE.Reversed();
3535 Handle(Geom2d_Curve) C2R =
3536 BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),Fforward,f,l);
3537 // Handle(Geom2d_Curve) C2R =
3538 // BRep_Tool::CurveOnSurface(TopoDS::Edge(CE.Reversed()),F,f,l);
3539 B.UpdateEdge (CE,C2,C2R,EF,BRep_Tool::Tolerance(CE));
3541 B.UpdateEdge (Ecs,C2,C2R,EF,BRep_Tool::Tolerance(CE));
3544 B.UpdateEdge (CE,C2,EF,BRep_Tool::Tolerance(CE));
3546 B.UpdateEdge (Ecs,C2,EF,BRep_Tool::Tolerance(CE));
3555 for (exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
3558 const TopoDS_Wire& W = TopoDS::Wire(exp.Current());
3559 TopTools_DataMapOfShapeListOfShape MVE; // Vertex -> Edges incidentes.
3560 TopTools_DataMapOfShapeShape NOnV1;
3561 TopTools_DataMapOfShapeShape NOnV2;
3563 MapVertexEdges (W,MVE);
3564 BuildNeighbour (W,F,NOnV1,NOnV2);
3566 TopTools_ListOfShape LInt1,LInt2;
3567 TopoDS_Face StopFace;
3568 //------------------------------------------------
3569 // Construction edges
3570 //------------------------------------------------
3571 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3572 exp2.More(); exp2.Next()) {
3573 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3574 if (ConstShapes.IsBound(E)) ToBuild.UnBind(E);
3575 if (ToBuild.IsBound(E)) {
3576 TopTools_ListOfShape LOE;
3578 BRepOffset_Tool::TryProject (TopoDS::Face(ToBuild(E)),
3579 EF,LOE,LInt2,LInt1,Side,TolConf);
3580 if (!LInt1.IsEmpty())
3585 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3586 exp2.More(); exp2.Next()) {
3587 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3588 if (ConstShapes.IsBound(E)) ToBuild.UnBind(E);
3589 if (ToBuild.IsBound(E)) {
3590 EnLargeFace(TopoDS::Face(ToBuild(E)),StopFace,Standard_False);
3591 BRepOffset_Tool::Inter3D (EF,StopFace,LInt1,LInt2,Side,E,Standard_True);
3592 // No intersection, it may happen for example for a chosen (non-offseted) planar face and
3593 // its neighbour offseted cylindrical face, if the offset is directed so that
3594 // the radius of the cylinder becomes smaller.
3595 if (LInt1.IsEmpty())
3597 if (LInt1.Extent() > 1) {
3598 // l intersection est en plusieurs edges (franchissement de couture)
3599 SelectEdge (F,EF,E,LInt1);
3601 NE = TopoDS::Edge(LInt1.First());
3602 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &NE.TShape());
3603 TE->Tolerance( TE->Tolerance()*10. ); //????
3604 if (NE.Orientation() == E.Orientation()) {
3605 Build.Bind(E,NE.Oriented(TopAbs_FORWARD));
3608 Build.Bind(E,NE.Oriented(TopAbs_REVERSED));
3610 const TopoDS_Edge& EOnV1 = TopoDS::Edge(NOnV1(E));
3611 if (!ToBuild .IsBound(EOnV1) &&
3612 !ConstShapes.IsBound(EOnV1) &&
3613 !Build .IsBound(EOnV1)) {
3614 ExtentEdge (F,EF,EOnV1,NE);
3615 Build.Bind (EOnV1,NE.Oriented(TopAbs_FORWARD));
3617 const TopoDS_Edge& EOnV2 = TopoDS::Edge(NOnV2(E));
3618 if (!ToBuild .IsBound(EOnV2) &&
3619 !ConstShapes.IsBound(EOnV2) &&
3620 !Build .IsBound(EOnV2)) {
3621 ExtentEdge (F,EF,EOnV2,NE);
3622 Build.Bind (EOnV2,NE.Oriented (TopAbs_FORWARD));
3627 //------------------------------------------------
3628 // Construction Vertex.
3629 //------------------------------------------------
3630 TopTools_ListOfShape LV;
3633 TopoDS_Vertex V1,V2;
3635 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3636 exp2.More(); exp2.Next()) {
3637 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3638 TopExp::Vertices (E,V1,V2);
3639 BRep_Tool::Range (E,f,l);
3641 if (Build.IsBound(E)) {
3642 const TopoDS_Edge& NEOnV1 = TopoDS::Edge(NOnV1(E));
3643 if (Build.IsBound(NEOnV1) &&
3644 (ToBuild.IsBound(E) || ToBuild.IsBound(NEOnV1))) {
3645 if (E.IsSame(NEOnV1))
3646 V = TopExp::FirstVertex(TopoDS::Edge(Build(E)));
3651 if (!Build.IsBound(V1)) {
3652 Inter2d (EF,TopoDS::Edge(Build(E)),
3653 TopoDS::Edge(Build(NEOnV1)),LV,/*TolConf*/Precision::Confusion());
3654 if (Build(E).Orientation() == TopAbs_FORWARD) {
3655 V = TopoDS::Vertex(LV.First());
3658 V = TopoDS::Vertex(LV.Last());
3662 V = TopoDS::Vertex(Build(V1));
3663 if (MVE (V1).Extent() > 2) {
3664 V.Orientation(TopAbs_FORWARD);
3665 if (Build(E).Orientation() == TopAbs_REVERSED)
3666 V.Orientation(TopAbs_REVERSED);
3667 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3677 if (ConstShapes.IsBound(V1)) V = TopoDS::Vertex(ConstShapes(V1));
3678 V.Orientation(TopAbs_FORWARD);
3679 if (Build(E).Orientation() == TopAbs_REVERSED)
3680 V.Orientation(TopAbs_REVERSED);
3681 if (!TryParameter (E,V,TopoDS::Edge(Build(E)),TolConf))
3682 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3684 ConstShapes.Bind(V1,V);
3686 const TopoDS_Edge& NEOnV2 = TopoDS::Edge(NOnV2(E));
3687 if (Build.IsBound(NEOnV2) &&
3688 (ToBuild.IsBound(E) || ToBuild.IsBound(NEOnV2))) {
3689 if (E.IsSame(NEOnV2))
3690 V = TopExp::LastVertex(TopoDS::Edge(Build(E)));
3695 if (!Build.IsBound(V2)) {
3696 Inter2d (EF,TopoDS::Edge(Build(E)),
3697 TopoDS::Edge(Build(NEOnV2)),LV,/*TolConf*/Precision::Confusion());
3698 if (Build(E).Orientation() == TopAbs_FORWARD) {
3699 V = TopoDS::Vertex(LV.Last());
3702 V = TopoDS::Vertex(LV.First());
3706 V = TopoDS::Vertex(Build(V2));
3707 if (MVE (V2).Extent() > 2) {
3708 V.Orientation(TopAbs_REVERSED);
3709 if (Build(E).Orientation() == TopAbs_REVERSED)
3710 V.Orientation(TopAbs_FORWARD);
3711 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3721 if (ConstShapes.IsBound(V2)) V = TopoDS::Vertex(ConstShapes(V2));
3722 V.Orientation(TopAbs_REVERSED);
3723 if (Build(E).Orientation() == TopAbs_REVERSED)
3724 V.Orientation(TopAbs_FORWARD);
3725 if (!TryParameter (E,V,TopoDS::Edge(Build(E)),TolConf))
3726 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3728 ConstShapes.Bind(V2,V);
3734 TopoDS_Vertex NV1,NV2;
3735 TopAbs_Orientation Or;
3736 Standard_Real U1,U2;
3737 Standard_Real eps = Precision::Confusion();
3747 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3748 exp2.More(); exp2.Next()) {
3749 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3750 TopExp::Vertices (E,V1,V2);
3751 if (Build.IsBound(E)) {
3752 NE = TopoDS::Edge(Build(E));
3753 BRep_Tool::Range(NE,f,l);
3754 Or = NE.Orientation();
3755 //-----------------------------------------------------
3756 // Copy pour virer les vertex deja sur la nouvelle edge.
3757 //-----------------------------------------------------
3758 NV1 = TopoDS::Vertex(ConstShapes(V1));
3759 NV2 = TopoDS::Vertex(ConstShapes(V2));
3761 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_INTERNAL);
3762 TopoDS_Shape aLocalEdge = NE.Oriented(TopAbs_INTERNAL);
3764 U1 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalVertex),
3765 TopoDS::Edge (aLocalEdge));
3766 aLocalVertex = NV2.Oriented(TopAbs_INTERNAL);
3767 aLocalEdge = NE.Oriented(TopAbs_FORWARD);
3768 U2 = BRep_Tool::Parameter
3769 (TopoDS::Vertex(aLocalVertex),TopoDS::Edge (aLocalEdge));
3770 // U1 = BRep_Tool::Parameter
3771 // (TopoDS::Vertex(NV1.Oriented(TopAbs_INTERNAL)),
3772 // TopoDS::Edge (NE .Oriented(TopAbs_FORWARD)));
3773 // U2 = BRep_Tool::Parameter
3774 // (TopoDS::Vertex(NV2.Oriented(TopAbs_INTERNAL)),
3775 // TopoDS::Edge (NE.Oriented(TopAbs_FORWARD)));
3776 aLocalEdge = NE.EmptyCopied();
3777 NE = TopoDS::Edge(aLocalEdge);
3778 NE.Orientation(TopAbs_FORWARD);
3779 if (NV1.IsSame(NV2))
3784 if (Or == TopAbs_FORWARD) {U1 = f; U2 = l;}
3785 else {U1 = l; U2 = f;}
3786 if (Or == TopAbs_FORWARD)
3790 if (Abs(U1-l) < eps) U1 = f;
3791 if (Abs(U2-f) < eps) U2 = l;
3793 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD );
3794 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3795 aLocalVertex = NV2.Oriented(TopAbs_REVERSED);
3796 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3797 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD )));
3798 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED)));
3800 ConstShapes.Bind(E,NE);
3801 NE.Orientation(E.Orientation());
3807 if (Abs(U2-l) < eps) U2 = f;
3808 if (Abs(U1-f) < eps) U1 = l;
3810 TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD );
3811 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3812 aLocalVertex = NV1.Oriented(TopAbs_REVERSED);
3813 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3814 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD )));
3815 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED)));
3817 ConstShapes.Bind(E,NE.Oriented(TopAbs_REVERSED));
3818 NE.Orientation(TopAbs::Reverse(E.Orientation()));
3823 //-------------------
3824 // edge is not ferme.
3825 //-------------------
3826 if (Or == TopAbs_FORWARD) {
3828 TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD );
3829 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3830 aLocalVertex = NV1.Oriented(TopAbs_REVERSED);
3831 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3832 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD )));
3833 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED)));
3838 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD );
3839 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3840 aLocalVertex = NV2.Oriented(TopAbs_REVERSED);
3841 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3842 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD )));
3843 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED)));
3846 ConstShapes.Bind(E,NE);
3847 NE.Orientation(E.Orientation());
3851 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD );
3852 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3853 aLocalVertex = NV2.Oriented(TopAbs_REVERSED);
3854 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3855 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD )));
3856 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED)));
3858 ConstShapes.Bind(E,NE);
3859 NE.Orientation(E.Orientation());
3863 TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD );
3864 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3865 aLocalVertex = NV1.Oriented(TopAbs_REVERSED);
3866 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3867 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD )));
3868 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED)));
3870 ConstShapes.Bind(E,NE.Oriented(TopAbs_REVERSED));
3871 NE.Orientation(TopAbs::Reverse(E.Orientation()));
3876 } // Build.IsBound(E)
3877 else if (ConstShapes.IsBound(E)) { // !Build.IsBound(E)
3878 NE = TopoDS::Edge(ConstShapes(E));
3879 BuildPCurves(NE,NF);
3880 Or = NE.Orientation();
3881 if (Or == TopAbs_REVERSED) {
3882 NE.Orientation(TopAbs::Reverse(E.Orientation()));
3885 NE.Orientation(E.Orientation());
3890 ConstShapes.Bind(E,NE.Oriented(TopAbs_FORWARD));
3894 B.Add(NF,NW.Oriented(W.Orientation()));
3896 NF.Orientation(F.Orientation());
3897 BRepTools::Update(NF); // Maj des UVPoints
3902 char* name = new char[100];
3903 sprintf(name,"FOB_%d",NbFOB++);
3904 DBRep::Set(name,NF);
3910 //=======================================================================
3911 //function : Deboucle3D
3913 //=======================================================================
3915 TopoDS_Shape BRepOffset_Tool::Deboucle3D(const TopoDS_Shape& S,
3916 const TopTools_MapOfShape& Boundary)
3918 return BRepAlgo_Tool::Deboucle3D(S,Boundary);
3921 //=======================================================================
3922 //function : IsInOut
3924 //=======================================================================
3926 static Standard_Boolean IsInOut (BRepTopAdaptor_FClass2d& FC,
3927 Geom2dAdaptor_Curve AC,
3928 const TopAbs_State& S )
3930 Standard_Real Def = 100*Precision::Confusion();
3931 GCPnts_QuasiUniformDeflection QU(AC,Def);
3933 for (Standard_Integer i = 1; i <= QU.NbPoints(); i++) {
3934 gp_Pnt2d P = AC.Value(QU.Parameter(i));
3935 if (FC.Perform(P) != S) {
3936 return Standard_False;
3940 return Standard_True;
3943 //=======================================================================
3944 //function : CorrectOrientation
3946 //=======================================================================
3948 void BRepOffset_Tool::CorrectOrientation(const TopoDS_Shape& SI,
3949 const TopTools_IndexedMapOfShape& NewEdges,
3950 Handle(BRepAlgo_AsDes)& AsDes,
3951 BRepAlgo_Image& InitOffset,
3952 const Standard_Real Offset)
3955 TopExp_Explorer exp;
3956 exp.Init(SI,TopAbs_FACE);
3957 Standard_Real f=0.,l=0.;
3959 for (; exp.More(); exp.Next()) {
3961 const TopoDS_Face& FI = TopoDS::Face(exp.Current());
3962 const TopTools_ListOfShape& LOF = InitOffset.Image(FI);
3963 TopTools_ListIteratorOfListOfShape it(LOF);
3964 for (; it.More(); it.Next()) {
3965 const TopoDS_Face& OF = TopoDS::Face(it.Value());
3966 TopTools_ListOfShape& LOE = AsDes->ChangeDescendant(OF);
3967 TopTools_ListIteratorOfListOfShape itE(LOE);
3969 Standard_Boolean YaInt = Standard_False;
3970 for (; itE.More(); itE.Next()) {
3971 const TopoDS_Edge& OE = TopoDS::Edge(itE.Value());
3972 if (NewEdges.Contains(OE)) {YaInt = Standard_True; break;}
3975 TopoDS_Shape aLocalFace = FI.Oriented(TopAbs_FORWARD);
3976 BRepTopAdaptor_FClass2d FC (TopoDS::Face(aLocalFace),
3977 Precision::Confusion());
3978 // BRepTopAdaptor_FClass2d FC (TopoDS::Face(FI.Oriented(TopAbs_FORWARD)),
3979 // Precision::Confusion());
3980 for (itE.Initialize(LOE); itE.More(); itE.Next()) {
3981 TopoDS_Shape& OE = itE.Value();
3982 if (NewEdges.Contains(OE)) {
3983 Handle(Geom2d_Curve) CO2d =
3984 BRep_Tool::CurveOnSurface(TopoDS::Edge(OE),OF,f,l);
3985 Geom2dAdaptor_Curve AC(CO2d,f,l);
3988 if (IsInOut(FC,AC,TopAbs_OUT)) OE.Reverse();
3991 // if (IsInOut(FC,AC,TopAbs_IN)) OE.Reverse();