Mantid
Loading...
Searching...
No Matches
BinEdgeAxis.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10
11namespace Mantid::API {
12
13//----------------------------------------------------------------------------------------------
18BinEdgeAxis::BinEdgeAxis(const std::size_t &length)
19 : NumericAxis() // default constructor
20{
21 m_values.resize(length);
22}
23
28BinEdgeAxis::BinEdgeAxis(const std::vector<double> &edges)
29 : NumericAxis() // default constructor
30{
31 m_values = edges;
32}
33
34BinEdgeAxis::BinEdgeAxis(std::span<double const> edges)
35 : NumericAxis() // default constructor
36{
37 m_values.assign(edges.begin(), edges.end());
38}
39
45Axis *BinEdgeAxis::clone(const MatrixWorkspace *const parentWorkspace) {
46 UNUSED_ARG(parentWorkspace)
47 return new BinEdgeAxis(*this);
48}
49
55Axis *BinEdgeAxis::clone(const std::size_t length, const MatrixWorkspace *const parentWorkspace) {
56 UNUSED_ARG(parentWorkspace)
57 auto *newAxis = new BinEdgeAxis(*this);
58 newAxis->m_values.clear();
59 newAxis->m_values.resize(length);
60 return newAxis;
61}
62
67std::vector<double> BinEdgeAxis::createBinBoundaries() const { return this->getValues(); }
68
74void BinEdgeAxis::setValue(const std::size_t &index, const double &value) {
75 // Avoids setting edge information
76 if (index >= length()) {
77 throw Kernel::Exception::IndexError(index, length() - 1, "BinEdgeAxis: Index out of range.");
78 }
80}
81
91
99std::string BinEdgeAxis::label(const std::size_t &index) const {
100 if (index >= length() - 1) {
101 throw Kernel::Exception::IndexError(index, length() - 2, "BinEdgeAxis: Bin index out of range.");
102 }
103 return formatLabel(((*this)(index) + (*this)(index + 1)) / 2);
104}
105} // namespace Mantid::API
double value
The value of the point.
Definition FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:44
Class to represent the axis of a workspace.
Definition Axis.h:30
Stores numeric values that are assumed to be bin edge values.
Definition BinEdgeAxis.h:20
BinEdgeAxis(const std::size_t &length)
Constructor taking a length.
std::vector< double > createBinBoundaries() const override
Return the values axis as they are.
void setValue(const std::size_t &index, const double &value) override
Sets the axis value at a given position.
std::string label(const std::size_t &index) const override
Returns a text label which shows the value at the given bin index.
size_t indexOfValue(const double value) const override
Treats values as bin edges and returns the index of the bin, which the value falls into.
Axis * clone(const MatrixWorkspace *const parentWorkspace) override
Virtual constructor.
Base MatrixWorkspace Abstract Class.
Class to represent a numeric axis of a workspace.
Definition NumericAxis.h:30
std::string formatLabel(const double value) const
Get number label.
virtual const std::vector< double > & getValues() const
Return a const reference to the values.
std::size_t length() const override
Get the length of the axis.
Definition NumericAxis.h:42
std::vector< double > m_values
A vector holding the centre values.
Definition NumericAxis.h:66
Exception for index errors.
Definition Exception.h:284
size_t MANTID_KERNEL_DLL indexOfValueFromEdges(std::span< double const > bin_edges, const double value)
Gets the bin of a value from a vector of bin edges.