Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
spline.h
1 
2 /***************************************************************************
3  * spline.h - Cubic spline curve
4  *
5  * Created: Tue Oct 07 18:57:42 2008
6  * Copyright 2008 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __GEOMETRY_SPLINE_H_
25 #define __GEOMETRY_SPLINE_H_
26 
27 #include <geometry/transformable.h>
28 #include <geometry/hom_point.h>
29 #include <geometry/bezier.h>
30 #include <vector>
31 
32 namespace fawkes {
33 
34 class SplineDrawer;
35 
36 class Spline : public Transformable
37 {
38  friend class fawkes::SplineDrawer;
39 
40  public:
41  Spline();
42  Spline(const std::vector<HomPoint>& control_points);
43  virtual ~Spline();
44 
45  void set_control_points(const std::vector<HomPoint>& control_points);
46  void set_control_point(unsigned int i, const HomPoint& p);
47 
48  const std::vector<HomPoint>& get_control_points() const;
49  const std::vector<Bezier>& get_bezier_curves() const;
50 
51  HomPoint eval(unsigned int bezier_index, float t);
52  HomVector tangent(unsigned int bezier_index, float t);
53  HomVector tangent(unsigned int point_index);
54  std::vector<HomPoint> approximate(unsigned int num_subdivisions = 4);
55 
56  protected:
57  // transformable
58  virtual void register_primitives();
59  virtual void post_transform();
60 
61  private:
62  void construct_bezier_curves();
63 
64  std::vector<HomPoint> m_control_points;
65  std::vector<Bezier> m_bezier_curves;
66 
67  unsigned int m_num_subdivisions;
68 };
69 
70 }
71 
72 #endif /* __GEOMETRY_SPLINE_H_ */