Ponca  bab7704293a2c36e5bed9dea40def7ba839bfe08
Point Cloud Analysis library
Loading...
Searching...
No Matches
linePrimitive.h
1
2/*
3 Copyright (C) 2021 aniket agarwalla <aniketagarwalla37@gmail.com>
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8*/
9
10#pragma once
11
12#include "./defines.h"
13#include <Eigen/Geometry>
14#include <Eigen/Core>
15
16namespace Ponca
17{
18
33 template <class DataPoint, class _NFilter, typename T>
34 class Line : public T, public Eigen::ParametrizedLine<typename DataPoint::Scalar, DataPoint::Dim>
35 {
36 PONCA_FITTING_DECLARE_DEFAULT_TYPES
37
38 public:
40 using EigenBase = Eigen::ParametrizedLine<typename DataPoint::Scalar, DataPoint::Dim>;
41
42 protected:
43 enum
44 {
45 check = Base::PROVIDES_PRIMITIVE_BASE,
47 };
48
49 public:
50 PONCA_EXPLICIT_CAST_OPERATORS(Line, line)
51
52
55 PONCA_MULTIARCH inline void init()
56 {
57 Base::init();
58 EigenBase::origin().setZero();
59 EigenBase::direction().setZero();
60 }
61
65 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
66 {
67 static const typename EigenBase::VectorType zeros = EigenBase::VectorType::Zero();
68 return !(EigenBase::origin().isApprox(zeros) && EigenBase::direction().isApprox(zeros));
69 }
70
72 PONCA_MULTIARCH inline bool operator==(const Line<DataPoint, NeighborFilter, T>& other) const
73 {
74 return EigenBase::isApprox(other);
75 }
76
78 PONCA_MULTIARCH inline bool operator!=(const Line<DataPoint, NeighborFilter, T>& other) const
79 {
80 return !((*this) == other);
81 }
82
87 PONCA_MULTIARCH inline void setLine(const VectorType& origin, const VectorType& direction)
88 {
89 EigenBase* cc = static_cast<EigenBase*>(this);
90 *cc = EigenBase(origin, direction);
91 }
92
96 PONCA_MULTIARCH inline void changeBasis(const VectorType& newbasis)
97 {
98 VectorType diff = Base::getNeighborFilter().evalPos() - newbasis;
99 Base::m_nFilter.changeNeighborhoodFrame(newbasis);
100 Base::init();
101 EigenBase::origin() += diff;
102 }
103
106 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const
107 {
108 // The potential is the distance from a point to the line
109 return EigenBase::squaredDistance(VectorType::Zero());
110 }
111
116 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
117 {
118 // Turn to centered basis
119 const VectorType lq = Base::getNeighborFilter().convertToLocalBasis(_q);
120 // The potential is the distance from a point to the line
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
132 protected:
134 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal(const VectorType& _lq) const
135 {
136 // The potential is the distance from a point to the line
137 return EigenBase::squaredDistance(_lq);
138 }
139 }; // class Line
140
141} // 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 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 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.
@ PROVIDES_LINE
Provides Line.
@ check
Requires PrimitiveBase.
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.