Panda3D
nurbsSurfaceResult.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file nurbsSurfaceResult.I
10  * @author drose
11  * @date 2003-10-10
12  */
13 
14 /**
15  *
16  */
17 INLINE NurbsSurfaceResult::
18 ~NurbsSurfaceResult() {
19 }
20 
21 /**
22  * Returns the first legal value of u on the surface. Usually this is 0.0.
23  */
24 INLINE PN_stdfloat NurbsSurfaceResult::
25 get_start_u() const {
26  return _u_basis.get_start_t();
27 }
28 
29 /**
30  * Returns the last legal value of u on the surface.
31  */
32 INLINE PN_stdfloat NurbsSurfaceResult::
33 get_end_u() const {
34  return _u_basis.get_end_t();
35 }
36 
37 /**
38  * Returns the first legal value of v on the surface. Usually this is 0.0.
39  */
40 INLINE PN_stdfloat NurbsSurfaceResult::
41 get_start_v() const {
42  return _v_basis.get_start_t();
43 }
44 
45 /**
46  * Returns the last legal value of v on the surface.
47  */
48 INLINE PN_stdfloat NurbsSurfaceResult::
49 get_end_v() const {
50  return _v_basis.get_end_t();
51 }
52 
53 /**
54  * Computes the point on the surface corresponding to the indicated value in
55  * parametric time. Returns true if the u, v values are valid, false
56  * otherwise.
57  */
58 INLINE bool NurbsSurfaceResult::
59 eval_point(PN_stdfloat u, PN_stdfloat v, LVecBase3 &point) {
60  int ui = find_u_segment(u);
61  int vi = find_v_segment(v);
62  if (ui == -1 || vi == -1) {
63  return false;
64  }
65 
66  eval_segment_point(ui, vi, _u_basis.scale_t(ui, u), _v_basis.scale_t(vi, v),
67  point);
68  return true;
69 }
70 
71 /**
72  * Computes the normal to the surface at the indicated point in parametric
73  * time. This normal vector will not necessarily be normalized, and could be
74  * zero. See also eval_point().
75  */
76 INLINE bool NurbsSurfaceResult::
77 eval_normal(PN_stdfloat u, PN_stdfloat v, LVecBase3 &normal) {
78  int ui = find_u_segment(u);
79  int vi = find_v_segment(v);
80  if (ui == -1 || vi == -1) {
81  return false;
82  }
83 
84  eval_segment_normal(ui, vi, _u_basis.scale_t(ui, u), _v_basis.scale_t(vi, v),
85  normal);
86  return true;
87 }
88 
89 /**
90  * Evaluates the surface in n-dimensional space according to the extended
91  * vertices associated with the surface in the indicated dimension.
92  */
93 INLINE PN_stdfloat NurbsSurfaceResult::
94 eval_extended_point(PN_stdfloat u, PN_stdfloat v, int d) {
95  int ui = find_u_segment(u);
96  int vi = find_v_segment(v);
97  if (ui == -1 || vi == -1) {
98  return 0.0f;
99  }
100 
101  return eval_segment_extended_point(ui, vi, _u_basis.scale_t(ui, u),
102  _v_basis.scale_t(vi, v), d);
103 }
104 
105 /**
106  * Simultaneously performs eval_extended_point on a contiguous sequence of
107  * dimensions. The dimensions evaluated are d through (d + num_values - 1);
108  * the results are filled into the num_values elements in the indicated result
109  * array.
110  */
111 INLINE bool NurbsSurfaceResult::
112 eval_extended_points(PN_stdfloat u, PN_stdfloat v, int d, PN_stdfloat result[],
113  int num_values) {
114  int ui = find_u_segment(u);
115  int vi = find_v_segment(v);
116  if (ui == -1 || vi == -1) {
117  return false;
118  }
119 
120  eval_segment_extended_points(ui, vi, _u_basis.scale_t(ui, u),
121  _v_basis.scale_t(vi, v), d, result,
122  num_values);
123  return true;
124 }
125 
126 /**
127  * Returns the number of piecewise continuous segments within the surface in
128  * the U direction. This number is usually not important unless you plan to
129  * call eval_segment_point().
130  */
131 INLINE int NurbsSurfaceResult::
133  return _u_basis.get_num_segments();
134 }
135 
136 /**
137  * Returns the number of piecewise continuous segments within the surface in
138  * the V direction. This number is usually not important unless you plan to
139  * call eval_segment_point().
140  */
141 INLINE int NurbsSurfaceResult::
143  return _v_basis.get_num_segments();
144 }
145 
146 /**
147  * Accepts a u value in the range [0, 1], and assumed to be relative to the
148  * indicated segment (as in eval_segment_point()), and returns the
149  * corresponding u value in the entire surface (as in eval_point()).
150  */
151 INLINE PN_stdfloat NurbsSurfaceResult::
152 get_segment_u(int ui, PN_stdfloat u) const {
153  return u * (_u_basis.get_to(ui) - _u_basis.get_from(ui)) + _u_basis.get_from(ui);
154 }
155 
156 /**
157  * Accepts a v value in the range [0, 1], and assumed to be relative to the
158  * indicated segment (as in eval_segment_point()), and returns the
159  * corresponding v value in the entire surface (as in eval_point()).
160  */
161 INLINE PN_stdfloat NurbsSurfaceResult::
162 get_segment_v(int vi, PN_stdfloat v) const {
163  return v * (_v_basis.get_to(vi) - _v_basis.get_from(vi)) + _v_basis.get_from(vi);
164 }
165 
166 /**
167  * An internal function to dereference a 2-d vertex coordinate pair into a
168  * linear list of vertices. This returns the linear index corresponding to
169  * the 2-d pair.
170  */
171 INLINE int NurbsSurfaceResult::
172 verti(int ui, int vi) const {
173  return ui * _num_v_vertices + vi;
174 }
175 
176 /**
177  * An internal function to dereference a 2-d segment coordinate pair into a
178  * linear list of segments. This returns the linear index corresponding to
179  * the 2-d pair.
180  */
181 INLINE int NurbsSurfaceResult::
182 segi(int ui, int vi) const {
183  return ui * _v_basis.get_num_segments() + vi;
184 }
PN_stdfloat get_segment_v(int vi, PN_stdfloat v) const
Accepts a v value in the range [0, 1], and assumed to be relative to the indicated segment (as in eva...
bool eval_normal(PN_stdfloat u, PN_stdfloat v, LVecBase3 &normal)
Computes the normal to the surface at the indicated point in parametric time.
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
PN_stdfloat get_from(int segment) const
Returns the t value of the beginning of this segment.
PN_stdfloat get_start_v() const
Returns the first legal value of v on the surface.
PN_stdfloat get_segment_u(int ui, PN_stdfloat u) const
Accepts a u value in the range [0, 1], and assumed to be relative to the indicated segment (as in eva...
PN_stdfloat get_to(int segment) const
Returns the t value of the end of this segment.
int get_num_v_segments() const
Returns the number of piecewise continuous segments within the surface in the V direction.
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
PN_stdfloat get_end_v() const
Returns the last legal value of v on the surface.
PN_stdfloat get_start_u() const
Returns the first legal value of u on the surface.
PN_stdfloat scale_t(int segment, PN_stdfloat t) const
Scales the value of t into the range [0, 1] corresponding to [from, to].
PN_stdfloat get_end_u() const
Returns the last legal value of u on the surface.
void eval_segment_point(int ui, int vi, PN_stdfloat u, PN_stdfloat v, LVecBase3 &point) const
Evaluates the point on the surface corresponding to the indicated value in parametric time within the...
int get_num_u_segments() const
Returns the number of piecewise continuous segments within the surface in the U direction.
bool eval_point(PN_stdfloat u, PN_stdfloat v, LVecBase3 &point)
Computes the point on the surface corresponding to the indicated value in parametric time.
void eval_segment_normal(int ui, int vi, PN_stdfloat u, PN_stdfloat v, LVecBase3 &normal) const
As eval_segment_point, but computes the normal to the surface at the indicated point.
PN_stdfloat eval_segment_extended_point(int ui, int vi, PN_stdfloat u, PN_stdfloat v, int d) const
Evaluates the surface in n-dimensional space according to the extended vertices associated with the s...
bool eval_extended_points(PN_stdfloat u, PN_stdfloat v, int d, PN_stdfloat result[], int num_values)
Simultaneously performs eval_extended_point on a contiguous sequence of dimensions.
PN_stdfloat get_end_t() const
Returns the last legal value of t on the curve.
PN_stdfloat eval_extended_point(PN_stdfloat u, PN_stdfloat v, int d)
Evaluates the surface in n-dimensional space according to the extended vertices associated with the s...
void eval_segment_extended_points(int ui, int vi, PN_stdfloat u, PN_stdfloat v, int d, PN_stdfloat result[], int num_values) const
Simultaneously performs eval_extended_point on a contiguous sequence of dimensions.