Panda3D
curveFitter.h
1 // Filename: curveFitter.h
2 // Created by: drose (17Sep98)
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 #ifndef CURVEFITTER_H
16 #define CURVEFITTER_H
17 
18 #include "pandabase.h"
19 
20 #include "luse.h"
21 
22 #include "parametricCurveCollection.h"
23 
24 #include "typedef.h"
25 #include "pvector.h"
26 
27 class HermiteCurve;
28 class ParametricCurve;
29 class NurbsCurve;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : CurveFitter
33 // Description :
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDA_GOBJ CurveFitter {
36 PUBLISHED:
37  CurveFitter();
38  ~CurveFitter();
39 
40  void reset();
41  void add_xyz(PN_stdfloat t, const LVecBase3 &xyz);
42  void add_hpr(PN_stdfloat t, const LVecBase3 &hpr);
43  void add_xyz_hpr(PN_stdfloat t, const LVecBase3 &xyz, const LVecBase3 &hpr);
44 
45  int get_num_samples() const;
46  PN_stdfloat get_sample_t(int n) const;
47  LVecBase3 get_sample_xyz(int n) const;
48  LVecBase3 get_sample_hpr(int n) const;
49  LVecBase3 get_sample_tangent(int n) const;
50  void remove_samples(int begin, int end);
51 
52  void sample(ParametricCurveCollection *curves, int count);
53  void wrap_hpr();
54  void sort_points();
55  void desample(PN_stdfloat factor);
56 
57  void compute_tangents(PN_stdfloat scale);
58  PT(ParametricCurveCollection) make_hermite() const;
59  PT(ParametricCurveCollection) make_nurbs() const;
60 
61  void output(ostream &out) const;
62  void write(ostream &out) const;
63 
64 public:
65  class DataPoint {
66  public:
67  INLINE DataPoint();
68  INLINE void output(ostream &out) const;
69  INLINE bool operator < (const DataPoint &other) const;
70 
71  PN_stdfloat _t;
72  LVecBase3 _xyz;
73  LVecBase3 _hpr;
74  LVecBase3 _tangent;
75  LVecBase3 _hpr_tangent;
76  };
77 
78  typedef pvector<DataPoint> Data;
79  Data _data;
80 
81  bool _got_xyz;
82  bool _got_hpr;
83 
84 public:
85  static TypeHandle get_class_type() {
86  return _type_handle;
87  }
88  static void init_type() {
89  register_type(_type_handle, "CurveFitter");
90  }
91 
92 private:
93  static TypeHandle _type_handle;
94 };
95 
96 INLINE ostream &operator << (ostream &out, const CurveFitter::DataPoint &dp) {
97  dp.output(out);
98  return out;
99 }
100 
101 INLINE ostream &operator << (ostream &out, const CurveFitter &cf) {
102  cf.output(out);
103  return out;
104 }
105 
106 #include "curveFitter.I"
107 
108 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
A virtual base class for parametric curves.
A parametric curve defined by a sequence of control vertices, each with an in and out tangent...
Definition: hermiteCurve.h:88
This is a set of zero or more ParametricCurves, which may or may not be related.
A Nonuniform Rational B-Spline.
Definition: nurbsCurve.h:48
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85