BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RegionOfInterest Class Reference

Defines rectangular area for the detector which will be simulated/fitted. More...

Inheritance diagram for RegionOfInterest:
[legend]
Collaboration diagram for RegionOfInterest:
[legend]

Public Member Functions

 RegionOfInterest (const IDetector2D &detector, double xlow, double ylow, double xup, double yup)
 
 RegionOfInterest (const OutputData< double > &data, double xlow, double ylow, double xup, double yup)
 
 ~RegionOfInterest ()
 
std::unique_ptr< IAxisclipAxisToRoi (size_t axis_index, const IAxis &axis) const
 
RegionOfInterestclone () const
 
size_t detectorIndex (size_t roiIndex) const
 Converts roi index to the detector index. More...
 
size_t detectorSize () const
 Number of detector bins. More...
 
double getXlow () const
 
double getXup () const
 
double getYlow () const
 
double getYup () const
 
bool isInROI (size_t detectorIndex) const
 
RegionOfInterestoperator= (const RegionOfInterest &other)=delete
 
size_t roiIndex (size_t detectorIndex) const
 Converts global detector index to ROI index. More...
 
size_t roiSize () const
 Number of detector bins in ROI area. More...
 
virtual void transferToCPP ()
 Used for Python overriding of clone (see swig/tweaks.py) More...
 

Private Member Functions

 RegionOfInterest (const RegionOfInterest &other)
 
 RegionOfInterest (double xlow, double ylow, double xup, double yup)
 
void initFrom (const IAxis &x_axis, const IAxis &y_axis)
 
size_t xcoord (size_t index, const std::vector< size_t > &dims) const
 
size_t ycoord (size_t index, const std::vector< size_t > &dims) const
 

Private Attributes

size_t m_ax1
 Number of bins on detector axes corresponding to roi-rectangle. More...
 
size_t m_ax2
 
size_t m_ay1
 
size_t m_ay2
 
std::vector< size_t > m_detector_dims
 
size_t m_glob_index0
 Detector global index corresponding to the lower left corner of ROI. More...
 
std::unique_ptr< Rectanglem_rectangle
 
std::vector< size_t > m_roi_dims
 

Detailed Description

Defines rectangular area for the detector which will be simulated/fitted.

Definition at line 35 of file RegionOfInterest.h.

Constructor & Destructor Documentation

◆ RegionOfInterest() [1/4]

RegionOfInterest::RegionOfInterest ( const IDetector2D detector,
double  xlow,
double  ylow,
double  xup,
double  yup 
)

Definition at line 19 of file RegionOfInterest.cpp.

21  : RegionOfInterest(xlow, ylow, xup, yup)
22 {
23  initFrom(detector.axis(0), detector.axis(1));
24 }
const IAxis & axis(size_t index) const
Definition: IDetector.cpp:56
void initFrom(const IAxis &x_axis, const IAxis &y_axis)
RegionOfInterest(const IDetector2D &detector, double xlow, double ylow, double xup, double yup)

References IDetector::axis(), and initFrom().

Referenced by clone().

Here is the call graph for this function:

◆ RegionOfInterest() [2/4]

RegionOfInterest::RegionOfInterest ( const OutputData< double > &  data,
double  xlow,
double  ylow,
double  xup,
double  yup 
)

Definition at line 26 of file RegionOfInterest.cpp.

28  : RegionOfInterest(xlow, ylow, xup, yup)
29 {
30  if (data.rank() != 2)
31  throw std::runtime_error("RegionOfInterest::RegionOfInterest() -> Error. "
32  "Data is not two-dimensional.");
33 
34  initFrom(data.axis(0), data.axis(1));
35 }
size_t rank() const
Returns number of dimensions.
Definition: OutputData.h:56
const IAxis & axis(size_t serial_number) const
returns axis with given serial number
Definition: OutputData.h:318

References OutputData< T >::axis(), initFrom(), and OutputData< T >::rank().

Here is the call graph for this function:

◆ ~RegionOfInterest()

RegionOfInterest::~RegionOfInterest ( )
default

◆ RegionOfInterest() [3/4]

RegionOfInterest::RegionOfInterest ( double  xlow,
double  ylow,
double  xup,
double  yup 
)
private

Definition at line 37 of file RegionOfInterest.cpp.

38  : m_rectangle(new Rectangle(xlow, ylow, xup, yup))
39  , m_ax1(0)
40  , m_ay1(0)
41  , m_ax2(0)
42  , m_ay2(0)
43  , m_glob_index0(0)
44 {
45 }
A rectangle, for use in detector masks.
Definition: Rectangle.h:25
size_t m_ax1
Number of bins on detector axes corresponding to roi-rectangle.
std::unique_ptr< Rectangle > m_rectangle
size_t m_glob_index0
Detector global index corresponding to the lower left corner of ROI.

◆ RegionOfInterest() [4/4]

RegionOfInterest::RegionOfInterest ( const RegionOfInterest other)
private

Definition at line 54 of file RegionOfInterest.cpp.

55  : ICloneable()
56  , m_rectangle(other.m_rectangle->clone())
57  , m_ax1(other.m_ax1)
58  , m_ay1(other.m_ay1)
59  , m_ax2(other.m_ax2)
60  , m_ay2(other.m_ay2)
63  , m_roi_dims(other.m_roi_dims)
64 {
65 }
ICloneable()=default
std::vector< size_t > m_detector_dims
std::vector< size_t > m_roi_dims

Member Function Documentation

◆ clipAxisToRoi()

std::unique_ptr< IAxis > RegionOfInterest::clipAxisToRoi ( size_t  axis_index,
const IAxis axis 
) const

Definition at line 127 of file RegionOfInterest.cpp.

128 {
129  size_t nbin1 = (axis_index == 0 ? m_ax1 : m_ay1);
130  size_t nbin2 = (axis_index == 0 ? m_ax2 : m_ay2);
131  return std::unique_ptr<IAxis>(new FixedBinAxis(
132  axis.getName(), nbin2 - nbin1 + 1, axis.bin(nbin1).m_lower, axis.bin(nbin2).m_upper));
133 }
Axis with fixed bin size.
Definition: FixedBinAxis.h:23
virtual Bin1D bin(size_t index) const =0
retrieve a 1d bin for the given index
std::string getName() const
retrieve the label of the axis
Definition: IAxis.h:40
double m_upper
upper bound of the bin
Definition: Bin.h:24
double m_lower
lower bound of the bin
Definition: Bin.h:23

References IAxis::bin(), IAxis::getName(), m_ax1, m_ax2, m_ay1, m_ay2, Bin1D::m_lower, and Bin1D::m_upper.

Here is the call graph for this function:

◆ clone()

RegionOfInterest * RegionOfInterest::clone ( ) const
virtual

Implements ICloneable.

Definition at line 47 of file RegionOfInterest.cpp.

48 {
49  return new RegionOfInterest(*this);
50 }

References RegionOfInterest().

Referenced by IDetector2D::IDetector2D().

Here is the call graph for this function:

◆ detectorIndex()

size_t RegionOfInterest::detectorIndex ( size_t  roiIndex) const

Converts roi index to the detector index.

Definition at line 87 of file RegionOfInterest.cpp.

88 {
91 }
size_t xcoord(size_t index, const std::vector< size_t > &dims) const
size_t ycoord(size_t index, const std::vector< size_t > &dims) const
size_t roiIndex(size_t detectorIndex) const
Converts global detector index to ROI index.

References m_detector_dims, m_glob_index0, m_roi_dims, roiIndex(), xcoord(), and ycoord().

Referenced by SimulationArea::detectorIndex(), and isInROI().

Here is the call graph for this function:

◆ detectorSize()

size_t RegionOfInterest::detectorSize ( ) const

Number of detector bins.

Definition at line 111 of file RegionOfInterest.cpp.

112 {
113  return m_detector_dims[0] * m_detector_dims[1];
114 }

References m_detector_dims.

◆ getXlow()

double RegionOfInterest::getXlow ( ) const

Definition at line 67 of file RegionOfInterest.cpp.

68 {
69  return m_rectangle->getXlow();
70 }

References m_rectangle.

Referenced by initFrom(), and TransformFromDomain::setMaskContainer().

◆ getXup()

double RegionOfInterest::getXup ( ) const

Definition at line 77 of file RegionOfInterest.cpp.

78 {
79  return m_rectangle->getXup();
80 }

References m_rectangle.

Referenced by initFrom(), and TransformFromDomain::setMaskContainer().

◆ getYlow()

double RegionOfInterest::getYlow ( ) const

Definition at line 72 of file RegionOfInterest.cpp.

73 {
74  return m_rectangle->getYlow();
75 }

References m_rectangle.

Referenced by initFrom(), and TransformFromDomain::setMaskContainer().

◆ getYup()

double RegionOfInterest::getYup ( ) const

Definition at line 82 of file RegionOfInterest.cpp.

83 {
84  return m_rectangle->getYup();
85 }

References m_rectangle.

Referenced by initFrom(), and TransformFromDomain::setMaskContainer().

◆ initFrom()

void RegionOfInterest::initFrom ( const IAxis x_axis,
const IAxis y_axis 
)
private

Definition at line 135 of file RegionOfInterest.cpp.

136 {
137  m_detector_dims.push_back(x_axis.size());
138  m_detector_dims.push_back(y_axis.size());
139 
140  m_ax1 = x_axis.findClosestIndex(getXlow());
141  m_ax2 = x_axis.findClosestIndex(getXup());
142  m_ay1 = y_axis.findClosestIndex(getYlow());
143  m_ay2 = y_axis.findClosestIndex(getYup());
144 
145  m_roi_dims.push_back(m_ax2 - m_ax1 + 1);
146  m_roi_dims.push_back(m_ay2 - m_ay1 + 1);
147 
149 }
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual size_t size() const =0
retrieve the number of bins
double getYlow() const
double getYup() const
double getXlow() const
double getXup() const

References IAxis::findClosestIndex(), getXlow(), getXup(), getYlow(), getYup(), m_ax1, m_ax2, m_ay1, m_ay2, m_detector_dims, m_glob_index0, m_roi_dims, and IAxis::size().

Referenced by RegionOfInterest().

Here is the call graph for this function:

◆ isInROI()

bool RegionOfInterest::isInROI ( size_t  detectorIndex) const

Definition at line 116 of file RegionOfInterest.cpp.

117 {
118  size_t ny = ycoord(detectorIndex, m_detector_dims);
119  if (ny < m_ay1 || ny > m_ay2)
120  return false;
121  size_t nx = xcoord(detectorIndex, m_detector_dims);
122  if (nx < m_ax1 || nx > m_ax2)
123  return false;
124  return true;
125 }
size_t detectorIndex(size_t roiIndex) const
Converts roi index to the detector index.

References detectorIndex(), m_ax2, m_ay2, m_detector_dims, xcoord(), and ycoord().

Here is the call graph for this function:

◆ operator=()

RegionOfInterest& RegionOfInterest::operator= ( const RegionOfInterest other)
delete

◆ roiIndex()

size_t RegionOfInterest::roiIndex ( size_t  detectorIndex) const

Converts global detector index to ROI index.

Definition at line 93 of file RegionOfInterest.cpp.

94 {
95  size_t ny = ycoord(globalIndex, m_detector_dims);
96  if (ny < m_ay1 || ny > m_ay2)
97  throw std::runtime_error("RegionOfInterest::roiIndex() -> Error.");
98 
99  size_t nx = xcoord(globalIndex, m_detector_dims);
100  if (nx < m_ax1 || nx > m_ax2)
101  throw std::runtime_error("RegionOfInterest::roiIndex() -> Error.");
102 
103  return ny - m_ay1 + (nx - m_ax1) * m_roi_dims[1];
104 }

References m_ax1, m_ax2, m_ay1, m_ay2, m_detector_dims, m_roi_dims, xcoord(), and ycoord().

Referenced by detectorIndex().

Here is the call graph for this function:

◆ roiSize()

size_t RegionOfInterest::roiSize ( ) const

Number of detector bins in ROI area.

Definition at line 106 of file RegionOfInterest.cpp.

107 {
108  return m_roi_dims[0] * m_roi_dims[1];
109 }

References m_roi_dims.

Referenced by SimulationArea::SimulationArea().

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 34 of file ICloneable.h.

◆ xcoord()

size_t RegionOfInterest::xcoord ( size_t  index,
const std::vector< size_t > &  dims 
) const
inlineprivate

Definition at line 84 of file RegionOfInterest.h.

85 {
86  return index / dims[1] % dims[0];
87 }

Referenced by detectorIndex(), isInROI(), and roiIndex().

◆ ycoord()

size_t RegionOfInterest::ycoord ( size_t  index,
const std::vector< size_t > &  dims 
) const
inlineprivate

Definition at line 89 of file RegionOfInterest.h.

90 {
91  return index % dims[1];
92 }

Referenced by detectorIndex(), isInROI(), and roiIndex().

Member Data Documentation

◆ m_ax1

size_t RegionOfInterest::m_ax1
private

Number of bins on detector axes corresponding to roi-rectangle.

Definition at line 77 of file RegionOfInterest.h.

Referenced by clipAxisToRoi(), initFrom(), and roiIndex().

◆ m_ax2

size_t RegionOfInterest::m_ax2
private

Definition at line 77 of file RegionOfInterest.h.

Referenced by clipAxisToRoi(), initFrom(), isInROI(), and roiIndex().

◆ m_ay1

size_t RegionOfInterest::m_ay1
private

Definition at line 77 of file RegionOfInterest.h.

Referenced by clipAxisToRoi(), initFrom(), and roiIndex().

◆ m_ay2

size_t RegionOfInterest::m_ay2
private

Definition at line 77 of file RegionOfInterest.h.

Referenced by clipAxisToRoi(), initFrom(), isInROI(), and roiIndex().

◆ m_detector_dims

std::vector<size_t> RegionOfInterest::m_detector_dims
private

Definition at line 80 of file RegionOfInterest.h.

Referenced by detectorIndex(), detectorSize(), initFrom(), isInROI(), and roiIndex().

◆ m_glob_index0

size_t RegionOfInterest::m_glob_index0
private

Detector global index corresponding to the lower left corner of ROI.

Definition at line 79 of file RegionOfInterest.h.

Referenced by detectorIndex(), and initFrom().

◆ m_rectangle

std::unique_ptr<Rectangle> RegionOfInterest::m_rectangle
private

Definition at line 75 of file RegionOfInterest.h.

Referenced by getXlow(), getXup(), getYlow(), and getYup().

◆ m_roi_dims

std::vector<size_t> RegionOfInterest::m_roi_dims
private

Definition at line 81 of file RegionOfInterest.h.

Referenced by detectorIndex(), initFrom(), roiIndex(), and roiSize().


The documentation for this class was generated from the following files: