BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RegionOfInterest Class Reference
Inheritance diagram for RegionOfInterest:
Collaboration diagram for RegionOfInterest:

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)
 
RegionOfInterestoperator= (const RegionOfInterest &other)=delete
 
RegionOfInterestclone () const
 
 ~RegionOfInterest ()
 
double getXlow () const
 
double getYlow () const
 
double getXup () const
 
double getYup () const
 
size_t detectorIndex (size_t roiIndex) const
 
size_t roiIndex (size_t detectorIndex) const
 
size_t roiSize () const
 
size_t detectorSize () const
 
bool isInROI (size_t detectorIndex) const
 
std::unique_ptr< IAxisclipAxisToRoi (size_t axis_index, const IAxis &axis) const
 
virtual void transferToCPP ()
 

Private Member Functions

 RegionOfInterest (double xlow, double ylow, double xup, double yup)
 
 RegionOfInterest (const RegionOfInterest &other)
 
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
 
void initFrom (const IAxis &x_axis, const IAxis &y_axis)
 

Private Attributes

std::unique_ptr< Rectanglem_rectangle
 
size_t m_ax1
 
size_t m_ay1
 
size_t m_ax2
 
size_t m_ay2
 
size_t m_glob_index0
 
std::vector< size_t > m_detector_dims
 
std::vector< size_t > m_roi_dims
 

Detailed Description

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

Definition at line 30 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.getAxis(0), detector.getAxis(1));
24 }
const IAxis & getAxis(size_t index) const
Definition: IDetector.cpp:54
void initFrom(const IAxis &x_axis, const IAxis &y_axis)
RegionOfInterest(const IDetector2D &detector, double xlow, double ylow, double xup, double yup)

References IDetector::getAxis(), 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.getRank() != 2)
31  throw Exceptions::RuntimeErrorException("RegionOfInterest::RegionOfInterest() -> Error. "
32  "Data is not two-dimensional.");
33 
34  initFrom(data.getAxis(0), data.getAxis(1));
35 }
size_t getRank() const
Returns number of dimensions.
Definition: OutputData.h:59
const IAxis & getAxis(size_t serial_number) const
returns axis with given serial number
Definition: OutputData.h:314

References OutputData< T >::getAxis(), OutputData< T >::getRank(), and initFrom().

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)), m_ax1(0), m_ay1(0), m_ax2(0), m_ay2(0),
39  m_glob_index0(0)
40 {
41 }
The rectangle shape having its axis aligned to the (non-rotated) coordinate system.
Definition: Rectangle.h:24
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 50 of file RegionOfInterest.cpp.

51  : ICloneable(), m_rectangle(other.m_rectangle->clone()), m_ax1(other.m_ax1), m_ay1(other.m_ay1),
52  m_ax2(other.m_ax2), m_ay2(other.m_ay2), m_glob_index0(other.m_glob_index0),
54 {
55 }
ICloneable()=default
std::vector< size_t > m_detector_dims
std::vector< size_t > m_roi_dims

Member Function Documentation

◆ operator=()

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

◆ clone()

RegionOfInterest * RegionOfInterest::clone ( ) const
virtual

Implements ICloneable.

Definition at line 43 of file RegionOfInterest.cpp.

44 {
45  return new RegionOfInterest(*this);
46 }

References RegionOfInterest().

Referenced by IDetector2D::IDetector2D().

Here is the call graph for this function:

◆ getXlow()

double RegionOfInterest::getXlow ( ) const

Definition at line 57 of file RegionOfInterest.cpp.

58 {
59  return m_rectangle->getXlow();
60 }

References m_rectangle.

Referenced by SimulationToPython::defineDetector(), and initFrom().

◆ getYlow()

double RegionOfInterest::getYlow ( ) const

Definition at line 62 of file RegionOfInterest.cpp.

63 {
64  return m_rectangle->getYlow();
65 }

References m_rectangle.

Referenced by SimulationToPython::defineDetector(), and initFrom().

◆ getXup()

double RegionOfInterest::getXup ( ) const

Definition at line 67 of file RegionOfInterest.cpp.

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

References m_rectangle.

Referenced by SimulationToPython::defineDetector(), and initFrom().

◆ getYup()

double RegionOfInterest::getYup ( ) const

Definition at line 72 of file RegionOfInterest.cpp.

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

References m_rectangle.

Referenced by SimulationToPython::defineDetector(), and initFrom().

◆ detectorIndex()

size_t RegionOfInterest::detectorIndex ( size_t  roiIndex) const

Converts roi index to the detector index.

Definition at line 77 of file RegionOfInterest.cpp.

78 {
81 }
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:

◆ roiIndex()

size_t RegionOfInterest::roiIndex ( size_t  detectorIndex) const

Converts global detector index to ROI index.

Definition at line 83 of file RegionOfInterest.cpp.

84 {
85  size_t ny = ycoord(globalIndex, m_detector_dims);
86  if (ny < m_ay1 || ny > m_ay2)
87  throw Exceptions::RuntimeErrorException("RegionOfInterest::roiIndex() -> Error.");
88 
89  size_t nx = xcoord(globalIndex, m_detector_dims);
90  if (nx < m_ax1 || nx > m_ax2)
91  throw Exceptions::RuntimeErrorException("RegionOfInterest::roiIndex() -> Error.");
92 
93  return ny - m_ay1 + (nx - m_ax1) * m_roi_dims[1];
94 }

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 96 of file RegionOfInterest.cpp.

97 {
98  return m_roi_dims[0] * m_roi_dims[1];
99 }

References m_roi_dims.

Referenced by SimulationArea::SimulationArea().

◆ detectorSize()

size_t RegionOfInterest::detectorSize ( ) const

Number of detector bins.

Definition at line 101 of file RegionOfInterest.cpp.

102 {
103  return m_detector_dims[0] * m_detector_dims[1];
104 }

References m_detector_dims.

◆ isInROI()

bool RegionOfInterest::isInROI ( size_t  detectorIndex) const

Definition at line 106 of file RegionOfInterest.cpp.

107 {
108  size_t ny = ycoord(detectorIndex, m_detector_dims);
109  if (ny < m_ay1 || ny > m_ay2)
110  return false;
111  size_t nx = xcoord(detectorIndex, m_detector_dims);
112  if (nx < m_ax1 || nx > m_ax2)
113  return false;
114  return true;
115 }
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:

◆ clipAxisToRoi()

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

Definition at line 117 of file RegionOfInterest.cpp.

118 {
119  size_t nbin1 = (axis_index == 0 ? m_ax1 : m_ay1);
120  size_t nbin2 = (axis_index == 0 ? m_ax2 : m_ay2);
121  return std::unique_ptr<IAxis>(new FixedBinAxis(
122  axis.getName(), nbin2 - nbin1 + 1, axis.getBin(nbin1).m_lower, axis.getBin(nbin2).m_upper));
123 }
Axis with fixed bin size.
Definition: FixedBinAxis.h:24
virtual Bin1D getBin(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::getBin(), 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:

◆ xcoord()

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

Definition at line 80 of file RegionOfInterest.h.

81 {
82  return index / dims[1] % dims[0];
83 }

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 85 of file RegionOfInterest.h.

86 {
87  return index % dims[1];
88 }

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

◆ initFrom()

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

Definition at line 125 of file RegionOfInterest.cpp.

126 {
127  m_detector_dims.push_back(x_axis.size());
128  m_detector_dims.push_back(y_axis.size());
129 
130  m_ax1 = x_axis.findClosestIndex(getXlow());
131  m_ax2 = x_axis.findClosestIndex(getXup());
132  m_ay1 = y_axis.findClosestIndex(getYlow());
133  m_ay2 = y_axis.findClosestIndex(getYup());
134 
135  m_roi_dims.push_back(m_ax2 - m_ax1 + 1);
136  m_roi_dims.push_back(m_ay2 - m_ay1 + 1);
137 
139 }
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:

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

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

Definition at line 34 of file ICloneable.h.

Member Data Documentation

◆ m_rectangle

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

Definition at line 71 of file RegionOfInterest.h.

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

◆ m_ax1

size_t RegionOfInterest::m_ax1
private

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

Definition at line 73 of file RegionOfInterest.h.

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

◆ m_ay1

size_t RegionOfInterest::m_ay1
private

Definition at line 73 of file RegionOfInterest.h.

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

◆ m_ax2

size_t RegionOfInterest::m_ax2
private

Definition at line 73 of file RegionOfInterest.h.

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

◆ m_ay2

size_t RegionOfInterest::m_ay2
private

Definition at line 73 of file RegionOfInterest.h.

Referenced by clipAxisToRoi(), 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 75 of file RegionOfInterest.h.

Referenced by detectorIndex(), and initFrom().

◆ m_detector_dims

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

Definition at line 76 of file RegionOfInterest.h.

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

◆ m_roi_dims

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

Definition at line 77 of file RegionOfInterest.h.

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


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