Fawkes API  Fawkes Development Version
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_ */
HomVector tangent_at_t(float t)
Compute the tangent vector at position t.
Definition: bezier.cpp:190
unsigned int degree() const
Get the degree of the polynom.
Definition: bezier.cpp:167
virtual void register_primitives()
Here, a derived class should register its primitives (HomPoints and HomVectors) by calling add_primit...
Definition: bezier.cpp:354
Fawkes library namespace.
A Bezier curve class.
Definition: bezier.h:34
void subdivide(float t, Bezier &c, Bezier &d)
Subdivide the curve into two polynome of the same degree.
Definition: bezier.cpp:222
void set_control_points(const std::vector< HomPoint > &control_points)
Set the control points.
Definition: bezier.cpp:94
HomPoint get_control_point(unsigned int i) const
Get a specific control point.
Definition: bezier.cpp:155
const std::vector< HomPoint > & approximate(unsigned int num_subdivisions=4)
Approximate the curve with points.
Definition: bezier.cpp:253
Bezier()
Constructor.
Definition: bezier.cpp:38
~Bezier()
Destructor.
Definition: bezier.cpp:82
A homogeneous point.
Definition: hom_point.h:33
virtual void post_transform()
This method is called after the primitives are transformed.
Definition: bezier.cpp:367
A homogeneous vector.
Definition: hom_vector.h:31
Interface class for all transformable objects.
Definition: transformable.h:34
HomVector tangent_at_point(unsigned int index)
Compute the tangent vector at the specified control point.
Definition: bezier.cpp:205
HomPoint eval(float t)
Evalutate the polynom for a given t.
Definition: bezier.cpp:177
void set_control_point(unsigned int index, const HomPoint &control_point)
Replace a specific control point.
Definition: bezier.cpp:130
std::vector< HomPoint > get_control_points() const
Get the control points.
Definition: bezier.cpp:145