12 #include <mrpt/config.h> 40 template <
class MATRIXLIKE>
41 inline size_t size(
const MATRIXLIKE& m,
const int dim)
44 return m.getRowCount();
46 return m.getColCount();
49 "size: Queried matrix dimension must be 1 or 2. Called with i=%i",
65 return std::sqrt(
x *
x +
y *
y);
85 #ifdef DEG2RAD // functions are preferred over macros 92 #define M_PI 3.14159265358979323846 105 #ifdef HAVE_LONG_DOUBLE 107 inline long double DEG2RAD(
const long double x) {
return x * M_PIl / 180.0; }
109 inline long double RAD2DEG(
const long double x) {
return x * 180.0 / M_PIl; }
113 DEG2RAD // This is required to avoid other libs (like PCL) to #define their 116 RAD2DEG // This is required to avoid other libs (like PCL) to #define their 120 template <
typename T>
123 return x < 0 ? -1 : 1;
127 template <
typename T>
130 return (
x == 0 ||
x == -0) ? 0 :
sign(
x);
135 template <
typename T>
149 template <
typename T>
155 template <
typename T>
156 inline const T
min3(
const T& A,
const T& B,
const T& C)
158 return std::min<T>(A, std::min<T>(B, C));
160 template <
typename T>
161 inline const T
max3(
const T& A,
const T& B,
const T& C)
163 return std::max<T>(A, std::max<T>(B, C));
167 template <
typename T>
170 return x > 0 ?
static_cast<int>(floor(static_cast<double>(
x)))
171 : static_cast<int>(ceil(static_cast<double>(
x)));
178 template <
class R,
class SMART_PTR>
181 return static_cast<R*
>(&(*o));
185 template <
class R,
class SMART_PTR>
186 inline const R*
getAs(
const SMART_PTR& o)
188 return static_cast<const R*
>(&(*o));
204 #ifdef HAVE_LONG_DOUBLE 219 template <
typename T,
typename K>
222 if (test_val < var) var = test_val;
226 template <
typename T,
typename K>
229 if (test_val > var) var = test_val;
233 template <
typename T>
234 inline void saturate(T& var,
const T sat_min,
const T sat_max)
236 if (var > sat_max) var = sat_max;
237 if (var < sat_min) var = sat_min;
241 template <
typename T>
245 if (var > sat_max) var = sat_max;
246 if (var < sat_min) var = sat_min;
264 template <
class VECTOR_T>
272 template <
typename T>
275 if (0 != (
len & 0x03))
len += (4 - (
len & 0x03));
279 #define SELBYTE0(v) (v & 0xff) 280 #define SELBYTE1(v) ((v >> 8) & 0xff) 281 #define SELBYTE2(v) ((v >> 16) & 0xff) 282 #define SELBYTE3(v) ((v >> 24) & 0xff) 284 #define MAKEWORD16B(__LOBYTE, __HILOBYTE) ((__LOBYTE) | ((__HILOBYTE) << 8)) 285 #define MAKEWORD32B(__LOWORD16, __HIWORD16) \ 286 ((__LOWORD16) | ((__HIWORD16) << 16)) 287 #define MAKEWORD64B(__LOWORD32, __HIWORD32) \ 288 ((__LOWORD32) | ((__HIWORD32) << 32))
unsigned __int16 uint16_t
const T min3(const T &A, const T &B, const T &C)
size_t size(const MATRIXLIKE &m, const int dim)
T hypot_fast(const T x, const T y)
Faster version of std::hypot(), to use when overflow is not an issue and we prefer fast code...
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
T abs_diff(const T a, const T b)
Efficient and portable evaluation of the absolute difference of two unsigned integer values (but will...
T saturate_val(const T &value, const T sat_min, const T sat_max)
Like saturate() but it returns the value instead of modifying the variable.
void global_profiler_leave(const char *func_name) noexcept
void saturate(T &var, const T sat_min, const T sat_max)
Saturate the value of var (the variable gets modified) so it does not get out of [min,max].
R * getAs(SMART_PTR &o)
Utility to get a cast'ed pointer from a smart pointer.
void reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
int signWithZero(T x)
Returns the sign of X as "0", "1" or "-1".
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
T square(const T x)
Inline function for the square of a number.
void delete_safe(T *&ptr)
Calls "delete" to free an object only if the pointer is not nullptr, then set the pointer to NULL...
CProfilerProxy(const char *func_name)
T length2length4N(T len)
Returns the smaller number >=len such that it's a multiple of 4.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double DEG2RAD(const double x)
Degrees to radians.
GLsizei const GLchar ** string
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
int sign(T x)
Returns the sign of X as "1" or "-1".
void reverseBytes(const T &v_in, T &v_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
unsigned __int64 uint64_t
void vector_strong_clear(VECTOR_T &v)
Like calling a std::vector<>'s clear() method, but really forcing deallocating the memory...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void global_profiler_enter(const char *func_name) noexcept
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
T square(const T x)
Inline function for the square of a number.
const T max3(const T &A, const T &B, const T &C)
double RAD2DEG(const double x)
Radians to degrees.
GLsizei const GLfloat * value
unsigned __int32 uint32_t
GLubyte GLubyte GLubyte a
T lowestPositive(const T a, const T b)
Returns the lowest, possitive among two numbers.
int fix(T x)
Rounds toward zero.