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