Panda3D
 All Classes Functions Variables Enumerations
nurbsCurve.h
00001 // Filename: nurbsCurve.h
00002 // Created by:  drose (27Feb98)
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 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 //       Class : NurbsCurve
00026 // Description : A Nonuniform Rational B-Spline.
00027 //
00028 //               This class is actually implemented as a
00029 //               PiecewiseCurve made up of several CubicCurvesegs,
00030 //               each of which is created using the nurbs_basis()
00031 //               method.  The list of CV's and knots is kept here,
00032 //               within the NurbsCurve class.
00033 //
00034 //               This class is the original Panda-native
00035 //               implementation of a NURBS curve.  It is typedeffed as
00036 //               "NurbsCurve" and performs all NURBS curve functions
00037 //               if we do not have the NURBS++ library available.
00038 //
00039 //               However, if we *do* have the NURBS++ library, another
00040 //               class exists, the NurbsPPCurve, which is a wrapper
00041 //               around that library and provides some additional
00042 //               functionality.  In that case, the other class is
00043 //               typedeffed to "NurbsCurve" instead of this one, and
00044 //               performs most of the NURBS curve functions.  This
00045 //               class then becomes vestigial.
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   // We don't need to re-publish these, since they're all published
00061   // from NurbsCurveInterface.
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 // TypedWritable stuff
00117 public:
00118   static void register_with_read_factory();
00119 
00120 protected:
00121   static TypedWritable *make_NurbsCurve(const FactoryParams &params);
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
 All Classes Functions Variables Enumerations