Panda3D
Loading...
Searching...
No Matches
curveFitter.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file curveFitter.h
10 * @author drose
11 * @date 1998-09-17
12 */
13
14#ifndef CURVEFITTER_H
15#define CURVEFITTER_H
16
17#include "pandabase.h"
18
19#include "luse.h"
20
22
23#include "typedef.h"
24#include "pvector.h"
25
26class HermiteCurve;
27class ParametricCurve;
28class NurbsCurve;
29
30/**
31 *
32 */
33class EXPCL_PANDA_PARAMETRICS CurveFitter {
34PUBLISHED:
35 CurveFitter();
36 ~CurveFitter();
37
38 void reset();
39 void add_xyz(PN_stdfloat t, const LVecBase3 &xyz);
40 void add_hpr(PN_stdfloat t, const LVecBase3 &hpr);
41 void add_xyz_hpr(PN_stdfloat t, const LVecBase3 &xyz, const LVecBase3 &hpr);
42
43 int get_num_samples() const;
44 PN_stdfloat get_sample_t(int n) const;
45 LVecBase3 get_sample_xyz(int n) const;
46 LVecBase3 get_sample_hpr(int n) const;
47 LVecBase3 get_sample_tangent(int n) const;
48 void remove_samples(int begin, int end);
49
50 void sample(ParametricCurveCollection *curves, int count);
51 void wrap_hpr();
52 void sort_points();
53 void desample(PN_stdfloat factor);
54
55 void compute_tangents(PN_stdfloat scale);
56 PT(ParametricCurveCollection) make_hermite() const;
57 PT(ParametricCurveCollection) make_nurbs() const;
58
59 void output(std::ostream &out) const;
60 void write(std::ostream &out) const;
61
62public:
63 class DataPoint {
64 public:
65 INLINE DataPoint();
66 INLINE void output(std::ostream &out) const;
67 INLINE bool operator < (const DataPoint &other) const;
68
69 PN_stdfloat _t;
70 LVecBase3 _xyz;
71 LVecBase3 _hpr;
72 LVecBase3 _tangent;
73 LVecBase3 _hpr_tangent;
74 };
75
76 typedef pvector<DataPoint> Data;
77 Data _data;
78
79 bool _got_xyz;
80 bool _got_hpr;
81
82public:
83 static TypeHandle get_class_type() {
84 return _type_handle;
85 }
86 static void init_type() {
87 register_type(_type_handle, "CurveFitter");
88 }
89
90private:
91 static TypeHandle _type_handle;
92};
93
94INLINE std::ostream &operator << (std::ostream &out, const CurveFitter::DataPoint &dp) {
95 dp.output(out);
96 return out;
97}
98
99INLINE std::ostream &operator << (std::ostream &out, const CurveFitter &cf) {
100 cf.output(out);
101 return out;
102}
103
104#include "curveFitter.I"
105
106#endif
void add_xyz(PN_stdfloat t, const LVecBase3 &xyz)
Adds a single sample xyz.
PN_stdfloat get_sample_t(int n) const
Returns the parametric value of the nth sample added.
LVecBase3 get_sample_xyz(int n) const
Returns the point in space of the nth sample added.
void wrap_hpr()
Resets each HPR data point so that the maximum delta between any two consecutive points is 180 degree...
int get_num_samples() const
Returns the number of sample points that have been added.
void sort_points()
Sorts all the data points in order by parametric time, in case they were added in an incorrect order.
void sample(ParametricCurveCollection *curves, int count)
Generates a series of data points by sampling the given curve (or xyz/hpr curves) the indicated numbe...
void compute_tangents(PN_stdfloat scale)
Once a set of points has been built, and prior to calling MakeHermite() or MakeNurbs(),...
LVecBase3 get_sample_tangent(int n) const
Returns the tangent associated with the nth sample added.
void remove_samples(int begin, int end)
Eliminates all samples from index begin, up to but not including index end, from the database.
void add_hpr(PN_stdfloat t, const LVecBase3 &hpr)
Adds a single sample hpr.
void add_xyz_hpr(PN_stdfloat t, const LVecBase3 &xyz, const LVecBase3 &hpr)
Adds a single sample xyz & hpr simultaneously.
LVecBase3 get_sample_hpr(int n) const
Returns the orientation of the nth sample added.
void desample(PN_stdfloat factor)
Removes sample points in order to reduce the complexity of a sampled curve.
void reset()
Removes all the data points previously added to the CurveFitter, and initializes it for a new curve.
A parametric curve defined by a sequence of control vertices, each with an in and out tangent.
A Nonuniform Rational B-Spline.
Definition nurbsCurve.h:41
This is a set of zero or more ParametricCurves, which may or may not be related.
A virtual base class for parametric curves.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.