BSplinebasis
Loading...
Searching...
No Matches
Position.h
1/*
2 * ########################################################################
3 * The contents of this file is free and unencumbered software released into the
4 * public domain. For more information, please refer to <http://unlicense.org/>
5 * ########################################################################
6 */
7
8#ifndef BSPLINE_OPERATORS_POSITION_H
9#define BSPLINE_OPERATORS_POSITION_H
10
11#include <bspline/internal/misc.h>
12#include <bspline/operators/GenericOperators.h>
13
17namespace bspline::operators {
18namespace internal = bspline::internal;
19
27template <size_t n>
28class Position final : public Operator {
29 private:
37 template <typename T>
38 static std::array<T, n + 1> expandPower(const T &xm) {
39 std::array<T, n + 1> retVal;
40 T power_of_xm = static_cast<T>(1);
41 for (size_t i = 0; i < n + 1; i++) {
42 retVal[n - i] = internal::binomialCoefficient<T>(n, i) * power_of_xm;
43 power_of_xm *= xm;
44 }
45 return retVal;
46 }
47
48 public:
55 static constexpr size_t outputOrder(size_t inputOrder) {
56 return inputOrder + n;
57 }
58
74 template <typename T, size_t size>
75 std::array<T, outputOrder(size - 1) + 1> transform(
76 const std::array<T, size> &input, const support::Grid<T> &grid,
77 size_t intervalIndex) const {
78 constexpr size_t OUTPUT_SIZE = size + n;
79
80 const T xm =
81 (grid[intervalIndex] + grid[intervalIndex + 1]) / static_cast<T>(2);
82
83 const std::array<T, n + 1> expanded = expandPower<T>(xm);
84
85 std::array<T, OUTPUT_SIZE> retVal;
86 retVal.fill(static_cast<T>(0));
87
88 for (size_t i = 0; i < input.size(); i++) {
89 for (size_t j = 0; j < expanded.size(); j++) {
90 retVal[i + j] += expanded[j] * input[i];
91 }
92 }
93 return retVal;
94 }
95};
96
104template <size_t n>
106
107} // namespace bspline::operators
108#endif // BSPLINE_OPERATORS_POSITION_H
Marker interface for operators.
Definition GenericOperators.h:23
Position operator.
Definition Position.h:28
static constexpr size_t outputOrder(size_t inputOrder)
Returns the order of the output spline for a given input order.
Definition Position.h:55
std::array< T, outputOrder(size - 1)+1 > transform(const std::array< T, size > &input, const support::Grid< T > &grid, size_t intervalIndex) const
Applies operator to one interval.
Definition Position.h:75
Represents a global Grid.
Definition Grid.h:27
size_t size() const
Returns the number of elements of the Grid.
Definition Grid.h:169
Operator definitions.
Definition CompoundOperators.h:13