BornAgain  1.18.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 scattering at grazing incidence
4 //
5 //! @file Base/Axis/IAxis.h
6 //! @brief Defines class 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 BORNAGAIN_CORE_AXIS_IAXIS_H
16 #define BORNAGAIN_CORE_AXIS_IAXIS_H
17 
18 #include "Base/Axis/Bin.h"
19 #include <vector>
20 
21 //! Interface for one-dimensional axes.
22 //! @ingroup tools_internal
23 
24 class IAxis
25 {
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 getBin(size_t index) const = 0;
50 
51  //! Returns value of first point of axis
52  virtual double getMin() const = 0;
53 
54  //! Returns value of last point of axis
55  virtual double getMax() const = 0;
56 
57  virtual double getBinCenter(size_t index) const = 0;
58 
59  //! find bin index which is best match for given value
60  virtual size_t findClosestIndex(double value) const = 0;
61 
62  //! test for equality
63  bool operator==(const IAxis& right) const { return equals(right); }
64  bool operator!=(const IAxis& right) const { return !(*this == right); }
65 
66  friend std::ostream& operator<<(std::ostream& ostr, const IAxis& m)
67  {
68  m.print(ostr);
69  return ostr;
70  }
71 
72  virtual std::vector<double> getBinCenters() const;
73 
74  virtual std::vector<double> getBinBoundaries() const;
75 
76  //! Creates a new clipped axis
77  virtual IAxis* createClippedAxis(double left, double right) const;
78 
79  //! Returns true if axis contains given point
80  virtual bool contains(double value) const;
81 
82  virtual std::string pyString(const std::string& units, size_t offset) const = 0;
83 
84 protected:
85  virtual void print(std::ostream& ostr) const = 0;
86  virtual bool equals(const IAxis& other) const; // overloaded in child classes
87 
88 private:
89  IAxis(const IAxis&);
90  IAxis& operator=(const IAxis&);
91 
92  std::string m_name; //!< axis name
93 };
94 
95 //! global helper function for comparison of axes
96 inline bool HaveSameNameAndShape(const IAxis& left, const IAxis& right)
97 {
98  return left == right;
99 }
100 
101 #endif // BORNAGAIN_CORE_AXIS_IAXIS_H
Defines structs Bin1D, Bin1DCVector.
bool HaveSameNameAndShape(const IAxis &left, const IAxis &right)
global helper function for comparison of axes
Definition: IAxis.h:96
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:34
virtual bool contains(double value) const
Returns true if axis contains given point.
Definition: IAxis.cpp:40
bool operator==(const IAxis &right) const
test for equality
Definition: IAxis.h:63
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual Bin1D getBin(size_t index) const =0
retrieve a 1d bin for the given index
IAxis & operator=(const IAxis &)
virtual ~IAxis()
destructor
Definition: IAxis.h:34
virtual bool equals(const IAxis &other) const
Definition: IAxis.cpp:18
virtual double getBinCenter(size_t index) const =0
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:66
virtual double getMin() const =0
Returns value of first point of axis.
virtual std::vector< double > getBinCenters() const
Definition: IAxis.cpp:23
IAxis(const std::string &name)
constructors
Definition: IAxis.h:28
virtual std::string pyString(const std::string &units, size_t offset) const =0
virtual size_t size() const =0
retrieve the number of bins
std::string m_name
axis name
Definition: IAxis.h:92
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:64
virtual double getMax() const =0
Returns value of last point of axis.
std::string getName() const
retrieve the label of the axis
Definition: IAxis.h:40
virtual std::vector< double > getBinBoundaries() const
Definition: IAxis.cpp:28
Definition: Bin.h:20