10#ifndef BSPLINE_BSPLINEGENERATOR_H
11#define BSPLINE_BSPLINEGENERATOR_H
13#include <bspline/Spline.h>
14#include <bspline/exceptions/BSplineException.h>
15#include <bspline/operators/CompoundOperators.h>
16#include <bspline/operators/Position.h>
17#include <bspline/operators/ScalarOperators.h>
40 std::vector<T> _knots;
54 Grid<T> generateGrid(std::vector<T> knots) {
55 const auto endIterator = std::unique(knots.begin(), knots.end());
56 knots.erase(endIterator, knots.end());
102 template <
size_t order>
104 static constexpr size_t k =
order + 1;
105 if (_knots.size() <
k) {
107 "The knots vector contains too few elements to "
108 "generate BSplines of the requested order.");
111 if constexpr (
order == 0) {
112 return generateZerothOrderSplines();
115 std::vector<Spline<T, order>>
ret;
116 ret.reserve(_knots.size() -
k);
117 for (
size_t i = 0;
i < _knots.
size() -
k;
i++) {
142 Spline<
T,
k - 1> applyRecursionRelation(
145 static_assert(
k >= 2,
"k has to be at least 2.");
149 const T &
xi = _knots.
at(
i);
173 std::vector<Spline<T, 0>> generateZerothOrderSplines()
const {
174 std::vector<Spline<T, 0>>
ret;
175 const size_t numberOfSplines = (_knots.empty()) ? 0 : _knots.size() - 1;
179 const T &
xi = _knots.
at(
i);
187 std::vector<std::array<T, 1>>
coefficients{{
static_cast<T>(1)}};
210template <
size_t order,
typename T>
Generates the BSplines on a grid.
Definition BSplineGenerator.h:33
std::vector< Spline< T, order > > generateBSplines() const
Generates all BSplines with respect to the knots vector.
Definition BSplineGenerator.h:103
BSplineGenerator(std::vector< T > knots, const Grid< T > &grid)
Constructor using the provided grid instance.
Definition BSplineGenerator.h:80
BSplineGenerator(std::vector< T > knots)
Constructor generating the grid from the knots vector.
Definition BSplineGenerator.h:67
Grid< T > getGrid() const
Returns the grid.
Definition BSplineGenerator.h:93
The central Spline class of the library.
Definition Spline.h:59
The main exception class.
Definition BSplineException.h:84
Represents a global Grid.
Definition Grid.h:27
const T & at(size_t i) const
Gives access to the i-th element of the Grid.
Definition Grid.h:218
size_t size() const
Returns the number of elements of the Grid.
Definition Grid.h:169
size_t findElement(const T &x) const
Returns the index corresponding to the element x.
Definition Grid.h:275
Represents the Spline's Support.
Definition Support.h:33
Exceptions and error codes.
Definition BSplineException.h:19
Main namespace for this library.
Definition BSplineGenerator.h:21
std::vector< Spline< T, order > > generateBSplines(std::vector< T > knots)
Convenience method to generate a set of BSplines.
Definition BSplineGenerator.h:211