Claw  1.7.3
curve.hpp
Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2011 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022   contact: julien.jorge@gamned.org
00023 */
00029 #ifndef __CLAW_MATH_CURVE_HPP__
00030 #define __CLAW_MATH_CURVE_HPP__
00031 
00032 #include <claw/coordinate_traits.hpp>
00033 #include <list>
00034 #include <vector>
00035 
00036 namespace claw
00037 {
00038   namespace math
00039   {
00048     template< typename C, typename Traits = coordinate_traits<C> >
00049     class curve
00050     {
00051     public:
00053       typedef C coordinate_type;
00054 
00057       typedef Traits traits_type;
00058 
00060       typedef typename traits_type::value_type value_type;
00061 
00067       class control_point
00068       {
00069       public:
00071         typedef C coordinate_type;
00072 
00073       public:
00074         control_point();
00075         explicit control_point( const coordinate_type& p );
00076         control_point
00077         ( const coordinate_type& p, const coordinate_type& input_direction,
00078           const coordinate_type& output_direction );
00079 
00080         const coordinate_type& get_position() const;
00081         const coordinate_type& get_input_direction() const;
00082         const coordinate_type& get_output_direction() const;
00083 
00084       private:
00086         coordinate_type m_position;
00087 
00090         coordinate_type m_input_direction;
00091 
00094         coordinate_type m_output_direction;
00095 
00096       }; // class control_point
00097 
00098     private:
00101       typedef std::list<control_point> control_point_list;
00102 
00103     public:
00105       typedef typename control_point_list::iterator iterator;
00106 
00108       typedef typename control_point_list::const_iterator const_iterator;
00109 
00114       class section
00115       {
00116       public:
00118         typedef C coordinate_type;
00119 
00122         typedef Traits traits_type;
00123 
00125         typedef typename traits_type::value_type value_type;
00126 
00128         typedef const_iterator iterator_type;
00129 
00134         class resolved_point
00135         {
00136         public:
00138           typedef C coordinate_type;
00139 
00140         public:
00141           resolved_point
00142           ( const coordinate_type& position, const section& s, const double t );
00143 
00144           const coordinate_type& get_position() const;
00145           const section& get_section() const;
00146           double get_date() const;
00147 
00148         private:
00150           coordinate_type m_position;
00151 
00153           section m_section;
00154 
00156           double m_date;
00157 
00158         }; // class resolved_point
00159 
00160       public:
00161         section( const iterator_type& origin, const iterator_type& end );
00162 
00163         coordinate_type get_point_at( double t ) const;
00164         coordinate_type get_tangent_at( double t ) const;
00165         std::vector<resolved_point>
00166         get_point_at_x( value_type x, bool off_domain = false  ) const;
00167 
00168         const iterator_type& get_origin() const;
00169 
00170         bool empty() const;
00171 
00172       private:
00173         value_type evaluate
00174         ( double t, value_type origin, value_type output_direction,
00175           value_type input_direction, value_type end ) const;
00176         value_type evaluate_derived
00177         ( double t, value_type origin, value_type output_direction,
00178           value_type input_direction, value_type end ) const;
00179 
00180         void ensure_ends_in_points
00181         ( std::vector<resolved_point>& p, bool ensure_origin,
00182           bool ensure_end ) const;
00183 
00184         std::vector<resolved_point>
00185         extract_domain_points( const std::vector<resolved_point>& p ) const;
00186 
00187         std::vector<double> get_roots
00188         ( value_type x, value_type origin, value_type output_direction,
00189           value_type input_direction, value_type end ) const;
00190 
00191         std::vector<double> get_roots_degree_2
00192         ( value_type a, value_type b, value_type c ) const;
00193         std::vector<double> get_roots_degree_3
00194         ( value_type a, value_type b, value_type c, value_type d ) const;
00195 
00196       private:
00198         iterator_type m_origin;
00199 
00201         iterator_type m_end;
00202 
00203       }; // class section
00204 
00205     public:
00206       void push_back( const control_point& p );
00207       void push_front( const control_point& p );
00208       void insert( const iterator& pos, const control_point& p );
00209 
00210       section get_section( const const_iterator& pos ) const;
00211       
00212       std::vector<typename section::resolved_point>
00213       get_point_at_x( value_type x, bool off_domain = false ) const;
00214 
00215       iterator begin();
00216       iterator end();
00217       const_iterator begin() const;
00218       const_iterator end() const;
00219 
00220     private:
00221       std::vector<typename section::resolved_point>
00222       get_point_at_x_before_origin( value_type x ) const;
00223       std::vector<typename section::resolved_point>
00224       get_point_at_x_after_end( value_type x ) const;
00225 
00226     private:
00228       control_point_list m_points;
00229       
00230     }; // class curve
00231 
00232   } // namespace math
00233 } // namespace claw
00234 
00235 #include "claw/impl/curve.tpp"
00236 
00237 #endif // __CLAW_MATH_CURVE_HPP__