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

panda/src/parametrics/parametricCurve.h

Go to the documentation of this file.
00001 // Filename: parametricCurve.h
00002 // Created by:  drose (04Mar01)
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 PARAMETRICCURVE_H
00020 #define PARAMETRICCURVE_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "pandaNode.h"
00025 #include "luse.h"
00026 
00027 #include "typedef.h"
00028 #include "plist.h"
00029 #include "pvector.h"
00030 
00031 
00032 // Parametric curve semantic types.  A parametric curve may have one
00033 // of these types specified.  These serve as hints to the egg reader
00034 // and writer code about the intention of this curve, and have no
00035 // other effect on the curve.
00036 
00037 BEGIN_PUBLISH //[
00038 #define PCT_NONE        0
00039 // Unspecified type.
00040 
00041 #define PCT_XYZ         1
00042 // A three-dimensional curve in space.
00043 
00044 #define PCT_HPR         2
00045 // The curve represents Euler rotation angles.
00046 
00047 #define PCT_T           3
00048 // A one-dimensional timewarp curve.
00049 END_PUBLISH //]
00050 
00051 class ParametricCurveDrawer;
00052 class HermiteCurveCV;
00053 class HermiteCurve;
00054 class ClassicNurbsCurve;
00055 class NurbsCurveInterface;
00056 
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //       Class : ParametricCurve
00060 // Description : A virtual base class for parametric curves.
00061 //               This encapsulates all curves in 3-d space defined
00062 //               for a single parameter t in the range [0,get_max_t()].
00063 ////////////////////////////////////////////////////////////////////
00064 class EXPCL_PANDA ParametricCurve : public PandaNode {
00065 PUBLISHED:
00066   ParametricCurve();
00067   virtual ~ParametricCurve();
00068 
00069 public:
00070   virtual bool safe_to_flatten() const;
00071   virtual bool safe_to_transform() const;
00072 
00073 PUBLISHED:
00074   virtual bool is_valid() const;
00075 
00076   virtual float get_max_t() const;
00077 
00078   void set_curve_type(int type);
00079   int get_curve_type() const;
00080 
00081   void set_num_dimensions(int num);
00082   int get_num_dimensions() const;
00083 
00084   float calc_length() const;
00085   float calc_length(float from, float to) const;
00086   float find_length(float start_t, float length_offset) const;
00087 
00088   virtual bool get_point(float t, LVecBase3f &point) const=0;
00089   virtual bool get_tangent(float t, LVecBase3f &tangent) const=0;
00090   virtual bool get_pt(float t, LVecBase3f &point, LVecBase3f &tangent) const=0;
00091   virtual bool get_2ndtangent(float t, LVecBase3f &tangent2) const=0;
00092 
00093   virtual bool adjust_point(float t, float px, float py, float pz);
00094   virtual bool adjust_tangent(float t, float tx, float ty, float tz);
00095   virtual bool adjust_pt(float t,
00096                          float px, float py, float pz,
00097                          float tx, float ty, float tz);
00098 
00099   virtual bool recompute();
00100 
00101   virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
00102 
00103   bool write_egg(Filename filename, CoordinateSystem cs = CS_default);
00104   bool write_egg(ostream &out, const Filename &filename, CoordinateSystem cs);
00105 
00106 public:
00107   struct BezierSeg {
00108   public:
00109     LVecBase3f _v[4];
00110     float _t;
00111   };
00112   typedef pvector<BezierSeg> BezierSegs;
00113 
00114   virtual bool get_bezier_segs(BezierSegs &) const;
00115   virtual bool get_bezier_seg(BezierSeg &) const;
00116   virtual NurbsCurveInterface *get_nurbs_interface();
00117 
00118   virtual bool convert_to_hermite(HermiteCurve *hc) const;
00119   virtual bool convert_to_nurbs(ParametricCurve *nc) const;
00120 
00121   void register_drawer(ParametricCurveDrawer *drawer);
00122   void unregister_drawer(ParametricCurveDrawer *drawer);
00123 
00124 protected:
00125   void invalidate(float t1, float t2);
00126   void invalidate_all();
00127 
00128   virtual bool format_egg(ostream &out, const string &name,
00129                           const string &curve_type, int indent_level) const;
00130 
00131 private:
00132   float r_calc_length(float t1, float t2,
00133                       const LPoint3f &p1, const LPoint3f &p2,
00134                       float seglength) const;
00135   bool r_find_length(float target_length, float &found_t,
00136                      float t1, float t2,
00137                      const LPoint3f &p1, const LPoint3f &p2,
00138                      float &seglength) const;
00139   bool r_find_t(float target_length, float &found_t,
00140                 float t1, float t2,
00141                 const LPoint3f &p1, const LPoint3f &p2) const;
00142   bool find_t_linear(float target_length, float &found_t,
00143              float t1, float t2,
00144              const LPoint3f &p1, const LPoint3f &p2) const;
00145 
00146 protected:
00147   int _curve_type;
00148   int _num_dimensions;
00149 
00150 private:
00151   typedef plist<ParametricCurveDrawer *> DrawerList;
00152   DrawerList _drawers;
00153 
00154 // TypedWritable stuff
00155 protected:
00156   virtual void write_datagram(BamWriter *manager, Datagram &me);
00157   void fillin(DatagramIterator &scan, BamReader *manager);
00158 
00159 public:
00160   static TypeHandle get_class_type() {
00161     return _type_handle;
00162   }
00163   static void init_type() {
00164     PandaNode::init_type();
00165     register_type(_type_handle, "ParametricCurve",
00166                   PandaNode::get_class_type());
00167   }
00168   virtual TypeHandle get_type() const {
00169     return get_class_type();
00170   }
00171   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00172 
00173 private:
00174   static TypeHandle _type_handle;
00175 };
00176 
00177 #endif

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