Commit 0a4f1eb8 authored by Nicolas Mellado's avatar Nicolas Mellado

Grenaille::CompactPoint now inherit Eigen::Hyperplane

parent 9073ac85
......@@ -11,6 +11,7 @@
#include "primitive.h" // PrimitiveBase
#include <Eigen/Geometry>
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
(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<DataPoint, _WFunctor>
class CompactPlane : public PrimitiveBase<DataPoint, _WFunctor>,
public Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim >
typedef PrimitiveBase<DataPoint, _WFunctor> Base;
using Base = PrimitiveBase<DataPoint, _WFunctor>;
/// \brief Specialization of Eigen::Hyperplane inherited by Grenaille::CompactPlane
using EigenBase = Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim >;
......@@ -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
HVectorType m_p; /*!< \brief Homogeneous plane representation */
/*! \brief Default constructor */
MULTIARCH inline CompactPlane()
: Base()
: Base(), EigenBase()
......@@ -86,11 +79,12 @@ public:
MULTIARCH inline void resetPrimitive()
m_p = HVectorType::Zero();
EigenBase* cc = static_cast<EigenBase*>(this);
*cc = EigenBase();
MULTIARCH inline bool operator==(const CompactPlane<DataPoint, WFunctor, T>& 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<DataPoint::Dim>() = _dir.normalized();
m_p.template tail<1>()<< head<DataPoint::Dim>());
EigenBase* cc = static_cast<EigenBase*>(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<DataPoint::Dim>().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<DataPoint::Dim>();
// 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<DataPoint::Dim>();
return EigenBase::normal();
......@@ -31,7 +31,6 @@ public:
enum {Dim = 3};
typedef double Scalar;
typedef Eigen::Matrix<Scalar, Dim, 1> VectorType;
typedef Eigen::Matrix<Scalar, Dim+1, 1> HVectorType;
typedef Eigen::Matrix<Scalar, Dim, Dim> MatrixType;
MULTIARCH inline MyPoint( const VectorType& _pos = VectorType::Zero(),
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment