From 0a4f1eb80c7f177b53909c20a6848410b3fa09cb Mon Sep 17 00:00:00 2001 From: Nicolas Mellado Date: Thu, 16 Aug 2018 12:05:31 +0200 Subject: [PATCH] Grenaille::CompactPoint now inherit Eigen::Hyperplane --- Patate/Grenaille/Core/plane.h | 53 ++++++++----------- .../Grenaille/cpp/grenaille_fit_plane.cpp | 1 - 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/Patate/Grenaille/Core/plane.h b/Patate/Grenaille/Core/plane.h index 4f45194..c64a60b 100644 --- a/Patate/Grenaille/Core/plane.h +++ b/Patate/Grenaille/Core/plane.h @@ -11,6 +11,7 @@ #define _GRENAILLE_PLANE_ #include "primitive.h" // PrimitiveBase +#include namespace Grenaille { @@ -24,28 +25,27 @@ namespace Grenaille \f$s_\mathbf{u}(\mathbf{x}) = \left[ \mathbf{x}^T \; 1 \;\right]^T \cdot \mathbf{p} \f$. - This class uses a compact storage of n+1 scalars in n-dimensionnal space. It - can be sensitive to the data scale, leading to potential instabilities - due to round errors at large scales. - \todo Add standard plane storing 2n scalars (direction and center). - + This class inherits Eigen::Hyperplane. This primitive requires the definition of n-dimensionnal vectors - (VectorType) and homogeneous n-dimensionnal vectors (HVectorType) in - Concept::PointConcept. + (VectorType) in Concept::PointConcept. This primitive provides: \verbatim PROVIDES_PLANE \endverbatim - \note The first n-components of the plane must define a normalized vector - */ template < class DataPoint, class _WFunctor, typename T = void > -class CompactPlane : public PrimitiveBase +class CompactPlane : public PrimitiveBase, + public Eigen::Hyperplane { private: - typedef PrimitiveBase Base; + using Base = PrimitiveBase; + +public: + /// \brief Specialization of Eigen::Hyperplane inherited by Grenaille::CompactPlane + using EigenBase = Eigen::Hyperplane; + protected: @@ -62,21 +62,14 @@ public: typedef typename DataPoint::VectorType VectorType; /*! \brief Matrix type inherited from DataPoint */ typedef typename DataPoint::MatrixType MatrixType; - /*! \brief Homogeneous vector type inherited from DataPoint */ - typedef typename DataPoint::HVectorType HVectorType; /*! \brief Weight Function */ typedef _WFunctor WFunctor; -// results -public: - - HVectorType m_p; /*!< \brief Homogeneous plane representation */ - public: /*! \brief Default constructor */ MULTIARCH inline CompactPlane() - : Base() + : Base(), EigenBase() { resetPrimitive(); } @@ -86,11 +79,12 @@ public: MULTIARCH inline void resetPrimitive() { Base::resetPrimitive(); - m_p = HVectorType::Zero(); + EigenBase* cc = static_cast(this); + *cc = EigenBase(); } MULTIARCH inline bool operator==(const CompactPlane& other) const{ - return m_p == other.m_p; + return EigenBase::isApprox(other); } /*! \brief Comparison operator, convenience function */ @@ -99,36 +93,35 @@ public: } /* \brief Init the plane from a direction and a position - \param _dir Orientation of the plane + \param _dir Orientation of the plane, does not need to be normalized \param _pos Position of the plane */ MULTIARCH inline void setPlane (const VectorType& _dir, const VectorType& _pos) { - m_p.template head() = _dir.normalized(); - m_p.template tail<1>()<< -_pos.dot(m_p.template head()); + EigenBase* cc = static_cast(this); + *cc = EigenBase(_dir.normalized(), _pos); } //! \brief Value of the scalar field at the location \f$\mathbf{q} \f$ MULTIARCH inline Scalar potential (const VectorType& _q) const { - // Project on the normal vector and add the offset value - return m_p.template head().dot(_q) + - *( m_p.template tail<1>().data() ); + // The potential is the distance from the point to the plane + return EigenBase::signedDistance(_q); } //! \brief Project a point on the plane MULTIARCH inline VectorType project (const VectorType& _q) const { - // The potential is the distance from the point to the plane - return _q - potential(_q) * m_p.template head(); + // Project on the normal vector and add the offset value + return EigenBase::projection(_q); } //! \brief Scalar field gradient direction at \f$\mathbf{q}\f$ MULTIARCH inline VectorType primitiveGradient (const VectorType&) const { // Uniform gradient defined only by the orientation of the plane - return m_p.template head(); + return EigenBase::normal(); } diff --git a/examples/Grenaille/cpp/grenaille_fit_plane.cpp b/examples/Grenaille/cpp/grenaille_fit_plane.cpp index e13f38e..a055789 100644 --- a/examples/Grenaille/cpp/grenaille_fit_plane.cpp +++ b/examples/Grenaille/cpp/grenaille_fit_plane.cpp @@ -31,7 +31,6 @@ public: enum {Dim = 3}; typedef double Scalar; typedef Eigen::Matrix VectorType; - typedef Eigen::Matrix HVectorType; typedef Eigen::Matrix MatrixType; MULTIARCH inline MyPoint( const VectorType& _pos = VectorType::Zero(), -- 2.22.0