BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationAreaIterator.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
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  : m_area(area), m_index(start_at_index), m_element_index(0)
20 {
21  if (m_index > m_area->totalSize())
22  throw Exceptions::RuntimeErrorException("SimulationAreaIterator::SimulationAreaIterator() "
23  "-> Error. Invalid initial index");
24 
27 }
28 
30 {
31  return m_area->roiIndex(m_index);
32 }
33 
35 {
36  return m_area->detectorIndex(m_index);
37 }
38 
40 {
41  size_t index = nextIndex(m_index);
42  if (index != m_index) {
44  m_index = index;
45  }
46  return *this;
47 }
48 
50 {
51  SimulationAreaIterator result(*this);
52  this->operator++();
53  return result;
54 }
55 
56 size_t SimulationAreaIterator::nextIndex(size_t currentIndex)
57 {
58  size_t result = ++currentIndex;
59  if (result < m_area->totalSize()) {
60  while (m_area->isMasked(result)) {
61  ++result;
62  if (result == m_area->totalSize())
63  break;
64  }
65  } else {
66  return m_area->totalSize();
67  }
68  return result;
69 }
Defines interface IDetector2D.
Defines class SimulationArea.
An iterator for SimulationArea.
size_t nextIndex(size_t currentIndex)
const SimulationArea * m_area
SimulationAreaIterator(const SimulationArea *area, size_t start_at_index)
SimulationAreaIterator & operator++()
prefix increment
size_t m_index
global index in detector plane defined by its axes
size_t m_element_index
sequential number for SimulationElementVector
Holds iteration logic over active detector channels in the presence of masked areas and RegionOfInter...
size_t totalSize() const
virtual bool isMasked(size_t index) const
returns true if given iterator index correspond to masked detector channel
size_t detectorIndex(size_t index) const
Return detector index from iterator index.
size_t roiIndex(size_t index) const
Return index in ROI map from iterator index.