GestureRecognitionToolkit  Version: 0.1.0
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
GRTTypedefs.h
1 /*
2 GRT MIT License
3 Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6 and associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all copies or substantial
12 portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
20 
21 #ifndef GRT_TYPEDEFS_HEADER
22 #define GRT_TYPEDEFS_HEADER
23 
24 #include "GRTVersionInfo.h"
25 #include <iostream>
26 #include <iterator> // std::front_inserter
27 #include <vector>
28 #include <algorithm> // std::copy
29 #include <fstream>
30 #include <sstream>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <limits>
34 #include <cmath>
35 
36 #define GRT_BEGIN_NAMESPACE namespace GRT {
37 #define GRT_END_NAMESPACE }
38 
39 GRT_BEGIN_NAMESPACE
40 
41 //Define any common GRT OS independent typedefs
42 typedef double Float;
43 typedef long double LongFloat;
44 
45 //Declare any common definitions that are not OS specific
46 #ifndef PI
47 #define PI 3.14159265358979323846264338327950288
48 #endif
49 
50 #ifndef TWO_PI
51 #define TWO_PI 6.28318530718
52 #endif
53 
54 #ifndef SQRT_TWO_PI
55 #define SQRT_TWO_PI 2.506628274631
56 #endif
57 
58 template<class T> inline T SQR(const T &a) {return a*a;}
59 template<class T> inline void SWAP(T &a,T &b) { T temp(a); a = b; b = temp; }
60 template<class T> inline T SIGN(const T &a, const T &b) {return (b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a));}
61 
62 template<class T> inline void grt_swap(T &a,T &b) { T temp(a); a = b; b = temp; }
63 
64 template< class T >
66 public:
67  static T min() { return std::numeric_limits< T >::min(); }
68  static T max() { return std::numeric_limits< T >::max(); }
69 };
70 
71 inline Float grt_sqr( const Float &x ){ return x*x; }
72 
73 inline Float grt_sqrt( const Float &x ){ return sqrt(x); }
74 
75 inline Float grt_antilog( const Float &x ){ return exp( x ); }
76 
77 inline Float grt_exp( const Float &x ){ return exp( x ); }
78 
79 inline Float grt_log( const Float &x ){ return log( x ); }
80 
81 inline Float grt_sigmoid( const Float &x ) { return 1.0 / (1.0 + exp(-x)); }
82 
83 template< class T >
84 T grt_scale(const T &x,const T &minSource,const T &maxSource,const T &minTarget,const T &maxTarget,const bool constrain = false){
85  if( constrain ){
86  if( x <= minSource ) return minTarget;
87  if( x >= maxSource ) return maxTarget;
88  }
89  if( minSource == maxSource ) return minTarget;
90  return (((x-minSource)*(maxTarget-minTarget))/(maxSource-minSource))+minTarget;
91 }
92 
93 template< class T >
94 std::string grt_to_str( const T &value ){
95  std::stringstream s;
96  s << value;
97  return s.str();
98 }
99 
100 template< class T >
101 T grt_from_str( const std::string &str ){
102  std::stringstream s( str );
103  T i;
104  s >> i;
105  return i;
106 }
107 
108 #define grt_min(a,b) (((a)<(b))?(a):(b))
109 #define grt_max(a,b) (((a)>(b))?(a):(b))
110 
111 #ifndef MIN
112 #define MIN(a,b) (((a)<(b))?(a):(b))
113 #endif
114 #ifndef MAX
115 #define MAX(a,b) (((a)>(b))?(a):(b))
116 #endif
117 
118 #define GRT_DEFAULT_NULL_CLASS_LABEL 0
119 #define GRT_SAFE_CHECKING true
120 
121 //Specific defines for Windows
122 #ifdef __GRT_WINDOWS_BUILD__
123 #define grt_isnan(x) (x != x)
124 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
125 
126 //NAN is not defined on Visual Studio version of math.h so define it here
127 #ifndef NAN
128 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
129 #define NAN (*(const float *) __nan)
130 #endif
131 
132 #ifndef INFINITY
133 #define INFINITY (DBL_MAX+DBL_MAX)
134 #endif
135 
136 //Remove the min and max macros as they cause lots of issues
137 #ifndef NOMINMAX
138 #define NOMINMAX
139 #endif
140 
141 #endif
142 
143 //Specific defines for OSX
144 #ifdef __GRT_OSX_BUILD__
145 #define grt_isnan(x) (x != x)
146 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
147 
148 typedef unsigned int UINT;
149 typedef signed int SINT;
150 typedef unsigned long ULONG;
151 #endif
152 
153 //Specific defines for Linux
154 #ifdef __GRT_LINUX_BUILD__
155 #define grt_isnan(x) (x != x)
156 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
157 
158 typedef unsigned int UINT;
159 typedef signed int SINT;
160 typedef unsigned long ULONG;
161 #endif
162 
163 // Cross-platform deprecation warning, based on openFrameworks OF_DEPRECATED
164 #ifdef __GNUC__
165 // clang also has this defined. deprecated(message) is only for gcc>=4.5
166 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 5)
167 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated(message)))
168 #else
169 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated))
170 #endif
171 #define GRT_DEPRECATED(func) func __attribute__ ((deprecated))
172 #elif defined(_MSC_VER)
173 #define GRT_DEPRECATED_MSG(message, func) __declspec(deprecated(message)) func
174 #define GRT_DEPRECATED(func) __declspec(deprecated) func
175 #else
176 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
177 #define GRT_DEPRECATED_MSG(message, func) func
178 #define GRT_DEPRECATED(func) func
179 #endif
180 
184 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
185 
189 #define grt_to_str(x) (#x)
190 
191 #if !defined NDEBUG
192 
195 #define grt_assert(x) \
196 do { \
197 if (0 == (x)) { \
198 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __func__, __LINE__, grt_to_str(x) ); \
199 abort(); \
200 } \
201 } while (0)
202 #else
203 #define grt_assert(x)
204 #endif
205 
206 //Declare typedefs for the legacy data types
207 class ClassificationData;
209 class RegressionData;
211 class UnlabelledData;
212 class VectorFloat;
213 class MatrixFloat;
219 typedef VectorFloat VectorDouble;
220 typedef MatrixFloat MatrixDouble;
221 
222 GRT_END_NAMESPACE
223 
224 #endif //GRT_TYPEDEFS_HEADER