Mantid
Loading...
Searching...
No Matches
FunctionDomain1D.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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
11
12namespace Mantid::API {
13
15FunctionDomain1D::FunctionDomain1D(const double *x, size_t n) : m_data(x), m_n(n), m_peakRadius(0) {}
16
18std::vector<double> FunctionDomain1D::toVector() const {
19 std::vector<double> res;
20 if (m_n > 0) {
21 res.assign(m_data, m_data + m_n);
22 }
23 return res;
24}
25
31
36
41FunctionDomain1DVector::FunctionDomain1DVector(const std::vector<double> &xvalues) : FunctionDomain1D(nullptr, 0) {
42 if (xvalues.empty()) {
43 throw std::invalid_argument("FunctionDomain1D cannot have zero size.");
44 }
45 m_X.assign(xvalues.begin(), xvalues.end());
46 resetData(&m_X[0], m_X.size());
47}
48
53FunctionDomain1DVector::FunctionDomain1DVector(std::vector<double> &&xvalues) : FunctionDomain1D(nullptr, 0) {
54 if (xvalues.empty()) {
55 throw std::invalid_argument("FunctionDomain1D cannot have zero size.");
56 }
57 m_X = std::move(xvalues);
58 /* clear the invalidated object */
59 xvalues.clear();
60 resetData(&m_X[0], m_X.size());
61}
62
68FunctionDomain1DVector::FunctionDomain1DVector(std::vector<double>::const_iterator from,
69 std::vector<double>::const_iterator to)
70 : FunctionDomain1D(nullptr, 0) {
71 if (from == to) {
72 throw std::invalid_argument("FunctionDomain1D cannot have zero size.");
73 }
74 m_X.assign(from, to);
75 resetData(&m_X[0], m_X.size());
76}
77
86FunctionDomain1DVector::FunctionDomain1DVector(const double startX, const double endX, const size_t n)
87 : FunctionDomain1D(nullptr, 0) {
88 if (n == 0) {
89 throw std::invalid_argument("FunctionDomain1D cannot have zero size.");
90 }
91 m_X.resize(n);
92 if (n == 1) {
93 m_X[0] = (startX + endX) / 2;
94 } else {
95 const double dx = (endX - startX) / double(n - 1);
96 for (size_t i = 0; i < n; ++i) {
97 m_X[i] = startX + dx * double(i);
98 }
99 }
100 resetData(&m_X[0], m_X.size());
101}
102
108 m_X.resize(1);
109 m_X[0] = x;
110 resetData(&m_X[0], m_X.size());
111}
112
118 *this = right;
119}
120
126 if (right.m_X.empty()) {
127 throw std::invalid_argument("FunctionDomain1D cannot have zero size.");
128 }
129 m_X.assign(right.m_X.begin(), right.m_X.end());
130 resetData(&m_X[0], m_X.size());
131 return *this;
132}
133
139FunctionDomain1DSpectrum::FunctionDomain1DSpectrum(size_t wi, const std::vector<double> &xvalues)
140 : FunctionDomain1DVector(xvalues), m_workspaceIndex(wi) {}
141
148FunctionDomain1DSpectrum::FunctionDomain1DSpectrum(size_t wi, std::vector<double>::const_iterator from,
149 std::vector<double>::const_iterator to)
150 : FunctionDomain1DVector(from, to), m_workspaceIndex(wi) {}
151
155 : FunctionDomain1DHistogram(bins.begin(), bins.end()) {}
156
162FunctionDomain1DHistogram::FunctionDomain1DHistogram(std::vector<double>::const_iterator from,
163 std::vector<double>::const_iterator to)
164 : FunctionDomain1D(nullptr, 0), m_bins(from, to) {
165 if (m_bins.size() < 2) {
166 throw std::runtime_error("Cannot initialize FunctionDomain1DHistogram with "
167 "less than 2 bin boundaries.");
168 }
169 resetData(&m_bins[1], m_bins.size() - 1);
170}
171
173double FunctionDomain1DHistogram::leftBoundary() const { return m_bins.front(); }
174
175} // namespace Mantid::API
double right
Definition: LineProfile.cpp:81
double radius
Definition: Rasterize.cpp:31
const std::vector< Type > & m_data
Definition: TableColumn.h:417
Implements FunctionDomain1D as a set of bins for a histogram.
double leftBoundary() const
Get the leftmost boundary.
std::vector< double > m_bins
vector of bin boundaries
FunctionDomain1DHistogram(const std::vector< double > &bins)
Constructor.
FunctionDomain1DSpectrum(size_t wi, const std::vector< double > &xvalues)
Constructor.
Implements FunctionDomain1D with its own storage in form of a std::vector.
FunctionDomain1DVector(const double x)
Constructor.
FunctionDomain1DVector & operator=(const FunctionDomain1DVector &)
Copy assignment operator.
std::vector< double > m_X
vector of function arguments
Represent a domain for functions of one real argument.
int getPeakRadius() const
Get the peak radius.
void setPeakRadius(int radius)
Set a peak radius to pass to peak functions.
size_t m_n
size of the data
int m_peakRadius
A peak radius that IPeakFunctions should use.
const double * m_data
pointer to the start of the domain data
std::vector< double > toVector() const
Convert to a vector.
FunctionDomain1D(const FunctionDomain1D &right)=delete
copying is not allowed.
void resetData(const double *x, size_t n)
Reset the pointer and size of the domain.