Panda3D
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 
26 class HermiteCurve;
27 class ParametricCurve;
28 class NurbsCurve;
29 
30 /**
31  *
32  */
33 class EXPCL_PANDA_PARAMETRICS CurveFitter {
34 PUBLISHED:
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 
62 public:
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 
82 public:
83  static TypeHandle get_class_type() {
84  return _type_handle;
85  }
86  static void init_type() {
87  register_type(_type_handle, "CurveFitter");
88  }
89 
90 private:
91  static TypeHandle _type_handle;
92 };
93 
94 INLINE std::ostream &operator << (std::ostream &out, const CurveFitter::DataPoint &dp) {
95  dp.output(out);
96  return out;
97 }
98 
99 INLINE 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
A virtual base class for parametric curves.
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(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A parametric curve defined by a sequence of control vertices, each with an in and out tangent.
Definition: hermiteCurve.h:83
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a set of zero or more ParametricCurves, which may or may not be related.
A Nonuniform Rational B-Spline.
Definition: nurbsCurve.h:41
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81