1 // Created on: 1995-01-04
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 <BRep_Builder.hxx>
19 #include <BRepLib.hxx>
20 #include <BRepLib_MakeFace.hxx>
21 #include <BRepLib_MakeShell.hxx>
22 #include <Geom2d_Line.hxx>
23 #include <Geom_BSplineSurface.hxx>
24 #include <Geom_RectangularTrimmedSurface.hxx>
25 #include <Geom_Surface.hxx>
26 #include <GeomAdaptor_Surface.hxx>
28 #include <Precision.hxx>
29 #include <StdFail_NotDone.hxx>
30 #include <TColGeom2d_Array1OfCurve.hxx>
31 #include <TColStd_Array1OfReal.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopTools_Array1OfShape.hxx>
41 //=======================================================================
42 //function : BRepLib_MakeShell
44 //=======================================================================
45 BRepLib_MakeShell::BRepLib_MakeShell() :
46 myError(BRepLib_EmptyShell)
51 //=======================================================================
52 //function : BRepLib_MakeShell
54 //=======================================================================
56 BRepLib_MakeShell::BRepLib_MakeShell(const Handle(Geom_Surface)& S,
57 const Standard_Boolean Segment)
59 Standard_Real UMin,UMax,VMin,VMax;
60 S->Bounds(UMin,UMax,VMin,VMax);
61 Init(S,UMin,UMax,VMin,VMax,Segment);
65 //=======================================================================
66 //function : BRepLib_MakeShell
68 //=======================================================================
70 BRepLib_MakeShell::BRepLib_MakeShell(const Handle(Geom_Surface)& S,
71 const Standard_Real UMin,
72 const Standard_Real UMax,
73 const Standard_Real VMin,
74 const Standard_Real VMax,
75 const Standard_Boolean Segment)
77 Init(S,UMin,UMax,VMin,VMax,Segment);
81 //=======================================================================
84 //=======================================================================
86 void BRepLib_MakeShell::Init(const Handle(Geom_Surface)& S,
87 const Standard_Real UMin,
88 const Standard_Real UMax,
89 const Standard_Real VMin,
90 const Standard_Real VMax,
91 const Standard_Boolean Segment)
93 Handle(Geom_Surface) BS = S;
94 if ( S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
95 Handle(Geom_RectangularTrimmedSurface) RTS =
96 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
97 BS = RTS->BasisSurface();
99 myError = BRepLib_EmptyShell;
100 Standard_Real tol = Precision::Confusion();
102 // Make a shell from a surface
103 GeomAdaptor_Surface GS(BS,UMin,UMax,VMin,VMax);
105 Standard_Integer nu = GS.NbUIntervals(GeomAbs_C2);
106 Standard_Integer nv = GS.NbVIntervals(GeomAbs_C2);
108 Standard_Boolean uperiodic = GS.IsUPeriodic();
109 Standard_Boolean vperiodic = GS.IsVPeriodic();
111 if (nu == 0 || nv == 0) return;
113 // arrays of parameters and pcurves
114 TColStd_Array1OfReal upars(1,nu+1);
115 TColStd_Array1OfReal vpars(1,nv+1);
116 TColGeom2d_Array1OfCurve uisos(1,nu+1);
117 TColGeom2d_Array1OfCurve visos(1,nv+1);
119 Standard_Integer iu,iv;
121 GS.UIntervals(upars,GeomAbs_C2);
123 for (iu = 1; iu <= nu+1; iu++) {
124 Standard_Real u = upars(iu);
125 if (!Precision::IsInfinite(u))
126 uisos(iu) = new Geom2d_Line(gp_Pnt2d(u,0.),dv);
129 GS.VIntervals(vpars,GeomAbs_C2);
131 for (iv = 1; iv <= nv+1 ; iv++) {
132 Standard_Real v = vpars(iv);
133 if (!Precision::IsInfinite(v))
134 visos(iv) = new Geom2d_Line(gp_Pnt2d(0.,v),du);
141 B.MakeShell(TopoDS::Shell(myShape));
143 // arrays of edges and vertices for each row
144 TopTools_Array1OfShape botedges(1,nu);
145 TopTools_Array1OfShape botvertices(1,nu+1);
147 // copies of the first ones for periodic case
148 TopTools_Array1OfShape fbotedges(1,nu);
149 TopTools_Array1OfShape fbotvertices(1,nu+1);
153 TopoDS_Edge eleft,eright,etop,ebot,feleft;
154 TopoDS_Vertex vlb,vlt,vrb,vrt,fvlt;
157 // init the botedges and botvertices
158 if (!Precision::IsInfinite(vpars(1))) {
159 if (!Precision::IsInfinite(upars(1)))
160 B.MakeVertex(vrt,S->Value(upars(1),vpars(1)),tol);
161 fbotvertices(1) = botvertices(1) = vrt;
163 for (iu = 1; iu <= nu; iu++) {
166 if (uperiodic && iu == nu)
167 vrt = TopoDS::Vertex(botvertices(1));
168 else if (!Precision::IsInfinite(upars(iu+1)))
169 B.MakeVertex(vrt,S->Value(upars(iu+1),vpars(1)),tol);
171 fbotvertices(iu+1) = botvertices(iu+1) = vrt;
174 vlt.Orientation(TopAbs_FORWARD);
178 vrt.Orientation(TopAbs_REVERSED);
181 fbotedges(iu) = botedges(iu) = etop;
185 for (iv = 1; iv <= nv; iv++) {
187 // compute the first edge and vertices of the line
188 vrb = TopoDS::Vertex(botvertices(1));
190 if (vperiodic && iv == nv) {
191 vrt = TopoDS::Vertex(fbotvertices(1));
195 if (!Precision::IsInfinite(vpars(iv+1))) {
196 if (!Precision::IsInfinite(upars(1)))
197 B.MakeVertex(vrt,S->Value(upars(1),vpars(iv+1)),tol);
202 if (!Precision::IsInfinite(upars(1))) {
205 vrb.Orientation(TopAbs_FORWARD);
209 vrt.Orientation(TopAbs_REVERSED);
218 // make the row of faces
220 for (iu = 1; iu <= nu; iu++) {
222 // create the face at iu, iv
225 Handle(Geom_Surface) SS = Handle(Geom_Surface)::DownCast(BS->Copy());
226 if (GS.GetType() == GeomAbs_BSplineSurface && Segment) {
227 Handle(Geom_BSplineSurface)::DownCast(SS)
228 ->Segment(upars(iu),upars(iu+1),
229 vpars(iv),vpars(iv+1) );
231 B.MakeFace(F,SS,tol);
240 vrb = TopoDS::Vertex(botvertices(iu+1));
243 if (uperiodic && iu == nu)
247 if (!Precision::IsInfinite(vpars(iv+1))) {
248 if (!Precision::IsInfinite(upars(iu+1)))
249 B.MakeVertex(vrt,S->Value(upars(iu+1),vpars(iv+1)),tol);
253 botvertices(iu) = vlt;
254 botvertices(iu+1) = vrt;
260 if (uperiodic && iu == nu)
264 if (!Precision::IsInfinite(upars(iu+1))) {
267 vrb.Orientation(TopAbs_FORWARD);
271 vrt.Orientation(TopAbs_REVERSED);
277 if ( uperiodic && nu == 1) {
278 if (!eleft.IsNull() && !eright.IsNull()) {
279 B.UpdateEdge(eleft,uisos(2),uisos(1),F,tol);
280 B.Range(eleft,F,vpars(iv),vpars(iv+1));
284 if (!eleft.IsNull()) {
285 B.UpdateEdge(eleft,uisos(iu),F,tol);
286 B.Range(eleft,F,vpars(iv),vpars(iv+1));
288 if (!eright.IsNull()) {
289 B.UpdateEdge(eright,uisos(iu+1),F,tol);
290 B.Range(eright,F,vpars(iv),vpars(iv+1));
294 ebot = TopoDS::Edge(botedges(iu));
296 if (vperiodic && iv == nv)
297 etop = TopoDS::Edge(fbotedges(iu));
300 if (!Precision::IsInfinite(vpars(iv+1))) {
303 vlt.Orientation(TopAbs_FORWARD);
307 vrt.Orientation(TopAbs_REVERSED);
313 if ( vperiodic && nv == 1) {
314 if (!ebot.IsNull() && !etop.IsNull()) {
315 B.UpdateEdge(ebot,visos(1),visos(2),F,tol);
316 B.Range(ebot,F,vpars(iv),vpars(iv+1));
320 if (!ebot.IsNull()) {
321 B.UpdateEdge(ebot,visos(iv),F,tol);
322 B.Range(ebot,F,upars(iu),upars(iu+1));
324 if (!etop.IsNull()) {
325 B.UpdateEdge(etop,visos(iv+1),F,tol);
326 B.Range(etop,F,upars(iu),upars(iu+1));
332 if (!eleft.IsNull()) {
333 eleft.Orientation(TopAbs_REVERSED);
336 if (!ebot.IsNull()) {
337 ebot.Orientation(TopAbs_FORWARD);
340 if (!eright.IsNull()) {
341 eright.Orientation(TopAbs_FORWARD);
344 if (!etop.IsNull()) {
345 etop.Orientation(TopAbs_REVERSED);
354 // codage des courbes 3d et regularites.
355 BRepLib::BuildCurves3d(myShape,tol);
356 BRepLib::EncodeRegularity(myShape);
357 myShape.Closed (BRep_Tool::IsClosed (myShape));
359 // Additional checking for degenerated edges
360 Standard_Boolean isDegenerated;
361 Standard_Real aFirst, aLast;
362 Standard_Real aTol = Precision::Confusion();
363 Standard_Real anActTol;
364 TopExp_Explorer anExp(myShape, TopAbs_EDGE);
365 for ( ; anExp.More(); anExp.Next())
367 const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
368 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
369 isDegenerated = BRepLib_MakeFace::IsDegenerated(aCurve, aTol, anActTol);
370 B.Degenerated(anEdge, isDegenerated);
373 myError = BRepLib_ShellDone;
378 //=======================================================================
381 //=======================================================================
383 BRepLib_ShellError BRepLib_MakeShell::Error() const
389 //=======================================================================
390 //function : TopoDS_Shell&
392 //=======================================================================
394 const TopoDS_Shell& BRepLib_MakeShell::Shell() const
396 return TopoDS::Shell(myShape);
401 //=======================================================================
402 //function : TopoDS_Shell
404 //=======================================================================
406 BRepLib_MakeShell::operator TopoDS_Shell() const