ShLibSplinesImpl.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library 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 GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHLIBSPLINESIMPL_HPP
00021 #define SHLIBSPLINESIMPL_HPP
00022 
00023 #include "ShLibSplines.hpp"
00024 #include "ShDebug.hpp"
00025 
00026 namespace SH {
00027 
00028 template<int N, typename T>
00029 ShGeneric<N, T> bernstein(const ShGeneric<1, T>& a)
00030 {
00031   ShAttrib<N, SH_TEMP, T> result;
00032   if (4 == N) {
00033     ShAttrib<1, SH_TEMP, T> it = ShAttrib<1,SH_TEMP, T>(1.0f) - a;
00034     result(0) = it*it*it;
00035     result(1) = 3.0*it*it*a;
00036     result(2) = 3.0*it*a*a;
00037     result(3) = a*a*a;
00038   }
00039   else {
00040     // TODO: implement the real thing for the general case
00041     SH_DEBUG_WARN("bernstein is not fully implemented yet");
00042     for (int i=0; i < N; i++) {
00043       result[i] = a[0];
00044     }
00045   }
00046   return result;
00047 }
00048 
00049 template <int N, typename T>
00050 ShGeneric<N, T> bezier(const ShGeneric<1, T>& t, const ShGeneric<N, T>& p)
00051 {
00052   ShAttrib<N, SH_TEMP, T> B = bernstein<N>(t(0));
00053   ShAttrib<N, SH_TEMP, T> r;
00054   r(0) = B[0] * p[0];
00055   for (int i=1; i < N; i++) {
00056     r(i) = B[i] * p[i];
00057   }
00058   return r;
00059 }
00060 
00061 template <int N, typename T>
00062 ShGeneric<N, T> hermite(const ShGeneric<1, T>& a, const ShGeneric<N, T>& b, 
00063                         const ShGeneric<N, T>& c, const ShGeneric<N, T>& d, 
00064                         const ShGeneric<N, T>& e)
00065 {
00066   ShAttrib<N, SH_TEMP, T> result;
00067 
00068   // TODO: implement the real thing
00069   SH_DEBUG_WARN("hermite is not implemented yet");
00070   for (int i=0; i < N; i++) {
00071     result[i] = a[0];
00072   }
00073 
00074   return result;
00075 }
00076 
00077 }
00078 
00079 #endif

Generated on Thu Feb 16 14:51:34 2006 for Sh by  doxygen 1.4.6