Newer
Older
// ************************************************************************************************
// BornAgain: simulate and fit reflection and scattering
//! @brief Implements class DetectorMask.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
// ************************************************************************************************
#include "Base/Axis/IAxis.h"
#include "Device/Data/Powerfield.h"
#include "Device/Histo/Histogram2D.h"
MaskPattern::MaskPattern(IShape2D* shape_, bool doMask_)
: shape(shape_)
, doMask(doMask_)
{
}
MaskPattern::~MaskPattern()
{
delete shape;
}
MaskPattern* MaskPattern::clone() const
{
return new MaskPattern(shape->clone(), doMask);
}
DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis)
: m_masked(new Powerfield<bool>(xAxis, yAxis))
DetectorMask::~DetectorMask() = default;
DetectorMask::DetectorMask(const DetectorMask& other)
, m_masked(other.m_masked->clone())
, m_number_of_masked_channels(other.m_number_of_masked_channels)
{
m_masked->copyFrom(*other.m_masked);
DetectorMask& DetectorMask::operator=(const DetectorMask& other)
{
m_masked.reset(other.m_masked->clone());
m_number_of_masked_channels = other.m_number_of_masked_channels;
void DetectorMask::addMask(const IShape2D& shape, bool mask_value)
{
m_stack.emplace_back(new MaskPattern(shape.clone(), mask_value));
m_number_of_masked_channels = 0;
void DetectorMask::initMaskData(const IAxis& xAxis, const IAxis& yAxis)
bool DetectorMask::isMasked(size_t index) const
{
return m_number_of_masked_channels == 0 ? false : (*m_masked)[index];
size_t DetectorMask::numberOfMasks() const
{
const MaskPattern* DetectorMask::patternAt(size_t iMask) const
{
return m_stack.at(iMask);
}
void DetectorMask::process_masks()
{
m_masked->setAllTo(false);
m_number_of_masked_channels = 0;
for (size_t index = 0; index < m_masked->allocatedSize(); ++index) {
Bin1D binx = m_masked->projectedBin(index, 0);
Bin1D biny = m_masked->projectedBin(index, 1);
// setting mask to the data starting from last shape added
bool is_masked(false);
for (size_t k = m_stack.size(); k > 0; --k) {
const MaskPattern* const pat = m_stack[k - 1];
if (pat->shape->contains(binx, biny)) {
if (pat->doMask)
is_masked = true;
(*m_masked)[index] = pat->doMask;
break; // index is covered by the shape, stop looking further
++m_number_of_masked_channels;