BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IDetector2D.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Detector/IDetector2D.h
6 //! @brief Defines interface IDetector2D.
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 #ifndef BORNAGAIN_CORE_DETECTOR_IDETECTOR2D_H
16 #define BORNAGAIN_CORE_DETECTOR_IDETECTOR2D_H
17 
20 #include <memory>
21 
22 class Beam;
23 class IPixel;
24 class IShape2D;
25 class DetectorContext;
26 
27 //! Abstract 2D detector interface.
28 //! @ingroup detector
29 
30 class IDetector2D : public IDetector
31 {
32 public:
33  IDetector2D();
34 
35  IDetector2D* clone() const override = 0;
36 
37  virtual ~IDetector2D();
38 
39  //! Sets detector parameters using angle ranges
40  void setDetectorParameters(size_t n_x, double x_min, double x_max, size_t n_y, double y_min,
41  double y_max);
42 
43  //! Removes all masks from the detector
44  void removeMasks();
45 
46  const DetectorMask* detectorMask() const override;
47 
48  //! Adds mask of given shape to the stack of detector masks. The mask value 'true' means
49  //! that the channel will be excluded from the simulation. The mask which is added last
50  //! has priority.
51  //! @param shape The shape of mask (Rectangle, Polygon, Line, Ellipse)
52  //! @param mask_value The value of mask
53  void addMask(const IShape2D& shape, bool mask_value = true);
54 
55  //! Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
56  void maskAll();
57 
58  //! Returns region of interest if exists.
59  const RegionOfInterest* regionOfInterest() const override;
60 
61  //! Sets rectangular region of interest with lower left and upper right corners defined.
62  void setRegionOfInterest(double xlow, double ylow, double xup, double yup);
63 
64  //! Resets region of interest making whole detector plane available for the simulation.
65  void resetRegionOfInterest() override;
66 
67  //! Returns vector of unmasked detector indices.
68  std::vector<size_t> active_indices() const;
69 
70  //! Creates an IPixel for the given OutputData object and index
71  virtual IPixel* createPixel(size_t index) const = 0;
72 
73  //! Returns index of pixel that contains the specular wavevector.
74  //! If no pixel contains this specular wavevector, the number of pixels is
75  //! returned. This corresponds to an overflow index.
76  virtual size_t indexOfSpecular(const Beam& beam) const = 0;
77 
78 #ifndef SWIG
79  std::unique_ptr<DetectorContext> createContext() const;
80 #endif
81 
82 protected:
83  IDetector2D(const IDetector2D& other);
84 
85  //! Calculate global index from two axis indices
86  size_t getGlobalIndex(size_t x, size_t y) const;
87 
88 private:
89  DetectorMask m_detector_mask;
90  std::unique_ptr<RegionOfInterest> m_region_of_interest;
91 };
92 
93 #endif // BORNAGAIN_CORE_DETECTOR_IDETECTOR2D_H
Defines class DetectorMask.
Defines common detector interface.
Beam defined by wavelength, direction and intensity.
Definition: Beam.h:27
Holds precalculated information for faster SimulationElement generation.
Collection of detector masks.
Definition: DetectorMask.h:29
Abstract 2D detector interface.
Definition: IDetector2D.h:31
void resetRegionOfInterest() override
Resets region of interest making whole detector plane available for the simulation.
Definition: IDetector2D.cpp:54
virtual IPixel * createPixel(size_t index) const =0
Creates an IPixel for the given OutputData object and index.
void setRegionOfInterest(double xlow, double ylow, double xup, double yup)
Sets rectangular region of interest with lower left and upper right corners defined.
Definition: IDetector2D.cpp:48
virtual size_t indexOfSpecular(const Beam &beam) const =0
Returns index of pixel that contains the specular wavevector.
const RegionOfInterest * regionOfInterest() const override
Returns region of interest if exists.
Definition: IDetector2D.cpp:43
void addMask(const IShape2D &shape, bool mask_value=true)
Adds mask of given shape to the stack of detector masks.
Definition: IDetector2D.cpp:79
void setDetectorParameters(size_t n_x, double x_min, double x_max, size_t n_y, double y_min, double y_max)
Sets detector parameters using angle ranges.
Definition: IDetector2D.cpp:35
void removeMasks()
Removes all masks from the detector.
Definition: IDetector2D.cpp:74
void maskAll()
Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
Definition: IDetector2D.cpp:85
size_t getGlobalIndex(size_t x, size_t y) const
Calculate global index from two axis indices.
Definition: IDetector2D.cpp:98
std::vector< size_t > active_indices() const
Returns vector of unmasked detector indices.
Definition: IDetector2D.cpp:60
const DetectorMask * detectorMask() const override
Returns detector masks container.
Definition: IDetector2D.cpp:93
Abstract detector interface.
Definition: IDetector.h:36
Interface for a function that maps [0,1]x[0,1] to the kvectors in a pixel.
Definition: IPixel.h:24
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
Defines rectangular area for the detector which will be simulated/fitted.