15 #include "pandabase.h" 16 #include "pointerTo.h" 18 #include "curveFitter.h" 19 #include "config_parametrics.h" 20 #include "parametricCurve.h" 21 #include "nurbsCurve.h" 22 #include "hermiteCurve.h" 55 _data.erase(_data.begin(), _data.end());
120 nassertr(n >= 0 && n < (
int)_data.size(), 0.0f);
132 return _data[n]._xyz;
143 return _data[n]._hpr;
156 return _data[n]._tangent;
167 begin = max(0, min((
int)_data.size(), begin));
168 end = max(0, min((
int)_data.size(), end));
170 nassertv(begin <= end);
172 _data.erase(_data.begin() + begin, _data.begin() + end);
187 PN_stdfloat t, last_t, d;
193 for (i = 0; i < count; i++) {
194 t = max_t * (PN_stdfloat)i / (PN_stdfloat)(count-1);
195 if (curves->
evaluate(t, dp._xyz, dp._hpr)) {
224 for (di = _data.begin(); di != _data.end(); ++di) {
226 for (i = 0; i < 3; i++) {
227 (*di)._hpr[i] += net[i];
229 while (((*di)._hpr[i] - last[i]) > 180.0f) {
230 (*di)._hpr[i] -= 360.0f;
234 while (((*di)._hpr[i] - last[i]) < -180.0f) {
235 (*di)._hpr[i] += 360.0f;
239 last[i] = (*di)._hpr[i];
252 sort(_data.begin(), _data.end());
266 PN_stdfloat count = factor;
269 for (in = 0; in < (int)_data.size()-1; in++) {
270 if (count >= factor) {
271 _data[out] = _data[in];
278 _data[out] = _data.back();
281 _data.erase(_data.begin() + out, _data.end());
300 (_data.front()._xyz.almost_equal(_data.back()._xyz, 0.001f));
302 }
else if (_got_hpr) {
304 (_data.front()._hpr.almost_equal(_data.back()._hpr, 0.001f));
308 int len = _data.size();
314 for (i = 1; i < len-1; i++) {
316 (_data[i+1]._xyz - _data[i-1]._xyz) * scale /
317 (_data[i+1]._t - _data[i-1]._t);
321 for (i = 1; i < len-1; i++) {
322 _data[i]._hpr_tangent =
323 (_data[i+1]._hpr - _data[i-1]._hpr) * scale /
324 (_data[i+1]._t - _data[i-1]._t);
331 _data[0]._tangent = _data[len-1]._tangent =
332 (_data[1]._xyz - _data[len-2]._xyz) * scale /
333 ((_data[1]._t - _data[0]._t) + (_data[len-1]._t - _data[len-2]._t));
336 _data[0]._tangent = _data[len-1]._tangent =
337 (_data[1]._hpr - _data[len-2]._hpr) * scale /
338 ((_data[1]._t - _data[0]._t) + (_data[len-1]._t - _data[len-2]._t));
344 (_data[1]._xyz - _data[0]._xyz) * scale /
345 ((_data[1]._t - _data[0]._t) * 2.0f);
346 _data[len-1]._tangent =
347 (_data[len-1]._xyz - _data[len-2]._xyz) * scale /
348 ((_data[len-1]._t - _data[len-2]._t) * 2.0f);
352 (_data[1]._hpr - _data[0]._hpr) * scale /
353 ((_data[1]._t - _data[0]._t) * 2.0f);
354 _data[len-1]._tangent =
355 (_data[len-1]._hpr - _data[len-2]._hpr) * scale /
356 ((_data[len-1]._t - _data[len-2]._t) * 2.0f);
368 make_hermite()
const {
373 result->add_curve(hc);
376 Data::const_iterator di;
377 for (di = _data.begin(); di != _data.end(); ++di) {
388 result->add_curve(hc);
391 Data::const_iterator di;
392 for (di = _data.begin(); di != _data.end(); ++di) {
419 for (
int c = 0; c < num_curves; c++) {
421 result->add_curve(nc);
430 assert(nc->get_order() == 4);
431 assert(num_knots > 0);
441 PN_stdfloat k1, k2 = nc->
get_knot(num_knots-1);
442 const PN_stdfloat one_third = 1.0f/3.0f;
443 for (i = 3; i < num_knots - 4; i += 3) {
446 nc->
set_knot(i, (k1 + k1 + k2) * one_third);
447 nc->
set_knot(i+1, (k1 + k2 + k2) * one_third);
466 output(ostream &out)
const {
467 out <<
"CurveFitter, " << _data.size() <<
" samples.\n";
476 write(ostream &out)
const {
477 out <<
"CurveFitter, " << _data.size() <<
" samples:\n";
478 Data::const_iterator di;
479 for (di = _data.begin(); di != _data.end(); ++di) {
480 out <<
" " << (*di) <<
"\n";
This is the base class for all three-component vectors and points.
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.
A virtual base class for parametric curves.
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.
ParametricCurve * get_hpr_curve() const
Returns the first HPR curve in the collection, if any, or NULL if there are none. ...
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...
static const LVecBase3f & zero()
Returns a zero-length vector.
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...
PN_stdfloat get_max_t() const
Returns the maximum T value associated with the last* curve in the collection.
void compute_tangents(PN_stdfloat scale)
Once a set of points has been built, and prior to calling MakeHermite() or MakeNurbs(), ComputeTangents() must be called to set up the tangents correctly (unless the tangents were defined as the points were added).
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.
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...
ParametricCurve * get_xyz_curve() const
Returns the first XYZ curve in the collection, if any, or NULL if there are none. ...
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.
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.
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...
int get_num_curves() const
Returns the number of ParametricCurves in the collection.
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...