Fawkes API  Fawkes Development Version
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_ */
A spline made up of cubic Bezier curves.
Definition: spline.h:36
void set_control_point(unsigned int i, const HomPoint &p)
Set a specific control point.
Definition: spline.cpp:78
HomPoint eval(unsigned int bezier_index, float t)
Get a point on the curve for a specified segment and value t.
Definition: spline.cpp:111
Fawkes library namespace.
Drawer for Spline objects.
Definition: spline_drawer.h:33
std::vector< HomPoint > approximate(unsigned int num_subdivisions=4)
Get linear approximation of the curve.
Definition: spline.cpp:161
void set_control_points(const std::vector< HomPoint > &control_points)
Set the control points.
Definition: spline.cpp:64
Spline()
Constructor.
Definition: spline.cpp:38
virtual ~Spline()
Destructor.
Definition: spline.cpp:56
const std::vector< Bezier > & get_bezier_curves() const
Get the Bezier curves.
Definition: spline.cpp:100
A homogeneous point.
Definition: hom_point.h:33
virtual void register_primitives()
Here, a derived class should register its primitives (HomPoints and HomVectors) by calling add_primit...
Definition: spline.cpp:191
HomVector tangent(unsigned int bezier_index, float t)
Compute the tangent vector at position t of the i-th Bezier curve.
Definition: spline.cpp:122
A homogeneous vector.
Definition: hom_vector.h:31
Interface class for all transformable objects.
Definition: transformable.h:34
virtual void post_transform()
This method is called after the primitives are transformed.
Definition: spline.cpp:204
const std::vector< HomPoint > & get_control_points() const
Get the control points.
Definition: spline.cpp:91