sampledFunctions.h

Go to the documentation of this file.
00001 
00016 #ifndef _DLRNUMERIC_SAMPLEDFUNCTIONS_H_
00017 #define _DLRNUMERIC_SAMPLEDFUNCTIONS_H_
00018 
00019 #include <dlrNumeric/array1D.h>
00020 
00021 namespace dlr {
00022 
00023   namespace numeric {
00024 
00047     template <class TYPE>
00048     Array1D<TYPE>
00049     getGaussian1D(double sigma,
00050                   size_t size = 0,
00051                   bool normalize = false);
00052 
00053   } // namespace numeric
00054   
00055 } // namespace dlr
00056 
00057 
00058 /* =============================================================== */
00059 /* Implementation follows.                                         */
00060 /* =============================================================== */
00061 
00062 
00063 #include <cmath>
00064 #include <dlrNumeric/functional.h>
00065 #include <dlrNumeric/utilities.h>
00066 
00067 namespace dlr {
00068 
00069   namespace numeric {
00070 
00071     // This function returns an array in which the elements are
00072     // sampled from a 1D Gaussian.
00073     template <class TYPE>
00074     Array1D<TYPE>
00075     getGaussian1D(double sigma, size_t size, bool normalize)
00076     {
00077       if(size == 0) {
00078         size = static_cast<size_t>(6.0 * sigma + 0.5);
00079         if(size % 2 == 0) {
00080           ++size;
00081         }
00082       }
00083       Array1D<TYPE> result(size);
00084       Gaussian1DFunctor<double> functor(sigma);
00085       double x = (1.0 - static_cast<double>(size))/2.0;
00086       for(size_t index0 = 0; index0 < size; ++index0) {
00087         result[index0] = functor(x);
00088         x += 1.0;
00089       }
00090       if(normalize) {
00091         result /= sum(result);
00092       }
00093       return result;
00094     }
00095     
00096   } // namespace numeric
00097   
00098 } // namespace dlr
00099 
00100 #endif /* #ifndef _DLRNUMERIC_SAMPLEDFUNCTIONS_H_ */

Generated on Wed Nov 25 00:42:42 2009 for dlrUtilities Utility Library by  doxygen 1.5.8