base.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 Revision 1.21  2007/01/08 09:23:49  pietroni
00028 added explicit cast in function inline float Sqrt(const int v) in order to avoid warnings
00029 
00030 Revision 1.20  2006/10/13 13:14:50  cignoni
00031 Added two sqrt templates for resolving ambiguity of sqrt(int)
00032 
00033 Revision 1.19  2005/12/01 01:03:37  cignoni
00034 Removed excess ';' from end of template functions, for gcc compiling
00035 
00036 Revision 1.18  2004/08/31 15:42:59  fasano
00037 Aggiunte macro sin/cos/atan per C++ Builder
00038 
00039 Revision 1.17  2004/05/10 13:00:14  ganovelli
00040 limits function cancelled
00041 
00042 Revision 1.16  2004/05/03 08:38:08  ganovelli
00043 correction on templates
00044 
00045 Revision 1.15  2004/04/15 09:36:59  ganovelli
00046  Min and Max changed from const members to static class function
00047 Use: Value<float>::Min()
00048 
00049 Revision 1.14  2004/03/31 12:41:55  tarini
00050 debugged Max and Min const values (to make them linkable)
00051 
00052 Revision 1.13  2004/03/31 10:09:19  cignoni
00053 int64 -> long long for GCC compatibility
00054 
00055 Revision 1.12  2004/03/16 00:23:50  tarini
00056 - added VoidType    - added "static_assert"
00057 
00058 Revision 1.11  2004/03/10 17:37:54  tarini
00059 Added Atan2.
00060 Added common utilities: Max, Min, Swap, Sort(a,b), Sort(a,b,c).
00061 Changed Max values syntax. example:  Value<float>::Max
00062 
00063 Revision 1.10  2004/03/10 16:54:57  tarini
00064 Added Atan2.
00065 Added common utilities: Max, Min, Swap, Sort(a,b), Sort(a,b,c).
00066 Changed Max values syntax. example:  Value<float>::Max
00067 
00068 Revision 1.7  2004/03/08 19:38:29  tarini
00069 Added Min e Max. usage: Min<float>::Value (tarini)
00070 
00071 Revision 1.6  2004/03/08 14:49:37  ponchio
00072 Aggiunti un po di inline davanti alle funzioni
00073 
00074 Revision 1.5  2004/03/04 00:21:00  ponchio
00075 added Acos e Asin
00076 
00077 Revision 1.4  2004/03/03 22:51:49  cignoni
00078 changed math from class to template
00079 
00080 Revision 1.2  2004/02/13 02:18:57  cignoni
00081 Edited Comments and GPL license
00082 
00083 
00084 ****************************************************************************/
00085 
00086 #ifndef __VCGLIB_MATH_BASE
00087 #define __VCGLIB_MATH_BASE
00088 
00089 #include <float.h>
00090 #include <math.h>
00091 #include <assert.h>
00092 #include <limits>
00093 #include <algorithm>
00094 
00095 
00096   #ifdef __BORLANDC__
00097     float sqrtf (float v) {return sqrt(v);}
00098     float fabsf (float v) {return fabs(v);}
00099     float cosf  (float v) {return cos(v);}
00100     float sinf  (float v) {return sin(v);}
00101     float acosf  (float v) {return acos(v);}
00102     float asinf  (float v) {return asin(v);}
00103     float atan2f (float v0, float v1) {return atan2(v0,v1);}
00104   #endif
00105 
00106 namespace vcg {
00107 
00108 namespace math {
00109 
00110  template <class SCALAR>
00111  class MagnitudoComparer
00112     {
00113       public:
00114         inline bool operator() ( const SCALAR a, const SCALAR b ) { return fabs(a)>fabs(b);  }
00115     };
00116 
00117   inline float Sqrt(const short v)   { return sqrtf(v); }
00118   inline float Sqrt(const int v)   { return sqrtf((float)v); }
00119 
00120   inline float Sqrt(const float v)   { return sqrtf(v); }
00121   inline float Abs(const float v)   { return fabsf(v); }
00122   inline float Cos(const float v)   { return cosf(v); }
00123   inline float Sin(const float v)   { return sinf(v); }
00124   inline float Acos(const float v)   { return acosf(v); }
00125   inline float Asin(const float v)   { return asinf(v); }
00126   inline float Atan2(const float v0,const float v1)   { return atan2f(v0,v1); }
00127 
00128   inline double Sqrt(const double v)   { return sqrt(v); }
00129   inline double Abs(const double v)   { return fabs(v); }
00130   inline double Cos(const double v)   { return cos(v); }
00131   inline double Sin(const double v)   { return sin(v); }
00132   inline double Acos(const double v)   { return acos(v); }
00133   inline double Asin(const double v)   { return asin(v); }
00134   inline double Atan2(const double v0,const double v1)   { return atan2(v0,v1); }
00135 
00136     template <typename T> inline static T Sqr(T a) { return a*a; }
00137 
00138   template<class T> inline const T & Min(const T &a, const T &b,const T &c){
00139     if (a<b) {
00140       if(a<c) return a;
00141          else return c;
00142       } else {
00143       if(b<c) return b;
00144       else return c;
00145       }
00146     }
00147   template<class T> inline const T & Max(const T &a, const T &b, const T &c){
00148     if (a>b) {
00149       if(a>c) return a;
00150          else return c; // if c<a then c is smaller than b...
00151       } else {
00152       if(b>c) return b;
00153       else return c;
00154       }
00155   }
00156 
00157         template<class T> inline void Sort(T &a, T &b){
00158                 if (a>b) std::swap(a,b);
00159         }
00160         template<class T> inline void Sort(T &a, T &b, T &c){
00161                 if (a>b) std::swap(a,b);
00162                 if (b>c) {std::swap(b,c); if (a>b) std::swap(a,b);}
00163         }
00164 
00165 /* Some <math.h> files do not define M_PI... */
00166 #ifndef M_PI
00167 #define M_PI 3.14159265358979323846
00168 #endif
00169 
00170 #ifndef SQRT_TWO
00171 #define SQRT_TWO 1.4142135623730950488
00172 #endif
00173 
00174 template <class SCALAR>
00175 inline SCALAR  Clamp( const SCALAR & val, const SCALAR& minval, const SCALAR& maxval)
00176 {
00177         if(val < minval) return minval;
00178         if(val > maxval) return maxval;
00179         return val;
00180 }
00181 
00182 
00183 
00184 inline float   ToDeg(const float &a){return a*180.0f/float(M_PI);}
00185 inline float   ToRad(const float &a){return float(M_PI)*a/180.0f;}
00186 inline double  ToDeg(const double &a){return a*180.0/M_PI;}
00187 inline double  ToRad(const double &a){return M_PI*a/180.0;}
00188 
00189 template <typename T>
00190 int Sgn(T val) {
00191     return (T(0) < val) - (val < T(0));
00192 }
00193 
00194 #if defined(_MSC_VER) // Microsoft Visual C++
00195 template<class T> int IsNAN(T t) {    return _isnan(t) || (!_finite(t)); }
00196 #elif defined(__MINGW32__) // GCC
00197 template<class T> int IsNAN(T t) {    return std::isnan(t) || std::isinf(t); }
00198 #elif defined(__GNUC__) // GCC
00199 template<class T> int IsNAN(T t) {    return isnan(t) || isinf(t); }
00200 #else // generic
00201 
00202 template<class T> int IsNAN(T t)
00203 {
00204      if(std::numeric_limits<T>::has_infinity)
00205          return !(t <= std::numeric_limits<T>::infinity());
00206      else
00207          return t != t;
00208 }
00209 
00210 #endif
00211 }       // End math namespace
00212 
00214 class VoidType{ public:
00215     VoidType(){};
00216 };
00217 
00218 }       // End vcg namespace
00219 
00220 
00221 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:29:07