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__