31 template<
class T1,
class T2>
33 return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
51 return lhs>rhs ? lhs - rhs : rhs - lhs;
82 void BASE_IMPEXP medianFilter(
const std::vector<double> &inV, std::vector<double> &outV,
const int &winSize,
const int &numberOfSigmas = 2 );
84 #ifdef HAVE_LONG_DOUBLE 94 template<
typename T,
typename VECTOR>
95 void linspace(T first,T last,
size_t count, VECTOR &out_vector)
99 out_vector.assign(count,last);
104 out_vector.resize(count);
105 const T incr = (last-first)/T(count-1);
107 for (
size_t i=0;i<count;i++,c+=incr)
113 template<
class T,T STEP>
116 std::vector<T> ret(length);
117 if (!length)
return ret;
119 while (length--) { ret[i++]=first; first+=STEP; }
126 template<
class VEC1,
class VEC2>
129 typename VEC1::Scalar total=0;
130 const size_t N = v.size();
131 for (
size_t i=0;i<N;i++)
133 total = std::sqrt(total);
136 out_v = v * (1.0/total);
138 else out_v.assign(v.size(),0);
147 template <
class VECTOR_OF_VECTORS,
class VECTORLIKE>
150 const size_t N = data.size();
151 out_column.resize(N);
152 for (
size_t i=0;i<N;i++)
153 out_column[i]=data[i][colIndex];
190 const float &stdCount,
191 const std::string &style = std::string(
"b"),
192 const size_t &nEllipsePoints = 30 );
205 const float &stdCount,
206 const std::string &style = std::string(
"b"),
207 const size_t &nEllipsePoints = 30 );
219 template <
typename EIGEN_VECTOR,
typename At,
size_t N>
220 EIGEN_VECTOR&
loadVector(EIGEN_VECTOR &v, At (&theArray)[N] )
223 v.derived().resize(N);
224 for (
size_t i=0; i < N; i++)
225 (v.derived())[i] = static_cast<typename EIGEN_VECTOR::Scalar>(theArray[i]);
229 template <
typename T,
typename At,
size_t N>
230 std::vector<T>&
loadVector( std::vector<T> &v, At (&theArray)[N] )
234 for (
size_t i=0; i < N; i++)
235 v[i] = static_cast<T>(theArray[i]);
248 template <
size_t N,
typename T>
259 for (
size_t i=1;i<N;i++)
260 ret.push_back( va_arg(args,T) );
280 template <
class TRIPLET>
283 #if defined(_MSC_VER) && (_MSC_VER>=1400) // Use a secure version in Visual Studio 2005+ 285 if (0!=::fopen_s(&f,sFile.c_str(),
"wt")) f= NULL;
287 FILE *f=
::fopen(sFile.c_str(),
"wt");
290 if (!f)
return false;
292 for (
size_t i=0;i<tri.size();i++)
293 fprintf(f,
"%u %u %e\n", 1+tri[i].row(), 1+tri[i].col(), tri[i].value() );
bool BASE_IMPEXP isFinite(float f) MRPT_NO_THROWS
Returns true if the number is non infinity.
uint64_t BASE_IMPEXP factorial64(unsigned int n)
Computes the factorial of an integer number and returns it as a 64-bit integer number.
void normalize(const VEC1 &v, VEC2 &out_v)
Normalize a vector, such as its norm is the unity.
double BASE_IMPEXP factorial(unsigned int n)
Computes the factorial of an integer number and returns it as a double value (internally it uses loga...
bool saveEigenSparseTripletsToFile(const std::string &sFile, std::vector< TRIPLET > &tri)
Saves to a plain-text file the nonzero entries of a Eigen sparse matrix, represented as a vector of t...
#define THROW_EXCEPTION(msg)
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
This CStream derived class allow using a file as a read/write binary stream, creating it if the file ...
#define MRPT_NO_THROWS
C++11 noexcept: Used after member declarations.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
std::vector< T > make_vector(const T val1,...)
A versatile template to build vectors on-the-fly in a style close to MATLAB's v=[a b c d ...
T square(const T x)
Inline function for the square of a number.
T round2up(T val)
Round up to the nearest power of two of a given number.
void linspace(T first, T last, size_t count, VECTOR &out_vector)
Generates an equidistant sequence of numbers given the first one, the last one and the desired number...
#define MRPT_COMPILE_TIME_ASSERT(f)
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.
bool BASE_IMPEXP loadVector(utils::CFileStream &f, std::vector< int > &d)
Loads one row of a text file as a numerical std::vector.
void extractColumnFromVectorOfVectors(const size_t colIndex, const VECTOR_OF_VECTORS &data, VECTORLIKE &out_column)
Extract a column from a vector of vectors, and store it in another vector.
double mean(const CONTAINER &v)
Computes the mean value of a vector.
void BASE_IMPEXP medianFilter(const std::vector< double > &inV, std::vector< double > &outV, const int &winSize, const int &numberOfSigmas=2)
A matrix of dynamic size.
T absDiff(const T &lhs, const T &rhs)
Absolute difference between two numbers.
std::string BASE_IMPEXP MATLAB_plotCovariance2D(const CMatrixFloat &cov22, const CVectorFloat &mean, const float &stdCount, const std::string &style=std::string("b"), const size_t &nEllipsePoints=30)
Generates a string with the MATLAB commands required to plot an confidence interval (ellipse) for a 2...
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
bool approximatelyEqual(T1 a, T1 b, T2 epsilon)
Compare 2 floats and determine whether they are equal.
std::vector< T > sequenceStdVec(T first, size_t length)
Generates a sequence of values [first,first+STEP,first+2*STEP,...].