BornAgain  1.18.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 scattering at grazing incidence
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 #ifndef BORNAGAIN_CORE_DETECTOR_REGIONOFINTEREST_H
16 #define BORNAGAIN_CORE_DETECTOR_REGIONOFINTEREST_H
17 
18 #include "Base/Types/ICloneable.h"
19 #include <memory>
20 #include <vector>
21 
22 class Rectangle;
23 class IDetector2D;
24 class IAxis;
25 template <class T> class OutputData;
26 
27 //! Defines rectangular area for the detector which will be simulated/fitted.
28 //! @ingroup detector
29 
31 {
32 public:
33  RegionOfInterest(const IDetector2D& detector, double xlow, double ylow, double xup, double yup);
34  RegionOfInterest(const OutputData<double>& data, double xlow, double ylow, double xup,
35  double yup);
36 
37  RegionOfInterest& operator=(const RegionOfInterest& other) = delete;
38  RegionOfInterest* clone() const;
40 
41  double getXlow() const;
42  double getYlow() const;
43  double getXup() const;
44  double getYup() const;
45 
46  //! Converts roi index to the detector index.
47  size_t detectorIndex(size_t roiIndex) const;
48 
49  //! Converts global detector index to ROI index.
50  size_t roiIndex(size_t detectorIndex) const;
51 
52  //! Number of detector bins in ROI area
53  size_t roiSize() const;
54 
55  //! Number of detector bins.
56  size_t detectorSize() const;
57 
58  bool isInROI(size_t detectorIndex) const;
59 
60  std::unique_ptr<IAxis> clipAxisToRoi(size_t axis_index, const IAxis& axis) const;
61 
62 private:
63  RegionOfInterest(double xlow, double ylow, double xup, double yup);
64  RegionOfInterest(const RegionOfInterest& other);
65 
66  size_t xcoord(size_t index, const std::vector<size_t>& dims) const;
67  size_t ycoord(size_t index, const std::vector<size_t>& dims) const;
68 
69  void initFrom(const IAxis& x_axis, const IAxis& y_axis);
70 
71  std::unique_ptr<Rectangle> m_rectangle;
72  //! Number of bins on detector axes corresponding to roi-rectangle.
73  size_t m_ax1, m_ay1, m_ax2, m_ay2;
74  //! Detector global index corresponding to the lower left corner of ROI
75  size_t m_glob_index0;
76  std::vector<size_t> m_detector_dims;
77  std::vector<size_t> m_roi_dims;
78 };
79 
80 inline size_t RegionOfInterest::xcoord(size_t index, const std::vector<size_t>& dims) const
81 {
82  return index / dims[1] % dims[0];
83 }
84 
85 inline size_t RegionOfInterest::ycoord(size_t index, const std::vector<size_t>& dims) const
86 {
87  return index % dims[1];
88 }
89 
90 #endif // BORNAGAIN_CORE_DETECTOR_REGIONOFINTEREST_H
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
Template class to store data of any type in multi-dimensional space.
Definition: OutputData.h:33
The rectangle shape having its axis aligned to the (non-rotated) coordinate system.
Definition: Rectangle.h:24
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