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

Public Member Functions

 DetectorMask ()
 
 DetectorMask (const DetectorMask &other)
 
DetectorMaskoperator= (const DetectorMask &other)
 
void addMask (const IShape2D &shape, bool mask_value)
 
void initMaskData (const IDetector2D &detector)
 
void initMaskData (const OutputData< double > &data)
 
bool isMasked (size_t index) const
 
const OutputData< bool > * getMaskData () const
 
Histogram2DcreateHistogram () const
 
void removeMasks ()
 
bool hasMasks () const
 
int numberOfMaskedChannels () const
 
size_t numberOfMasks () const
 
const IShape2DgetMaskShape (size_t mask_index, bool &mask_value) const
 

Private Member Functions

void process_masks ()
 

Private Attributes

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

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:70

◆ DetectorMask() [2/2]

DetectorMask::DetectorMask ( const DetectorMask other)

Definition at line 21 of file DetectorMask.cpp.

24 {
26 }
SafePointerVector< IShape2D > m_shapes
Definition: DetectorMask.h:67
std::vector< bool > m_mask_of_shape
Definition: DetectorMask.h:68
OutputData< bool > m_mask_data
Definition: DetectorMask.h:69
void copyFrom(const OutputData< T > &x)
Definition: OutputData.h:261

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

Here is the call graph for this function:

Member Function Documentation

◆ operator=()

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

Definition at line 28 of file DetectorMask.cpp.

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

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:

◆ 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 41 of file DetectorMask.cpp.

42 {
43  m_shapes.push_back(shape.clone());
44  m_mask_of_shape.push_back(mask_value);
47 }
virtual IShape2D * clone() const =0
void clear()
Sets object into initial state (no dimensions, data)
Definition: OutputData.h:473
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().

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 49 of file DetectorMask.cpp.

50 {
51  if (detector.dimension() != 2)
52  throw Exceptions::RuntimeErrorException("DetectorMask::initMaskData() -> Error. Attempt "
53  "to add masks to uninitialized detector.");
54 
55  ASSERT(m_shapes.size() == m_mask_of_shape.size());
57 
58  for (size_t dim = 0; dim < detector.dimension(); ++dim) {
59  const IAxis& axis = detector.getAxis(dim);
60  m_mask_data.addAxis(axis);
61  }
62 
63  process_masks();
64 }
#define ASSERT(condition)
Definition: Assert.h:26
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:44
const IAxis & getAxis(size_t index) const
Definition: IDetector.cpp:54
void addAxis(const IAxis &new_axis)
Definition: OutputData.h:289
size_t size() const

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

Referenced by IDetector2D::addMask(), 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 66 of file DetectorMask.cpp.

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

Here is the call graph for this function:

◆ isMasked()

bool DetectorMask::isMasked ( size_t  index) const

Definition at line 77 of file DetectorMask.cpp.

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

References m_mask_data, and m_number_of_masked_channels.

◆ getMaskData()

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

Definition at line 48 of file DetectorMask.h.

48 { return &m_mask_data; }

References m_mask_data.

◆ createHistogram()

Histogram2D * DetectorMask::createHistogram ( ) const

Definition at line 82 of file DetectorMask.cpp.

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

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

Here is the call graph for this function:

◆ removeMasks()

void DetectorMask::removeMasks ( )

remove all masks and return object to initial state

Definition at line 91 of file DetectorMask.cpp.

92 {
93  m_shapes.clear();
94  m_mask_of_shape.clear();
96 }

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

Referenced by IDetector2D::maskAll(), and IDetector2D::removeMasks().

Here is the call graph for this function:

◆ hasMasks()

bool DetectorMask::hasMasks ( ) const
inline

returns true if has masks

Definition at line 56 of file DetectorMask.h.

56 { return !m_shapes.empty(); }

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

Here is the call graph for this function:

◆ numberOfMaskedChannels()

int DetectorMask::numberOfMaskedChannels ( ) const
inline

Definition at line 58 of file DetectorMask.h.

References m_number_of_masked_channels.

◆ numberOfMasks()

size_t DetectorMask::numberOfMasks ( ) const

Definition at line 98 of file DetectorMask.cpp.

99 {
100  return m_shapes.size();
101 }

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

Referenced by SimulationToPython::defineMasks(), and getMaskShape().

Here is the call graph for this function:

◆ getMaskShape()

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

Definition at line 103 of file DetectorMask.cpp.

104 {
105  if (mask_index >= numberOfMasks())
106  return nullptr;
107  mask_value = m_mask_of_shape[mask_index];
108  return m_shapes[mask_index];
109 }
size_t numberOfMasks() const

References m_mask_of_shape, m_shapes, and numberOfMasks().

Referenced by SimulationToPython::defineMasks().

Here is the call graph for this function:

◆ process_masks()

void DetectorMask::process_masks ( )
private

Definition at line 111 of file DetectorMask.cpp.

112 {
113  m_mask_data.setAllTo(false);
114  if (!!m_shapes.empty())
115  return;
116 
118  for (size_t index = 0; index < m_mask_data.getAllocatedSize(); ++index) {
119  Bin1D binx = m_mask_data.getAxisBin(index, 0);
120  Bin1D biny = m_mask_data.getAxisBin(index, 1);
121  // setting mask to the data starting from last shape added
122  bool is_masked(false);
123  for (size_t i_shape = m_shapes.size(); i_shape > 0; --i_shape) {
124  const IShape2D* shape = m_shapes[i_shape - 1];
125  if (shape->contains(binx, biny)) {
126  if (m_mask_of_shape[i_shape - 1])
127  is_masked = true;
128  m_mask_data[index] = m_mask_of_shape[i_shape - 1];
129  break; // index is covered by the shape, stop looking further
130  }
131  }
132  if (is_masked)
134  }
135 }
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:479
Bin1D getAxisBin(size_t global_index, size_t i_selected_axis) const
Returns bin of selected axis for given global_index.
Definition: OutputData.h:455
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_shapes

SafePointerVector<IShape2D> DetectorMask::m_shapes
private

◆ m_mask_of_shape

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

◆ m_mask_data

OutputData<bool> DetectorMask::m_mask_data
private

◆ m_number_of_masked_channels

int DetectorMask::m_number_of_masked_channels
private

Definition at line 70 of file DetectorMask.h.

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


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