Panda3D
nurbsCurve.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 nurbsCurve.h
10  * @author drose
11  * @date 1998-02-27
12  */
13 
14 #ifndef NURBSCURVE_H
15 #define NURBSCURVE_H
16 
17 #include "pandabase.h"
18 
19 #include "piecewiseCurve.h"
20 #include "nurbsCurveInterface.h"
21 #include "cubicCurveseg.h"
22 #include "epvector.h"
23 
24 /**
25  * A Nonuniform Rational B-Spline.
26  *
27  * This class is actually implemented as a PiecewiseCurve made up of several
28  * CubicCurvesegs, each of which is created using the nurbs_basis() method.
29  * The list of CV's and knots is kept here, within the NurbsCurve class.
30  *
31  * This class is the original Panda-native implementation of a NURBS curve.
32  * It is typedeffed as "NurbsCurve" and performs all NURBS curve functions if
33  * we do not have the NURBS++ library available.
34  *
35  * However, if we *do* have the NURBS++ library, another class exists, the
36  * NurbsPPCurve, which is a wrapper around that library and provides some
37  * additional functionality. In that case, the other class is typedeffed to
38  * "NurbsCurve" instead of this one, and performs most of the NURBS curve
39  * functions. This class then becomes vestigial.
40  */
41 class EXPCL_PANDA_PARAMETRICS NurbsCurve : public PiecewiseCurve, public NurbsCurveInterface {
42 PUBLISHED:
43  NurbsCurve();
44  NurbsCurve(const ParametricCurve &pc);
45 public:
46  NurbsCurve(int order, int num_cvs,
47  const PN_stdfloat knots[], const LVecBase4 cvs[]);
48 PUBLISHED:
49  virtual ~NurbsCurve();
50 
51 public:
52  virtual PandaNode *make_copy() const;
53 
54  // We don't need to re-publish these, since they're all published from
55  // NurbsCurveInterface.
56  virtual void set_order(int order);
57  virtual int get_order() const;
58 
59  virtual int get_num_cvs() const;
60  virtual int get_num_knots() const;
61 
62  virtual bool insert_cv(PN_stdfloat t);
63 
64  virtual bool remove_cv(int n);
65  virtual void remove_all_cvs();
66 
67  virtual bool set_cv(int n, const LVecBase4 &v);
68  virtual LVecBase4 get_cv(int n) const;
69 
70  virtual bool set_knot(int n, PN_stdfloat t);
71  virtual PN_stdfloat get_knot(int n) const;
72 
73  virtual bool recompute();
74 
75 public:
76  virtual bool
77  rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
78  int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
79  int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
80  int rtype3, PN_stdfloat t3, const LVecBase4 &v3);
81 
82  virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
83 
84  INLINE CubicCurveseg *get_curveseg(int ti);
85 
87  virtual bool convert_to_nurbs(ParametricCurve *nc) const;
88  virtual void write(std::ostream &out, int indent_level = 0) const;
89 
90 protected:
91  virtual int append_cv_impl(const LVecBase4 &v);
92  virtual bool format_egg(std::ostream &out, const std::string &name,
93  const std::string &curve_type, int indent_level) const;
94 
95  int find_cv(PN_stdfloat t);
96 
97  int _order;
98 
99  class CV {
100  public:
101  CV() {}
102  CV(const LVecBase4 &p, PN_stdfloat t) : _p(p), _t(t) {}
103  LVecBase4 _p;
104  PN_stdfloat _t;
105  };
106 
107  epvector<CV> _cvs;
108 
109 // TypedWritable stuff
110 public:
111  static void register_with_read_factory();
112 
113 protected:
114  static TypedWritable *make_NurbsCurve(const FactoryParams &params);
115  virtual void write_datagram(BamWriter *manager, Datagram &me);
116  void fillin(DatagramIterator &scan, BamReader *manager);
117 
118 public:
119  static TypeHandle get_class_type() {
120  return _type_handle;
121  }
122  static void init_type() {
123  PiecewiseCurve::init_type();
124  NurbsCurveInterface::init_type();
125  register_type(_type_handle, "NurbsCurve",
126  PiecewiseCurve::get_class_type(),
127  NurbsCurveInterface::get_class_type());
128  }
129  virtual TypeHandle get_type() const {
130  return get_class_type();
131  }
132  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
133 
134 private:
135  static TypeHandle _type_handle;
136 };
137 
138 #include "nurbsCurve.I"
139 
140 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
ParametricCurve * get_curveseg(int ti)
Returns the curve segment corresponding to the given index.
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.
virtual bool recompute()
Recalculates the curve, if necessary.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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...
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:3580
virtual NurbsCurveInterface * get_nurbs_interface()
Returns a pointer to the object as a NurbsCurveInterface object if it happens to be a NURBS-style cur...
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors,...
Definition: cubicCurveseg.h:50
virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b)
Regenerates this curve as one long curve: the first curve connected end-to- end with the second one.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A PiecewiseCurve is a curve made up of several curve segments, connected in a head-to-tail fashion.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
A Nonuniform Rational B-Spline.
Definition: nurbsCurve.h:41
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:487
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 convert_to_nurbs(ParametricCurve *nc) const
Stores in the indicated NurbsCurve a NURBS representation of an equivalent curve.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
virtual bool rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0, int rtype1, PN_stdfloat t1, const LVecBase4 &v1, int rtype2, PN_stdfloat t2, const LVecBase4 &v2, int rtype3, PN_stdfloat t3, const LVecBase4 &v3)
Rebuilds the current curve segment (as selected by the most recent call to find_curve()) according to...