Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/parametrics/classicNurbsCurve.h

Go to the documentation of this file.
00001 // Filename: classicNurbsCurve.h
00002 // Created by:  drose (27Feb98)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef CLASSICNURBSCURVE_H
00020 #define CLASSICNURBSCURVE_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "piecewiseCurve.h"
00025 #include "nurbsCurveInterface.h"
00026 #include "cubicCurveseg.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : ClassicNurbsCurve
00030 // Description : A Nonuniform Rational B-Spline.
00031 //
00032 //               This class is actually implemented as a
00033 //               PiecewiseCurve made up of several CubicCurvesegs,
00034 //               each of which is created using the nurbs_basis()
00035 //               method.  The list of CV's and knots is kept here,
00036 //               within the ClassicNurbsCurve class.
00037 //
00038 //               This class is the original Panda-native
00039 //               implementation of a NURBS curve.  It is typedeffed as
00040 //               "NurbsCurve" and performs all NURBS curve functions
00041 //               if we do not have the NURBS++ library available.
00042 //
00043 //               However, if we *do* have the NURBS++ library, another
00044 //               class exists, the NurbsPPCurve, which is a wrapper
00045 //               around that library and provides some additional
00046 //               functionality.  In that case, the other class is
00047 //               typedeffed to "NurbsCurve" instead of this one, and
00048 //               performs most of the NURBS curve functions.  This
00049 //               class then becomes vestigial.
00050 ////////////////////////////////////////////////////////////////////
00051 class EXPCL_PANDA ClassicNurbsCurve : public PiecewiseCurve, public NurbsCurveInterface {
00052 PUBLISHED:
00053   ClassicNurbsCurve();
00054   ClassicNurbsCurve(const ParametricCurve &pc);
00055 public:
00056   ClassicNurbsCurve(int order, int num_cvs,
00057                     const float knots[], const LVecBase4f cvs[]);
00058 PUBLISHED:
00059   virtual ~ClassicNurbsCurve();
00060 
00061 public:
00062   // We don't need to re-publish these, since they're all published
00063   // from NurbsCurveInterface.
00064   virtual void set_order(int order);
00065   virtual int get_order() const;
00066 
00067   virtual int get_num_cvs() const;
00068   virtual int get_num_knots() const;
00069 
00070   virtual bool insert_cv(float t);
00071 
00072   virtual bool remove_cv(int n);
00073   virtual void remove_all_cvs();
00074 
00075   virtual bool set_cv(int n, const LVecBase4f &v);
00076   virtual LVecBase4f get_cv(int n) const;
00077 
00078   virtual bool set_knot(int n, float t);
00079   virtual float get_knot(int n) const;
00080 
00081   virtual bool recompute();
00082 
00083 public:
00084   virtual bool
00085   rebuild_curveseg(int rtype0, float t0, const LVecBase4f &v0,
00086                    int rtype1, float t1, const LVecBase4f &v1,
00087                    int rtype2, float t2, const LVecBase4f &v2,
00088                    int rtype3, float t3, const LVecBase4f &v3);
00089 
00090   virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
00091 
00092   INLINE CubicCurveseg *get_curveseg(int ti);
00093 
00094   virtual NurbsCurveInterface *get_nurbs_interface();
00095   virtual bool convert_to_nurbs(ParametricCurve *nc) const;
00096   virtual void write(ostream &out, int indent_level = 0) const;
00097 
00098 protected:
00099   virtual int append_cv_impl(const LVecBase4f &v);
00100   virtual bool format_egg(ostream &out, const string &name,
00101                           const string &curve_type, int indent_level) const;
00102 
00103   int find_cv(float t);
00104 
00105   int _order;
00106 
00107   class CV {
00108   public:
00109     CV() {}
00110     CV(const LVecBase4f &p, float t) : _p(p), _t(t) {}
00111     LVecBase4f _p;
00112     float _t;
00113   };
00114 
00115   pvector<CV> _cvs;
00116 
00117 
00118 // TypedWritable stuff
00119 public:
00120   static void register_with_read_factory();
00121 
00122 protected:
00123   static TypedWritable *make_ClassicNurbsCurve(const FactoryParams &params);
00124   virtual void write_datagram(BamWriter *manager, Datagram &me);
00125   void fillin(DatagramIterator &scan, BamReader *manager);
00126 
00127 public:
00128   static TypeHandle get_class_type() {
00129     return _type_handle;
00130   }
00131   static void init_type() {
00132     PiecewiseCurve::init_type();
00133     NurbsCurveInterface::init_type();
00134     register_type(_type_handle, "ClassicNurbsCurve",
00135                   PiecewiseCurve::get_class_type(),
00136                   NurbsCurveInterface::get_class_type());
00137     register_type(_orig_type_handle, "NurbsCurve",
00138                   PiecewiseCurve::get_class_type(),
00139                   NurbsCurveInterface::get_class_type());
00140  }
00141   virtual TypeHandle get_type() const {
00142     return get_class_type();
00143   }
00144   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00145 
00146 private:
00147   static TypeHandle _type_handle;
00148   static TypeHandle _orig_type_handle;
00149 };
00150 
00151 #ifndef HAVE_NURBSPP
00152 typedef ClassicNurbsCurve NurbsCurve;
00153 #endif
00154 
00155 #include "classicNurbsCurve.I"
00156 
00157 #endif

Generated on Fri May 2 00:40:39 2003 for Panda by doxygen1.3