BSplinebasis
Loading...
Searching...
No Matches
SplineOperator.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_SPLINEOPERATOR_H
9#define BSPLINE_OPERATORS_SPLINEOPERATOR_H
10
11#include <bspline/Spline.h>
12#include <bspline/exceptions/BSplineException.h>
13#include <bspline/internal/misc.h>
14#include <bspline/operators/GenericOperators.h>
15
16namespace bspline::operators {
17
24template <typename T, size_t order>
26 private:
29
30 public:
37
44 static constexpr size_t outputOrder(size_t inputOrder) {
45 return inputOrder + order;
46 }
47
65 template <size_t size>
66 auto transform(const std::array<T, size> &input, const support::Grid<T> &grid,
67 size_t intervalIndex) const {
68 static_assert(size >= 1);
69 constexpr size_t OUTPUT_SIZE = outputOrder(size - 1) + 1;
70
71 if (_s.getSupport().getGrid() != grid) {
72 throw exceptions::BSplineException(ErrorCode::DIFFERING_GRIDS);
73 }
74
75 const auto relativeIndex =
76 _s.getSupport().relativeFromAbsolute(intervalIndex);
77
78 auto retVal = internal::make_array<T, OUTPUT_SIZE>(static_cast<T>(0));
79
80 if (relativeIndex) {
81 // The interval is part of the Spline's support.
82 const auto &coeffs = _s.getCoefficients()[*relativeIndex];
83
84 for (size_t i = 0; i < input.size(); i++) {
85 for (size_t j = 0; j < coeffs.size(); j++) {
86 retVal[i + j] += input[i] * coeffs[j];
87 }
88 }
89 }
90 return retVal;
91 }
92};
93} // namespace bspline::operators
94#endif // BSPLINE_OPERATORS_SPLINEOPERATOR_H
The main exception class.
Definition BSplineException.h:84
Marker interface for operators.
Definition GenericOperators.h:23
Operator representation of a Spline.
Definition SplineOperator.h:25
auto transform(const std::array< T, size > &input, const support::Grid< T > &grid, size_t intervalIndex) const
Applies operator to a Spline.
Definition SplineOperator.h:66
SplineOperator(Spline< T, order > s)
Constructor constructing a SplineOperator from a Spline.
Definition SplineOperator.h:36
static constexpr size_t outputOrder(size_t inputOrder)
Returns the order of the output spline for a given input order.
Definition SplineOperator.h:44
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