00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef NURBSCURVE_H
00016 #define NURBSCURVE_H
00017
00018 #include "pandabase.h"
00019
00020 #include "piecewiseCurve.h"
00021 #include "nurbsCurveInterface.h"
00022 #include "cubicCurveseg.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class EXPCL_PANDA_PARAMETRICS NurbsCurve : public PiecewiseCurve, public NurbsCurveInterface {
00048 PUBLISHED:
00049 NurbsCurve();
00050 NurbsCurve(const ParametricCurve &pc);
00051 public:
00052 NurbsCurve(int order, int num_cvs,
00053 const PN_stdfloat knots[], const LVecBase4 cvs[]);
00054 PUBLISHED:
00055 virtual ~NurbsCurve();
00056
00057 public:
00058 virtual PandaNode *make_copy() const;
00059
00060
00061
00062 virtual void set_order(int order);
00063 virtual int get_order() const;
00064
00065 virtual int get_num_cvs() const;
00066 virtual int get_num_knots() const;
00067
00068 virtual bool insert_cv(PN_stdfloat t);
00069
00070 virtual bool remove_cv(int n);
00071 virtual void remove_all_cvs();
00072
00073 virtual bool set_cv(int n, const LVecBase4 &v);
00074 virtual LVecBase4 get_cv(int n) const;
00075
00076 virtual bool set_knot(int n, PN_stdfloat t);
00077 virtual PN_stdfloat get_knot(int n) const;
00078
00079 virtual bool recompute();
00080
00081 public:
00082 virtual bool
00083 rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
00084 int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
00085 int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
00086 int rtype3, PN_stdfloat t3, const LVecBase4 &v3);
00087
00088 virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
00089
00090 INLINE CubicCurveseg *get_curveseg(int ti);
00091
00092 virtual NurbsCurveInterface *get_nurbs_interface();
00093 virtual bool convert_to_nurbs(ParametricCurve *nc) const;
00094 virtual void write(ostream &out, int indent_level = 0) const;
00095
00096 protected:
00097 virtual int append_cv_impl(const LVecBase4 &v);
00098 virtual bool format_egg(ostream &out, const string &name,
00099 const string &curve_type, int indent_level) const;
00100
00101 int find_cv(PN_stdfloat t);
00102
00103 int _order;
00104
00105 class CV {
00106 public:
00107 CV() {}
00108 CV(const LVecBase4 &p, PN_stdfloat t) : _p(p), _t(t) {}
00109 LVecBase4 _p;
00110 PN_stdfloat _t;
00111 };
00112
00113 epvector<CV> _cvs;
00114
00115
00116
00117 public:
00118 static void register_with_read_factory();
00119
00120 protected:
00121 static TypedWritable *make_NurbsCurve(const FactoryParams ¶ms);
00122 virtual void write_datagram(BamWriter *manager, Datagram &me);
00123 void fillin(DatagramIterator &scan, BamReader *manager);
00124
00125 public:
00126 static TypeHandle get_class_type() {
00127 return _type_handle;
00128 }
00129 static void init_type() {
00130 PiecewiseCurve::init_type();
00131 NurbsCurveInterface::init_type();
00132 register_type(_type_handle, "NurbsCurve",
00133 PiecewiseCurve::get_class_type(),
00134 NurbsCurveInterface::get_class_type());
00135 }
00136 virtual TypeHandle get_type() const {
00137 return get_class_type();
00138 }
00139 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00140
00141 private:
00142 static TypeHandle _type_handle;
00143 };
00144
00145 #include "nurbsCurve.I"
00146
00147 #endif