Ponca  bab7704293a2c36e5bed9dea40def7ba839bfe08
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
34 template <class DataPoint, class _NFilter, typename T>
35 class Plane : public T, public Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim>
36 {
37 PONCA_FITTING_DECLARE_DEFAULT_TYPES
38
39 public:
41 using EigenBase = Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim>;
42
43 protected:
44 enum
45 {
46 check = Base::PROVIDES_PRIMITIVE_BASE,
47 PROVIDES_PLANE
48 };
49
50 public:
52 PONCA_MULTIARCH inline Plane() : Base(), EigenBase() { init(); }
53
54 PONCA_EXPLICIT_CAST_OPERATORS(Plane, compactPlane) //< \fixme To be removed, kept for compatibility only
55 PONCA_EXPLICIT_CAST_OPERATORS(Plane, plane)
56
58 PONCA_MULTIARCH inline void init()
59 {
60 Base::init();
61 EigenBase::coeffs().setZero();
62 }
63
67 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
68 {
69 return !EigenBase::coeffs().isApprox(EigenBase::Coefficients::Zero());
70 }
71
72 PONCA_MULTIARCH inline bool operator==(const Plane<DataPoint, NeighborFilter, T>& other) const
73 {
74 return EigenBase::isApprox(other);
75 }
76
78 PONCA_MULTIARCH inline bool operator!=(const Plane<DataPoint, NeighborFilter, T>& other) const
79 {
80 return !((*this) == other);
81 }
82
83 /* \brief Init the plane from a direction and a position
84 \param _dir Orientation of the plane, does not need to be normalized
85 \param _pos Position of the plane
86 */
87 PONCA_MULTIARCH inline void setPlane(const VectorType& _dir, const VectorType& _pos)
88 {
89 auto cc = static_cast<EigenBase*>(this);
90 *cc = EigenBase(_dir.normalized(), _pos);
91 }
92
100 PONCA_MULTIARCH inline void changeBasis(const VectorType& newbasis)
101 {
102 VectorType diff = Base::getNeighborFilter().evalPos() - newbasis;
103 Base::m_nFilter.changeNeighborhoodFrame(newbasis);
104 Base::init();
105 EigenBase::offset() -= EigenBase::normal().dot(diff);
106 }
107
110 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const
111 {
112 return EigenBase::signedDistance(VectorType::Zero());
113 }
114
117 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
118 {
119 // turn to centered basis
120 const VectorType lq = Base::getNeighborFilter().convertToLocalBasis(_q);
121 return potentialLocal(lq);
122 }
123
125 PONCA_MULTIARCH [[nodiscard]] inline VectorType project(const VectorType& _q) const
126 {
127 // Project on the normal vector and add the offset value
128 return Base::getNeighborFilter().convertToGlobalBasis(
129 EigenBase::projection(Base::getNeighborFilter().convertToLocalBasis(_q)));
130 }
131
133 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient() const
134 {
135 // Uniform gradient defined only by the orientation of the plane
136 return EigenBase::normal();
137 }
138
140 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& /*_q*/) const
141 {
142 // Uniform gradient defined only by the orientation of the plane
143 return EigenBase::normal();
144 }
145
146 protected:
148 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal(const VectorType& _lq) const
149 {
150 // The potential is the distance from the point to the plane
151 return EigenBase::signedDistance(_lq);
152 }
154 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(const VectorType& /*_lq*/) const
155 {
156 return EigenBase::normal();
157 }
158 }; // class Plane
159
160} // namespace Ponca
Implicit hyperplane defined by an homogeneous vector .
Definition plane.h:36
Eigen::Hyperplane< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::Hyperplane inherited by Ponca::Plane.
Definition plane.h:41
VectorType project(const VectorType &_q) const
Project a point on the plane.
Definition plane.h:125
bool isValid() const
Tell if the plane as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
Definition plane.h:67
typename Base::VectorType VectorType
Alias to vector type.
Definition plane.h:37
VectorType primitiveGradientLocal(const VectorType &) const
Scalar field gradient direction at the evaluation point.
Definition plane.h:154
T Base
Base class of the procedure.
Definition plane.h:37
Scalar potential(const VectorType &_q) const
Value of the scalar field at the location .
Definition plane.h:117
VectorType primitiveGradient(const VectorType &) const
Scalar field gradient direction at .
Definition plane.h:140
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition plane.h:110
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition plane.h:37
Plane< DataPoint, _NFilter, T > & plane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition plane.h:55
bool operator!=(const Plane< DataPoint, NeighborFilter, T > &other) const
Comparison operator, convenience function.
Definition plane.h:78
Plane< DataPoint, _NFilter, T > & compactPlane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition plane.h:54
Plane()
Default constructor.
Definition plane.h:52
VectorType primitiveGradient() const
Scalar field gradient direction at the evaluation point.
Definition plane.h:133
void changeBasis(const VectorType &newbasis)
Express the scalar field relatively to a new basis.
Definition plane.h:100
Scalar potentialLocal(const VectorType &_lq) const
Value of the scalar field at the evaluation point.
Definition plane.h:148
void init()
Set the scalar field values to 0.
Definition plane.h:58
This Source Code Form is subject to the terms of the Mozilla Public License, v.