Mantid
Loading...
Searching...
No Matches
RefAxis.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 +
7#include "MantidAPI/RefAxis.h"
9
10namespace Mantid::API {
11
15// NumericAxis is set to length 0 since we do not need its internal storage. We
16// override public functions of NumericAxis that would access it.
17RefAxis::RefAxis(const MatrixWorkspace *const parentWorkspace) : NumericAxis(0), m_parentWS(parentWorkspace) {}
18
27RefAxis::RefAxis(const RefAxis &right, const MatrixWorkspace *const parentWorkspace)
28 : NumericAxis(right), m_parentWS(parentWorkspace) {}
29
35Axis *RefAxis::clone(const MatrixWorkspace *const parentWorkspace) { return new RefAxis(*this, parentWorkspace); }
36
37Axis *RefAxis::clone(const std::size_t length, const MatrixWorkspace *const parentWorkspace) {
38 static_cast<void>(length);
39 return clone(parentWorkspace);
40}
41
42std::size_t RefAxis::length() const { return m_parentWS->x(0).size(); }
43
54double RefAxis::operator()(const std::size_t &index, const std::size_t &verticalIndex) const {
55 const auto &x = m_parentWS->x(verticalIndex);
56 if (index >= x.size()) {
57 throw Kernel::Exception::IndexError(index, x.size() - 1, "Axis: Index out of range.");
58 }
59 return x[index];
60}
61
66void RefAxis::setValue(const std::size_t &index, const double &value) {
69 throw std::domain_error("This method cannot be used on a RefAxis.");
70}
71
76bool RefAxis::operator==(const Axis &axis2) const {
77 if (length() != axis2.length()) {
78 return false;
79 }
80 const auto *ra2 = dynamic_cast<const RefAxis *>(&axis2);
81 return ra2 != nullptr;
82}
83
89bool RefAxis::equalWithinTolerance(const Axis &axis2, const double tolerance) const {
91 return this->operator==(axis2);
92}
93
94size_t RefAxis::indexOfValue(const double value) const {
96 throw std::runtime_error("Calling indexOfValue() on RefAxis is forbidden.");
97}
98
99std::vector<double> RefAxis::createBinBoundaries() const {
100 throw std::runtime_error("Calling createBinBoundaries() on RefAxis is forbidden.");
101}
102
103const std::vector<double> &RefAxis::getValues() const {
104 throw std::runtime_error("Calling getValues() on RefAxis is forbidded.");
105}
106
107double RefAxis::getMin() const {
108 throw std::runtime_error("RefAxis cannot determine minimum value. Use readX "
109 "on the workspace instead");
110}
111double RefAxis::getMax() const {
112 throw std::runtime_error("RefAxis cannot determine maximum value. Use readX "
113 "on the workspace instead");
114}
115
116} // 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
double right
Definition: LineProfile.cpp:81
double tolerance
#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
virtual std::size_t length() const =0
Get the length of the axis.
Base MatrixWorkspace Abstract Class.
const HistogramData::HistogramX & x(const size_t index) const
Class to represent a numeric axis of a workspace.
Definition: NumericAxis.h:29
A class to represent the axis of a 2D (or more) workspace where the value at a given point on the axi...
Definition: RefAxis.h:23
std::vector< double > createBinBoundaries() const override
Create bin boundaries from the point values.
Definition: RefAxis.cpp:99
RefAxis(const MatrixWorkspace *const parentWorkspace)
Constructor.
Definition: RefAxis.cpp:17
std::size_t length() const override
Get the length of the axis.
Definition: RefAxis.cpp:42
Axis * clone(const MatrixWorkspace *const parentWorkspace) override
Virtual constructor.
Definition: RefAxis.cpp:35
bool operator==(const Axis &) const override
Check if two axis defined as spectra or numeric axis are equivalent.
Definition: RefAxis.cpp:76
const std::vector< double > & getValues() const override
Return a const reference to the values.
Definition: RefAxis.cpp:103
double getMax() const override
returns max value defined on axis
Definition: RefAxis.cpp:111
double getMin() const override
returns min value defined on axis
Definition: RefAxis.cpp:107
const MatrixWorkspace *const m_parentWS
A pointer to the workspace holding the axis.
Definition: RefAxis.h:51
size_t indexOfValue(const double value) const override
Returns the index of the value wrt bin edge representation of the axis.
Definition: RefAxis.cpp:94
double operator()(const std::size_t &index, const std::size_t &verticalIndex) const override
Get a value at the specified index.
Definition: RefAxis.cpp:54
void setValue(const std::size_t &index, const double &value) override
Method not available for RefAxis.
Definition: RefAxis.cpp:66
bool equalWithinTolerance(const Axis &axis2, const double tolerance) const override
Check if two numeric axis are equivalent to a given tolerance.
Definition: RefAxis.cpp:89
Exception for index errors.
Definition: Exception.h:284