BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
PointwiseAxis.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Axis/PointwiseAxis.h
6 //! @brief Defines class PointwiseAxis.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef USER_API
16 #ifndef BORNAGAIN_BASE_AXIS_POINTWISEAXIS_H
17 #define BORNAGAIN_BASE_AXIS_POINTWISEAXIS_H
18 
19 #include "Base/Axis/IAxis.h"
20 
21 //! Axis containing arbitrary (non-equidistant) coordinate values.
22 //! Lower boundary of the first bin and upper boundary of the
23 //! last bin correspond to first and last passed coordinates.
24 //! Other bin boundaries are computed as arithmetical mean of
25 //! two adjacent coordinates.
26 //! One should be aware, that bin centers reported
27 //! by PointwiseAxis::binCenter do not coincide with the
28 //! values produced by Bin1D::center.
29 //! On-axis values are bounded by minimum/maximum
30 //! values passed to the constructor.
31 //! @ingroup tools
32 
33 class PointwiseAxis : public IAxis {
34 public:
35  template <class String, class Vector>
36  PointwiseAxis(String&& name, Vector&& coordinate_values)
37  : IAxis(std::forward<String>(name))
38  , m_coordinates(std::forward<Vector>(coordinate_values))
39  {
40  sanityCheck();
41  }
42 
43  //! clone function
44  PointwiseAxis* clone() const override;
45 
46  ~PointwiseAxis() override;
47 
48  //! retrieve the number of bins
49  size_t size() const override { return m_coordinates.size(); }
50 
51  //! indexed accessor retrieves a sample
52  double operator[](size_t index) const override { return binCenter(index); }
53 
54  //! retrieve a 1d bin for the given index
55  Bin1D bin(size_t index) const override;
56 
57  //! Returns value of first on-axis point
58  double min() const override;
59 
60  //! Returns value of last on-axis point
61  double max() const override;
62 
63  //! Returns the coordinate corresponding to the
64  //! given index. For this type of axis ("pointwise")
65  //! this equals returning an explicitly defined coordinate.
66  double binCenter(size_t index) const override;
67 
68  //! find index of the coordinate closest to the given value
69  size_t findClosestIndex(double value) const override;
70 
71  std::vector<double> binCenters() const override { return m_coordinates; }
72 
73  std::vector<double> binBoundaries() const override;
74 
75  void clip(double lower, double upper) override;
76 
77 private:
78  void print(std::ostream& ostr) const override;
79  bool equals(const IAxis& other) const override;
80 
81  double minary(size_t index) const;
82  double maxary(size_t index) const;
83  void checkIndex(size_t index) const;
84  void sanityCheck() const;
85 
86  std::vector<double> m_coordinates;
87 };
88 
89 #endif // BORNAGAIN_BASE_AXIS_POINTWISEAXIS_H
90 #endif // USER_API
Defines interface IAxis.
Definition: Bin.h:20
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
Axis containing arbitrary (non-equidistant) coordinate values. Lower boundary of the first bin and up...
Definition: PointwiseAxis.h:33
~PointwiseAxis() override
PointwiseAxis(String &&name, Vector &&coordinate_values)
Definition: PointwiseAxis.h:36
PointwiseAxis * clone() const override
clone function
double min() const override
Returns value of first on-axis point.
double binCenter(size_t index) const override
Returns the coordinate corresponding to the given index. For this type of axis ("pointwise") this equ...
Bin1D bin(size_t index) const override
retrieve a 1d bin for the given index
void checkIndex(size_t index) const
std::vector< double > m_coordinates
Definition: PointwiseAxis.h:86
size_t findClosestIndex(double value) const override
find index of the coordinate closest to the given value
std::vector< double > binBoundaries() const override
double operator[](size_t index) const override
indexed accessor retrieves a sample
Definition: PointwiseAxis.h:52
void clip(double lower, double upper) override
Clips this axis to the given values.
double maxary(size_t index) const
double minary(size_t index) const
size_t size() const override
retrieve the number of bins
Definition: PointwiseAxis.h:49
bool equals(const IAxis &other) const override
std::vector< double > binCenters() const override
Definition: PointwiseAxis.h:71
void print(std::ostream &ostr) const override
void sanityCheck() const
double max() const override
Returns value of last on-axis point.