Ponca  8e4373a7fc557bbfb1afb9210d70f03872388d04
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 _NFilter, 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(); }
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()
57 {
58 Base::init();
59 EigenBase::coeffs().setZero();
60 }
61
65 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const{
66 return ! EigenBase::coeffs().isApprox(EigenBase::Coefficients::Zero());
67 }
68
69 PONCA_MULTIARCH inline bool operator==(const Plane<DataPoint, NeighborFilter, T>& other) const{
70 return EigenBase::isApprox(other);
71 }
72
74 PONCA_MULTIARCH inline bool operator!=(const Plane<DataPoint, NeighborFilter, 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 auto cc = static_cast<EigenBase*>(this);
86 *cc = EigenBase(_dir.normalized(), _pos);
87 }
88
96 PONCA_MULTIARCH inline void changeBasis(const VectorType& newbasis)
97 {
98 VectorType diff = Base::getNeighborFilter().evalPos() - newbasis;
99 Base::getNeighborFilter().changeNeighborhoodFrame(newbasis);
100 Base::init();
101 EigenBase::offset() -= EigenBase::normal().dot(diff);
102 }
103
106 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential ( ) const
107 {
108 return EigenBase::signedDistance(VectorType::Zero());
109 }
110
113 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential (const VectorType& _q) const
114 {
115 // turn to centered basis
116 const VectorType lq = Base::getNeighborFilter().convertToLocalBasis(_q);
117 return potentialLocal( lq );
118 }
119
121 PONCA_MULTIARCH [[nodiscard]] inline VectorType project (const VectorType& _q) const
122 {
123 // Project on the normal vector and add the offset value
124 return Base::getNeighborFilter().convertToGlobalBasis(EigenBase::projection(Base::getNeighborFilter().convertToLocalBasis(_q)));
125 }
126
128 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient () const
129 {
130 // Uniform gradient defined only by the orientation of the plane
131 return EigenBase::normal();
132 }
133
135 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient (const VectorType& /*_q*/) const
136 {
137 // Uniform gradient defined only by the orientation of the plane
138 return EigenBase::normal();
139 }
140protected:
142 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal (const VectorType& _lq) const {
143 // The potential is the distance from the point to the plane
144 return EigenBase::signedDistance(_lq);
145 }
147 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal (const VectorType& /*_lq*/) const {
148 return EigenBase::normal();
149 }
150}; //class Plane
151
152}
Implicit hyperplane defined by an homogeneous vector .
Definition plane.h:37
Eigen::Hyperplane< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::Hyperplane inherited by Ponca::Plane.
Definition plane.h:42
VectorType project(const VectorType &_q) const
Project a point on the plane.
Definition plane.h:121
bool isValid() const
Tell if the plane as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
Definition plane.h:65
typename Base::VectorType VectorType
Alias to vector type.
Definition plane.h:38
VectorType primitiveGradientLocal(const VectorType &) const
Scalar field gradient direction at the evaluation point.
Definition plane.h:147
T Base
Base class of the procedure.
Definition plane.h:38
Scalar potential(const VectorType &_q) const
Value of the scalar field at the location .
Definition plane.h:113
VectorType primitiveGradient(const VectorType &) const
Scalar field gradient direction at .
Definition plane.h:135
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition plane.h:106
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition plane.h:38
Plane< DataPoint, _NFilter, T > & plane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition plane.h:53
bool operator!=(const Plane< DataPoint, NeighborFilter, T > &other) const
Comparison operator, convenience function.
Definition plane.h:74
Plane< DataPoint, _NFilter, T > & compactPlane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition plane.h:52
Plane()
Default constructor.
Definition plane.h:50
VectorType primitiveGradient() const
Scalar field gradient direction at the evaluation point.
Definition plane.h:128
void changeBasis(const VectorType &newbasis)
Express the scalar field relatively to a new basis.
Definition plane.h:96
Scalar potentialLocal(const VectorType &_lq) const
Value of the scalar field at the evaluation point.
Definition plane.h:142
void init()
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.