Claw  1.7.3
curve.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  contact: julien.jorge@gamned.org
23 */
29 #ifndef __CLAW_MATH_CURVE_HPP__
30 #define __CLAW_MATH_CURVE_HPP__
31 
33 #include <list>
34 #include <vector>
35 
36 namespace claw
37 {
38  namespace math
39  {
48  template< typename C, typename Traits = coordinate_traits<C> >
49  class curve
50  {
51  public:
53  typedef C coordinate_type;
54 
57  typedef Traits traits_type;
58 
60  typedef typename traits_type::value_type value_type;
61 
68  {
69  public:
71  typedef C coordinate_type;
72 
73  public:
74  control_point();
75  explicit control_point( const coordinate_type& p );
77  ( const coordinate_type& p, const coordinate_type& input_direction,
78  const coordinate_type& output_direction );
79 
80  const coordinate_type& get_position() const;
81  const coordinate_type& get_input_direction() const;
83 
84  private:
86  coordinate_type m_position;
87 
90  coordinate_type m_input_direction;
91 
94  coordinate_type m_output_direction;
95 
96  }; // class control_point
97 
98  private:
101  typedef std::list<control_point> control_point_list;
102 
103  public:
105  typedef typename control_point_list::iterator iterator;
106 
108  typedef typename control_point_list::const_iterator const_iterator;
109 
114  class section
115  {
116  public:
118  typedef C coordinate_type;
119 
122  typedef Traits traits_type;
123 
125  typedef typename traits_type::value_type value_type;
126 
129 
135  {
136  public:
138  typedef C coordinate_type;
139 
140  public:
142  ( const coordinate_type& position, const section& s, const double t );
143 
144  const coordinate_type& get_position() const;
145  const section& get_section() const;
146  double get_date() const;
147 
148  private:
150  coordinate_type m_position;
151 
153  section m_section;
154 
156  double m_date;
157 
158  }; // class resolved_point
159 
160  public:
161  section( const iterator_type& origin, const iterator_type& end );
162 
163  coordinate_type get_point_at( double t ) const;
164  coordinate_type get_tangent_at( double t ) const;
165  std::vector<resolved_point>
166  get_point_at_x( value_type x, bool off_domain = false ) const;
167 
168  const iterator_type& get_origin() const;
169 
170  bool empty() const;
171 
172  private:
173  value_type evaluate
174  ( double t, value_type origin, value_type output_direction,
175  value_type input_direction, value_type end ) const;
176  value_type evaluate_derived
177  ( double t, value_type origin, value_type output_direction,
178  value_type input_direction, value_type end ) const;
179 
180  void ensure_ends_in_points
181  ( std::vector<resolved_point>& p, bool ensure_origin,
182  bool ensure_end ) const;
183 
184  std::vector<resolved_point>
185  extract_domain_points( const std::vector<resolved_point>& p ) const;
186 
187  std::vector<double> get_roots
188  ( value_type x, value_type origin, value_type output_direction,
189  value_type input_direction, value_type end ) const;
190 
191  std::vector<double> get_roots_degree_2
192  ( value_type a, value_type b, value_type c ) const;
193  std::vector<double> get_roots_degree_3
194  ( value_type a, value_type b, value_type c, value_type d ) const;
195 
196  private:
198  iterator_type m_origin;
199 
201  iterator_type m_end;
202 
203  }; // class section
204 
205  public:
206  void push_back( const control_point& p );
207  void push_front( const control_point& p );
208  void insert( const iterator& pos, const control_point& p );
209 
210  section get_section( const const_iterator& pos ) const;
211 
212  std::vector<typename section::resolved_point>
213  get_point_at_x( value_type x, bool off_domain = false ) const;
214 
215  iterator begin();
216  iterator end();
217  const_iterator begin() const;
218  const_iterator end() const;
219 
220  private:
221  std::vector<typename section::resolved_point>
222  get_point_at_x_before_origin( value_type x ) const;
223  std::vector<typename section::resolved_point>
224  get_point_at_x_after_end( value_type x ) const;
225 
226  private:
228  control_point_list m_points;
229 
230  }; // class curve
231 
232  } // namespace math
233 } // namespace claw
234 
235 #include "claw/impl/curve.tpp"
236 
237 #endif // __CLAW_MATH_CURVE_HPP__
resolved_point(const coordinate_type &position, const section &s, const double t)
Constructor.
Definition: curve.tpp:123
coordinate_type get_tangent_at(double t) const
Get the direction of the tangent at a given date.
Definition: curve.tpp:217
section(const iterator_type &origin, const iterator_type &end)
Constructor.
Definition: curve.tpp:176
The control_point class describes a control point of the curve, with the direction of the curve befor...
Definition: curve.hpp:67
const section & get_section() const
Get the section on which the point has been found.
Definition: curve.tpp:147
coordinate_type get_point_at(double t) const
Get the point of this section at a given date.
Definition: curve.tpp:189
void push_front(const control_point &p)
Add a point at the beginning of the curve.
Definition: curve.tpp:558
std::vector< resolved_point > get_point_at_x(value_type x, bool off_domain=false) const
Get the points having the given x-coordinate on this section.
Definition: curve.tpp:247
The coordinate traits provide an access to the members of the structures representing a coordinate in...
Implementation of claw::math::curve.
const_iterator iterator_type
The type of the iterators on the ends of the section.
Definition: curve.hpp:128
C coordinate_type
The type of the coordinates of the curve.
Definition: curve.hpp:138
A section is a part of the curve between two control points.
Definition: curve.hpp:114
C coordinate_type
The type of the coordinates of the curve.
Definition: curve.hpp:118
iterator end()
Get an iterator past the last control point.
Definition: curve.tpp:652
const coordinate_type & get_position() const
Get The position of the point.
Definition: curve.tpp:136
const iterator_type & get_origin() const
Get an iterator on the control point at the origin of the section in the curve from which it was crea...
Definition: curve.tpp:282
const coordinate_type & get_output_direction() const
Get the point in the direction of which the curve leaves this position.
Definition: curve.tpp:105
const coordinate_type & get_position() const
Get the position of this control point.
Definition: curve.tpp:81
std::vector< typename section::resolved_point > get_point_at_x(value_type x, bool off_domain=false) const
Get the points having the given x-coordinate on the curve.
Definition: curve.tpp:607
C coordinate_type
The type of the coordinates of the curve.
Definition: curve.hpp:53
bool empty() const
Tell if there is no points on this section.
Definition: curve.tpp:292
traits_type::value_type value_type
The type of the components of the coordinates.
Definition: curve.hpp:60
Traits traits_type
The traits provide an access to the properties of the coordinates.
Definition: curve.hpp:122
traits_type::value_type value_type
The type of the components of the coordinates.
Definition: curve.hpp:125
section get_section(const const_iterator &pos) const
Get the section of the curve starting at a given control point.
Definition: curve.tpp:584
C coordinate_type
The type of the coordinates of the curve.
Definition: curve.hpp:71
void push_back(const control_point &p)
Add a point at the end of the curve.
Definition: curve.tpp:547
const coordinate_type & get_input_direction() const
Get the point in the direction of which the curve enters this position.
Definition: curve.tpp:93
Traits traits_type
The traits provide an access to the properties of the coordinates.
Definition: curve.hpp:57
void insert(const iterator &pos, const control_point &p)
Add a point before an other point of the curve.
Definition: curve.tpp:571
control_point()
Constructor.
Definition: curve.tpp:37
control_point_list::const_iterator const_iterator
The type of the iterator on the control points of the curve.
Definition: curve.hpp:108
control_point_list::iterator iterator
The type of the iterator on the control points of the curve.
Definition: curve.hpp:105
Implementation of the Bézier curve.
Definition: curve.hpp:49
iterator begin()
Get an iterator on the first control point.
Definition: curve.tpp:641
double get_date() const
Get the date of the point on the section.
Definition: curve.tpp:158
The resolved point class is a point found on a section.
Definition: curve.hpp:134