bezier.h

00001 
00002 /***************************************************************************
00003  *  bezier.h - Bezier curve
00004  *
00005  *  Created: Mon Oct 06 14:52:57 2008
00006  *  Copyright  2008  Daniel Beck
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __GEOMETRY_BEZIER_H_
00025 #define __GEOMETRY_BEZIER_H_
00026 
00027 #include <geometry/transformable.h>
00028 #include <vector>
00029 
00030 namespace fawkes {
00031 class HomPoint;
00032 class HomVector;
00033 
00034 class Bezier : public Transformable
00035 {
00036  public:
00037   Bezier();
00038   Bezier(const std::vector<HomPoint>& control_points);
00039   Bezier(const Bezier& b);
00040   ~Bezier();
00041 
00042   void set_control_points(const std::vector<HomPoint>& control_points);
00043   void set_control_point(unsigned int index, const HomPoint& control_point);
00044   
00045   std::vector<HomPoint> get_control_points() const;
00046   HomPoint              get_control_point(unsigned int i) const;
00047 
00048   unsigned int degree() const;
00049  
00050   HomPoint  eval(float t);
00051   HomVector tangent_at_t(float t);
00052   HomVector tangent_at_point(unsigned int index);
00053   void      subdivide(float t, Bezier& c, Bezier& d);
00054   const std::vector<HomPoint>& approximate(unsigned int num_subdivisions = 4);
00055 
00056  protected:
00057   // transformable
00058   virtual void register_primitives();
00059   virtual void post_transform();
00060 
00061  private:
00062   void init_dclj_array();
00063   unsigned int get_dclj_array_index(unsigned int k, unsigned int i) const;
00064 
00065   std::vector<HomPoint> m_control_points;
00066   std::vector<HomPoint> m_approximation;
00067   unsigned int m_num_subdivisions;
00068 
00069   HomPoint de_casteljau(unsigned int k, unsigned int i, float t);
00070   
00071   std::pair<HomPoint*, bool>* m_de_casteljau_points;
00072   unsigned int m_dclj_array_size;
00073 
00074   unsigned int m_num_control_points;
00075 
00076   float m_last_t;
00077 };
00078 
00079 } // end namespace fawkes
00080 
00081 #endif /* __GEOMETRY_BEZIER_H_ */

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1