BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SimulationAreaIterator.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Detector/SimulationAreaIterator.h
6 //! @brief Defines class SimulationAreaIterator.
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_DEVICE_DETECTOR_SIMULATIONAREAITERATOR_H
21 #define BORNAGAIN_DEVICE_DETECTOR_SIMULATIONAREAITERATOR_H
22 
23 #include <cstdlib>
24 
25 class IDetector;
26 
27 //! An iterator for SimulationArea.
28 //! @ingroup detector
29 
31 public:
32  //! Mode how the points shall be traversed
33  enum Mode {
34  regionOfInterest, //!< iterate over all points in "region of interest", no matter whether
35  //!< masked
36  notMasked //!< iterate over all points in "region of interest" and not masked
37  };
38 
39 private:
40  explicit SimulationAreaIterator(const IDetector* detector, Mode mode, size_t start_at_index);
41 
42 public:
43  //! Create begin-iterator to iterate over all points according to the given mode.
44  static SimulationAreaIterator createBegin(const IDetector* detector, Mode mode);
45 
46  //! Create end-iterator to iterate over all points according to the given mode.
47  static SimulationAreaIterator createEnd(const IDetector* detector, Mode mode);
48 
49  //! Convenience function to create an end-iterator matching to this iterator.
51 
52  size_t roiIndex() const;
53  size_t detectorIndex() const;
54 
55  bool operator==(const SimulationAreaIterator& other) const;
56  bool operator!=(const SimulationAreaIterator& right) const;
57 
58  //! prefix increment
60 
61 private:
62  size_t nextIndex(size_t currentIndex);
63 
64  //! Check whether masked according to the actual mode (always false if mode is
65  //! regionOfInterest). index is an ROI index.
66  bool isMasked(size_t index) const;
67 
69  size_t m_index; //!< ROI related index
70  size_t m_maxIndex; //!< ROI related maximum index
72 };
73 
75 {
76  return m_detector == other.m_detector && m_index == other.m_index && m_mode == other.m_mode;
77 }
78 
80 {
81  return !(*this == right);
82 }
83 
84 #endif // BORNAGAIN_DEVICE_DETECTOR_SIMULATIONAREAITERATOR_H
85 #endif // USER_API
Abstract detector interface.
Definition: IDetector.h:57
An iterator for SimulationArea.
SimulationAreaIterator createEnd() const
Convenience function to create an end-iterator matching to this iterator.
Mode
Mode how the points shall be traversed.
@ notMasked
iterate over all points in "region of interest" and not masked
@ regionOfInterest
iterate over all points in "region of interest", no matter whether masked
size_t nextIndex(size_t currentIndex)
size_t m_maxIndex
ROI related maximum index.
bool isMasked(size_t index) const
Check whether masked according to the actual mode (always false if mode is regionOfInterest)....
SimulationAreaIterator(const IDetector *detector, Mode mode, size_t start_at_index)
SimulationAreaIterator & operator++()
prefix increment
size_t m_index
ROI related index.
bool operator==(const SimulationAreaIterator &other) const
static SimulationAreaIterator createBegin(const IDetector *detector, Mode mode)
Create begin-iterator to iterate over all points according to the given mode.
bool operator!=(const SimulationAreaIterator &right) const