Ponca  4d2a58fa5c6375adef5c4b208f4d47e016cecd6d
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#include "../../defines.h"
11#include "../concepts.h"
12
13#include <Eigen/Geometry>
14
15#define PLANE_REQUIREMENTS ProvidesBasketUnitBase<T>
16
17namespace Ponca
18{
36 template <class DataPoint, class _NFilter, typename T>
37 requires PLANE_REQUIREMENTS
38 class Plane : public T, public Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim>
39 {
40 PONCA_FITTING_DECLARE_DEFAULT_TYPES
41
42 public:
44 using EigenBase = Eigen::Hyperplane<typename DataPoint::Scalar, DataPoint::Dim>;
45
46 public:
48 PONCA_MULTIARCH inline Plane() : Base(), EigenBase() { init(); }
49
50 PONCA_EXPLICIT_CAST_OPERATORS(Plane, plane)
51 PONCA_EXPLICIT_CAST_OPERATORS(Plane, implicitPrimitive)
52 PONCA_EXPLICIT_CAST_OPERATORS(Plane, projectionOperator)
53
55 PONCA_MULTIARCH inline void init()
56 {
57 Base::init();
58 EigenBase::coeffs().setZero();
59 }
60
64 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
65 {
66 return !EigenBase::coeffs().isApprox(EigenBase::Coefficients::Zero());
67 }
68
69 PONCA_MULTIARCH inline bool operator==(const Plane<DataPoint, NeighborFilter, T>& other) const
70 {
71 return EigenBase::isApprox(other);
72 }
73
75 PONCA_MULTIARCH inline bool operator!=(const Plane<DataPoint, NeighborFilter, T>& other) const
76 {
77 return !((*this) == other);
78 }
79
80 /* \brief Init the plane from a direction and a position
81 \param _dir Orientation of the plane, does not need to be normalized
82 \param _pos Position of the plane
83 */
84 PONCA_MULTIARCH inline void setPlane(const VectorType& _dir, const VectorType& _pos)
85 {
86 auto cc = static_cast<EigenBase*>(this);
87 *cc = EigenBase(_dir.normalized(), _pos);
88 }
89
97 PONCA_MULTIARCH inline void changeBasis(const VectorType& newbasis)
98 {
99 VectorType diff = Base::getNeighborFrame().center() - newbasis;
100 Base::m_nFilter.changeNeighborhoodFrame(newbasis);
101 Base::init();
102 EigenBase::offset() -= EigenBase::normal().dot(diff);
103 }
104
107 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const
108 {
109 return EigenBase::signedDistance(VectorType::Zero());
110 }
111
114 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
115 {
116 // turn to centered basis
117 const VectorType lq = Base::getNeighborFrame().convertToLocalBasis(_q);
118 return potentialLocal(lq);
119 }
120
122 PONCA_MULTIARCH [[nodiscard]] inline VectorType project(const VectorType& _q) const
123 {
124 // Project on the normal vector and add the offset value
125 return Base::getNeighborFrame().convertToGlobalBasis(
126 EigenBase::projection(Base::getNeighborFrame().convertToLocalBasis(_q)));
127 }
128
130 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient() const
131 {
132 // Uniform gradient defined only by the orientation of the plane
133 return EigenBase::normal();
134 }
135
137 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& /*_q*/) const
138 {
139 // Uniform gradient defined only by the orientation of the plane
140 return EigenBase::normal();
141 }
142
143 protected:
145 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal(const VectorType& _lq) const
146 {
147 // The potential is the distance from the point to the plane
148 return EigenBase::signedDistance(_lq);
149 }
150
152 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(const VectorType& /*_lq*/) const
153 {
154 return EigenBase::normal();
155 }
156 }; // class Plane
157} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:260
Implicit hyperplane defined by an homogeneous vector .
Definition plane.h:39
Eigen::Hyperplane< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::Hyperplane inherited by Ponca::Plane.
Definition plane.h:44
VectorType project(const VectorType &_q) const
Project a point on the plane.
Definition plane.h:122
bool isValid() const
Tell if the plane as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
Definition plane.h:64
typename Base::VectorType VectorType
Alias to vector type.
Definition plane.h:40
VectorType primitiveGradientLocal(const VectorType &) const
Scalar field gradient direction at the evaluation point.
Definition plane.h:152
T Base
Base class of the procedure.
Definition plane.h:40
Plane< DataPoint, _NFilter, T > & projectionOperator()
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:114
Plane< DataPoint, _NFilter, T > & implicitPrimitive()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition plane.h:51
VectorType primitiveGradient(const VectorType &) const
Scalar field gradient direction at .
Definition plane.h:137
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition plane.h:107
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition plane.h:40
Plane< DataPoint, _NFilter, T > & plane()
Explicit conversion to Plane , to access methods potentially hidden by heritage.
Definition plane.h:50
bool operator!=(const Plane< DataPoint, NeighborFilter, T > &other) const
Comparison operator, convenience function.
Definition plane.h:75
Plane()
Default constructor.
Definition plane.h:48
VectorType primitiveGradient() const
Scalar field gradient direction at the evaluation point.
Definition plane.h:130
void changeBasis(const VectorType &newbasis)
Express the scalar field relatively to a new basis.
Definition plane.h:97
Scalar potentialLocal(const VectorType &_lq) const
Value of the scalar field at the evaluation point.
Definition plane.h:145
void init()
Set the scalar field values to 0.
Definition plane.h:55
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11