Panda3D
eggNurbsSurface.I
1 // Filename: eggNurbsSurface.I
2 // Created by: drose (15Feb00)
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 // Function: EggNurbsSurface::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE EggNurbsSurface::
21 EggNurbsSurface(const string &name) : EggSurface(name) {
22  _u_order = 0;
23  _v_order = 0;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: EggNurbsSurface::Copy constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 INLINE EggNurbsSurface::
32 EggNurbsSurface(const EggNurbsSurface &copy) :
33  EggSurface(copy),
34  _u_knots(copy._u_knots),
35  _v_knots(copy._v_knots),
36  _u_order(copy._u_order),
37  _v_order(copy._v_order)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: EggNurbsSurface::Copy assignment operator
43 // Access: Public
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 INLINE EggNurbsSurface &EggNurbsSurface::
47 operator = (const EggNurbsSurface &copy) {
48  EggSurface::operator = (copy);
49  _u_knots = copy._u_knots;
50  _v_knots = copy._v_knots;
51  _u_order = copy._u_order;
52  _v_order = copy._v_order;
53  return *this;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: EggNurbsSurface::set_u_order
58 // Access: Public
59 // Description: Directly changes the order in the U direction to the
60 // indicated value (which must be an integer in the
61 // range 1 <= u_order <= 4). If possible, it is
62 // preferable to use the setup() method instead of this
63 // method, since changing the order directly may result
64 // in an invalid surface.
65 ////////////////////////////////////////////////////////////////////
66 INLINE void EggNurbsSurface::
67 set_u_order(int u_order) {
68  nassertv(u_order >= 1 && u_order <= 4);
69  _u_order = u_order;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: EggNurbsSurface::set_v_order
74 // Access: Public
75 // Description: Directly changes the order in the V direction to the
76 // indicated value (which must be an integer in the
77 // range 1 <= v_order <= 4). If possible, it is
78 // preferable to use the setup() method instead of this
79 // method, since changing the order directly may result
80 // in an invalid surface.
81 ////////////////////////////////////////////////////////////////////
82 INLINE void EggNurbsSurface::
83 set_v_order(int v_order) {
84  nassertv(v_order >= 1 && v_order <= 4);
85  _v_order = v_order;
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: EggNurbsSurface::set_u_knot
90 // Access: Public
91 // Description: Resets the value of the indicated knot as indicated.
92 // k must be in the range 0 <= k < get_num_u_knots(),
93 // and the value must be in the range get_u_knot(k - 1)
94 // <= value <= get_u_knot(k + 1).
95 ////////////////////////////////////////////////////////////////////
96 INLINE void EggNurbsSurface::
97 set_u_knot(int k, double value) {
98  nassertv(k >= 0 && k < (int)_u_knots.size());
99  _u_knots[k] = value;
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: EggNurbsSurface::set_v_knot
104 // Access: Public
105 // Description: Resets the value of the indicated knot as indicated.
106 // k must be in the range 0 <= k < get_num_v_knots(),
107 // and the value must be in the range get_v_knot(k - 1)
108 // <= value <= get_v_knot(k + 1).
109 ////////////////////////////////////////////////////////////////////
110 INLINE void EggNurbsSurface::
111 set_v_knot(int k, double value) {
112  nassertv(k >= 0 && k < (int)_v_knots.size());
113  _v_knots[k] = value;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: EggNurbsSurface::set_cv
118 // Access: Public
119 // Description: Redefines the control vertex associated with a
120 // particular u, v coordinate pair. This is just a
121 // shorthand to access the EggPrimitive's normal vertex
122 // assignment for a 2-d control vertex.
123 ////////////////////////////////////////////////////////////////////
124 INLINE void EggNurbsSurface::
125 set_cv(int ui, int vi, EggVertex *vertex) {
126  int vertex_index = get_vertex_index(ui, vi);
127  set_vertex(vertex_index, vertex);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: EggNurbsSurface::get_u_order
132 // Access: Public
133 // Description: Returns the order of the surface in the U direction.
134 // The order is the degree of the NURBS equation plus 1;
135 // for a typical NURBS, the order is 4. With this
136 // implementation of NURBS, the order must be in the
137 // range [1, 4].
138 ////////////////////////////////////////////////////////////////////
139 INLINE int EggNurbsSurface::
140 get_u_order() const {
141  return _u_order;
142 }
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: EggNurbsSurface::get_v_order
146 // Access: Public
147 // Description: Returns the order of the surface in the V direction.
148 // The order is the degree of the NURBS equation plus 1;
149 // for a typical NURBS, the order is 4. With this
150 // implementation of NURBS, the order must be in the
151 // range [1, 4].
152 ////////////////////////////////////////////////////////////////////
153 INLINE int EggNurbsSurface::
154 get_v_order() const {
155  return _v_order;
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: EggNurbsSurface::get_u_degree
160 // Access: Public
161 // Description: Returns the degree of the surface in the U direction.
162 // For a typical NURBS, the degree is 3.
163 ////////////////////////////////////////////////////////////////////
164 INLINE int EggNurbsSurface::
165 get_u_degree() const {
166  return _u_order - 1;
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: EggNurbsSurface::get_v_degree
171 // Access: Public
172 // Description: Returns the degree of the surface in the V direction.
173 // for a typical NURBS, the degree is 3.
174 ////////////////////////////////////////////////////////////////////
175 INLINE int EggNurbsSurface::
176 get_v_degree() const {
177  return _v_order - 1;
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: EggNurbsSurface::get_num_u_knots
182 // Access: Public
183 // Description: Returns the number of knots in the U direction.
184 ////////////////////////////////////////////////////////////////////
185 INLINE int EggNurbsSurface::
187  return _u_knots.size();
188 }
189 
190 ////////////////////////////////////////////////////////////////////
191 // Function: EggNurbsSurface::get_num_v_knots
192 // Access: Public
193 // Description: Returns the number of knots in the V direction.
194 ////////////////////////////////////////////////////////////////////
195 INLINE int EggNurbsSurface::
197  return _v_knots.size();
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: EggNurbsSurface::get_num_u_cvs
202 // Access: Public
203 // Description: Returns the number of control vertices that should be
204 // present in the U direction. This is determined by
205 // the number of knots and the order; it does not
206 // necessarily reflect the number of vertices that have
207 // actually been added to the surface. (However, if the
208 // number of vertices in the surface are wrong, the
209 // surface is invalid.)
210 ////////////////////////////////////////////////////////////////////
211 INLINE int EggNurbsSurface::
212 get_num_u_cvs() const {
213  return get_num_u_knots() - get_u_order();
214 }
215 
216 ////////////////////////////////////////////////////////////////////
217 // Function: EggNurbsSurface::get_num_v_cvs
218 // Access: Public
219 // Description: Returns the number of control vertices that should be
220 // present in the V direction. This is determined by
221 // the number of knots and the order; it does not
222 // necessarily reflect the number of vertices that have
223 // actually been added to the surface. (However, if the
224 // number of vertices in the surface are wrong, the
225 // surface is invalid.)
226 ////////////////////////////////////////////////////////////////////
227 INLINE int EggNurbsSurface::
228 get_num_v_cvs() const {
229  return get_num_v_knots() - get_v_order();
230 }
231 
232 ////////////////////////////////////////////////////////////////////
233 // Function: EggNurbsSurface::get_num_cvs
234 // Access: Public
235 // Description: Returns the total number of control vertices that
236 // *should* be defined for the surface. This is
237 // determined by the number of knots and the order, in
238 // each direction; it does not necessarily reflect the
239 // number of vertices that have actually been added to
240 // the surface. (However, if the number of vertices in
241 // the surface are wrong, the surface is invalid.)
242 ////////////////////////////////////////////////////////////////////
243 INLINE int EggNurbsSurface::
244 get_num_cvs() const {
245  return get_num_u_cvs() * get_num_v_cvs();
246 }
247 
248 ////////////////////////////////////////////////////////////////////
249 // Function: EggNurbsSurface::get_u_index
250 // Access: Public
251 // Description: Returns the U index number of the given vertex within
252 // the EggPrimitive's linear list of vertices. An
253 // EggNurbsSurface maps a linear list of vertices to its
254 // 2-d mesh; this returns the U index number that
255 // corresponds to the nth vertex in the list.
256 ////////////////////////////////////////////////////////////////////
257 INLINE int EggNurbsSurface::
258 get_u_index(int vertex_index) const {
259  nassertr(vertex_index >= 0 && vertex_index < get_num_cvs(), 0);
260  return vertex_index % get_num_u_cvs();
261 }
262 
263 ////////////////////////////////////////////////////////////////////
264 // Function: EggNurbsSurface::get_v_index
265 // Access: Public
266 // Description: Returns the V index number of the given vertex within
267 // the EggPrimitive's linear list of vertices. An
268 // EggNurbsSurface maps a linear list of vertices to its
269 // 2-d mesh; this returns the V index number that
270 // corresponds to the nth vertex in the list.
271 ////////////////////////////////////////////////////////////////////
272 INLINE int EggNurbsSurface::
273 get_v_index(int vertex_index) const {
274  nassertr(vertex_index >= 0 && vertex_index < get_num_cvs(), 0);
275  return vertex_index / get_num_u_cvs();
276 }
277 
278 ////////////////////////////////////////////////////////////////////
279 // Function: EggNurbsSurface::get_vertex_index
280 // Access: Public
281 // Description: Returns the index number within the EggPrimitive's
282 // list of the control vertex at position ui, vi.
283 ////////////////////////////////////////////////////////////////////
284 INLINE int EggNurbsSurface::
285 get_vertex_index(int ui, int vi) const {
286  nassertr(ui >= 0 && ui < get_num_u_cvs(), 0);
287  nassertr(vi >= 0 && vi < get_num_v_cvs(), 0);
288  return vi * get_num_u_cvs() + ui;
289 }
290 
291 ////////////////////////////////////////////////////////////////////
292 // Function: EggNurbsSurface::get_u_knot
293 // Access: Public
294 // Description: Returns the nth knot value defined in the U
295 // direction.
296 ////////////////////////////////////////////////////////////////////
297 INLINE double EggNurbsSurface::
298 get_u_knot(int k) const {
299  nassertr(k >= 0 && k < (int)_u_knots.size(), 0.0);
300  return _u_knots[k];
301 }
302 
303 ////////////////////////////////////////////////////////////////////
304 // Function: EggNurbsSurface::get_v_knot
305 // Access: Public
306 // Description: Returns the nth knot value defined in the V
307 // direction.
308 ////////////////////////////////////////////////////////////////////
309 INLINE double EggNurbsSurface::
310 get_v_knot(int k) const {
311  nassertr(k >= 0 && k < (int)_v_knots.size(), 0.0);
312  return _v_knots[k];
313 }
314 
315 ////////////////////////////////////////////////////////////////////
316 // Function: EggNurbsSurface::get_cv
317 // Access: Public
318 // Description: Returns the control vertex at the indicate U, V
319 // position.
320 ////////////////////////////////////////////////////////////////////
322 get_cv(int ui, int vi) const {
323  int vertex_index = get_vertex_index(ui, vi);
324  return get_vertex(vertex_index);
325 }
int get_u_degree() const
Returns the degree of the surface in the U direction.
int get_num_v_knots() const
Returns the number of knots in the V direction.
int get_num_u_cvs() const
Returns the number of control vertices that should be present in the U direction. ...
int get_v_index(int vertex_index) const
Returns the V index number of the given vertex within the EggPrimitive&#39;s linear list of vertices...
void set_vertex(int index, EggVertex *vertex)
Replaces a particular vertex based on its index number in the list of vertices.
Definition: eggPrimitive.I:455
void set_u_knot(int k, double value)
Resets the value of the indicated knot as indicated.
double get_u_knot(int k) const
Returns the nth knot value defined in the U direction.
int get_vertex_index(int ui, int vi) const
Returns the index number within the EggPrimitive&#39;s list of the control vertex at position ui...
int get_num_v_cvs() const
Returns the number of control vertices that should be present in the V direction. ...
int get_u_order() const
Returns the order of the surface in the U direction.
void set_v_knot(int k, double value)
Resets the value of the indicated knot as indicated.
int get_num_cvs() const
Returns the total number of control vertices that should* be defined for the surface.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
int get_u_index(int vertex_index) const
Returns the U index number of the given vertex within the EggPrimitive&#39;s linear list of vertices...
void set_cv(int ui, int vi, EggVertex *vertex)
Redefines the control vertex associated with a particular u, v coordinate pair.
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...
int get_v_order() const
Returns the order of the surface in the V direction.
A parametric NURBS surface.
double get_v_knot(int k) const
Returns the nth knot value defined 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...
A parametric surface of some kind.
Definition: eggSurface.h:27
int get_v_degree() const
Returns the degree of the surface in the V direction.
int get_num_u_knots() const
Returns the number of knots in the U direction.
EggVertex * get_vertex(int index) const
Returns a particular index based on its index number.
Definition: eggPrimitive.I:466
EggVertex * get_cv(int ui, int vi) const
Returns the control vertex at the indicate U, V position.