8c247b66767dab44fea4ecefa2293fbd57bfd3e0
[occt.git] / src / Adaptor3d / Adaptor3d_HSurfaceTool.cxx
1 // Created by: Laurent BUCHARD
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <Adaptor3d_HSurfaceTool.ixx>
17
18 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesU(const Handle(Adaptor3d_HSurface)& S)
19 {
20   switch (S->GetType())
21   {
22     case GeomAbs_Plane: return 2;
23     case GeomAbs_BezierSurface: return (3 + S->NbUPoles());
24     case GeomAbs_BSplineSurface:
25     {
26       const Standard_Integer nbs = S->NbUKnots() * S->UDegree();
27       return (nbs < 2 ? 2 : nbs);
28     }
29     case GeomAbs_Torus: return 20;
30     default:
31       break;
32   }
33   return 10;
34 }
35
36 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesV(const Handle(Adaptor3d_HSurface)& S)
37 {
38   switch (S->GetType())
39   {
40     case GeomAbs_Plane: return 2;
41     case GeomAbs_BezierSurface: return (3 + S->NbVPoles());
42     case GeomAbs_BSplineSurface: 
43     {
44       const Standard_Integer nbs = S->NbVKnots() * S->VDegree();
45       return (nbs < 2 ? 2 : nbs);
46     }
47     case GeomAbs_Cylinder:
48     case GeomAbs_Cone:
49     case GeomAbs_Sphere:
50     case GeomAbs_Torus:
51     case GeomAbs_SurfaceOfRevolution:
52     case GeomAbs_SurfaceOfExtrusion: return 15;
53     default:
54       break;
55   }
56   return 10;
57 }
58
59 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesU(const Handle(Adaptor3d_HSurface)& S,
60                                                     const Standard_Real u1,
61                                                     const Standard_Real u2)
62 {
63   const Standard_Integer nbs = NbSamplesU(S);
64   Standard_Integer n = nbs;
65   if(nbs>10)
66   { 
67     const Standard_Real uf = FirstUParameter(S);
68     const Standard_Real ul = LastUParameter(S);
69     n *= (Standard_Integer)((u2-u1)/(ul-uf));
70     if (n>nbs || n>50) n = nbs;
71     if (n<5)   n = 5;
72   }
73   return n;
74 }
75
76 Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesV(const Handle(Adaptor3d_HSurface)& S,
77                                                     const Standard_Real v1,
78                                                     const Standard_Real v2)
79 {
80   const Standard_Integer nbs = NbSamplesV(S);
81   Standard_Integer n = nbs;
82   if(nbs>10)
83   {
84     const Standard_Real vf = FirstVParameter(S);
85     const Standard_Real vl = LastVParameter(S);
86     n *= (Standard_Integer)((v2-v1)/(vl-vf));
87     if (n>nbs || n>50) n = nbs;
88     if (n<5)   n = 5;
89   }
90   return n;
91 }