BornAgain  1.19.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 reflection and scattering
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 USER_API
16 #ifndef BORNAGAIN_DEVICE_DETECTOR_IDETECTOR2D_H
17 #define BORNAGAIN_DEVICE_DETECTOR_IDETECTOR2D_H
18 
21 #include <memory>
22 
23 class Beam;
24 class IPixel;
25 class IShape2D;
26 class DetectorContext;
27 
28 //! Abstract 2D detector interface.
29 //! @ingroup detector
30 
31 class IDetector2D : public IDetector {
32 public:
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  const DetectorMask* detectorMask() const override;
44 
45  //! Adds mask of given shape to the stack of detector masks. The mask value 'true' means
46  //! that the channel will be excluded from the simulation. The mask which is added last
47  //! has priority.
48  //! @param shape The shape of mask (Rectangle, Polygon, Line, Ellipse)
49  //! @param mask_value The value of mask
50  void addMask(const IShape2D& shape, bool mask_value = true);
51 
52  //! Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
53  void maskAll();
54 
55  //! Returns region of interest if exists.
56  const RegionOfInterest* regionOfInterest() const override;
57 
58  //! Sets rectangular region of interest with lower left and upper right corners defined.
59  void setRegionOfInterest(double xlow, double ylow, double xup, double yup);
60 
61  //! Resets region of interest making whole detector plane available for the simulation.
62  void resetRegionOfInterest() override;
63 
64  //! Returns vector of unmasked detector indices.
65  std::vector<size_t> active_indices() const;
66 
67  //! Creates an IPixel for the given OutputData object and index
68  virtual IPixel* createPixel(size_t index) const = 0;
69 
70  //! Returns index of pixel that contains the specular wavevector.
71  //! If no pixel contains this specular wavevector, the number of pixels is
72  //! returned. This corresponds to an overflow index.
73  virtual size_t indexOfSpecular(const Beam& beam) const = 0;
74 
75 #ifndef SWIG
76  std::unique_ptr<DetectorContext> createContext() const;
77 #endif
78 
79 protected:
80  IDetector2D(const IDetector2D& other);
81 
82  //! Calculate global index from two axis indices
83  size_t getGlobalIndex(size_t x, size_t y) const;
84 
85 private:
87  std::unique_ptr<RegionOfInterest> m_region_of_interest;
88 };
89 
90 #endif // BORNAGAIN_DEVICE_DETECTOR_IDETECTOR2D_H
91 #endif // USER_API
Defines class DetectorMask.
Defines common detector interface.
An incident neutron or x-ray beam.
Definition: Beam.h:27
Holds precalculated information for faster SimulationElement generation.
Collection of detector masks.
Definition: DetectorMask.h:28
Abstract 2D detector interface.
Definition: IDetector2D.h:31
DetectorMask m_detector_mask
Definition: IDetector2D.h:86
void resetRegionOfInterest() override
Resets region of interest making whole detector plane available for the simulation.
Definition: IDetector2D.cpp:54
std::unique_ptr< DetectorContext > createContext() const
Definition: IDetector2D.cpp:69
virtual IPixel * createPixel(size_t index) const =0
Creates an IPixel for the given OutputData object and index.
std::unique_ptr< RegionOfInterest > m_region_of_interest
Definition: IDetector2D.h:87
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.
IDetector2D * clone() const override=0
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:74
virtual ~IDetector2D()
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 maskAll()
Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
Definition: IDetector2D.cpp:80
size_t getGlobalIndex(size_t x, size_t y) const
Calculate global index from two axis indices.
Definition: IDetector2D.cpp:92
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:87
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:25
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
Defines rectangular area for the detector which will be simulated/fitted.