Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef PCL_MACROS_H_
00038 #define PCL_MACROS_H_
00039
00040 #include <pcl/pcl_config.h>
00041 #include <boost/cstdint.hpp>
00042 #include <cstdlib>
00043
00044 namespace pcl
00045 {
00046 using boost::uint8_t;
00047 using boost::int8_t;
00048 using boost::int16_t;
00049 using boost::uint16_t;
00050 using boost::int32_t;
00051 using boost::uint32_t;
00052 using boost::int64_t;
00053 using boost::uint64_t;
00054 }
00055
00056 #if defined __INTEL_COMPILER
00057 #pragma warning disable 2196 2536 279
00058 #endif
00059
00060 #if defined _MSC_VER
00061 #pragma warning (disable: 4521 4251)
00062 #endif
00063
00064 #include <iostream>
00065 #include <stdarg.h>
00066 #include <stdio.h>
00067 #define _USE_MATH_DEFINES
00068 #include <math.h>
00069
00070
00071 #if defined _WIN32 && defined _MSC_VER
00072
00073
00074 #ifndef M_PI
00075
00076 # define M_PI 3.14159265358979323846 // pi
00077 # define M_PI_2 1.57079632679489661923 // pi/2
00078 # define M_PI_4 0.78539816339744830962 // pi/4
00079 # define M_PIl 3.1415926535897932384626433832795029L // pi
00080 # define M_PI_2l 1.5707963267948966192313216916397514L // pi/2
00081 # define M_PI_4l 0.7853981633974483096156608458198757L // pi/4
00082 #endif
00083
00084
00085 #ifndef NOMINMAX
00086 # define NOMINMAX
00087 #endif
00088
00089 # define pcl_isnan(x) _isnan(x)
00090 # define pcl_isfinite(x) (_finite(x) != 0)
00091 # define pcl_isinf(x) (_finite(x) == 0)
00092
00093 # define __PRETTY_FUNCTION__ __FUNCTION__
00094 # define __func__ __FUNCTION__
00095
00096 #elif ANDROID
00097
00098 # include <math.h>
00099 # define pcl_isnan(x) isnan(x)
00100 # define pcl_isfinite(x) isfinite(x)
00101 # define pcl_isinf(x) isinf(x)
00102
00103 #elif _GLIBCXX_USE_C99_MATH
00104
00105 # include <cmath>
00106 # define pcl_isnan(x) std::isnan(x)
00107 # define pcl_isfinite(x) std::isfinite(x)
00108 # define pcl_isinf(x) std::isinf(x)
00109
00110 #elif __PATHCC__
00111 # include <cmath>
00112 # include <stdio.h>
00113 template <typename T> int
00114 pcl_isnan (T &val)
00115 {
00116 return (val != val);
00117 }
00118
00119 # define pcl_isfinite(x) std::isfinite(x)
00120 # define pcl_isinf(x) std::isinf(x)
00121
00122 #else
00123
00124 # include <math.h>
00125 # define pcl_isnan(x) isnan(x)
00126 # define pcl_isfinite(x) isfinite(x)
00127 # define pcl_isinf(x) isinf(x)
00128
00129 #endif
00130
00131 #ifndef DEG2RAD
00132 #define DEG2RAD(x) ((x)*0.017453293)
00133 #endif
00134
00135 #ifndef RAD2DEG
00136 #define RAD2DEG(x) ((x)*57.29578)
00137 #endif
00138
00143 __inline double
00144 pcl_round (double number)
00145 {
00146 return (number < 0.0 ? ceil (number - 0.5) : floor (number + 0.5));
00147 }
00148 __inline float
00149 pcl_round (float number)
00150 {
00151 return (number < 0.0f ? ceilf (number - 0.5f) : floorf (number + 0.5f));
00152 }
00153
00154 #define pcl_lrint(x) (static_cast<long int>(pcl_round(x)))
00155 #define pcl_lrintf(x) (static_cast<long int>(pcl_round(x)))
00156
00157 #ifdef _WIN32
00158 __inline float
00159 log2f (float x)
00160 {
00161 return (static_cast<float> (logf (x) * M_LOG2E));
00162 }
00163 #endif
00164
00165 #ifdef WIN32
00166 #define pcl_sleep(x) Sleep(1000*(x))
00167 #else
00168 #define pcl_sleep(x) sleep(x)
00169 #endif
00170
00171 #ifndef PVAR
00172 #define PVAR(s) \
00173 #s << " = " << (s) << std::flush
00174 #endif
00175 #ifndef PVARN
00176 #define PVARN(s) \
00177 #s << " = " << (s) << "\n"
00178 #endif
00179 #ifndef PVARC
00180 #define PVARC(s) \
00181 #s << " = " << (s) << ", " << std::flush
00182 #endif
00183 #ifndef PVARS
00184 #define PVARS(s) \
00185 #s << " = " << (s) << " " << std::flush
00186 #endif
00187 #ifndef PVARA
00188 #define PVARA(s) \
00189 #s << " = " << RAD2DEG(s) << "deg" << std::flush
00190 #endif
00191 #ifndef PVARAN
00192 #define PVARAN(s) \
00193 #s << " = " << RAD2DEG(s) << "deg\n"
00194 #endif
00195 #ifndef PVARAC
00196 #define PVARAC(s) \
00197 #s << " = " << RAD2DEG(s) << "deg, " << std::flush
00198 #endif
00199 #ifndef PVARAS
00200 #define PVARAS(s) \
00201 #s << " = " << RAD2DEG(s) << "deg " << std::flush
00202 #endif
00203
00204 #define FIXED(s) \
00205 std::fixed << s << std::resetiosflags(std::ios_base::fixed)
00206
00207 #ifndef ERASE_STRUCT
00208 #define ERASE_STRUCT(var) memset(&var, 0, sizeof(var))
00209 #endif
00210
00211 #ifndef ERASE_ARRAY
00212 #define ERASE_ARRAY(var, size) memset(var, 0, size*sizeof(*var))
00213 #endif
00214
00215 #ifndef SET_ARRAY
00216 #define SET_ARRAY(var, value, size) { for (int i = 0; i < static_cast<int> (size); ++i) var[i]=value; }
00217 #endif
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 #ifndef PCL_EXTERN_C
00246 #ifdef __cplusplus
00247 #define PCL_EXTERN_C extern "C"
00248 #else
00249 #define PCL_EXTERN_C
00250 #endif
00251 #endif
00252
00253 #if defined WIN32 || defined _WIN32 || defined WINCE || defined __MINGW32__
00254 #ifdef PCLAPI_EXPORTS
00255 #define PCL_EXPORTS __declspec(dllexport)
00256 #else
00257 #define PCL_EXPORTS
00258 #endif
00259 #else
00260 #define PCL_EXPORTS
00261 #endif
00262
00263 #if defined WIN32 || defined _WIN32
00264 #define PCL_CDECL __cdecl
00265 #define PCL_STDCALL __stdcall
00266 #else
00267 #define PCL_CDECL
00268 #define PCL_STDCALL
00269 #endif
00270
00271 #ifndef PCLAPI
00272 #define PCLAPI(rettype) PCL_EXTERN_C PCL_EXPORTS rettype PCL_CDECL
00273 #endif
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 #ifdef __GNUC__
00285 #define GCC_VERSION (__GNUC__ * 10000 \
00286 + __GNUC_MINOR__ * 100 \
00287 + __GNUC_PATCHLEVEL__)
00288 #if GCC_VERSION < 40500
00289 #define PCL_DEPRECATED(func, message) func __attribute__ ((deprecated))
00290 #else
00291 #define PCL_DEPRECATED(func, message) func __attribute__ ((deprecated(message)))
00292 #endif
00293
00294 #elif defined(_MSC_VER)
00295 #define PCL_DEPRECATED(func, message) __declspec(deprecated(message)) func
00296 #else
00297 #pragma message("WARNING: You need to implement PCL_DEPRECATED for this compiler")
00298 #define PCL_DEPRECATED(func) func
00299 #endif
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 #ifdef __GNUC__
00319 #define GCC_VERSION (__GNUC__ * 10000 \
00320 + __GNUC_MINOR__ * 100 \
00321 + __GNUC_PATCHLEVEL__)
00322 #if GCC_VERSION < 40500
00323 #define PCL_DEPRECATED_CLASS(func, message) __attribute__ ((deprecated)) func
00324 #else
00325 #define PCL_DEPRECATED_CLASS(func, message) __attribute__ ((deprecated(message))) func
00326 #endif
00327
00328 #elif defined(_MSC_VER)
00329 #define PCL_DEPRECATED_CLASS(func, message) __declspec(deprecated(message)) func
00330 #else
00331 #pragma message("WARNING: You need to implement PCL_DEPRECATED for this compiler")
00332 #define PCL_DEPRECATED_CLASS(func) func
00333 #endif
00334
00335 #if defined (__GNUC__) || defined (__PGI) || defined (__IBMCPP__) || defined (__SUNPRO_CC)
00336 #define PCL_ALIGN(alignment) __attribute__((aligned(alignment)))
00337 #elif defined (_MSC_VER)
00338 #define PCL_ALIGN(alignment) __declspec(align(alignment))
00339 #else
00340 #error Alignment not supported on your platform
00341 #endif
00342
00343 #if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \
00344 && defined(__LP64__)
00345 #define GLIBC_MALLOC_ALIGNED 1
00346 #else
00347 #define GLIBC_MALLOC_ALIGNED 0
00348 #endif
00349
00350 #if defined(__FreeBSD__) && !defined(__arm__) && !defined(__mips__)
00351 #define FREEBSD_MALLOC_ALIGNED 1
00352 #else
00353 #define FREEBSD_MALLOC_ALIGNED 0
00354 #endif
00355
00356 #if defined(__APPLE__) || defined(_WIN64) || GLIBC_MALLOC_ALIGNED || FREEBSD_MALLOC_ALIGNED
00357 #define MALLOC_ALIGNED 1
00358 #else
00359 #define MALLOC_ALIGNED 0
00360 #endif
00361
00362 inline void*
00363 aligned_malloc (size_t size)
00364 {
00365 void *ptr;
00366 #if defined (MALLOC_ALIGNED)
00367 ptr = std::malloc (size);
00368 #elif defined (HAVE_POSIX_MEMALIGN)
00369 if (posix_memalign (&ptr, 16, size))
00370 ptr = 0;
00371 #elif defined (HAVE_MM_MALLOC)
00372 ptr = _mm_malloc (size, 16);
00373 #elif defined (_MSC_VER)
00374 ptr = _aligned_malloc (size, 16);
00375 #else
00376 #error aligned_malloc not supported on your platform
00377 ptr = 0;
00378 #endif
00379 return (ptr);
00380 }
00381
00382 inline void
00383 aligned_free (void* ptr)
00384 {
00385 #if defined (MALLOC_ALIGNED) || defined (HAVE_POSIX_MEMALIGN)
00386 std::free (ptr);
00387 #elif defined (HAVE_MM_MALLOC)
00388 ptr = _mm_free (ptr);
00389 #elif defined (_MSC_VER)
00390 _aligned_free (ptr);
00391 #else
00392 #error aligned_free not supported on your platform
00393 #endif
00394 }
00395
00396 #endif //#ifndef PCL_MACROS_H_