1 // File: BRepLib_MakeShell.cxx
2 // Created: Wed Jan 4 13:37:46 1995
3 // Author: Bruno DUMORTIER
7 #include <BRepLib_MakeShell.ixx>
10 #include <Precision.hxx>
11 #include <TColStd_Array1OfReal.hxx>
13 #include <Geom_RectangularTrimmedSurface.hxx>
14 #include <Geom_BSplineSurface.hxx>
15 #include <Geom2d_Line.hxx>
16 #include <GeomAdaptor_Surface.hxx>
17 #include <TColGeom2d_Array1OfCurve.hxx>
21 #include <TopoDS_Face.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <TopoDS_Vertex.hxx>
25 #include <TopTools_Array1OfShape.hxx>
26 #include <BRep_Builder.hxx>
29 //=======================================================================
30 //function : BRepLib_MakeShell
32 //=======================================================================
34 BRepLib_MakeShell::BRepLib_MakeShell() :
35 myError(BRepLib_EmptyShell)
40 //=======================================================================
41 //function : BRepLib_MakeShell
43 //=======================================================================
45 BRepLib_MakeShell::BRepLib_MakeShell(const Handle(Geom_Surface)& S,
46 const Standard_Boolean Segment)
48 Standard_Real UMin,UMax,VMin,VMax;
49 S->Bounds(UMin,UMax,VMin,VMax);
50 Init(S,UMin,UMax,VMin,VMax,Segment);
54 //=======================================================================
55 //function : BRepLib_MakeShell
57 //=======================================================================
59 BRepLib_MakeShell::BRepLib_MakeShell(const Handle(Geom_Surface)& S,
60 const Standard_Real UMin,
61 const Standard_Real UMax,
62 const Standard_Real VMin,
63 const Standard_Real VMax,
64 const Standard_Boolean Segment)
66 Init(S,UMin,UMax,VMin,VMax,Segment);
70 //=======================================================================
73 //=======================================================================
75 void BRepLib_MakeShell::Init(const Handle(Geom_Surface)& S,
76 const Standard_Real UMin,
77 const Standard_Real UMax,
78 const Standard_Real VMin,
79 const Standard_Real VMax,
80 const Standard_Boolean Segment)
82 Handle(Geom_Surface) BS = S;
83 if ( S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
84 Handle(Geom_RectangularTrimmedSurface) RTS =
85 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
86 BS = RTS->BasisSurface();
88 myError = BRepLib_EmptyShell;
89 Standard_Real tol = Precision::Confusion();
91 // Make a shell from a surface
92 GeomAdaptor_Surface GS(BS,UMin,UMax,VMin,VMax);
94 Standard_Integer nu = GS.NbUIntervals(GeomAbs_C2);
95 Standard_Integer nv = GS.NbVIntervals(GeomAbs_C2);
97 Standard_Boolean uperiodic = GS.IsUPeriodic();
98 Standard_Boolean vperiodic = GS.IsVPeriodic();
100 if (nu == 0 || nv == 0) return;
102 // arrays of parameters and pcurves
103 TColStd_Array1OfReal upars(1,nu+1);
104 TColStd_Array1OfReal vpars(1,nv+1);
105 TColGeom2d_Array1OfCurve uisos(1,nu+1);
106 TColGeom2d_Array1OfCurve visos(1,nv+1);
108 Standard_Integer iu,iv;
110 GS.UIntervals(upars,GeomAbs_C2);
112 for (iu = 1; iu <= nu+1; iu++) {
113 Standard_Real u = upars(iu);
114 if (!Precision::IsInfinite(u))
115 uisos(iu) = new Geom2d_Line(gp_Pnt2d(u,0.),dv);
118 GS.VIntervals(vpars,GeomAbs_C2);
120 for (iv = 1; iv <= nv+1 ; iv++) {
121 Standard_Real v = vpars(iv);
122 if (!Precision::IsInfinite(v))
123 visos(iv) = new Geom2d_Line(gp_Pnt2d(0.,v),du);
130 B.MakeShell(TopoDS::Shell(myShape));
132 // arrays of edges and vertices for each row
133 TopTools_Array1OfShape botedges(1,nu);
134 TopTools_Array1OfShape botvertices(1,nu+1);
136 // copies of the first ones for periodic case
137 TopTools_Array1OfShape fbotedges(1,nu);
138 TopTools_Array1OfShape fbotvertices(1,nu+1);
142 TopoDS_Edge eleft,eright,etop,ebot,feleft;
143 TopoDS_Vertex vlb,vlt,vrb,vrt,fvlt;
146 // init the botedges and botvertices
147 if (!Precision::IsInfinite(vpars(1))) {
148 if (!Precision::IsInfinite(upars(1)))
149 B.MakeVertex(vrt,S->Value(upars(1),vpars(1)),tol);
150 fbotvertices(1) = botvertices(1) = vrt;
152 for (iu = 1; iu <= nu; iu++) {
155 if (uperiodic && iu == nu)
156 vrt = TopoDS::Vertex(botvertices(1));
157 else if (!Precision::IsInfinite(upars(iu+1)))
158 B.MakeVertex(vrt,S->Value(upars(iu+1),vpars(1)),tol);
160 fbotvertices(iu+1) = botvertices(iu+1) = vrt;
163 vlt.Orientation(TopAbs_FORWARD);
167 vrt.Orientation(TopAbs_REVERSED);
170 fbotedges(iu) = botedges(iu) = etop;
174 for (iv = 1; iv <= nv; iv++) {
176 // compute the first edge and vertices of the line
177 vrb = TopoDS::Vertex(botvertices(1));
179 if (vperiodic && iv == nv) {
180 vrt = TopoDS::Vertex(fbotvertices(1));
184 if (!Precision::IsInfinite(vpars(iv+1))) {
185 if (!Precision::IsInfinite(upars(1)))
186 B.MakeVertex(vrt,S->Value(upars(1),vpars(iv+1)),tol);
191 if (!Precision::IsInfinite(upars(1))) {
194 vrb.Orientation(TopAbs_FORWARD);
198 vrt.Orientation(TopAbs_REVERSED);
207 // make the row of faces
209 for (iu = 1; iu <= nu; iu++) {
211 // create the face at iu, iv
214 Handle(Geom_Surface) SS = Handle(Geom_Surface)::DownCast(BS->Copy());
215 if (GS.GetType() == GeomAbs_BSplineSurface && Segment) {
216 Handle(Geom_BSplineSurface)::DownCast(SS)
217 ->Segment(upars(iu),upars(iu+1),
218 vpars(iv),vpars(iv+1) );
220 B.MakeFace(F,SS,tol);
229 vrb = TopoDS::Vertex(botvertices(iu+1));
232 if (uperiodic && iu == nu)
236 if (!Precision::IsInfinite(vpars(iv+1))) {
237 if (!Precision::IsInfinite(upars(iu+1)))
238 B.MakeVertex(vrt,S->Value(upars(iu+1),vpars(iv+1)),tol);
242 botvertices(iu) = vlt;
243 botvertices(iu+1) = vrt;
249 if (uperiodic && iu == nu)
253 if (!Precision::IsInfinite(upars(iu+1))) {
256 vrb.Orientation(TopAbs_FORWARD);
260 vrt.Orientation(TopAbs_REVERSED);
266 if ( uperiodic && nu == 1) {
267 if (!eleft.IsNull() && !eright.IsNull()) {
268 B.UpdateEdge(eleft,uisos(2),uisos(1),F,tol);
269 B.Range(eleft,F,vpars(iv),vpars(iv+1));
273 if (!eleft.IsNull()) {
274 B.UpdateEdge(eleft,uisos(iu),F,tol);
275 B.Range(eleft,F,vpars(iv),vpars(iv+1));
277 if (!eright.IsNull()) {
278 B.UpdateEdge(eright,uisos(iu+1),F,tol);
279 B.Range(eright,F,vpars(iv),vpars(iv+1));
283 ebot = TopoDS::Edge(botedges(iu));
285 if (vperiodic && iv == nv)
286 etop = TopoDS::Edge(fbotedges(iu));
289 if (!Precision::IsInfinite(vpars(iv+1))) {
292 vlt.Orientation(TopAbs_FORWARD);
296 vrt.Orientation(TopAbs_REVERSED);
302 if ( vperiodic && nv == 1) {
303 if (!ebot.IsNull() && !etop.IsNull()) {
304 B.UpdateEdge(ebot,visos(1),visos(2),F,tol);
305 B.Range(ebot,F,vpars(iv),vpars(iv+1));
309 if (!ebot.IsNull()) {
310 B.UpdateEdge(ebot,visos(iv),F,tol);
311 B.Range(ebot,F,upars(iu),upars(iu+1));
313 if (!etop.IsNull()) {
314 B.UpdateEdge(etop,visos(iv+1),F,tol);
315 B.Range(etop,F,upars(iu),upars(iu+1));
321 if (!eleft.IsNull()) {
322 eleft.Orientation(TopAbs_REVERSED);
325 if (!ebot.IsNull()) {
326 ebot.Orientation(TopAbs_FORWARD);
329 if (!eright.IsNull()) {
330 eright.Orientation(TopAbs_FORWARD);
333 if (!etop.IsNull()) {
334 etop.Orientation(TopAbs_REVERSED);
343 // codage des courbes 3d et regularites.
344 BRepLib::BuildCurves3d(myShape,tol);
345 BRepLib::EncodeRegularity(myShape);
347 myError = BRepLib_ShellDone;
352 //=======================================================================
355 //=======================================================================
357 BRepLib_ShellError BRepLib_MakeShell::Error() const
363 //=======================================================================
364 //function : TopoDS_Shell&
366 //=======================================================================
368 const TopoDS_Shell& BRepLib_MakeShell::Shell() const
370 return TopoDS::Shell(myShape);
375 //=======================================================================
376 //function : TopoDS_Shell
378 //=======================================================================
380 BRepLib_MakeShell::operator TopoDS_Shell() const