1 #ifndef PMPL_MP_UTILS_H_
2 #define PMPL_MP_UTILS_H_
13 #include <containers/sequential/graph/algorithms/connected_components.h>
21 #include <boost/math/special_functions/binomial.hpp>
22 #include <boost/math/special_functions/factorials.hpp>
32 #define MAX_INT std::numeric_limits<int>::max()
33 #define MAX_DBL std::numeric_limits<double>::max()
40 static constexpr T tenEpsilon = T(10) * std::numeric_limits<T>::epsilon();
41 return std::min(std::abs(_t1), std::abs(_t2)) * tenEpsilon;
61 double GRand(
bool _reset =
false);
67 void SRand(
const unsigned long _seed);
79 double TriangleHeight(
const Point3d& _a,
const Point3d& _b,
const Point3d& _c);
87 bool PtInTriangle(
const Point2d& _a,
const Point2d& _b,
const Point2d& _c,
98 bool PtInTriangle(
const Point2d& _a,
const Point2d& _b,
const Point2d& _c,
99 const Point2d& _p,
double& _u,
double& _v);
104 const Point3d& _c,
double _u,
double _v);
118 template <
typename T,
typename U>
121 const bool operator()(
const std::pair<T, U>& _a,
const std::pair<T, U>& _b)
123 return _a.second < _b.second;
133 template <
typename T,
typename U>
136 const bool operator()(
const std::pair<T, U>& _a,
const std::pair<T, U>& _b)
138 return _a.second > _b.second;
151 template<
class CfgType,
class Environment>
155 CfgType diff = _cfg1 - _cfg2;
167 template<
class CfgType>
170 const CfgType& _p2) {
171 CfgType b = _p2 - _p1;
172 CfgType c = _ref - _p1;
177 for(
auto itb = b.GetData().begin(), itc = c.GetData().begin();
178 itb != b.GetData().end(); ++itb, ++itc) {
179 bDotC += (*itb) * (*itc);
180 bSquared += (*itb) * (*itb);
185 else if(bDotC >= bSquared)
188 return b * (bDotC / bSquared) + _p1;
203 binom_test(
double _alpha,
size_t _n,
size_t _k,
double _p);
215 binomial(
size_t _n,
size_t _k,
double _p);
224 NullOutputIterator> {
241 template <
class RandomIterator,
class T,
class Compare = std::less<T>>
243 BinarySearch(RandomIterator _begin, RandomIterator _end,
const T& _value,
244 Compare _comparator = Compare()) {
248 while(start != end) {
249 const size_t mid = (size_t) (end - start) / 2;
250 RandomIterator middle = start;
251 std::advance(middle, mid);
253 if(_value == *middle)
255 if(_comparator(_value, *middle))
264 std::vector<Cfg>
LoadPath(
const std::string &_filename,
Robot* _robot);
267 template <
typename T>
CfgType ClosestPtOnLineSegment(const CfgType &_ref, const CfgType &_p1, const CfgType &_p2)
Definition: MPUtils.h:169
double TriangleHeight(const Point3d &_a, const Point3d &_b, const Point3d &_c)
Definition: MPUtils.cpp:68
RandomIterator BinarySearch(RandomIterator _begin, RandomIterator _end, const T &_value, Compare _comparator=Compare())
Definition: MPUtils.h:243
long LRand()
Definition: MPUtils.cpp:9
long MRand()
Definition: MPUtils.cpp:10
double DRand()
Definition: MPUtils.cpp:8
bool binom_test(double _alpha, size_t _n, size_t _k, double _p)
Definition: MPUtils.cpp:159
Point3d GetPtFromBarycentricCoords(const Point3d &_a, const Point3d &_b, const Point3d &_c, double _u, double _v)
Definition: MPUtils.cpp:144
double GaussianDistribution(double _mean, double _stdev)
Same as GRand, but one can specify the mean and stdev of the distribution.
Definition: MPUtils.cpp:44
double GRand(bool _reset=false)
Definition: MPUtils.cpp:13
double NormalizeTheta(double _theta)
Definition: MPUtils.cpp:151
bool IsWithinResolution(const CfgType &_cfg1, const CfgType &_cfg2, Environment *_env)
Definition: MPUtils.h:153
std::vector< Cfg > LoadPath(const std::string &_filename, Robot *_robot)
Loads a configuration path from a file for a dynamic obstacle.
Definition: MPUtils.cpp:187
double Normalize(const double &_a)
Normalize a value into the range [-1,1).
Definition: MPUtils.cpp:58
bool PtInTriangle(const Point2d &_a, const Point2d &_b, const Point2d &_c, const Point2d &_p)
Definition: MPUtils.cpp:81
double binomial(size_t _n, size_t _k, double _p)
Definition: MPUtils.cpp:178
void SRand(const unsigned long _seed)
Use seedval as the seed.
Definition: MPUtils.cpp:50
T Identity(const T &_t) noexcept
Definition: MPUtils.h:269
const T Epsilon(const T &_t1, const T &_t2)
Definition: MPUtils.h:39
Definition: Environment.h:137
double GetOrientationRes() const noexcept
Get the orientation resolution.
Definition: Environment.cpp:600
double GetPositionRes() const noexcept
Get the position resolution.
Definition: Environment.cpp:586
Definition: MPUtils.h:134
const bool operator()(const std::pair< T, U > &_a, const std::pair< T, U > &_b) const noexcept
Definition: MPUtils.h:136
Definition: MPUtils.h:119
const bool operator()(const std::pair< T, U > &_a, const std::pair< T, U > &_b) const noexcept
Definition: MPUtils.h:121
Definition: MPUtils.h:224
NullOutputIterator & operator*()
Definition: MPUtils.h:231
NullOutputIterator operator++(int)
Definition: MPUtils.h:230
void operator=(const T &)
Definition: MPUtils.h:227
NullOutputIterator & operator++()
Definition: MPUtils.h:229