Ponca  aa50bfdf187919869239c5b44b748842569114c1
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 _WFunctor, 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(const VectorType& _basisCenter = VectorType::Zero())
58 {
59 Base::init(_basisCenter);
60 EigenBase::origin().setZero();
61 EigenBase::direction().setZero();
62 }
63
67 PONCA_MULTIARCH 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, WFunctor, T>& other) const{
74 return EigenBase::isApprox(other);
75 }
76
78 PONCA_MULTIARCH inline bool operator!=(const Line<DataPoint, WFunctor, 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
95 PONCA_MULTIARCH inline Scalar potential ( ) const
96 {
97 // The potential is the distance from a point to the line
98 return EigenBase::squaredDistance(VectorType::Zero());
99 }
100
105 PONCA_MULTIARCH inline Scalar potential (const VectorType& _q) const
106 {
107 // The potential is the distance from a point to the line
108 return EigenBase::squaredDistance(Base::m_w.convertToLocalBasis(_q));
109 }
110
112 PONCA_MULTIARCH inline VectorType project (const VectorType& _q) const
113 {
114 // Project on the normal vector and add the offset value
115 return Base::m_w.convertToGlobalBasis(EigenBase::projection(Base::m_w.convertToLocalBasis(_q)));
116 }
117}; //class Line
118
119
120}
A parametrized line is defined by an origin point and a unit direction vector such that the line co...
Definition: linePrimitive.h:36
void setLine(const VectorType &origin, const VectorType &direction)
Init the line from a direction and a position.
Definition: linePrimitive.h:86
bool isValid() const
Tell if the line as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
Definition: linePrimitive.h:67
Eigen::ParametrizedLine< typename DataPoint::Scalar, DataPoint::Dim > EigenBase
Specialization of Eigen::ParametrizedLine inherited by Ponca::Line.
Definition: linePrimitive.h:41
typename Base::VectorType VectorType
Alias to vector type.
Definition: linePrimitive.h:37
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 init(const VectorType &_basisCenter=VectorType::Zero())
Set the scalar field values to 0 and reset the distance() and origin() status.
Definition: linePrimitive.h:57
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition: linePrimitive.h:37
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition: linePrimitive.h:95
bool operator==(const Line< DataPoint, WFunctor, T > &other) const
Comparison operator.
Definition: linePrimitive.h:73
bool operator!=(const Line< DataPoint, WFunctor, T > &other) const
Comparison operator, convenience function.
Definition: linePrimitive.h:78
@ PROVIDES_LINE
Provides Line.
Definition: linePrimitive.h:48
@ check
Requires PrimitiveBase.
Definition: linePrimitive.h:47
Line< DataPoint, _WFunctor, T > & line()
Explicit conversion to Line , to access methods potentially hidden by heritage.
Definition: linePrimitive.h:52
This Source Code Form is subject to the terms of the Mozilla Public License, v.