Ponca  8e4373a7fc557bbfb1afb9210d70f03872388d04
Point Cloud Analysis library
Loading...
Searching...
No Matches
weightKernel.h
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6#pragma once
7
8#include "./defines.h"
9#include PONCA_MULTIARCH_INCLUDE_CU_STD(cmath)
10
16namespace Ponca
17{
23template <typename _Scalar>
25{
26public:
28 typedef _Scalar Scalar;
29
32 static constexpr bool isCompact = true;
33
34 // Init
36 PONCA_MULTIARCH inline ConstantWeightKernel(const Scalar& _value = Scalar(1.)) : m_y(_value){}
38 PONCA_MULTIARCH inline void setValue(const Scalar& _value){ m_y = _value; }
39
40 // Functor
42 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar&) const { return m_y; }
44 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar&) const { return Scalar(0.); }
46 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar&) const { return Scalar(0.); }
47
49 static constexpr bool isDValid = true;
51 static constexpr bool isDDValid = true;
52
53private:
54 Scalar m_y;
55};// class ConstantWeightKernel
56
57
64template <typename _Scalar>
66{
67public:
69 typedef _Scalar Scalar;
70
72 static constexpr bool isCompact = true;
73
74 // Functor
76 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar& _x) const { Scalar v = _x*_x - Scalar(1.); return v*v; }
78 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar& _x) const { return Scalar(4.)*_x*(_x*_x-Scalar(1.)); }
80 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const { return Scalar(12.)*_x*_x - Scalar(4.); }
82 static constexpr bool isDValid = true;
84 static constexpr bool isDDValid = true;
85};//class SmoothWeightKernel
86
92template <typename _Scalar, int m, int n>
94{
95public:
97 typedef _Scalar Scalar;
98
100 static constexpr bool isCompact = true;
101
102 // Functor
104 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar& _x) const {
105 PONCA_MULTIARCH_STD_MATH(pow);
106 return pow(
107 pow(_x, Scalar(n)) - Scalar(1.),
108 Scalar(m)
109 );
110 }
112 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar& _x) const {
113 PONCA_MULTIARCH_STD_MATH(pow);
114 return pow(
115 Scalar(m*n)*_x,
116 Scalar(n-1)) * pow(pow(_x, Scalar(n)) -1, Scalar(m-1)
117 );
118 }
120 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const {
121 PONCA_MULTIARCH_STD_MATH(pow);
122 return Scalar((m-1)*m*n*n)
123 * pow( _x, Scalar(2*n-2))
124 * pow(
125 pow(_x, Scalar(n))-Scalar(1),
126 Scalar(m-2)
127 )
128 + Scalar(m*(n-1)*n)
129 * pow(
130 _x,
131 Scalar(n-2)
132 )
133 * pow(
134 pow(_x, Scalar(n))-Scalar(1),
135 Scalar(m-1)
136 );
137 }
139 static constexpr bool isDValid = true;
141 static constexpr bool isDDValid = true;
142};//class PolynomialSmoothWeightKernel
143
151template <typename _Scalar>
153{
154public:
156 typedef _Scalar Scalar;
157
159 static constexpr bool isCompact = true;
160
161 // Functor
163 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar& _x) const {
164 const Scalar v = Scalar(1.) - _x;
165 return v * v * v * v * ((Scalar(4.) * _x) + Scalar(1.));
166 }
168 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar& _x) const {
169 const Scalar v = _x - Scalar(1.);
170 return Scalar(20.) * _x * v * v * v;
171 }
173 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const {
174 const Scalar v = _x - Scalar(1.);
175 return v * v * (Scalar(80.) * _x - Scalar(20));
176 }
178 static constexpr bool isDValid = true;
180 static constexpr bool isDDValid = true;
181};//class WendlandWeightKernel
182
183
192template <typename _Scalar>
194{
195public:
197 typedef _Scalar Scalar;
198
200 static constexpr bool isCompact = true;
201
202 // Functor
204 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar& _x) const {
205 return Scalar(1.) / (_x * _x);
206 }
208 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar& _x) const {
209 return Scalar(-2.) / (_x * _x * _x);
210 }
212 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const {
213 return Scalar(6.) / (_x * _x * _x * _x);
214 }
216 static constexpr bool isDValid = true;
218 static constexpr bool isDDValid = true;
219};//class SingularWeightKernel
220
221
231template <typename _Scalar>
233{
234public:
236 typedef _Scalar Scalar;
237
239 static constexpr bool isCompact = true;
240
241 // Functor
245 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar& _x) const {
246 PONCA_MULTIARCH_STD_MATH(exp);
247 Scalar v = _x*_x;
248 return exp(-v/(Scalar(1)-v));
249 }
253 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar& _x) const {
254 PONCA_MULTIARCH_STD_MATH(exp);
255 Scalar v = _x*_x; Scalar mv = v-Scalar(1); return -(Scalar(2) * exp(v/mv) * _x)/(mv*mv);
256 }
261 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const {
262 PONCA_MULTIARCH_STD_MATH(exp);
263 PONCA_MULTIARCH_STD_MATH(pow);
264 Scalar v = _x*_x; // x^2
265 Scalar mv = v-Scalar(1); // x^2-1
266 Scalar mvpow = Scalar(2)/mv; // 2/(x^2-1)
267 Scalar cmvpow = pow(_x,mvpow); // x^{2/(x^2-1)}
268 return Scalar(2) * exp(cmvpow) * ((Scalar(4) * pow(_x,mvpow + Scalar(2)) * log(_x) - mv * (-Scalar(3) * v + Scalar(2) * cmvpow - Scalar(1))))/(mv*mv*mv*mv);
269 }
270
272 static constexpr bool isDValid = true;
274 static constexpr bool isDDValid = false;
275};//class CompactExpWeightKernel
276
290 template <typename _Scalar>
292 {
293 public:
295 typedef _Scalar Scalar;
296
298 static constexpr bool isCompact = false;
299
306 PONCA_MULTIARCH [[nodiscard]] inline Scalar f (const Scalar& _x) const {
307 PONCA_MULTIARCH_STD_MATH(exp);
308 return exp((-_x*_x)/Scalar(2));
309 }
310
312 PONCA_MULTIARCH [[nodiscard]] inline Scalar df (const Scalar& _x) const {
313 return - f(_x)*_x;
314 }
316 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const {
317 return f(_x)*(_x*_x-Scalar(1));
318 }
320 static constexpr bool isDValid = true;
322 static constexpr bool isDDValid = true;
323 };//class GaussianWeightKernel
324
325}// namespace Ponca
Compact Exponential WeightKernel defined in .
static constexpr bool isCompact
The kernel is compact and shall not be evaluated outside of the scale bounds.
Scalar f(const Scalar &_x) const
Defines the smooth weighting function .
static constexpr bool isDValid
df is defined and valid on the definition interval
static constexpr bool isDDValid
ddf is not defined and valid on the definition interval
Scalar ddf(const Scalar &_x) const
Defines the smooth second order weighting function .
_Scalar Scalar
Scalar type defined outside the class.
Scalar df(const Scalar &_x) const
Defines the smooth first order weighting function .
Concept::WeightKernelConcept returning a constant value.
static constexpr bool isCompact
The kernel is compact and shall not be evaluated outside of the scale bounds.
static constexpr bool isDDValid
ddf is defined and valid on the definition interval
Scalar df(const Scalar &) const
Return .
Scalar ddf(const Scalar &) const
Return .
Scalar f(const Scalar &) const
Return the constant value.
static constexpr bool isDValid
df is defined and valid on the definition interval
void setValue(const Scalar &_value)
Set the returned value.
_Scalar Scalar
Scalar type defined outside the class.
ConstantWeightKernel(const Scalar &_value=Scalar(1.))
Default constructor that could be used to set the returned value.
Non-compact Gaussian WeightKernel.
static constexpr bool isCompact
The kernel is not compact and can be evaluated outside of the scale bounds.
static constexpr bool isDDValid
ddf is defined and valid on the definition interval
Scalar ddf(const Scalar &_x) const
Defines the Gaussian weighting function second order derivative .
Scalar f(const Scalar &_x) const
Defines the Gaussian weighting function .
Scalar df(const Scalar &_x) const
Defines the Gaussian weighting function first order derivative .
_Scalar Scalar
Scalar type defined outside the class.
static constexpr bool isDValid
df is defined and valid on the definition interval
Compact generalised version of SmoothWeightKernel with arbitrary degrees : .
static constexpr bool isDValid
df is defined and valid on the definition interval
_Scalar Scalar
Scalar type defined outside the class.
Scalar df(const Scalar &_x) const
Defines the smooth first order weighting function .
static constexpr bool isCompact
The kernel is compact and shall not be evaluated outside of the scale bounds.
Scalar ddf(const Scalar &_x) const
Defines the smooth second order weighting function .
static constexpr bool isDDValid
ddf is defined and valid on the definition interval
Scalar f(const Scalar &_x) const
Defines the smooth weighting function .
Compact singular WeightKernel defined in .
Scalar ddf(const Scalar &_x) const
Defines the Singular second order weighting function .
static constexpr bool isDDValid
ddf is defined and valid on the definition interval
Scalar df(const Scalar &_x) const
Defines the Singular first order weighting function .
Scalar f(const Scalar &_x) const
Defines the Singular weighting function .
_Scalar Scalar
Scalar type defined outside the class.
static constexpr bool isCompact
The kernel is compact and shall not be evaluated outside of the scale bounds.
static constexpr bool isDValid
df is defined and valid on the definition interval
Compact smooth WeightKernel of 2nd degree, defined in Special case of PolynomialSmoothWeightKernel<S...
Scalar df(const Scalar &_x) const
Defines the smooth first order weighting function .
Scalar f(const Scalar &_x) const
Defines the smooth weighting function .
static constexpr bool isDValid
df is defined and valid on the definition interval
static constexpr bool isCompact
The kernel is compact and shall not be evaluated outside of the scale bounds.
static constexpr bool isDDValid
ddf is defined and valid on the definition interval
Scalar ddf(const Scalar &_x) const
Defines the smooth second order weighting function .
_Scalar Scalar
Scalar type defined outside the class.
Compact Wendland WeightKernel defined in .
_Scalar Scalar
Scalar type defined outside the class.
static constexpr bool isDValid
df is defined and valid on the definition interval
static constexpr bool isDDValid
ddf is defined and valid on the definition interval
Scalar df(const Scalar &_x) const
Defines the Wendland first order weighting function .
Scalar ddf(const Scalar &_x) const
Defines the Wendland second order weighting function .
static constexpr bool isCompact
The kernel is compact and shall not be evaluated outside of the scale bounds.
Scalar f(const Scalar &_x) const
Defines the Wendland weighting function .
This Source Code Form is subject to the terms of the Mozilla Public License, v.