Newer
Older
// ************************************************************************************************
// BornAgain: simulate and fit reflection and scattering
//! @file Device/Mask/MaskStack.cpp
//! @brief Implements class MaskStack.
//!
//! @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)
// ************************************************************************************************
struct MaskPattern {
MaskPattern(IShape2D* shape_, bool doMask_, bool in_bins_);
MaskPattern(const MaskPattern&) = delete;
~MaskPattern();
MaskPattern* clone() const;
IShape2D* shape; // cloneable
bool doMask;
bool inBins;
};

Wuttke, Joachim
committed
MaskPattern::MaskPattern(IShape2D* shape_, bool doMask_, bool in_bins_)

Wuttke, Joachim
committed
, inBins(in_bins_)

Wuttke, Joachim
committed

Wuttke, Joachim
committed

Wuttke, Joachim
committed
return new MaskPattern(shape->clone(), doMask, inBins);

Wuttke, Joachim
committed
MaskStack::MaskStack() = default;
MaskStack::MaskStack(const MaskStack&) = default;
MaskStack::~MaskStack() = default;
void MaskStack::pushMask(const IShape2D& shape, bool mask_value, bool in_bins)
m_stack.push_back(new MaskPattern(shape.clone(), mask_value, in_bins));
bool MaskStack::isMasked(size_t i_flat, const Frame& frame) const

Wuttke, Joachim
committed
size_t ix = i_flat % nx;
size_t iy = i_flat / nx;
for (int k = m_stack.size() - 1; k >= 0; --k) {
const MaskPattern* const pat = m_stack[k];

Wuttke, Joachim
committed
Bin1D binx = pat->inBins ? Bin1D::FromTo(ix - 0.5, ix + 0.5) : frame.xAxis().bin(ix);
Bin1D biny = pat->inBins ? Bin1D::FromTo(iy - 0.5, iy + 0.5) : frame.yAxis().bin(iy);
if (pat->shape->contains(binx, biny))
return pat->doMask;
}
return false;
size_t MaskStack::numberOfMasks() const
std::pair<IShape2D*, bool> MaskStack::patternAt(size_t iMask) const