48 _data.erase(_data.begin(), _data.end());
55 add_xyz(PN_stdfloat t,
const LVecBase3 &xyz) {
67 add_hpr(PN_stdfloat t,
const LVecBase3 &hpr) {
79 add_xyz_hpr(PN_stdfloat t,
const LVecBase3 &xyz,
const LVecBase3 &hpr) {
102 nassertr(n >= 0 && n < (
int)_data.size(), 0.0f);
111 nassertr(n >= 0 && n < (
int)_data.size(), LVecBase3::zero());
112 return _data[n]._xyz;
120 nassertr(n >= 0 && n < (
int)_data.size(), LVecBase3::zero());
121 return _data[n]._hpr;
130 nassertr(n >= 0 && n < (
int)_data.size(), LVecBase3::zero());
131 return _data[n]._tangent;
140 begin = std::max(0, std::min((
int)_data.size(), begin));
141 end = std::max(0, std::min((
int)_data.size(), end));
143 nassertv(begin <= end);
145 _data.erase(_data.begin() + begin, _data.begin() + end);
155 nassertv(curves !=
nullptr);
161 for (i = 0; i < count; i++) {
162 t = max_t * (PN_stdfloat)i / (PN_stdfloat)(count-1);
163 if (curves->
evaluate(t, dp._xyz, dp._hpr)) {
187 LVecBase3 last(0.0f, 0.0f, 0.0f);
188 LVecBase3 net(0.0f, 0.0f, 0.0f);
190 for (di = _data.begin(); di != _data.end(); ++di) {
192 for (i = 0; i < 3; i++) {
193 (*di)._hpr[i] += net[i];
195 while (((*di)._hpr[i] - last[i]) > 180.0f) {
196 (*di)._hpr[i] -= 360.0f;
200 while (((*di)._hpr[i] - last[i]) < -180.0f) {
201 (*di)._hpr[i] += 360.0f;
205 last[i] = (*di)._hpr[i];
216 sort(_data.begin(), _data.end());
227 PN_stdfloat count = factor;
230 for (in = 0; in < (int)_data.size()-1; in++) {
231 if (count >= factor) {
232 _data[out] = _data[in];
239 _data[out] = _data.back();
242 _data.erase(_data.begin() + out, _data.end());
257 (_data.front()._xyz.almost_equal(_data.back()._xyz, 0.001f));
259 }
else if (_got_hpr) {
261 (_data.front()._hpr.almost_equal(_data.back()._hpr, 0.001f));
265 int len = _data.size();
270 for (i = 1; i < len-1; i++) {
272 (_data[i+1]._xyz - _data[i-1]._xyz) * scale /
273 (_data[i+1]._t - _data[i-1]._t);
277 for (i = 1; i < len-1; i++) {
278 _data[i]._hpr_tangent =
279 (_data[i+1]._hpr - _data[i-1]._hpr) * scale /
280 (_data[i+1]._t - _data[i-1]._t);
287 _data[0]._tangent = _data[len-1]._tangent =
288 (_data[1]._xyz - _data[len-2]._xyz) * scale /
289 ((_data[1]._t - _data[0]._t) + (_data[len-1]._t - _data[len-2]._t));
292 _data[0]._tangent = _data[len-1]._tangent =
293 (_data[1]._hpr - _data[len-2]._hpr) * scale /
294 ((_data[1]._t - _data[0]._t) + (_data[len-1]._t - _data[len-2]._t));
300 (_data[1]._xyz - _data[0]._xyz) * scale /
301 ((_data[1]._t - _data[0]._t) * 2.0f);
302 _data[len-1]._tangent =
303 (_data[len-1]._xyz - _data[len-2]._xyz) * scale /
304 ((_data[len-1]._t - _data[len-2]._t) * 2.0f);
308 (_data[1]._hpr - _data[0]._hpr) * scale /
309 ((_data[1]._t - _data[0]._t) * 2.0f);
310 _data[len-1]._tangent =
311 (_data[len-1]._hpr - _data[len-2]._hpr) * scale /
312 ((_data[len-1]._t - _data[len-2]._t) * 2.0f);
321 make_hermite()
const {
326 result->add_curve(hc);
329 Data::const_iterator di;
330 for (di = _data.begin(); di != _data.end(); ++di) {
341 result->add_curve(hc);
344 Data::const_iterator di;
345 for (di = _data.begin(); di != _data.end(); ++di) {
369 for (
int c = 0; c < num_curves; c++) {
371 result->add_curve(nc);
380 assert(nc->get_order() == 4);
381 assert(num_knots > 0);
391 PN_stdfloat k1, k2 = nc->
get_knot(num_knots-1);
392 const PN_stdfloat one_third = 1.0f/3.0f;
393 for (i = 3; i < num_knots - 4; i += 3) {
396 nc->
set_knot(i, (k1 + k1 + k2) * one_third);
397 nc->
set_knot(i+1, (k1 + k2 + k2) * one_third);
414 output(std::ostream &out)
const {
415 out <<
"CurveFitter, " << _data.size() <<
" samples.\n";
422 write(std::ostream &out)
const {
423 out <<
"CurveFitter, " << _data.size() <<
" samples:\n";
424 Data::const_iterator di;
425 for (di = _data.begin(); di != _data.end(); ++di) {
426 out <<
" " << (*di) <<
"\n";
get_max_t
Returns the maximum T value associated with the *last* curve in the collection.
void desample(PN_stdfloat factor)
Removes sample points in order to reduce the complexity of a sampled curve.
PN_stdfloat get_sample_t(int n) const
Returns the parametric value of the nth sample added.
int insert_cv(PN_stdfloat t)
Inserts a new CV at the given parametric point along the curve.
bool set_cv_out(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's out tangent.
int get_num_samples() const
Returns the number of sample points that have been added.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_curves
Returns the number of ParametricCurves in the collection.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool evaluate(PN_stdfloat t, LVecBase3 &xyz, LVecBase3 &hpr) const
Computes the position and rotation represented by the first XYZ and HPR curves in the collection at t...
bool set_cv_point(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's position.
virtual PN_stdfloat get_knot(int n) const
Retrieves the value of the indicated knot.
A parametric curve defined by a sequence of control vertices, each with an in and out tangent.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void compute_tangents(PN_stdfloat scale)
Once a set of points has been built, and prior to calling MakeHermite() or MakeNurbs(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LVecBase3 get_sample_tangent(int n) const
Returns the tangent associated with the nth sample added.
void add_xyz_hpr(PN_stdfloat t, const LVecBase3 &xyz, const LVecBase3 &hpr)
Adds a single sample xyz & hpr simultaneously.
This is a set of zero or more ParametricCurves, which may or may not be related.
virtual bool set_knot(int n, PN_stdfloat t)
Sets the value of the indicated knot.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_hpr_curve
Returns the first HPR curve in the collection, if any, or NULL if there are none.
void wrap_hpr()
Resets each HPR data point so that the maximum delta between any two consecutive points is 180 degree...
virtual bool recompute()
Recalculates the curve basis according to the latest position of the CV's, knots, etc.
LVecBase3 get_sample_hpr(int n) const
Returns the orientation of the nth sample added.
A Nonuniform Rational B-Spline.
LVecBase3 get_sample_xyz(int n) const
Returns the point in space of the nth sample added.
virtual int get_num_knots() const
Returns the number of knots on the curve.
void add_hpr(PN_stdfloat t, const LVecBase3 &hpr)
Adds a single sample hpr.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool set_cv_type(int n, int type)
Changes the given CV's continuity type.
void add_xyz(PN_stdfloat t, const LVecBase3 &xyz)
Adds a single sample xyz.
void set_curve_type(int type)
Sets the flag indicating the use to which the curve is intended to be put.
get_xyz_curve
Returns the first XYZ curve in the collection, if any, or NULL if there are none.
void sort_points()
Sorts all the data points in order by parametric time, in case they were added in an incorrect order.
void remove_samples(int begin, int end)
Eliminates all samples from index begin, up to but not including index end, from the database.
void sample(ParametricCurveCollection *curves, int count)
Generates a series of data points by sampling the given curve (or xyz/hpr curves) the indicated numbe...
TypeHandle is the identifier used to differentiate C++ class types.
bool set_cv_in(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's in tangent.
void reset()
Removes all the data points previously added to the CurveFitter, and initializes it for a new curve.