Panda3D
nurbsCurve.h
1 // Filename: nurbsCurve.h
2 // Created by: drose (27Feb98)
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 NURBSCURVE_H
16 #define NURBSCURVE_H
17 
18 #include "pandabase.h"
19 
20 #include "piecewiseCurve.h"
21 #include "nurbsCurveInterface.h"
22 #include "cubicCurveseg.h"
23 #include "epvector.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : NurbsCurve
27 // Description : A Nonuniform Rational B-Spline.
28 //
29 // This class is actually implemented as a
30 // PiecewiseCurve made up of several CubicCurvesegs,
31 // each of which is created using the nurbs_basis()
32 // method. The list of CV's and knots is kept here,
33 // within the NurbsCurve class.
34 //
35 // This class is the original Panda-native
36 // implementation of a NURBS curve. It is typedeffed as
37 // "NurbsCurve" and performs all NURBS curve functions
38 // if we do not have the NURBS++ library available.
39 //
40 // However, if we *do* have the NURBS++ library, another
41 // class exists, the NurbsPPCurve, which is a wrapper
42 // around that library and provides some additional
43 // functionality. In that case, the other class is
44 // typedeffed to "NurbsCurve" instead of this one, and
45 // performs most of the NURBS curve functions. This
46 // class then becomes vestigial.
47 ////////////////////////////////////////////////////////////////////
48 class EXPCL_PANDA_PARAMETRICS NurbsCurve : public PiecewiseCurve, public NurbsCurveInterface {
49 PUBLISHED:
50  NurbsCurve();
51  NurbsCurve(const ParametricCurve &pc);
52 public:
53  NurbsCurve(int order, int num_cvs,
54  const PN_stdfloat knots[], const LVecBase4 cvs[]);
55 PUBLISHED:
56  virtual ~NurbsCurve();
57 
58 public:
59  virtual PandaNode *make_copy() const;
60 
61  // We don't need to re-publish these, since they're all published
62  // from NurbsCurveInterface.
63  virtual void set_order(int order);
64  virtual int get_order() const;
65 
66  virtual int get_num_cvs() const;
67  virtual int get_num_knots() const;
68 
69  virtual bool insert_cv(PN_stdfloat t);
70 
71  virtual bool remove_cv(int n);
72  virtual void remove_all_cvs();
73 
74  virtual bool set_cv(int n, const LVecBase4 &v);
75  virtual LVecBase4 get_cv(int n) const;
76 
77  virtual bool set_knot(int n, PN_stdfloat t);
78  virtual PN_stdfloat get_knot(int n) const;
79 
80  virtual bool recompute();
81 
82 public:
83  virtual bool
84  rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
85  int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
86  int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
87  int rtype3, PN_stdfloat t3, const LVecBase4 &v3);
88 
89  virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b);
90 
91  INLINE CubicCurveseg *get_curveseg(int ti);
92 
94  virtual bool convert_to_nurbs(ParametricCurve *nc) const;
95  virtual void write(ostream &out, int indent_level = 0) const;
96 
97 protected:
98  virtual int append_cv_impl(const LVecBase4 &v);
99  virtual bool format_egg(ostream &out, const string &name,
100  const string &curve_type, int indent_level) const;
101 
102  int find_cv(PN_stdfloat t);
103 
104  int _order;
105 
106  class CV {
107  public:
108  CV() {}
109  CV(const LVecBase4 &p, PN_stdfloat t) : _p(p), _t(t) {}
110  LVecBase4 _p;
111  PN_stdfloat _t;
112  };
113 
114  epvector<CV> _cvs;
115 
116 // TypedWritable stuff
117 public:
118  static void register_with_read_factory();
119 
120 protected:
121  static TypedWritable *make_NurbsCurve(const FactoryParams &params);
122  virtual void write_datagram(BamWriter *manager, Datagram &me);
123  void fillin(DatagramIterator &scan, BamReader *manager);
124 
125 public:
126  static TypeHandle get_class_type() {
127  return _type_handle;
128  }
129  static void init_type() {
130  PiecewiseCurve::init_type();
131  NurbsCurveInterface::init_type();
132  register_type(_type_handle, "NurbsCurve",
133  PiecewiseCurve::get_class_type(),
134  NurbsCurveInterface::get_class_type());
135  }
136  virtual TypeHandle get_type() const {
137  return get_class_type();
138  }
139  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
140 
141 private:
142  static TypeHandle _type_handle;
143 };
144 
145 #include "nurbsCurve.I"
146 
147 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
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:122
A virtual base class for parametric curves.
virtual bool recompute()
Recalculates the curve, if necessary.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
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...
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:58
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...
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:40
A Nonuniform Rational B-Spline.
Definition: nurbsCurve.h:48
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
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 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:43
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...