BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationArea.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Detector/SimulationArea.cpp
6 //! @brief Implements class SimulationArea.
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 
19 #include "Device/Mask/Rectangle.h"
20 #include <sstream>
21 
22 SimulationArea::SimulationArea(const IDetector* detector) : m_detector(detector), m_max_index(0)
23 {
24  if (m_detector == nullptr)
25  throw std::runtime_error("SimulationArea::SimulationArea: null pointer passed"
26  " as detector");
27 
28  if (m_detector->dimension() == 0)
29  throw std::runtime_error(
30  "SimulationArea::SimulationArea: detector of unspecified dimensionality");
31 
32  if (m_detector->regionOfInterest())
33  m_max_index = m_detector->regionOfInterest()->roiSize();
34  else
35  m_max_index = m_detector->totalSize();
36 }
37 
38 SimulationAreaIterator SimulationArea::begin()
39 {
40  return SimulationAreaIterator(this, 0);
41 }
42 
43 SimulationAreaIterator SimulationArea::end()
44 {
45  return SimulationAreaIterator(this, totalSize());
46 }
47 
48 bool SimulationArea::isMasked(size_t index) const
49 {
50  auto masks = m_detector->detectorMask();
51  return (masks && masks->hasMasks() && masks->isMasked(detectorIndex(index)));
52 }
53 
54 size_t SimulationArea::roiIndex(size_t index) const
55 {
56  return index;
57 }
58 
59 size_t SimulationArea::detectorIndex(size_t index) const
60 {
61  if (!m_detector->regionOfInterest())
62  return index;
63 
64  return m_detector->regionOfInterest()->detectorIndex(index);
65 }
66 
67 // --------------------------------------------------------------------------------------
68 
69 SimulationRoiArea::SimulationRoiArea(const IDetector* detector) : SimulationArea(detector) {}
70 
71 bool SimulationRoiArea::isMasked(size_t) const
72 {
73  return false;
74 }
Defines class DetectorMask.
Defines common detector interface.
Defines class Rectangle.
Defines class RegionOfInterest.
Defines class SimulationArea.
Abstract detector interface.
Definition: IDetector.h:36
virtual const DetectorMask * detectorMask() const =0
Returns detector masks container.
virtual const RegionOfInterest * regionOfInterest() const =0
Returns region of interest if exists.
size_t detectorIndex(size_t roiIndex) const
Converts roi index to the detector index.
An iterator for SimulationArea.
Holds iteration logic over active detector channels in the presence of masked areas and RegionOfInter...
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.
virtual bool isMasked(size_t) const
returns true if given iterator index correspond to masked detector channel