b311480e |
1 | // Created by: Laurent BUCHARD |
2 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <Adaptor3d_HCurve.hxx> |
18 | #include <Adaptor3d_HSurface.hxx> |
19 | #include <Adaptor3d_HSurfaceTool.hxx> |
20 | #include <Geom_BezierSurface.hxx> |
21 | #include <Geom_BSplineSurface.hxx> |
22 | #include <gp_Pnt.hxx> |
23 | #include <gp_Vec.hxx> |
24 | #include <Standard_NoSuchObject.hxx> |
25 | #include <Standard_OutOfRange.hxx> |
7fd59977 |
26 | |
27 | Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesU(const Handle(Adaptor3d_HSurface)& S) |
28 | { |
29 | switch (S->GetType()) |
30 | { |
31 | case GeomAbs_Plane: return 2; |
32 | case GeomAbs_BezierSurface: return (3 + S->NbUPoles()); |
33 | case GeomAbs_BSplineSurface: |
34 | { |
35 | const Standard_Integer nbs = S->NbUKnots() * S->UDegree(); |
36 | return (nbs < 2 ? 2 : nbs); |
37 | } |
38 | case GeomAbs_Torus: return 20; |
566f8441 |
39 | default: |
40 | break; |
7fd59977 |
41 | } |
42 | return 10; |
43 | } |
44 | |
45 | Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesV(const Handle(Adaptor3d_HSurface)& S) |
46 | { |
47 | switch (S->GetType()) |
48 | { |
49 | case GeomAbs_Plane: return 2; |
50 | case GeomAbs_BezierSurface: return (3 + S->NbVPoles()); |
51 | case GeomAbs_BSplineSurface: |
52 | { |
53 | const Standard_Integer nbs = S->NbVKnots() * S->VDegree(); |
54 | return (nbs < 2 ? 2 : nbs); |
55 | } |
56 | case GeomAbs_Cylinder: |
57 | case GeomAbs_Cone: |
58 | case GeomAbs_Sphere: |
59 | case GeomAbs_Torus: |
60 | case GeomAbs_SurfaceOfRevolution: |
61 | case GeomAbs_SurfaceOfExtrusion: return 15; |
566f8441 |
62 | default: |
63 | break; |
7fd59977 |
64 | } |
65 | return 10; |
66 | } |
67 | |
68 | Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesU(const Handle(Adaptor3d_HSurface)& S, |
69 | const Standard_Real u1, |
70 | const Standard_Real u2) |
71 | { |
72 | const Standard_Integer nbs = NbSamplesU(S); |
73 | Standard_Integer n = nbs; |
74 | if(nbs>10) |
75 | { |
76 | const Standard_Real uf = FirstUParameter(S); |
77 | const Standard_Real ul = LastUParameter(S); |
78 | n *= (Standard_Integer)((u2-u1)/(ul-uf)); |
79 | if (n>nbs || n>50) n = nbs; |
80 | if (n<5) n = 5; |
81 | } |
82 | return n; |
83 | } |
84 | |
85 | Standard_Integer Adaptor3d_HSurfaceTool::NbSamplesV(const Handle(Adaptor3d_HSurface)& S, |
86 | const Standard_Real v1, |
87 | const Standard_Real v2) |
88 | { |
89 | const Standard_Integer nbs = NbSamplesV(S); |
90 | Standard_Integer n = nbs; |
91 | if(nbs>10) |
92 | { |
93 | const Standard_Real vf = FirstVParameter(S); |
94 | const Standard_Real vl = LastVParameter(S); |
95 | n *= (Standard_Integer)((v2-v1)/(vl-vf)); |
96 | if (n>nbs || n>50) n = nbs; |
97 | if (n<5) n = 5; |
98 | } |
99 | return n; |
100 | } |