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_SurfaceOfLinearExtrusion.hxx>
49 #include <Geom_SurfaceOfRevolution.hxx>
50 #include <Geom_Surface.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <GeomAdaptor_Curve.hxx>
53 #include <GeomAdaptor_HCurve.hxx>
54 #include <GeomAdaptor_HSurface.hxx>
55 #include <GeomAdaptor_Surface.hxx>
56 #include <GeomAPI.hxx>
57 #include <GeomAPI_ExtremaCurveCurve.hxx>
58 #include <GeomAPI_ProjectPointOnCurve.hxx>
59 #include <GeomConvert_ApproxSurface.hxx>
60 #include <GeomFill_Pipe.hxx>
61 #include <GeomLib.hxx>
62 #include <GeomProjLib.hxx>
65 #include <gp_Cylinder.hxx>
67 #include <gp_Pnt2d.hxx>
68 #include <gp_Torus.hxx>
69 #include <GProp_GProps.hxx>
70 #include <Precision.hxx>
71 #include <ShapeFix_Shape.hxx>
72 #include <Standard_ConstructionError.hxx>
74 #include <TopExp_Explorer.hxx>
76 #include <TopoDS_Edge.hxx>
77 #include <TopoDS_Face.hxx>
78 #include <TopoDS_Shape.hxx>
79 #include <TopoDS_Vertex.hxx>
80 #include <TopoDS_Wire.hxx>
81 #include <TopTools_IndexedMapOfShape.hxx>
82 #include <TopTools_ListIteratorOfListOfShape.hxx>
83 #include <TopTools_MapOfShape.hxx>
84 #include <TopTools_SequenceOfShape.hxx>
87 static Standard_Boolean Affich = Standard_False;
88 static Standard_Integer NbOFFSET = 0;
91 #include <DrawTrSurf.hxx>
95 #include <Geom_BSplineSurface.hxx>
98 static gp_Pnt GetFarestCorner(const TopoDS_Wire& aWire)
100 TopTools_IndexedMapOfShape Vertices;
101 TopExp::MapShapes(aWire, TopAbs_VERTEX, Vertices);
103 Standard_Real MaxDist = 0.;
105 for (Standard_Integer i = 1; i <= Vertices.Extent(); i++)
106 for (Standard_Integer j = 1; j <= Vertices.Extent(); j++)
108 const TopoDS_Vertex& V1 = TopoDS::Vertex(Vertices(i));
109 const TopoDS_Vertex& V2 = TopoDS::Vertex(Vertices(j));
110 gp_Pnt P1 = BRep_Tool::Pnt(V1);
111 gp_Pnt P2 = BRep_Tool::Pnt(V2);
112 Standard_Real aDist = P1.SquareDistance(P2);
123 //=======================================================================
124 //function : UpdateEdge
126 //=======================================================================
128 static void UpdateEdge(const TopoDS_Edge& E,
129 const Handle(Geom_Curve)& C,
130 const TopLoc_Location& L,
131 const Standard_Real Tol)
133 // Cut curves to avoid copies in the extensions.
135 Handle(Geom_TrimmedCurve) BC = Handle(Geom_TrimmedCurve)::DownCast(C);
137 B.UpdateEdge(E,BC->BasisCurve(),L,Tol);
140 B.UpdateEdge(E,C,L,Tol);
144 //=======================================================================
145 //function : UpdateEdge
147 //=======================================================================
149 static void UpdateEdge(const TopoDS_Edge& E,
150 const Handle(Geom2d_Curve)& C,
151 const TopoDS_Face& F,
152 const Standard_Real Tol)
154 // Cut curves to avoid copies in the extensions.
156 Handle(Geom2d_TrimmedCurve) BC = Handle(Geom2d_TrimmedCurve)::DownCast(C);
158 B.UpdateEdge(E,BC->BasisCurve(),F,Tol);
161 B.UpdateEdge(E,C,F,Tol);
165 //=======================================================================
166 //function : UpdateEdge
168 //=======================================================================
170 static void UpdateEdge (const TopoDS_Edge& E,
171 const Handle(Geom2d_Curve)& C1,
172 const Handle(Geom2d_Curve)& C2,
173 const TopoDS_Face& F,
174 const Standard_Real Tol)
176 // Cut curves to avoid copies in the extensions.
178 Handle(Geom2d_Curve) NC1,NC2;
179 Handle(Geom2d_TrimmedCurve) BC1 = Handle(Geom2d_TrimmedCurve)::DownCast(C1);
180 Handle(Geom2d_TrimmedCurve) BC2 = Handle(Geom2d_TrimmedCurve)::DownCast(C2);
181 if (!BC1.IsNull()) NC1 = BC1->BasisCurve(); else NC1 = C1;
182 if (!BC2.IsNull()) NC2 = BC2->BasisCurve(); else NC2 = C2;
183 B.UpdateEdge(E,NC1,NC2,F,Tol);
187 //=======================================================================
188 //function : ComputeCurve3d
189 //purpose : Particular case of Curve On Surface.
190 //=======================================================================
192 static void ComputeCurve3d(TopoDS_Edge Edge,
193 const Handle(Geom2d_Curve)& Curve,
194 const Handle(Geom_Surface)& Surf,
195 const TopLoc_Location Loc,
198 // try to find the particular case
199 // if not found call BRepLib::BuildCurve3d
201 Standard_Boolean IsComputed = Standard_False;
203 // Search only isos on analytic surfaces.
204 Geom2dAdaptor_Curve C(Curve);
205 GeomAdaptor_Surface S(Surf);
206 GeomAbs_CurveType CTy = C.GetType();
207 GeomAbs_SurfaceType STy = S.GetType();
208 BRep_Builder TheBuilder;
210 if ( STy != GeomAbs_Plane) { // if plane buildcurve3d manage KPart
211 if ( CTy == GeomAbs_Line) {
212 gp_Dir2d D = C.Line().Direction();
213 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
214 if ( STy == GeomAbs_Sphere) {
215 gp_Pnt2d P = C.Line().Location();
216 if ( Abs( Abs(P.Y()) -M_PI/2. ) < Precision::PConfusion()) {
217 TheBuilder.Degenerated(Edge, Standard_True);
220 gp_Sphere Sph = S.Sphere();
221 gp_Ax3 Axis = Sph.Position();
222 gp_Circ Ci = ElSLib::SphereVIso(Axis,
225 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
226 gp_Ax1 AxeRev(Axis.Location(), DRev);
227 Ci.Rotate(AxeRev, P.X());
228 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
229 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
231 UpdateEdge(Edge, Circle, Loc, Tol);
233 IsComputed = Standard_True;
235 else if ( STy == GeomAbs_Cylinder) {
236 gp_Cylinder Cyl = S.Cylinder();
237 gp_Pnt2d P = C.Line().Location();
238 gp_Ax3 Axis = Cyl.Position();
239 gp_Circ Ci = ElSLib::CylinderVIso(Axis,
242 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
243 gp_Ax1 AxeRev(Axis.Location(), DRev);
244 Ci.Rotate(AxeRev, P.X());
245 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
246 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
248 UpdateEdge(Edge, Circle, Loc, Tol);
249 IsComputed = Standard_True;
251 else if ( STy == GeomAbs_Cone) {
252 gp_Cone Cone = S.Cone();
253 gp_Pnt2d P = C.Line().Location();
254 gp_Ax3 Axis = Cone.Position();
255 gp_Circ Ci = ElSLib::ConeVIso(Axis,
259 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
260 gp_Ax1 AxeRev(Axis.Location(), DRev);
261 Ci.Rotate(AxeRev, P.X());
262 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
263 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
265 UpdateEdge(Edge, Circle, Loc, Tol);
266 IsComputed = Standard_True;
268 else if ( STy == GeomAbs_Torus) {
269 gp_Torus Tore = S.Torus();
270 gp_Pnt2d P = C.Line().Location();
271 gp_Ax3 Axis = Tore.Position();
272 gp_Circ Ci = ElSLib::TorusVIso(Axis,
276 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
277 gp_Ax1 AxeRev(Axis.Location(), DRev);
278 Ci.Rotate(AxeRev, P.X());
279 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
280 if ( D.IsOpposite(gp::DX2d(),Precision::Angular()))
282 UpdateEdge(Edge, Circle, Loc, Tol);
283 IsComputed = Standard_True;
286 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
287 if ( STy == GeomAbs_Sphere) {
288 gp_Sphere Sph = S.Sphere();
289 gp_Pnt2d P = C.Line().Location();
290 gp_Ax3 Axis = Sph.Position();
292 gp_Circ Ci = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
294 // set to sameparameter (rotation of circle - offset of Y)
295 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
296 gp_Ax1 AxeRev(Axis.Location(),DRev);
297 Ci.Rotate(AxeRev, P.Y());
299 // transformation en iso U ( = P.X())
300 DRev = Axis.XDirection().Crossed(Axis.YDirection());
301 AxeRev = gp_Ax1(Axis.Location(), DRev);
302 Ci.Rotate(AxeRev, P.X());
303 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
305 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
307 UpdateEdge(Edge, Circle, Loc, Tol);
308 IsComputed = Standard_True;
310 else if ( STy == GeomAbs_Cylinder) {
311 gp_Cylinder Cyl = S.Cylinder();
312 gp_Pnt2d P = C.Line().Location();
313 gp_Lin L = ElSLib::CylinderUIso(Cyl.Position(),
316 gp_Vec Tr(L.Direction());
319 Handle(Geom_Line) Line = new Geom_Line(L);
320 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
322 UpdateEdge(Edge, Line, Loc, Tol);
323 IsComputed = Standard_True;
325 else if ( STy == GeomAbs_Cone) {
326 gp_Cone Cone = S.Cone();
327 gp_Pnt2d P = C.Line().Location();
328 gp_Lin L = ElSLib::ConeUIso(Cone.Position(),
332 gp_Vec Tr(L.Direction());
334 L.Translate(Tr); Handle(Geom_Line) Line = new Geom_Line(L);
335 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
337 UpdateEdge(Edge, Line, Loc, Tol);
338 IsComputed = Standard_True;
340 else if ( STy == GeomAbs_Torus) {
341 gp_Torus Tore = S.Torus();
342 gp_Pnt2d P = C.Line().Location();
343 gp_Ax3 Axis = Tore.Position();
344 gp_Circ Ci = ElSLib::TorusUIso(Axis,
348 Ci.Rotate(Ci.Axis(),P.Y());
349 Handle(Geom_Circle) Circle = new Geom_Circle(Ci);
351 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
353 UpdateEdge(Edge, Circle, Loc, Tol);
354 IsComputed = Standard_True;
360 Handle(Geom_Curve) C3d = GeomAPI::To3d(Curve,S.Plane());
361 UpdateEdge(Edge, C3d, Loc, Tol);
362 IsComputed = Standard_True;
365 //BRepLib::BuildCurves3d(Edge,Tol);
366 //Les Courbes 3d des edges dans le cas general ne sont calcules que si
368 //ie dans les tuyaux et les bouchons ..
369 // dans la derniere etapes de MakeShells on reconstruira les courbes3d
370 // des edges du resultat qui n en ont pas.
375 //=======================================================================
376 //function : BRepOffset_Offset
378 //=======================================================================
380 BRepOffset_Offset::BRepOffset_Offset()
385 //=======================================================================
386 //function : BRepOffset_Offset
388 //=======================================================================
390 BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Face& Face,
391 const Standard_Real Offset,
392 const Standard_Boolean OffsetOutside,
393 const GeomAbs_JoinType JoinType)
395 Init(Face, Offset, OffsetOutside, JoinType);
399 //=======================================================================
400 //function : BRepOffset_Offset
402 //=======================================================================
404 BRepOffset_Offset::BRepOffset_Offset
405 (const TopoDS_Face& Face,
406 const Standard_Real Offset,
407 const TopTools_DataMapOfShapeShape& Created,
408 const Standard_Boolean OffsetOutside,
409 const GeomAbs_JoinType JoinType)
411 Init(Face,Offset,Created,OffsetOutside,JoinType);
415 //=======================================================================
416 //function : BRepOffset_Offset
418 //=======================================================================
420 BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Edge& Path,
421 const TopoDS_Edge& Edge1,
422 const TopoDS_Edge& Edge2,
423 const Standard_Real Offset,
424 const Standard_Boolean Polynomial,
425 const Standard_Real Tol,
426 const GeomAbs_Shape Conti)
428 Init(Path,Edge1,Edge2,Offset,Polynomial,Tol,Conti);
432 //=======================================================================
433 //function : BRepOffset_Offset
435 //=======================================================================
437 BRepOffset_Offset::BRepOffset_Offset
438 (const TopoDS_Edge& Path,
439 const TopoDS_Edge& Edge1,
440 const TopoDS_Edge& Edge2,
441 const Standard_Real Offset,
442 const TopoDS_Edge& FirstEdge,
443 const TopoDS_Edge& LastEdge,
444 const Standard_Boolean Polynomial,
445 const Standard_Real Tol,
446 const GeomAbs_Shape Conti)
448 Init(Path,Edge1,Edge2,Offset,FirstEdge,LastEdge,Polynomial,Tol,Conti);
452 //=======================================================================
453 //function : BRepOffset_Offset
455 //=======================================================================
457 BRepOffset_Offset::BRepOffset_Offset(const TopoDS_Vertex& Vertex,
458 const TopTools_ListOfShape& LEdge,
459 const Standard_Real Offset,
460 const Standard_Boolean Polynomial,
461 const Standard_Real Tol,
462 const GeomAbs_Shape Conti)
464 Init(Vertex,LEdge,Offset,Polynomial,Tol,Conti);
468 //=======================================================================
471 //=======================================================================
473 void BRepOffset_Offset::Init(const TopoDS_Face& Face,
474 const Standard_Real Offset,
475 const Standard_Boolean OffsetOutside,
476 const GeomAbs_JoinType JoinType)
478 TopTools_DataMapOfShapeShape Empty;
479 Init(Face,Offset,Empty,OffsetOutside,JoinType);
483 //=======================================================================
486 //=======================================================================
488 void BRepOffset_Offset::Init(const TopoDS_Face& Face,
489 const Standard_Real Offset,
490 const TopTools_DataMapOfShapeShape& Created,
491 const Standard_Boolean OffsetOutside,
492 const GeomAbs_JoinType JoinType)
495 Standard_Real myOffset = Offset;
496 if ( Face.Orientation() == TopAbs_REVERSED)
500 Handle(Geom_Surface) S = BRep_Tool::Surface(Face,L);
501 // On detrime les surfaces, evite des recopies dans les extensions.
502 Handle(Geom_RectangularTrimmedSurface) RT =
503 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
504 if (!RT.IsNull()) S = RT->BasisSurface();
505 Standard_Boolean IsTransformed = Standard_False;
506 if ((S->IsKind(STANDARD_TYPE(Geom_BSplineSurface)) ||
507 S->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) ||
508 S->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)) ||
509 S->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) && !L.IsIdentity())
511 S = Handle(Geom_Surface)::DownCast(S->Copy());
512 S->Transform(L.Transformation());
513 IsTransformed = Standard_True;
515 // particular case of cone
516 Handle(Geom_ConicalSurface) Co;
517 Co = Handle(Geom_ConicalSurface)::DownCast(S);
520 gp_Pnt Apex = Co->Apex();
521 ElSLib::Parameters( Co->Cone(),Apex,Uc,Vc);
522 Standard_Real UU1,UU2,VV1,VV2;
523 BRepTools::UVBounds(Face,UU1,UU2,VV1,VV2);
524 if ( VV2 < Vc && Co->SemiAngle() > 0 )
526 else if ( VV1 > Vc && Co->SemiAngle() < 0 )
528 if ( !Co->Position().Direct()) myOffset *= -1;
531 Handle(Geom_Surface) TheSurf =
532 BRepOffset::Surface( S, myOffset, myStatus);
534 //processing offsets of faces with possible degenerated edges
535 Standard_Boolean UminDegen = Standard_False;
536 Standard_Boolean UmaxDegen = Standard_False;
537 Standard_Boolean VminDegen = Standard_False;
538 Standard_Boolean VmaxDegen = Standard_False;
539 Standard_Boolean UisoDegen = Standard_False;
540 gp_Pnt MinApex, MaxApex;
541 Standard_Boolean HasSingularity = Standard_False;
542 Standard_Real uf1, uf2, vf1, vf2, fpar, lpar;
543 BRepTools::UVBounds(Face, uf1, uf2, vf1, vf2);
544 if (!(OffsetOutside && JoinType == GeomAbs_Arc) &&
545 (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface) ||
546 TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)))
548 TopTools_SequenceOfShape DegEdges;
549 TopExp_Explorer Explo(Face, TopAbs_EDGE);
550 for (; Explo.More(); Explo.Next())
552 const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
554 if (BRep_Tool::Degenerated(anEdge))
556 Standard_Real aF, aL;
557 Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface(anEdge, Face, aF, aL);
559 gp_Pnt2d aFPnt2d = c2d->Value(aF),
560 aLPnt2d = c2d->Value(aL);
562 gp_Pnt aFPnt = S->Value(aFPnt2d.X(), aFPnt2d.Y()),
563 aLPnt = S->Value(aLPnt2d.X(), aLPnt2d.Y());
565 // aFPnt.SquareDistance(aLPnt) > Precision::SquareConfusion() -
566 // is a sufficient condition of troubles: non-singular case, but edge is degenerated.
567 // So, normal handling of degenerated edges is not applicable in case of non-singular point.
568 if (aFPnt.SquareDistance(aLPnt) < Precision::SquareConfusion())
570 DegEdges.Append(anEdge);
574 if (!DegEdges.IsEmpty())
576 const Standard_Real TolApex = 1.e-5;
577 //define the iso of singularity (u or v)
578 TopoDS_Edge theDegEdge = TopoDS::Edge(DegEdges(1));
579 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar);
580 gp_Pnt2d fp2d = aCurve->Value(fpar);
581 gp_Pnt2d lp2d = aCurve->Value(lpar);
582 if (Abs(fp2d.X() - lp2d.X()) <= Precision::PConfusion())
583 UisoDegen = Standard_True;
585 if (DegEdges.Length() == 2)
588 { UminDegen = Standard_True; UmaxDegen = Standard_True; }
590 { VminDegen = Standard_True; VmaxDegen = Standard_True; }
592 else //DegEdges.Length() == 1
596 if (Abs(fp2d.X() - uf1) <= Precision::Confusion())
597 UminDegen = Standard_True;
599 UmaxDegen = Standard_True;
603 if (Abs(fp2d.Y() - vf1) <= Precision::Confusion())
604 VminDegen = Standard_True;
606 VmaxDegen = Standard_True;
609 if (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
611 gp_Cone theCone = Handle(Geom_ConicalSurface)::DownCast (TheSurf)->Cone();
612 gp_Pnt apex = theCone.Apex();
613 Standard_Real Uapex, Vapex;
614 ElSLib::Parameters( theCone, apex, Uapex, Vapex );
617 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, Vapex, vf2);
619 HasSingularity = Standard_True;
623 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, Vapex);
625 HasSingularity = Standard_True;
628 else //TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)
632 Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
633 if (BRepOffset_Tool::Gabarit( uiso ) > TolApex)
635 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
636 gp_Pnt Papex, Pfirst, Pquart, Pmid;
637 Papex = BasisSurf->Value( uf1, vf1 );
638 Pfirst = TheSurf->Value( uf1, vf1 );
639 Pquart = TheSurf->Value( uf1, 0.75*vf1+0.25*vf2 );
640 Pmid = TheSurf->Value( uf1, 0.5*(vf1+vf2) );
641 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
642 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
643 gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 1, 0 );
644 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
645 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
647 theExtrema.NearestPoints(Pint1, Pint2);
648 Standard_Real length = Pfirst.Distance(Pint1);
651 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
652 GeomLib::ExtendSurfByLength (aSurf, length, 1, Standard_True, Standard_False);
654 Standard_Real u1, u2, v1, v2;
655 TheSurf->Bounds( u1, u2, v1, v2 );
656 MinApex = TheSurf->Value( u1, vf1 );
660 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
661 GeomAPI_ProjectPointOnCurve Projector( Pint1, viso );
662 Standard_Real NewFirstU = Projector.LowerDistanceParameter();
663 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, NewFirstU, uf2, vf1, vf2);
664 MinApex = TheSurf->Value( NewFirstU, vf1 );
666 HasSingularity = Standard_True;
668 } //end of if (UminDegen)
671 Handle(Geom_Curve) uiso = TheSurf->UIso( uf2 );
672 if (BRepOffset_Tool::Gabarit( uiso ) > TolApex)
674 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
675 gp_Pnt Papex, Pfirst, Pquart, Pmid;
676 Papex = BasisSurf->Value( uf2, vf1 );
677 Pfirst = TheSurf->Value( uf2, vf1 );
678 Pquart = TheSurf->Value( uf2, 0.75*vf1+0.25*vf2 );
679 Pmid = TheSurf->Value( uf2, 0.5*(vf1+vf2) );
680 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
681 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
682 gp_Vec DirGeneratrix = BasisSurf->DN( uf2, vf1, 1, 0 );
683 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
684 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
686 theExtrema.NearestPoints(Pint1, Pint2);
687 Standard_Real length = Pfirst.Distance(Pint1);
690 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
691 GeomLib::ExtendSurfByLength(aSurf, length, 1, Standard_True, Standard_True);
693 Standard_Real u1, u2, v1, v2;
694 TheSurf->Bounds( u1, u2, v1, v2 );
695 MaxApex = TheSurf->Value( u2, vf1 );
699 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
700 GeomAPI_ProjectPointOnCurve Projector( Pint1, viso );
701 Standard_Real NewLastU = Projector.LowerDistanceParameter();
702 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, NewLastU, vf1, vf2);
703 MaxApex = TheSurf->Value( NewLastU, vf1 );
705 HasSingularity = Standard_True;
707 } //end of if (UmaxDegen)
710 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
711 if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
713 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
714 gp_Pnt Papex, Pfirst, Pquart, Pmid;
715 Papex = BasisSurf->Value( uf1, vf1 );
716 Pfirst = TheSurf->Value( uf1, vf1 );
717 Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf1 );
718 Pmid = TheSurf->Value( 0.5*(uf1+uf2), vf1 );
719 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
720 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
721 gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 0, 1 );
722 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
723 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
725 theExtrema.NearestPoints(Pint1, Pint2);
726 Standard_Real length = Pfirst.Distance(Pint1);
729 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
730 GeomLib::ExtendSurfByLength(aSurf, length, 1, Standard_False, Standard_False);
732 Standard_Real u1, u2, v1, v2;
733 TheSurf->Bounds( u1, u2, v1, v2 );
734 MinApex = TheSurf->Value( uf1, v1 );
738 Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
739 GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
740 Standard_Real NewFirstV = Projector.LowerDistanceParameter();
741 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, NewFirstV, vf2);
742 MinApex = TheSurf->Value( uf1, NewFirstV );
743 //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1+length, vf2);
744 //MinApex = TheSurf->Value( uf1, vf1+length );
746 HasSingularity = Standard_True;
748 } //end of if (VminDegen)
751 Handle(Geom_Curve) viso = TheSurf->VIso( vf2 );
752 if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
754 Handle(Geom_Surface) BasisSurf = Handle(Geom_OffsetSurface)::DownCast (TheSurf)->BasisSurface();
755 gp_Pnt Papex, Pfirst, Pquart, Pmid;
756 Papex = BasisSurf->Value( uf1, vf2 );
757 Pfirst = TheSurf->Value( uf1, vf2 );
758 Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf2 );
759 Pmid = TheSurf->Value( 0.5*(uf1+uf2), vf2 );
760 gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
761 Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
762 gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf2, 0, 1 );
763 Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
764 GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
766 theExtrema.NearestPoints(Pint1, Pint2);
767 Standard_Real length = Pfirst.Distance(Pint1);
770 Handle(Geom_BoundedSurface) aSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
771 GeomLib::ExtendSurfByLength(aSurf, length, 1, Standard_False, Standard_True);
773 Standard_Real u1, u2, v1, v2;
774 TheSurf->Bounds( u1, u2, v1, v2 );
775 MaxApex = TheSurf->Value( uf1, v2 );
779 Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
780 GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
781 Standard_Real NewLastV = Projector.LowerDistanceParameter();
782 TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, NewLastV);
783 MaxApex = TheSurf->Value( uf1, NewLastV );
784 //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2-length);
785 //MaxApex = TheSurf->Value( uf1, vf2-length );
787 HasSingularity = Standard_True;
789 } //end of if (VmaxDegen)
790 } //end of else (case of Geom_OffsetSurface)
791 } //end of if (!DegEdges.IsEmpty())
792 } //end of processing offsets of faces with possible degenerated edges
794 // find the PCurves of the edges of <Faces>
796 BRep_Builder myBuilder;
797 myBuilder.MakeFace(myFace);
799 myBuilder.UpdateFace(myFace,TheSurf, L, BRep_Tool::Tolerance(Face));
801 myBuilder.UpdateFace(myFace,TheSurf, TopLoc_Location(), BRep_Tool::Tolerance(Face));
803 TopTools_DataMapOfShapeShape MapSS;
805 // mise a jour de la map sur les vertex deja crees
806 TopoDS_Shape aLocalShapeOriented = Face.Oriented(TopAbs_FORWARD);
807 TopoDS_Face CurFace = TopoDS::Face(aLocalShapeOriented);
808 // TopoDS_Face CurFace = TopoDS::Face(Face.Oriented(TopAbs_FORWARD));
810 TopTools_MapOfShape VonDegen;
811 Standard_Real u1, u2, v1, v2;
812 TheSurf->Bounds( u1, u2, v1, v2 );
814 TopExp_Explorer exp(CurFace, TopAbs_EDGE);
815 for ( ; exp.More(); exp.Next()) {
816 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
817 TopoDS_Vertex V1,V2,OV1,OV2;
818 TopExp::Vertices(E ,V1 ,V2 );
819 if (HasSingularity && BRep_Tool::Degenerated(E))
821 if (Created.IsBound(E)) {
822 const TopoDS_Edge& OE = TopoDS::Edge(Created(E));
823 TopExp::Vertices(OE,OV1,OV2);
824 if (!MapSS.IsBound(V1)) MapSS.Bind(V1,OV1);
825 if (!MapSS.IsBound(V2)) MapSS.Bind(V2,OV2);
827 if (Created.IsBound(V1)) {
828 if (!MapSS.IsBound(V1)) MapSS.Bind(V1,Created(V1));
830 if (Created.IsBound(V2)) {
831 if (!MapSS.IsBound(V2)) MapSS.Bind(V2,Created(V2));
835 TopExp_Explorer expw(CurFace, TopAbs_WIRE);
836 for ( ; expw.More(); expw.Next()) {
837 const TopoDS_Wire& W = TopoDS::Wire(expw.Current());
838 TopExp_Explorer expe(W.Oriented(TopAbs_FORWARD),
841 myBuilder.MakeWire(OW);
842 for ( ; expe.More(); expe.Next()) {
843 const TopoDS_Edge& E = TopoDS::Edge(expe.Current());
845 TopExp::Vertices(E,V1,V2);
848 Standard_Real vstart, vend;
850 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,CurFace,f,l);
852 if (MapSS.IsBound(E) &&
853 !VonDegen.Contains(V1) && !VonDegen.Contains(V2)) { // c`est un edge de couture
854 OE = TopoDS::Edge(MapSS(E));
855 TopoDS_Shape aLocalShape = E.Reversed();
856 Handle(Geom2d_Curve) C2d_1 =
857 BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),CurFace,f,l);
858 // Handle(Geom2d_Curve) C2d_1 =
859 // BRep_Tool::CurveOnSurface(TopoDS::Edge(E.Reversed()),CurFace,f,l);
860 if ( E.Orientation() == TopAbs_FORWARD)
861 UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E));
863 UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E));
864 myBuilder.Range(OE,f,l);
867 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
868 TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape);
869 P2d1 = C2d->Value(BRep_Tool::Parameter(V1,Eforward,CurFace));
870 P2d2 = C2d->Value(BRep_Tool::Parameter(V2,Eforward,CurFace));
871 if (VonDegen.Contains(V1))
873 if (Abs(P2d1.Y() - vf1) <= Precision::Confusion())
875 P1 = MinApex; vstart = v1;
879 P1 = MaxApex; vstart = v2;
884 TheSurf->D0(P2d1.X(),P2d1.Y(),P1);
885 if (!L.IsIdentity() && !IsTransformed)
886 P1.Transform(L.Transformation());
889 if (VonDegen.Contains(V2))
891 if (Abs(P2d2.Y() - vf1) <= Precision::Confusion())
893 P2 = MinApex; vend = v1;
897 P2 = MaxApex; vend = v2;
902 TheSurf->D0(P2d2.X(),P2d2.Y(),P2);
903 if (!L.IsIdentity() && !IsTransformed)
904 P2.Transform(L.Transformation());
907 // E a-t-il ume image dans la Map des Created ?
908 if ( Created.IsBound(E)) {
909 OE = TopoDS::Edge(Created(E));
911 else if (MapSS.IsBound(E)) //seam edge
912 OE = TopoDS::Edge(MapSS(E));
914 myBuilder.MakeEdge(OE);
915 TopoDS_Vertex OV1,OV2;
916 if ( MapSS.IsBound(V1)) {
917 OV1 = TopoDS::Vertex(MapSS(V1));
920 myBuilder.MakeVertex(OV1);
921 myBuilder.UpdateVertex(OV1,P1,BRep_Tool::Tolerance(V1));
924 if ( MapSS.IsBound(V2)) {
925 OV2 = TopoDS::Vertex(MapSS(V2));
928 myBuilder.MakeVertex(OV2);
929 myBuilder.UpdateVertex(OV2,P2,BRep_Tool::Tolerance(V2));
932 myBuilder.Add(OE,OV1.Oriented(V1.Orientation()));
933 myBuilder.Add(OE,OV2.Oriented(V2.Orientation()));
934 if (BRep_Tool::Degenerated(E)) {
935 myBuilder.Degenerated(OE, Standard_True);
940 P2d = C2d->Value(f); TheSurf->D0(P2d.X(),P2d.Y(),P1);
941 P2d = C2d->Value(l); TheSurf->D0(P2d.X(),P2d.Y(),P2);
942 Standard_Real Tol = BRep_Tool::Tolerance(V1);
943 if (!P1.IsEqual(P2,Tol)) {
944 std::cout <<"BRepOffset_Offset : E degenerated -> OE not degenerated"<<std::endl;
950 if (VonDegen.Contains(V1) || VonDegen.Contains(V2))
952 if (VonDegen.Contains(V1))
954 if (VonDegen.Contains(V2))
956 C2d = new Geom2d_Line( P2d1, gp_Vec2d(P2d1, P2d2) );
957 f = 0.; l = P2d1.Distance( P2d2 );
958 if (MapSS.IsBound(E)) //seam edge
960 Handle(Geom2d_Curve) C2d_1 = BRep_Tool::CurveOnSurface(OE, myFace, f, l);
961 if (E.Orientation() == TopAbs_FORWARD)
962 UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E));
964 UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E));
967 UpdateEdge(OE,C2d,myFace,BRep_Tool::Tolerance(E));
968 //myBuilder.Range(OE,f,l);
969 myBuilder.Range(OE, myFace, f, l);
970 if (!BRep_Tool::Degenerated(E) && TheSurf->IsUClosed())
972 TopoDS_Shape aLocalShapeReversedE = E.Reversed();
973 Handle(Geom2d_Curve) C2d_1 =
974 BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShapeReversedE),CurFace,f,l);
975 P2d1 = C2d_1->Value(BRep_Tool::Parameter(V1,E,CurFace));
976 P2d2 = C2d_1->Value(BRep_Tool::Parameter(V2,E,CurFace));
977 if (VonDegen.Contains(V1))
979 if (VonDegen.Contains(V2))
981 C2d_1 = new Geom2d_Line( P2d1, gp_Vec2d(P2d1, P2d2) );
982 if ( E.Orientation() == TopAbs_FORWARD)
983 UpdateEdge(OE,C2d,C2d_1,myFace,BRep_Tool::Tolerance(E));
985 UpdateEdge(OE,C2d_1,C2d,myFace,BRep_Tool::Tolerance(E));
988 if (!BRep_Tool::Degenerated(E))
990 Handle(Geom_Line) theLine = new Geom_Line( P1, gp_Vec(P1, P2) );
991 myBuilder.UpdateEdge( OE, theLine, BRep_Tool::Tolerance(E) );
997 UpdateEdge(OE,C2d,myFace,BRep_Tool::Tolerance(E));
998 myBuilder.Range(OE,f,l);
999 //ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E));
1001 if (!BRep_Tool::Degenerated(OE))
1002 ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E));
1005 myBuilder.Add(OW, OE.Oriented(E.Orientation()));
1007 myBuilder.Add(myFace, OW.Oriented(W.Orientation()));
1010 myFace.Orientation(Face.Orientation());
1012 BRepTools::Update(myFace);
1016 //=======================================================================
1019 //=======================================================================
1021 void BRepOffset_Offset::Init(const TopoDS_Edge& Path,
1022 const TopoDS_Edge& Edge1,
1023 const TopoDS_Edge& Edge2,
1024 const Standard_Real Offset,
1025 const Standard_Boolean Polynomial,
1026 const Standard_Real Tol,
1027 const GeomAbs_Shape Conti)
1029 TopoDS_Edge FirstEdge,LastEdge;
1030 Init(Path,Edge1,Edge2,Offset,FirstEdge,LastEdge,Polynomial,Tol,Conti);
1034 //=======================================================================
1037 //=======================================================================
1039 void BRepOffset_Offset::Init(const TopoDS_Edge& Path,
1040 const TopoDS_Edge& Edge1,
1041 const TopoDS_Edge& Edge2,
1042 const Standard_Real Offset,
1043 const TopoDS_Edge& FirstEdge,
1044 const TopoDS_Edge& LastEdge,
1045 const Standard_Boolean Polynomial,
1046 const Standard_Real Tol,
1047 const GeomAbs_Shape Conti)
1049 Standard_Boolean C1Denerated = Standard_False;
1050 Standard_Boolean C2Denerated = Standard_False;
1051 myStatus = BRepOffset_Good;
1054 TopLoc_Location Loc;
1055 Standard_Real f[3],l[3];
1057 Handle(Geom_Curve) CP = BRep_Tool::Curve(Path,Loc,f[0],l[0]);
1058 CP = new Geom_TrimmedCurve(CP,f[0], l[0]);
1059 CP->Transform(Loc.Transformation());
1060 Handle(GeomAdaptor_HCurve) HCP = new GeomAdaptor_HCurve(CP);
1062 Handle(Geom_Curve) C1 = BRep_Tool::Curve(Edge1,Loc,f[1],l[1]);
1064 Handle(Adaptor3d_HCurve) HEdge1;
1065 Standard_Boolean C1is3D = Standard_True;
1067 C1is3D = Standard_False;
1068 Handle(Geom2d_Curve) C12d;
1069 Handle(Geom_Surface) S1;
1070 BRep_Tool::CurveOnSurface(Edge1,C12d,S1,Loc,f[1],l[1]);
1071 S1 = Handle(Geom_Surface)::DownCast(S1->Transformed(Loc.Transformation()));
1072 C12d = new Geom2d_TrimmedCurve(C12d,f[1],l[1]);
1073 Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(S1);
1074 Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C12d);
1075 Adaptor3d_CurveOnSurface Cons(HC1,HS1);
1076 HEdge1 = new Adaptor3d_HCurveOnSurface(Cons);
1079 C1 = new Geom_TrimmedCurve(C1, f[1], l[1]);
1080 C1->Transform(Loc.Transformation());
1081 HEdge1 = new GeomAdaptor_HCurve(C1);
1082 GeomAdaptor_Curve AC1(C1);
1083 if ( AC1.GetType() == GeomAbs_Circle) {
1084 C1Denerated = (AC1.Circle().Radius() < Precision::Confusion());
1088 Handle(Geom_Curve) C2 = BRep_Tool::Curve(Edge2,Loc,f[2],l[2]);
1090 Handle(Adaptor3d_HCurve) HEdge2;
1091 Standard_Boolean C2is3D = Standard_True;
1093 C2is3D = Standard_False;
1094 Handle(Geom2d_Curve) C12d;
1095 Handle(Geom_Surface) S1;
1096 BRep_Tool::CurveOnSurface(Edge2,C12d,S1,Loc,f[2],l[2]);
1097 S1 = Handle(Geom_Surface)::DownCast(S1->Transformed(Loc.Transformation()));
1098 C12d = new Geom2d_TrimmedCurve(C12d,f[2],l[2]);
1099 Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(S1);
1100 Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C12d);
1101 Adaptor3d_CurveOnSurface Cons(HC1,HS1);
1102 HEdge2 = new Adaptor3d_HCurveOnSurface(Cons);
1105 C2 = new Geom_TrimmedCurve(C2, f[2], l[2]);
1106 C2->Transform(Loc.Transformation());
1107 HEdge2 = new GeomAdaptor_HCurve(C2);
1108 GeomAdaptor_Curve AC2(C2);
1109 if ( AC2.GetType() == GeomAbs_Circle) {
1110 C2Denerated = (AC2.Circle().Radius() < Precision::Confusion());
1115 GeomFill_Pipe Pipe(HCP, HEdge1, HEdge2, Abs(Offset));
1116 Pipe.Perform(Tol, Polynomial, Conti);
1118 throw Standard_ConstructionError("GeomFill_Pipe : Cannot make a surface");
1119 Standard_Real ErrorPipe = Pipe.ErrorOnSurf();
1121 Handle(Geom_Surface) S = Pipe.Surface();
1122 Standard_Boolean ExchUV = Pipe.ExchangeUV();
1123 Standard_Real f1,l1,f2,l2;
1124 S->Bounds(f1,l1,f2,l2);
1127 Standard_Real PathTol = BRep_Tool::Tolerance(Path);
1128 Standard_Real TheTol;
1129 BRep_Builder myBuilder;
1130 myBuilder.MakeFace(myFace);
1132 myBuilder.UpdateFace(myFace,S,Id,PathTol);
1134 // update de Edge1. (Rem : has already a 3d curve)
1135 Standard_Real U,U1,U2;
1136 Handle(Geom2d_Curve) PC;
1138 PC = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0));
1141 if (!C1is3D) C1 = S->VIso(f2);
1144 PC = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1));
1147 if (!C1is3D) C1 = S->UIso(f1);
1150 Handle(Geom_Curve) Dummy;
1152 UpdateEdge(Edge1,C1,Id,BRep_Tool::Tolerance(Edge1));
1153 else if ( C1Denerated) {
1154 UpdateEdge(Edge1,Dummy,Id,BRep_Tool::Tolerance(Edge1));
1155 myBuilder.Degenerated(Edge1,Standard_True);
1158 TheTol = Max(PathTol, BRep_Tool::Tolerance(Edge1) + ErrorPipe);
1159 UpdateEdge(Edge1, PC, myFace, TheTol);
1161 // mise a same range de la nouvelle pcurve.
1162 if ( !C1is3D && !C1Denerated)
1164 myBuilder.SameRange (Edge1,Standard_False);
1165 myBuilder.Range(Edge1,U1,U2, Standard_True);
1167 myBuilder.Range(Edge1,myFace,U1,U2);
1168 BRepLib::SameRange(Edge1);
1170 // mise a sameparameter pour les KPart
1171 if (ErrorPipe == 0) {
1172 TheTol = Max(TheTol, Tol);
1173 myBuilder.SameParameter(Edge1,Standard_False);
1174 BRepLib::SameParameter(Edge1, TheTol);
1177 // Update de edge2. (Rem : has already a 3d curve)
1179 PC = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0));
1182 if (!C2is3D) C2 = S->VIso(l2);
1185 PC = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1));
1188 if (!C2is3D) C2 = S->UIso(l1);
1192 UpdateEdge(Edge2,C2,Id,BRep_Tool::Tolerance(Edge2));
1193 else if ( C2Denerated) {
1194 UpdateEdge(Edge2,Dummy,Id,BRep_Tool::Tolerance(Edge2));
1195 myBuilder.Degenerated(Edge2,Standard_True);
1198 TheTol = Max(PathTol, BRep_Tool::Tolerance(Edge2) + ErrorPipe);
1199 UpdateEdge(Edge2, PC, myFace, TheTol);
1201 // mise a same range de la nouvelle pcurve.
1202 myBuilder.SameRange (Edge2,Standard_False);
1203 if ( !C2is3D && !C2Denerated)
1204 myBuilder.Range(Edge2, U1, U2, Standard_True);
1205 myBuilder.Range(Edge2,myFace,U1,U2);
1206 BRepLib::SameRange(Edge2);
1208 // mise a sameparameter pour les KPart
1209 if (ErrorPipe == 0) {
1210 TheTol = Max(TheTol, Tol);
1211 myBuilder.SameParameter(Edge2,Standard_False);
1212 BRepLib::SameParameter(Edge2, TheTol);
1215 TopoDS_Edge Edge3, Edge4;
1217 TopoDS_Vertex V1f,V1l,V2f,V2l;
1218 TopExp::Vertices(Path,V1f,V1l);
1219 Standard_Boolean IsClosed = ( V1f.IsSame(V1l));
1221 TopExp::Vertices(Edge1,V1f,V1l);
1222 TopExp::Vertices(Edge2,V2f,V2l);
1224 Standard_Boolean StartDegenerated = (V1f.IsSame(V2f));
1225 Standard_Boolean EndDegenerated = (V1l.IsSame(V2l));
1227 Standard_Boolean E3rev = Standard_False;
1228 Standard_Boolean E4rev = Standard_False;
1230 TopoDS_Vertex VVf,VVl;
1231 if ( FirstEdge.IsNull()) {
1232 myBuilder.MakeEdge(Edge3);
1233 myBuilder.Add(Edge3,V1f.Oriented(TopAbs_FORWARD));
1234 myBuilder.Add(Edge3,V2f.Oriented(TopAbs_REVERSED));
1237 TopoDS_Shape aLocalEdge = FirstEdge.Oriented(TopAbs_FORWARD);
1238 Edge3 = TopoDS::Edge(aLocalEdge);
1239 // Edge3 = TopoDS::Edge(FirstEdge.Oriented(TopAbs_FORWARD));
1240 TopExp::Vertices(Edge3,VVf,VVl);
1242 // si firstedge n est pas nul, il faut que les vertex soient partages
1243 if ( !VVf.IsSame(V1f) && !VVf.IsSame(V2f) ) {
1244 std::cout << "Attention Vertex non partages !!!!!!" << std::endl;
1247 if ( !VVf.IsSame(V1f) && !VVf.IsSame(V2f) ) {
1248 // On fait vraisemblablement des conneries !!
1249 // On cree un autre edge, on appelle le Sewing apres.
1250 myBuilder.MakeEdge(Edge3);
1251 myBuilder.Add(Edge3,V1f.Oriented(TopAbs_FORWARD));
1252 myBuilder.Add(Edge3,V2f.Oriented(TopAbs_REVERSED));
1254 else if ( !VVf.IsSame(V1f)) {
1256 E3rev = Standard_True;
1263 Standard_Real TolApp = Precision::Approximation();
1265 Handle(Geom2d_Line) L1,L2;
1268 // rem : si ExchUv, il faut reverser le Wire.
1269 // donc l'edge Forward dans la face sera E4 : d'ou L1 et L2
1270 L2 = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1));
1271 L1 = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1));
1276 L1 = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0));
1277 L2 = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0));
1282 L1->Reverse(); L2->Reverse();
1287 UpdateEdge(Edge3, L1, L2, myFace,PathTol);
1288 myBuilder.Range(Edge3,myFace,U1,U2);
1289 if (StartDegenerated)
1290 myBuilder.Degenerated(Edge3,Standard_True);
1291 else if (FirstEdge.IsNull()) // then the 3d curve has not been yet computed
1292 ComputeCurve3d(Edge3,L1,S,Id,TolApp);
1295 if ( LastEdge.IsNull()) {
1296 myBuilder.MakeEdge(Edge4);
1297 myBuilder.Add(Edge4,V1l.Oriented(TopAbs_FORWARD));
1298 myBuilder.Add(Edge4,V2l.Oriented(TopAbs_REVERSED));
1301 TopoDS_Shape aLocalEdge = LastEdge.Oriented(TopAbs_FORWARD);
1302 Edge4 = TopoDS::Edge(aLocalEdge);
1303 // Edge4 = TopoDS::Edge(LastEdge.Oriented(TopAbs_FORWARD));
1304 TopExp::Vertices(Edge4,VVf,VVl);
1306 // si lastedge n est pas nul, il faut que les vertex soient partages
1307 if ( !VVf.IsSame(V1l) && !VVf.IsSame(V2l) ) {
1308 std::cout << "Attention Vertex non partages !!!!!!" << std::endl;
1311 if ( !VVf.IsSame(V1l) && !VVf.IsSame(V2l) ) {
1312 // On fait vraisemblablement des conneries !!
1313 // On cree un autre edge, on appelle le Sewing apres.
1314 myBuilder.MakeEdge(Edge4);
1315 myBuilder.Add(Edge4,V1l.Oriented(TopAbs_FORWARD));
1316 myBuilder.Add(Edge4,V2l.Oriented(TopAbs_REVERSED));
1318 else if ( !VVf.IsSame(V1l)) {
1320 E4rev = Standard_True;
1325 L1 = new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1));
1330 L1 = new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0));
1340 UpdateEdge(Edge3,L1,myFace,PathTol);
1341 myBuilder.Range(Edge3,myFace,U1,U2);
1342 if (StartDegenerated)
1343 myBuilder.Degenerated(Edge3,Standard_True);
1344 else if (FirstEdge.IsNull()) // then the 3d curve has not been yet computed
1345 ComputeCurve3d(Edge3,L1,S,Id,TolApp);
1348 L2 = new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1));
1353 L2 = new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0));
1363 UpdateEdge(Edge4,L2 ,myFace,PathTol);
1364 myBuilder.Range(Edge4,myFace,U1,U2);
1366 myBuilder.Degenerated(Edge4,Standard_True);
1367 else if (LastEdge.IsNull()) // then the 3d curve has not been yet computed
1368 ComputeCurve3d(Edge4,L2,S,Id,TolApp);
1372 if ( !FirstEdge.IsNull() && !StartDegenerated) {
1373 BRepLib::BuildCurve3d (Edge3,PathTol);
1374 myBuilder.SameRange (Edge3,Standard_False);
1375 myBuilder.SameParameter(Edge3,Standard_False);
1376 BRepLib::SameParameter (Edge3, Tol);
1378 if ( !LastEdge.IsNull() && !EndDegenerated) {
1379 BRepLib::BuildCurve3d (Edge4,PathTol);
1380 myBuilder.SameRange (Edge4,Standard_False);
1381 myBuilder.SameParameter(Edge4,Standard_False);
1382 BRepLib::SameParameter (Edge4, Tol);
1386 myBuilder.MakeWire(W);
1388 myBuilder.Add(W, Edge1.Oriented(TopAbs_REVERSED));
1389 myBuilder.Add(W, Edge2.Oriented(TopAbs_FORWARD));
1390 myBuilder.Add(W, Edge4.Reversed());
1391 myBuilder.Add(W, Edge3);
1397 myBuilder.Add(myFace, W);
1398 if (ExchUV) myFace.Reverse();
1400 BRepTools::Update(myFace);
1402 if ( Edge1.Orientation() == TopAbs_REVERSED)
1408 //=======================================================================
1411 //=======================================================================
1413 void BRepOffset_Offset::Init(const TopoDS_Vertex& Vertex,
1414 const TopTools_ListOfShape& LEdge,
1415 const Standard_Real Offset,
1416 const Standard_Boolean Polynomial,
1417 const Standard_Real TolApp,
1418 const GeomAbs_Shape Conti)
1420 myStatus = BRepOffset_Good;
1423 // evaluate the Ax3 of the Sphere
1424 // find 3 different vertices in LEdge
1425 TopTools_ListIteratorOfListOfShape it;
1426 gp_Pnt P, P1, P2, P3;
1427 TopoDS_Vertex V1, V2, V3, V4;
1431 char* name = new char[100];
1435 sprintf(name,"VOnSph_%d",NbOFFSET);
1437 DBRep::Set(name, Vertex);
1439 Standard_Integer NbEdges = 1;
1440 for (it.Initialize(LEdge); it.More(); it.Next()) {
1441 sprintf(name,"EOnSph_%d_%d",NbOFFSET,NbEdges++);
1443 const TopoDS_Shape& CurE = it.Value();
1444 DBRep::Set(name, CurE);
1451 gp_Pnt Origin = BRep_Tool::Pnt(Vertex);
1453 //// Find the axis of the sphere to exclude
1454 //// degenerated and seam edges from the face under construction
1455 BRepLib_MakeWire MW;
1457 TopoDS_Wire theWire = MW.Wire();
1459 ShapeFix_Shape Fixer(theWire);
1461 theWire = TopoDS::Wire(Fixer.Shape());
1463 GProp_GProps GlobalProps;
1464 BRepGProp::LinearProperties(theWire, GlobalProps);
1465 gp_Pnt BaryCenter = GlobalProps.CentreOfMass();
1466 gp_Vec Xdir(BaryCenter, Origin);
1468 gp_Pnt FarestCorner = GetFarestCorner(theWire);
1469 gp_Pln thePlane = gce_MakePln(Origin, BaryCenter, FarestCorner);
1470 gp_Dir Vdir = thePlane.Axis().Direction();
1472 gp_Ax3 Axis(Origin, Vdir, Xdir);
1474 Handle(Geom_Surface) S
1475 = new Geom_SphericalSurface( Axis, Abs(Offset));
1477 Standard_Real f, l, Tol = BRep_Tool::Tolerance(Vertex);
1479 TopLoc_Location Loc;
1480 BRep_Builder myBuilder;
1481 myBuilder.MakeFace(myFace);
1482 Handle(Geom_Surface) SS = S;
1484 // En polynomial, calcul de la surface par F(u,v).
1485 // Pas de changement de parametre, donc ProjLib sur la Sphere
1488 GeomConvert_ApproxSurface Approx(S,TolApp,Conti,Conti,10,10,10,1);
1489 if (Approx.IsDone()) {
1490 SS = Approx.Surface();
1494 myBuilder.UpdateFace(myFace, SS, Loc, Tol);
1497 myBuilder.MakeWire(W);
1503 sprintf(name,"SPHERE_%d",NbOFFSET);
1504 DrawTrSurf::Set(name, S);
1506 Standard_Integer CO = 1;
1509 for ( it.Initialize(LEdge); it.More(); it.Next()) {
1510 TopoDS_Edge E = TopoDS::Edge(it.Value());
1512 Handle(Geom_Curve) C = BRep_Tool::Curve(E,Loc,f,l);
1514 BRepLib::BuildCurve3d(E,BRep_Tool::Tolerance(E));
1515 C = BRep_Tool::Curve(E,Loc,f,l);
1517 C = new Geom_TrimmedCurve(C, f, l);
1518 C->Transform(Loc.Transformation());
1522 sprintf(name,"CURVE_%d_%d",NbOFFSET,CO);
1523 DrawTrSurf::Set(name, C);
1528 Handle(Geom2d_Curve) PCurve = GeomProjLib::Curve2d(C, S);
1529 // check if the first point of PCurve in is the canonical boundaries
1530 // of the sphere. Else move it.
1531 // the transformation is : U` = U + PI + 2 k PI
1532 // V` = +/- PI + 2 k` PI
1533 gp_Pnt2d P2d = PCurve->Value(f);
1534 Standard_Boolean IsToAdjust = Standard_False;
1535 if ( P2d.Y() < -M_PI/2.) {
1536 IsToAdjust = Standard_True;
1537 PCurve->Mirror(gp_Ax2d(gp_Pnt2d(0.,-M_PI/2.),gp::DX2d()));
1539 else if ( P2d.Y() > M_PI/2.) {
1540 IsToAdjust = Standard_True;
1541 PCurve->Mirror(gp_Ax2d(gp_Pnt2d(0., M_PI/2.),gp::DX2d()));
1544 // set the u firstpoint in [0,2*pi]
1545 gp_Vec2d Tr( M_PI, 0.);
1546 if ( P2d.X() > M_PI) Tr.Reverse();
1547 PCurve->Translate(Tr);
1550 UpdateEdge(E, PCurve, myFace, Tol);
1551 myBuilder.Range(E, myFace, f, l);
1552 myBuilder.Add(W, E);
1555 myBuilder.Add(myFace, W.Oriented(TopAbs_REVERSED));
1559 myBuilder.Add(myFace, W);
1562 BRepTools::Update(myFace);
1566 //=======================================================================
1569 //=======================================================================
1571 void BRepOffset_Offset::Init(const TopoDS_Edge& Edge,
1572 const Standard_Real Offset)
1575 Standard_Real myOffset = Abs(Offset);
1578 TopLoc_Location Loc;
1580 Handle(Geom_Curve) CP = BRep_Tool::Curve(Edge,Loc,f,l);
1581 CP = new Geom_TrimmedCurve(CP,f,l);
1582 CP->Transform(Loc.Transformation());
1584 GeomFill_Pipe Pipe(CP,myOffset);
1587 throw Standard_ConstructionError("GeomFill_Pipe : Cannot make a surface");
1589 BRepLib_MakeFace MF(Pipe.Surface(), Precision::Confusion());
1592 if ( Offset < 0.) myFace.Reverse();
1596 //=======================================================================
1599 //=======================================================================
1601 const TopoDS_Face& BRepOffset_Offset::Face() const
1607 //=======================================================================
1608 //function : Generated
1610 //=======================================================================
1612 TopoDS_Shape BRepOffset_Offset::Generated(const TopoDS_Shape& Shape) const
1614 TopoDS_Shape aShape;
1616 switch ( myShape.ShapeType())
1620 TopExp_Explorer exp (myShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1621 TopExp_Explorer expo (myFace .Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1622 for (; exp.More() && expo.More(); exp.Next(), expo.Next())
1624 if (Shape.IsSame (exp.Current()))
1626 if (myShape.Orientation() == TopAbs_REVERSED)
1627 aShape = expo.Current().Reversed();
1629 aShape = expo.Current();
1637 // have generate a pipe.
1639 TopoDS_Vertex V1, V2;
1640 TopExp::Vertices(TopoDS::Edge(myShape), V1, V2);
1642 TopExp_Explorer expf(myFace.Oriented(TopAbs_FORWARD), TopAbs_WIRE);
1643 TopExp_Explorer expo(expf.Current().Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1647 if ( V2.IsSame(Shape)) {
1648 if (expf.Current().Orientation() == TopAbs_REVERSED)
1649 aShape = expo.Current().Reversed();
1651 aShape = expo.Current();
1655 if (expf.Current().Orientation() == TopAbs_REVERSED)
1656 aShape = expo.Current().Reversed();
1658 aShape = expo.Current();
1660 if (myFace.Orientation() == TopAbs_REVERSED)
1672 //=======================================================================
1675 //=======================================================================
1677 BRepOffset_Status BRepOffset_Offset::Status() const