Ponca  aa50bfdf187919869239c5b44b748842569114c1
Point Cloud Analysis library
Loading...
Searching...
No Matches
plane.h
1/*
2 Copyright (C) 2014 Nicolas Mellado <nmellado0@gmail.com>
3
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7*/
8
9#pragma once
10
11#include "./defines.h"
12#include <Eigen/Geometry>
13
14namespace Ponca
15{
16
34template < class DataPoint, class _WFunctor, typename T >
35class Plane : public T,
36 public Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim >
37{
38 PONCA_FITTING_DECLARE_DEFAULT_TYPES
39
40public:
42 using EigenBase = Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim >;
43
44protected:
45 enum { check = Base::PROVIDES_PRIMITIVE_BASE, PROVIDES_PLANE };
46
47public:
48
50 PONCA_MULTIARCH inline Plane() : Base(), EigenBase() { init(VectorType::Zero()); }
51
52 PONCA_EXPLICIT_CAST_OPERATORS(Plane,compactPlane) //< \fixme To be removed, kept for compatibility only
53 PONCA_EXPLICIT_CAST_OPERATORS(Plane,plane)
54
56 PONCA_MULTIARCH inline void init(const VectorType& _basisCenter = VectorType::Zero())
57 {
58 Base::init(_basisCenter);
59 EigenBase::coeffs().setZero();
60 }
61
65 PONCA_MULTIARCH inline bool isValid() const{
66 return ! EigenBase::coeffs().isApprox(EigenBase::Coefficients::Zero());
67 }
68
69 PONCA_MULTIARCH inline bool operator==(const Plane<DataPoint, WFunctor, T>& other) const{
70 return EigenBase::isApprox(other);
71 }
72
74 PONCA_MULTIARCH inline bool operator!=(const Plane<DataPoint, WFunctor, T>& other) const{
75 return ! ((*this) == other);
76 }
77
78 /* \brief Init the plane from a direction and a position
79 \param _dir Orientation of the plane, does not need to be normalized
80 \param _pos Position of the plane
81 */
82 PONCA_MULTIARCH inline void setPlane (const VectorType& _dir,
83 const VectorType& _pos)
84 {
85 EigenBase* cc = static_cast<EigenBase*>(this);
86 *cc = EigenBase(_dir.normalized(), _pos);
87 }
88
91 PONCA_MULTIARCH inline Scalar potential ( ) const
92 {
93 return EigenBase::signedDistance(VectorType::Zero());
94 }
95
98 PONCA_MULTIARCH inline Scalar potential (const VectorType& _q) const
99 {
100 // The potential is the distance from the point to the plane
101 return EigenBase::signedDistance(Base::m_w.convertToLocalBasis(_q) );
102 }
103
105 PONCA_MULTIARCH inline VectorType project (const VectorType& _q) const
106 {
107 // Project on the normal vector and add the offset value
108 return Base::m_w.convertToGlobalBasis(EigenBase::projection(Base::m_w.convertToLocalBasis(_q)));
109 }
110
112 PONCA_MULTIARCH inline VectorType primitiveGradient () const
113 {
114 // Uniform gradient defined only by the orientation of the plane
115 return EigenBase::normal();
116 }
117
119 PONCA_MULTIARCH inline VectorType primitiveGradient (const VectorType&) const
120 {
121 // Uniform gradient defined only by the orientation of the plane
122 return EigenBase::normal();
123 }
124}; //class Plane
125
126}
Implicit hyperplane defined by an homogeneous vector .
Definition: plane.h:37
Plane< DataPoint, _WFunctor, T > & plane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition: plane.h:53
Eigen::Hyperplane< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::Hyperplane inherited by Ponca::Plane.
Definition: plane.h:42
T Base
Base class of the procedure.
Definition: plane.h:38
VectorType primitiveGradient() const
Scalar field gradient direction at the evaluation point.
Definition: plane.h:112
VectorType project(const VectorType &_q) const
Project a point on the plane.
Definition: plane.h:105
Plane()
Default constructor.
Definition: plane.h:50
Plane< DataPoint, _WFunctor, T > & compactPlane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition: plane.h:52
Scalar potential(const VectorType &_q) const
Value of the scalar field at the location .
Definition: plane.h:98
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition: plane.h:38
bool isValid() const
Tell if the plane as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
Definition: plane.h:65
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition: plane.h:91
VectorType primitiveGradient(const VectorType &) const
Scalar field gradient direction at .
Definition: plane.h:119
typename Base::VectorType VectorType
Alias to vector type.
Definition: plane.h:38
bool operator!=(const Plane< DataPoint, WFunctor, T > &other) const
Comparison operator, convenience function.
Definition: plane.h:74
void init(const VectorType &_basisCenter=VectorType::Zero())
Set the scalar field values to 0.
Definition: plane.h:56
This Source Code Form is subject to the terms of the Mozilla Public License, v.