12 #include <mrpt/config.h>    14 #define _USE_MATH_DEFINES // (For VS to define M_PI, etc. in cmath)    42                 template <
class MATRIXLIKE>
    43                 inline size_t size( 
const MATRIXLIKE& m, 
const int dim )
    45                         if (dim==1) 
return m.getRowCount();
    46                         else if (dim==2) 
return m.getColCount();
    47                         else THROW_EXCEPTION_FMT(
"size: Queried matrix dimension must be 1 or 2. Called with i=%i",dim);
    71 #ifdef DEG2RAD  // functions are preferred over macros    78 #       define M_PI 3.14159265358979323846    92 #       ifdef HAVE_LONG_DOUBLE    94                 inline long double DEG2RAD(
const long double x) { 
return x*M_PIl/180.0; }
    96                 inline long double RAD2DEG(
const long double x) { 
return x*180.0/M_PIl; }
    99 #define DEG2RAD DEG2RAD  // This is required to avoid other libs (like PCL) to #define their own versions of DEG2RAD   100 #define RAD2DEG RAD2DEG  // This is required to avoid other libs (like PCL) to #define their own versions of RAD2DEG   103                 template <
typename T>
   104                 inline int sign(T 
x) { 
return x<0 ? -1:1; }
   107                 template <
typename T>
   111                 template <
typename T>
   123                 template <
typename T>
   128                 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) ); }
   129                 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) ); }
   132                 template <
typename T>
   133                 inline int fix(T 
x) { 
return  x>0 ? 
static_cast<int>(floor(static_cast<double>(
x))) : static_cast<int>(ceil(static_cast<double>(
x))) ; }
   138                 template <
class R, 
class SMART_PTR>
   139                 inline R* 
getAs(SMART_PTR &o) { 
return static_cast<R*
>( & (*o) ); }
   142                 template <
class R, 
class SMART_PTR>
   143                 inline const R* 
getAs(
const SMART_PTR &o) { 
return static_cast<const R*
>( & (*o) ); }
   157 #ifdef HAVE_LONG_DOUBLE   170                 template <
typename T,
typename K>
   172                         if (test_val<var) var = test_val;
   175                 template <
typename T,
typename K>
   177                         if (test_val>var) var = test_val;
   180                 template <
typename T>
   181                 inline void saturate(T &var, 
const T sat_min, 
const T sat_max) {
   182                         if (var>sat_max) var = sat_max;
   183                         if (var<sat_min) var = sat_min;
   186                 template <
typename T>
   189                         if (var>sat_max) var = sat_max;
   190                         if (var<sat_min) var = sat_min;
   204                 template <
class VECTOR_T>
   208                 template <
typename T>
   210                         if (0!=(
len & 0x03)) 
len+= (4 - (
len & 0x03));
   214 #define SELBYTE0(v)  (v & 0xff)   215 #define SELBYTE1(v)  ((v>>8) & 0xff)   216 #define SELBYTE2(v)  ((v>>16) & 0xff)   217 #define SELBYTE3(v)  ((v>>24) & 0xff)   219 #define MAKEWORD16B(__LOBYTE,__HILOBYTE)  ((__LOBYTE) | ((__HILOBYTE)<<8))   220 #define MAKEWORD32B(__LOWORD16,__HIWORD16)  ((__LOWORD16) | ((__HIWORD16)<<16))   221 #define MAKEWORD64B(__LOWORD32,__HIWORD32)  ((__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...
 
#define MRPT_NO_THROWS
C++11 noexcept: 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)
< Allow square() to be available under mrpt::math and mrpt::utils 
 
void BASE_IMPEXP 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. 
 
bool BASE_IMPEXP isNaN(float f) MRPT_NO_THROWS
Returns true if the number is NaN. 
 
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)
 
T length2length4N(T len)
Returns the smaller number >=len such that it's a multiple of 4. 
 
std::string BASE_IMPEXP 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) ...
 
bool BASE_IMPEXP isFinite(float f) MRPT_NO_THROWS
Returns true if the number is non infinity. 
 
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 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. 
 
void BASE_IMPEXP global_profiler_enter(const char *func_name) MRPT_NO_THROWS
 
const T max3(const T &A, const T &B, const T &C)
 
void BASE_IMPEXP global_profiler_leave(const char *func_name) MRPT_NO_THROWS
 
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.