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