From f9ff2b717df98e8e0672d3e063d261ec59b2d1d6 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 18 May 2022 17:39:13 +0200 Subject: [PATCH] merge two vectors --- Device/Mask/DetectorMask.cpp | 44 ++++++++++++++++++++---------------- Device/Mask/DetectorMask.h | 7 ++++-- auto/Wrap/doxygenDevice.i | 10 ++++++++ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Device/Mask/DetectorMask.cpp b/Device/Mask/DetectorMask.cpp index de536bcfdd2..f4a83fd8a14 100644 --- a/Device/Mask/DetectorMask.cpp +++ b/Device/Mask/DetectorMask.cpp @@ -16,6 +16,17 @@ #include "Base/Axis/IAxis.h" #include "Device/Histo/Histogram2D.h" #include "Device/Mask/IShape2D.h" +#include "Base/Types/ICloneable.h" + +class MaskPattern : public ICloneable { +public: + MaskPattern(IShape2D* shape_, bool doMask_) : shape(shape_), doMask(doMask_) {} + ~MaskPattern() { delete shape; } + MaskPattern* clone() const { return new MaskPattern(shape->clone(), doMask); } + IShape2D* shape; // owning + bool doMask; +}; + DetectorMask::DetectorMask() : m_number_of_masked_channels(0) @@ -24,7 +35,6 @@ DetectorMask::DetectorMask() DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis) { - ASSERT(m_shapes.size() == m_mask_of_shape.size()); m_mask_data.clear(); m_mask_data.addAxis(xAxis); @@ -36,8 +46,7 @@ DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis) DetectorMask::~DetectorMask() = default; DetectorMask::DetectorMask(const DetectorMask& other) - : m_shapes(other.m_shapes) - , m_mask_of_shape(other.m_mask_of_shape) + : m_stack(other.m_stack) , m_number_of_masked_channels(other.m_number_of_masked_channels) { m_mask_data.copyFrom(other.m_mask_data); @@ -46,27 +55,22 @@ DetectorMask::DetectorMask(const DetectorMask& other) DetectorMask& DetectorMask::operator=(const DetectorMask& other) { if (this != &other) { - m_shapes = other.m_shapes; - m_mask_of_shape = other.m_mask_of_shape; + m_stack = other.m_stack; m_mask_data.copyFrom(other.m_mask_data); m_number_of_masked_channels = other.m_number_of_masked_channels; - // DetectorMask tmp(other); - // tmp.swapContent(*this); } return *this; } void DetectorMask::addMask(const IShape2D& shape, bool mask_value) { - m_shapes.emplace_back(shape.clone()); - m_mask_of_shape.push_back(mask_value); + m_stack.emplace_back(new MaskPattern(shape.clone(), mask_value)); m_mask_data.clear(); m_number_of_masked_channels = 0; } void DetectorMask::initMaskData(const IAxis& xAxis, const IAxis& yAxis) { - ASSERT(m_shapes.size() == m_mask_of_shape.size()); m_mask_data.clear(); m_mask_data.addAxis(xAxis); @@ -91,26 +95,26 @@ Histogram2D* DetectorMask::createHistogram() const bool DetectorMask::hasMasks() const { - return !m_shapes.empty(); + return !m_stack.empty(); } size_t DetectorMask::numberOfMasks() const { - return m_shapes.size(); + return m_stack.size(); } const IShape2D* DetectorMask::getMaskShape(size_t mask_index, bool& mask_value) const { if (mask_index >= numberOfMasks()) return nullptr; - mask_value = m_mask_of_shape[mask_index]; - return m_shapes[mask_index]; + mask_value = m_stack[mask_index]->doMask; + return m_stack[mask_index]->shape; } void DetectorMask::process_masks() { m_mask_data.setAllTo(false); - if (!!m_shapes.empty()) + if (!!m_stack.empty()) return; m_number_of_masked_channels = 0; @@ -119,12 +123,12 @@ void DetectorMask::process_masks() Bin1D biny = m_mask_data.getAxisBin(index, 1); // setting mask to the data starting from last shape added bool is_masked(false); - for (size_t i_shape = m_shapes.size(); i_shape > 0; --i_shape) { - const IShape2D* const shape = m_shapes[i_shape - 1]; - if (shape->contains(binx, biny)) { - if (m_mask_of_shape[i_shape - 1]) + 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_mask_data[index] = m_mask_of_shape[i_shape - 1]; + m_mask_data[index] = pat->doMask; break; // index is covered by the shape, stop looking further } } diff --git a/Device/Mask/DetectorMask.h b/Device/Mask/DetectorMask.h index ea63d292a47..646abf08775 100644 --- a/Device/Mask/DetectorMask.h +++ b/Device/Mask/DetectorMask.h @@ -23,6 +23,7 @@ class Histogram2D; class IAxis; class IShape2D; +class MaskPattern; template <class T> class Powerfield; @@ -65,10 +66,12 @@ public: private: void process_masks(); + // primary data: #ifndef SWIG - OwningVector<IShape2D> m_shapes; + OwningVector<MaskPattern> m_stack; #endif - std::vector<bool> m_mask_of_shape; + + // cached secondary data: Powerfield<bool> m_mask_data; int m_number_of_masked_channels; }; diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index 1eb9c324bc3..25a265c20ac 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -1884,6 +1884,16 @@ C++ includes: LLData.h "; +// File: classMaskPattern.xml +%feature("docstring") MaskPattern ""; + +%feature("docstring") MaskPattern::~MaskPattern "MaskPattern::~MaskPattern() +"; + +%feature("docstring") MaskPattern::clone "MaskPattern* MaskPattern::clone() const +"; + + // File: classOffSpecularCoordinates.xml %feature("docstring") OffSpecularCoordinates " -- GitLab