Point Cloud Library (PCL)  1.9.1
pcl_macros.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef PCL_MACROS_H_
38 #define PCL_MACROS_H_
39 
40 #include <pcl/pcl_config.h>
41 #include <boost/cstdint.hpp>
42 #include <cstdlib>
43 
44 namespace pcl
45 {
46  using boost::uint8_t;
47  using boost::int8_t;
48  using boost::int16_t;
49  using boost::uint16_t;
50  using boost::int32_t;
51  using boost::uint32_t;
52  using boost::int64_t;
53  using boost::uint64_t;
54  using boost::int_fast16_t;
55 }
56 
57 #if defined __INTEL_COMPILER
58  #pragma warning disable 2196 2536 279
59 #endif
60 
61 #if defined _MSC_VER
62  // 4244 : conversion from 'type1' to 'type2', possible loss of data
63  // 4661 : no suitable definition provided for explicit template instantiation reques
64  // 4503 : decorated name length exceeded, name was truncated
65  // 4146 : unary minus operator applied to unsigned type, result still unsigned
66  #pragma warning (disable: 4018 4244 4267 4521 4251 4661 4305 4503 4146)
67 #endif
68 
69 #include <iostream>
70 #include <stdarg.h>
71 #include <stdio.h>
72 #ifndef _USE_MATH_DEFINES
73 #define _USE_MATH_DEFINES
74 #endif
75 #include <math.h>
76 
77 // MSCV doesn't have std::{isnan,isfinite}
78 #if defined _WIN32 && defined _MSC_VER
79 
80 // If M_PI is not defined, then probably all of them are undefined
81 #ifndef M_PI
82 // Copied from math.h
83 # define M_PI 3.14159265358979323846 // pi
84 # define M_PI_2 1.57079632679489661923 // pi/2
85 # define M_PI_4 0.78539816339744830962 // pi/4
86 # define M_PIl 3.1415926535897932384626433832795029L // pi
87 # define M_PI_2l 1.5707963267948966192313216916397514L // pi/2
88 # define M_PI_4l 0.7853981633974483096156608458198757L // pi/4
89 #endif
90 
91 // Stupid. This should be removed when all the PCL dependencies have min/max fixed.
92 #ifndef NOMINMAX
93 # define NOMINMAX
94 #endif
95 
96 # define pcl_isnan(x) _isnan(x)
97 # define pcl_isfinite(x) (_finite(x) != 0)
98 # define pcl_isinf(x) (_finite(x) == 0)
99 
100 # define __PRETTY_FUNCTION__ __FUNCTION__
101 # define __func__ __FUNCTION__
102 
103 #elif ANDROID
104 // Use the math.h macros
105 # include <math.h>
106 # define pcl_isnan(x) std::isnan(x)
107 # define pcl_isfinite(x) std::isfinite(x)
108 # define pcl_isinf(x) std::isinf(x)
109 
110 #elif _GLIBCXX_USE_C99_MATH
111 // Are the C++ cmath functions enabled?
112 # include <cmath>
113 # define pcl_isnan(x) std::isnan(x)
114 # define pcl_isfinite(x) std::isfinite(x)
115 # define pcl_isinf(x) std::isinf(x)
116 
117 #elif __PATHCC__
118 # include <cmath>
119 # include <stdio.h>
120 template <typename T> int
121 pcl_isnan (T &val)
122 {
123  return (val != val);
124 }
125 //# define pcl_isnan(x) std::isnan(x)
126 # define pcl_isfinite(x) std::isfinite(x)
127 # define pcl_isinf(x) std::isinf(x)
128 
129 #else
130 // Use the math.h macros
131 # include <math.h>
132 # define pcl_isnan(x) isnan(x)
133 # define pcl_isfinite(x) isfinite(x)
134 # define pcl_isinf(x) isinf(x)
135 
136 #endif
137 
138 #ifndef DEG2RAD
139 #define DEG2RAD(x) ((x)*0.017453293)
140 #endif
141 
142 #ifndef RAD2DEG
143 #define RAD2DEG(x) ((x)*57.29578)
144 #endif
145 
146 /** \brief Macro that maps version information given by major.minor.patch to a linear integer value to enable easy comparison
147  */
148 #define PCL_LINEAR_VERSION(major,minor,patch) ((major)<<16|(minor)<<8|(patch))
149 
150 /** Win32 doesn't seem to have rounding functions.
151  * Therefore implement our own versions of these functions here.
152  */
153 
154 __inline double
155 pcl_round (double number)
156 {
157  return (number < 0.0 ? ceil (number - 0.5) : floor (number + 0.5));
158 }
159 __inline float
160 pcl_round (float number)
161 {
162  return (number < 0.0f ? ceilf (number - 0.5f) : floorf (number + 0.5f));
163 }
164 
165 #ifdef __GNUC__
166 #define pcl_lrint(x) (lrint(static_cast<double> (x)))
167 #define pcl_lrintf(x) (lrintf(static_cast<float> (x)))
168 #else
169 #define pcl_lrint(x) (static_cast<long int>(pcl_round(x)))
170 #define pcl_lrintf(x) (static_cast<long int>(pcl_round(x)))
171 #endif
172 
173 
174 #ifdef _WIN32
175 __inline float
176 log2f (float x)
177 {
178  return (static_cast<float> (logf (x) * M_LOG2E));
179 }
180 #endif
181 
182 #ifdef WIN32
183 #define pcl_sleep(x) Sleep(1000*(x))
184 #else
185 #define pcl_sleep(x) sleep(x)
186 #endif
187 
188 #ifndef PVAR
189  #define PVAR(s) \
190  #s << " = " << (s) << std::flush
191 #endif
192 #ifndef PVARN
193 #define PVARN(s) \
194  #s << " = " << (s) << "\n"
195 #endif
196 #ifndef PVARC
197 #define PVARC(s) \
198  #s << " = " << (s) << ", " << std::flush
199 #endif
200 #ifndef PVARS
201 #define PVARS(s) \
202  #s << " = " << (s) << " " << std::flush
203 #endif
204 #ifndef PVARA
205 #define PVARA(s) \
206  #s << " = " << RAD2DEG(s) << "deg" << std::flush
207 #endif
208 #ifndef PVARAN
209 #define PVARAN(s) \
210  #s << " = " << RAD2DEG(s) << "deg\n"
211 #endif
212 #ifndef PVARAC
213 #define PVARAC(s) \
214  #s << " = " << RAD2DEG(s) << "deg, " << std::flush
215 #endif
216 #ifndef PVARAS
217 #define PVARAS(s) \
218  #s << " = " << RAD2DEG(s) << "deg " << std::flush
219 #endif
220 
221 #define FIXED(s) \
222  std::fixed << s << std::resetiosflags(std::ios_base::fixed)
223 
224 #ifndef ERASE_STRUCT
225 #define ERASE_STRUCT(var) memset(&var, 0, sizeof(var))
226 #endif
227 
228 #ifndef ERASE_ARRAY
229 #define ERASE_ARRAY(var, size) memset(var, 0, size*sizeof(*var))
230 #endif
231 
232 #ifndef SET_ARRAY
233 #define SET_ARRAY(var, value, size) { for (int i = 0; i < static_cast<int> (size); ++i) var[i]=value; }
234 #endif
235 
236 /* //This is copy/paste from http://gcc.gnu.org/wiki/Visibility */
237 /* #if defined _WIN32 || defined __CYGWIN__ */
238 /* #ifdef BUILDING_DLL */
239 /* #ifdef __GNUC__ */
240 /* #define DLL_PUBLIC __attribute__((dllexport)) */
241 /* #else */
242 /* #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. */
243 /* #endif */
244 /* #else */
245 /* #ifdef __GNUC__ */
246 /* #define DLL_PUBLIC __attribute__((dllimport)) */
247 /* #else */
248 /* #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. */
249 /* #endif */
250 /* #endif */
251 /* #define DLL_LOCAL */
252 /* #else */
253 /* #if __GNUC__ >= 4 */
254 /* #define DLL_PUBLIC __attribute__ ((visibility("default"))) */
255 /* #define DLL_LOCAL __attribute__ ((visibility("hidden"))) */
256 /* #else */
257 /* #define DLL_PUBLIC */
258 /* #define DLL_LOCAL */
259 /* #endif */
260 /* #endif */
261 
262 #ifndef PCL_EXTERN_C
263  #ifdef __cplusplus
264  #define PCL_EXTERN_C extern "C"
265  #else
266  #define PCL_EXTERN_C
267  #endif
268 #endif
269 
270 #if defined WIN32 || defined _WIN32 || defined WINCE || defined __MINGW32__
271  #ifdef PCLAPI_EXPORTS
272  #define PCL_EXPORTS __declspec(dllexport)
273  #else
274  #define PCL_EXPORTS
275  #endif
276 #else
277  #define PCL_EXPORTS
278 #endif
279 
280 #if defined WIN32 || defined _WIN32
281  #define PCL_CDECL __cdecl
282  #define PCL_STDCALL __stdcall
283 #else
284  #define PCL_CDECL
285  #define PCL_STDCALL
286 #endif
287 
288 #ifndef PCLAPI
289  #define PCLAPI(rettype) PCL_EXTERN_C PCL_EXPORTS rettype PCL_CDECL
290 #endif
291 
292 // Macro for pragma operator
293 #if (defined (__GNUC__) || defined(__clang__))
294  #define PCL_PRAGMA(x) _Pragma (#x)
295 #elif _MSC_VER
296  #define PCL_PRAGMA(x) __pragma (#x)
297 #else
298  #define PCL_PRAGMA
299 #endif
300 
301 // Macro for emitting pragma warning
302 #if (defined (__GNUC__) || defined(__clang__))
303  #define PCL_PRAGMA_WARNING(x) PCL_PRAGMA (GCC warning x)
304 #elif _MSC_VER
305  #define PCL_PRAGMA_WARNING(x) PCL_PRAGMA (warning (x))
306 #else
307  #define PCL_PRAGMA_WARNING
308 #endif
309 
310 
311 // Macro to deprecate old functions
312 //
313 // Usage:
314 // don't use me any more
315 // PCL_DEPRECATED(void OldFunc(int a, float b), "Use newFunc instead, this functions will be gone in the next major release");
316 // use me instead
317 // void NewFunc(int a, double b);
318 
319 //for clang cf. http://clang.llvm.org/docs/LanguageExtensions.html
320 #ifndef __has_extension
321  #define __has_extension(x) 0 // Compatibility with pre-3.0 compilers.
322 #endif
323 
324 // check Intel compiler first since it usually also defines __GNUC__, __clang__, etc.
325 #if defined(__INTEL_COMPILER)
326  #define PCL_DEPRECATED(message) __attribute((deprecated))
327 #elif (defined(__GNUC__) && PCL_LINEAR_VERSION(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) < PCL_LINEAR_VERSION(4,5,0) && ! defined(__clang__)) || defined(__INTEL_COMPILER)
328  #define PCL_DEPRECATED(message) __attribute__ ((deprecated))
329 // gcc supports this starting from 4.5 : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43666
330 #elif (defined(__GNUC__) && PCL_LINEAR_VERSION(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= PCL_LINEAR_VERSION(4,5,0)) || (defined(__clang__) && __has_extension(attribute_deprecated_with_message))
331  #define PCL_DEPRECATED(message) __attribute__ ((deprecated(message)))
332 #elif defined(_MSC_VER)
333  #define PCL_DEPRECATED(message) __declspec(deprecated(message))
334 #else
335  #pragma message("WARNING: You need to implement PCL_DEPRECATED for this compiler")
336  #define PCL_DEPRECATED(message)
337 #endif
338 
339 
340 // Macro to deprecate old classes/structs
341 //
342 // Usage:
343 // don't use me any more
344 // class PCL_DEPRECATED_CLASS(OldClass, "Use newClass instead, this class will be gone in the next major release")
345 // {
346 // public:
347 // OldClass() {}
348 // };
349 // use me instead
350 // class NewFunc
351 // {
352 // public:
353 // NewClass() {}
354 // };
355 
356 // check Intel compiler first since it usually also defines __GNUC__, __clang__, etc.
357 #if defined(__INTEL_COMPILER)
358  #define PCL_DEPRECATED_CLASS(func, message) __attribute((deprecated)) func
359 #elif (defined(__GNUC__) && PCL_LINEAR_VERSION(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) < PCL_LINEAR_VERSION(4,5,0) && ! defined(__clang__)) || defined(__INTEL_COMPILER)
360  #define PCL_DEPRECATED_CLASS(func, message) __attribute__ ((deprecated)) func
361 // gcc supports this starting from 4.5 : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43666
362 #elif (defined(__GNUC__) && PCL_LINEAR_VERSION(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= PCL_LINEAR_VERSION(4,5,0)) || (defined(__clang__) && __has_extension(attribute_deprecated_with_message))
363  #define PCL_DEPRECATED_CLASS(func, message) __attribute__ ((deprecated(message))) func
364 #elif defined(_MSC_VER)
365  #define PCL_DEPRECATED_CLASS(func, message) __declspec(deprecated(message)) func
366 #else
367  #pragma message("WARNING: You need to implement PCL_DEPRECATED_CLASS for this compiler")
368  #define PCL_DEPRECATED_CLASS(func) func
369 #endif
370 
371 #if defined (__GNUC__) || defined (__PGI) || defined (__IBMCPP__) || defined (__SUNPRO_CC)
372  #define PCL_ALIGN(alignment) __attribute__((aligned(alignment)))
373 #elif defined (_MSC_VER)
374  #define PCL_ALIGN(alignment) __declspec(align(alignment))
375 #else
376  #error Alignment not supported on your platform
377 #endif
378 
379 #if defined(__GLIBC__) && PCL_LINEAR_VERSION(__GLIBC__,__GLIBC_MINOR__,0)>PCL_LINEAR_VERSION(2,8,0)
380  #define GLIBC_MALLOC_ALIGNED 1
381 #else
382  #define GLIBC_MALLOC_ALIGNED 0
383 #endif
384 
385 #if defined(__FreeBSD__) && !defined(__arm__) && !defined(__mips__)
386  #define FREEBSD_MALLOC_ALIGNED 1
387 #else
388  #define FREEBSD_MALLOC_ALIGNED 0
389 #endif
390 
391 #if defined(__APPLE__) || defined(_WIN64) || GLIBC_MALLOC_ALIGNED || FREEBSD_MALLOC_ALIGNED
392  #define MALLOC_ALIGNED 1
393 #endif
394 
395 #if defined (HAVE_MM_MALLOC)
396  // Intel compiler defines an incompatible _mm_malloc signature
397  #if defined(__INTEL_COMPILER)
398  #include <malloc.h>
399  #else
400  #include <mm_malloc.h>
401  #endif
402 #endif
403 
404 inline void*
405 aligned_malloc (size_t size)
406 {
407  void *ptr;
408 #if defined (MALLOC_ALIGNED)
409  ptr = std::malloc (size);
410 #elif defined (HAVE_POSIX_MEMALIGN)
411  if (posix_memalign (&ptr, 16, size))
412  ptr = 0;
413 #elif defined (HAVE_MM_MALLOC)
414  ptr = _mm_malloc (size, 16);
415 #elif defined (_MSC_VER)
416  ptr = _aligned_malloc (size, 16);
417 #elif defined (ANDROID)
418  ptr = memalign (16, size);
419 #else
420  #error aligned_malloc not supported on your platform
421  ptr = 0;
422 #endif
423  return (ptr);
424 }
425 
426 inline void
427 aligned_free (void* ptr)
428 {
429 #if defined (MALLOC_ALIGNED) || defined (HAVE_POSIX_MEMALIGN)
430  std::free (ptr);
431 #elif defined (HAVE_MM_MALLOC)
432  _mm_free (ptr);
433 #elif defined (_MSC_VER)
434  _aligned_free (ptr);
435 #elif defined (ANDROID)
436  free (ptr);
437 #else
438  #error aligned_free not supported on your platform
439 #endif
440 }
441 
442 #endif //#ifndef PCL_MACROS_H_
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45