Panda3D
 All Classes Functions Variables Enumerations
nurbsCurveEvaluator.I
1 // Filename: nurbsCurveEvaluator.I
2 // Created by: drose (05Dec02)
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: NurbsCurveEvaluator::set_order
18 // Access: Published
19 // Description: Sets the order of the curve. This resets the knot
20 // vector to the default knot vector for the number of
21 // vertices.
22 //
23 // The order must be 1, 2, 3, or 4, and the value is one
24 // more than the degree of the curve.
25 ////////////////////////////////////////////////////////////////////
26 INLINE void NurbsCurveEvaluator::
27 set_order(int order) {
28  _order = order;
29  _knots_dirty = true;
30  _basis_dirty = true;
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: NurbsCurveEvaluator::get_order
35 // Access: Published
36 // Description: Returns the order of the curve as set by a previous
37 // call to set_order().
38 ////////////////////////////////////////////////////////////////////
39 INLINE int NurbsCurveEvaluator::
40 get_order() const {
41  return _order;
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: NurbsCurveEvaluator::get_num_vertices
46 // Access: Published
47 // Description: Returns the number of control vertices in the curve.
48 // This is the number passed to the last call to
49 // reset().
50 ////////////////////////////////////////////////////////////////////
51 INLINE int NurbsCurveEvaluator::
53  return (int)_vertices.size();
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: NurbsCurveEvaluator::set_vertex
58 // Access: Published
59 // Description: Sets the nth control vertex of the curve, as a vertex
60 // in 4-d homogeneous space. In this form, the first
61 // three components of the vertex should already have
62 // been scaled by the fourth component, which is the
63 // homogeneous weight.
64 ////////////////////////////////////////////////////////////////////
65 INLINE void NurbsCurveEvaluator::
66 set_vertex(int i, const LVecBase4 &vertex) {
67  nassertv(i >= 0 && i < (int)_vertices.size());
68  _vertices[i].set_vertex(vertex);
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: NurbsCurveEvaluator::set_vertex
73 // Access: Published
74 // Description: Sets the nth control vertex of the curve. This
75 // flavor sets the vertex as a 3-d coordinate and a
76 // weight; the 3-d coordinate values are implicitly
77 // scaled up by the weight factor.
78 ////////////////////////////////////////////////////////////////////
79 INLINE void NurbsCurveEvaluator::
80 set_vertex(int i, const LVecBase3 &vertex, PN_stdfloat weight) {
81  nassertv(i >= 0 && i < (int)_vertices.size());
82  _vertices[i].set_vertex(LVecBase4(vertex[0] * weight, vertex[1] * weight, vertex[2] * weight, weight));
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: NurbsCurveEvaluator::get_vertex
87 // Access: Published
88 // Description: Returns the nth control vertex of the curve, relative
89 // to its indicated coordinate space.
90 ////////////////////////////////////////////////////////////////////
91 INLINE const LVecBase4 &NurbsCurveEvaluator::
92 get_vertex(int i) const {
93  nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4::zero());
94  return _vertices[i].get_vertex();
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: NurbsCurveEvaluator::get_vertex
99 // Access: Published
100 // Description: Returns the nth control vertex of the curve, relative
101 // to the given coordinate space.
102 ////////////////////////////////////////////////////////////////////
104 get_vertex(int i, const NodePath &rel_to) const {
105  nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4::zero());
106 
107  NodePath space = _vertices[i].get_space(rel_to);
108  const LVecBase4 &vertex = _vertices[i].get_vertex();
109  if (space.is_empty()) {
110  return vertex;
111  } else {
112  const LMatrix4 &mat = space.get_mat(rel_to);
113  return vertex * mat;
114  }
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: NurbsCurveEvaluator::set_vertex_space
119 // Access: Published
120 // Description: Sets the coordinate space of the nth control vertex.
121 // If this is not specified, or is set to an empty
122 // NodePath, the nth control vertex is deemed to be in
123 // the coordinate space passed to evaluate().
124 //
125 // This specifies the space as a fixed NodePath, which
126 // is always the same NodePath. Also see setting the
127 // space as a path string, which can specify a different
128 // NodePath for different instances of the curve.
129 ////////////////////////////////////////////////////////////////////
130 INLINE void NurbsCurveEvaluator::
131 set_vertex_space(int i, const NodePath &space) {
132  nassertv(i >= 0 && i < (int)_vertices.size());
133  _vertices[i].set_space(space);
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: NurbsCurveEvaluator::set_vertex_space
138 // Access: Published
139 // Description: Sets the coordinate space of the nth control vertex.
140 // If this is not specified, or is set to an empty
141 // string, the nth control vertex is deemed to be in
142 // the coordinate space passed to evaluate().
143 //
144 // This specifies the space as a string, which describes
145 // the path to find the node relative to the rel_to
146 // NodePath when the curve is evaluated.
147 ////////////////////////////////////////////////////////////////////
148 INLINE void NurbsCurveEvaluator::
149 set_vertex_space(int i, const string &space) {
150  nassertv(i >= 0 && i < (int)_vertices.size());
151  _vertices[i].set_space(space);
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: NurbsCurveEvaluator::set_extended_vertex
156 // Access: Public
157 // Description: Sets an n-dimensional vertex value. This allows
158 // definition of a NURBS surface or curve in a sparse
159 // n-dimensional space, typically used for associating
160 // additional properties (like color or joint
161 // membership) with each vertex of a surface.
162 //
163 // The value d is an arbitrary integer value and
164 // specifies the dimension of question for this
165 // particular vertex. Any number of dimensions may be
166 // specified, and they need not be consecutive. If a
167 // value for a given dimension is not specified, is it
168 // implicitly 0.0.
169 //
170 // The value is implicitly scaled by the homogenous
171 // weight value--that is, the fourth component of the
172 // value passed to set_vertex(). This means the
173 // ordinary vertex must be set first, before the
174 // extended vertices can be set.
175 ////////////////////////////////////////////////////////////////////
176 INLINE void NurbsCurveEvaluator::
177 set_extended_vertex(int i, int d, PN_stdfloat value) {
178  nassertv(i >= 0 && i < (int)_vertices.size());
179  _vertices[i].set_extended_vertex(d, value);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: NurbsCurveEvaluator::get_extended_vertex
184 // Access: Public
185 // Description: Returns an n-dimensional vertex value. See
186 // set_extended_vertex(). This returns the value set
187 // for the indicated dimension, or 0.0 if nothing has
188 // been set.
189 ////////////////////////////////////////////////////////////////////
190 INLINE PN_stdfloat NurbsCurveEvaluator::
191 get_extended_vertex(int i, int d) const {
192  nassertr(i >= 0 && i < (int)_vertices.size(), 0.0f);
193  return _vertices[i].get_extended_vertex(d);
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: NurbsCurveEvaluator::get_num_knots
198 // Access: Published
199 // Description: Returns the number of knot values in the curve. This
200 // is based on the number of vertices and the order.
201 ////////////////////////////////////////////////////////////////////
202 INLINE int NurbsCurveEvaluator::
203 get_num_knots() const {
204  return (int)_vertices.size() + _order;
205 }
206 
207 ////////////////////////////////////////////////////////////////////
208 // Function: NurbsCurveEvaluator::get_num_segments
209 // Access: Published
210 // Description: Returns the number of piecewise continuous segments
211 // in the curve. This is based on the knot vector.
212 ////////////////////////////////////////////////////////////////////
213 INLINE int NurbsCurveEvaluator::
215  if (_basis_dirty) {
216  ((NurbsCurveEvaluator *)this)->recompute_basis();
217  }
218  return _basis.get_num_segments();
219 }
220 
221 INLINE ostream &
222 operator << (ostream &out, const NurbsCurveEvaluator &n) {
223  n.output(out);
224  return out;
225 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
This class is an abstraction for evaluating NURBS curves.
int get_num_knots() const
Returns the number of knot values in the curve.
const LVecBase4 & get_vertex(int i) const
Returns the nth control vertex of the curve, relative to its indicated coordinate space...
void set_order(int order)
Sets the order of the curve.
void set_extended_vertex(int i, int d, PN_stdfloat value)
Sets an n-dimensional vertex value.
int get_num_vertices() const
Returns the number of control vertices in the curve.
void set_vertex(int i, const LVecBase4 &vertex)
Sets the nth control vertex of the curve, as a vertex in 4-d homogeneous space.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
PN_stdfloat get_extended_vertex(int i, int d) const
Returns an n-dimensional vertex value.
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
void set_vertex_space(int i, const NodePath &space)
Sets the coordinate space of the nth control vertex.
int get_order() const
Returns the order of the curve as set by a previous call to set_order().
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:492