Ponca  4cffe9d86bf544d7691ffcacd98b5202d7de2aab
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
15namespace Ponca
16{
22 template <typename _Scalar>
24 {
25 public:
27 using Scalar = _Scalar;
28
31 static constexpr bool isCompact = true;
32
33 // Init
35 PONCA_MULTIARCH inline ConstantWeightKernel(const Scalar& _value = Scalar(1.)) : m_y(_value) {}
37 PONCA_MULTIARCH inline void setValue(const Scalar& _value) { m_y = _value; }
38
39 // Functor
41 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar&) const { return m_y; }
43 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar&) const { return Scalar(0.); }
45 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar&) const { return Scalar(0.); }
46
48 static constexpr bool isDValid = true;
50 static constexpr bool isDDValid = true;
51
52 private:
53 Scalar m_y;
54 }; // class ConstantWeightKernel
55
62 template <typename _Scalar>
64 {
65 public:
67 using Scalar = _Scalar;
68
70 static constexpr bool isCompact = true;
71
72 // Functor
74 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar& _x) const
75 {
76 Scalar v = _x * _x - Scalar(1.);
77 return v * v;
78 }
80 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar& _x) const
81 {
82 return Scalar(4.) * _x * (_x * _x - Scalar(1.));
83 }
85 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const
86 {
87 return Scalar(12.) * _x * _x - Scalar(4.);
88 }
90 static constexpr bool isDValid = true;
92 static constexpr bool isDDValid = true;
93 }; // class SmoothWeightKernel
94
100 template <typename _Scalar, int m, int n>
102 {
103 public:
106
108 static constexpr bool isCompact = true;
109
110 // Functor
112 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar& _x) const
113 {
114 PONCA_MULTIARCH_STD_MATH(pow);
115 return pow(pow(_x, Scalar(n)) - Scalar(1.), Scalar(m));
116 }
119 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar& _x) const
120 {
121 PONCA_MULTIARCH_STD_MATH(pow);
122 return pow(Scalar(m * n) * _x, Scalar(n - 1)) * pow(pow(_x, Scalar(n)) - 1, Scalar(m - 1));
123 }
126 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const
127 {
128 PONCA_MULTIARCH_STD_MATH(pow);
129 return Scalar((m - 1) * m * n * n) * pow(_x, Scalar(2 * n - 2)) *
130 pow(pow(_x, Scalar(n)) - Scalar(1), Scalar(m - 2)) +
131 Scalar(m * (n - 1) * n) * pow(_x, Scalar(n - 2)) *
132 pow(pow(_x, Scalar(n)) - Scalar(1), Scalar(m - 1));
133 }
135 static constexpr bool isDValid = true;
137 static constexpr bool isDDValid = true;
138 }; // class PolynomialSmoothWeightKernel
139
147 template <typename _Scalar>
149 {
150 public:
153
155 static constexpr bool isCompact = true;
156
157 // Functor
159 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar& _x) const
160 {
161 const Scalar v = Scalar(1.) - _x;
162 return v * v * v * v * ((Scalar(4.) * _x) + Scalar(1.));
163 }
165 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar& _x) const
166 {
167 const Scalar v = _x - Scalar(1.);
168 return Scalar(20.) * _x * v * v * v;
169 }
171 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const
172 {
173 const Scalar v = _x - Scalar(1.);
174 return v * v * (Scalar(80.) * _x - Scalar(20));
175 }
177 static constexpr bool isDValid = true;
179 static constexpr bool isDDValid = true;
180 }; // class WendlandWeightKernel
181
191 template <typename _Scalar>
193 {
194 public:
197
199 static constexpr bool isCompact = true;
200
201 // Functor
203 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar& _x) const { return Scalar(1.) / (_x * _x); }
205 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar& _x) const { return Scalar(-2.) / (_x * _x * _x); }
207 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const
208 {
209 return Scalar(6.) / (_x * _x * _x * _x);
210 }
212 static constexpr bool isDValid = true;
214 static constexpr bool isDDValid = true;
215 }; // class SingularWeightKernel
216
227 template <typename _Scalar>
229 {
230 public:
233
235 static constexpr bool isCompact = true;
236
237 // Functor
242 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar& _x) const
243 {
244 PONCA_MULTIARCH_STD_MATH(exp);
245 Scalar v = _x * _x;
246 return exp(-v / (Scalar(1) - v));
247 }
253 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar& _x) const
254 {
255 PONCA_MULTIARCH_STD_MATH(exp);
256 Scalar v = _x * _x;
257 Scalar mv = v - Scalar(1);
258 return -(Scalar(2) * exp(v / mv) * _x) / (mv * mv);
259 }
266 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const
267 {
268 PONCA_MULTIARCH_STD_MATH(exp);
269 PONCA_MULTIARCH_STD_MATH(pow);
270 Scalar v = _x * _x; // x^2
271 Scalar mv = v - Scalar(1); // x^2-1
272 Scalar mvpow = Scalar(2) / mv; // 2/(x^2-1)
273 Scalar cmvpow = pow(_x, mvpow); // x^{2/(x^2-1)}
274 return Scalar(2) * exp(cmvpow) *
275 ((Scalar(4) * pow(_x, mvpow + Scalar(2)) * log(_x) -
276 mv * (-Scalar(3) * v + Scalar(2) * cmvpow - Scalar(1)))) /
277 (mv * mv * mv * mv);
278 }
279
281 static constexpr bool isDValid = true;
283 static constexpr bool isDDValid = false;
284 }; // class CompactExpWeightKernel
285
300 template <typename _Scalar>
302 {
303 public:
306
308 static constexpr bool isCompact = false;
309
316 PONCA_MULTIARCH [[nodiscard]] inline Scalar f(const Scalar& _x) const
317 {
318 PONCA_MULTIARCH_STD_MATH(exp);
319 return exp((-_x * _x) / Scalar(2));
320 }
321
323 PONCA_MULTIARCH [[nodiscard]] inline Scalar df(const Scalar& _x) const { return -f(_x) * _x; }
326 PONCA_MULTIARCH [[nodiscard]] inline Scalar ddf(const Scalar& _x) const
327 {
328 return f(_x) * (_x * _x - Scalar(1));
329 }
331 static constexpr bool isDValid = true;
333 static constexpr bool isDDValid = true;
334 }; // class GaussianWeightKernel
335
336} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:318
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 df(const Scalar &_x) const
Defines the smooth first order weighting function .
_Scalar Scalar
Scalar type defined outside the class.
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
_Scalar Scalar
Scalar type defined outside the class.
void setValue(const Scalar &_value)
Set the returned value.
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 .
static constexpr bool isDValid
df is defined and valid on the definition interval
_Scalar Scalar
Scalar type defined outside the class.
Compact generalised version of SmoothWeightKernel with arbitrary degrees : .
static constexpr bool isDValid
df is defined and valid on the definition interval
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 Scalar
Scalar type defined outside the class.
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 Scalar
Scalar type defined outside the class.
Scalar ddf(const Scalar &_x) const
Defines the smooth second order weighting function .
Compact Wendland WeightKernel defined in .
static constexpr bool isDValid
df is defined and valid on the definition interval
_Scalar Scalar
Scalar type defined outside the class.
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.