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