BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IAxis.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Axis/IAxis.h
6 //! @brief Defines interface IAxis.
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_IAXIS_H
17 #define BORNAGAIN_BASE_AXIS_IAXIS_H
18 
19 #include "Base/Axis/Bin.h"
20 #include <vector>
21 
22 //! Interface for one-dimensional axes.
23 //! @ingroup tools_internal
24 
25 class IAxis {
26 public:
27  //! constructors
28  IAxis(const std::string& name) : m_name(name) {}
29 
30  //! clone function
31  virtual IAxis* clone() const = 0;
32 
33  //! destructor
34  virtual ~IAxis() {}
35 
36  //! retrieve the number of bins
37  virtual size_t size() const = 0;
38 
39  //! retrieve the label of the axis
40  std::string getName() const { return m_name; }
41 
42  //! Sets the axis label
43  void setName(std::string name) { m_name = name; }
44 
45  //! indexed accessor retrieves a sample
46  virtual double operator[](size_t index) const = 0;
47 
48  //! retrieve a 1d bin for the given index
49  virtual Bin1D bin(size_t index) const = 0;
50 
51  //! Returns value of first point of axis
52  virtual double lowerBound() const = 0;
53 
54  //! Returns value of last point of axis
55  virtual double upperBound() const = 0;
56 
57  //! Returns distance from first to last point
58  double span() const;
59 
60  //! Returns midpoint of axis
61  double center() const;
62 
63  virtual double binCenter(size_t index) const = 0;
64 
65  //! find bin index which is best match for given value
66  virtual size_t findClosestIndex(double value) const = 0;
67 
68  //! test for equality
69  bool operator==(const IAxis& right) const { return equals(right); }
70  bool operator!=(const IAxis& right) const { return !(*this == right); }
71 
72  friend std::ostream& operator<<(std::ostream& ostr, const IAxis& m)
73  {
74  m.print(ostr);
75  return ostr;
76  }
77 
78  virtual std::vector<double> binCenters() const;
79 
80  virtual std::vector<double> binBoundaries() const;
81 
82  //! Creates a new clipped axis
83  virtual IAxis* createClippedAxis(double left, double right) const;
84 
85  //! Returns true if axis contains given point
86  virtual bool contains(double value) const;
87 
88 protected:
89  virtual void print(std::ostream& ostr) const = 0;
90  virtual bool equals(const IAxis& other) const; // overloaded in child classes
91 
92 private:
93  IAxis(const IAxis&);
94  IAxis& operator=(const IAxis&);
95 
96  std::string m_name; //!< axis name
97 };
98 
99 //! global helper function for comparison of axes
100 inline bool HaveSameNameAndShape(const IAxis& left, const IAxis& right)
101 {
102  return left == right;
103 }
104 
105 #endif // BORNAGAIN_BASE_AXIS_IAXIS_H
106 #endif // USER_API
Defines structs Bin1D, Bin1DCVector.
bool HaveSameNameAndShape(const IAxis &left, const IAxis &right)
global helper function for comparison of axes
Definition: IAxis.h:100
Interface for one-dimensional axes.
Definition: IAxis.h:25
virtual IAxis * createClippedAxis(double left, double right) const
Creates a new clipped axis.
Definition: IAxis.cpp:32
double span() const
Returns distance from first to last point.
Definition: IAxis.cpp:42
virtual bool contains(double value) const
Returns true if axis contains given point.
Definition: IAxis.cpp:37
virtual std::vector< double > binCenters() const
Definition: IAxis.cpp:22
bool operator==(const IAxis &right) const
test for equality
Definition: IAxis.h:69
virtual std::vector< double > binBoundaries() const
Definition: IAxis.cpp:27
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
IAxis & operator=(const IAxis &)
virtual ~IAxis()
destructor
Definition: IAxis.h:34
virtual bool equals(const IAxis &other) const
Definition: IAxis.cpp:17
virtual void print(std::ostream &ostr) const =0
void setName(std::string name)
Sets the axis label.
Definition: IAxis.h:43
virtual IAxis * clone() const =0
clone function
friend std::ostream & operator<<(std::ostream &ostr, const IAxis &m)
Definition: IAxis.h:72
virtual double upperBound() const =0
Returns value of last point of axis.
IAxis(const std::string &name)
constructors
Definition: IAxis.h:28
virtual Bin1D bin(size_t index) const =0
retrieve a 1d bin for the given index
virtual size_t size() const =0
retrieve the number of bins
std::string m_name
axis name
Definition: IAxis.h:96
virtual double lowerBound() const =0
Returns value of first point of axis.
IAxis(const IAxis &)
virtual double operator[](size_t index) const =0
indexed accessor retrieves a sample
bool operator!=(const IAxis &right) const
Definition: IAxis.h:70
std::string getName() const
retrieve the label of the axis
Definition: IAxis.h:40
virtual double binCenter(size_t index) const =0
double center() const
Returns midpoint of axis.
Definition: IAxis.cpp:47
QString const & name(EShape k)
Definition: particles.cpp:21
Definition: Bin.h:20