BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
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 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_BASE_AXIS_POINTWISEAXIS_H
21 #define BORNAGAIN_BASE_AXIS_POINTWISEAXIS_H
22 
23 #include "Base/Axis/IAxis.h"
24 
25 //! Axis containing arbitrary (non-equidistant) coordinate values.
26 //! Lower boundary of the first bin and upper boundary of the
27 //! last bin correspond to first and last passed coordinates.
28 //! Other bin boundaries are computed as arithmetical mean of
29 //! two adjacent coordinates.
30 //! One should be aware, that bin centers reported
31 //! by PointwiseAxis::binCenter do not coincide with the
32 //! values produced by Bin1D::getMidPoint.
33 //! On-axis values are bounded by minimum/maximum
34 //! values passed to the constructor.
35 //! @ingroup tools
36 
37 class PointwiseAxis : public IAxis {
38 public:
39  template <class String, class Vector>
40  PointwiseAxis(String&& name, Vector&& coordinate_values)
41  : IAxis(std::forward<String>(name)), m_coordinates(std::forward<Vector>(coordinate_values))
42  {
43  sanityCheck();
44  }
45 
46  //! clone function
47  PointwiseAxis* clone() const override;
48 
49  ~PointwiseAxis() override = default;
50 
51  //! retrieve the number of bins
52  size_t size() const override { return m_coordinates.size(); }
53 
54  //! indexed accessor retrieves a sample
55  double operator[](size_t index) const override { return binCenter(index); }
56 
57  //! retrieve a 1d bin for the given index
58  Bin1D bin(size_t index) const override;
59 
60  //! Returns value of first on-axis point
61  double lowerBound() const override;
62 
63  //! Returns value of last on-axis point
64  double upperBound() const override;
65 
66  //! Returns the coordinate corresponding to the
67  //! given index. For this type of axis ("pointwise")
68  //! this equals returning an explicitly defined coordinate.
69  double binCenter(size_t index) const override;
70 
71  //! find index of the coordinate closest to the given value
72  size_t findClosestIndex(double value) const override;
73 
74  std::vector<double> binCenters() const override { return m_coordinates; }
75 
76  std::vector<double> binBoundaries() const override;
77 
78  //! Creates a new clipped axis
79  PointwiseAxis* createClippedAxis(double left, double right) const override;
80 
81 private:
82  void print(std::ostream& ostr) const override;
83  bool equals(const IAxis& other) const override;
84 
85  double lowerBoundary(size_t index) const;
86  double upperBoundary(size_t index) const;
87  void checkIndex(size_t index) const;
88  void sanityCheck() const;
89 
90  std::vector<double> m_coordinates;
91 };
92 
93 #endif // BORNAGAIN_BASE_AXIS_POINTWISEAXIS_H
94 #endif // USER_API
Defines interface IAxis.
Interface for one-dimensional axes.
Definition: IAxis.h:25
Axis containing arbitrary (non-equidistant) coordinate values.
Definition: PointwiseAxis.h:37
double upperBoundary(size_t index) const
double lowerBoundary(size_t index) const
PointwiseAxis(String &&name, Vector &&coordinate_values)
Definition: PointwiseAxis.h:40
PointwiseAxis * clone() const override
clone function
~PointwiseAxis() override=default
double upperBound() const override
Returns value of last on-axis point.
double binCenter(size_t index) const override
Returns the coordinate corresponding to the given index.
Bin1D bin(size_t index) const override
retrieve a 1d bin for the given index
void checkIndex(size_t index) const
double lowerBound() const override
Returns value of first on-axis point.
std::vector< double > m_coordinates
Definition: PointwiseAxis.h:90
PointwiseAxis * createClippedAxis(double left, double right) const override
Creates a new clipped axis.
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:55
size_t size() const override
retrieve the number of bins
Definition: PointwiseAxis.h:52
bool equals(const IAxis &other) const override
std::vector< double > binCenters() const override
Definition: PointwiseAxis.h:74
void print(std::ostream &ostr) const override
void sanityCheck() const
QString const & name(EShape k)
Definition: particles.cpp:21
Definition: filesystem.h:81
Definition: Bin.h:20