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