Mantid
Loading...
Searching...
No Matches
BSpline.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
16
17#include <memory>
18#include <unsupported/Eigen/Splines>
19
21
22typedef Eigen::Spline<double, 1, Eigen::Dynamic> Spline1D;
23
28class MANTID_CURVEFITTING_DLL BSpline : public BackgroundFunction {
29public:
31 BSpline();
33 std::string name() const override { return "BSpline"; }
34 const std::string category() const override { return "Background"; }
35 void function1D(double *out, const double *xValues, const size_t nData) const override;
36 void derivative1D(double *out, const double *xValues, size_t nData, const size_t order) const override;
37
39 void setAttribute(const std::string &attName, const Attribute &) override;
41 std::vector<std::string> getAttributeNames() const override;
42
44 void resetParameters();
46 void resetKnots();
48 void resetValidators();
50 [[nodiscard]] std::vector<double> calcUniformBreakPoints(const double startX, const double endX);
52 void resetKnotVector(const std::vector<double> &breakPoints);
54 size_t evaluateBasisFunctions(EigenVector &B, const double x, size_t currentBBase) const;
56 void initialiseSpline(const std::vector<double> &breakPoints);
58 size_t getSpanIndex(const double x, const size_t currentBBase, const bool clamped = true) const;
60 [[nodiscard]] EigenMatrix evaluateBasisFnDerivatives(const double x, const size_t derivOrder) const;
61
63 inline int getNBSplineCoefficients() { return getNBreakPoints() + getOrder() - 2; }
65 inline int getNBreakPoints() const { return getAttribute("NBreak").asInt(); }
67 inline int getNKnots() const { return getNBreakPoints() + getClampedKnots() * 2 - 2; }
69 inline int getOrder() const { return getAttribute("Order").asInt(); }
71 inline int getClampedKnots() const { return getDegree() + 1; }
73 inline int getDegree() const { return getOrder() - 1; }
74
77 std::vector<double> m_knots;
78};
79
80} // namespace Mantid::CurveFitting::Functions
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
A wrapper around Eigen::Matrix.
Definition: EigenMatrix.h:33
A wrapper around Eigen::Vector.
Definition: EigenVector.h:27
A wrapper around Eigen functions implementing a B-spline.
Definition: BSpline.h:28
const std::string category() const override
overwrite IFunction base class methods
Definition: BSpline.h:34
std::string name() const override
overwrite IFunction base class methods
Definition: BSpline.h:33
int getOrder() const
Get order of the spline, k.
Definition: BSpline.h:69
int getNBreakPoints() const
Get number of Break Points.
Definition: BSpline.h:65
int getClampedKnots() const
Get number of knots required to clamp the spline closed.
Definition: BSpline.h:71
int getDegree() const
Get the degree of constituent polynomial functions.
Definition: BSpline.h:73
int getNBSplineCoefficients()
Get number of B-Spline coefficients.
Definition: BSpline.h:63
Spline1D m_spline
Member variable for spline.
Definition: BSpline.h:76
int getNKnots() const
Get number of Knots.
Definition: BSpline.h:67
std::vector< double > m_knots
Definition: BSpline.h:77
Eigen::Spline< double, 1, Eigen::Dynamic > Spline1D
Definition: BSpline.h:22