Panda3D
nurbsSurfaceEvaluator.I
1 // Filename: nurbsSurfaceEvaluator.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: NurbsSurfaceEvaluator::set_u_order
18 // Access: Published
19 // Description: Sets the order of the surface in the U direction.
20 // This resets the knot vector to the default knot
21 // vector for the number of vertices.
22 //
23 // The order must be 1, 2, 3, or 4, and the value is one
24 // more than the degree of the surface.
25 ////////////////////////////////////////////////////////////////////
26 INLINE void NurbsSurfaceEvaluator::
27 set_u_order(int u_order) {
28  _u_order = u_order;
29  _u_knots_dirty = true;
30  _u_basis_dirty = true;
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: NurbsSurfaceEvaluator::get_u_order
35 // Access: Published
36 // Description: Returns the order of the surface in the U direction
37 // as set by a previous call to set_u_order().
38 ////////////////////////////////////////////////////////////////////
39 INLINE int NurbsSurfaceEvaluator::
40 get_u_order() const {
41  return _u_order;
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: NurbsSurfaceEvaluator::set_v_order
46 // Access: Published
47 // Description: Sets the order of the surface in the V direction.
48 // This resets the knot vector to the default knot
49 // vector for the number of vertices.
50 //
51 // The order must be 1, 2, 3, or 4, and the value is one
52 // more than the degree of the surface.
53 ////////////////////////////////////////////////////////////////////
54 INLINE void NurbsSurfaceEvaluator::
55 set_v_order(int v_order) {
56  _v_order = v_order;
57  _v_knots_dirty = true;
58  _v_basis_dirty = true;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: NurbsSurfaceEvaluator::get_v_order
63 // Access: Published
64 // Description: Returns the order of the surface in the V direction
65 // as set by a previous call to set_v_order().
66 ////////////////////////////////////////////////////////////////////
67 INLINE int NurbsSurfaceEvaluator::
68 get_v_order() const {
69  return _v_order;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: NurbsSurfaceEvaluator::get_num_u_vertices
74 // Access: Published
75 // Description: Returns the number of control vertices in the U
76 // direction on the surface. This is the number passed
77 // to the last call to reset().
78 ////////////////////////////////////////////////////////////////////
79 INLINE int NurbsSurfaceEvaluator::
81  return _num_u_vertices;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: NurbsSurfaceEvaluator::get_num_v_vertices
86 // Access: Published
87 // Description: Returns the number of control vertices in the V
88 // direction on the surface. This is the number passed
89 // to the last call to reset().
90 ////////////////////////////////////////////////////////////////////
91 INLINE int NurbsSurfaceEvaluator::
93  return _num_v_vertices;
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: NurbsSurfaceEvaluator::set_vertex
98 // Access: Published
99 // Description: Sets the nth control vertex of the surface, as a vertex
100 // in 4-d homogeneous space. In this form, the first
101 // three components of the vertex should already have
102 // been scaled by the fourth component, which is the
103 // homogeneous weight.
104 ////////////////////////////////////////////////////////////////////
105 INLINE void NurbsSurfaceEvaluator::
106 set_vertex(int ui, int vi, const LVecBase4 &vertex) {
107  nassertv(ui >= 0 && ui < _num_u_vertices &&
108  vi >= 0 && vi < _num_v_vertices);
109  vert(ui, vi).set_vertex(vertex);
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: NurbsSurfaceEvaluator::set_vertex
114 // Access: Published
115 // Description: Sets the nth control vertex of the surface. This
116 // flavor sets the vertex as a 3-d coordinate and a
117 // weight; the 3-d coordinate values are implicitly
118 // scaled up by the weight factor.
119 ////////////////////////////////////////////////////////////////////
120 INLINE void NurbsSurfaceEvaluator::
121 set_vertex(int ui, int vi, const LVecBase3 &vertex, PN_stdfloat weight) {
122  nassertv(ui >= 0 && ui < _num_u_vertices &&
123  vi >= 0 && vi < _num_v_vertices);
124  vert(ui, vi).set_vertex(LVecBase4(vertex[0] * weight, vertex[1] * weight, vertex[2] * weight, weight));
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: NurbsSurfaceEvaluator::get_vertex
129 // Access: Published
130 // Description: Returns the nth control vertex of the surface, relative
131 // to its indicated coordinate space.
132 ////////////////////////////////////////////////////////////////////
134 get_vertex(int ui, int vi) const {
135  nassertr(ui >= 0 && ui < _num_u_vertices &&
136  vi >= 0 && vi < _num_v_vertices, LVecBase4::zero());
137  return vert(ui, vi).get_vertex();
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: NurbsSurfaceEvaluator::get_vertex
142 // Access: Published
143 // Description: Returns the nth control vertex of the surface, relative
144 // to the given coordinate space.
145 ////////////////////////////////////////////////////////////////////
147 get_vertex(int ui, int vi, const NodePath &rel_to) const {
148  nassertr(ui >= 0 && ui < _num_u_vertices &&
149  vi >= 0 && vi < _num_v_vertices, LVecBase4::zero());
150 
151  NodePath space = vert(ui, vi).get_space(rel_to);
152  const LVecBase4 &vertex = vert(ui, vi).get_vertex();
153  if (space.is_empty()) {
154  return vertex;
155  } else {
156  const LMatrix4 &mat = space.get_mat(rel_to);
157  return vertex * mat;
158  }
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: NurbsSurfaceEvaluator::set_vertex_space
163 // Access: Published
164 // Description: Sets the coordinate space of the nth control vertex.
165 // If this is not specified, or is set to an empty
166 // NodePath, the nth control vertex is deemed to be in
167 // the coordinate space passed to evaluate().
168 //
169 // This specifies the space as a fixed NodePath, which
170 // is always the same NodePath. Also see setting the
171 // space as a path string, which can specify a different
172 // NodePath for different instances of the surface.
173 ////////////////////////////////////////////////////////////////////
174 INLINE void NurbsSurfaceEvaluator::
175 set_vertex_space(int ui, int vi, const NodePath &space) {
176  nassertv(ui >= 0 && ui < _num_u_vertices &&
177  vi >= 0 && vi < _num_v_vertices);
178  vert(ui, vi).set_space(space);
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: NurbsSurfaceEvaluator::set_vertex_space
183 // Access: Published
184 // Description: Sets the coordinate space of the nth control vertex.
185 // If this is not specified, or is set to an empty
186 // string, the nth control vertex is deemed to be in
187 // the coordinate space passed to evaluate().
188 //
189 // This specifies the space as a string, which describes
190 // the path to find the node relative to the rel_to
191 // NodePath when the surface is evaluated.
192 ////////////////////////////////////////////////////////////////////
193 INLINE void NurbsSurfaceEvaluator::
194 set_vertex_space(int ui, int vi, const string &space) {
195  nassertv(ui >= 0 && ui < _num_u_vertices &&
196  vi >= 0 && vi < _num_v_vertices);
197  vert(ui, vi).set_space(space);
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: NurbsSurfaceEvaluator::set_extended_vertex
202 // Access: Public
203 // Description: Sets an n-dimensional vertex value. This allows
204 // definition of a NURBS surface or surface in a sparse
205 // n-dimensional space, typically used for associating
206 // additional properties (like color or joint
207 // membership) with each vertex of a surface.
208 //
209 // The value d is an arbitrary integer value and
210 // specifies the dimension of question for this
211 // particular vertex. Any number of dimensions may be
212 // specified, and they need not be consecutive. If a
213 // value for a given dimension is not specified, is it
214 // implicitly 0.0.
215 //
216 // The value is implicitly scaled by the homogenous
217 // weight value--that is, the fourth component of the
218 // value passed to set_vertex(). This means the
219 // ordinary vertex must be set first, before the
220 // extended vertices can be set.
221 ////////////////////////////////////////////////////////////////////
222 INLINE void NurbsSurfaceEvaluator::
223 set_extended_vertex(int ui, int vi, int d, PN_stdfloat value) {
224  nassertv(ui >= 0 && ui < _num_u_vertices &&
225  vi >= 0 && vi < _num_v_vertices);
226  vert(ui, vi).set_extended_vertex(d, value);
227 }
228 
229 ////////////////////////////////////////////////////////////////////
230 // Function: NurbsSurfaceEvaluator::get_extended_vertex
231 // Access: Public
232 // Description: Returns an n-dimensional vertex value. See
233 // set_extended_vertex(). This returns the value set
234 // for the indicated dimension, or 0.0 if nothing has
235 // been set.
236 ////////////////////////////////////////////////////////////////////
237 INLINE PN_stdfloat NurbsSurfaceEvaluator::
238 get_extended_vertex(int ui, int vi, int d) const {
239  nassertr(ui >= 0 && ui < _num_u_vertices &&
240  vi >= 0 && vi < _num_v_vertices, 0.0f);
241  return vert(ui, vi).get_extended_vertex(d);
242 }
243 
244 ////////////////////////////////////////////////////////////////////
245 // Function: NurbsSurfaceEvaluator::get_num_u_knots
246 // Access: Published
247 // Description: Returns the number of knot values in the surface in
248 // the U direction. This is based on the number of
249 // vertices and the order.
250 ////////////////////////////////////////////////////////////////////
251 INLINE int NurbsSurfaceEvaluator::
253  return _num_u_vertices + _u_order;
254 }
255 
256 ////////////////////////////////////////////////////////////////////
257 // Function: NurbsSurfaceEvaluator::get_num_v_knots
258 // Access: Published
259 // Description: Returns the number of knot values in the surface in
260 // the V direction. This is based on the number of
261 // vertices and the order.
262 ////////////////////////////////////////////////////////////////////
263 INLINE int NurbsSurfaceEvaluator::
265  return _num_v_vertices + _v_order;
266 }
267 
268 ////////////////////////////////////////////////////////////////////
269 // Function: NurbsSurfaceEvaluator::get_num_u_segments
270 // Access: Published
271 // Description: Returns the number of piecewise continuous segments
272 // in the surface in the U direction. This is based on
273 // the knot vector.
274 ////////////////////////////////////////////////////////////////////
275 INLINE int NurbsSurfaceEvaluator::
277  if (_u_basis_dirty) {
278  ((NurbsSurfaceEvaluator *)this)->recompute_u_basis();
279  }
280  return _u_basis.get_num_segments();
281 }
282 
283 ////////////////////////////////////////////////////////////////////
284 // Function: NurbsSurfaceEvaluator::get_num_v_segments
285 // Access: Published
286 // Description: Returns the number of piecewise continuous segments
287 // in the surface in the V direction. This is based on
288 // the knot vector.
289 ////////////////////////////////////////////////////////////////////
290 INLINE int NurbsSurfaceEvaluator::
292  if (_v_basis_dirty) {
293  ((NurbsSurfaceEvaluator *)this)->recompute_v_basis();
294  }
295  return _v_basis.get_num_segments();
296 }
297 
298 ////////////////////////////////////////////////////////////////////
299 // Function: NurbsSurfaceEvaluator::vert
300 // Access: Private
301 // Description: Internal accessor to dereference the 2-d vertex
302 // coordinate pair into a linear list of vertices.
303 ////////////////////////////////////////////////////////////////////
304 INLINE NurbsVertex &NurbsSurfaceEvaluator::
305 vert(int ui, int vi) {
306  return _vertices[ui * _num_v_vertices + vi];
307 }
308 
309 ////////////////////////////////////////////////////////////////////
310 // Function: NurbsSurfaceEvaluator::vert
311 // Access: Private
312 // Description: Internal accessor to dereference the 2-d vertex
313 // coordinate pair into a linear list of vertices.
314 ////////////////////////////////////////////////////////////////////
315 INLINE const NurbsVertex &NurbsSurfaceEvaluator::
316 vert(int ui, int vi) const {
317  return _vertices[ui * _num_v_vertices + vi];
318 }
319 
320 INLINE ostream &
321 operator << (ostream &out, const NurbsSurfaceEvaluator &n) {
322  n.output(out);
323  return out;
324 }
void set_vertex_space(int ui, int vi, const NodePath &space)
Sets the coordinate space of the nth control vertex.
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
int get_num_v_knots() const
Returns the number of knot values in the surface in the V direction.
const LVecBase4 & get_vertex(int ui, int vi) const
Returns the nth control vertex of the surface, relative to its indicated coordinate space...
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:236
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
void set_extended_vertex(int ui, int vi, int d, PN_stdfloat value)
Sets an n-dimensional vertex value.
int get_u_order() const
Returns the order of the surface in the U direction as set by a previous call to set_u_order().
This class is an abstraction for evaluating NURBS surfaces.
int get_v_order() const
Returns the order of the surface in the V direction as set by a previous call to set_v_order().
int get_num_v_vertices() const
Returns the number of control vertices in the V direction on the surface.
This represents a single control vertex in a NurbsEvaluator.
Definition: nurbsVertex.h:36
int get_num_u_vertices() const
Returns the number of control vertices in the U direction on the surface.
int get_num_u_knots() const
Returns the number of knot values in the surface in the U direction.
void set_vertex(int ui, int vi, const LVecBase4 &vertex)
Sets the nth control vertex of the surface, as a vertex in 4-d homogeneous space. ...
int get_num_v_segments() const
Returns the number of piecewise continuous segments in the surface in the V direction.
int get_num_u_segments() const
Returns the number of piecewise continuous segments in the surface in the U direction.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
void set_space(const NodePath &space)
Sets the space of this vertex as a fixed NodePath.
Definition: nurbsVertex.I:86
void set_u_order(int u_order)
Sets the order of the surface in the U direction.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
PN_stdfloat get_extended_vertex(int d) const
Returns an n-dimensional vertex value.
Definition: nurbsVertex.cxx:54
void set_v_order(int v_order)
Sets the order of the surface in the V direction.
const LMatrix4 & get_mat() const
Returns the transform matrix that has been applied to the referenced node, or the identity matrix if ...
Definition: nodePath.I:965
void set_extended_vertex(int d, PN_stdfloat value)
Sets an n-dimensional vertex value.
Definition: nurbsVertex.cxx:41
PN_stdfloat get_extended_vertex(int ui, int vi, int d) const
Returns an n-dimensional vertex value.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
static const LVecBase4f & zero()
Returns a zero-length vector.
Definition: lvecBase4.h:493