BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RegionOfInterest.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Detector/RegionOfInterest.h
6 //! @brief Defines class RegionOfInterest.
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 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_DEVICE_DETECTOR_REGIONOFINTEREST_H
21 #define BORNAGAIN_DEVICE_DETECTOR_REGIONOFINTEREST_H
22 
23 #include "Base/Types/ICloneable.h"
24 #include <memory>
25 #include <vector>
26 
27 class Rectangle;
28 class IDetector2D;
29 class IAxis;
30 template <class T> class OutputData;
31 
32 //! Defines rectangular area for the detector which will be simulated/fitted.
33 //! @ingroup detector
34 
35 class RegionOfInterest : public ICloneable {
36 public:
37  RegionOfInterest(const IDetector2D& detector, double xlow, double ylow, double xup, double yup);
38  RegionOfInterest(const OutputData<double>& data, double xlow, double ylow, double xup,
39  double yup);
40 
41  RegionOfInterest& operator=(const RegionOfInterest& other) = delete;
42  RegionOfInterest* clone() const;
44 
45  double getXlow() const;
46  double getYlow() const;
47  double getXup() const;
48  double getYup() const;
49 
50  //! Converts roi index to the detector index.
51  size_t detectorIndex(size_t roiIndex) const;
52 
53  //! Converts global detector index to ROI index.
54  size_t roiIndex(size_t detectorIndex) const;
55 
56  //! Number of detector bins in ROI area
57  size_t roiSize() const;
58 
59  //! Number of detector bins.
60  size_t detectorSize() const;
61 
62  bool isInROI(size_t detectorIndex) const;
63 
64  std::unique_ptr<IAxis> clipAxisToRoi(size_t axis_index, const IAxis& axis) const;
65 
66 private:
67  RegionOfInterest(double xlow, double ylow, double xup, double yup);
68  RegionOfInterest(const RegionOfInterest& other);
69 
70  size_t xcoord(size_t index, const std::vector<size_t>& dims) const;
71  size_t ycoord(size_t index, const std::vector<size_t>& dims) const;
72 
73  void initFrom(const IAxis& x_axis, const IAxis& y_axis);
74 
75  std::unique_ptr<Rectangle> m_rectangle;
76  //! Number of bins on detector axes corresponding to roi-rectangle.
77  size_t m_ax1, m_ay1, m_ax2, m_ay2;
78  //! Detector global index corresponding to the lower left corner of ROI
79  size_t m_glob_index0;
80  std::vector<size_t> m_detector_dims;
81  std::vector<size_t> m_roi_dims;
82 };
83 
84 inline size_t RegionOfInterest::xcoord(size_t index, const std::vector<size_t>& dims) const
85 {
86  return index / dims[1] % dims[0];
87 }
88 
89 inline size_t RegionOfInterest::ycoord(size_t index, const std::vector<size_t>& dims) const
90 {
91  return index % dims[1];
92 }
93 
94 #endif // BORNAGAIN_DEVICE_DETECTOR_REGIONOFINTEREST_H
95 #endif // USER_API
Defines and implements the standard mix-in ICloneable.
Interface for one-dimensional axes.
Definition: IAxis.h:25
Interface for polymorphic classes that should not be copied, except by explicit cloning.
Definition: ICloneable.h:25
Abstract 2D detector interface.
Definition: IDetector2D.h:31
Templated class to store data of type double or CumulativeValue in multi-dimensional space.
Definition: OutputData.h:32
A rectangle, for use in detector masks.
Definition: Rectangle.h:25
Defines rectangular area for the detector which will be simulated/fitted.
size_t detectorSize() const
Number of detector bins.
bool isInROI(size_t detectorIndex) const
std::unique_ptr< IAxis > clipAxisToRoi(size_t axis_index, const IAxis &axis) const
size_t xcoord(size_t index, const std::vector< size_t > &dims) const
size_t detectorIndex(size_t roiIndex) const
Converts roi index to the detector index.
void initFrom(const IAxis &x_axis, const IAxis &y_axis)
size_t m_ax1
Number of bins on detector axes corresponding to roi-rectangle.
size_t ycoord(size_t index, const std::vector< size_t > &dims) const
std::vector< size_t > m_detector_dims
size_t roiSize() const
Number of detector bins in ROI area.
std::vector< size_t > m_roi_dims
double getYlow() const
size_t roiIndex(size_t detectorIndex) const
Converts global detector index to ROI index.
RegionOfInterest & operator=(const RegionOfInterest &other)=delete
double getYup() const
RegionOfInterest * clone() const
std::unique_ptr< Rectangle > m_rectangle
double getXlow() const
size_t m_glob_index0
Detector global index corresponding to the lower left corner of ROI.
RegionOfInterest(const IDetector2D &detector, double xlow, double ylow, double xup, double yup)
double getXup() const