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/Histo/Histogram2D.h"
#include "Device/Data/Powerfield.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()
: m_masked(new Powerfield<bool>)
, m_number_of_masked_channels(0)
DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis)
m_masked->addAxis(xAxis);
m_masked->addAxis(yAxis);
// m_masked.reset(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)
m_masked->addAxis(xAxis);
m_masked->addAxis(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 IShape2D* DetectorMask::getMaskShape(size_t mask_index, bool& mask_value) const
{
return nullptr;
mask_value = m_stack[mask_index]->doMask;
return m_stack[mask_index]->shape;
void DetectorMask::process_masks()
{
m_masked->setAllTo(false);
m_number_of_masked_channels = 0;
for (size_t index = 0; index < m_masked->getAllocatedSize(); ++index) {
Bin1D binx = m_masked->getAxisBin(index, 0);
Bin1D biny = m_masked->getAxisBin(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;