GestureRecognitionToolkit  Version: 0.2.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 #ifdef __GRT_WINDOWS_BUILD__
37 
38 #define NOMINMAX
39 
40 #include <windows.h>
41 
42 #endif
43 
44 
45 #define GRT_BEGIN_NAMESPACE namespace GRT {
46 #define GRT_END_NAMESPACE }
47 
48 GRT_BEGIN_NAMESPACE
49 
50 //Define any common GRT OS independent typedefs
51 typedef double Float;
52 typedef long double LongFloat;
53 
54 //Declare any common definitions that are not OS specific
55 #ifndef PI
56 #define PI 3.14159265358979323846264338327950288
57 #endif
58 
59 #ifndef TWO_PI
60 #define TWO_PI 6.28318530718
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::stringstream 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_to_str(x) (#x)
209 
210 #if !defined NDEBUG
211 
214 #if defined(_MSC_VER) && _MSC_VER <= 1800
215 //Use __FUNCTION__ instead of __func__ for Visual Studio 2013 & earlier
216 #define grt_assert(x) \
217 do { \
218 if (0 == (x)) { \
219 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __FUNCTION__, __LINE__, grt_to_str(x) ); \
220 abort(); \
221 } \
222 } while (0)
223 #else // _MSC_VER <= 1800
224 #define grt_assert(x) \
225 do { \
226 if (0 == (x)) { \
227 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __func__, __LINE__, grt_to_str(x) ); \
228 abort(); \
229 } \
230 } while (0)
231 #endif // _MSC_VER <= 1800
232 #else // !NDEBUG
233 #define grt_assert(x)
234 #endif // !NDEBUG
235 
236 //Declare typedefs for the legacy data types
237 class ClassificationData;
239 class RegressionData;
241 class UnlabelledData;
242 class VectorFloat;
243 class MatrixFloat;
249 typedef VectorFloat VectorDouble;
250 typedef MatrixFloat MatrixDouble;
251 
252 GRT_END_NAMESPACE
253 
254 #endif //GRT_TYPEDEFS_HEADER