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
9 // under the terms of the GNU Lesser General Public 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.
17 #include <BRepLib_MakeShell.ixx>
19 #include <BRepLib.hxx>
20 #include <Precision.hxx>
21 #include <TColStd_Array1OfReal.hxx>
23 #include <Geom_RectangularTrimmedSurface.hxx>
24 #include <Geom_BSplineSurface.hxx>
25 #include <Geom2d_Line.hxx>
26 #include <GeomAdaptor_Surface.hxx>
27 #include <TColGeom2d_Array1OfCurve.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopTools_Array1OfShape.hxx>
36 #include <BRep_Builder.hxx>
39 //=======================================================================
40 //function : BRepLib_MakeShell
42 //=======================================================================
44 BRepLib_MakeShell::BRepLib_MakeShell() :
45 myError(BRepLib_EmptyShell)
50 //=======================================================================
51 //function : BRepLib_MakeShell
53 //=======================================================================
55 BRepLib_MakeShell::BRepLib_MakeShell(const Handle(Geom_Surface)& S,
56 const Standard_Boolean Segment)
58 Standard_Real UMin,UMax,VMin,VMax;
59 S->Bounds(UMin,UMax,VMin,VMax);
60 Init(S,UMin,UMax,VMin,VMax,Segment);
64 //=======================================================================
65 //function : BRepLib_MakeShell
67 //=======================================================================
69 BRepLib_MakeShell::BRepLib_MakeShell(const Handle(Geom_Surface)& S,
70 const Standard_Real UMin,
71 const Standard_Real UMax,
72 const Standard_Real VMin,
73 const Standard_Real VMax,
74 const Standard_Boolean Segment)
76 Init(S,UMin,UMax,VMin,VMax,Segment);
80 //=======================================================================
83 //=======================================================================
85 void BRepLib_MakeShell::Init(const Handle(Geom_Surface)& S,
86 const Standard_Real UMin,
87 const Standard_Real UMax,
88 const Standard_Real VMin,
89 const Standard_Real VMax,
90 const Standard_Boolean Segment)
92 Handle(Geom_Surface) BS = S;
93 if ( S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
94 Handle(Geom_RectangularTrimmedSurface) RTS =
95 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
96 BS = RTS->BasisSurface();
98 myError = BRepLib_EmptyShell;
99 Standard_Real tol = Precision::Confusion();
101 // Make a shell from a surface
102 GeomAdaptor_Surface GS(BS,UMin,UMax,VMin,VMax);
104 Standard_Integer nu = GS.NbUIntervals(GeomAbs_C2);
105 Standard_Integer nv = GS.NbVIntervals(GeomAbs_C2);
107 Standard_Boolean uperiodic = GS.IsUPeriodic();
108 Standard_Boolean vperiodic = GS.IsVPeriodic();
110 if (nu == 0 || nv == 0) return;
112 // arrays of parameters and pcurves
113 TColStd_Array1OfReal upars(1,nu+1);
114 TColStd_Array1OfReal vpars(1,nv+1);
115 TColGeom2d_Array1OfCurve uisos(1,nu+1);
116 TColGeom2d_Array1OfCurve visos(1,nv+1);
118 Standard_Integer iu,iv;
120 GS.UIntervals(upars,GeomAbs_C2);
122 for (iu = 1; iu <= nu+1; iu++) {
123 Standard_Real u = upars(iu);
124 if (!Precision::IsInfinite(u))
125 uisos(iu) = new Geom2d_Line(gp_Pnt2d(u,0.),dv);
128 GS.VIntervals(vpars,GeomAbs_C2);
130 for (iv = 1; iv <= nv+1 ; iv++) {
131 Standard_Real v = vpars(iv);
132 if (!Precision::IsInfinite(v))
133 visos(iv) = new Geom2d_Line(gp_Pnt2d(0.,v),du);
140 B.MakeShell(TopoDS::Shell(myShape));
142 // arrays of edges and vertices for each row
143 TopTools_Array1OfShape botedges(1,nu);
144 TopTools_Array1OfShape botvertices(1,nu+1);
146 // copies of the first ones for periodic case
147 TopTools_Array1OfShape fbotedges(1,nu);
148 TopTools_Array1OfShape fbotvertices(1,nu+1);
152 TopoDS_Edge eleft,eright,etop,ebot,feleft;
153 TopoDS_Vertex vlb,vlt,vrb,vrt,fvlt;
156 // init the botedges and botvertices
157 if (!Precision::IsInfinite(vpars(1))) {
158 if (!Precision::IsInfinite(upars(1)))
159 B.MakeVertex(vrt,S->Value(upars(1),vpars(1)),tol);
160 fbotvertices(1) = botvertices(1) = vrt;
162 for (iu = 1; iu <= nu; iu++) {
165 if (uperiodic && iu == nu)
166 vrt = TopoDS::Vertex(botvertices(1));
167 else if (!Precision::IsInfinite(upars(iu+1)))
168 B.MakeVertex(vrt,S->Value(upars(iu+1),vpars(1)),tol);
170 fbotvertices(iu+1) = botvertices(iu+1) = vrt;
173 vlt.Orientation(TopAbs_FORWARD);
177 vrt.Orientation(TopAbs_REVERSED);
180 fbotedges(iu) = botedges(iu) = etop;
184 for (iv = 1; iv <= nv; iv++) {
186 // compute the first edge and vertices of the line
187 vrb = TopoDS::Vertex(botvertices(1));
189 if (vperiodic && iv == nv) {
190 vrt = TopoDS::Vertex(fbotvertices(1));
194 if (!Precision::IsInfinite(vpars(iv+1))) {
195 if (!Precision::IsInfinite(upars(1)))
196 B.MakeVertex(vrt,S->Value(upars(1),vpars(iv+1)),tol);
201 if (!Precision::IsInfinite(upars(1))) {
204 vrb.Orientation(TopAbs_FORWARD);
208 vrt.Orientation(TopAbs_REVERSED);
217 // make the row of faces
219 for (iu = 1; iu <= nu; iu++) {
221 // create the face at iu, iv
224 Handle(Geom_Surface) SS = Handle(Geom_Surface)::DownCast(BS->Copy());
225 if (GS.GetType() == GeomAbs_BSplineSurface && Segment) {
226 Handle(Geom_BSplineSurface)::DownCast(SS)
227 ->Segment(upars(iu),upars(iu+1),
228 vpars(iv),vpars(iv+1) );
230 B.MakeFace(F,SS,tol);
239 vrb = TopoDS::Vertex(botvertices(iu+1));
242 if (uperiodic && iu == nu)
246 if (!Precision::IsInfinite(vpars(iv+1))) {
247 if (!Precision::IsInfinite(upars(iu+1)))
248 B.MakeVertex(vrt,S->Value(upars(iu+1),vpars(iv+1)),tol);
252 botvertices(iu) = vlt;
253 botvertices(iu+1) = vrt;
259 if (uperiodic && iu == nu)
263 if (!Precision::IsInfinite(upars(iu+1))) {
266 vrb.Orientation(TopAbs_FORWARD);
270 vrt.Orientation(TopAbs_REVERSED);
276 if ( uperiodic && nu == 1) {
277 if (!eleft.IsNull() && !eright.IsNull()) {
278 B.UpdateEdge(eleft,uisos(2),uisos(1),F,tol);
279 B.Range(eleft,F,vpars(iv),vpars(iv+1));
283 if (!eleft.IsNull()) {
284 B.UpdateEdge(eleft,uisos(iu),F,tol);
285 B.Range(eleft,F,vpars(iv),vpars(iv+1));
287 if (!eright.IsNull()) {
288 B.UpdateEdge(eright,uisos(iu+1),F,tol);
289 B.Range(eright,F,vpars(iv),vpars(iv+1));
293 ebot = TopoDS::Edge(botedges(iu));
295 if (vperiodic && iv == nv)
296 etop = TopoDS::Edge(fbotedges(iu));
299 if (!Precision::IsInfinite(vpars(iv+1))) {
302 vlt.Orientation(TopAbs_FORWARD);
306 vrt.Orientation(TopAbs_REVERSED);
312 if ( vperiodic && nv == 1) {
313 if (!ebot.IsNull() && !etop.IsNull()) {
314 B.UpdateEdge(ebot,visos(1),visos(2),F,tol);
315 B.Range(ebot,F,vpars(iv),vpars(iv+1));
319 if (!ebot.IsNull()) {
320 B.UpdateEdge(ebot,visos(iv),F,tol);
321 B.Range(ebot,F,upars(iu),upars(iu+1));
323 if (!etop.IsNull()) {
324 B.UpdateEdge(etop,visos(iv+1),F,tol);
325 B.Range(etop,F,upars(iu),upars(iu+1));
331 if (!eleft.IsNull()) {
332 eleft.Orientation(TopAbs_REVERSED);
335 if (!ebot.IsNull()) {
336 ebot.Orientation(TopAbs_FORWARD);
339 if (!eright.IsNull()) {
340 eright.Orientation(TopAbs_FORWARD);
343 if (!etop.IsNull()) {
344 etop.Orientation(TopAbs_REVERSED);
353 // codage des courbes 3d et regularites.
354 BRepLib::BuildCurves3d(myShape,tol);
355 BRepLib::EncodeRegularity(myShape);
357 myError = BRepLib_ShellDone;
362 //=======================================================================
365 //=======================================================================
367 BRepLib_ShellError BRepLib_MakeShell::Error() const
373 //=======================================================================
374 //function : TopoDS_Shell&
376 //=======================================================================
378 const TopoDS_Shell& BRepLib_MakeShell::Shell() const
380 return TopoDS::Shell(myShape);
385 //=======================================================================
386 //function : TopoDS_Shell
388 //=======================================================================
390 BRepLib_MakeShell::operator TopoDS_Shell() const