12 #define _USE_MATH_DEFINES // (For VS to define M_PI, etc. in cmath) 37 template <
class MATRIXLIKE>
38 inline size_t size(
const MATRIXLIKE& m,
int dim )
40 if (dim==1)
return m.getRowCount();
41 else if (dim==2)
return m.getColCount();
58 #ifdef DEG2RAD // functions are preferred over macros 65 # define M_PI 3.14159265358979323846 69 inline double DEG2RAD(
const double x) {
return x*
M_PI/180.0; }
75 inline double RAD2DEG(
const double x) {
return x*180.0/
M_PI; }
79 # ifdef HAVE_LONG_DOUBLE 81 inline long double DEG2RAD(
const long double x) {
return x*M_PIl/180.0; }
83 inline long double RAD2DEG(
const long double x) {
return x*180.0/M_PIl; }
86 #define DEG2RAD DEG2RAD // This is required to avoid other libs (like PCL) to #define their own versions of DEG2RAD 87 #define RAD2DEG RAD2DEG // This is required to avoid other libs (like PCL) to #define their own versions of RAD2DEG 91 inline int sign(T x) {
return x<0 ? -1:1; }
101 return std::max(a,b) - std::min(a,b);
104 template<
typename T>
inline const T
min3(
const T& A,
const T& B,
const T& C) {
return std::min<T>(A, std::min<T>(B,C) ); }
105 template<
typename T>
inline const T
max3(
const T& A,
const T& B,
const T& C) {
return std::max<T>(A, std::max<T>(B,C) ); }
108 template <
typename T>
109 inline int fix(T x) {
return x>0 ?
static_cast<int>(floor(static_cast<double>(x))) : static_cast<int>(ceil(static_cast<double>(x))) ; }
113 inline T
square(
const T x) {
return x*x; }
116 template <
class R,
class SMART_PTR>
117 inline R*
getAs(SMART_PTR &o) {
return static_cast<R*
>( & (*o) ); }
120 template <
class R,
class SMART_PTR>
121 inline const R*
getAs(
const SMART_PTR &o) {
return static_cast<const R*
>( & (*o) ); }
126 unsigned char *ptr =
reinterpret_cast<unsigned char*
>(&v_in_out);
127 std::reverse(ptr,ptr+
sizeof(T));
139 template <
typename T,
typename K>
141 if (test_val<var) var = test_val;
144 template <
typename T,
typename K>
146 if (test_val>var) var = test_val;
149 template <
typename T>
150 inline void saturate(T &var,
const T sat_min,
const T sat_max) {
151 if (var>sat_max) var = sat_max;
152 if (var<sat_min) var = sat_min;
155 template <
typename T>
156 inline T
saturate_val(
const T &value,
const T sat_min,
const T sat_max) {
158 if (var>sat_max) var = sat_max;
159 if (var<sat_min) var = sat_min;
173 template <
class VECTOR_T>
bool BASE_IMPEXP isFinite(float f) MRPT_NO_THROWS
Returns true if the number is non infinity.
const T min3(const T &A, const T &B, const T &C)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
T abs_diff(const T a, const T b)
Efficient and portable evaluation of the absolute difference of two unsigned integer values (but will...
#define MRPT_NO_THROWS
Used after member declarations.
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 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.
int signWithZero(T x)
Returns the sign of X as "0", "1" or "-1".
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
void delete_safe(T *&ptr)
Calls "delete" to free an object only if the pointer is not NULL, then set the pointer to NULL...
CProfilerProxy(const char *func_name)
void reverseBytesInPlace(T &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
double DEG2RAD(const double x)
Degrees to radians.
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) ...
T square(const T x)
Inline function for the square of a number.
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.
bool BASE_IMPEXP isNaN(float f) MRPT_NO_THROWS
Returns true if the number is NaN.
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...
size_t size(const MATRIXLIKE &m, int dim)
const T max3(const T &A, const T &B, const T &C)
double RAD2DEG(const double x)
Radians to degrees.
void BASE_IMPEXP global_profiler_leave(const char *func_name) MRPT_NO_THROWS
void BASE_IMPEXP global_profiler_enter(const char *func_name) MRPT_NO_THROWS
#define THROW_EXCEPTION_CUSTOM_MSG1(msg, param1)
int fix(T x)
Rounds toward zero.