Panda3D
eggNurbsCurve.I
1 // Filename: eggNurbsCurve.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: EggNurbsCurve::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE EggNurbsCurve::
21 EggNurbsCurve(const string &name) : EggCurve(name) {
22  _order = 0;
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: EggNurbsCurve::Copy constructor
27 // Access: Public
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE EggNurbsCurve::
31 EggNurbsCurve(const EggNurbsCurve &copy) :
32  EggCurve(copy),
33  _knots(copy._knots),
34  _order(copy._order)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: EggNurbsCurve::Copy assignment operator
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 INLINE EggNurbsCurve &EggNurbsCurve::
44 operator = (const EggNurbsCurve &copy) {
45  EggCurve::operator = (copy);
46  _knots = copy._knots;
47  _order = copy._order;
48  return *this;
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: EggNurbsCurve::set_order
53 // Access: Public
54 // Description: Directly changes the order to the indicated value
55 // (which must be an integer in the range 1 <= order <=
56 // 4). If possible, it is preferable to use the setup()
57 // method instead of this method, since changing the
58 // order directly may result in an invalid curve.
59 ////////////////////////////////////////////////////////////////////
60 INLINE void EggNurbsCurve::
61 set_order(int order) {
62  nassertv(order >= 1 && order <= 4);
63  _order = order;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: EggNurbsCurve::set_knot
68 // Access: Public
69 // Description: Resets the value of the indicated knot as indicated.
70 // k must be in the range 0 <= k < get_num_knots(),
71 // and the value must be in the range get_knot(k - 1)
72 // <= value <= get_knot(k + 1).
73 ////////////////////////////////////////////////////////////////////
74 INLINE void EggNurbsCurve::
75 set_knot(int k, double value) {
76  nassertv(k >= 0 && k < (int)_knots.size());
77  _knots[k] = value;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: EggNurbsCurve::get_order
82 // Access: Public
83 // Description: Returns the order of the curve. The order is the
84 // degree of the NURBS equation plus 1; for a typical
85 // NURBS, the order is 4. With this implementation of
86 // NURBS, the order must be in the range [1, 4].
87 ////////////////////////////////////////////////////////////////////
88 INLINE int EggNurbsCurve::
89 get_order() const {
90  return _order;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: EggNurbsCurve::get_degree
95 // Access: Public
96 // Description: Returns the degree of the curve. For a typical
97 // NURBS, the degree is 3.
98 ////////////////////////////////////////////////////////////////////
99 INLINE int EggNurbsCurve::
100 get_degree() const {
101  return _order - 1;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: EggNurbsCurve::get_num_knots
106 // Access: Public
107 // Description: Returns the number of knots.
108 ////////////////////////////////////////////////////////////////////
109 INLINE int EggNurbsCurve::
110 get_num_knots() const {
111  return _knots.size();
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: EggNurbsCurve::get_num_cvs
116 // Access: Public
117 // Description: Returns the total number of control vertices that
118 // *should* be defined for the curve. This is
119 // determined by the number of knots and the order, in
120 // each direction; it does not necessarily reflect the
121 // number of vertices that have actually been added to
122 // the curve. (However, if the number of vertices in
123 // the curve are wrong, the curve is invalid.)
124 ////////////////////////////////////////////////////////////////////
125 INLINE int EggNurbsCurve::
126 get_num_cvs() const {
127  return get_num_knots() - get_order();
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: EggNurbsCurve::get_knot
132 // Access: Public
133 // Description: Returns the nth knot value defined.
134 ////////////////////////////////////////////////////////////////////
135 INLINE double EggNurbsCurve::
136 get_knot(int k) const {
137  nassertr(k >= 0 && k < (int)_knots.size(), 0.0);
138  return _knots[k];
139 }
140 
int get_order() const
Returns the order of the curve.
Definition: eggNurbsCurve.I:89
void set_knot(int k, double value)
Resets the value of the indicated knot as indicated.
Definition: eggNurbsCurve.I:75
double get_knot(int k) const
Returns the nth knot value defined.
int get_num_knots() const
Returns the number of knots.
int get_degree() const
Returns the degree of the curve.
A parametric NURBS curve.
Definition: eggNurbsCurve.h:28
void set_order(int order)
Directly changes the order to the indicated value (which must be an integer in the range 1 <= order <...
Definition: eggNurbsCurve.I:61
A parametric curve of some kind.
Definition: eggCurve.h:27
int get_num_cvs() const
Returns the total number of control vertices that should* be defined for the curve.