|
Point Cloud Library (PCL)
1.6.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 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 // MSCV doesn't have std::{isnan,isfinite} 00071 #if defined _WIN32 && defined _MSC_VER 00072 00073 // If M_PI is not defined, then probably all of them are undefined 00074 #ifndef M_PI 00075 // Copied from math.h 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 // Stupid. This should be removed when all the PCL dependencies have min/max fixed. 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 // Use the math.h macros 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 // Are the C++ cmath functions enabled? 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 //# define pcl_isnan(x) std::isnan(x) 00119 # define pcl_isfinite(x) std::isfinite(x) 00120 # define pcl_isinf(x) std::isinf(x) 00121 00122 #else 00123 // Use the math.h macros 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 /* //This is copy/paste from http://gcc.gnu.org/wiki/Visibility */ 00220 /* #if defined _WIN32 || defined __CYGWIN__ */ 00221 /* #ifdef BUILDING_DLL */ 00222 /* #ifdef __GNUC__ */ 00223 /* #define DLL_PUBLIC __attribute__((dllexport)) */ 00224 /* #else */ 00225 /* #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. */ 00226 /* #endif */ 00227 /* #else */ 00228 /* #ifdef __GNUC__ */ 00229 /* #define DLL_PUBLIC __attribute__((dllimport)) */ 00230 /* #else */ 00231 /* #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. */ 00232 /* #endif */ 00233 /* #endif */ 00234 /* #define DLL_LOCAL */ 00235 /* #else */ 00236 /* #if __GNUC__ >= 4 */ 00237 /* #define DLL_PUBLIC __attribute__ ((visibility("default"))) */ 00238 /* #define DLL_LOCAL __attribute__ ((visibility("hidden"))) */ 00239 /* #else */ 00240 /* #define DLL_PUBLIC */ 00241 /* #define DLL_LOCAL */ 00242 /* #endif */ 00243 /* #endif */ 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 // Macro to deprecate old functions 00276 // 00277 // Usage: 00278 // don't use me any more 00279 // PCL_DEPRECATED(void OldFunc(int a, float b), "Use newFunc instead, this functions will be gone in the next major release"); 00280 // use me instead 00281 // void NewFunc(int a, double b); 00282 00283 // gcc supports this starting from 4.5 : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43666 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 // Macro to deprecate old classes/structs 00302 // 00303 // Usage: 00304 // don't use me any more 00305 // class PCL_DEPRECATED_CLASS(OldClass, "Use newClass instead, this class will be gone in the next major release") 00306 // { 00307 // public: 00308 // OldClass() {} 00309 // }; 00310 // use me instead 00311 // class NewFunc 00312 // { 00313 // public: 00314 // NewClass() {} 00315 // }; 00316 00317 // gcc supports this starting from 4.5 : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43666 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_
1.7.6.1