00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef HERMITECURVE_H
00020 #define HERMITECURVE_H
00021
00022 #include "piecewiseCurve.h"
00023 #include "cubicCurveseg.h"
00024
00025
00026 BEGIN_PUBLISH
00027
00028 #define HC_CUT 1
00029
00030
00031
00032 #define HC_FREE 2
00033
00034
00035
00036 #define HC_G1 3
00037
00038
00039
00040
00041
00042
00043
00044 #define HC_SMOOTH 4
00045
00046
00047
00048
00049 END_PUBLISH
00050
00051
00052
00053
00054
00055
00056 class HermiteCurveCV {
00057 public:
00058 HermiteCurveCV();
00059 HermiteCurveCV(const HermiteCurveCV &c);
00060 ~HermiteCurveCV();
00061
00062 void set_point(const LVecBase3f &point) { _p = point; }
00063 void set_in(const LVecBase3f &in);
00064 void set_out(const LVecBase3f &out);
00065 void set_type(int type);
00066 void set_name(const string &name);
00067
00068 void format_egg(ostream &out, int indent, int num_dimensions,
00069 bool show_in, bool show_out,
00070 float scale_in, float scale_out) const;
00071
00072 void write_datagram(BamWriter *manager, Datagram &me) const;
00073 void fillin(DatagramIterator &scan, BamReader *manager);
00074
00075 LVecBase3f _p, _in, _out;
00076 int _type;
00077 string _name;
00078 };
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 class HermiteCurve : public PiecewiseCurve {
00093 PUBLISHED:
00094 HermiteCurve();
00095 HermiteCurve(const ParametricCurve &pc);
00096 virtual ~HermiteCurve();
00097
00098 int get_num_cvs() const;
00099
00100 int insert_cv(float t);
00101 int append_cv(int type, float x, float y, float z);
00102 inline int append_cv(int type, const LVecBase3f &v) {
00103 return append_cv(type, v[0], v[1], v[2]);
00104 }
00105
00106 bool remove_cv(int n);
00107 void remove_all_cvs();
00108
00109 bool set_cv_type(int n, int type);
00110 bool set_cv_point(int n, float x, float y, float z);
00111 inline bool set_cv_point(int n, const LVecBase3f &v) {
00112 return set_cv_point(n, v[0], v[1], v[2]);
00113 }
00114 bool set_cv_in(int n, float x, float y, float z);
00115 inline bool set_cv_in(int n, const LVecBase3f &v) {
00116 return set_cv_in(n, v[0], v[1], v[2]);
00117 }
00118 bool set_cv_out(int n, float x, float y, float z);
00119 inline bool set_cv_out(int n, const LVecBase3f &v) {
00120 return set_cv_out(n, v[0], v[1], v[2]);
00121 }
00122 bool set_cv_tstart(int n, float tstart);
00123 bool set_cv_name(int n, const char *name);
00124
00125
00126 int get_cv_type(int n) const;
00127 const LVecBase3f &get_cv_point(int n) const;
00128 void get_cv_point(int n, LVecBase3f &v) const;
00129 const LVecBase3f &get_cv_in(int n) const;
00130 void get_cv_in(int n, LVecBase3f &v) const;
00131 const LVecBase3f &get_cv_out(int n) const;
00132 void get_cv_out(int n, LVecBase3f &v) const;
00133 float get_cv_tstart(int n) const;
00134 string get_cv_name(int n) const;
00135
00136 virtual void output(ostream &out) const;
00137 void write_cv(ostream &out, int n) const;
00138
00139 public:
00140
00141 CubicCurveseg *get_curveseg(int ti) {
00142 return (CubicCurveseg *)PiecewiseCurve::get_curveseg(ti);
00143 }
00144
00145 virtual bool
00146 rebuild_curveseg(int rtype0, float t0, const LVecBase4f &v0,
00147 int rtype1, float t1, const LVecBase4f &v1,
00148 int rtype2, float t2, const LVecBase4f &v2,
00149 int rtype3, float t3, const LVecBase4f &v3);
00150
00151 protected:
00152 virtual bool format_egg(ostream &out, const string &name,
00153 const string &curve_type, int indent_level) const;
00154
00155 void invalidate_cv(int n, bool redo_all);
00156 int find_cv(float t);
00157 void recompute_basis();
00158
00159 pvector<HermiteCurveCV> _points;
00160
00161
00162 public:
00163 static void register_with_read_factory();
00164
00165 protected:
00166 static TypedWritable *make_HermiteCurve(const FactoryParams ¶ms);
00167 virtual void write_datagram(BamWriter *manager, Datagram &me);
00168 void fillin(DatagramIterator &scan, BamReader *manager);
00169
00170 public:
00171 static TypeHandle get_class_type() {
00172 return _type_handle;
00173 }
00174 static void init_type() {
00175 register_type(_type_handle, "HermiteCurve");
00176 }
00177 virtual TypeHandle get_type() const {
00178 return get_class_type();
00179 }
00180 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00181
00182 private:
00183 static TypeHandle _type_handle;
00184 };
00185
00186 #endif