Ponca  7b3f8ad3fde25a027e6452783ccee143798a71b8
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{
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_CAST_OPERATORS(Line, line)
45 PONCA_EXPLICIT_CAST_OPERATORS(Line, implicitPrimitive)
46 PONCA_EXPLICIT_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 static 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 EigenBase::isApprox(other);
71 }
72
74 PONCA_MULTIARCH inline bool operator!=(const Line<DataPoint, NeighborFilter, T>& other) const
75 {
76 return !((*this) == other);
77 }
78
83 PONCA_MULTIARCH inline void setLine(const VectorType& origin, const VectorType& direction)
84 {
85 EigenBase* cc = static_cast<EigenBase*>(this);
87 }
88
92 PONCA_MULTIARCH inline void changeBasis(const VectorType& newbasis)
93 {
94 VectorType diff = Base::getNeighborFrame().center() - newbasis;
95 Base::m_nFilter.changeNeighborhoodFrame(newbasis);
96 Base::init();
97 EigenBase::origin() += diff;
98 }
99
102 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const
103 {
104 // The potential is the distance from a point to the line
105 return EigenBase::squaredDistance(VectorType::Zero());
106 }
107
112 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
113 {
114 // Turn to centered basis
115 const VectorType lq = Base::getNeighborFrame().convertToLocalBasis(_q);
116 // The potential is the distance from a point to the line
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::getNeighborFrame().convertToGlobalBasis(
125 EigenBase::projection(Base::getNeighborFrame().convertToLocalBasis(_q)));
126 }
127
130 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& _q) const
131 {
132 // Turn to centered basis
133 const VectorType lq = Base::getNeighborFrame().convertToLocalBasis(_q);
134 return primitiveGradientLocal(lq);
135 }
136
138 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& primitiveGradient() const { return VectorType::Zero(); }
139
140 protected:
142 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal(const VectorType& _lq) const
143 {
144 // The potential is the distance from a point to the line
145 return EigenBase::squaredDistance(_lq);
146 }
147
148 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(const VectorType& _lq) const
149 {
150 return project(_lq) - _lq;
151 }
152 }; // class Line
153} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
A parametrized line is defined by an origin point and a unit direction vector such that the line co...
const VectorType & primitiveGradient() const
Gradient of the scalar field at the line location.
Line< DataPoint, _NFilter, T > & line()
Explicit conversion to Line , to access methods potentially hidden by heritage.
Line< DataPoint, _NFilter, T > & projectionOperator()
Explicit conversion to Line , 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 Line , 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.
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