Panda3D
parametricCurve.h
1 // Filename: parametricCurve.h
2 // Created by: drose (04Mar01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PARAMETRICCURVE_H
16 #define PARAMETRICCURVE_H
17 
18 #include "pandabase.h"
19 
20 #include "pandaNode.h"
21 #include "luse.h"
22 
23 #include "typedef.h"
24 #include "plist.h"
25 #include "pvector.h"
26 
27 
28 // Parametric curve semantic types. A parametric curve may have one
29 // of these types specified. These serve as hints to the egg reader
30 // and writer code about the intention of this curve, and have no
31 // other effect on the curve.
32 
33 BEGIN_PUBLISH //[
34 #define PCT_NONE 0
35 // Unspecified type.
36 
37 #define PCT_XYZ 1
38 // A three-dimensional curve in space.
39 
40 #define PCT_HPR 2
41 // The curve represents Euler rotation angles.
42 
43 #define PCT_T 3
44 // A one-dimensional timewarp curve.
45 END_PUBLISH //]
46 
47 class ParametricCurveDrawer;
48 class HermiteCurveCV;
49 class HermiteCurve;
50 class NurbsCurve;
52 
53 
54 ////////////////////////////////////////////////////////////////////
55 // Class : ParametricCurve
56 // Description : A virtual base class for parametric curves.
57 // This encapsulates all curves in 3-d space defined
58 // for a single parameter t in the range [0,get_max_t()].
59 ////////////////////////////////////////////////////////////////////
60 class EXPCL_PANDA_PARAMETRICS ParametricCurve : public PandaNode {
61 PUBLISHED:
63  virtual ~ParametricCurve();
64 
65 public:
66  virtual bool safe_to_flatten() const;
67  virtual bool safe_to_transform() const;
68 
69 PUBLISHED:
70  virtual bool is_valid() const;
71 
72  virtual PN_stdfloat get_max_t() const;
73 
74  void set_curve_type(int type);
75  int get_curve_type() const;
76 
77  void set_num_dimensions(int num);
78  int get_num_dimensions() const;
79 
80  PN_stdfloat calc_length() const;
81  PN_stdfloat calc_length(PN_stdfloat from, PN_stdfloat to) const;
82  PN_stdfloat find_length(PN_stdfloat start_t, PN_stdfloat length_offset) const;
83 
84  virtual bool get_point(PN_stdfloat t, LVecBase3 &point) const=0;
85  virtual bool get_tangent(PN_stdfloat t, LVecBase3 &tangent) const=0;
86  virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const=0;
87  virtual bool get_2ndtangent(PN_stdfloat t, LVecBase3 &tangent2) const=0;
88 
89  virtual bool adjust_point(PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz);
90  virtual bool adjust_tangent(PN_stdfloat t, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz);
91  virtual bool adjust_pt(PN_stdfloat t,
92  PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz,
93  PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz);
94 
95  virtual bool recompute();
96 
97  virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
98 
99  bool write_egg(Filename filename, CoordinateSystem cs = CS_default);
100  bool write_egg(ostream &out, const Filename &filename, CoordinateSystem cs);
101 
102 public:
103  struct BezierSeg {
104  public:
105  LVecBase3 _v[4];
106  PN_stdfloat _t;
107  };
109 
110  virtual bool get_bezier_segs(BezierSegs &) const;
111  virtual bool get_bezier_seg(BezierSeg &) const;
112  virtual NurbsCurveInterface *get_nurbs_interface();
113 
114  virtual bool convert_to_hermite(HermiteCurve *hc) const;
115  virtual bool convert_to_nurbs(ParametricCurve *nc) const;
116 
117  void register_drawer(ParametricCurveDrawer *drawer);
118  void unregister_drawer(ParametricCurveDrawer *drawer);
119 
120 protected:
121  void invalidate(PN_stdfloat t1, PN_stdfloat t2);
122  void invalidate_all();
123 
124  virtual bool format_egg(ostream &out, const string &name,
125  const string &curve_type, int indent_level) const;
126 
127 private:
128  PN_stdfloat r_calc_length(PN_stdfloat t1, PN_stdfloat t2,
129  const LPoint3 &p1, const LPoint3 &p2,
130  PN_stdfloat seglength) const;
131  bool r_find_length(PN_stdfloat target_length, PN_stdfloat &found_t,
132  PN_stdfloat t1, PN_stdfloat t2,
133  const LPoint3 &p1, const LPoint3 &p2,
134  PN_stdfloat &seglength) const;
135  bool r_find_t(PN_stdfloat target_length, PN_stdfloat &found_t,
136  PN_stdfloat t1, PN_stdfloat t2,
137  const LPoint3 &p1, const LPoint3 &p2) const;
138  bool find_t_linear(PN_stdfloat target_length, PN_stdfloat &found_t,
139  PN_stdfloat t1, PN_stdfloat t2,
140  const LPoint3 &p1, const LPoint3 &p2) const;
141 
142 protected:
143  int _curve_type;
144  int _num_dimensions;
145 
146 private:
148  DrawerList _drawers;
149 
150 // TypedWritable stuff
151 protected:
152  virtual void write_datagram(BamWriter *manager, Datagram &me);
153  void fillin(DatagramIterator &scan, BamReader *manager);
154 
155 public:
156  static TypeHandle get_class_type() {
157  return _type_handle;
158  }
159  static void init_type() {
160  PandaNode::init_type();
161  register_type(_type_handle, "ParametricCurve",
162  PandaNode::get_class_type());
163  }
164  virtual TypeHandle get_type() const {
165  return get_class_type();
166  }
167  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
168 
169 private:
170  static TypeHandle _type_handle;
171 };
172 
173 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A virtual base class for parametric curves.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This abstract class defines the interface only for a Nurbs-style curve, with knots and coordinates in...
A parametric curve defined by a sequence of control vertices, each with an in and out tangent...
Definition: hermiteCurve.h:88
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A Nonuniform Rational B-Spline.
Definition: nurbsCurve.h:48
A single CV of a Hermite curve.
Definition: hermiteCurve.h:52
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of PandaNode by calling the xf...
Definition: pandaNode.cxx:249
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
Definition: pandaNode.cxx:237