10 #ifndef ApproxMVBB_PointFunctions_hpp 11 #define ApproxMVBB_PointFunctions_hpp 16 #include ApproxMVBB_AssertionDebug_INCLUDE_FILE 17 #include ApproxMVBB_StaticAssert_INCLUDE_FILE 19 #include ApproxMVBB_TypeDefs_INCLUDE_FILE 28 namespace PointFunctions {
33 template<
typename Derived,
typename Gen>
35 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3, Eigen::Dynamic)
37 q.coeffs() = q.coeffs().unaryExpr(g);
41 trans = trans.unaryExpr(g);
43 points.colwise() += trans;
46 template<
typename Derived>
49 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3, Eigen::Dynamic)
51 q.coeffs().setRandom();
57 points.colwise() += trans;
62 template<
typename VecT1,
typename VecT2>
63 inline bool almostEqualAbs(
const VecT1 & a,
const VecT2 & b, PREC eps = 1.0e-8 ) {
64 return ((a-b).array().abs() <= eps).all();
67 template<
typename VecT1,
typename VecT2>
70 for(
unsigned int i=0;i<a.size();i++){
77 template<
typename VecT1,
typename VecT2>
78 inline bool equal(
const VecT1 & a,
const VecT2 & b) {
79 return (a.array() == b.array()).all();
83 template<
typename VecT1,
typename VecT2,
typename VecT3>
84 inline int orient2d(
const VecT1 & a,
const VecT2 & b,
const VecT3 & c) {
85 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT1,2)
86 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT2,2)
87 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT3,2)
90 const_cast<double*>(b.data()),
91 const_cast<double*>(c.data()));
93 return ( ( f_A < 0.0 )? -1 : ( (f_A > 0.0)? 1 : 0) );
98 template<
typename VecT1,
typename VecT2,
typename VecT3>
99 inline bool leftTurn(
const VecT1 & a,
const VecT2 & b,
const VecT3 & c) {
100 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT1,2)
101 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT2,2)
102 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT3,2)
107 template<
typename VecT1,
typename VecT2,
typename VecT3>
109 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT1,2)
110 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT2,2)
111 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT3,2)
113 if (a(0) < b(0))
return !(c(0) < b(0));
114 if (b(0) < a(0))
return !(b(0) < c(0));
115 if (a(1) < b(1))
return !(c(1) < b(1));
116 if (b(1) < a(1))
return !(b(1) < c(1));
124 template<
typename VecT1,
typename VecT2>
125 inline PREC
getAngle(
const VecT1 & a,
const VecT2 & b) {
126 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT1,2)
127 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT2,2)
129 PREC angle = std::atan2(t(1),t(0));
136 template<
typename VecT1,
typename VecT2>
138 const VecT2 & p2, PREC ang2, PREC eps = 1e-10) {
139 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT1,2)
140 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VecT2,2)
155 PREC nom = (p1(0)-p2(0))*by - (p1(1)-p2(1)) *bx;
157 PREC det = a(1)*bx - a(0)*by;
160 if(abs(nom) < eps ) {
163 a(0) = std::numeric_limits<PREC>::infinity();
164 a(1) = std::numeric_limits<PREC>::infinity();
168 return (nom / det) *a + p1;
172 template<
typename Derived>
173 inline unsigned int minPointYX(
const MatrixBase<Derived> & points) {
174 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,2, Eigen::Dynamic)
175 unsigned int index = 0;
176 for(
unsigned int i=1; i<points.cols(); ++i) {
177 if( points(1,i) < points(1,index) ) {
179 }
else if( points(1,i) == points(1,index) && points(0,i) < points(0,index) ) {
187 template<
typename Derived>
188 inline unsigned int minPointXY(
const MatrixBase<Derived> & points) {
189 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,2, Eigen::Dynamic)
190 unsigned int index = 0;
191 for(
unsigned int i=1; i<points.cols(); ++i) {
192 if( points(0,i) < points(0,index) ) {
194 }
else if( points(0,i) == points(0,index) && points(1,i) < points(1,index) ) {
201 template<
unsigned int Dimension,
209 ApproxMVBB_STATIC_ASSERTM((std::is_same<typename Derived::Scalar, PREC>::value),
"estimate diameter can only accept double so far")
214 auto size = points.cols();
215 PREC
const * *pList =
new PREC
const*[size];
216 for(decltype(size) i=0; i<size; ++i) {
217 pList[i] = points.col(i).data() ;
222 diamEstimator.
estimateDiameter(&pairP,pList,0,(
int)(size-1),Dimension,epsilon);
225 const MatrixMap<const Vector2d> p1(pairP.
extremity1);
226 const MatrixMap<const Vector2d> p2(pairP.
extremity2);
231 <<
"p2: " << p2.transpose() << std::endl
241 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
250 template<
typename Derived>
253 unsigned int baseIdx,
254 unsigned int & deletedPoints): m_p(points), m_base(base),m_baseIdx(baseIdx), m_deletedPoints(deletedPoints) {
255 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,2, Eigen::Dynamic)
262 using namespace PointFunctions;
265 unsigned int idx1 = point1.first;
266 unsigned int idx2 = point2.first;
283 int sgn =
orient2d( m_base, m_p.col(idx1), m_p.col(idx2) );
284 if(sgn != 0){
return (sgn > 0);}
286 int sgn =
orient2d( m_base, m_p.col(idx2), m_p.col(idx1) );
287 if(sgn != 0) {
return (sgn < 0);}
300 const MatrixRef<const Matrix2Dyn>
m_p;
bool almostEqualAbs(const VecT1 &a, const VecT2 &b, PREC eps=1.0e-8)
Eigen::Quaternion< Scalar > Quaternion
unsigned int minPointXY(const MatrixBase< Derived > &points)
unsigned int minPointYX(const MatrixBase< Derived > &points)
Eigen::Matrix< Scalar, M, 1 > VectorStat
These are some container definitions.
double const * extremity2
double estimateDiameter(Diameter::TypeSegment *theDiam, double const **theList, const int first, const int last, const int dim, double epsilon)
bool almostEqualUlp(const VecT1 &a, const VecT2 &b)
unsigned int & m_deletedPoints
std::pair< unsigned int, bool > PointData
REAL orient2d(REAL *pa, REAL *pb, REAL *pc)
int orient2d(const VecT1 &a, const VecT2 &b, const VecT3 &c)
CompareByAngle(const MatrixBase< Derived > &points, const Vector2 &base, unsigned int baseIdx, unsigned int &deletedPoints)
bool equal(const VecT1 &a, const VecT2 &b)
static const uint64_t defaultSeed
Eigen::Matrix< Scalar, 3, 3 > Matrix33
int operator()(const PointData &point1In, const PointData &point2In)
const MatrixRef< const Matrix2Dyn > m_p
#define ApproxMVBB_DEFINE_POINTS_CONFIG_TYPES
bool leftTurn(const VecT1 &a, const VecT2 &b, const VecT3 &c)
#define ApproxMVBB_MSGLOG_L2(message)
Eigen::Matrix< Scalar, 2, 1 > Vector2
Vector2 intersectLines(const VecT1 &p1, PREC ang1, const VecT2 &p2, PREC ang2, PREC eps=1e-10)
double const * extremity1
Eigen::Matrix< Scalar, 3, 1 > Vector3
const unsigned int m_baseIdx
#define ApproxMVBB_STATIC_ASSERTM(B, COMMENT)
auto estimateDiameter(const MatrixBase< Derived > &points, const PREC epsilon, std::size_t seed=RandomGenerators::defaultSeed) -> std::pair< VectorStat< Dimension >, VectorStat< Dimension > >
#define ApproxMVBB_DEFINE_MATRIX_TYPES
PREC getAngle(const VecT1 &a, const VecT2 &b)
ApproxMVBB_DEFINE_MATRIX_TYPES ApproxMVBB_DEFINE_POINTS_CONFIG_TYPES void applyRandomRotTrans(MatrixBase< Derived > &points, Gen &g)
int collinearAreOrderedAlongLine(const VecT1 &a, const VecT2 &b, const VecT3 &c)