Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
pcl_macros.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #ifndef PCL_MACROS_H_
00036 #define PCL_MACROS_H_
00037 
00038 #include <pcl/pcl_config.h>
00039 #include <boost/cstdint.hpp>
00040 #include <cstdlib>
00041 
00042 namespace pcl
00043 {
00044   using boost::uint8_t;
00045   using boost::int8_t;
00046   using boost::int16_t;
00047   using boost::uint16_t;
00048   using boost::int32_t;
00049   using boost::uint32_t;
00050   using boost::int64_t;
00051   using boost::uint64_t;
00052 }
00053 
00054 #if defined __INTEL_COMPILER
00055   #pragma warning disable 2196 2536 279
00056 #endif
00057 
00058 #if defined _MSC_VER
00059   #pragma warning (disable: 4521 4251)
00060 #endif
00061 
00062 #include <iostream>
00063 #include <stdarg.h>
00064 #include <stdio.h>
00065 
00066 // MSCV doesn't have std::{isnan,isfinite}
00067 #if defined _WIN32 && defined _MSC_VER
00068 
00069 // Stupid. This should be removed when all the PCL dependencies have min/max fixed.
00070 #ifndef NOMINMAX
00071 # define NOMINMAX
00072 #endif
00073 
00074 # define pcl_isnan(x)    _isnan(x)
00075 # define pcl_isfinite(x) (_finite(x) != 0)
00076 # define pcl_isinf(x)    (_finite(x) == 0)
00077 
00078 # define __PRETTY_FUNCTION__ __FUNCTION__
00079 # define __func__ __FUNCTION__
00080 
00081 #elif ANDROID
00082 // Use the math.h macros
00083 # include <math.h>
00084 # define pcl_isnan(x)    isnan(x)
00085 # define pcl_isfinite(x) isfinite(x)
00086 # define pcl_isinf(x)    isinf(x)
00087 
00088 #elif _GLIBCXX_USE_C99_MATH
00089 // Are the C++ cmath functions enabled?
00090 # include <cmath>
00091 # define pcl_isnan(x)    std::isnan(x)
00092 # define pcl_isfinite(x) std::isfinite(x)
00093 # define pcl_isinf(x)    std::isinf(x)
00094 
00095 #elif __PATHCC__
00096 # include <cmath>
00097 # include <stdio.h>
00098 template <typename T> int
00099 pcl_isnan (T &val)
00100 {
00101   return (val != val);
00102 }
00103 //# define pcl_isnan(x)    std::isnan(x)
00104 # define pcl_isfinite(x) std::isfinite(x)
00105 # define pcl_isinf(x)    std::isinf(x)
00106 
00107 #else
00108 // Use the math.h macros
00109 # include <math.h>
00110 # define pcl_isnan(x)    isnan(x)
00111 # define pcl_isfinite(x) isfinite(x)
00112 # define pcl_isinf(x)    isinf(x)
00113 
00114 #endif
00115 
00116 // Windows doesn't like M_PI.
00117 #ifndef M_PI
00118 #define M_PI 3.14159265358979323846
00119 #endif
00120 
00121 #ifndef M_PI_4
00122 #define M_PI_4 0.785398163397448309616
00123 #endif
00124 
00125 #ifndef M_E
00126 #define M_E 2.7182818284590452354
00127 #endif
00128 
00129 #ifndef M_LN2
00130 #define M_LN2 0.693147180559945309417
00131 #endif
00132 
00133 #ifndef DEG2RAD
00134 #define DEG2RAD(x) ((x)*0.017453293)
00135 #endif
00136 
00137 #ifndef RAD2DEG
00138 #define RAD2DEG(x) ((x)*57.29578)
00139 #endif
00140 
00144 #include <math.h>
00145 __inline double
00146 pcl_round (double number)
00147 {
00148   return (number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5));
00149 }
00150 __inline float
00151 pcl_round (float number)
00152 {
00153   return (number < 0.0f ? ceil(number - 0.5f) : floor(number + 0.5f));
00154 }
00155 
00156 #define pcl_lrint(x) ((long int) pcl_round(x))
00157 #define pcl_lrintf(x) ((long int) pcl_round(x))
00158 
00159 #ifdef WIN32
00160 #define pcl_sleep(x) Sleep(1000*(x))
00161 #else
00162 #define pcl_sleep(x) sleep(x)
00163 #endif
00164 
00165 #ifndef PVAR
00166   #define PVAR(s) \
00167     #s << " = " << (s) << std::flush
00168 #endif
00169 #ifndef PVARN
00170 #define PVARN(s) \
00171   #s << " = " << (s) << "\n"
00172 #endif
00173 #ifndef PVARC
00174 #define PVARC(s) \
00175   #s << " = " << (s) << ", " << std::flush
00176 #endif
00177 #ifndef PVARS
00178 #define PVARS(s) \
00179   #s << " = " << (s) << " " << std::flush
00180 #endif
00181 #ifndef PVARA
00182 #define PVARA(s) \
00183   #s << " = " << RAD2DEG(s) << "deg" << std::flush
00184 #endif
00185 #ifndef PVARAN
00186 #define PVARAN(s) \
00187   #s << " = " << RAD2DEG(s) << "deg\n"
00188 #endif
00189 #ifndef PVARAC
00190 #define PVARAC(s) \
00191   #s << " = " << RAD2DEG(s) << "deg, " << std::flush
00192 #endif
00193 #ifndef PVARAS
00194 #define PVARAS(s) \
00195   #s << " = " << RAD2DEG(s) << "deg " << std::flush
00196 #endif
00197 
00198 #define FIXED(s) \
00199   std::fixed << s << std::resetiosflags(std::ios_base::fixed)
00200 
00201 #ifndef ERASE_STRUCT
00202 #define ERASE_STRUCT(var) memset(&var, 0, sizeof(var))
00203 #endif
00204 
00205 #ifndef ERASE_ARRAY
00206 #define ERASE_ARRAY(var, size) memset(var, 0, size*sizeof(*var))
00207 #endif
00208 
00209 #ifndef SET_ARRAY
00210 #define SET_ARRAY(var, value, size) {for (int i=0; i<(int)size; ++i) var[i]=value;}
00211 #endif
00212 
00213 /* //This is copy/paste from http://gcc.gnu.org/wiki/Visibility */
00214 /* #if defined _WIN32 || defined __CYGWIN__ */
00215 /*   #ifdef BUILDING_DLL */
00216 /*     #ifdef __GNUC__ */
00217 /* #define DLL_PUBLIC __attribute__((dllexport)) */
00218 /*     #else */
00219 /* #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. */
00220 /*     #endif */
00221 /*   #else */
00222 /*     #ifdef __GNUC__ */
00223 /* #define DLL_PUBLIC __attribute__((dllimport)) */
00224 /*     #else */
00225 /* #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. */
00226 /*     #endif */
00227 /*   #endif */
00228 /*   #define DLL_LOCAL */
00229 /* #else */
00230 /*   #if __GNUC__ >= 4 */
00231 /* #define DLL_PUBLIC __attribute__ ((visibility("default"))) */
00232 /* #define DLL_LOCAL  __attribute__ ((visibility("hidden"))) */
00233 /*   #else */
00234 /*     #define DLL_PUBLIC */
00235 /*     #define DLL_LOCAL */
00236 /*   #endif */
00237 /* #endif */
00238 
00239 #ifndef PCL_EXTERN_C
00240     #ifdef __cplusplus
00241         #define PCL_EXTERN_C extern "C"
00242     #else
00243         #define PCL_EXTERN_C
00244     #endif
00245 #endif
00246 
00247 #if defined WIN32 || defined _WIN32 || defined WINCE || defined __MINGW32__
00248     #ifdef PCLAPI_EXPORTS
00249         #define PCL_EXPORTS __declspec(dllexport)
00250     #else
00251         #define PCL_EXPORTS
00252     #endif
00253 #else
00254     #define PCL_EXPORTS
00255 #endif
00256 
00257 #if defined WIN32 || defined _WIN32
00258     #define PCL_CDECL __cdecl
00259     #define PCL_STDCALL __stdcall
00260 #else
00261     #define PCL_CDECL
00262     #define PCL_STDCALL
00263 #endif
00264 
00265 #ifndef PCLAPI
00266     #define PCLAPI(rettype) PCL_EXTERN_C PCL_EXPORTS rettype PCL_CDECL
00267 #endif
00268 
00269 // Macro to deprecate old functions
00270 //
00271 // Usage:
00272 // don't use me any more
00273 // PCL_DEPRECATED(void OldFunc(int a, float b), "Use newFunc instead, this functions will be gone in the next major release");
00274 // use me instead
00275 // void NewFunc(int a, double b);
00276 
00277 // gcc supports this starting from 4.5 : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43666
00278 #ifdef __GNUC__
00279 #define GCC_VERSION (__GNUC__ * 10000 \
00280     + __GNUC_MINOR__ * 100 \
00281     + __GNUC_PATCHLEVEL__)
00282 #if GCC_VERSION < 40500
00283 #define PCL_DEPRECATED(func, message) func __attribute__ ((deprecated))
00284 #else
00285 #define PCL_DEPRECATED(func, message) func __attribute__ ((deprecated(message)))
00286 #endif
00287 
00288 #elif defined(_MSC_VER)
00289 #define PCL_DEPRECATED(func, message) __declspec(deprecated(message)) func
00290 #else
00291 #pragma message("WARNING: You need to implement PCL_DEPRECATED for this compiler")
00292 #define PCL_DEPRECATED(func) func
00293 #endif
00294 
00295 #if defined (__GNUC__) || defined (__PGI) || defined (__IBMCPP__) || defined (__SUNPRO_CC)
00296   #define PCL_ALIGN(alignment) __attribute__((aligned(alignment)))
00297 #elif defined (_MSC_VER)
00298   #define PCL_ALIGN(alignment) __declspec(align(alignment))
00299 #else
00300   #error Alignment not supported on your platform
00301 #endif
00302 
00303 #if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \
00304  && defined(__LP64__)
00305   #define GLIBC_MALLOC_ALIGNED 1
00306 #else
00307   #define GLIBC_MALLOC_ALIGNED 0
00308 #endif
00309 
00310 #if defined(__FreeBSD__) && !defined(__arm__) && !defined(__mips__)
00311   #define FREEBSD_MALLOC_ALIGNED 1
00312 #else
00313   #define FREEBSD_MALLOC_ALIGNED 0
00314 #endif
00315 
00316 #if defined(__APPLE__) || defined(_WIN64) || GLIBC_MALLOC_ALIGNED || FREEBSD_MALLOC_ALIGNED
00317   #define MALLOC_ALIGNED 1
00318 #else
00319   #define MALLOC_ALIGNED 0
00320 #endif
00321 
00322 inline void* 
00323 aligned_malloc (size_t size)
00324 {
00325   void *ptr;
00326 #if   defined (MALLOC_ALIGNED)
00327   ptr = std::malloc (size);
00328 #elif defined (HAVE_POSIX_MEMALIGN)
00329   if (posix_memalign (&ptr, 16, size))
00330     ptr = 0;
00331 #elif defined (HAVE_MM_MALLOC)
00332   ptr = _mm_malloc (size, 16);
00333 #elif defined (_MSC_VER)
00334   ptr = _aligned_malloc (size, 16);
00335 #else
00336   #error aligned_malloc not supported on your platform
00337   ptr = 0;
00338 #endif
00339   return (ptr);
00340 }
00341 
00342 inline void 
00343 aligned_free (void* ptr)
00344 {
00345 #if   defined (MALLOC_ALIGNED) || defined (HAVE_POSIX_MEMALIGN)
00346   std::free (ptr);
00347 #elif defined (HAVE_MM_MALLOC)
00348   ptr = _mm_free (ptr);
00349 #elif defined (_MSC_VER)
00350   _aligned_free (ptr);
00351 #else
00352   #error aligned_free not supported on your platform
00353 #endif
00354 }
00355 
00356 #endif  //#ifndef PCL_MACROS_H_