Panda3D
Loading...
Searching...
No Matches
nurbsSurfaceEvaluator.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 nurbsSurfaceEvaluator.I
10 * @author drose
11 * @date 2003-10-10
12 */
13
14/**
15 * Sets the order of the surface in the U direction. This resets the knot
16 * vector to the default 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 surface.
20 */
22set_u_order(int u_order) {
23 _u_order = u_order;
24 _u_knots_dirty = true;
25 _u_basis_dirty = true;
26}
27
28/**
29 * Returns the order of the surface in the U direction as set by a previous
30 * call to set_u_order().
31 */
33get_u_order() const {
34 return _u_order;
35}
36
37/**
38 * Sets the order of the surface in the V direction. This resets the knot
39 * vector to the default knot vector for the number of vertices.
40 *
41 * The order must be 1, 2, 3, or 4, and the value is one more than the degree
42 * of the surface.
43 */
45set_v_order(int v_order) {
46 _v_order = v_order;
47 _v_knots_dirty = true;
48 _v_basis_dirty = true;
49}
50
51/**
52 * Returns the order of the surface in the V direction as set by a previous
53 * call to set_v_order().
54 */
56get_v_order() const {
57 return _v_order;
58}
59
60/**
61 * Returns the number of control vertices in the U direction on the surface.
62 * This is the number passed to the last call to reset().
63 */
65get_num_u_vertices() const {
66 return _num_u_vertices;
67}
68
69/**
70 * Returns the number of control vertices in the V direction on the surface.
71 * This is the number passed to the last call to reset().
72 */
74get_num_v_vertices() const {
75 return _num_v_vertices;
76}
77
78/**
79 * Sets the nth control vertex of the surface, as a vertex in 4-d homogeneous
80 * space. In this form, the first three components of the vertex should
81 * already have been scaled by the fourth component, which is the homogeneous
82 * weight.
83 */
85set_vertex(int ui, int vi, const LVecBase4 &vertex) {
86 nassertv(ui >= 0 && ui < _num_u_vertices &&
87 vi >= 0 && vi < _num_v_vertices);
88 vert(ui, vi).set_vertex(vertex);
89}
90
91/**
92 * Sets the nth control vertex of the surface. This flavor sets the vertex as
93 * a 3-d coordinate and a weight; the 3-d coordinate values are implicitly
94 * scaled up by the weight factor.
95 */
97set_vertex(int ui, int vi, const LVecBase3 &vertex, PN_stdfloat weight) {
98 nassertv(ui >= 0 && ui < _num_u_vertices &&
99 vi >= 0 && vi < _num_v_vertices);
100 vert(ui, vi).set_vertex(LVecBase4(vertex[0] * weight, vertex[1] * weight, vertex[2] * weight, weight));
101}
102
103/**
104 * Returns the nth control vertex of the surface, relative to its indicated
105 * coordinate space.
106 */
107INLINE const LVecBase4 &NurbsSurfaceEvaluator::
108get_vertex(int ui, int vi) const {
109 nassertr(ui >= 0 && ui < _num_u_vertices &&
110 vi >= 0 && vi < _num_v_vertices, LVecBase4::zero());
111 return vert(ui, vi).get_vertex();
112}
113
114/**
115 * Returns the nth control vertex of the surface, relative to the given
116 * coordinate space.
117 */
119get_vertex(int ui, int vi, const NodePath &rel_to) const {
120 nassertr(ui >= 0 && ui < _num_u_vertices &&
121 vi >= 0 && vi < _num_v_vertices, LVecBase4::zero());
122
123 NodePath space = vert(ui, vi).get_space(rel_to);
124 const LVecBase4 &vertex = vert(ui, vi).get_vertex();
125 if (space.is_empty()) {
126 return vertex;
127 } else {
128 const LMatrix4 &mat = space.get_mat(rel_to);
129 return vertex * mat;
130 }
131}
132
133/**
134 * Sets the coordinate space of the nth control vertex. If this is not
135 * specified, or is set to an empty NodePath, the nth control vertex is deemed
136 * to be in the coordinate space passed to evaluate().
137 *
138 * This specifies the space as a fixed NodePath, which is always the same
139 * NodePath. Also see setting the space as a path string, which can specify a
140 * different NodePath for different instances of the surface.
141 */
143set_vertex_space(int ui, int vi, const NodePath &space) {
144 nassertv(ui >= 0 && ui < _num_u_vertices &&
145 vi >= 0 && vi < _num_v_vertices);
146 vert(ui, vi).set_space(space);
147}
148
149/**
150 * Sets the coordinate space of the nth control vertex. If this is not
151 * specified, or is set to an empty string, the nth control vertex is deemed
152 * to be in the coordinate space passed to evaluate().
153 *
154 * This specifies the space as a string, which describes the path to find the
155 * node relative to the rel_to NodePath when the surface is evaluated.
156 */
158set_vertex_space(int ui, int vi, const std::string &space) {
159 nassertv(ui >= 0 && ui < _num_u_vertices &&
160 vi >= 0 && vi < _num_v_vertices);
161 vert(ui, vi).set_space(space);
162}
163
164/**
165 * Sets an n-dimensional vertex value. This allows definition of a NURBS
166 * surface or surface in a sparse n-dimensional space, typically used for
167 * associating additional properties (like color or joint membership) with
168 * each vertex of a surface.
169 *
170 * The value d is an arbitrary integer value and specifies the dimension of
171 * question for this particular vertex. Any number of dimensions may be
172 * specified, and they need not be consecutive. If a value for a given
173 * dimension is not specified, is it implicitly 0.0.
174 *
175 * The value is implicitly scaled by the homogenous weight value--that is, the
176 * fourth component of the value passed to set_vertex(). This means the
177 * ordinary vertex must be set first, before the extended vertices can be set.
178 */
180set_extended_vertex(int ui, int vi, int d, PN_stdfloat value) {
181 nassertv(ui >= 0 && ui < _num_u_vertices &&
182 vi >= 0 && vi < _num_v_vertices);
183 vert(ui, vi).set_extended_vertex(d, value);
184}
185
186/**
187 * Returns an n-dimensional vertex value. See set_extended_vertex(). This
188 * returns the value set for the indicated dimension, or 0.0 if nothing has
189 * been set.
190 */
191INLINE PN_stdfloat NurbsSurfaceEvaluator::
192get_extended_vertex(int ui, int vi, int d) const {
193 nassertr(ui >= 0 && ui < _num_u_vertices &&
194 vi >= 0 && vi < _num_v_vertices, 0.0f);
195 return vert(ui, vi).get_extended_vertex(d);
196}
197
198/**
199 * Returns the number of knot values in the surface in the U direction. This
200 * is based on the number of vertices and the order.
201 */
203get_num_u_knots() const {
204 return _num_u_vertices + _u_order;
205}
206
207/**
208 * Returns the number of knot values in the surface in the V direction. This
209 * is based on the number of vertices and the order.
210 */
212get_num_v_knots() const {
213 return _num_v_vertices + _v_order;
214}
215
216/**
217 * Returns the number of piecewise continuous segments in the surface in the U
218 * direction. This is based on the knot vector.
219 */
221get_num_u_segments() const {
222 if (_u_basis_dirty) {
223 ((NurbsSurfaceEvaluator *)this)->recompute_u_basis();
224 }
225 return _u_basis.get_num_segments();
226}
227
228/**
229 * Returns the number of piecewise continuous segments in the surface in the V
230 * direction. This is based on the knot vector.
231 */
233get_num_v_segments() const {
234 if (_v_basis_dirty) {
235 ((NurbsSurfaceEvaluator *)this)->recompute_v_basis();
236 }
237 return _v_basis.get_num_segments();
238}
239
240/**
241 * Internal accessor to dereference the 2-d vertex coordinate pair into a
242 * linear list of vertices.
243 */
244INLINE NurbsVertex &NurbsSurfaceEvaluator::
245vert(int ui, int vi) {
246 return _vertices[ui * _num_v_vertices + vi];
247}
248
249/**
250 * Internal accessor to dereference the 2-d vertex coordinate pair into a
251 * linear list of vertices.
252 */
253INLINE const NurbsVertex &NurbsSurfaceEvaluator::
254vert(int ui, int vi) const {
255 return _vertices[ui * _num_v_vertices + vi];
256}
257
258INLINE std::ostream &
259operator << (std::ostream &out, const NurbsSurfaceEvaluator &n) {
260 n.output(out);
261 return out;
262}
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 surfaces.
void set_extended_vertex(int ui, int vi, int d, PN_stdfloat value)
Sets an n-dimensional vertex value.
get_v_order
Returns the order of the surface in the V direction as set by a previous call to set_v_order().
PN_stdfloat get_extended_vertex(int ui, int vi, int d) const
Returns an n-dimensional vertex value.
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.
get_num_v_knots
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.
set_u_order
Sets the order of the surface in the U direction.
set_v_order
Sets the order of the surface in the V direction.
int get_num_u_vertices() const
Returns the number of control vertices in the U direction on the surface.
get_num_u_knots
Returns the number of knot values in the surface in the U direction.
int get_num_v_vertices() const
Returns the number of control vertices in the V direction on the surface.
void set_vertex_space(int ui, int vi, const NodePath &space)
Sets the coordinate space of the nth control vertex.
get_u_order
Returns the order of the surface in the U direction as set by a previous call to set_u_order().
int get_num_u_segments() const
Returns the number of piecewise continuous segments in the surface in the U direction.
This represents a single control vertex in a NurbsEvaluator.
Definition nurbsVertex.h:32
void set_extended_vertex(int d, PN_stdfloat value)
Sets an n-dimensional vertex value.
void set_space(const NodePath &space)
Sets the space of this vertex as a fixed NodePath.
Definition nurbsVertex.I:70
PN_stdfloat get_extended_vertex(int d) const
Returns an n-dimensional vertex value.