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

Collection of detector masks. More...

Collaboration diagram for DetectorMask:
[legend]

Public Member Functions

 DetectorMask ()
 
 DetectorMask (const DetectorMask &other)
 
void addMask (const IShape2D &shape, bool mask_value)
 Add mask to the stack of detector masks. More...
 
Histogram2DcreateHistogram () const
 
const OutputData< bool > * getMaskData () const
 
const IShape2DgetMaskShape (size_t mask_index, bool &mask_value) const
 
bool hasMasks () const
 returns true if has masks More...
 
void initMaskData (const IDetector2D &detector)
 Init the map of masks for the given detector plane. More...
 
void initMaskData (const OutputData< double > &data)
 
bool isMasked (size_t index) const
 
int numberOfMaskedChannels () const
 
size_t numberOfMasks () const
 
DetectorMaskoperator= (const DetectorMask &other)
 

Private Member Functions

void process_masks ()
 

Private Attributes

OutputData< bool > m_mask_data
 
std::vector< bool > m_mask_of_shape
 
int m_number_of_masked_channels
 
SafePointerVector< IShape2Dm_shapes
 

Detailed Description

Collection of detector masks.

Definition at line 28 of file DetectorMask.h.

Constructor & Destructor Documentation

◆ DetectorMask() [1/2]

DetectorMask::DetectorMask ( )

Definition at line 19 of file DetectorMask.cpp.

int m_number_of_masked_channels
Definition: DetectorMask.h:66

◆ DetectorMask() [2/2]

DetectorMask::DetectorMask ( const DetectorMask other)

Definition at line 21 of file DetectorMask.cpp.

22  : m_shapes(other.m_shapes)
25 {
27 }
SafePointerVector< IShape2D > m_shapes
Definition: DetectorMask.h:63
std::vector< bool > m_mask_of_shape
Definition: DetectorMask.h:64
OutputData< bool > m_mask_data
Definition: DetectorMask.h:65
void copyFrom(const OutputData< T > &x)
Definition: OutputData.h:267

References OutputData< T >::copyFrom(), and m_mask_data.

Here is the call graph for this function:

Member Function Documentation

◆ addMask()

void DetectorMask::addMask ( const IShape2D shape,
bool  mask_value 
)

Add mask to the stack of detector masks.

The value "true" means that the area will be excluded from the analysis.

Parameters
shapeThe shape of mask.
mask_valueThe value of mask

Definition at line 42 of file DetectorMask.cpp.

43 {
44  m_shapes.push_back(shape.clone());
45  m_mask_of_shape.push_back(mask_value);
48 }
virtual IShape2D * clone() const =0
void clear()
Sets object into initial state (no dimensions, data)
Definition: OutputData.h:470
void push_back(T *pointer)

References OutputData< T >::clear(), IShape2D::clone(), m_mask_data, m_mask_of_shape, m_number_of_masked_channels, m_shapes, and SafePointerVector< T >::push_back().

Referenced by IDetector2D::addMask(), and MaskResultsPresenter::createMaskPresentation().

Here is the call graph for this function:

◆ createHistogram()

Histogram2D * DetectorMask::createHistogram ( ) const

Definition at line 83 of file DetectorMask.cpp.

84 {
85  OutputData<double> data;
87  for (size_t i = 0; i < m_mask_data.getAllocatedSize(); ++i)
88  data[i] = static_cast<double>(m_mask_data[i]);
89  return dynamic_cast<Histogram2D*>(IHistogram::createHistogram(data));
90 }
Two dimensional histogram.
Definition: Histogram2D.h:24
static IHistogram * createHistogram(const OutputData< double > &source)
Definition: IHistogram.cpp:243
void copyShapeFrom(const OutputData< U > &other)
Definition: OutputData.h:277
size_t getAllocatedSize() const
Returns total size of data buffer (product of bin number in every dimension).
Definition: OutputData.h:59

References OutputData< T >::copyShapeFrom(), IHistogram::createHistogram(), OutputData< T >::getAllocatedSize(), and m_mask_data.

Here is the call graph for this function:

◆ getMaskData()

const OutputData<bool>* DetectorMask::getMaskData ( ) const
inline

Definition at line 47 of file DetectorMask.h.

47 { return &m_mask_data; }

References m_mask_data.

◆ getMaskShape()

const IShape2D * DetectorMask::getMaskShape ( size_t  mask_index,
bool &  mask_value 
) const

Definition at line 97 of file DetectorMask.cpp.

98 {
99  if (mask_index >= numberOfMasks())
100  return nullptr;
101  mask_value = m_mask_of_shape[mask_index];
102  return m_shapes[mask_index];
103 }
size_t numberOfMasks() const

References m_mask_of_shape, m_shapes, and numberOfMasks().

Here is the call graph for this function:

◆ hasMasks()

bool DetectorMask::hasMasks ( ) const
inline

returns true if has masks

Definition at line 52 of file DetectorMask.h.

52 { return !m_shapes.empty(); }

References SafePointerVector< T >::empty(), and m_shapes.

Referenced by MaskResultsPresenter::createMaskPresentation().

Here is the call graph for this function:

◆ initMaskData() [1/2]

void DetectorMask::initMaskData ( const IDetector2D detector)

Init the map of masks for the given detector plane.

Definition at line 50 of file DetectorMask.cpp.

51 {
52  if (detector.dimension() != 2)
53  throw std::runtime_error("DetectorMask::initMaskData() -> Error. Attempt "
54  "to add masks to uninitialized detector.");
55 
56  ASSERT(m_shapes.size() == m_mask_of_shape.size());
58 
59  for (size_t dim = 0; dim < detector.dimension(); ++dim) {
60  const IAxis& axis = detector.axis(dim);
61  m_mask_data.addAxis(axis);
62  }
63 
64  process_masks();
65 }
#define ASSERT(condition)
Definition: Assert.h:31
void process_masks()
Interface for one-dimensional axes.
Definition: IAxis.h:25
size_t dimension() const
Returns actual dimensionality of the detector (number of defined axes)
Definition: IDetector.cpp:46
const IAxis & axis(size_t index) const
Definition: IDetector.cpp:56
void addAxis(const IAxis &new_axis)
Definition: OutputData.h:295
size_t size() const

References OutputData< T >::addAxis(), ASSERT, IDetector::axis(), OutputData< T >::clear(), IDetector::dimension(), m_mask_data, m_mask_of_shape, m_shapes, process_masks(), and SafePointerVector< T >::size().

Referenced by IDetector2D::addMask(), MaskResultsPresenter::createMaskPresentation(), IDetector2D::resetRegionOfInterest(), and IDetector2D::setRegionOfInterest().

Here is the call graph for this function:

◆ initMaskData() [2/2]

void DetectorMask::initMaskData ( const OutputData< double > &  data)

Definition at line 67 of file DetectorMask.cpp.

68 {
69  ASSERT(m_shapes.size() == m_mask_of_shape.size());
71 
72  for (size_t dim = 0; dim < data.rank(); ++dim)
73  m_mask_data.addAxis(data.axis(dim));
74 
75  process_masks();
76 }
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 >::addAxis(), ASSERT, OutputData< T >::axis(), OutputData< T >::clear(), m_mask_data, m_mask_of_shape, m_shapes, process_masks(), OutputData< T >::rank(), and SafePointerVector< T >::size().

Here is the call graph for this function:

◆ isMasked()

bool DetectorMask::isMasked ( size_t  index) const

Definition at line 78 of file DetectorMask.cpp.

79 {
80  return m_number_of_masked_channels == 0 ? false : m_mask_data[index];
81 }

References m_mask_data, and m_number_of_masked_channels.

Referenced by MaskResultsPresenter::createMaskPresentation().

◆ numberOfMaskedChannels()

int DetectorMask::numberOfMaskedChannels ( ) const
inline

Definition at line 54 of file DetectorMask.h.

References m_number_of_masked_channels.

◆ numberOfMasks()

size_t DetectorMask::numberOfMasks ( ) const

Definition at line 92 of file DetectorMask.cpp.

93 {
94  return m_shapes.size();
95 }

References m_shapes, and SafePointerVector< T >::size().

Referenced by getMaskShape(), and TransformFromDomain::setDetectorMasks().

Here is the call graph for this function:

◆ operator=()

DetectorMask & DetectorMask::operator= ( const DetectorMask other)

Definition at line 29 of file DetectorMask.cpp.

30 {
31  if (this != &other) {
32  m_shapes = other.m_shapes;
36  // DetectorMask tmp(other);
37  // tmp.swapContent(*this);
38  }
39  return *this;
40 }

References OutputData< T >::copyFrom(), m_mask_data, m_mask_of_shape, m_number_of_masked_channels, and m_shapes.

Here is the call graph for this function:

◆ process_masks()

void DetectorMask::process_masks ( )
private

Definition at line 105 of file DetectorMask.cpp.

106 {
107  m_mask_data.setAllTo(false);
108  if (!!m_shapes.empty())
109  return;
110 
112  for (size_t index = 0; index < m_mask_data.getAllocatedSize(); ++index) {
113  Bin1D binx = m_mask_data.getAxisBin(index, 0);
114  Bin1D biny = m_mask_data.getAxisBin(index, 1);
115  // setting mask to the data starting from last shape added
116  bool is_masked(false);
117  for (size_t i_shape = m_shapes.size(); i_shape > 0; --i_shape) {
118  const IShape2D* shape = m_shapes[i_shape - 1];
119  if (shape->contains(binx, biny)) {
120  if (m_mask_of_shape[i_shape - 1])
121  is_masked = true;
122  m_mask_data[index] = m_mask_of_shape[i_shape - 1];
123  break; // index is covered by the shape, stop looking further
124  }
125  }
126  if (is_masked)
128  }
129 }
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
virtual bool contains(double x, double y) const =0
Returns true if point with given coordinates is inside or on border of the shape.
void setAllTo(const T &value)
Sets content of output data to specific value.
Definition: OutputData.h:476
Bin1D getAxisBin(size_t global_index, size_t i_selected_axis) const
Returns bin of selected axis for given global_index.
Definition: OutputData.h:452
Definition: Bin.h:20

References IShape2D::contains(), SafePointerVector< T >::empty(), OutputData< T >::getAllocatedSize(), OutputData< T >::getAxisBin(), m_mask_data, m_mask_of_shape, m_number_of_masked_channels, m_shapes, OutputData< T >::setAllTo(), and SafePointerVector< T >::size().

Referenced by initMaskData().

Here is the call graph for this function:

Member Data Documentation

◆ m_mask_data

OutputData<bool> DetectorMask::m_mask_data
private

◆ m_mask_of_shape

std::vector<bool> DetectorMask::m_mask_of_shape
private

Definition at line 64 of file DetectorMask.h.

Referenced by addMask(), getMaskShape(), initMaskData(), operator=(), and process_masks().

◆ m_number_of_masked_channels

int DetectorMask::m_number_of_masked_channels
private

Definition at line 66 of file DetectorMask.h.

Referenced by addMask(), isMasked(), numberOfMaskedChannels(), operator=(), and process_masks().

◆ m_shapes

SafePointerVector<IShape2D> DetectorMask::m_shapes
private

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