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
39Axis *BinEdgeAxis::clone(const MatrixWorkspace *const parentWorkspace) {
40 UNUSED_ARG(parentWorkspace)
41 return new BinEdgeAxis(*this);
42}
43
49Axis *BinEdgeAxis::clone(const std::size_t length, const MatrixWorkspace *const parentWorkspace) {
50 UNUSED_ARG(parentWorkspace)
51 auto *newAxis = new BinEdgeAxis(*this);
52 newAxis->m_values.clear();
53 newAxis->m_values.resize(length);
54 return newAxis;
55}
56
61std::vector<double> BinEdgeAxis::createBinBoundaries() const { return this->getValues(); }
62
68void BinEdgeAxis::setValue(const std::size_t &index, const double &value) {
69 // Avoids setting edge information
70 if (index >= length()) {
71 throw Kernel::Exception::IndexError(index, length() - 1, "BinEdgeAxis: Index out of range.");
72 }
74}
75
82size_t BinEdgeAxis::indexOfValue(const double value) const {
84}
85
93std::string BinEdgeAxis::label(const std::size_t &index) const {
94 if (index >= length() - 1) {
95 throw Kernel::Exception::IndexError(index, length() - 2, "BinEdgeAxis: Bin index out of range.");
96 }
97 return formatLabel(((*this)(index) + (*this)(index + 1)) / 2);
98}
99} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
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.
Definition: BinEdgeAxis.cpp:18
std::vector< double > createBinBoundaries() const override
Return the values axis as they are.
Definition: BinEdgeAxis.cpp:61
void setValue(const std::size_t &index, const double &value) override
Sets the axis value at a given position.
Definition: BinEdgeAxis.cpp:68
std::string label(const std::size_t &index) const override
Returns a text label which shows the value at the given bin index.
Definition: BinEdgeAxis.cpp:93
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.
Definition: BinEdgeAxis.cpp:82
Axis * clone(const MatrixWorkspace *const parentWorkspace) override
Virtual constructor.
Definition: BinEdgeAxis.cpp:39
Base MatrixWorkspace Abstract Class.
Class to represent a numeric axis of a workspace.
Definition: NumericAxis.h:29
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:38
std::vector< double > m_values
A vector holding the centre values.
Definition: NumericAxis.h:61
Exception for index errors.
Definition: Exception.h:284
size_t MANTID_KERNEL_DLL indexOfValueFromEdges(const std::vector< double > &bin_edges, const double value)
Gets the bin of a value from a vector of bin edges.