Skip to content
Snippets Groups Projects
Commit 6ad44661 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

spell out computation of bin indices for rank<=2; let DetectorMask directly own IAxis*

parent a4356455
No related branches found
No related tags found
1 merge request!928Simplify Frame API; simplify DetectorMask API and internals; no longer use Powerfield<bool>
......@@ -49,6 +49,17 @@ std::vector<int> Frame::allIndices(size_t i_flat) const
size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const
{
if (rank()==1) {
return i_flat;
} else if (rank()==2) {
if (k_axis==0)
return (i_flat / m_axes[1]->size()) % m_axes[0]->size();
if (k_axis==1)
return i_flat % m_axes[1]->size();
ASSERT(0);
}
ASSERT(0);
/* // generic code for rank>2 currently unused
size_t remainder(i_flat);
for (int k = rank() - 1; k >= 0; --k) {
size_t result = remainder % m_axes[k]->size();
......@@ -56,7 +67,7 @@ size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const
return result;
remainder /= m_axes[k]->size();
}
ASSERT(0);
*/
}
size_t Frame::toGlobalIndex(const std::vector<unsigned>& axes_indices) const
......
......@@ -34,7 +34,9 @@ MaskPattern* MaskPattern::clone() const
}
DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis)
: m_masked(new Powerfield<bool>(xAxis, yAxis))
: m_xAxis(xAxis.clone())
, m_yAxis(yAxis.clone())
, m_masked(new Powerfield<bool>(xAxis, yAxis))
{
process_masks();
}
......@@ -42,7 +44,9 @@ DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis)
DetectorMask::~DetectorMask() = default;
DetectorMask::DetectorMask(const DetectorMask& other)
: m_stack(other.m_stack)
: m_xAxis(other.m_xAxis->clone())
, m_yAxis(other.m_yAxis->clone())
, m_stack(other.m_stack)
, m_masked(other.m_masked->clone())
, m_number_of_masked_channels(other.m_number_of_masked_channels)
{
......@@ -100,9 +104,9 @@ void DetectorMask::process_masks()
return;
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);
for (size_t i_flat = 0; i_flat < m_masked->allocatedSize(); ++i_flat) {
Bin1D binx = m_xAxis->bin((i_flat / m_yAxis->size()) % m_yAxis->size());
Bin1D biny = m_yAxis->bin(i_flat % m_yAxis->size());
// setting mask to the data starting from last shape added
bool is_masked(false);
for (size_t k = m_stack.size(); k > 0; --k) {
......@@ -110,8 +114,8 @@ void DetectorMask::process_masks()
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_masked)[i_flat] = pat->doMask;
break; // i_flat is covered by the shape, stop looking further
}
}
if (is_masked)
......
......@@ -76,6 +76,8 @@ private:
// primary data:
#ifndef SWIG
OwningVector<MaskPattern> m_stack;
const IAxis* m_xAxis;
const IAxis* m_yAxis;
#endif
// cached secondary data:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment