GestureRecognitionToolkit  Version: 0.2.5
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 #ifdef __GRT_WINDOWS_BUILD__
37 #define NOMINMAX
38 #include <windows.h>
39 #endif
40 
41 #define GRT_BEGIN_NAMESPACE namespace GRT {
42 #define GRT_END_NAMESPACE }
43 
44 GRT_BEGIN_NAMESPACE
45 
46 //Define any common GRT OS independent typedefs
47 typedef double Float;
48 typedef long double LongFloat;
49 
50 //Declare any common definitions that are not OS specific
51 #ifndef PI
52 #define PI 3.14159265358979323846264338327950288
53 #endif
54 
55 #ifndef TWO_PI
56 #define TWO_PI 6.28318530718
57 #endif
58 
59 #ifndef ONE_OVER_TWO_PI
60 #define ONE_OVER_TWO_PI (1.0/TWO_PI)
61 #endif
62 
63 #ifndef SQRT_TWO_PI
64 #define SQRT_TWO_PI 2.506628274631
65 #endif
66 
67 template<class T> inline T SQR(const T &a) {return a*a;}
68 template<class T> inline void SWAP(T &a,T &b) { T temp(a); a = b; b = temp; }
69 template<class T> inline T SIGN(const T &a, const T &b) {return (b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a));}
70 
71 template<class T> inline void grt_swap(T &a,T &b) { T temp(a); a = b; b = temp; }
72 
73 template< class T >
75 public:
76  static T min() { return std::numeric_limits< T >::min(); }
77  static T max() { return std::numeric_limits< T >::max(); }
78 };
79 
80 inline Float grt_sqr( const Float &x ){ return x*x; }
81 
82 inline Float grt_sqrt( const Float &x ){ return sqrt(x); }
83 
84 inline Float grt_antilog( const Float &x ){ return exp( x ); }
85 
86 inline Float grt_exp( const Float &x ){ return exp( x ); }
87 
88 inline Float grt_log( const Float &x ){ return log( x ); }
89 
90 inline Float grt_sigmoid( const Float &x ) { return 1.0 / (1.0 + exp(-x)); }
91 
92 template< class T >
93 T grt_scale(const T &x,const T &minSource,const T &maxSource,const T &minTarget,const T &maxTarget,const bool constrain = false){
94  if( constrain ){
95  if( x <= minSource ) return minTarget;
96  if( x >= maxSource ) return maxTarget;
97  }
98  if( minSource == maxSource ) return minTarget;
99  return (((x-minSource)*(maxTarget-minTarget))/(maxSource-minSource))+minTarget;
100 }
101 
102 template< class T >
103 std::string grt_to_str( const T &value ){
104  std::ostringstream s;
105  s << value;
106  return s.str();
107 }
108 
109 template< class T >
110 T grt_from_str( const std::string &str ){
111  std::stringstream s( str );
112  T i;
113  s >> i;
114  return i;
115 }
116 
117 #define grt_min(a,b) (((a)<(b))?(a):(b))
118 #define grt_max(a,b) (((a)>(b))?(a):(b))
119 
120 #define GRT_DEFAULT_NULL_CLASS_LABEL 0
121 #define GRT_SAFE_CHECKING true
122 
123 //No need for this on non-Windows platforms, but
124 //must have an empty definition.
125 #define GRT_API
126 
127 //Specific defines for Windows
128 #ifdef __GRT_WINDOWS_BUILD__
129 #define grt_isnan(x) (x != x)
130 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
131 
132 //NAN is not defined on Visual Studio version of math.h so define it here
133 #ifndef NAN
134 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
135 #define NAN (*(const float *) __nan)
136 #endif
137 
138 #ifndef INFINITY
139 #define INFINITY (DBL_MAX+DBL_MAX)
140 #endif
141 
142 //Remove the min and max macros as they cause lots of issues
143 #ifndef NOMINMAX
144 #define NOMINMAX
145 #endif
146 
147 //Allow DLL exports.
148 #if !defined(GRT_STATIC_LIB) && defined(_MSC_VER)
149  #undef GRT_API
150  #ifdef GRT_DLL_EXPORTS
151  #define GRT_API __declspec(dllexport)
152  #else // GRT_DLL_EXPORTS
153  #define GRT_API __declspec(dllimport)
154  #endif // GRT_DLL_EXPORTS
155 
156  //disable warnings about a "dllexport" class using a regular class
157  # pragma warning(disable: 4251)
158 #endif // !GRT_STATIC_LIB && MSC_VER
159 
160 #endif
161 
162 //Specific defines for OSX
163 #ifdef __GRT_OSX_BUILD__
164 #define grt_isnan(x) (x != x)
165 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
166 
167 typedef unsigned int UINT;
168 typedef signed int SINT;
169 typedef unsigned long ULONG;
170 #endif
171 
172 //Specific defines for Linux
173 #ifdef __GRT_LINUX_BUILD__
174 #define grt_isnan(x) (x != x)
175 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
176 
177 typedef unsigned int UINT;
178 typedef signed int SINT;
179 typedef unsigned long ULONG;
180 #endif
181 
182 // Cross-platform deprecation warning, based on openFrameworks OF_DEPRECATED
183 #ifdef __GNUC__
184 // clang also has this defined. deprecated(message) is only for gcc>=4.5
185 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 5)
186 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated(message)))
187 #else
188 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated))
189 #endif
190 #define GRT_DEPRECATED(func) func __attribute__ ((deprecated))
191 #elif defined(_MSC_VER)
192 #define GRT_DEPRECATED_MSG(message, func) __declspec(deprecated(message)) func
193 #define GRT_DEPRECATED(func) __declspec(deprecated) func
194 #else
195 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
196 #define GRT_DEPRECATED_MSG(message, func) func
197 #define GRT_DEPRECATED(func) func
198 #endif
199 
203 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
204 
208 #define __GRT_LOG__ (std::string(__FILENAME__) + std::string(" ") + std::string(__FUNCTION__) + std::string(":") + grt_to_str(__LINE__))
209 
213 #define grt_print_str(x) (#x)
214 
215 #if !defined NDEBUG
216 
219 #if defined(_MSC_VER) && _MSC_VER <= 1800
220 //Use __FUNCTION__ instead of __func__ for Visual Studio 2013 & earlier
221 #define grt_assert(x) \
222 do { \
223 if (0 == (x)) { \
224 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __FUNCTION__, __LINE__, grt_print_str(x) ); \
225 abort(); \
226 } \
227 } while (0)
228 #else // _MSC_VER <= 1800
229 #define grt_assert(x) \
230 do { \
231 if (0 == (x)) { \
232 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __func__, __LINE__, grt_print_str(x) ); \
233 abort(); \
234 } \
235 } while (0)
236 #endif // _MSC_VER <= 1800
237 #else // !NDEBUG
238 #define grt_assert(x)
239 #endif // !NDEBUG
240 
241 //Declare typedefs for the legacy data types
242 class ClassificationData;
244 class RegressionData;
246 class UnlabelledData;
247 class VectorFloat;
248 class MatrixFloat;
254 typedef VectorFloat VectorDouble;
255 typedef MatrixFloat MatrixDouble;
256 
257 GRT_END_NAMESPACE
258 
259 #endif //GRT_TYPEDEFS_HEADER