MathStuff.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2007-2008 Anael Orlinski
00003 *
00004 * This file is part of Panomatic.
00005 *
00006 * Panomatic is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * Panomatic is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with Panomatic; if not, write to the Free Software
00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef __lfeat_math_h
00022 #define __lfeat_math_h
00023 
00024 #include <vector>
00025 
00026 #define PI      3.14159
00027 
00028 namespace lfeat
00029 {
00030 struct Math
00031 {
00032 
00033     static bool                         SolveLinearSystem33(double* solution, double sq[3][3]);
00034     static inline double        Abs(const double iD)
00035     {
00036         return (iD > 0.0 ? iD : -iD);
00037     }
00038     static inline int           Round(const double iD)
00039     {
00040         return (int)(iD + 0.5);
00041     }
00042     static bool                         Normalize(double* iVec, int iLen);
00043 
00044 
00045 };
00046 
00047 template <int LBound = -128, int UBound = 127, class TResult = double, class TArg = double>
00048 class LUT
00049 {
00050 public:
00051     explicit LUT (TResult (*f) (TArg), double coeffadd = 0, double coeffmul = 1)
00052     {
00053         lut = lut_array - LBound;
00054         for (int i = LBound; i <= UBound; i++)
00055         {
00056             lut[i] = f(coeffmul * (i+coeffadd));
00057         }
00058     }
00059 
00060     const TResult& operator()(int i) const
00061     {
00062         return lut[i];
00063     }
00064 private:
00065     TResult lut_array[UBound - LBound + 1];
00066     TResult* lut;
00067 };
00068 
00069 }
00070 
00071 #endif //__lfeat_math_h

Generated on 23 Nov 2014 for Hugintrunk by  doxygen 1.4.7