CubicHermiteCurve.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Jacques Gasselin                                *
00003  *   jacquesgasselin@hotmail.com                                           *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef GLCUBICHERMITECURVE_H
00021 #define GLCUBICHERMITECURVE_H
00022 
00023 #include "GLMatrix.h"
00030 namespace mathglpp
00031 {
00032 
00033 template <typename T>
00034 class GLCubicHermiteCurve4
00035 {
00036 public:
00037     enum { D = 4 };
00038     typedef T value_type;
00039     typedef GLVector4<value_type> vector_type;
00040     typedef GLMatrix<value_type> matrix_type;
00041 
00043     GLCubicHermiteCurve4(const value_type* cpoints)
00044     :basis(cpoints)
00045     {
00047         static const value_type coeffs[16] =
00048             {  1,  0,  0,  0,
00049                0,  1,  0,  0,
00050               -3, -2,  3, -1,
00051                2,  1, -2,  1 };
00052 
00054         basis *= matrix_type(coeffs);
00055     }
00056 
00058     GLCubicHermiteCurve4(const vector_type* cpoints)
00059     :basis()
00060     {
00062         static const value_type coeffs[16] =
00063             {  1,  0,  0,  0,
00064                0,  1,  0,  0,
00065               -3, -2,  3, -1,
00066                2,  1, -2,  1 };
00067 
00068         cpoints[0].copyTo(&basis[0]);
00069         cpoints[1].copyTo(&basis[4]);
00070         cpoints[2].copyTo(&basis[8]);
00071         cpoints[3].copyTo(&basis[12]);
00072 
00074         basis *= matrix_type(coeffs);
00075     }
00076 
00078     GLCubicHermiteCurve4(const vector_type& c0, const vector_type& c1, const vector_type& c2, const vector_type& c3)
00079     :basis()
00080     {
00082         static const value_type coeffs[16] =
00083             {  1,  0,  0,  0,
00084                0,  1,  0,  0,
00085               -3, -2,  3, -1,
00086                2,  1, -2,  1 };
00087 
00088         c0.copyTo(&basis[0]);
00089         c1.copyTo(&basis[4]);
00090         c2.copyTo(&basis[8]);
00091         c3.copyTo(&basis[12]);
00092 
00094         basis *= matrix_type(coeffs);
00095     }
00096 
00097     GLCubicHermiteCurve4(const GLCubicHermiteCurve4& hc)
00098     :basis(hc.basis) {}
00099 
00101     ~GLCubicHermiteCurve4(){}
00102 
00104     inline void glVertex(GLclampf interp) const
00105     {
00106         value_type interpVec[D] = { 1, value_type(interp), value_type(interp * interp), value_type(interp * interp * interp) };
00107         basis.dot4(interpVec).glVertex();
00108     }
00109 
00111     inline vector_type interpolate(GLclampf interp) const
00112     {
00113         value_type interpVec[D] = { 1, value_type(interp), value_type(interp * interp), value_type(interp * interp * interp) };
00114         return basis.dot4(interpVec);
00115     }
00116 
00118     void interpolate(GLclampf interp, value_type* vertex) const
00119     {
00120         vertex[0] = 1;
00121         vertex[1] = value_type(interp);
00122         vertex[2] = value_type(interp * interp);
00123         vertex[3] = value_type(interp * interp * interp);
00124         basis.vdot4(vertex);
00125     }
00126 
00127     inline vector_type operator()(GLclampf interp) const
00128     {
00129         value_type interpVec[D] = { 1, value_type(interp), value_type(interp * interp), value_type(interp * interp * interp) };
00130         return basis.dot4(interpVec);
00131     }
00132 
00133     inline void operator()(GLclampf interp, value_type* v) const
00134     {
00135         v[0] = 1;
00136         v[1] = value_type(interp);
00137         v[2] = value_type(interp * interp);
00138         v[3] = value_type(interp * interp * interp);
00139         basis.vdot4(v);
00140     }
00141 
00142 private:
00143     matrix_type basis;
00144 };
00145 
00146 
00148 typedef GLCubicHermiteCurve4<GLbyte> GLCubicHermiteCurve4b;
00150 typedef GLCubicHermiteCurve4<GLshort> GLCubicHermiteCurve4s;
00152 typedef GLCubicHermiteCurve4<GLint> GLCubicHermiteCurve4i;
00154 typedef GLCubicHermiteCurve4<GLfloat> GLCubicHermiteCurve4f;
00156 typedef GLCubicHermiteCurve4<GLdouble> GLCubicHermiteCurve4d;
00157 
00158 };
00159 #endif

Generated on Wed Oct 3 12:50:48 2007 for MathGL++ by  doxygen 1.5.2