1 // Created on: 1995-10-19
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor3d_CurveOnSurface.hxx>
19 #include <Adaptor3d_HCurveOnSurface.hxx>
20 #include <BRep_Builder.hxx>
21 #include <BRep_GCurve.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23 #include <BRep_ListOfCurveRepresentation.hxx>
24 #include <BRep_TEdge.hxx>
25 #include <BRep_Tool.hxx>
26 #include <BRepGProp.hxx>
27 #include <BRepLib.hxx>
28 #include <BRepLib_MakeFace.hxx>
29 #include <BRepLib_MakeWire.hxx>
30 #include <BRepOffset.hxx>
31 #include <BRepOffset_Offset.hxx>
32 #include <BRepOffset_Tool.hxx>
33 #include <BRepTools.hxx>
35 #include <gce_MakePln.hxx>
36 #include <Geom2d_Curve.hxx>
37 #include <Geom2d_Line.hxx>
38 #include <Geom2d_TrimmedCurve.hxx>
39 #include <Geom2dAdaptor_Curve.hxx>
40 #include <Geom2dAdaptor_HCurve.hxx>
41 #include <Geom_Circle.hxx>
42 #include <Geom_ConicalSurface.hxx>
43 #include <Geom_Curve.hxx>
44 #include <Geom_Line.hxx>
45 #include <Geom_OffsetSurface.hxx>
46 #include <Geom_RectangularTrimmedSurface.hxx>
47 #include <Geom_SphericalSurface.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_TrimmedCurve.hxx>
50 #include <GeomAdaptor_Curve.hxx>
51 #include <GeomAdaptor_HCurve.hxx>
52 #include <GeomAdaptor_HSurface.hxx>
53 #include <GeomAdaptor_Surface.hxx>
54 #include <GeomAPI.hxx>
55 #include <GeomAPI_ExtremaCurveCurve.hxx>
56 #include <GeomAPI_ProjectPointOnCurve.hxx>
57 #include <GeomConvert_ApproxSurface.hxx>
58 #include <GeomFill_Pipe.hxx>
59 #include <GeomLib.hxx>
60 #include <GeomProjLib.hxx>
63 #include <gp_Cylinder.hxx>
65 #include <gp_Pnt2d.hxx>
66 #include <gp_Torus.hxx>
67 #include <GProp_GProps.hxx>
68 #include <Precision.hxx>
69 #include <ShapeFix_Shape.hxx>
70 #include <Standard_ConstructionError.hxx>
72 #include <TopExp_Explorer.hxx>
74 #include <TopoDS_Edge.hxx>
75 #include <TopoDS_Face.hxx>
76 #include <TopoDS_Shape.hxx>
77 #include <TopoDS_Vertex.hxx>
78 #include <TopoDS_Wire.hxx>
79 #include <TopTools_IndexedMapOfShape.hxx>
80 #include <TopTools_ListIteratorOfListOfShape.hxx>
81 #include <TopTools_MapOfShape.hxx>
82 #include <TopTools_SequenceOfShape.hxx>
85 static Standard_Boolean Affich = Standard_False;
86 static Standard_Integer NbOFFSET = 0;
89 #include <DrawTrSurf.hxx>
95 static gp_Pnt GetFarestCorner(const TopoDS_Wire& aWire)
97 TopTools_IndexedMapOfShape Vertices;
98 TopExp::MapShapes(aWire, TopAbs_VERTEX, Vertices);
100 Standard_Real MaxDist = 0.;
102 for (Standard_Integer i = 1; i <= Vertices.Extent(); i++)
103 for (Standard_Integer j = 1; j <= Vertices.Extent(); j++)
105 const TopoDS_Vertex& V1 = TopoDS::Vertex(Vertices(i));
106 const TopoDS_Vertex& V2 = TopoDS::Vertex(Vertices(j));
107 gp_Pnt P1 = BRep_Tool::Pnt(V1);
108 gp_Pnt P2 = BRep_Tool::Pnt(V2);
109 Standard_Real aDist = P1.SquareDistance(P2);
120 //=======================================================================
121 //function : UpdateEdge
123 //=======================================================================
125 static void UpdateEdge(const TopoDS_Edge& E,
126 const Handle(Geom_Curve)& C,
127 const TopLoc_Location& L,
128 const Standard_Real Tol)
130 // Cut curves to avoid copies in the extensions.
132 Handle(Geom_TrimmedCurve) BC = Handle(Geom_TrimmedCurve)::DownCast(C);
134 B.UpdateEdge(E,BC->BasisCurve(),L,Tol);
137 B.UpdateEdge(E,C,L,Tol);
141 //=======================================================================
142 //function : UpdateEdge
144 //=======================================================================
146 static void UpdateEdge(const TopoDS_Edge& E,
147 const Handle(Geom2d_Curve)& C,
148 const TopoDS_Face& F,
149 const Standard_Real Tol)
151 // Cut curves to avoid copies in the extensions.
153 Handle(Geom2d_TrimmedCurve) BC = Handle(Geom2d_TrimmedCurve)::DownCast(C);
155 B.UpdateEdge(E,BC->BasisCurve(),F,Tol);
158 B.UpdateEdge(E,C,F,Tol);
162 //=======================================================================
163 //function : UpdateEdge
165 //=======================================================================
167 static void UpdateEdge (const TopoDS_Edge& E,
168 const Handle(Geom2d_Curve)& C1,
169 const Handle(Geom2d_Curve)& C2,
170 const TopoDS_Face& F,
171 const Standard_Real Tol)
173 // Cut curves to avoid copies in the extensions.
175 Handle(Geom2d_Curve) NC1,NC2;
176 Handle(Geom2d_TrimmedCurve) BC1 = Handle(Geom2d_TrimmedCurve)::DownCast(C1);
177 Handle(Geom2d_TrimmedCurve) BC2 = Handle(Geom2d_TrimmedCurve)::DownCast(C2);
178 if (!BC1.IsNull()) NC1 = BC1->BasisCurve(); else NC1 = C1;
179 if (!BC2.IsNull()) NC2 = BC2->BasisCurve(); else NC2 = C2;
180 B.UpdateEdge(E,NC1,NC2,F,Tol);
184 //=======================================================================
185 //function : ComputeCurve3d
186 //purpose : Particular case of Curve On Surface.
187 //=======================================================================
189 static void ComputeCurve3d(TopoDS_Edge Edge,
190 const Handle(Geom2d_Curve)& Curve,
191 const Handle(Geom_Surface)& Surf,
192 const TopLoc_Location Loc,
195 // try to find the particular case
196 // if not found call BRepLib::BuildCurve3d
198 Standard_Boolean IsComputed = Standard_False;
200 // Search only isos on analytic surfaces.
201 Geom2dAdaptor_Curve C(Curve);
202 GeomAdaptor_Surface S(Surf);
203 GeomAbs_CurveType CTy = C.GetType();
204 GeomAbs_SurfaceType STy = S.GetType();
205 BRep_Builder TheBuilder;
207 if ( STy != GeomAbs_Plane) { // if plane buildcurve3d manage KPart
208 if ( CTy == GeomAbs_Line) {
209 gp_Dir2d D = C.Line().Direction();
210 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
211 if ( STy == GeomAbs_Sphere) {
212 gp_Pnt2d P = C.Line().Location();
213 if ( Abs( Abs(P.Y()) -M_PI/2. ) < Precision::PConfusion()) {
214 TheBuilder.Degenerated(Edge, Standard_True);
217 gp_Sphere Sph = S.Sphere();
218 gp_Ax3 Axis = Sph.Position();
219 gp_Circ Ci = ElSLib::SphereVIso(Axis,
222 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
223 gp_Ax1 AxeRev(Axis.Location(), DRev);
224 Ci.Rotate(AxeRev, P.X());
225 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
226 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
228 UpdateEdge(Edge, Circle, Loc, Tol);
230 IsComputed = Standard_True;
232 else if ( STy == GeomAbs_Cylinder) {
233 gp_Cylinder Cyl = S.Cylinder();
234 gp_Pnt2d P = C.Line().Location();
235 gp_Ax3 Axis = Cyl.Position();
236 gp_Circ Ci = ElSLib::CylinderVIso(Axis,
239 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
240 gp_Ax1 AxeRev(Axis.Location(), DRev);
241 Ci.Rotate(AxeRev, P.X());
242 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
243 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
245 UpdateEdge(Edge, Circle, Loc, Tol);
246 IsComputed = Standard_True;
248 else if ( STy == GeomAbs_Cone) {
249 gp_Cone Cone = S.Cone();
250 gp_Pnt2d P = C.Line().Location();
251 gp_Ax3 Axis = Cone.Position();
252 gp_Circ Ci = ElSLib::ConeVIso(Axis,
256 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
257 gp_Ax1 AxeRev(Axis.Location(), DRev);
258 Ci.Rotate(AxeRev, P.X());
259 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
260 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
262 UpdateEdge(Edge, Circle, Loc, Tol);
263 IsComputed = Standard_True;
265 else if ( STy == GeomAbs_Torus) {
266 gp_Torus Tore = S.Torus();
267 gp_Pnt2d P = C.Line().Location();
268 gp_Ax3 Axis = Tore.Position();
269 gp_Circ Ci = ElSLib::TorusVIso(Axis,
273 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
274 gp_Ax1 AxeRev(Axis.Location(), DRev);
275 Ci.Rotate(AxeRev, P.X());
276 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
277 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
279 UpdateEdge(Edge, Circle, Loc, Tol);
280 IsComputed = Standard_True;
283 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
284 if ( STy == GeomAbs_Sphere) {
285 gp_Sphere Sph = S.Sphere();
286 gp_Pnt2d P = C.Line().Location();
287 gp_Ax3 Axis = Sph.Position();
289 gp_Circ Ci = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
291 // set to sameparameter (rotation of circle - offset of Y)
292 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
293 gp_Ax1 AxeRev(Axis.Location(),DRev);
294 Ci.Rotate(AxeRev, P.Y());
296 // transformation en iso U ( = P.X())
297 DRev = Axis.XDirection().Crossed(Axis.YDirection());
298 AxeRev = gp_Ax1(Axis.Location(), DRev);
299 Ci.Rotate(AxeRev, P.X());
300 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
302 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
304 UpdateEdge(Edge, Circle, Loc, Tol);
305 IsComputed = Standard_True;
307 else if ( STy == GeomAbs_Cylinder) {
308 gp_Cylinder Cyl = S.Cylinder();
309 gp_Pnt2d P = C.Line().Location();
310 gp_Lin L = ElSLib::CylinderUIso(Cyl.Position(),
313 gp_Vec Tr(L.Direction());
316 Handle(Geom_Line) Line = new Geom_Line(L);
317 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
319 UpdateEdge(Edge, Line, Loc, Tol);
320 IsComputed = Standard_True;
322 else if ( STy == GeomAbs_Cone) {
323 gp_Cone Cone = S.Cone();
324 gp_Pnt2d P = C.Line().Location();
325 gp_Lin L = ElSLib::ConeUIso(Cone.Position(),
329 gp_Vec Tr(L.Direction());
331 L.Translate(Tr); Handle(Geom_Line) Line = new Geom_Line(L);
332 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
334 UpdateEdge(Edge, Line, Loc, Tol);
335 IsComputed = Standard_True;
337 else if ( STy == GeomAbs_Torus) {
338 gp_Torus Tore = S.Torus();
339 gp_Pnt2d P = C.Line().Location();
340 gp_Ax3 Axis = Tore.Position();
341 gp_Circ Ci = ElSLib::TorusUIso(Axis,
345 Ci.Rotate(Ci.Axis(),P.Y());
346 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
348 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
350 UpdateEdge(Edge, Circle, Loc, Tol);
351 IsComputed = Standard_True;
357 Handle(Geom_Curve) C3d = GeomAPI::To3d(Curve,S.Plane());
358 UpdateEdge(Edge, C3d, Loc, Tol);
359 IsComputed = Standard_True;
362 //BRepLib::BuildCurves3d(Edge,Tol);
363 //Les Courbes 3d des edges dans le cas general ne sont calcules que si
365 //ie dans les tuyaux et les bouchons ..
366 // dans la derniere etapes de MakeShells on reconstruira les courbes3d
367 // des edges du resultat qui n en ont pas.
372 //=======================================================================
373 //function : BRepOffset_Offset
375 //=======================================================================
377 BRepOffset_Offset::BRepOffset_Offset()
382 //=======================================================================
383 //function : BRepOffset_Offset
385 //=======================================================================
387 BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Face& Face,
388 const Standard_Real Offset,
389 const Standard_Boolean OffsetOutside,
390 const GeomAbs_JoinType JoinType)
392 Init(Face, Offset, OffsetOutside, JoinType);
396 //=======================================================================
397 //function : BRepOffset_Offset
399 //=======================================================================
401 BRepOffset_Offset::BRepOffset_Offset
402 (const TopoDS_Face& Face,
403 const Standard_Real Offset,
404 const TopTools_DataMapOfShapeShape& Created,
405 const Standard_Boolean OffsetOutside,
406 const GeomAbs_JoinType JoinType)
408 Init(Face,Offset,Created,OffsetOutside,JoinType);
412 //=======================================================================
413 //function : BRepOffset_Offset
415 //=======================================================================
417 BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Edge& Path,
418 const TopoDS_Edge& Edge1,
419 const TopoDS_Edge& Edge2,
420 const Standard_Real Offset,
421 const Standard_Boolean Polynomial,
422 const Standard_Real Tol,
423 const GeomAbs_Shape Conti)
425 Init(Path,Edge1,Edge2,Offset,Polynomial,Tol,Conti);
429 //=======================================================================
430 //function : BRepOffset_Offset
432 //=======================================================================
434 BRepOffset_Offset::BRepOffset_Offset
435 (const TopoDS_Edge& Path,
436 const TopoDS_Edge& Edge1,
437 const TopoDS_Edge& Edge2,
438 const Standard_Real Offset,
439 const TopoDS_Edge& FirstEdge,
440 const TopoDS_Edge& LastEdge,
441 const Standard_Boolean Polynomial,
442 const Standard_Real Tol,
443 const GeomAbs_Shape Conti)
445 Init(Path,Edge1,Edge2,Offset,FirstEdge,LastEdge,Polynomial,Tol,Conti);
449 //=======================================================================
450 //function : BRepOffset_Offset
452 //=======================================================================
454 BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Vertex& Vertex,
455 const TopTools_ListOfShape& LEdge,
456 const Standard_Real Offset,
457 const Standard_Boolean Polynomial,
458 const Standard_Real Tol,
459 const GeomAbs_Shape Conti)
461 Init(Vertex,LEdge,Offset,Polynomial,Tol,Conti);
465 //=======================================================================
468 //=======================================================================
470 void BRepOffset_Offset::Init(const TopoDS_Face& Face,
471 const Standard_Real Offset,
472 const Standard_Boolean OffsetOutside,
473 const GeomAbs_JoinType JoinType)
475 TopTools_DataMapOfShapeShape Empty;
476 Init(Face,Offset,Empty,OffsetOutside,JoinType);
480 //=======================================================================
483 //=======================================================================
485 void BRepOffset_Offset::Init(const TopoDS_Face& Face,
486 const Standard_Real Offset,
487 const TopTools_DataMapOfShapeShape& Created,
488 const Standard_Boolean OffsetOutside,
489 const GeomAbs_JoinType JoinType)
492 Standard_Real myOffset = Offset;
493 if ( Face.Orientation() == TopAbs_REVERSED)
497 Handle(Geom_Surface) S = BRep_Tool::Surface(Face,L);
499 // On detrime les surfaces, evite des recopies dans les extensions.
500 Handle(Geom_RectangularTrimmedSurface) RT =
501 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
502 if (!RT.IsNull()) S = RT->BasisSurface();
504 // particular case of cone
505 Handle(Geom_ConicalSurface) Co;
506 Co = Handle(Geom_ConicalSurface)::DownCast(S);
509 gp_Pnt Apex = Co->Apex();
510 ElSLib::Parameters( Co->Cone(),Apex,Uc,Vc);
511 Standard_Real UU1,UU2,VV1,VV2;
512 BRepTools::UVBounds(Face,UU1,UU2,VV1,VV2);
513 if ( VV2 < Vc && Co->SemiAngle() > 0 )
515 else if ( VV1 > Vc && Co->SemiAngle() < 0 )
517 if ( !Co->Position().Direct()) myOffset *= -1;
520 Handle(Geom_Surface) TheSurf =
521 BRepOffset::Surface( S, myOffset, myStatus);
523 //processing offsets of faces with possible degenerated edges
524 Standard_Boolean UminDegen = Standard_False;
525 Standard_Boolean UmaxDegen = Standard_False;
526 Standard_Boolean VminDegen = Standard_False;
527 Standard_Boolean VmaxDegen = Standard_False;
528 Standard_Boolean UisoDegen = Standard_False;
529 gp_Pnt MinApex, MaxApex;
530 Standard_Boolean HasSingularity = Standard_False;
531 Standard_Real uf1, uf2, vf1, vf2, fpar, lpar;
532 BRepTools::UVBounds(Face, uf1, uf2, vf1, vf2);
533 if (!(OffsetOutside && JoinType == GeomAbs_Arc) &&
534 (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface) ||
535 TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)))
537 TopTools_SequenceOfShape DegEdges;
538 TopExp_Explorer Explo(Face, TopAbs_EDGE);
539 for (; Explo.More(); Explo.Next())
541 const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
543 if (BRep_Tool::Degenerated(anEdge))
545 Standard_Real aF, aL;
546 Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface(anEdge, Face, aF, aL);
548 gp_Pnt2d aFPnt2d = c2d->Value(aF),
549 aLPnt2d = c2d->Value(aL);
551 gp_Pnt aFPnt = S->Value(aFPnt2d.X(), aFPnt2d.Y()),
552 aLPnt = S->Value(aLPnt2d.X(), aLPnt2d.Y());
554 // aFPnt.SquareDistance(aLPnt) > Precision::SquareConfusion() -
555 // is a sufficient condition of troubles: non-singular case, but edge is degenerated.
556 // So, normal handling of degenerated edges is not applicable in case of non-singular point.
557 if (aFPnt.SquareDistance(aLPnt) < Precision::SquareConfusion())
559 DegEdges.Append(anEdge);
563 if (!DegEdges.IsEmpty())
565 const Standard_Real TolApex = 1.e-5;
566 //define the iso of singularity (u or v)
567 const TopoDS_Edge& theDegEdge = TopoDS::Edge(DegEdges(1));
568 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar);
569 gp_Pnt2d fp2d = aCurve->Value(fpar);
570 gp_Pnt2d lp2d = aCurve->Value(lpar);
571 if (Abs(fp2d.X() - lp2d.X()) <= Precision::PConfusion())
572 UisoDegen = Standard_True;
574 if (DegEdges.Length() == 2)
577 { UminDegen = Standard_True; UmaxDegen = Standard_True; }
579 { VminDegen = Standard_True; VmaxDegen = Standard_True; }
581 else //DegEdges.Length() == 1
583 const TopoDS_Edge& theDegEdge = TopoDS::Edge(DegEdges(1));
584 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar);
587 if (Abs(fp2d.X() - uf1) <= Precision::Confusion())
588 UminDegen = Standard_True;
590 UmaxDegen = Standard_True;
594 if (Abs(fp2d.Y() - vf1) <= Precision::Confusion())
595 VminDegen = Standard_True;
597 VmaxDegen = Standard_True;
600 if (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
602 gp_Cone theCone = Handle(Geom_ConicalSurface)::DownCast (TheSurf)->Cone();
603 gp_Pnt apex = theCone.Apex();
604 Standard_Real Uapex, Vapex;
605 ElSLib::Parameters( theCone, apex, Uapex, Vapex );
608 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, Vapex, vf2);
610 HasSingularity = Standard_True;
614 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, Vapex);
616 HasSingularity = Standard_True;
619 else //TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)
623 Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
624 if (BRepOffset_Tool::Gabarit( uiso ) > TolApex)
626 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
627 gp_Pnt Papex, Pfirst, Pquart, Pmid;
628 Papex = BasisSurf->Value( uf1, vf1 );
629 Pfirst = TheSurf->Value( uf1, vf1 );
630 Pquart = TheSurf->Value( uf1, 0.75*vf1+0.25*vf2 );
631 Pmid = TheSurf->Value( uf1, 0.5*(vf1+vf2) );
632 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
633 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
634 gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 1, 0 );
635 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
636 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
638 theExtrema.NearestPoints(Pint1, Pint2);
639 Standard_Real length = Pfirst.Distance(Pint1);
642 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
643 GeomLib::ExtendSurfByLength (aSurf, length, 1, Standard_True, Standard_False);
645 Standard_Real u1, u2, v1, v2;
646 TheSurf->Bounds( u1, u2, v1, v2 );
647 MinApex = TheSurf->Value( u1, vf1 );
651 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
652 GeomAPI_ProjectPointOnCurve Projector( Pint1, viso );
653 Standard_Real NewFirstU = Projector.LowerDistanceParameter();
654 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, NewFirstU, uf2, vf1, vf2);
655 MinApex = TheSurf->Value( NewFirstU, vf1 );
657 HasSingularity = Standard_True;
659 } //end of if (UminDegen)
662 Handle(Geom_Curve) uiso = TheSurf->UIso( uf2 );
663 if (BRepOffset_Tool::Gabarit( uiso ) > TolApex)
665 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
666 gp_Pnt Papex, Pfirst, Pquart, Pmid;
667 Papex = BasisSurf->Value( uf2, vf1 );
668 Pfirst = TheSurf->Value( uf2, vf1 );
669 Pquart = TheSurf->Value( uf2, 0.75*vf1+0.25*vf2 );
670 Pmid = TheSurf->Value( uf2, 0.5*(vf1+vf2) );
671 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
672 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
673 gp_Vec DirGeneratrix = BasisSurf->DN( uf2, vf1, 1, 0 );
674 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
675 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
677 theExtrema.NearestPoints(Pint1, Pint2);
678 Standard_Real length = Pfirst.Distance(Pint1);
681 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
682 GeomLib::ExtendSurfByLength(aSurf, length, 1, Standard_True, Standard_True);
684 Standard_Real u1, u2, v1, v2;
685 TheSurf->Bounds( u1, u2, v1, v2 );
686 MaxApex = TheSurf->Value( u2, vf1 );
690 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
691 GeomAPI_ProjectPointOnCurve Projector( Pint1, viso );
692 Standard_Real NewLastU = Projector.LowerDistanceParameter();
693 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, NewLastU, vf1, vf2);
694 MaxApex = TheSurf->Value( NewLastU, vf1 );
696 HasSingularity = Standard_True;
698 } //end of if (UmaxDegen)
701 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
702 if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
704 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
705 gp_Pnt Papex, Pfirst, Pquart, Pmid;
706 Papex = BasisSurf->Value( uf1, vf1 );
707 Pfirst = TheSurf->Value( uf1, vf1 );
708 Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf1 );
709 Pmid = TheSurf->Value( 0.5*(uf1+uf2), vf1 );
710 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
711 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
712 gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 0, 1 );
713 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
714 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
716 theExtrema.NearestPoints(Pint1, Pint2);
717 Standard_Real length = Pfirst.Distance(Pint1);
720 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
721 GeomLib::ExtendSurfByLength(aSurf, length, 1, Standard_False, Standard_False);
723 Standard_Real u1, u2, v1, v2;
724 TheSurf->Bounds( u1, u2, v1, v2 );
725 MinApex = TheSurf->Value( uf1, v1 );
729 Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
730 GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
731 Standard_Real NewFirstV = Projector.LowerDistanceParameter();
732 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, NewFirstV, vf2);
733 MinApex = TheSurf->Value( uf1, NewFirstV );
734 //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1+length, vf2);
735 //MinApex = TheSurf->Value( uf1, vf1+length );
737 HasSingularity = Standard_True;
739 } //end of if (VminDegen)
742 Handle(Geom_Curve) viso = TheSurf->VIso( vf2 );
743 if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
745 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
746 gp_Pnt Papex, Pfirst, Pquart, Pmid;
747 Papex = BasisSurf->Value( uf1, vf2 );
748 Pfirst = TheSurf->Value( uf1, vf2 );
749 Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf2 );
750 Pmid = TheSurf->Value( 0.5*(uf1+uf2), vf2 );
751 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
752 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
753 gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf2, 0, 1 );
754 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
755 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
757 theExtrema.NearestPoints(Pint1, Pint2);
758 Standard_Real length = Pfirst.Distance(Pint1);
761 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
762 GeomLib::ExtendSurfByLength(aSurf, length, 1, Standard_False, Standard_True);
764 Standard_Real u1, u2, v1, v2;
765 TheSurf->Bounds( u1, u2, v1, v2 );
766 MaxApex = TheSurf->Value( uf1, v2 );
770 Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
771 GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
772 Standard_Real NewLastV = Projector.LowerDistanceParameter();
773 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, NewLastV);
774 MaxApex = TheSurf->Value( uf1, NewLastV );
775 //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2-length);
776 //MaxApex = TheSurf->Value( uf1, vf2-length );
778 HasSingularity = Standard_True;
780 } //end of if (VmaxDegen)
781 } //end of else (case of Geom_OffsetSurface)
782 } //end of if (!DegEdges.IsEmpty())
783 } //end of processing offsets of faces with possible degenerated edges
785 // find the PCurves of the edges of <Faces>
787 BRep_Builder myBuilder;
788 myBuilder.MakeFace(myFace);
789 myBuilder.UpdateFace(myFace,TheSurf,L,BRep_Tool::Tolerance(Face));
791 TopTools_DataMapOfShapeShape MapSS;
793 // mise a jour de la map sur les vertex deja crees
794 TopoDS_Shape aLocalShape = Face.Oriented(TopAbs_FORWARD);
795 TopoDS_Face CurFace = TopoDS::Face(aLocalShape);
796 // TopoDS_Face CurFace = TopoDS::Face(Face.Oriented(TopAbs_FORWARD));
798 TopTools_MapOfShape VonDegen;
799 Standard_Real u1, u2, v1, v2;
800 TheSurf->Bounds( u1, u2, v1, v2 );
802 TopExp_Explorer exp(CurFace, TopAbs_EDGE);
803 for ( ; exp.More(); exp.Next()) {
804 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
805 TopoDS_Vertex V1,V2,OV1,OV2;
806 TopExp::Vertices(E ,V1 ,V2 );
807 if (HasSingularity && BRep_Tool::Degenerated(E))
809 if (Created.IsBound(E)) {
810 const TopoDS_Edge& OE = TopoDS::Edge(Created(E));
811 TopExp::Vertices(OE,OV1,OV2);
812 if (!MapSS.IsBound(V1)) MapSS.Bind(V1,OV1);
813 if (!MapSS.IsBound(V2)) MapSS.Bind(V2,OV2);
815 if (Created.IsBound(V1)) {
816 if (!MapSS.IsBound(V1)) MapSS.Bind(V1,Created(V1));
818 if (Created.IsBound(V2)) {
819 if (!MapSS.IsBound(V2)) MapSS.Bind(V2,Created(V2));
823 TopExp_Explorer expw(CurFace, TopAbs_WIRE);
824 for ( ; expw.More(); expw.Next()) {
825 const TopoDS_Wire& W = TopoDS::Wire(expw.Current());
826 TopExp_Explorer expe(W.Oriented(TopAbs_FORWARD),
829 myBuilder.MakeWire(OW);
830 for ( ; expe.More(); expe.Next()) {
831 const TopoDS_Edge& E = TopoDS::Edge(expe.Current());
833 TopExp::Vertices(E,V1,V2);
836 Standard_Real vstart, vend;
838 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,CurFace,f,l);
840 if (MapSS.IsBound(E) &&
841 !VonDegen.Contains(V1) && !VonDegen.Contains(V2)) { // c`est un edge de couture
842 OE = TopoDS::Edge(MapSS(E));
843 TopoDS_Shape aLocalShape = E.Reversed();
844 Handle(Geom2d_Curve) C2d_1 =
845 BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),CurFace,f,l);
846 // Handle(Geom2d_Curve) C2d_1 =
847 // BRep_Tool::CurveOnSurface(TopoDS::Edge(E.Reversed()),CurFace,f,l);
848 if ( E.Orientation() == TopAbs_FORWARD)
849 UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E));
851 UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E));
852 myBuilder.Range(OE,f,l);
855 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
856 TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape);
857 P2d1 = C2d->Value(BRep_Tool::Parameter(V1,Eforward,CurFace));
858 P2d2 = C2d->Value(BRep_Tool::Parameter(V2,Eforward,CurFace));
859 if (VonDegen.Contains(V1))
861 if (Abs(P2d1.Y() - vf1) <= Precision::Confusion())
863 P1 = MinApex; vstart = v1;
867 P1 = MaxApex; vstart = v2;
872 TheSurf->D0(P2d1.X(),P2d1.Y(),P1);
873 P1.Transform(L.Transformation());
876 if (VonDegen.Contains(V2))
878 if (Abs(P2d2.Y() - vf1) <= Precision::Confusion())
880 P2 = MinApex; vend = v1;
884 P2 = MaxApex; vend = v2;
889 TheSurf->D0(P2d2.X(),P2d2.Y(),P2);
890 P2.Transform(L.Transformation());
893 // E a-t-il ume image dans la Map des Created ?
894 if ( Created.IsBound(E)) {
895 OE = TopoDS::Edge(Created(E));
897 else if (MapSS.IsBound(E)) //seam edge
898 OE = TopoDS::Edge(MapSS(E));
900 myBuilder.MakeEdge(OE);
901 TopoDS_Vertex OV1,OV2;
902 if ( MapSS.IsBound(V1)) {
903 OV1 = TopoDS::Vertex(MapSS(V1));
906 myBuilder.MakeVertex(OV1);
907 myBuilder.UpdateVertex(OV1,P1,BRep_Tool::Tolerance(V1));
910 if ( MapSS.IsBound(V2)) {
911 OV2 = TopoDS::Vertex(MapSS(V2));
914 myBuilder.MakeVertex(OV2);
915 myBuilder.UpdateVertex(OV2,P2,BRep_Tool::Tolerance(V2));
918 myBuilder.Add(OE,OV1.Oriented(V1.Orientation()));
919 myBuilder.Add(OE,OV2.Oriented(V2.Orientation()));
920 if (BRep_Tool::Degenerated(E)) {
921 myBuilder.Degenerated(OE, Standard_True);
926 P2d = C2d->Value(f); TheSurf->D0(P2d.X(),P2d.Y(),P1);
927 P2d = C2d->Value(l); TheSurf->D0(P2d.X(),P2d.Y(),P2);
928 Standard_Real Tol = BRep_Tool::Tolerance(V1);
929 if (!P1.IsEqual(P2,Tol)) {
930 cout <<"BRepOffset_Offset : E degenerated -> OE not degenerated"<<endl;
936 if (VonDegen.Contains(V1) || VonDegen.Contains(V2))
938 if (VonDegen.Contains(V1))
940 if (VonDegen.Contains(V2))
942 C2d = new Geom2d_Line( P2d1, gp_Vec2d(P2d1, P2d2) );
943 f = 0.; l = P2d1.Distance( P2d2 );
944 if (MapSS.IsBound(E)) //seam edge
946 Handle(Geom2d_Curve) C2d_1 = BRep_Tool::CurveOnSurface(OE, myFace, f, l);
947 if (E.Orientation() == TopAbs_FORWARD)
948 UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E));
950 UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E));
953 UpdateEdge(OE,C2d,myFace,BRep_Tool::Tolerance(E));
954 //myBuilder.Range(OE,f,l);
955 myBuilder.Range(OE, myFace, f, l);
956 if (!BRep_Tool::Degenerated(E) && TheSurf->IsUClosed())
958 TopoDS_Shape aLocalShape = E.Reversed();
959 Handle(Geom2d_Curve) C2d_1 =
960 BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),CurFace,f,l);
961 P2d1 = C2d_1->Value(BRep_Tool::Parameter(V1,E,CurFace));
962 P2d2 = C2d_1->Value(BRep_Tool::Parameter(V2,E,CurFace));
963 if (VonDegen.Contains(V1))
965 if (VonDegen.Contains(V2))
967 C2d_1 = new Geom2d_Line( P2d1, gp_Vec2d(P2d1, P2d2) );
968 if ( E.Orientation() == TopAbs_FORWARD)
969 UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E));
971 UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E));
974 if (!BRep_Tool::Degenerated(E))
976 Handle(Geom_Line) theLine = new Geom_Line( P1, gp_Vec(P1, P2) );
977 myBuilder.UpdateEdge( OE, theLine, BRep_Tool::Tolerance(E) );
983 UpdateEdge(OE,C2d,myFace,BRep_Tool::Tolerance(E));
984 myBuilder.Range(OE,f,l);
985 //ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E));
987 if (!BRep_Tool::Degenerated(OE))
988 ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E));
991 myBuilder.Add(OW, OE.Oriented(E.Orientation()));
993 myBuilder.Add(myFace, OW.Oriented(W.Orientation()));
996 myFace.Orientation(Face.Orientation());
998 BRepTools::Update(myFace);
1002 //=======================================================================
1005 //=======================================================================
1007 void BRepOffset_Offset::Init(const TopoDS_Edge& Path,
1008 const TopoDS_Edge& Edge1,
1009 const TopoDS_Edge& Edge2,
1010 const Standard_Real Offset,
1011 const Standard_Boolean Polynomial,
1012 const Standard_Real Tol,
1013 const GeomAbs_Shape Conti)
1015 TopoDS_Edge FirstEdge,LastEdge;
1016 Init(Path,Edge1,Edge2,Offset,FirstEdge,LastEdge,Polynomial,Tol,Conti);
1020 //=======================================================================
1023 //=======================================================================
1025 void BRepOffset_Offset::Init(const TopoDS_Edge& Path,
1026 const TopoDS_Edge& Edge1,
1027 const TopoDS_Edge& Edge2,
1028 const Standard_Real Offset,
1029 const TopoDS_Edge& FirstEdge,
1030 const TopoDS_Edge& LastEdge,
1031 const Standard_Boolean Polynomial,
1032 const Standard_Real Tol,
1033 const GeomAbs_Shape Conti)
1035 Standard_Boolean C1Denerated = Standard_False;
1036 Standard_Boolean C2Denerated = Standard_False;
1037 myStatus = BRepOffset_Good;
1040 TopLoc_Location Loc;
1041 Standard_Real f[3],l[3];
1043 Handle(Geom_Curve) CP = BRep_Tool::Curve(Path,Loc,f[0],l[0]);
1044 CP = new Geom_TrimmedCurve(CP,f[0], l[0]);
1045 CP->Transform(Loc.Transformation());
1046 Handle(GeomAdaptor_HCurve) HCP = new GeomAdaptor_HCurve(CP);
1048 Handle(Geom_Curve) C1 = BRep_Tool::Curve(Edge1,Loc,f[1],l[1]);
1050 Handle(Adaptor3d_HCurve) HEdge1;
1051 Standard_Boolean C1is3D = Standard_True;
1053 C1is3D = Standard_False;
1054 Handle(Geom2d_Curve) C12d;
1055 Handle(Geom_Surface) S1;
1056 BRep_Tool::CurveOnSurface(Edge1,C12d,S1,Loc,f[1],l[1]);
1057 S1 = Handle(Geom_Surface)::DownCast(S1->Transformed(Loc.Transformation()));
1058 C12d = new Geom2d_TrimmedCurve(C12d,f[1],l[1]);
1059 Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(S1);
1060 Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C12d);
1061 Adaptor3d_CurveOnSurface Cons(HC1,HS1);
1062 HEdge1 = new Adaptor3d_HCurveOnSurface(Cons);
1065 C1 = new Geom_TrimmedCurve(C1, f[1], l[1]);
1066 C1->Transform(Loc.Transformation());
1067 HEdge1 = new GeomAdaptor_HCurve(C1);
1068 GeomAdaptor_Curve AC1(C1);
1069 if ( AC1.GetType() == GeomAbs_Circle) {
1070 C1Denerated = (AC1.Circle().Radius() < Precision::Confusion());
1074 Handle(Geom_Curve) C2 = BRep_Tool::Curve(Edge2,Loc,f[2],l[2]);
1076 Handle(Adaptor3d_HCurve) HEdge2;
1077 Standard_Boolean C2is3D = Standard_True;
1079 C2is3D = Standard_False;
1080 Handle(Geom2d_Curve) C12d;
1081 Handle(Geom_Surface) S1;
1082 BRep_Tool::CurveOnSurface(Edge2,C12d,S1,Loc,f[2],l[2]);
1083 S1 = Handle(Geom_Surface)::DownCast(S1->Transformed(Loc.Transformation()));
1084 C12d = new Geom2d_TrimmedCurve(C12d,f[2],l[2]);
1085 Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(S1);
1086 Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C12d);
1087 Adaptor3d_CurveOnSurface Cons(HC1,HS1);
1088 HEdge2 = new Adaptor3d_HCurveOnSurface(Cons);
1091 C2 = new Geom_TrimmedCurve(C2, f[2], l[2]);
1092 C2->Transform(Loc.Transformation());
1093 HEdge2 = new GeomAdaptor_HCurve(C2);
1094 GeomAdaptor_Curve AC2(C2);
1095 if ( AC2.GetType() == GeomAbs_Circle) {
1096 C2Denerated = (AC2.Circle().Radius() < Precision::Confusion());
1101 GeomFill_Pipe Pipe(HCP, HEdge1, HEdge2, Abs(Offset));
1102 Pipe.Perform(Tol, Polynomial, Conti);
1103 Standard_Real ErrorPipe = Pipe.ErrorOnSurf();
1105 Handle(Geom_Surface) S = Pipe.Surface();
1106 Standard_Boolean ExchUV = Pipe.ExchangeUV();
1107 Standard_Real f1,l1,f2,l2;
1108 S->Bounds(f1,l1,f2,l2);
1111 Standard_Real PathTol = BRep_Tool::Tolerance(Path);
1112 Standard_Real TheTol;
1113 BRep_Builder myBuilder;
1114 myBuilder.MakeFace(myFace);
1116 myBuilder.UpdateFace(myFace,S,Id,PathTol);
1118 // update de Edge1. (Rem : has already a 3d curve)
1119 Standard_Real U,U1,U2;
1120 Handle(Geom2d_Curve) PC;
1122 PC = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0));
1125 if (!C1is3D) C1 = S->VIso(f2);
1128 PC = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1));
1131 if (!C1is3D) C1 = S->UIso(f1);
1134 Handle(Geom_Curve) Dummy;
1136 UpdateEdge(Edge1,C1,Id,BRep_Tool::Tolerance(Edge1));
1137 else if ( C1Denerated) {
1138 UpdateEdge(Edge1,Dummy,Id,BRep_Tool::Tolerance(Edge1));
1139 myBuilder.Degenerated(Edge1,Standard_True);
1142 TheTol = Max(PathTol, BRep_Tool::Tolerance(Edge1) + ErrorPipe);
1143 UpdateEdge(Edge1, PC, myFace, TheTol);
1145 // mise a same range de la nouvelle pcurve.
1146 if ( !C1is3D && !C1Denerated)
1148 myBuilder.SameRange (Edge1,Standard_False);
1149 myBuilder.Range(Edge1,U1,U2, Standard_True);
1151 myBuilder.Range(Edge1,myFace,U1,U2);
1152 BRepLib::SameRange(Edge1);
1154 // mise a sameparameter pour les KPart
1155 if (ErrorPipe == 0) {
1156 TheTol = Max(TheTol, Tol);
1157 myBuilder.SameParameter(Edge1,Standard_False);
1158 BRepLib::SameParameter(Edge1, TheTol);
1161 // Update de edge2. (Rem : has already a 3d curve)
1163 PC = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0));
1166 if (!C2is3D) C2 = S->VIso(l2);
1169 PC = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1));
1172 if (!C2is3D) C2 = S->UIso(l1);
1176 UpdateEdge(Edge2,C2,Id,BRep_Tool::Tolerance(Edge2));
1177 else if ( C2Denerated) {
1178 UpdateEdge(Edge2,Dummy,Id,BRep_Tool::Tolerance(Edge2));
1179 myBuilder.Degenerated(Edge2,Standard_True);
1182 TheTol = Max(PathTol, BRep_Tool::Tolerance(Edge2) + ErrorPipe);
1183 UpdateEdge(Edge2, PC, myFace, TheTol);
1185 // mise a same range de la nouvelle pcurve.
1186 myBuilder.SameRange (Edge2,Standard_False);
1187 if ( !C2is3D && !C2Denerated)
1188 myBuilder.Range(Edge2, U1, U2, Standard_True);
1189 myBuilder.Range(Edge2,myFace,U1,U2);
1190 BRepLib::SameRange(Edge2);
1192 // mise a sameparameter pour les KPart
1193 if (ErrorPipe == 0) {
1194 TheTol = Max(TheTol, Tol);
1195 myBuilder.SameParameter(Edge2,Standard_False);
1196 BRepLib::SameParameter(Edge2, TheTol);
1199 TopoDS_Edge Edge3, Edge4;
1201 TopoDS_Vertex V1f,V1l,V2f,V2l;
1202 TopExp::Vertices(Path,V1f,V1l);
1203 Standard_Boolean IsClosed = ( V1f.IsSame(V1l));
1205 TopExp::Vertices(Edge1,V1f,V1l);
1206 TopExp::Vertices(Edge2,V2f,V2l);
1208 Standard_Boolean StartDegenerated = (V1f.IsSame(V2f));
1209 Standard_Boolean EndDegenerated = (V1l.IsSame(V2l));
1211 Standard_Boolean E3rev = Standard_False;
1212 Standard_Boolean E4rev = Standard_False;
1214 TopoDS_Vertex VVf,VVl;
1215 if ( FirstEdge.IsNull()) {
1216 myBuilder.MakeEdge(Edge3);
1217 myBuilder.Add(Edge3,V1f.Oriented(TopAbs_FORWARD));
1218 myBuilder.Add(Edge3,V2f.Oriented(TopAbs_REVERSED));
1221 TopoDS_Shape aLocalEdge = FirstEdge.Oriented(TopAbs_FORWARD);
1222 Edge3 = TopoDS::Edge(aLocalEdge);
1223 // Edge3 = TopoDS::Edge(FirstEdge.Oriented(TopAbs_FORWARD));
1224 TopExp::Vertices(Edge3,VVf,VVl);
1226 // si firstedge n est pas nul, il faut que les vertex soient partages
1227 if ( !VVf.IsSame(V1f) && !VVf.IsSame(V2f) ) {
1228 cout << "Attention Vertex non partages !!!!!!" << endl;
1231 if ( !VVf.IsSame(V1f) && !VVf.IsSame(V2f) ) {
1232 // On fait vraisemblablement des conneries !!
1233 // On cree un autre edge, on appelle le Sewing apres.
1234 myBuilder.MakeEdge(Edge3);
1235 myBuilder.Add(Edge3,V1f.Oriented(TopAbs_FORWARD));
1236 myBuilder.Add(Edge3,V2f.Oriented(TopAbs_REVERSED));
1238 else if ( !VVf.IsSame(V1f)) {
1240 E3rev = Standard_True;
1247 Standard_Real TolApp = Precision::Approximation();
1249 Handle(Geom2d_Line) L1,L2;
1252 // rem : si ExchUv, il faut reverser le Wire.
1253 // donc l'edge Forward dans la face sera E4 : d'ou L1 et L2
1254 L2 = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1));
1255 L1 = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1));
1260 L1 = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0));
1261 L2 = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0));
1266 L1->Reverse(); L2->Reverse();
1271 UpdateEdge(Edge3, L1, L2, myFace,PathTol);
1272 myBuilder.Range(Edge3,myFace,U1,U2);
1273 if (StartDegenerated)
1274 myBuilder.Degenerated(Edge3,Standard_True);
1275 else if (FirstEdge.IsNull()) // then the 3d curve has not been yet computed
1276 ComputeCurve3d(Edge3,L1,S,Id,TolApp);
1279 if ( LastEdge.IsNull()) {
1280 myBuilder.MakeEdge(Edge4);
1281 myBuilder.Add(Edge4,V1l.Oriented(TopAbs_FORWARD));
1282 myBuilder.Add(Edge4,V2l.Oriented(TopAbs_REVERSED));
1285 TopoDS_Shape aLocalEdge = LastEdge.Oriented(TopAbs_FORWARD);
1286 Edge4 = TopoDS::Edge(aLocalEdge);
1287 // Edge4 = TopoDS::Edge(LastEdge.Oriented(TopAbs_FORWARD));
1288 TopExp::Vertices(Edge4,VVf,VVl);
1290 // si lastedge n est pas nul, il faut que les vertex soient partages
1291 if ( !VVf.IsSame(V1l) && !VVf.IsSame(V2l) ) {
1292 cout << "Attention Vertex non partages !!!!!!" << endl;
1295 if ( !VVf.IsSame(V1l) && !VVf.IsSame(V2l) ) {
1296 // On fait vraisemblablement des conneries !!
1297 // On cree un autre edge, on appelle le Sewing apres.
1298 myBuilder.MakeEdge(Edge4);
1299 myBuilder.Add(Edge4,V1l.Oriented(TopAbs_FORWARD));
1300 myBuilder.Add(Edge4,V2l.Oriented(TopAbs_REVERSED));
1302 else if ( !VVf.IsSame(V1l)) {
1304 E4rev = Standard_True;
1309 L1 = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1));
1314 L1 = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0));
1324 UpdateEdge(Edge3,L1,myFace,PathTol);
1325 myBuilder.Range(Edge3,myFace,U1,U2);
1326 if (StartDegenerated)
1327 myBuilder.Degenerated(Edge3,Standard_True);
1328 else if (FirstEdge.IsNull()) // then the 3d curve has not been yet computed
1329 ComputeCurve3d(Edge3,L1,S,Id,TolApp);
1332 L2 = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1));
1337 L2 = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0));
1347 UpdateEdge(Edge4,L2 ,myFace,PathTol);
1348 myBuilder.Range(Edge4,myFace,U1,U2);
1350 myBuilder.Degenerated(Edge4,Standard_True);
1351 else if (LastEdge.IsNull()) // then the 3d curve has not been yet computed
1352 ComputeCurve3d(Edge4,L2,S,Id,TolApp);
1356 if ( !FirstEdge.IsNull() && !StartDegenerated) {
1357 BRepLib::BuildCurve3d (Edge3,PathTol);
1358 myBuilder.SameRange (Edge3,Standard_False);
1359 myBuilder.SameParameter(Edge3,Standard_False);
1360 BRepLib::SameParameter (Edge3, Tol);
1362 if ( !LastEdge.IsNull() && !EndDegenerated) {
1363 BRepLib::BuildCurve3d (Edge4,PathTol);
1364 myBuilder.SameRange (Edge4,Standard_False);
1365 myBuilder.SameParameter(Edge4,Standard_False);
1366 BRepLib::SameParameter (Edge4, Tol);
1370 myBuilder.MakeWire(W);
1372 myBuilder.Add(W, Edge1.Oriented(TopAbs_REVERSED));
1373 myBuilder.Add(W, Edge2.Oriented(TopAbs_FORWARD));
1374 myBuilder.Add(W, Edge4.Reversed());
1375 myBuilder.Add(W, Edge3);
1381 myBuilder.Add(myFace, W);
1382 if (ExchUV) myFace.Reverse();
1384 BRepTools::Update(myFace);
1386 if ( Edge1.Orientation() == TopAbs_REVERSED)
1392 //=======================================================================
1395 //=======================================================================
1397 void BRepOffset_Offset::Init(const TopoDS_Vertex& Vertex,
1398 const TopTools_ListOfShape& LEdge,
1399 const Standard_Real Offset,
1400 const Standard_Boolean Polynomial,
1401 const Standard_Real TolApp,
1402 const GeomAbs_Shape Conti)
1404 myStatus = BRepOffset_Good;
1407 // evaluate the Ax3 of the Sphere
1408 // find 3 different vertices in LEdge
1409 TopTools_ListIteratorOfListOfShape it;
1410 gp_Pnt P, P1, P2, P3;
1411 TopoDS_Vertex V1, V2, V3, V4;
1415 char* name = new char[100];
1419 sprintf(name,"VOnSph_%d",NbOFFSET);
1421 DBRep::Set(name, Vertex);
1423 Standard_Integer NbEdges = 1;
1424 for (it.Initialize(LEdge); it.More(); it.Next()) {
1425 sprintf(name,"EOnSph_%d_%d",NbOFFSET,NbEdges++);
1427 const TopoDS_Shape& CurE = it.Value();
1428 DBRep::Set(name, CurE);
1435 gp_Pnt Origin = BRep_Tool::Pnt(Vertex);
1437 //// Find the axis of the sphere to exclude
1438 //// degenerated and seam edges from the face under construction
1439 BRepLib_MakeWire MW;
1441 TopoDS_Wire theWire = MW.Wire();
1443 ShapeFix_Shape Fixer(theWire);
1445 theWire = TopoDS::Wire(Fixer.Shape());
1447 GProp_GProps GlobalProps;
1448 BRepGProp::LinearProperties(theWire, GlobalProps);
1449 gp_Pnt BaryCenter = GlobalProps.CentreOfMass();
1450 gp_Vec Xdir(BaryCenter, Origin);
1452 gp_Pnt FarestCorner = GetFarestCorner(theWire);
1453 gp_Pln thePlane = gce_MakePln(Origin, BaryCenter, FarestCorner);
1454 gp_Dir Vdir = thePlane.Axis().Direction();
1456 gp_Ax3 Axis(Origin, Vdir, Xdir);
1458 Handle(Geom_Surface) S
1459 = new Geom_SphericalSurface( Axis, Abs(Offset));
1461 Standard_Real f, l, Tol = BRep_Tool::Tolerance(Vertex);
1463 TopLoc_Location Loc;
1464 BRep_Builder myBuilder;
1465 myBuilder.MakeFace(myFace);
1466 Handle(Geom_Surface) SS = S;
1468 // En polynomial, calcul de la surface par F(u,v).
1469 // Pas de changement de parametre, donc ProjLib sur la Sphere
1472 GeomConvert_ApproxSurface Approx(S,TolApp,Conti,Conti,10,10,10,1);
1473 if (Approx.IsDone()) {
1474 SS = Approx.Surface();
1478 myBuilder.UpdateFace(myFace, SS, Loc, Tol);
1481 myBuilder.MakeWire(W);
1487 sprintf(name,"SPHERE_%d",NbOFFSET);
1488 DrawTrSurf::Set(name, S);
1490 Standard_Integer CO = 1;
1493 for ( it.Initialize(LEdge); it.More(); it.Next()) {
1494 TopoDS_Edge E = TopoDS::Edge(it.Value());
1496 Handle(Geom_Curve) C = BRep_Tool::Curve(E,Loc,f,l);
1498 BRepLib::BuildCurve3d(E,BRep_Tool::Tolerance(E));
1499 C = BRep_Tool::Curve(E,Loc,f,l);
1501 C = new Geom_TrimmedCurve(C, f, l);
1502 C->Transform(Loc.Transformation());
1506 sprintf(name,"CURVE_%d_%d",NbOFFSET,CO);
1507 DrawTrSurf::Set(name, C);
1512 Handle(Geom2d_Curve) PCurve = GeomProjLib::Curve2d(C, S);
1513 // check if the first point of PCurve in is the canonical boundaries
1514 // of the sphere. Else move it.
1515 // the transformation is : U` = U + PI + 2 k PI
1516 // V` = +/- PI + 2 k` PI
1517 gp_Pnt2d P2d = PCurve->Value(f);
1518 Standard_Boolean IsToAdjust = Standard_False;
1519 if ( P2d.Y() < -M_PI/2.) {
1520 IsToAdjust = Standard_True;
1521 PCurve->Mirror(gp_Ax2d(gp_Pnt2d(0.,-M_PI/2.),gp::DX2d()));
1523 else if ( P2d.Y() > M_PI/2.) {
1524 IsToAdjust = Standard_True;
1525 PCurve->Mirror(gp_Ax2d(gp_Pnt2d(0., M_PI/2.),gp::DX2d()));
1528 // set the u firstpoint in [0,2*pi]
1529 gp_Vec2d Tr( M_PI, 0.);
1530 if ( P2d.X() > M_PI) Tr.Reverse();
1531 PCurve->Translate(Tr);
1534 UpdateEdge(E, PCurve, myFace, Tol);
1535 myBuilder.Range(E, myFace, f, l);
1536 myBuilder.Add(W, E);
1539 myBuilder.Add(myFace, W.Oriented(TopAbs_REVERSED));
1543 myBuilder.Add(myFace, W);
1546 BRepTools::Update(myFace);
1550 //=======================================================================
1553 //=======================================================================
1555 void BRepOffset_Offset::Init(const TopoDS_Edge& Edge,
1556 const Standard_Real Offset)
1559 Standard_Real myOffset = Abs(Offset);
1562 TopLoc_Location Loc;
1564 Handle(Geom_Curve) CP = BRep_Tool::Curve(Edge,Loc,f,l);
1565 CP = new Geom_TrimmedCurve(CP,f,l);
1566 CP->Transform(Loc.Transformation());
1568 GeomFill_Pipe Pipe(CP,myOffset);
1571 BRepLib_MakeFace MF(Pipe.Surface(), Precision::Confusion());
1574 if ( Offset < 0.) myFace.Reverse();
1578 //=======================================================================
1581 //=======================================================================
1583 const TopoDS_Face& BRepOffset_Offset::Face() const
1589 //=======================================================================
1590 //function : Generated
1592 //=======================================================================
1594 TopoDS_Shape BRepOffset_Offset::Generated(const TopoDS_Shape& Shape) const
1596 TopoDS_Shape aShape;
1598 switch ( myShape.ShapeType()) {
1602 TopExp_Explorer exp (myShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1603 TopExp_Explorer expo(myFace .Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1604 for ( ; exp.More() && expo.More(); exp.Next(), expo.Next()) {
1605 if ( Shape.IsSame(exp.Current())) {
1606 if ( myShape.Orientation() == TopAbs_REVERSED)
1607 aShape = expo.Current().Reversed();
1609 aShape = expo.Current();
1616 // have generate a pipe.
1618 TopoDS_Vertex V1, V2;
1619 TopExp::Vertices(TopoDS::Edge(myShape), V1, V2);
1621 TopExp_Explorer expf(myFace .Oriented(TopAbs_FORWARD), TopAbs_WIRE);
1622 TopExp_Explorer expo(expf.Current().Oriented(TopAbs_FORWARD),
1627 if ( V2.IsSame(Shape)) {
1628 if ( expf.Current().Orientation() == TopAbs_REVERSED)
1629 aShape = expo.Current().Reversed();
1631 aShape = expo.Current();
1635 if ( expf.Current().Orientation() == TopAbs_REVERSED)
1636 aShape = expo.Current().Reversed();
1638 aShape = expo.Current();
1640 if ( myFace.Orientation() == TopAbs_REVERSED)
1652 //=======================================================================
1655 //=======================================================================
1657 BRepOffset_Status BRepOffset_Offset::Status() const