Point Cloud Library (PCL)  1.10.0
pcl_macros.h
Go to the documentation of this file.
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 #pragma once
38 
39 /**
40  * \file pcl/pcl_macros.h
41  *
42  * \brief Defines all the PCL and non-PCL macros used
43  * \ingroup common
44  */
45 
46 #if defined __INTEL_COMPILER
47  #pragma warning disable 2196 2536 279
48 #endif
49 
50 #if defined _MSC_VER
51  // 4244 : conversion from 'type1' to 'type2', possible loss of data
52  // 4661 : no suitable definition provided for explicit template instantiation reques
53  // 4503 : decorated name length exceeded, name was truncated
54  // 4146 : unary minus operator applied to unsigned type, result still unsigned
55  #pragma warning (disable: 4018 4244 4267 4521 4251 4661 4305 4503 4146)
56 #endif
57 
58 #ifndef _USE_MATH_DEFINES
59 #define _USE_MATH_DEFINES
60 #endif
61 #include <cmath>
62 #include <cstdarg>
63 #include <cstdio>
64 #include <cstdlib>
65 #include <cstdint>
66 #include <iostream>
67 
68 #include <boost/cstdint.hpp>
69 #include <boost/smart_ptr/shared_ptr.hpp>
70 
71 //Eigen has an enum that clashes with X11 Success define, which is ultimately included by pcl
72 #ifdef Success
73  #undef Success
74 #endif
75 #include <Eigen/Core>
76 
77 #include <pcl/pcl_config.h>
78 
79 namespace pcl
80 {
81  /**
82  * \brief Alias for boost::shared_ptr
83  *
84  * For ease of switching from boost::shared_ptr to std::shared_ptr
85  *
86  * \see pcl::make_shared
87  * \tparam T Type of the object stored inside the shared_ptr
88  */
89  template <typename T>
90  using shared_ptr = boost::shared_ptr<T>;
91 
92  using uint8_t [[deprecated("use std::uint8_t instead of pcl::uint8_t")]] = std::uint8_t;
93  using int8_t [[deprecated("use std::int8_t instead of pcl::int8_t")]] = std::int8_t;
94  using uint16_t [[deprecated("use std::uint16_t instead of pcl::uint16_t")]] = std::uint16_t;
95  using int16_t [[deprecated("use std::uint16_t instead of pcl::int16_t")]] = std::int16_t;
96  using uint32_t [[deprecated("use std::uint32_t instead of pcl::uint32_t")]] = std::uint32_t;
97  using int32_t [[deprecated("use std::int32_t instead of pcl::int32_t")]] = std::int32_t;
98  using uint64_t [[deprecated("use std::uint64_t instead of pcl::uint64_t")]] = std::uint64_t;
99  using int64_t [[deprecated("use std::int64_t instead of pcl::int64_t")]] = std::int64_t;
100  using int_fast16_t [[deprecated("use std::int_fast16_t instead of pcl::int_fast16_t")]] = std::int_fast16_t;
101 }
102 
103 #if defined _WIN32 && defined _MSC_VER
104 
105 // Define math constants, without including math.h, to prevent polluting global namespace with old math methods
106 // Copied from math.h
107 #ifndef _MATH_DEFINES_DEFINED
108  #define _MATH_DEFINES_DEFINED
109 
110  #define M_E 2.71828182845904523536 // e
111  #define M_LOG2E 1.44269504088896340736 // log2(e)
112  #define M_LOG10E 0.434294481903251827651 // log10(e)
113  #define M_LN2 0.693147180559945309417 // ln(2)
114  #define M_LN10 2.30258509299404568402 // ln(10)
115  #define M_PI 3.14159265358979323846 // pi
116  #define M_PI_2 1.57079632679489661923 // pi/2
117  #define M_PI_4 0.785398163397448309616 // pi/4
118  #define M_1_PI 0.318309886183790671538 // 1/pi
119  #define M_2_PI 0.636619772367581343076 // 2/pi
120  #define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi)
121  #define M_SQRT2 1.41421356237309504880 // sqrt(2)
122  #define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2)
123 #endif
124 
125 // Stupid. This should be removed when all the PCL dependencies have min/max fixed.
126 #ifndef NOMINMAX
127 # define NOMINMAX
128 #endif
129 
130 # define __PRETTY_FUNCTION__ __FUNCTION__
131 # define __func__ __FUNCTION__
132 
133 #endif //defined _WIN32 && defined _MSC_VER
134 
135 
136 template<typename T>
137 [[deprecated("use std::isnan instead of pcl_isnan")]]
138 bool pcl_isnan (T&& x) { return std::isnan (std::forward<T> (x)); }
139 
140 template<typename T>
141 [[deprecated("use std::isfinite instead of pcl_isfinite")]]
142 bool pcl_isfinite (T&& x) { return std::isfinite (std::forward<T> (x)); }
143 
144 template<typename T>
145 [[deprecated("use std::isinf instead of pcl_isinf")]]
146 bool pcl_isinf (T&& x) { return std::isinf (std::forward<T> (x)); }
147 
148 
149 #ifndef DEG2RAD
150 #define DEG2RAD(x) ((x)*0.017453293)
151 #endif
152 
153 #ifndef RAD2DEG
154 #define RAD2DEG(x) ((x)*57.29578)
155 #endif
156 
157 /** \brief Macro that maps version information given by major.minor.patch to a linear integer value to enable easy comparison
158  */
159 #define PCL_LINEAR_VERSION(major,minor,patch) ((major)<<16|(minor)<<8|(patch))
160 
161 /** Win32 doesn't seem to have rounding functions.
162  * Therefore implement our own versions of these functions here.
163  */
164 
165 __inline double
166 pcl_round (double number)
167 {
168  return (number < 0.0 ? std::ceil (number - 0.5) : std::floor (number + 0.5));
169 }
170 __inline float
171 pcl_round (float number)
172 {
173  return (number < 0.0f ? std::ceil (number - 0.5f) : std::floor (number + 0.5f));
174 }
175 
176 #ifdef __GNUC__
177 #define pcl_lrint(x) (lrint(static_cast<double> (x)))
178 #define pcl_lrintf(x) (lrintf(static_cast<float> (x)))
179 #else
180 #define pcl_lrint(x) (static_cast<long int>(pcl_round(x)))
181 #define pcl_lrintf(x) (static_cast<long int>(pcl_round(x)))
182 #endif
183 
184 #ifdef WIN32
185 #define pcl_sleep(x) Sleep(1000*(x))
186 #else
187 #define pcl_sleep(x) sleep(x)
188 #endif
189 
190 #ifndef PVAR
191  #define PVAR(s) \
192  #s << " = " << (s) << std::flush
193 #endif
194 #ifndef PVARN
195 #define PVARN(s) \
196  #s << " = " << (s) << "\n"
197 #endif
198 #ifndef PVARC
199 #define PVARC(s) \
200  #s << " = " << (s) << ", " << std::flush
201 #endif
202 #ifndef PVARS
203 #define PVARS(s) \
204  #s << " = " << (s) << " " << std::flush
205 #endif
206 #ifndef PVARA
207 #define PVARA(s) \
208  #s << " = " << RAD2DEG(s) << "deg" << std::flush
209 #endif
210 #ifndef PVARAN
211 #define PVARAN(s) \
212  #s << " = " << RAD2DEG(s) << "deg\n"
213 #endif
214 #ifndef PVARAC
215 #define PVARAC(s) \
216  #s << " = " << RAD2DEG(s) << "deg, " << std::flush
217 #endif
218 #ifndef PVARAS
219 #define PVARAS(s) \
220  #s << " = " << RAD2DEG(s) << "deg " << std::flush
221 #endif
222 
223 #define FIXED(s) \
224  std::fixed << s << std::resetiosflags(std::ios_base::fixed)
225 
226 #ifndef ERASE_STRUCT
227 #define ERASE_STRUCT(var) memset(&var, 0, sizeof(var))
228 #endif
229 
230 #ifndef ERASE_ARRAY
231 #define ERASE_ARRAY(var, size) memset(var, 0, size*sizeof(*var))
232 #endif
233 
234 #ifndef SET_ARRAY
235 #define SET_ARRAY(var, value, size) { for (decltype(size) i = 0; i < size; ++i) var[i]=value; }
236 #endif
237 
238 #ifndef PCL_EXTERN_C
239  #ifdef __cplusplus
240  #define PCL_EXTERN_C extern "C"
241  #else
242  #define PCL_EXTERN_C
243  #endif
244 #endif
245 
246 #if defined WIN32 || defined _WIN32 || defined WINCE || defined __MINGW32__
247  #ifdef PCLAPI_EXPORTS
248  #define PCL_EXPORTS __declspec(dllexport)
249  #else
250  #define PCL_EXPORTS
251  #endif
252 #else
253  #define PCL_EXPORTS
254 #endif
255 
256 #if defined WIN32 || defined _WIN32
257  #define PCL_CDECL __cdecl
258  #define PCL_STDCALL __stdcall
259 #else
260  #define PCL_CDECL
261  #define PCL_STDCALL
262 #endif
263 
264 #ifndef PCLAPI
265  #define PCLAPI(rettype) PCL_EXTERN_C PCL_EXPORTS rettype PCL_CDECL
266 #endif
267 
268 // Macro for pragma operator
269 #if (defined (__GNUC__) || defined(__clang__))
270  #define PCL_PRAGMA(x) _Pragma (#x)
271 #elif _MSC_VER
272  #define PCL_PRAGMA(x) __pragma (#x)
273 #else
274  #define PCL_PRAGMA
275 #endif
276 
277 // Macro for emitting pragma warning
278 #if (defined (__GNUC__) || defined(__clang__))
279  #define PCL_PRAGMA_WARNING(x) PCL_PRAGMA (GCC warning x)
280 #elif _MSC_VER
281  #define PCL_PRAGMA_WARNING(x) PCL_PRAGMA (warning (x))
282 #else
283  #define PCL_PRAGMA_WARNING
284 #endif
285 
286 //for clang cf. http://clang.llvm.org/docs/LanguageExtensions.html
287 #ifndef __has_extension
288  #define __has_extension(x) 0 // Compatibility with pre-3.0 compilers.
289 #endif
290 
291 #if defined (__GNUC__) || defined (__PGI) || defined (__IBMCPP__) || defined (__SUNPRO_CC)
292  #define PCL_ALIGN(alignment) __attribute__((aligned(alignment)))
293 #elif defined (_MSC_VER)
294  #define PCL_ALIGN(alignment) __declspec(align(alignment))
295 #else
296  #error Alignment not supported on your platform
297 #endif
298 
299 #if defined(__GLIBC__) && PCL_LINEAR_VERSION(__GLIBC__,__GLIBC_MINOR__,0)>PCL_LINEAR_VERSION(2,8,0)
300  #define GLIBC_MALLOC_ALIGNED 1
301 #else
302  #define GLIBC_MALLOC_ALIGNED 0
303 #endif
304 
305 #if defined(__FreeBSD__) && !defined(__arm__) && !defined(__mips__)
306  #define FREEBSD_MALLOC_ALIGNED 1
307 #else
308  #define FREEBSD_MALLOC_ALIGNED 0
309 #endif
310 
311 #if defined(__APPLE__) || defined(_WIN64) || GLIBC_MALLOC_ALIGNED || FREEBSD_MALLOC_ALIGNED
312  #define MALLOC_ALIGNED 1
313 #endif
314 
315 #if defined (HAVE_MM_MALLOC)
316  // Intel compiler defines an incompatible _mm_malloc signature
317  #if defined(__INTEL_COMPILER)
318  #include <malloc.h>
319  #else
320  #include <mm_malloc.h>
321  #endif
322 #endif
323 
324 inline void*
325 aligned_malloc (std::size_t size)
326 {
327  void *ptr;
328 #if defined (MALLOC_ALIGNED)
329  ptr = std::malloc (size);
330 #elif defined (HAVE_POSIX_MEMALIGN)
331  if (posix_memalign (&ptr, 16, size))
332  ptr = 0;
333 #elif defined (HAVE_MM_MALLOC)
334  ptr = _mm_malloc (size, 16);
335 #elif defined (_MSC_VER)
336  ptr = _aligned_malloc (size, 16);
337 #elif defined (ANDROID)
338  ptr = memalign (16, size);
339 #else
340  #error aligned_malloc not supported on your platform
341  ptr = 0;
342 #endif
343  return (ptr);
344 }
345 
346 inline void
347 aligned_free (void* ptr)
348 {
349 #if defined (MALLOC_ALIGNED) || defined (HAVE_POSIX_MEMALIGN)
350  std::free (ptr);
351 #elif defined (HAVE_MM_MALLOC)
352  _mm_free (ptr);
353 #elif defined (_MSC_VER)
354  _aligned_free (ptr);
355 #elif defined (ANDROID)
356  free (ptr);
357 #else
358  #error aligned_free not supported on your platform
359 #endif
360 }
361 
362 /**
363  * \brief Macro to signal a class requires a custom allocator
364  *
365  * It's an implementation detail to have pcl::has_custom_allocator work, a
366  * thin wrapper over Eigen's own macro
367  *
368  * \see pcl::has_custom_allocator, pcl::make_shared
369  * \ingroup common
370  */
371 #define PCL_MAKE_ALIGNED_OPERATOR_NEW \
372  EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
373  using _custom_allocator_type_trait = void;
374 
375 /**
376  * \brief Macro to add a no-op or a fallthrough attribute based on compiler feature
377  *
378  * \ingroup common
379  */
380 #if (__cplusplus >= 201703L) || (defined(_MSC_VER) && (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703L))
381  #define PCL_FALLTHROUGH [[fallthrough]];
382 #elif defined(__clang__)
383  #define PCL_FALLTHROUGH [[clang::fallthrough]];
384 #elif defined(__GNUC__) && (__GNUC__ >= 7)
385  #define PCL_FALLTHROUGH [[gnu::fallthrough]];
386 #else
387  #define PCL_FALLTHROUGH
388 #endif
389 
390 #if (__cplusplus >= 201703L) || (defined(_MSC_VER) && (_MSC_VER >= 1911) && (_MSVC_LANG >= 201703L))
391  #define PCL_NODISCARD [[nodiscard]]
392 #elif defined(__clang__) && (PCL_LINEAR_VERSION(__clang_major__, __clang_minor__, 0) >= PCL_LINEAR_VERSION(3, 9, 0))
393  #define PCL_NODISCARD [[clang::warn_unused_result]]
394 #elif defined(__GNUC__)
395  #define PCL_NODISCARD [[gnu::warn_unused_result]]
396 #else
397  #define PCL_NODISCARD
398 #endif
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::uint32_t
std::uint32_t uint32_t
Definition: pcl_macros.h:96
pcl_isnan
bool pcl_isnan(T &&x)
Definition: pcl_macros.h:138
aligned_free
void aligned_free(void *ptr)
Definition: pcl_macros.h:347
pcl::int32_t
std::int32_t int32_t
Definition: pcl_macros.h:97
pcl::int16_t
std::int16_t int16_t
Definition: pcl_macros.h:95
pcl::uint16_t
std::uint16_t uint16_t
Definition: pcl_macros.h:94
pcl::int_fast16_t
std::int_fast16_t int_fast16_t
Definition: pcl_macros.h:100
pcl_isfinite
bool pcl_isfinite(T &&x)
Definition: pcl_macros.h:142
pcl::int64_t
std::int64_t int64_t
Definition: pcl_macros.h:99
aligned_malloc
void * aligned_malloc(std::size_t size)
Definition: pcl_macros.h:325
pcl::int8_t
std::int8_t int8_t
Definition: pcl_macros.h:93
pcl_isinf
bool pcl_isinf(T &&x)
Definition: pcl_macros.h:146
pcl_round
__inline double pcl_round(double number)
Win32 doesn't seem to have rounding functions.
Definition: pcl_macros.h:166
pcl::uint8_t
std::uint8_t uint8_t
Definition: pcl_macros.h:92
pcl::shared_ptr
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:90
pcl::uint64_t
std::uint64_t uint64_t
Definition: pcl_macros.h:98