Panda3D
Loading...
Searching...
No Matches
nurbsCurveEvaluator.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 nurbsCurveEvaluator.I
10 * @author drose
11 * @date 2002-12-05
12 */
13
14/**
15 * Sets the order of the curve. This resets the knot vector to the default
16 * knot vector for the number of vertices.
17 *
18 * The order must be 1, 2, 3, or 4, and the value is one more than the degree
19 * of the curve.
20 */
22set_order(int order) {
23 _order = order;
24 _knots_dirty = true;
25 _basis_dirty = true;
26}
27
28/**
29 * Returns the order of the curve as set by a previous call to set_order().
30 */
32get_order() const {
33 return _order;
34}
35
36/**
37 * Returns the number of control vertices in the curve. This is the number
38 * passed to the last call to reset().
39 */
40INLINE int NurbsCurveEvaluator::
41get_num_vertices() const {
42 return (int)_vertices.size();
43}
44
45/**
46 * Sets the nth control vertex of the curve, as a vertex in 4-d homogeneous
47 * space. In this form, the first three components of the vertex should
48 * already have been scaled by the fourth component, which is the homogeneous
49 * weight.
50 */
52set_vertex(int i, const LVecBase4 &vertex) {
53 nassertv(i >= 0 && i < (int)_vertices.size());
54 _vertices[i].set_vertex(vertex);
55}
56
57/**
58 * Sets the nth control vertex of the curve. This flavor sets the vertex as a
59 * 3-d coordinate and a weight; the 3-d coordinate values are implicitly
60 * scaled up by the weight factor.
61 */
63set_vertex(int i, const LVecBase3 &vertex, PN_stdfloat weight) {
64 nassertv(i >= 0 && i < (int)_vertices.size());
65 _vertices[i].set_vertex(LVecBase4(vertex[0] * weight, vertex[1] * weight, vertex[2] * weight, weight));
66}
67
68/**
69 * Returns the nth control vertex of the curve, relative to its indicated
70 * coordinate space.
71 */
72INLINE const LVecBase4 &NurbsCurveEvaluator::
73get_vertex(int i) const {
74 nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4::zero());
75 return _vertices[i].get_vertex();
76}
77
78/**
79 * Returns the nth control vertex of the curve, relative to the given
80 * coordinate space.
81 */
82INLINE LVecBase4 NurbsCurveEvaluator::
83get_vertex(int i, const NodePath &rel_to) const {
84 nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4::zero());
85
86 NodePath space = _vertices[i].get_space(rel_to);
87 const LVecBase4 &vertex = _vertices[i].get_vertex();
88 if (space.is_empty()) {
89 return vertex;
90 } else {
91 const LMatrix4 &mat = space.get_mat(rel_to);
92 return vertex * mat;
93 }
94}
95
96/**
97 * Sets the coordinate space of the nth control vertex. If this is not
98 * specified, or is set to an empty NodePath, the nth control vertex is deemed
99 * to be in the coordinate space passed to evaluate().
100 *
101 * This specifies the space as a fixed NodePath, which is always the same
102 * NodePath. Also see setting the space as a path string, which can specify a
103 * different NodePath for different instances of the curve.
104 */
106set_vertex_space(int i, const NodePath &space) {
107 nassertv(i >= 0 && i < (int)_vertices.size());
108 _vertices[i].set_space(space);
109}
110
111/**
112 * Sets the coordinate space of the nth control vertex. If this is not
113 * specified, or is set to an empty string, the nth control vertex is deemed
114 * to be in the coordinate space passed to evaluate().
115 *
116 * This specifies the space as a string, which describes the path to find the
117 * node relative to the rel_to NodePath when the curve is evaluated.
118 */
120set_vertex_space(int i, const std::string &space) {
121 nassertv(i >= 0 && i < (int)_vertices.size());
122 _vertices[i].set_space(space);
123}
124
125/**
126 * Sets an n-dimensional vertex value. This allows definition of a NURBS
127 * surface or curve in a sparse n-dimensional space, typically used for
128 * associating additional properties (like color or joint membership) with
129 * each vertex of a surface.
130 *
131 * The value d is an arbitrary integer value and specifies the dimension of
132 * question for this particular vertex. Any number of dimensions may be
133 * specified, and they need not be consecutive. If a value for a given
134 * dimension is not specified, is it implicitly 0.0.
135 *
136 * The value is implicitly scaled by the homogenous weight value--that is, the
137 * fourth component of the value passed to set_vertex(). This means the
138 * ordinary vertex must be set first, before the extended vertices can be set.
139 */
141set_extended_vertex(int i, int d, PN_stdfloat value) {
142 nassertv(i >= 0 && i < (int)_vertices.size());
143 _vertices[i].set_extended_vertex(d, value);
144}
145
146/**
147 * Returns an n-dimensional vertex value. See set_extended_vertex(). This
148 * returns the value set for the indicated dimension, or 0.0 if nothing has
149 * been set.
150 */
151INLINE PN_stdfloat NurbsCurveEvaluator::
152get_extended_vertex(int i, int d) const {
153 nassertr(i >= 0 && i < (int)_vertices.size(), 0.0f);
154 return _vertices[i].get_extended_vertex(d);
155}
156
157/**
158 * Returns the number of knot values in the curve. This is based on the
159 * number of vertices and the order.
160 */
161INLINE int NurbsCurveEvaluator::
162get_num_knots() const {
163 return (int)_vertices.size() + _order;
164}
165
166/**
167 * Returns the number of piecewise continuous segments in the curve. This is
168 * based on the knot vector.
169 */
171get_num_segments() const {
172 if (_basis_dirty) {
173 ((NurbsCurveEvaluator *)this)->recompute_basis();
174 }
175 return _basis.get_num_segments();
176}
177
178INLINE std::ostream &
179operator << (std::ostream &out, const NurbsCurveEvaluator &n) {
180 n.output(out);
181 return out;
182}
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition nodePath.I:188
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:776
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
This class is an abstraction for evaluating NURBS curves.
get_num_vertices
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.
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.
get_vertex
Returns the nth control vertex of the curve, relative to its indicated coordinate space.
int get_order() const
Returns the order of the curve as set by a previous call to set_order().
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
PN_stdfloat get_extended_vertex(int i, int d) const
Returns an n-dimensional vertex value.
get_num_knots
Returns the number of knot values in the curve.
void set_vertex_space(int i, const NodePath &space)
Sets the coordinate space of the nth control vertex.