Panda3D
|
00001 // Filename: curveFitter.h 00002 // Created by: drose (17Sep98) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CURVEFITTER_H 00016 #define CURVEFITTER_H 00017 00018 #include "pandabase.h" 00019 00020 #include "luse.h" 00021 00022 #include "parametricCurveCollection.h" 00023 00024 #include "typedef.h" 00025 #include "pvector.h" 00026 00027 class HermiteCurve; 00028 class ParametricCurve; 00029 class NurbsCurve; 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Class : CurveFitter 00033 // Description : 00034 //////////////////////////////////////////////////////////////////// 00035 class CurveFitter { 00036 PUBLISHED: 00037 CurveFitter(); 00038 ~CurveFitter(); 00039 00040 void reset(); 00041 void add_xyz(PN_stdfloat t, const LVecBase3 &xyz); 00042 void add_hpr(PN_stdfloat t, const LVecBase3 &hpr); 00043 void add_xyz_hpr(PN_stdfloat t, const LVecBase3 &xyz, const LVecBase3 &hpr); 00044 00045 int get_num_samples() const; 00046 PN_stdfloat get_sample_t(int n) const; 00047 LVecBase3 get_sample_xyz(int n) const; 00048 LVecBase3 get_sample_hpr(int n) const; 00049 LVecBase3 get_sample_tangent(int n) const; 00050 void remove_samples(int begin, int end); 00051 00052 void sample(ParametricCurveCollection *curves, int count); 00053 void wrap_hpr(); 00054 void sort_points(); 00055 void desample(PN_stdfloat factor); 00056 00057 void compute_tangents(PN_stdfloat scale); 00058 PT(ParametricCurveCollection) make_hermite() const; 00059 PT(ParametricCurveCollection) make_nurbs() const; 00060 00061 void output(ostream &out) const; 00062 void write(ostream &out) const; 00063 00064 public: 00065 class DataPoint { 00066 public: 00067 INLINE DataPoint(); 00068 INLINE void output(ostream &out) const; 00069 INLINE bool operator < (const DataPoint &other) const; 00070 00071 PN_stdfloat _t; 00072 LVecBase3 _xyz; 00073 LVecBase3 _hpr; 00074 LVecBase3 _tangent; 00075 LVecBase3 _hpr_tangent; 00076 }; 00077 00078 typedef pvector<DataPoint> Data; 00079 Data _data; 00080 00081 bool _got_xyz; 00082 bool _got_hpr; 00083 00084 public: 00085 static TypeHandle get_class_type() { 00086 return _type_handle; 00087 } 00088 static void init_type() { 00089 register_type(_type_handle, "CurveFitter"); 00090 } 00091 00092 private: 00093 static TypeHandle _type_handle; 00094 }; 00095 00096 INLINE ostream &operator << (ostream &out, const CurveFitter::DataPoint &dp) { 00097 dp.output(out); 00098 return out; 00099 } 00100 00101 INLINE ostream &operator << (ostream &out, const CurveFitter &cf) { 00102 cf.output(out); 00103 return out; 00104 } 00105 00106 #include "curveFitter.I" 00107 00108 #endif