58aea7434189b0482de37ec258488b7f9e7d8431
[occt.git] / src / Adaptor3d / Adaptor3d_HSurfaceTool.cxx
1 // Created by: Laurent BUCHARD
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <Adaptor3d_HSurfaceTool.ixx>
22
23 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesU(const Handle(Adaptor3d_HSurface)& S)
24 {
25   switch (S->GetType())
26   {
27     case GeomAbs_Plane: return 2;
28     case GeomAbs_BezierSurface: return (3 + S->NbUPoles());
29     case GeomAbs_BSplineSurface:
30     {
31       const Standard_Integer nbs = S->NbUKnots() * S->UDegree();
32       return (nbs < 2 ? 2 : nbs);
33     }
34     case GeomAbs_Torus: return 20;
35   }
36   return 10;
37 }
38
39 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesV(const Handle(Adaptor3d_HSurface)& S)
40 {
41   switch (S->GetType())
42   {
43     case GeomAbs_Plane: return 2;
44     case GeomAbs_BezierSurface: return (3 + S->NbVPoles());
45     case GeomAbs_BSplineSurface: 
46     {
47       const Standard_Integer nbs = S->NbVKnots() * S->VDegree();
48       return (nbs < 2 ? 2 : nbs);
49     }
50     case GeomAbs_Cylinder:
51     case GeomAbs_Cone:
52     case GeomAbs_Sphere:
53     case GeomAbs_Torus:
54     case GeomAbs_SurfaceOfRevolution:
55     case GeomAbs_SurfaceOfExtrusion: return 15;
56   }
57   return 10;
58 }
59
60 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesU(const Handle(Adaptor3d_HSurface)& S,
61                                                     const Standard_Real u1,
62                                                     const Standard_Real u2)
63 {
64   const Standard_Integer nbs = NbSamplesU(S);
65   Standard_Integer n = nbs;
66   if(nbs>10)
67   { 
68     const Standard_Real uf = FirstUParameter(S);
69     const Standard_Real ul = LastUParameter(S);
70     n *= (Standard_Integer)((u2-u1)/(ul-uf));
71     if (n>nbs || n>50) n = nbs;
72     if (n<5)   n = 5;
73   }
74   return n;
75 }
76
77 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesV(const Handle(Adaptor3d_HSurface)& S,
78                                                     const Standard_Real v1,
79                                                     const Standard_Real v2)
80 {
81   const Standard_Integer nbs = NbSamplesV(S);
82   Standard_Integer n = nbs;
83   if(nbs>10)
84   {
85     const Standard_Real vf = FirstVParameter(S);
86     const Standard_Real vl = LastVParameter(S);
87     n *= (Standard_Integer)((v2-v1)/(vl-vf));
88     if (n>nbs || n>50) n = nbs;
89     if (n<5)   n = 5;
90   }
91   return n;
92 }