1 // Created on: 1995-07-24
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503
25 #include <BndLib_AddSurface.ixx>
28 #include <Adaptor3d_HSurface.hxx>
29 #include <GeomAbs_SurfaceType.hxx>
34 #include <TColgp_Array2OfPnt.hxx>
35 #include <Geom_BSplineSurface.hxx>
36 #include <Geom_BezierSurface.hxx>
38 #include <Precision.hxx>
40 //=======================================================================
43 //=======================================================================
45 void BndLib_AddSurface::Add(const Adaptor3d_Surface& S,
46 const Standard_Real Tol,
50 BndLib_AddSurface::Add(S,
54 S.LastVParameter (),Tol,B);
56 //=======================================================================
57 //function : NbUSamples
59 //=======================================================================
61 static Standard_Integer NbUSamples(const Adaptor3d_Surface& S)
64 GeomAbs_SurfaceType Type = S.GetType();
66 case GeomAbs_BezierSurface:
71 case GeomAbs_BSplineSurface:
73 const Handle(Geom_BSplineSurface)& BS = S.BSpline();
74 N = 2*(BS->UDegree() + 1)*(BS->NbUKnots() -1);
83 //=======================================================================
84 //function : NbVSamples
86 //=======================================================================
88 static Standard_Integer NbVSamples(const Adaptor3d_Surface& S)
91 GeomAbs_SurfaceType Type = S.GetType();
93 case GeomAbs_BezierSurface:
98 case GeomAbs_BSplineSurface:
100 const Handle(Geom_BSplineSurface)& BS = S.BSpline();
101 N = 2*(BS->VDegree() + 1)*(BS->NbVKnots() - 1) ;
110 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 Begin
111 static gp_Pnt BaryCenter(const gp_Pln &aPlane,
112 const Standard_Real aUMin,
113 const Standard_Real aUMax,
114 const Standard_Real aVMin,
115 const Standard_Real aVMax)
117 Standard_Real aU, aV;
118 Standard_Boolean isU1Inf = Precision::IsInfinite(aUMin);
119 Standard_Boolean isU2Inf = Precision::IsInfinite(aUMax);
120 Standard_Boolean isV1Inf = Precision::IsInfinite(aVMin);
121 Standard_Boolean isV2Inf = Precision::IsInfinite(aVMax);
123 if (isU1Inf && isU2Inf)
130 aU = (aUMin + aUMax)/2.;
132 if (isV1Inf && isV2Inf)
139 aV = (aVMin + aVMax)/2.;
141 gp_Pnt aCenter = ElSLib::Value(aU, aV, aPlane);
146 static void TreatInfinitePlane(const gp_Pln &aPlane,
147 const Standard_Real aUMin,
148 const Standard_Real aUMax,
149 const Standard_Real aVMin,
150 const Standard_Real aVMax,
151 const Standard_Real aTol,
154 // Get 3 coordinate axes of the plane.
155 const gp_Dir &aNorm = aPlane.Axis().Direction();
156 const Standard_Real anAngularTol = RealEpsilon();
158 // Get location of the plane as its barycenter
159 gp_Pnt aLocation = BaryCenter(aPlane, aUMin, aUMax, aVMin, aVMax);
161 if (aNorm.IsParallel(gp::DX(), anAngularTol)) {
167 } else if (aNorm.IsParallel(gp::DY(), anAngularTol)) {
173 } else if (aNorm.IsParallel(gp::DZ(), anAngularTol)) {
186 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 End
188 //=======================================================================
191 //=======================================================================
193 void BndLib_AddSurface::Add(const Adaptor3d_Surface& S,
194 const Standard_Real UMin,
195 const Standard_Real UMax,
196 const Standard_Real VMin,
197 const Standard_Real VMax,
198 const Standard_Real Tol,
201 GeomAbs_SurfaceType Type = S.GetType(); // skv OCC6503
203 if (Precision::IsInfinite(VMin) ||
204 Precision::IsInfinite(VMax) ||
205 Precision::IsInfinite(UMin) ||
206 Precision::IsInfinite(UMax) ) {
207 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 Begin
213 TreatInfinitePlane(S.Plane(), UMin, UMax, VMin, VMax, Tol, B);
222 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 End
225 // GeomAbs_SurfaceType Type = S.GetType(); // skv OCC6503
231 gp_Pln Plan = S.Plane();
232 B.Add(ElSLib::Value(UMin,VMin,Plan));
233 B.Add(ElSLib::Value(UMin,VMax,Plan));
234 B.Add(ElSLib::Value(UMax,VMin,Plan));
235 B.Add(ElSLib::Value(UMax,VMax,Plan));
239 case GeomAbs_Cylinder:
241 BndLib::Add(S.Cylinder(),UMin,UMax,VMin,VMax,Tol,B);
246 BndLib::Add(S.Cone(),UMin,UMax,VMin,VMax,Tol,B);
251 BndLib::Add(S.Torus(),UMin,UMax,VMin,VMax,Tol,B);
256 if (Abs(UMin) < Precision::Angular() &&
257 Abs(UMax - 2.*M_PI) < Precision::Angular() &&
258 Abs(VMin + M_PI/2.) < Precision::Angular() &&
259 Abs(VMax - M_PI/2.) < Precision::Angular()) // a whole sphere
260 BndLib::Add(S.Sphere(),Tol,B);
262 BndLib::Add(S.Sphere(),UMin,UMax,VMin,VMax,Tol,B);
265 case GeomAbs_OffsetSurface:
267 Handle(Adaptor3d_HSurface) HS = S.BasisSurface();
268 Add (HS->Surface(),UMin,UMax,VMin,VMax,Tol,B);
269 B.Enlarge(S.OffsetValue());
273 case GeomAbs_BezierSurface:
274 case GeomAbs_BSplineSurface:
276 Standard_Real PTol = Precision::Parametric(Precision::Confusion());
277 if (Abs(UMin-S.FirstUParameter()) < PTol &&
278 Abs(VMin-S.FirstVParameter()) < PTol &&
279 Abs(UMax-S.LastUParameter ()) < PTol &&
280 Abs(VMax-S.LastVParameter ()) < PTol ) {
281 TColgp_Array2OfPnt Tp(1,S.NbUPoles(),1,S.NbVPoles());
282 if (Type == GeomAbs_BezierSurface) {
283 S.Bezier()->Poles(Tp);
286 S.BSpline()->Poles(Tp);
288 for (Standard_Integer i = Tp.LowerRow();i<=Tp.UpperRow();i++) {
289 for (Standard_Integer j = Tp.LowerCol();j<=Tp.UpperCol();j++) {
299 Standard_Integer Nu = NbUSamples(S);
300 Standard_Integer Nv = NbVSamples(S);
302 for (Standard_Integer i =1 ;i<=Nu;i++){
303 Standard_Real U = UMin + ((UMax-UMin)*(i-1)/(Nu-1));
304 for (Standard_Integer j=1 ;j<=Nv;j++){
305 Standard_Real V = VMin + ((VMax-VMin)*(j-1)/(Nv-1));