BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SimulationAreaIterator Class Reference

Description

An iterator for SimulationArea.

Definition at line 30 of file SimulationAreaIterator.h.

Collaboration diagram for SimulationAreaIterator:
[legend]

Public Types

enum  Mode { regionOfInterest , notMasked }
 Mode how the points shall be traversed. More...
 

Public Member Functions

SimulationAreaIterator createEnd () const
 Convenience function to create an end-iterator matching to this iterator. More...
 
size_t detectorIndex () const
 
bool operator!= (const SimulationAreaIterator &right) const
 
SimulationAreaIteratoroperator++ ()
 prefix increment More...
 
bool operator== (const SimulationAreaIterator &other) const
 
size_t roiIndex () const
 

Static Public Member Functions

static SimulationAreaIterator createBegin (const IDetector *detector, Mode mode)
 Create begin-iterator to iterate over all points according to the given mode. More...
 
static SimulationAreaIterator createEnd (const IDetector *detector, Mode mode)
 Create end-iterator to iterate over all points according to the given mode. More...
 

Private Member Functions

 SimulationAreaIterator (const IDetector *detector, Mode mode, size_t start_at_index)
 
bool isMasked (size_t index) const
 Check whether masked according to the actual mode (always false if mode is regionOfInterest). index is an ROI index. More...
 
size_t nextIndex (size_t currentIndex)
 

Private Attributes

const IDetectorm_detector
 
size_t m_index
 ROI related index. More...
 
size_t m_maxIndex
 ROI related maximum index. More...
 
Mode m_mode
 

Member Enumeration Documentation

◆ Mode

Mode how the points shall be traversed.

Enumerator
regionOfInterest 

iterate over all points in "region of interest", no matter whether masked

notMasked 

iterate over all points in "region of interest" and not masked

Definition at line 33 of file SimulationAreaIterator.h.

33  {
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  };
@ 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

Constructor & Destructor Documentation

◆ SimulationAreaIterator()

SimulationAreaIterator::SimulationAreaIterator ( const IDetector detector,
Mode  mode,
size_t  start_at_index 
)
explicitprivate

Definition at line 18 of file SimulationAreaIterator.cpp.

20  : m_detector(detector)
21  , m_index(start_at_index)
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 }
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 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)....
size_t m_index
ROI related index.

References isMasked(), m_index, m_maxIndex, and nextIndex().

Referenced by createBegin(), and createEnd().

Here is the call graph for this function:

Member Function Documentation

◆ createBegin()

SimulationAreaIterator SimulationAreaIterator::createBegin ( const IDetector detector,
Mode  mode 
)
static

Create begin-iterator to iterate over all points according to the given mode.

Definition at line 33 of file SimulationAreaIterator.cpp.

34 {
35  return SimulationAreaIterator(detector, mode, 0);
36 }
SimulationAreaIterator(const IDetector *detector, Mode mode, size_t start_at_index)

References SimulationAreaIterator().

Referenced by IDetector::beginNonMaskedPoints(), and IDetector::beginRegionOfInterestPoints().

Here is the call graph for this function:

◆ createEnd() [1/2]

SimulationAreaIterator SimulationAreaIterator::createEnd ( ) const

Convenience function to create an end-iterator matching to this iterator.

Definition at line 43 of file SimulationAreaIterator.cpp.

44 {
45  return createEnd(m_detector, m_mode);
46 }
SimulationAreaIterator createEnd() const
Convenience function to create an end-iterator matching to this iterator.

References m_detector, and m_mode.

Referenced by IDetector::endNonMaskedPoints(), and IDetector::endRegionOfInterestPoints().

◆ createEnd() [2/2]

SimulationAreaIterator SimulationAreaIterator::createEnd ( const IDetector detector,
Mode  mode 
)
static

Create end-iterator to iterate over all points according to the given mode.

Definition at line 38 of file SimulationAreaIterator.cpp.

39 {
40  return SimulationAreaIterator(detector, mode, detector->sizeOfRegionOfInterest());
41 }

References SimulationAreaIterator(), and IDetector::sizeOfRegionOfInterest().

Here is the call graph for this function:

◆ detectorIndex()

size_t SimulationAreaIterator::detectorIndex ( ) const

Definition at line 53 of file SimulationAreaIterator.cpp.

54 {
56 }
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

References m_detector, m_index, and IDetector::regionOfInterestIndexToDetectorIndex().

Referenced by IDetector::active_indices(), and isMasked().

Here is the call graph for this function:

◆ isMasked()

bool SimulationAreaIterator::isMasked ( size_t  index) const
private

Check whether masked according to the actual mode (always false if mode is regionOfInterest). index is an ROI index.

Definition at line 84 of file SimulationAreaIterator.cpp.

85 {
86  if (m_mode == regionOfInterest)
87  return false;
88 
89  const auto* masks = m_detector->detectorMask();
91  return (masks && masks->isMasked(detectorIndex));
92 }
const DetectorMask * detectorMask() const
Definition: IDetector.cpp:372

References detectorIndex(), IDetector::detectorMask(), m_detector, m_mode, regionOfInterest, and IDetector::regionOfInterestIndexToDetectorIndex().

Referenced by SimulationAreaIterator(), and nextIndex().

Here is the call graph for this function:

◆ nextIndex()

size_t SimulationAreaIterator::nextIndex ( size_t  currentIndex)
private

Definition at line 67 of file SimulationAreaIterator.cpp.

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 }

References isMasked(), and m_maxIndex.

Referenced by SimulationAreaIterator(), and operator++().

Here is the call graph for this function:

◆ operator!=()

bool SimulationAreaIterator::operator!= ( const SimulationAreaIterator right) const
inline

Definition at line 79 of file SimulationAreaIterator.h.

80 {
81  return !(*this == right);
82 }

◆ operator++()

SimulationAreaIterator & SimulationAreaIterator::operator++ ( )

prefix increment

Definition at line 58 of file SimulationAreaIterator.cpp.

59 {
60  size_t index = nextIndex(m_index);
61  if (index != m_index)
62  m_index = index;
63 
64  return *this;
65 }

References m_index, and nextIndex().

Here is the call graph for this function:

◆ operator==()

bool SimulationAreaIterator::operator== ( const SimulationAreaIterator other) const
inline

Definition at line 74 of file SimulationAreaIterator.h.

75 {
76  return m_detector == other.m_detector && m_index == other.m_index && m_mode == other.m_mode;
77 }

References m_detector, m_index, and m_mode.

◆ roiIndex()

size_t SimulationAreaIterator::roiIndex ( ) const

Definition at line 48 of file SimulationAreaIterator.cpp.

49 {
50  return m_index;
51 }

References m_index.

Referenced by IDetector::applyDetectorResolution().

Member Data Documentation

◆ m_detector

const IDetector* SimulationAreaIterator::m_detector
private

Definition at line 68 of file SimulationAreaIterator.h.

Referenced by createEnd(), detectorIndex(), isMasked(), and operator==().

◆ m_index

size_t SimulationAreaIterator::m_index
private

ROI related index.

Definition at line 69 of file SimulationAreaIterator.h.

Referenced by SimulationAreaIterator(), detectorIndex(), operator++(), operator==(), and roiIndex().

◆ m_maxIndex

size_t SimulationAreaIterator::m_maxIndex
private

ROI related maximum index.

Definition at line 70 of file SimulationAreaIterator.h.

Referenced by SimulationAreaIterator(), and nextIndex().

◆ m_mode

Mode SimulationAreaIterator::m_mode
private

Definition at line 71 of file SimulationAreaIterator.h.

Referenced by createEnd(), isMasked(), and operator==().


The documentation for this class was generated from the following files: