• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/auxil.h

Go to the documentation of this file.
00001 // Copyright (C) 2011 Soren Hauberg
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 3
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful, but
00009 // WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00015  
00016 #ifndef AUXIL_H
00017 #define AUXIL_H
00018 
00019 #include <string>
00020 #include <vector>
00021 #include <iostream>
00022 #include "math_types.h"
00023 
00029 #ifdef _MSC_VER
00030 const std::string path_sep ("\\");
00031 #else
00032 const std::string path_sep ("/");
00033 #endif
00034 
00050 inline
00051 std::string fullfile (const std::string &dir, const std::string &filename)
00052 {
00053   return dir + path_sep + filename;
00054 }
00055 
00074 inline
00075 std::string fullfile (const std::string &dir1, const std::string &dir2, const std::string &filename)
00076 {
00077   return dir1 + path_sep + dir2 + path_sep + filename;
00078 }
00079 
00089 template <class T>
00090 inline
00091 int find_max_idx (const std::vector<T> &vec)
00092 {
00093   const int N = vec.size ();
00094   
00095   int max_idx = 0;
00096   
00097   for (int i = 1; i < N; i++)
00098     if (vec [i] > vec [max_idx])
00099       max_idx = i;
00100   
00101   return max_idx;
00102 }
00103 
00113 template <class T>
00114 inline
00115 T find_max (const std::vector<T> &vec)
00116 {
00117   return vec [find_max_idx (vec)];
00118 }
00119 
00129 inline
00130 double mod_2pi (const double dx)
00131 {
00132   const double dm = 2.0 * M_PI;
00133   if (dx < 0)
00134     return dm + dx + dm * floor (-dx/dm);
00135   else    
00136     return dx - dm * floor (dx/dm);
00137 }
00138 
00148 inline
00149 double mod_pi (const double dx)
00150 {
00151   const double dm = M_PI;
00152   if (dx < 0)
00153     return dm + dx + dm * floor (-dx/dm);
00154   else    
00155     return dx - dm * floor (dx/dm);
00156 }
00157 
00167 template <class T>
00168 inline
00169 T square (const T &a)
00170 {
00171   return a*a;
00172 }
00173 
00183 template <class T>
00184 inline
00185 double norm2 (const T &a)
00186 {
00187   return a*a;
00188 }
00189 
00199 template <class T>
00200 inline
00201 double norm (const T &a)
00202 {
00203   return sqrt (norm2 (a));
00204 }
00205 
00215 template <class T>
00216 inline
00217 T sign (const T &a)
00218 {
00219   if (a < 0)
00220     {
00221       return -1;
00222     }
00223   else if (a > 0)
00224     {
00225       return 1;
00226     }
00227   else
00228     {
00229       return 0;
00230     }
00231 }
00232 
00249 template<class T>
00250 inline
00251 T force_in_range (const T &val, const T &min_val, const T &max_val)
00252 {
00253   if (val > max_val)
00254     {
00255       return max_val;
00256     }
00257   else if (val < min_val)
00258     {
00259       return min_val;
00260     }
00261   else
00262     {
00263       return val;
00264     }
00265 } 
00266 
00282 inline
00283 vector3 project_point_on_line (const vector3 &p, const vector3 &l1, const vector3 &l2)
00284 {
00285   // XXX: This is a silly implementation
00286   const vector3 delta = l2 - l1;
00287   const double t = - ((l1 - p) * delta) / norm2 (delta);
00288   const vector3 retval = l1 + delta * t;
00289   
00290   return retval;
00291 }
00292 
00302 vector3 jet (const double x);
00303 
00313 vector3 hot (const double x);
00314 
00324 double bessi0 (double x);
00325 
00326 #endif // AUXIL_H

Generated on Thu Dec 1 2011 12:49:46 for HUMIM Tracker by  doxygen 1.7.1