Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bezier.h
1 
2 /***************************************************************************
3  * bezier.h - Bezier curve
4  *
5  * Created: Mon Oct 06 14:52:57 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_BEZIER_H_
25 #define __GEOMETRY_BEZIER_H_
26 
27 #include <geometry/transformable.h>
28 #include <vector>
29 
30 namespace fawkes {
31 class HomPoint;
32 class HomVector;
33 
34 class Bezier : public Transformable
35 {
36  public:
37  Bezier();
38  Bezier(const std::vector<HomPoint>& control_points);
39  Bezier(const Bezier& b);
40  ~Bezier();
41 
42  void set_control_points(const std::vector<HomPoint>& control_points);
43  void set_control_point(unsigned int index, const HomPoint& control_point);
44 
45  std::vector<HomPoint> get_control_points() const;
46  HomPoint get_control_point(unsigned int i) const;
47 
48  unsigned int degree() const;
49 
50  HomPoint eval(float t);
51  HomVector tangent_at_t(float t);
52  HomVector tangent_at_point(unsigned int index);
53  void subdivide(float t, Bezier& c, Bezier& d);
54  const 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 init_dclj_array();
63  unsigned int get_dclj_array_index(unsigned int k, unsigned int i) const;
64 
65  std::vector<HomPoint> m_control_points;
66  std::vector<HomPoint> m_approximation;
67  unsigned int m_num_subdivisions;
68 
69  HomPoint de_casteljau(unsigned int k, unsigned int i, float t);
70 
71  std::pair<HomPoint*, bool>* m_de_casteljau_points;
72  unsigned int m_dclj_array_size;
73 
74  unsigned int m_num_control_points;
75 
76  float m_last_t;
77 };
78 
79 } // end namespace fawkes
80 
81 #endif /* __GEOMETRY_BEZIER_H_ */