BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SimulationAreaIterator.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Detector/SimulationAreaIterator.cpp
6 //! @brief Implements 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 
17 
19  size_t start_at_index)
20  : m_detector(detector)
21  , m_index(start_at_index)
22  , m_maxIndex(m_detector->sizeOfRegionOfInterest())
23  , m_mode(mode)
24 {
25  if (m_index > m_maxIndex)
26  throw std::runtime_error("SimulationAreaIterator::SimulationAreaIterator() "
27  "-> Error. Invalid initial index");
28 
31 }
32 
34 {
35  return SimulationAreaIterator(detector, mode, 0);
36 }
37 
39 {
40  return SimulationAreaIterator(detector, mode, detector->sizeOfRegionOfInterest());
41 }
42 
44 {
45  return createEnd(m_detector, m_mode);
46 }
47 
49 {
50  return m_index;
51 }
52 
54 {
56 }
57 
59 {
60  size_t index = nextIndex(m_index);
61  if (index != m_index)
62  m_index = index;
63 
64  return *this;
65 }
66 
67 size_t SimulationAreaIterator::nextIndex(size_t currentIndex)
68 {
69  // #baROI + this can be optimized: Check whether a RegionOfInterest is present, then do not
70  // check every single point
71 
72  size_t result = ++currentIndex;
73  if (result >= m_maxIndex)
74  return m_maxIndex;
75 
76  while (isMasked(result)) {
77  ++result;
78  if (result == m_maxIndex)
79  break;
80  }
81  return result;
82 }
83 
84 bool SimulationAreaIterator::isMasked(size_t index) const
85 {
86  if (m_mode == regionOfInterest)
87  return false;
88 
89  const auto* masks = m_detector->detectorMask();
91  return (masks && masks->isMasked(detectorIndex));
92 }
Defines class DetectorMask.
Defines common detector interface.
Abstract detector interface.
Definition: IDetector.h:57
size_t sizeOfRegionOfInterest() const
The size of the "Region of Interest". Same as totalSize() if no region of interest has been explicitl...
Definition: IDetector.cpp:125
size_t regionOfInterestIndexToDetectorIndex(size_t regionOfInterestIndex) const
Convert an index of the region of interest to an index of the detector. If no region of interest is s...
Definition: IDetector.cpp:281
const DetectorMask * detectorMask() const
Definition: IDetector.cpp:372
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.
@ 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.
static SimulationAreaIterator createBegin(const IDetector *detector, Mode mode)
Create begin-iterator to iterate over all points according to the given mode.