BSplinebasis
Loading...
Searching...
No Matches
GenericOperators.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_GENERICOPERATORS_H
9#define BSPLINE_OPERATORS_GENERICOPERATORS_H
10
11#include <bspline/Spline.h>
12
16namespace bspline::operators {
17
23class Operator {};
24
33template <typename O>
34inline constexpr bool is_operator_v =
35 std::is_base_of_v<Operator, std::remove_cv_t<std::remove_reference_t<O>>>;
36
46template <typename O1, typename O2>
48
63template <typename T, size_t order, typename O,
64 std::enable_if_t<is_operator_v<O>, bool> = true>
66 constexpr size_t OUTPUT_SIZE = O::outputOrder(order) + 1;
67
68 const auto &oldCoefficients = spline.getCoefficients();
69
70 std::vector<std::array<T, OUTPUT_SIZE>> newCoefficients;
72
73 const auto &support = spline.getSupport();
74
75 for (size_t i = 0; i < oldCoefficients.size(); i++) {
76 const size_t absIndex = support.absoluteFromRelative(i);
77 newCoefficients.push_back(
78 op.transform(oldCoefficients[i], support.getGrid(), absIndex));
79 }
80
81 return Spline(spline.getSupport(), std::move(newCoefficients));
82}
83
84// ################## Generic Operator Definitions #######################
85// #######################################################################
86
87// #######################################################################
88// ########################## IdentityOperator ##############################
89
96 public:
105 static constexpr size_t outputOrder(size_t inputOrder) { return inputOrder; }
106
122 template <typename T, size_t size>
123 std::array<T, size> transform(const std::array<T, size> &input,
125 [[maybe_unused]] size_t intervalIndex) const {
126 return input;
127 }
128};
129
140template <typename O, typename S,
141 std::enable_if_t<is_operator_v<O> && is_spline_v<S>, bool> = true>
142auto operator*(const O &o, const S &s) {
143 return transformSpline(o, s);
144}
145} // namespace bspline::operators
146#endif // BSPLINE_OPERATORS_GENERICOPERATORS_H
The central Spline class of the library.
Definition Spline.h:59
Multiplicative identity operator.
Definition GenericOperators.h:95
static constexpr size_t outputOrder(size_t inputOrder)
Order of the resulting Spline.
Definition GenericOperators.h:105
std::array< T, size > transform(const std::array< T, size > &input, const support::Grid< T > &grid, size_t intervalIndex) const
Applies operator on one interval.
Definition GenericOperators.h:123
Marker interface for operators.
Definition GenericOperators.h:23
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
OperatorProduct< O1, O2 > operator*(O1 &&o1, O2 &&o2)
Operator multiplication operator.
Definition CompoundOperators.h:84
auto transformSpline(const O &op, const Spline< T, order > &spline)
Applies operator to spline.
Definition GenericOperators.h:65
constexpr bool is_operator_v
Checks whether O is an operator.
Definition GenericOperators.h:34
constexpr bool are_operators_v
Checks whether O1 and O2 are operators.
Definition GenericOperators.h:47