Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
Point Cloud Analysis library
Loading...
Searching...
No Matches
linePrimitive.h
1/*
2 Copyright (C) 2021 aniket agarwalla <aniketagarwalla37@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 LINE_REQUIREMENTS ProvidesBasketUnitBase<T>
16
17namespace Ponca
18{
32
33 template <class DataPoint, class _NFilter, typename T>
34 requires LINE_REQUIREMENTS
35 class Line : public T, public Eigen::ParametrizedLine<typename DataPoint::Scalar, DataPoint::Dim>
36 {
37 PONCA_FITTING_DECLARE_DEFAULT_TYPES
38
39 public:
41 using EigenBase = Eigen::ParametrizedLine<typename DataPoint::Scalar, DataPoint::Dim>;
42
43 public:
44 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(Line, line)
45 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(Line, implicitPrimitive)
46 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(Line, projectionOperator)
47
51 PONCA_MULTIARCH inline void init()
52 {
53 Base::init();
54 EigenBase::origin().setZero();
55 EigenBase::direction().setZero();
56 }
57
61 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
62 {
63 const typename EigenBase::VectorType zeros = EigenBase::VectorType::Zero();
64 return !(EigenBase::origin().isApprox(zeros) && EigenBase::direction().isApprox(zeros));
65 }
66
68 PONCA_MULTIARCH inline bool operator==(const Line<DataPoint, NeighborFilter, T>& other) const
69 {
70 return Base::operator==(other) && internal::isApprox(EigenBase::origin(), other.origin()) &&
71 internal::isApprox(EigenBase::direction(), other.direction());
72 }
73
75 PONCA_MULTIARCH inline bool operator!=(const Line<DataPoint, NeighborFilter, T>& other) const
76 {
77 return !((*this) == other);
78 }
79
84 PONCA_MULTIARCH inline void setLine(const VectorType& origin, const VectorType& direction)
85 {
86 EigenBase* cc = static_cast<EigenBase*>(this);
87 *cc = EigenBase(origin, direction);
88 }
89
93 PONCA_MULTIARCH inline void changeBasis(const VectorType& newbasis)
94 {
95 VectorType diff = Base::getNeighborFrame().center() - newbasis;
96 Base::m_nFilter.changeNeighborhoodFrame(newbasis);
97 Base::init();
98 EigenBase::origin() += diff;
99 }
100
103 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const
104 {
105 // The potential is the distance from a point to the line
106 return EigenBase::squaredDistance(VectorType::Zero());
107 }
108
113 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
114 {
115 // Turn to centered basis
116 const VectorType lq = Base::getNeighborFrame().convertToLocalBasis(_q);
117 // The potential is the distance from a point to the line
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
131 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& _q) const
132 {
133 // Turn to centered basis
134 const VectorType lq = Base::getNeighborFrame().convertToLocalBasis(_q);
135 return primitiveGradientLocal(lq);
136 }
137
139 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient() const { return VectorType::Zero(); }
140
141 protected:
143 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal(const VectorType& _lq) const
144 {
145 // The potential is the distance from a point to the line
146 return EigenBase::squaredDistance(_lq);
147 }
148
149 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(const VectorType& _lq) const
150 {
151 return project(_lq) - _lq;
152 }
153 }; // class Line
154} // namespace Ponca
A parametrized line is defined by an origin point and a unit direction vector such that the line co...
Line< DataPoint, _NFilter, T > & line()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Line< DataPoint, _NFilter, T > & projectionOperator()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Scalar potentialLocal(const VectorType &_lq) const
Value of the scalar field at the evaluation point.
Scalar potential() const
Value of the scalar field at the evaluation point.
void changeBasis(const VectorType &newbasis)
Express the line relatively to a new basis.
void init()
Set the scalar field values to 0 and reset the distance() and origin() status.
bool operator==(const Line< DataPoint, NeighborFilter, T > &other) const
Comparison operator.
VectorType primitiveGradient(const VectorType &_q) const
Approximation of the scalar field gradient at .
Line< DataPoint, _NFilter, T > & implicitPrimitive()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
VectorType project(const VectorType &_q) const
Project a point on the line.
Scalar potential(const VectorType &_q) const
Value of the scalar field at the location , defined as the squared distance between and the line.
void setLine(const VectorType &origin, const VectorType &direction)
Init the line from a direction and a position.
Eigen::ParametrizedLine< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::ParametrizedLine inherited by Ponca::Line.
typename DataPoint::Scalar Scalar
Alias to scalar type.
bool operator!=(const Line< DataPoint, NeighborFilter, T > &other) const
Comparison operator, convenience function.
typename Base::VectorType VectorType
Alias to vector type.
VectorType primitiveGradient() const
Gradient of the scalar field at the line location.
bool isValid() const
Tell if the line as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11