_hermite.h

Go to the documentation of this file.
00001 
00025 /* === S T A R T =========================================================== */
00026 
00027 #ifndef __ETL_HERMITE_H
00028 #define __ETL_HERMITE_H
00029 
00030 /* === H E A D E R S ======================================================= */
00031 
00032 #include "bezier"
00033 
00034 /* === M A C R O S ========================================================= */
00035 
00036 /* === T Y P E D E F S ===================================================== */
00037 
00038 /* === C L A S S E S & S T R U C T S ======================================= */
00039 
00040 _ETL_BEGIN_NAMESPACE
00041 
00042 /*
00043 template <typename T>
00044 class hermite_base : std::unary_function<float,T>
00045 {
00046 public:
00047     typedef T value_type;
00048     typedef float time_type;
00049 private:
00050     affine_combo<value_type,time_type> affine_func;
00051     value_type a,b,c,d;
00052     time_type r,s;
00053 
00054     value_type _coeff[3];
00055     time_type drs; // reciprocal of (s-r)
00056 public:
00057     hermite_base():r(0.0),s(1.0) { drs=1.0/(s-r); }
00058     hermite_base(
00059         const value_type &a, const value_type &b, const value_type &c, const value_type &d,
00060         const time_type &r=0.0, const time_type &s=1.0):
00061         a(a),b(b),c(c),d(d),r(r),s(s) { sync(); }
00062 
00063     void sync(void)
00064     {
00065         drs=1.0/(s-r);
00066         _coeff[0]=           c;
00067         _coeff[1]=-d*1 - c*2 + b*3 - a*3;
00068         _coeff[2]= d*1 + c*1 - b*2 + a*2;
00069     }
00070 
00071     inline value_type
00072     operator()(time_type t)const
00073     { t-=r; t*=drs; return a + (_coeff[0]+(_coeff[1]+(_coeff[2])*t)*t)*t; }
00074 
00075     void set_rs(time_type new_r, time_type new_s) { r=new_r; s=new_s; drs=1.0/(s-r); }
00076     void set_r(time_type new_r) { r=new_r; drs=1.0/(s-r); }
00077     void set_s(time_type new_s) { s=new_s; drs=1.0/(s-r); }
00078     const time_type &get_r(void)const { return r; }
00079     const time_type &get_s(void)const { return s; }
00080     time_type get_dt(void)const { return s-r; }
00081 
00082     value_type &
00083     operator[](int i)
00084     { return (&a)[i]; }
00085 
00086     const value_type &
00087     operator[](int i) const
00088     { return (&a)[i]; }
00089 };
00090 
00091 
00092 template <typename T>
00093 class hermite : public hermite_base<T>
00094 {
00095 public:
00096     typedef T value_type;
00097     typedef float time_type;
00098 
00099 
00100 
00101 public:
00102     hermite() { }
00103     hermite(const value_type &p1, const value_type &p2, const value_type &t1, const value_type &t2):
00104         P1(p1),P2(p2),T1(t1),T2(t2) { sync(); }
00105     hermite(const value_type &p1, const value_type &p2):
00106         P1(p1),P2(p2),T1(p2-p1),T2(p2-p1) { sync(); }
00107 
00108     value_type P1,P2,T1,T2;
00109 
00110     value_type &p1(void) { return P1; }
00111     value_type &p2(void) { return P2; }
00112     value_type &t1(void) { return T1; }
00113     value_type &t2(void) { return T2; }
00114 
00115     void sync(void)
00116     {
00117 //      hermite_base<T>::operator[](0)=P1;
00118 //      bezier<T>::operator[](1)=P1+T1/3;
00119 //      bezier<T>::operator[](2)=P2-T2/3;
00120 //      bezier<T>::operator[](3)=P2;
00121 
00122         hermite_base<T>::operator[](0)=P1;
00123         hermite_base<T>::operator[](1)=P2;
00124         hermite_base<T>::operator[](2)=T1;
00125         hermite_base<T>::operator[](3)=T2;
00126 
00127         hermite_base<T>::sync();
00128     }
00129 
00130 };
00131 
00132 */
00133 
00134 template <typename V,typename T=float>
00135 class hermite : public bezier<V,T>
00136 {
00137 public:
00138     typedef V value_type;
00139     typedef T time_type;
00140 
00141 
00142 
00143 public:
00144     hermite() { }
00145     hermite(const value_type &p1, const value_type &p2, const value_type &t1, const value_type &t2):
00146         P1(p1),P2(p2),T1(t1),T2(t2) { sync(); }
00147     hermite(const value_type &p1, const value_type &p2):
00148         P1(p1),P2(p2),T1(p2-p1),T2(p2-p1) { sync(); }
00149 
00150     value_type P1,P2,T1,T2;
00151 
00152     value_type &p1() { return P1; }
00153     value_type &p2() { return P2; }
00154     value_type &t1() { return T1; }
00155     value_type &t2() { return T2; }
00156 
00157     void sync()
00158     {
00159         bezier<V,T>::operator[](0)=P1;
00160         bezier<V,T>::operator[](1)=P1+T1/3;
00161         bezier<V,T>::operator[](2)=P2-T2/3;
00162         bezier<V,T>::operator[](3)=P2;
00163 
00164         bezier<V,T>::sync();
00165     }
00166 };
00167 
00168 _ETL_END_NAMESPACE
00169 
00170 /* === E X T E R N S ======================================================= */
00171 
00172 /* === E N D =============================================================== */
00173 
00174 #endif

Generated on Fri Jun 22 15:15:57 2007 for ETL by  doxygen 1.5.2