Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/numerics/functions.h

Go to the documentation of this file.
00001 /*
00002  * lib/numerics/functions.h 
00003  * 
00004  * Binary search templates. 
00005  * 
00006  * Copyright (c) 2004 by Klaus Sausen (nicolasius § users.sourceforge.net)
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 #ifndef _TemplateLibrary_FUNCTIONS_H_
00017 #define _TemplateLibrary_FUNCTIONS_H_ 1
00018 
00019 #include <lib/sconfig.h>
00020 #include <num_math.h>
00021 namespace NUM {
00022 
00023 
00028 template <class T, class U>
00029 T cosinterp(U x, T v0, T v1) {
00030     U f;
00031     f=U(0.5)*(U(1.0)-cos(U(M_PI)*x));
00032     return v0*(T(1.0)-f)+v1*f;
00033 }
00034 
00039 template <class T, class U>
00040 T cubinterp(U x, T v0, T v1, T v2, T v3) {
00041     T p,q,r,res;
00042     r=v0-v1;
00043     p=(v3-v2)-r;
00044     q=r-p;
00045     res=v1;
00046     res+=(v2-v0)*x;
00047     x*=x;
00048     res+=q*x;
00049     x*=x;
00050     res+=p*x;
00051     return res;
00052 }
00053 
00055 template <class T>
00056 T step (const T a, const T b) {
00057     return (a>=b)?1.0:0.0;
00058 }
00059 
00061 template <class T>
00062 T pulse (const T x, const T a, const T b) {
00063     return (step(x,a)-step(x,b));
00064 }
00065 
00069 template <class T>
00070 T bias(T b, T x) {
00071     return pow(x,-log2(b)); // optimized to use log2 (Wolfgang)
00072 }
00073 
00077 template <class T>
00078 T sbias(T b, T x) {
00079     return x*T(1.0)/( (T(1.0)-x)*(T(1.0)/(b-T(2.0)))+T(1.0) );
00080 }
00081 
00085 template <class T>
00086 T gain(T g, T x) {
00087     return (x<T(0.5))
00088     ?T(0.5)*bias<T>(T(1.0)-g,T(2.0)*x)
00089     :T(1.0)-bias<T>(T(1.0)-g,T(2.0)-T(2.0)*x)*T(0.5);
00090 }
00091 
00095 template <class T>
00096 T sgain(T g, T x) {
00097     T t = (T(1.0)-T(2.0)*x)*((T(1.0)/g)-T(2.0));
00098     return (x<T(0.5))
00099     ?   x *T(1.0)/( t+T(1.0))
00100     :(t-x)*T(1.0)/( t-T(1.0));
00101 }
00102 
00103 //TODO (types)
00105 /*template <class T>
00106 T sphong(T n, T x) {
00107 S (t) := t / (n-nt+t)
00108  n
00109 }*/
00110 
00111 };
00112 #endif

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5