BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DetectorMask Class Reference

Description

Collection of detector masks.

Definition at line 42 of file DetectorMask.h.

Collaboration diagram for DetectorMask:
[legend]

Public Member Functions

 DetectorMask (const DetectorMask &other)
 
 DetectorMask (const IAxis &xAxis, const IAxis &yAxis)
 
 ~DetectorMask ()
 
void 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. More...
 
bool hasMasks () const
 Returns true if has masks. More...
 
bool isMasked (size_t index) const
 
int numberOfMaskedChannels () const
 
size_t numberOfMasks () const
 
DetectorMaskoperator= (const DetectorMask &other)
 
const MaskPatternpatternAt (size_t iMask) const
 

Private Member Functions

void process_masks ()
 

Private Attributes

std::vector< bool > m_masked
 
int m_number_of_masked_channels
 
OwningVector< MaskPatternm_stack
 
const IAxism_xAxis
 
const IAxism_yAxis
 

Constructor & Destructor Documentation

◆ DetectorMask() [1/2]

DetectorMask::DetectorMask ( const IAxis xAxis,
const IAxis yAxis 
)

Definition at line 35 of file DetectorMask.cpp.

36  : m_xAxis(xAxis.clone())
37  , m_yAxis(yAxis.clone())
38  , m_masked(xAxis.size() * yAxis.size(), false)
39 {
40 }
const IAxis * m_yAxis
Definition: DetectorMask.h:72
const IAxis * m_xAxis
Definition: DetectorMask.h:71
std::vector< bool > m_masked
Definition: DetectorMask.h:77
virtual IAxis * clone() const =0
virtual size_t size() const =0
Returns the number of bins.

◆ ~DetectorMask()

DetectorMask::~DetectorMask ( )
default

◆ DetectorMask() [2/2]

DetectorMask::DetectorMask ( const DetectorMask other)

Definition at line 44 of file DetectorMask.cpp.

45  : m_xAxis(other.m_xAxis->clone())
46  , m_yAxis(other.m_yAxis->clone())
47  , m_stack(other.m_stack)
48  , m_masked(other.m_masked)
50 {
51 }
int m_number_of_masked_channels
Definition: DetectorMask.h:78
OwningVector< MaskPattern > m_stack
Definition: DetectorMask.h:73

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

64 {
65  m_stack.emplace_back(new MaskPattern(shape.clone(), mask_value));
66  process_masks();
67 }
void process_masks()
IShape2D * clone() const override=0
void emplace_back(T *e)
Definition: OwningVector.h:62

References IShape2D::clone(), OwningVector< T >::emplace_back(), m_stack, and process_masks().

Here is the call graph for this function:

◆ hasMasks()

bool DetectorMask::hasMasks ( ) const

Returns true if has masks.

Definition at line 74 of file DetectorMask.cpp.

75 {
76  return !m_stack.empty();
77 }
bool empty() const
Definition: OwningVector.h:71

References OwningVector< T >::empty(), and m_stack.

Here is the call graph for this function:

◆ isMasked()

bool DetectorMask::isMasked ( size_t  index) const

Definition at line 69 of file DetectorMask.cpp.

70 {
71  return m_number_of_masked_channels == 0 ? false : m_masked[i_flat];
72 }

References m_masked, and m_number_of_masked_channels.

◆ numberOfMaskedChannels()

int DetectorMask::numberOfMaskedChannels ( ) const
inline

Definition at line 60 of file DetectorMask.h.

References m_number_of_masked_channels.

◆ numberOfMasks()

size_t DetectorMask::numberOfMasks ( ) const

Definition at line 79 of file DetectorMask.cpp.

80 {
81  return m_stack.size();
82 }
size_t size() const
Definition: OwningVector.h:70

References m_stack, and OwningVector< T >::size().

Here is the call graph for this function:

◆ operator=()

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

Definition at line 53 of file DetectorMask.cpp.

54 {
55  if (this != &other) {
56  m_stack = other.m_stack;
57  m_masked = other.m_masked;
59  }
60  return *this;
61 }

References m_masked, m_number_of_masked_channels, and m_stack.

◆ patternAt()

const MaskPattern * DetectorMask::patternAt ( size_t  iMask) const

Definition at line 84 of file DetectorMask.cpp.

85 {
86  return m_stack.at(iMask);
87 }
T *const & at(int i) const
Definition: OwningVector.h:73

References OwningVector< T >::at(), and m_stack.

Here is the call graph for this function:

◆ process_masks()

void DetectorMask::process_masks ( )
private

Definition at line 89 of file DetectorMask.cpp.

90 {
92  m_masked.clear();
93  m_masked.resize(m_xAxis->size() * m_yAxis->size(), false);
94 
95  if (m_stack.empty())
96  return;
97 
99  for (size_t i_flat = 0; i_flat < m_masked.size(); ++i_flat) {
100  Bin1D binx = m_xAxis->bin((i_flat / m_yAxis->size()) % m_xAxis->size());
101  Bin1D biny = m_yAxis->bin(i_flat % m_yAxis->size());
102  // setting mask to the data starting from last shape added
103  bool is_masked(false);
104  for (int k = m_stack.size() - 1; k >= 0; --k) {
105  const MaskPattern* const pat = m_stack[k];
106  if (pat->shape->contains(binx, biny)) {
107  if (pat->doMask)
108  is_masked = true;
109  m_masked[i_flat] = pat->doMask;
110  break; // i_flat is covered by the shape, stop looking further
111  }
112  }
113  if (is_masked)
115  }
116 }
Definition: Bin.h:20
virtual Bin1D bin(size_t index) const =0
retrieve a 1d bin for the given index
virtual bool contains(double x, double y) const =0
Returns true if point with given coordinates is inside or on border of the shape.
IShape2D * shape
Definition: DetectorMask.h:35

References IAxis::bin(), IShape2D::contains(), MaskPattern::doMask, OwningVector< T >::empty(), m_masked, m_number_of_masked_channels, m_stack, m_xAxis, m_yAxis, MaskPattern::shape, OwningVector< T >::size(), and IAxis::size().

Referenced by addMask().

Here is the call graph for this function:

Member Data Documentation

◆ m_masked

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

Definition at line 77 of file DetectorMask.h.

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

◆ m_number_of_masked_channels

int DetectorMask::m_number_of_masked_channels
private

Definition at line 78 of file DetectorMask.h.

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

◆ m_stack

OwningVector<MaskPattern> DetectorMask::m_stack
private

Definition at line 73 of file DetectorMask.h.

Referenced by addMask(), hasMasks(), numberOfMasks(), operator=(), patternAt(), and process_masks().

◆ m_xAxis

const IAxis* DetectorMask::m_xAxis
private

Definition at line 71 of file DetectorMask.h.

Referenced by process_masks().

◆ m_yAxis

const IAxis* DetectorMask::m_yAxis
private

Definition at line 72 of file DetectorMask.h.

Referenced by process_masks().


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