BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Frame.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Axis/Frame.h
6 //! @brief Defines and implements templated class Frame.
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_BASE_AXIS_FRAME_H
16 #define BORNAGAIN_BASE_AXIS_FRAME_H
17 
19 
20 using std::size_t;
21 
22 class IAxis;
23 class Bin1D;
24 
25 //! Holds one or two axes.
26 
27 class Frame {
28 public:
29  //! Constructor that takes ownership of supplied axes.
30  Frame(const std::vector<IAxis*>& axes);
31  virtual ~Frame();
32 
33  //! Returns number of dimensions.
34  size_t rank() const { return m_axes.size(); }
35 
36  //! Returns total number of bins.
37  size_t size() const { return m_size; }
38 
39  //! Returns number of bins along axis.
40  size_t projectedSize(size_t k_axis) const;
41 
42  //! Returns cloned axes.
43  std::vector<IAxis*> cloned_axes() const;
44 
45  //! Returns axis with given serial number
46  const IAxis& axis(size_t k_axis) const { return *m_axes.at(k_axis); }
47  const IAxis& xAxis() const { return *m_axes.at(0); }
48  const IAxis& yAxis() const { return *m_axes.at(1); }
49 
50  //! Returns the value of selected axis for given i_flat.
51  //! @param i_flat The global index of this data structure.
52  //! @param k_axis Serial number of selected axis.
53  //! @return corresponding bin center of selected axis
54  double projectedCoord(size_t i_flat, size_t k_axis) const;
55 
56  //! Returns vector of axes indices for given global index
57  //! @param i_flat The global index of this data structure.
58  //! @return Vector of bin indices for all axes defined
59  std::vector<int> allIndices(size_t i_flat) const;
60 
61  //! Returns axis bin index for given global index
62  //! @param i_flat The global index of this data structure.
63  //! @param k_axis Serial number of selected axis.
64  //! @return Corresponding bin index for selected axis
65  size_t projectedIndex(size_t i_flat, size_t k_axis) const;
66 
67 
68  //! Returns global index for specified indices of axes
69  //! @param axes_indices Vector of axes indices for all specified axes in this dataset
70  //! @return Corresponding global index
71  size_t toGlobalIndex(const std::vector<unsigned>& axes_indices) const;
72 
73  //! Returns true if both Frame%s have same rank, and all axes have same sizes.
74  bool hasSameSizes(const Frame&) const;
75 
76  //! Returns true if both Frame%s have same rank, and all axes are equal.
77  bool operator==(const Frame&) const;
78 
79 protected:
81 
82 private:
83  size_t m_size; // cached product of axis sizes
84 };
85 
86 #endif // BORNAGAIN_BASE_AXIS_FRAME_H
Defines and implements templated class OwningVector.
Definition: Bin.h:20
Holds one or two axes.
Definition: Frame.h:27
size_t projectedIndex(size_t i_flat, size_t k_axis) const
Returns axis bin index for given global index.
Definition: Frame.cpp:56
const IAxis & axis(size_t k_axis) const
Returns axis with given serial number.
Definition: Frame.h:46
size_t size() const
Returns total number of bins.
Definition: Frame.h:37
std::vector< int > allIndices(size_t i_flat) const
Returns vector of axes indices for given global index.
Definition: Frame.cpp:48
bool operator==(const Frame &) const
Returns true if both Frames have same rank, and all axes are equal.
Definition: Frame.cpp:92
OwningVector< IAxis > m_axes
Definition: Frame.h:80
size_t toGlobalIndex(const std::vector< unsigned > &axes_indices) const
Returns global index for specified indices of axes.
Definition: Frame.cpp:79
const IAxis & xAxis() const
Definition: Frame.h:47
size_t projectedSize(size_t k_axis) const
Returns number of bins along axis.
Definition: Frame.cpp:37
Frame(const std::vector< IAxis * > &axes)
Constructor that takes ownership of supplied axes.
Definition: Frame.cpp:20
size_t m_size
Definition: Frame.h:83
virtual ~Frame()
const IAxis & yAxis() const
Definition: Frame.h:48
std::vector< IAxis * > cloned_axes() const
Returns cloned axes.
Definition: Frame.cpp:32
double projectedCoord(size_t i_flat, size_t k_axis) const
Returns the value of selected axis for given i_flat.
Definition: Frame.cpp:42
size_t rank() const
Returns number of dimensions.
Definition: Frame.h:34
bool hasSameSizes(const Frame &) const
Returns true if both Frames have same rank, and all axes have same sizes.
Definition: Frame.cpp:102
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
size_t size() const
Definition: OwningVector.h:70
T *const & at(int i) const
Definition: OwningVector.h:73