Orfeo Toolbox  4.0
otbMath.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 
19 #ifndef __otbMath_h
20 #define __otbMath_h
21 
28 #include "vcl_cmath.h"
29 
30 namespace otb {
31 
32 // For Windows MSVC, defines these macros.
33 #ifdef _USE_MATH_DEFINES
34 #define _MATH_DEFINES_DEFINED
35 #endif
36 
39 /* Some useful constants. */
40 const double CONST_E = 2.7182818284590452354; /* e */
41 const double CONST_LOG2E = 1.4426950408889634074; /* log_2 e */
42 const double CONST_LOG10E = 0.43429448190325182765; /* log_10 e */
43 const double CONST_LN2 = 0.69314718055994530942; /* log_e 2 */
44 const double CONST_LN10 = 2.30258509299404568402; /* log_e 10 */
45 const double CONST_PI = 3.14159265358979323846; /* pi */
46 const double CONST_PI_2 = 1.57079632679489661923; /* pi/2 */
47 const double CONST_PI_4 = 0.78539816339744830962; /* pi/4 */
48 const double CONST_PI_8 = 0.39269908169872415481; /* pi/8 */
49 const double CONST_1_PI = 0.31830988618379067154; /* 1/pi */
50 const double CONST_2_PI = 0.63661977236758134308; /* 2/pi */
51 const double CONST_2PI = 6.28318530717958647693; /* 2*pi */
52 const double CONST_PI_180 = 0.01745329251994329577; /* pi/180 */
53 const double CONST_180_PI = 57.2957795130823208768; /* 180/pi */
54 const double CONST_LNPI = std::log(CONST_PI); /* ln(pi)*/
55 const double CONST_SQRTPI = std::sqrt(CONST_PI); /* sqrt(pi)*/
56 const double CONST_2_SQRTPI = 1.12837916709551257390; /* 2/sqrt(pi) */
57 const double CONST_SQRT2 = 1.41421356237309504880; /* sqrt(2) */
58 const double CONST_SQRT1_2 = 0.70710678118654752440; /* 1/sqrt(2) */
59 const double CONST_SQRT3 = 1.73205080756887729353; /* sqrt(3) */
60 const double CONST_EULER = 0.57721566490153286060; /* euler constant*/
61 
62 /* The above constants are not adequate for computation using `long double's.
63  Therefore we provide as an extension constants with similar names as a
64  GNU extension. Provide enough digits for the 128-bit IEEE quad. */
65 #ifdef __USE_GNU
66 
67 const long double CONST_El = 2.7182818284590452353602874713526625L; /* e */
68 const long double CONST_LOG2El = 1.4426950408889634073599246810018921L; /* log_2 e */
69 const long double CONST_LOG10El = 0.4342944819032518276511289189166051L; /* log_10 e */
70 const long double CONST_LN2l = 0.6931471805599453094172321214581766L; /* log_e 2 */
71 const long double CONST_LN10l = 2.3025850929940456840179914546843642L; /* log_e 10 */
72 const long double CONST_PIl = 3.1415926535897932384626433832795029L; /* pi */
73 const long double CONST_PI_2l = 1.5707963267948966192313216916397514L; /* pi/2 */
74 const long double CONST_PI_4l = 0.7853981633974483096156608458198757L; /* pi/4 */
75 const long double CONST_PI_8l = 0.3926990816987241548078304229099379L; /* pi/8 */
76 const long double CONST_2_PIl = 0.6366197723675813430755350534900574L; /* 2/pi */
77 const long double CONST_2_SQRTPIl = 1.1283791670955125738961589031215452L; /* 2/sqrt(pi) */
78 const long double CONST_2PIl = 6.2831853071795864769252867665590058L; /* 2*pi */
79 const long double CONST_PI_180l = 0.0174532925199432957692369076848861L; /* pi/180 */
80 const long double CONST_180_PIl = 57.295779513082320876798154814105170L; /* 180/pi */
81 const long double CONST_LNPIl = std::log(CONST_PIl); /* ln(pi)*/
82 const long double CONST_SQRTPIl = std::sqrt(CONST_PIl); /* sqrt(pi)*/
83 const long double CONST_SQRT2l = 1.4142135623730950488016887242096981L; /* sqrt(2) */
84 const long double CONST_SQRT1_2l = 0.7071067811865475244008443621048490L; /* 1/sqrt(2) */
85 const long double CONST_SQRT3l = 1.7320508075688772935274463415058724L; /* sqrt(3) */
86 const long double CONST_EULERl = 0.5772156649015328606065120900824024L; /* euler constant*/
87 
88 #endif
89 
90 template <typename T> T InverseValue(const T & value)
91 {
92  return ((value > 0 || value > 0) ? 1/value : 0);
93 }
94 
95 template <typename T> T SignOfValue(const T & value)
96 {
97  return (value > 0) ? 1 : ((value < 0) ? -1 : 0);
98 }
99 
100 }
101 
102 #endif

Generated at Sat Mar 8 2014 16:06:54 for Orfeo Toolbox with doxygen 1.8.3.1