0023947: Eliminate trivial compiler warnings in MSVC++ with warning level 4
[occt.git] / src / BndLib / BndLib_AddSurface.cxx
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
5 //
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.
10 //
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.
13 //
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.
20
21
22 //  Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503
23
24
25 #include <BndLib_AddSurface.ixx>
26
27
28 #include <Adaptor3d_HSurface.hxx>
29 #include <GeomAbs_SurfaceType.hxx>
30 #include <BndLib.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Pln.hxx>
33 #include <ElSLib.hxx>
34 #include <TColgp_Array2OfPnt.hxx>
35 #include <Geom_BSplineSurface.hxx>
36 #include <Geom_BezierSurface.hxx>
37
38 #include <Precision.hxx>
39
40 //=======================================================================
41 //function : Add
42 //purpose  : 
43 //=======================================================================
44
45 void BndLib_AddSurface::Add(const Adaptor3d_Surface& S,
46                             const Standard_Real Tol,
47                             Bnd_Box& B ) 
48 {
49
50   BndLib_AddSurface::Add(S,
51                          S.FirstUParameter(),
52                          S.LastUParameter (),
53                          S.FirstVParameter(),
54                          S.LastVParameter (),Tol,B);
55 }
56 //=======================================================================
57 //function : NbUSamples
58 //purpose  : 
59 //=======================================================================
60
61 static Standard_Integer NbUSamples(const Adaptor3d_Surface& S) 
62 {
63   Standard_Integer N;
64   GeomAbs_SurfaceType Type = S.GetType();
65   switch (Type) {
66   case GeomAbs_BezierSurface: 
67     {
68       N = 2*S.NbUPoles();
69       break;
70     }
71   case GeomAbs_BSplineSurface: 
72     {
73       const Handle(Geom_BSplineSurface)& BS = S.BSpline();
74       N = 2*(BS->UDegree() + 1)*(BS->NbUKnots() -1);
75       break;
76     }
77   default:
78     N = 33;
79   }
80   return Min (50,N);
81 }
82
83 //=======================================================================
84 //function : NbVSamples
85 //purpose  : 
86 //=======================================================================
87
88 static Standard_Integer NbVSamples(const Adaptor3d_Surface& S) 
89 {
90   Standard_Integer N;
91   GeomAbs_SurfaceType Type = S.GetType();
92   switch (Type) {
93   case GeomAbs_BezierSurface:
94     {
95       N = 2*S.NbVPoles();
96       break;
97     }
98   case GeomAbs_BSplineSurface:
99     {
100       const Handle(Geom_BSplineSurface)& BS = S.BSpline();
101       N = 2*(BS->VDegree() + 1)*(BS->NbVKnots() - 1) ;
102       break;
103     }
104   default:
105     N = 33;
106   }
107   return Min(50,N);
108 }
109
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)
116 {
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);
122
123   if (isU1Inf && isU2Inf)
124     aU = 0;
125   else if (isU1Inf)
126     aU = aUMax - 10.;
127   else if (isU2Inf)
128     aU = aUMin + 10.;
129   else
130     aU = (aUMin + aUMax)/2.;
131     
132   if (isV1Inf && isV2Inf)
133     aV = 0;
134   else if (isV1Inf)
135     aV = aVMax - 10.;
136   else if (isV2Inf)
137     aV = aVMin + 10.;
138   else
139     aV = (aVMin + aVMax)/2.;
140
141   gp_Pnt aCenter = ElSLib::Value(aU, aV, aPlane);
142
143   return aCenter;
144 }
145
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,
152                                      Bnd_Box       &aB)
153 {
154   // Get 3 coordinate axes of the plane.
155   const gp_Dir        &aNorm        = aPlane.Axis().Direction();
156   const Standard_Real  anAngularTol = RealEpsilon();
157
158   // Get location of the plane as its barycenter
159   gp_Pnt aLocation = BaryCenter(aPlane, aUMin, aUMax, aVMin, aVMax);
160
161   if (aNorm.IsParallel(gp::DX(), anAngularTol)) {
162     aB.Add(aLocation);
163     aB.OpenYmin();
164     aB.OpenYmax();
165     aB.OpenZmin();
166     aB.OpenZmax();
167   } else if (aNorm.IsParallel(gp::DY(), anAngularTol)) {
168     aB.Add(aLocation);
169     aB.OpenXmin();
170     aB.OpenXmax();
171     aB.OpenZmin();
172     aB.OpenZmax();
173   } else if (aNorm.IsParallel(gp::DZ(), anAngularTol)) {
174     aB.Add(aLocation);
175     aB.OpenXmin();
176     aB.OpenXmax();
177     aB.OpenYmin();
178     aB.OpenYmax();
179   } else {
180     aB.SetWhole();
181     return;
182   }
183
184   aB.Enlarge(aTol);
185 }
186 //  Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 End
187
188 //=======================================================================
189 //function : Add
190 //purpose  : 
191 //=======================================================================
192
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,
199                             Bnd_Box& B ) 
200 {
201   GeomAbs_SurfaceType Type = S.GetType(); // skv OCC6503
202
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
208 //     B.SetWhole();
209 //     return;
210     switch (Type) {
211     case GeomAbs_Plane: 
212       {
213         TreatInfinitePlane(S.Plane(), UMin, UMax, VMin, VMax, Tol, B);
214         return;
215       }
216     default: 
217       {
218         B.SetWhole();
219         return;
220       }
221     }
222 //  Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 End
223   }
224
225 //   GeomAbs_SurfaceType Type = S.GetType(); // skv OCC6503
226
227   switch (Type) {
228     
229   case GeomAbs_Plane: 
230     {
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)); 
236       B.Enlarge(Tol);
237       break;
238     }
239   case GeomAbs_Cylinder: 
240     {
241       BndLib::Add(S.Cylinder(),UMin,UMax,VMin,VMax,Tol,B);
242       break;
243     }
244   case GeomAbs_Cone: 
245     {
246       BndLib::Add(S.Cone(),UMin,UMax,VMin,VMax,Tol,B);
247       break;
248     }
249   case GeomAbs_Torus: 
250     {
251       BndLib::Add(S.Torus(),UMin,UMax,VMin,VMax,Tol,B);
252       break;
253     }
254   case GeomAbs_Sphere: 
255     {
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);
261       else
262         BndLib::Add(S.Sphere(),UMin,UMax,VMin,VMax,Tol,B);
263       break;
264     }
265   case GeomAbs_OffsetSurface: 
266     {
267       Handle(Adaptor3d_HSurface) HS = S.BasisSurface();
268       Add (HS->Surface(),UMin,UMax,VMin,VMax,Tol,B);
269       B.Enlarge(S.OffsetValue());
270       B.Enlarge(Tol);
271       break;
272     } 
273   case GeomAbs_BezierSurface:
274   case GeomAbs_BSplineSurface: 
275     {
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);
284         }
285         else {
286           S.BSpline()->Poles(Tp);
287         }
288         for (Standard_Integer i = Tp.LowerRow();i<=Tp.UpperRow();i++) {
289           for (Standard_Integer j = Tp.LowerCol();j<=Tp.UpperCol();j++) {
290             B.Add(Tp(i,j));
291           }
292         }
293         B.Enlarge(Tol);
294         break;
295       }
296     }
297   default: 
298     {
299       Standard_Integer Nu = NbUSamples(S);
300       Standard_Integer Nv = NbVSamples(S);
301       gp_Pnt P;
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));
306           S.D0(U,V,P);
307           B.Add(P);
308         }
309       }
310       B.Enlarge(Tol);
311     }
312   }
313 }