Ponca  8e4373a7fc557bbfb1afb9210d70f03872388d04
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
33template < class DataPoint, class _NFilter, typename T >
34class Line : public T,
35 public Eigen::ParametrizedLine<typename DataPoint::Scalar, DataPoint::Dim >
36{
37PONCA_FITTING_DECLARE_DEFAULT_TYPES
38
39public:
41 using EigenBase = Eigen::ParametrizedLine<typename DataPoint::Scalar, DataPoint::Dim >;
42
43protected:
44
45 enum
46 {
47 check = Base::PROVIDES_PRIMITIVE_BASE,
49 };
50
51public:
52 PONCA_EXPLICIT_CAST_OPERATORS(Line,line)
53
54
57 PONCA_MULTIARCH inline void init()
58 {
59 Base::init();
60 EigenBase::origin().setZero();
61 EigenBase::direction().setZero();
62 }
63
67 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const{
68 static const typename EigenBase::VectorType zeros = EigenBase::VectorType::Zero();
69 return ! ( EigenBase::origin().isApprox(zeros) && EigenBase::direction().isApprox(zeros) ) ;
70 }
71
73 PONCA_MULTIARCH inline bool operator==(const Line<DataPoint, NeighborFilter, T>& other) const{
74 return EigenBase::isApprox(other);
75 }
76
78 PONCA_MULTIARCH inline bool operator!=(const Line<DataPoint, NeighborFilter, T>& other) const{
79 return ! ((*this) == other);
80 }
81
86 PONCA_MULTIARCH inline void setLine (const VectorType& origin,
87 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::getNeighborFilter().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(EigenBase::projection(Base::getNeighborFilter().convertToLocalBasis(_q)));
129 }
130protected:
132 PONCA_MULTIARCH [[nodiscard]] inline Scalar potentialLocal (const VectorType& _lq) const {
133 // The potential is the distance from a point to the line
134 return EigenBase::squaredDistance(_lq);
135 }
136}; //class Line
137
138
139}
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.
Eigen::ParametrizedLine< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::ParametrizedLine inherited by Ponca::Line.
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.
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.
@ PROVIDES_LINE
Provides Line.
@ check
Requires PrimitiveBase.
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.