0024180: Eliminate CLang / GCC compiler warning -Wswitch
[occt.git] / src / IntPatch / IntPatch_HInterTool.cxx
1 // Created on: 1995-07-02
2 // Created by: Laurent BUCHARD
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 #include <IntPatch_HInterTool.ixx>
23
24 #include <Extrema_EPCOfExtPC2d.hxx>
25 #include <Extrema_POnCurv2d.hxx>
26
27 #include <GeomAbs_SurfaceType.hxx>
28 #include <Standard_OutOfRange.hxx>
29
30 #include <Handle_Geom_BezierSurface.hxx>
31 #include <Handle_Geom_BSplineSurface.hxx>
32 #include <Handle_Geom2d_BezierCurve.hxx>
33 #include <Handle_Geom2d_BSplineCurve.hxx>
34
35 #include <Geom_BezierSurface.hxx>
36 #include <Geom_BSplineSurface.hxx>
37 #include <Geom2d_BezierCurve.hxx>
38 #include <Geom2d_BSplineCurve.hxx>
39
40 IntPatch_HInterTool::IntPatch_HInterTool() :
41     uinf (0.), vinf (0.), usup (0.), vsup (0.)
42 {
43 }
44
45 Standard_Integer IntPatch_HInterTool::NbSamplesV (const Handle(Adaptor3d_HSurface)& S,
46                                                   const Standard_Real, const Standard_Real)
47 {
48   switch (S->GetType())
49   {
50     case GeomAbs_Plane: return 2;
51     case GeomAbs_BezierSurface: return (3 + S->NbVPoles());
52     case GeomAbs_BSplineSurface: 
53     {
54       Standard_Integer nbs = S->NbVKnots();
55       nbs *= S->VDegree();
56       if (!S->IsVRational()) nbs *= 2;
57       if (nbs < 4) nbs = 4;
58           return nbs;
59     }
60     break;
61     case GeomAbs_Cylinder:
62     case GeomAbs_Cone:
63     case GeomAbs_Sphere:
64     case GeomAbs_Torus:
65     case GeomAbs_SurfaceOfRevolution:
66     case GeomAbs_SurfaceOfExtrusion: return 15;
67
68     case GeomAbs_OffsetSurface:
69     case GeomAbs_OtherSurface: return 10;
70   }
71   return 10;
72 }
73
74 Standard_Integer IntPatch_HInterTool::NbSamplesU (const Handle(Adaptor3d_HSurface)& S,
75                                                   const Standard_Real, const Standard_Real)
76 {
77   switch (S->GetType())
78   {
79     case GeomAbs_Plane: return 2;
80     case GeomAbs_BezierSurface: return (3 + S->NbUPoles());
81     case GeomAbs_BSplineSurface:
82     {
83       Standard_Integer nbs = S->NbUKnots();
84       nbs *= S->UDegree();
85       if (!S->IsURational()) nbs *= 2;
86       if (nbs < 4) nbs = 4;
87       return nbs;
88           }
89     case GeomAbs_Torus: return 20;
90
91     case GeomAbs_Cylinder:
92     case GeomAbs_Cone:
93     case GeomAbs_Sphere:
94     case GeomAbs_SurfaceOfRevolution:
95     case GeomAbs_SurfaceOfExtrusion:
96     case GeomAbs_OffsetSurface:
97     case GeomAbs_OtherSurface: return 10;
98   }
99   return 10;
100 }
101
102 Standard_Integer IntPatch_HInterTool::NbSamplePoints (const Handle(Adaptor3d_HSurface)& S)
103 {
104   uinf = S->FirstUParameter();
105   usup = S->LastUParameter();
106   vinf = S->FirstVParameter();
107   vsup = S->LastVParameter();
108
109   if (usup < uinf) {
110     Standard_Real temp = uinf;
111     uinf = usup;
112     usup = temp;
113     }
114     if (vsup < vinf) {
115     Standard_Real temp = vinf;
116     vinf = vsup;
117     vsup = temp;
118   }
119   if (uinf == RealFirst() && usup == RealLast()) {
120     uinf = -1.e5;
121     usup =  1.e5;
122   }
123   else if (uinf == RealFirst()) {
124     uinf = usup - 2.e5;
125   }
126   else if (usup == RealLast()) {
127     usup = uinf + 2.e5;
128   }
129   
130   if (vinf == RealFirst() && vsup == RealLast()) {
131     vinf = -1.e5;
132     vsup =  1.e5;
133   }
134   else if (vinf == RealFirst()) {
135     vinf = vsup - 2.e5;
136   }
137   else if (vsup == RealLast()) {
138     vsup = vinf + 2.e5;
139   }
140   const Standard_Integer m = (1+NbSamplesU(S,uinf,usup)/2) * (1+NbSamplesV(S,vinf,vsup)/2);
141   return(m);
142 }
143
144 void IntPatch_HInterTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
145                                        const Standard_Integer Index,
146                                        Standard_Real& U,
147                                        Standard_Real& V ) const
148 {
149   Standard_Integer nbIntU = 1+NbSamplesU(S,uinf,usup);
150   nbIntU>>=1;
151   Standard_Integer nbIntV = 1+NbSamplesV(S,vinf,vsup);     
152   nbIntV>>=1;
153   
154   if(nbIntU * nbIntV >5) {
155     
156     Standard_Integer NV = (Index-1) / nbIntU;
157     Standard_Integer NU = (Index-1) - NV * nbIntU;
158     Standard_Real du = ((usup-uinf)/((Standard_Real)(nbIntU+1)));
159     Standard_Real dv = ((vsup-vinf)/((Standard_Real)(nbIntV+1)));
160     
161     Standard_Integer perturb=(NU+NV) & 3;
162
163     //-- petite perturbation pou eviter les pbs de symetrie avec Les recherches de points int. 
164
165     switch(perturb) { 
166     case 1: dv*=1.001;  dv*=0.999; break;
167     case 2: du*=1.001;  dv*=1.001; break;
168     case 3: du*=0.999;             break;
169     default: break;
170     }
171     
172     U = uinf + du*(Standard_Real)(NU+1);
173     V = vinf + dv*(Standard_Real)(NV+1);
174     return;
175   }
176   
177   
178   switch (Index) {
179   case 1:
180     U = 0.76*uinf + 0.24*usup;
181     V = 0.74*vinf + 0.26*vsup;
182     break;
183   case 2:
184     U = 0.73*uinf + 0.27*usup;
185     V = 0.24*vinf + 0.76*vsup;
186     break;
187   case 3:
188     U = 0.25*uinf + 0.75*usup;
189     V = 0.76*vinf + 0.24*vsup;
190     break;
191   case 4:
192     U = 0.26*uinf + 0.74*usup;
193     V = 0.25*vinf + 0.75*vsup;
194     break;
195   default:
196     U = 0.51*uinf+0.49*usup; 
197     V = 0.49*vinf+0.51*vsup;
198   }
199 }
200
201
202 Standard_Integer IntPatch_HInterTool::NbSamplesOnArc (const Handle(Adaptor2d_HCurve2d)& A)
203 {
204   GeomAbs_CurveType CurveType  = A->GetType();
205
206 //  Standard_Real nbsOnC = 5;
207   Standard_Integer nbsOnC = 5;
208   switch(CurveType) { 
209   case GeomAbs_Line:
210     nbsOnC = 2;
211     break;
212   case GeomAbs_Circle:
213   case GeomAbs_Ellipse:
214   case GeomAbs_Hyperbola:
215   case GeomAbs_Parabola:
216     nbsOnC = 10;
217     break;
218   case GeomAbs_BezierCurve:
219     nbsOnC = A->NbPoles();
220     break;
221   case GeomAbs_BSplineCurve: { 
222     //-- Handle_Geom2d_BSplineCurve& BSC=A->BSpline();
223     nbsOnC = 2 + A->NbKnots() * A->Degree();
224     break;
225   }
226   default:
227     nbsOnC = 10;
228   } 
229   return(nbsOnC);
230 }
231
232 void IntPatch_HInterTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
233                                  Standard_Real& Ufirst,
234                                  Standard_Real& Ulast)
235 {
236   Ufirst = A->FirstParameter();
237   Ulast  = A->LastParameter();
238 }
239
240 Standard_Boolean IntPatch_HInterTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
241                                                const gp_Pnt2d& P,
242                                                Standard_Real& Paramproj,
243                                                gp_Pnt2d& Ptproj)
244 {
245   Standard_Real epsX = 1.e-8;
246   Standard_Integer Nbu = 20;
247   Standard_Real Tol = 1.e-5;
248   Standard_Real Dist2;
249
250   Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
251   if (!extrema.IsDone()) {
252     return Standard_False;
253   }
254   Standard_Integer Nbext = extrema.NbExt();
255   if (Nbext == 0) {
256     return Standard_False;
257   }
258   Standard_Integer indexmin = 1;
259   Dist2 = extrema.SquareDistance(1);
260   for (Standard_Integer i=2; i<=Nbext; i++) {
261     if (extrema.SquareDistance(i) < Dist2) {
262       indexmin = i;
263       Dist2 = extrema.SquareDistance(i);
264     }
265   }
266   Paramproj = extrema.Point(indexmin).Parameter();
267   Ptproj = extrema.Point(indexmin).Value();
268   return Standard_True;
269 }
270
271 Standard_Real IntPatch_HInterTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
272                                               const Handle(Adaptor2d_HCurve2d)& C)
273 {
274   return V->Resolution(C);
275 }
276
277 Standard_Real IntPatch_HInterTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
278                                               const Handle(Adaptor2d_HCurve2d)& C)
279 {
280   return V->Parameter(C);
281 }
282
283 Standard_Boolean IntPatch_HInterTool::HasBeenSeen(const Handle(Adaptor2d_HCurve2d)&)
284 {
285   return Standard_False;
286 }
287
288 Standard_Integer IntPatch_HInterTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
289 {
290   return 0;
291 }
292
293 void IntPatch_HInterTool::Value(const Handle(Adaptor2d_HCurve2d)&,
294                                 const Standard_Integer,
295                                 gp_Pnt&,
296                                 Standard_Real&,
297                                 Standard_Real&)
298 {
299   Standard_OutOfRange::Raise();
300 }
301
302 Standard_Boolean IntPatch_HInterTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
303                                                const Standard_Integer)
304 {
305   return Standard_False;
306 }
307
308 void IntPatch_HInterTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
309                                  const Standard_Integer,
310                                  Handle(Adaptor3d_HVertex)&)
311 {
312   Standard_OutOfRange::Raise();
313 }
314
315 Standard_Integer IntPatch_HInterTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
316 {
317   return 0;
318 }
319
320 Standard_Boolean IntPatch_HInterTool::HasFirstPoint (const Handle(Adaptor2d_HCurve2d)&,
321                                                      const Standard_Integer,
322                                                      Standard_Integer&)
323 {
324   Standard_OutOfRange::Raise();
325   return Standard_False;
326 }
327
328 Standard_Boolean IntPatch_HInterTool::HasLastPoint (const Handle(Adaptor2d_HCurve2d)&,
329                                                     const Standard_Integer,
330                                                     Standard_Integer&)
331 {
332   Standard_OutOfRange::Raise();
333   return Standard_False;
334 }
335
336 Standard_Boolean IntPatch_HInterTool::IsAllSolution (const Handle(Adaptor2d_HCurve2d)&)
337 {
338   return Standard_False;
339 }