Panda3D
 All Classes Functions Variables Enumerations
nurbsCurveResult.I
1 // Filename: nurbsCurveResult.I
2 // Created by: drose (04Dec02)
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 ////////////////////////////////////////////////////////////////////
17 // Function: NurbsCurveResult::Destructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE NurbsCurveResult::
22 ~NurbsCurveResult() {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: NurbsCurveResult::get_start_t
27 // Access: Published
28 // Description: Returns the first legal value of t on the curve.
29 // Usually this is 0.0.
30 ////////////////////////////////////////////////////////////////////
31 INLINE PN_stdfloat NurbsCurveResult::
32 get_start_t() const {
33  return _basis.get_start_t();
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: NurbsCurveResult::get_end_t
38 // Access: Published
39 // Description: Returns the last legal value of t on the curve.
40 ////////////////////////////////////////////////////////////////////
41 INLINE PN_stdfloat NurbsCurveResult::
42 get_end_t() const {
43  return _basis.get_end_t();
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: NurbsCurveResult::eval_point
48 // Access: Published
49 // Description: Computes the point on the curve corresponding to the
50 // indicated value in parametric time. Returns true if
51 // the t value is valid, false otherwise.
52 ////////////////////////////////////////////////////////////////////
53 INLINE bool NurbsCurveResult::
54 eval_point(PN_stdfloat t, LVecBase3 &point) {
55  int segment = find_segment(t);
56  if (segment == -1) {
57  return false;
58  }
59 
60  eval_segment_point(segment, _basis.scale_t(segment, t), point);
61  return true;
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: NurbsCurveResult::eval_tangent
66 // Access: Published
67 // Description: Computes the tangent to the curve at the indicated
68 // point in parametric time. This tangent vector will
69 // not necessarily be normalized, and could be zero.
70 // See also eval_point().
71 ////////////////////////////////////////////////////////////////////
72 INLINE bool NurbsCurveResult::
73 eval_tangent(PN_stdfloat t, LVecBase3 &tangent) {
74  int segment = find_segment(t);
75  if (segment == -1) {
76  return false;
77  }
78 
79  eval_segment_tangent(segment, _basis.scale_t(segment, t), tangent);
80  return true;
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: NurbsCurveResult::eval_extended_point
85 // Access: Published
86 // Description: Evaluates the curve in n-dimensional space according
87 // to the extended vertices associated with the curve in
88 // the indicated dimension.
89 ////////////////////////////////////////////////////////////////////
90 INLINE PN_stdfloat NurbsCurveResult::
91 eval_extended_point(PN_stdfloat t, int d) {
92  int segment = find_segment(t);
93  if (segment == -1) {
94  return 0.0f;
95  }
96 
97  return eval_segment_extended_point(segment, _basis.scale_t(segment, t), d);
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: NurbsCurveResult::eval_extended_points
102 // Access: Published
103 // Description: Simultaneously performs eval_extended_point on a
104 // contiguous sequence of dimensions. The dimensions
105 // evaluated are d through (d + num_values - 1); the
106 // results are filled into the num_values elements in
107 // the indicated result array.
108 ////////////////////////////////////////////////////////////////////
109 INLINE bool NurbsCurveResult::
110 eval_extended_points(PN_stdfloat t, int d, PN_stdfloat result[], int num_values) {
111  int segment = find_segment(t);
112  if (segment == -1) {
113  return false;
114  }
115 
116  eval_segment_extended_points(segment, _basis.scale_t(segment, t), d,
117  result, num_values);
118  return true;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: NurbsCurveResult::get_num_segments
123 // Access: Published
124 // Description: Returns the number of piecewise continuous segments
125 // within the curve. This number is usually not
126 // important unless you plan to call
127 // eval_segment_point().
128 ////////////////////////////////////////////////////////////////////
129 INLINE int NurbsCurveResult::
131  return _basis.get_num_segments();
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: NurbsCurveResult::get_segment_t
136 // Access: Published
137 // Description: Accepts a t value in the range [0, 1], and assumed to
138 // be relative to the indicated segment (as in
139 // eval_segment_point()), and returns the corresponding
140 // t value in the entire curve (as in eval_point()).
141 ////////////////////////////////////////////////////////////////////
142 INLINE PN_stdfloat NurbsCurveResult::
143 get_segment_t(int segment, PN_stdfloat t) const {
144  return t * (_basis.get_to(segment) - _basis.get_from(segment)) + _basis.get_from(segment);
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: NurbsCurveResult::get_num_samples
149 // Access: Published
150 // Description: Returns the number of sample points generated by the
151 // previous call to adaptive_sample().
152 ////////////////////////////////////////////////////////////////////
153 INLINE int NurbsCurveResult::
155  return (int)_adaptive_result.size();
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: NurbsCurveResult::get_sample_t
160 // Access: Published
161 // Description: Returns the t value of the nth sample point generated
162 // by the previous call to adaptive_sample().
163 ////////////////////////////////////////////////////////////////////
164 INLINE PN_stdfloat NurbsCurveResult::
165 get_sample_t(int n) const {
166  nassertr(n >= 0 && n < (int)_adaptive_result.size(), 0.0f);
167  return _adaptive_result[n]._t;
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: NurbsCurveResult::get_sample_point
172 // Access: Published
173 // Description: Returns the point on the curve of the nth sample
174 // point generated by the previous call to
175 // adaptive_sample().
176 //
177 // For tangents, or extended points, you should use
178 // get_sample_t() and pass it into eval_tangent() or
179 // eval_extended_point().
180 ////////////////////////////////////////////////////////////////////
181 INLINE const LPoint3 &NurbsCurveResult::
182 get_sample_point(int n) const {
183  nassertr(n >= 0 && n < (int)_adaptive_result.size(), LPoint3::zero());
184  return _adaptive_result[n]._point;
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: NurbsCurveResult::get_segment_t
189 // Access: Public
190 // Description: Accepts a t value in the range [0, 1], and assumed to
191 // be relative to the indicated segment (as in
192 // eval_segment_point()), and returns the corresponding
193 // t value in the entire curve (as in eval_point()).
194 ////////////////////////////////////////////////////////////////////
195 INLINE NurbsCurveResult::AdaptiveSample::
196 AdaptiveSample(PN_stdfloat t, const LPoint3 &point) :
197  _t(t),
198  _point(point)
199 {
200 }
201 
int get_num_segments() const
Returns the number of piecewise continuous segments within the curve.
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
PN_stdfloat get_from(int segment) const
Returns the t value of the beginning of this segment.
void eval_segment_point(int segment, PN_stdfloat t, LVecBase3 &point) const
Evaluates the point on the curve corresponding to the indicated value in parametric time within the i...
PN_stdfloat scale_t(int segment, PN_stdfloat t) const
Scales the value of t into the range [0, 1] corresponding to [from, to].
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:258
PN_stdfloat get_sample_t(int n) const
Returns the t value of the nth sample point generated by the previous call to adaptive_sample().
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
PN_stdfloat get_end_t() const
Returns the last legal value of t on the curve.
void eval_segment_tangent(int segment, PN_stdfloat t, LVecBase3 &tangent) const
As eval_segment_point, but computes the tangent to the curve at the indicated point.
const LPoint3 & get_sample_point(int n) const
Returns the point on the curve of the nth sample point generated by the previous call to adaptive_sam...
bool eval_tangent(PN_stdfloat t, LVecBase3 &tangent)
Computes the tangent to the curve at the indicated point in parametric time.
int get_num_samples() const
Returns the number of sample points generated by the previous call to adaptive_sample().
void eval_segment_extended_points(int segment, PN_stdfloat t, int d, PN_stdfloat result[], int num_values) const
Simultaneously performs eval_extended_point on a contiguous sequence of dimensions.
PN_stdfloat eval_segment_extended_point(int segment, PN_stdfloat t, int d) const
Evaluates the curve in n-dimensional space according to the extended vertices associated with the cur...
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
PN_stdfloat eval_extended_point(PN_stdfloat t, int d)
Evaluates the curve in n-dimensional space according to the extended vertices associated with the cur...
bool eval_point(PN_stdfloat t, LVecBase3 &point)
Computes the point on the curve corresponding to the indicated value in parametric time...
PN_stdfloat get_end_t() const
Returns the last legal value of t on the curve.
PN_stdfloat get_to(int segment) const
Returns the t value of the end of this segment.
PN_stdfloat get_segment_t(int segment, PN_stdfloat t) const
Accepts a t value in the range [0, 1], and assumed to be relative to the indicated segment (as in eva...
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
bool eval_extended_points(PN_stdfloat t, int d, PN_stdfloat result[], int num_values)
Simultaneously performs eval_extended_point on a contiguous sequence of dimensions.