43#include <visp3/core/vpConfig.h>
52#ifndef _USE_MATH_DEFINES
53#define _USE_MATH_DEFINES
59#if defined(VISP_HAVE_FUNC_ISNAN) || defined(VISP_HAVE_FUNC_STD_ISNAN) || defined(VISP_HAVE_FUNC_ISINF) || \
60 defined(VISP_HAVE_FUNC_STD_ISINF) || defined(VISP_HAVE_FUNC_STD_ROUND)
67#define M_PI 3.14159265358979323846
71#define M_PI_2 (M_PI / 2.0)
75#define M_PI_4 (M_PI / 4.0)
80#include <visp3/core/vpException.h>
81#include <visp3/core/vpImagePoint.h>
106 static inline double deg(
double rad) {
return (rad * 180.0) / M_PI; }
116 static inline double rad(
double deg) {
return (deg * M_PI) / 180.0; }
124 static inline double sqr(
double x) {
return x * x; }
127 static inline double fact(
unsigned int x);
130 static inline long double comb(
unsigned int n,
unsigned int p);
139 template <
typename T>
static inline T
clamp(
const T &v,
const T &lower,
const T &upper)
141#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
142 return std::clamp(v, lower, upper);
147 return (v < lower) ? lower : (upper < v) ? upper : v;
152 static inline int round(
double x);
155 static inline int sign(
double x);
158 static inline bool nul(
double x,
double threshold = 0.001);
161 static inline bool equal(
double x,
double y,
double threshold = 0.001);
164 static inline bool greater(
double x,
double y,
double threshold = 0.001);
172 template <
class Type>
static Type
maximum(
const Type &a,
const Type &b) {
return (a > b) ? a : b; }
180 template <
class Type>
static Type
minimum(
const Type &a,
const Type &b) {
return (a < b) ? a : b; }
187 template <
class Type>
static Type
abs(
const Type &x) {
return (x < 0) ? -x : x; }
190 static double sinc(
double x);
191 static double sinc(
double sinx,
double x);
192 static double mcosc(
double cosx,
double x);
193 static double msinc(
double sinx,
double x);
196 static inline double sigmoid(
double x,
double x0 = 0.,
double x1 = 1.,
double n = 12.);
204 template <
class Type>
static void swap(Type &a, Type &b)
211 static bool isNaN(
double value);
212 static bool isNaN(
float value);
213 static bool isInf(
double value);
214 static bool isInf(
float value);
215 static bool isFinite(
double value);
216 static bool isFinite(
float value);
217 static bool isNumber(
const std::string &str);
219 static double lineFitting(
const std::vector<vpImagePoint> &imPts,
double &a,
double &b,
double &c);
221 template <
typename _Tp>
static inline _Tp
saturate(
unsigned char v) {
return _Tp(v); }
222 template <
typename _Tp>
static inline _Tp
saturate(
char v) {
return _Tp(v); }
223 template <
typename _Tp>
static inline _Tp
saturate(
unsigned short v) {
return _Tp(v); }
224 template <
typename _Tp>
static inline _Tp
saturate(
short v) {
return _Tp(v); }
225 template <
typename _Tp>
static inline _Tp
saturate(
unsigned v) {
return _Tp(v); }
226 template <
typename _Tp>
static inline _Tp
saturate(
int v) {
return _Tp(v); }
227 template <
typename _Tp>
static inline _Tp
saturate(
float v) {
return _Tp(v); }
228 template <
typename _Tp>
static inline _Tp
saturate(
double v) {
return _Tp(v); }
230 static double getMean(
const std::vector<double> &v);
231 static double getMedian(
const std::vector<double> &v);
232 static double getStdev(
const std::vector<double> &v,
bool useBesselCorrection =
false);
234 static int modulo(
int a,
int n);
250 template <
typename T>
static std::vector<double>
linspace(T start_in, T end_in,
unsigned int num_in)
252 std::vector<double> linspaced;
254 double start =
static_cast<double>(start_in);
255 double end =
static_cast<double>(end_in);
256 double num =
static_cast<double>(num_in);
258 if (std::fabs(num) < std::numeric_limits<double>::epsilon()) {
261 if (std::fabs(num - 1) < std::numeric_limits<double>::epsilon()) {
262 linspaced.push_back(start);
266 double delta = (end - start) / (num - 1);
268 for (
int i = 0; i < num - 1; i++) {
269 linspaced.push_back(start + delta * i);
271 linspaced.push_back(end);
276 static std::vector<std::pair<double, double> > computeRegularPointsOnSphere(
unsigned int maxPoints);
277 static std::vector<vpHomogeneousMatrix>
278 getLocalTangentPlaneTransformations(
const std::vector<std::pair<double, double> > &lonlatVec,
double radius,
284 static const double ang_min_sinc;
285 static const double ang_min_mc;
296 if ((x == 1) || (x == 0))
298 return x *
fact(x - 1);
325#if defined(VISP_HAVE_FUNC_STD_ROUND)
326 return (
int)std::round(x);
327#elif defined(VISP_HAVE_FUNC_ROUND)
344 if (
fabs(x) < std::numeric_limits<double>::epsilon())
369bool vpMath::equal(
double x,
double y,
double threshold) {
return (
nul(x - y, threshold)); }
378bool vpMath::greater(
double x,
double y,
double threshold) {
return (x > (y - threshold)); }
397 double l0 = 1. / (1. +
exp(0.5 *
n));
398 double l1 = 1. / (1. +
exp(-0.5 *
n));
399 return (1. / (1. +
exp(-
n * ((x -
x0) / (x1 -
x0) - 0.5))) -
l0) / (
l1 -
l0);
410 if (std::numeric_limits<char>::is_signed)
411 return (
unsigned char)(((std::max))((
int)v, 0));
413 return (
unsigned char)((
unsigned int)v >
SCHAR_MAX ? 0 : v);
418 return (
unsigned char)((std::min))((
unsigned int)v, (
unsigned int)
UCHAR_MAX);
430 return (
unsigned char)((std::min))(v, (
unsigned int)
UCHAR_MAX);
450 return (
char)((std::min))((
unsigned int)v, (
unsigned int)
SCHAR_MAX);
485 if (std::numeric_limits<char>::is_signed)
486 return (
unsigned char)(((std::max))((
int)v, 0));
488 return (
unsigned char)((
unsigned int)v >
SCHAR_MAX ? 0 : v);
493 return (
unsigned short)((std::max))((
int)v, 0);
503 return (
unsigned short)((std::min))(v, (
unsigned int)
USHRT_MAX);
526 return (
short)((std::min))(v, (
unsigned int)
SHRT_MAX);
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Provides simple mathematics computation tools that are not available in the C mathematics library (ma...
static _Tp saturate(char v)
static void swap(Type &a, Type &b)
static double fact(unsigned int x)
static double rad(double deg)
static Type maximum(const Type &a, const Type &b)
static std::vector< double > linspace(T start_in, T end_in, unsigned int num_in)
static _Tp saturate(short v)
static _Tp saturate(double v)
static double sqr(double x)
static _Tp saturate(unsigned short v)
static bool greater(double x, double y, double threshold=0.001)
static Type abs(const Type &x)
static _Tp saturate(float v)
static bool equal(double x, double y, double threshold=0.001)
static double sigmoid(double x, double x0=0., double x1=1., double n=12.)
static _Tp saturate(unsigned v)
static T clamp(const T &v, const T &lower, const T &upper)
static bool nul(double x, double threshold=0.001)
static int round(double x)
static _Tp saturate(int v)
static Type minimum(const Type &a, const Type &b)
static int sign(double x)
static long double comb(unsigned int n, unsigned int p)
static double deg(double rad)
static _Tp saturate(unsigned char v)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Implementation of a generic rotation vector.
Implementation of a rotation vector as Euler angle minimal representation.
Class that consider the case of a translation vector.