00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NURBSPPCURVE_H
00020 #define NURBSPPCURVE_H
00021
00022 #include <pandabase.h>
00023
00024 #include "parametricCurve.h"
00025 #include "nurbsCurveInterface.h"
00026
00027 #include <nurbs.hh>
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class EXPCL_PANDA NurbsPPCurve : public ParametricCurve, public NurbsCurveInterface {
00042 PUBLISHED:
00043 NurbsPPCurve();
00044 NurbsPPCurve(const ParametricCurve &pc);
00045 public:
00046 NurbsPPCurve(int order, int num_cvs,
00047 const float knots[], const LVecBase4f cvs[]);
00048 PUBLISHED:
00049 virtual ~NurbsPPCurve();
00050
00051 public:
00052
00053
00054 virtual float get_max_t() const;
00055
00056 virtual void set_order(int order);
00057 virtual int get_order() const;
00058
00059 virtual int get_num_cvs() const;
00060 virtual int get_num_knots() const;
00061
00062 virtual bool insert_cv(float t);
00063
00064 virtual bool remove_cv(int n);
00065 virtual void remove_all_cvs();
00066
00067 virtual bool set_cv(int n, const LVecBase4f &v);
00068 virtual LVecBase4f get_cv(int n) const;
00069
00070 virtual bool set_knot(int n, float t);
00071 virtual float get_knot(int n) const;
00072
00073 virtual bool recompute();
00074
00075 public:
00076 virtual bool get_point(float t, LVecBase3f &point) const;
00077 virtual bool get_tangent(float t, LVecBase3f &tangent) const;
00078 virtual bool get_pt(float t, LVecBase3f &point, LVecBase3f &tangent) const;
00079 virtual bool get_2ndtangent(float t, LVecBase3f &tangent2) const;
00080
00081 virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
00082
00083 virtual NurbsCurveInterface *get_nurbs_interface();
00084 virtual bool convert_to_nurbs(ParametricCurve *nc) const;
00085 virtual void write(ostream &out, int indent_level = 0) const;
00086
00087 protected:
00088 virtual int append_cv_impl(const LVecBase4f &v);
00089 virtual bool format_egg(ostream &out, const string &name,
00090 const string &curve_type, int indent_level) const;
00091
00092 private:
00093 typedef pvector<LVecBase4f> Points;
00094 typedef pvector<float> Knots;
00095
00096 bool make_nurbs_valid();
00097 void make_arrays_valid();
00098 bool copy_nurbs(PLib::NurbsCurvef &nurbs) const;
00099 void copy_arrays(Points &points, Knots &knots, int &order) const;
00100
00101 static bool make_nurbs_from(PLib::NurbsCurvef &nurbs,
00102 const Points &points, const Knots &knots,
00103 int order);
00104 static void make_arrays_from(const PLib::NurbsCurvef &nurbs,
00105 Points &points, Knots &knots, int &order);
00106
00107 PLib::NurbsCurvef _nurbs;
00108
00109 int _order;
00110 Points _points;
00111 Knots _knots;
00112 bool _nurbs_valid;
00113
00114 public:
00115 static TypeHandle get_class_type() {
00116 return _type_handle;
00117 }
00118 static void init_type() {
00119 ParametricCurve::init_type();
00120 NurbsCurveInterface::init_type();
00121 register_type(_type_handle, "NurbsPPCurve",
00122 ParametricCurve::get_class_type(),
00123 NurbsCurveInterface::get_class_type());
00124 }
00125 virtual TypeHandle get_type() const {
00126 return get_class_type();
00127 }
00128 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00129
00130 private:
00131 static TypeHandle _type_handle;
00132 };
00133
00134 typedef NurbsPPCurve NurbsCurve;
00135
00136 #endif