Panda3D
Loading...
Searching...
No Matches
eggNurbsSurface.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 eggNurbsSurface.I
10 * @author drose
11 * @date 2000-02-15
12 */
13
14/**
15 *
16 */
17INLINE EggNurbsSurface::
18EggNurbsSurface(const std::string &name) : EggSurface(name) {
19 _u_order = 0;
20 _v_order = 0;
21}
22
23/**
24 *
25 */
26INLINE EggNurbsSurface::
27EggNurbsSurface(const EggNurbsSurface &copy) :
28 EggSurface(copy),
29 _u_knots(copy._u_knots),
30 _v_knots(copy._v_knots),
31 _u_order(copy._u_order),
32 _v_order(copy._v_order)
33{
34}
35
36/**
37 *
38 */
39INLINE EggNurbsSurface &EggNurbsSurface::
40operator = (const EggNurbsSurface &copy) {
41 EggSurface::operator = (copy);
42 _u_knots = copy._u_knots;
43 _v_knots = copy._v_knots;
44 _u_order = copy._u_order;
45 _v_order = copy._v_order;
46 return *this;
47}
48
49/**
50 * Directly changes the order in the U direction to the indicated value (which
51 * must be an integer in the range 1 <= u_order <= 4). If possible, it is
52 * preferable to use the setup() method instead of this method, since changing
53 * the order directly may result in an invalid surface.
54 */
56set_u_order(int u_order) {
57 nassertv(u_order >= 1 && u_order <= 4);
58 _u_order = u_order;
59}
60
61/**
62 * Directly changes the order in the V direction to the indicated value (which
63 * must be an integer in the range 1 <= v_order <= 4). If possible, it is
64 * preferable to use the setup() method instead of this method, since changing
65 * the order directly may result in an invalid surface.
66 */
68set_v_order(int v_order) {
69 nassertv(v_order >= 1 && v_order <= 4);
70 _v_order = v_order;
71}
72
73/**
74 * Resets the value of the indicated knot as indicated. k must be in the
75 * range 0 <= k < get_num_u_knots(), and the value must be in the range
76 * get_u_knot(k - 1) <= value <= get_u_knot(k + 1).
77 */
79set_u_knot(int k, double value) {
80 nassertv(k >= 0 && k < (int)_u_knots.size());
81 _u_knots[k] = value;
82}
83
84/**
85 * Resets the value of the indicated knot as indicated. k must be in the
86 * range 0 <= k < get_num_v_knots(), and the value must be in the range
87 * get_v_knot(k - 1) <= value <= get_v_knot(k + 1).
88 */
90set_v_knot(int k, double value) {
91 nassertv(k >= 0 && k < (int)_v_knots.size());
92 _v_knots[k] = value;
93}
94
95/**
96 * Redefines the control vertex associated with a particular u, v coordinate
97 * pair. This is just a shorthand to access the EggPrimitive's normal vertex
98 * assignment for a 2-d control vertex.
99 */
101set_cv(int ui, int vi, EggVertex *vertex) {
102 int vertex_index = get_vertex_index(ui, vi);
103 set_vertex(vertex_index, vertex);
104}
105
106/**
107 * Returns the order of the surface in the U direction. The order is the
108 * degree of the NURBS equation plus 1; for a typical NURBS, the order is 4.
109 * With this implementation of NURBS, the order must be in the range [1, 4].
110 */
112get_u_order() const {
113 return _u_order;
114}
115
116/**
117 * Returns the order of the surface in the V direction. The order is the
118 * degree of the NURBS equation plus 1; for a typical NURBS, the order is 4.
119 * With this implementation of NURBS, the order must be in the range [1, 4].
120 */
122get_v_order() const {
123 return _v_order;
124}
125
126/**
127 * Returns the degree of the surface in the U direction. For a typical NURBS,
128 * the degree is 3.
129 */
131get_u_degree() const {
132 return _u_order - 1;
133}
134
135/**
136 * Returns the degree of the surface in the V direction. for a typical NURBS,
137 * the degree is 3.
138 */
140get_v_degree() const {
141 return _v_order - 1;
142}
143
144/**
145 * Returns the number of knots in the U direction.
146 */
147INLINE int EggNurbsSurface::
148get_num_u_knots() const {
149 return _u_knots.size();
150}
151
152/**
153 * Returns the number of knots in the V direction.
154 */
155INLINE int EggNurbsSurface::
156get_num_v_knots() const {
157 return _v_knots.size();
158}
159
160/**
161 * Returns the number of control vertices that should be present in the U
162 * direction. This is determined by the number of knots and the order; it
163 * does not necessarily reflect the number of vertices that have actually been
164 * added to the surface. (However, if the number of vertices in the surface
165 * are wrong, the surface is invalid.)
166 */
168get_num_u_cvs() const {
169 return get_num_u_knots() - get_u_order();
170}
171
172/**
173 * Returns the number of control vertices that should be present in the V
174 * direction. This is determined by the number of knots and the order; it
175 * does not necessarily reflect the number of vertices that have actually been
176 * added to the surface. (However, if the number of vertices in the surface
177 * are wrong, the surface is invalid.)
178 */
180get_num_v_cvs() const {
181 return get_num_v_knots() - get_v_order();
182}
183
184/**
185 * Returns the total number of control vertices that *should* be defined for
186 * the surface. This is determined by the number of knots and the order, in
187 * each direction; it does not necessarily reflect the number of vertices that
188 * have actually been added to the surface. (However, if the number of
189 * vertices in the surface are wrong, the surface is invalid.)
190 */
192get_num_cvs() const {
193 return get_num_u_cvs() * get_num_v_cvs();
194}
195
196/**
197 * Returns the U index number of the given vertex within the EggPrimitive's
198 * linear list of vertices. An EggNurbsSurface maps a linear list of vertices
199 * to its 2-d mesh; this returns the U index number that corresponds to the
200 * nth vertex in the list.
201 */
203get_u_index(int vertex_index) const {
204 nassertr(vertex_index >= 0 && vertex_index < get_num_cvs(), 0);
205 return vertex_index % get_num_u_cvs();
206}
207
208/**
209 * Returns the V index number of the given vertex within the EggPrimitive's
210 * linear list of vertices. An EggNurbsSurface maps a linear list of vertices
211 * to its 2-d mesh; this returns the V index number that corresponds to the
212 * nth vertex in the list.
213 */
215get_v_index(int vertex_index) const {
216 nassertr(vertex_index >= 0 && vertex_index < get_num_cvs(), 0);
217 return vertex_index / get_num_u_cvs();
218}
219
220/**
221 * Returns the index number within the EggPrimitive's list of the control
222 * vertex at position ui, vi.
223 */
225get_vertex_index(int ui, int vi) const {
226 nassertr(ui >= 0 && ui < get_num_u_cvs(), 0);
227 nassertr(vi >= 0 && vi < get_num_v_cvs(), 0);
228 return vi * get_num_u_cvs() + ui;
229}
230
231/**
232 * Returns the nth knot value defined in the U direction.
233 */
234INLINE double EggNurbsSurface::
235get_u_knot(int k) const {
236 nassertr(k >= 0 && k < (int)_u_knots.size(), 0.0);
237 return _u_knots[k];
238}
239
240/**
241 * Returns the nth knot value defined in the V direction.
242 */
243INLINE double EggNurbsSurface::
244get_v_knot(int k) const {
245 nassertr(k >= 0 && k < (int)_v_knots.size(), 0.0);
246 return _v_knots[k];
247}
248
249/**
250 * Returns the control vertex at the indicate U, V position.
251 */
253get_cv(int ui, int vi) const {
254 int vertex_index = get_vertex_index(ui, vi);
255 return get_vertex(vertex_index);
256}
A parametric NURBS surface.
int get_u_order() const
Returns the order of the surface in the U direction.
int get_num_cvs() const
Returns the total number of control vertices that *should* be defined for the surface.
void set_u_order(int u_order)
Directly changes the order in the U direction to the indicated value (which must be an integer in the...
get_num_u_knots
Returns the number of knots in the U direction.
int get_vertex_index(int ui, int vi) const
Returns the index number within the EggPrimitive's list of the control vertex at position ui,...
int get_v_order() const
Returns the order of the surface in the V direction.
int get_v_degree() const
Returns the degree of the surface in the V direction.
void set_v_order(int v_order)
Directly changes the order in the V direction to the indicated value (which must be an integer in the...
get_v_knot
Returns the nth knot value defined in the V direction.
EggVertex * get_cv(int ui, int vi) const
Returns the control vertex at the indicate U, V position.
int get_u_index(int vertex_index) const
Returns the U index number of the given vertex within the EggPrimitive's linear list of vertices.
int get_num_v_cvs() const
Returns the number of control vertices that should be present in the V direction.
int get_u_degree() const
Returns the degree of the surface in the U direction.
void set_cv(int ui, int vi, EggVertex *vertex)
Redefines the control vertex associated with a particular u, v coordinate pair.
get_u_knot
Returns the nth knot value defined in the U direction.
int get_num_u_cvs() const
Returns the number of control vertices that should be present in the U direction.
void set_u_knot(int k, double value)
Resets the value of the indicated knot as indicated.
get_num_v_knots
Returns the number of knots in the V direction.
int get_v_index(int vertex_index) const
Returns the V index number of the given vertex within the EggPrimitive's linear list of vertices.
void set_v_knot(int k, double value)
Resets the value of the indicated knot as indicated.
get_vertex
Returns a particular index based on its index number.
set_vertex
Replaces a particular vertex based on its index number in the list of vertices.
A parametric surface of some kind.
Definition eggSurface.h:24
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition eggVertex.h:39