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

merge two vectors

parent 949e97ce
No related branches found
No related tags found
1 merge request!887simplify DetectorMask API
...@@ -16,6 +16,17 @@ ...@@ -16,6 +16,17 @@
#include "Base/Axis/IAxis.h" #include "Base/Axis/IAxis.h"
#include "Device/Histo/Histogram2D.h" #include "Device/Histo/Histogram2D.h"
#include "Device/Mask/IShape2D.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() DetectorMask::DetectorMask()
: m_number_of_masked_channels(0) : m_number_of_masked_channels(0)
...@@ -24,7 +35,6 @@ DetectorMask::DetectorMask() ...@@ -24,7 +35,6 @@ DetectorMask::DetectorMask()
DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis) DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis)
{ {
ASSERT(m_shapes.size() == m_mask_of_shape.size());
m_mask_data.clear(); m_mask_data.clear();
m_mask_data.addAxis(xAxis); m_mask_data.addAxis(xAxis);
...@@ -36,8 +46,7 @@ DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis) ...@@ -36,8 +46,7 @@ DetectorMask::DetectorMask(const IAxis& xAxis, const IAxis& yAxis)
DetectorMask::~DetectorMask() = default; DetectorMask::~DetectorMask() = default;
DetectorMask::DetectorMask(const DetectorMask& other) DetectorMask::DetectorMask(const DetectorMask& other)
: m_shapes(other.m_shapes) : m_stack(other.m_stack)
, m_mask_of_shape(other.m_mask_of_shape)
, m_number_of_masked_channels(other.m_number_of_masked_channels) , m_number_of_masked_channels(other.m_number_of_masked_channels)
{ {
m_mask_data.copyFrom(other.m_mask_data); m_mask_data.copyFrom(other.m_mask_data);
...@@ -46,27 +55,22 @@ DetectorMask::DetectorMask(const DetectorMask& other) ...@@ -46,27 +55,22 @@ DetectorMask::DetectorMask(const DetectorMask& other)
DetectorMask& DetectorMask::operator=(const DetectorMask& other) DetectorMask& DetectorMask::operator=(const DetectorMask& other)
{ {
if (this != &other) { if (this != &other) {
m_shapes = other.m_shapes; m_stack = other.m_stack;
m_mask_of_shape = other.m_mask_of_shape;
m_mask_data.copyFrom(other.m_mask_data); m_mask_data.copyFrom(other.m_mask_data);
m_number_of_masked_channels = other.m_number_of_masked_channels; m_number_of_masked_channels = other.m_number_of_masked_channels;
// DetectorMask tmp(other);
// tmp.swapContent(*this);
} }
return *this; return *this;
} }
void DetectorMask::addMask(const IShape2D& shape, bool mask_value) void DetectorMask::addMask(const IShape2D& shape, bool mask_value)
{ {
m_shapes.emplace_back(shape.clone()); m_stack.emplace_back(new MaskPattern(shape.clone(), mask_value));
m_mask_of_shape.push_back(mask_value);
m_mask_data.clear(); m_mask_data.clear();
m_number_of_masked_channels = 0; m_number_of_masked_channels = 0;
} }
void DetectorMask::initMaskData(const IAxis& xAxis, const IAxis& yAxis) 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.clear();
m_mask_data.addAxis(xAxis); m_mask_data.addAxis(xAxis);
...@@ -91,26 +95,26 @@ Histogram2D* DetectorMask::createHistogram() const ...@@ -91,26 +95,26 @@ Histogram2D* DetectorMask::createHistogram() const
bool DetectorMask::hasMasks() const bool DetectorMask::hasMasks() const
{ {
return !m_shapes.empty(); return !m_stack.empty();
} }
size_t DetectorMask::numberOfMasks() const 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 const IShape2D* DetectorMask::getMaskShape(size_t mask_index, bool& mask_value) const
{ {
if (mask_index >= numberOfMasks()) if (mask_index >= numberOfMasks())
return nullptr; return nullptr;
mask_value = m_mask_of_shape[mask_index]; mask_value = m_stack[mask_index]->doMask;
return m_shapes[mask_index]; return m_stack[mask_index]->shape;
} }
void DetectorMask::process_masks() void DetectorMask::process_masks()
{ {
m_mask_data.setAllTo(false); m_mask_data.setAllTo(false);
if (!!m_shapes.empty()) if (!!m_stack.empty())
return; return;
m_number_of_masked_channels = 0; m_number_of_masked_channels = 0;
...@@ -119,12 +123,12 @@ void DetectorMask::process_masks() ...@@ -119,12 +123,12 @@ void DetectorMask::process_masks()
Bin1D biny = m_mask_data.getAxisBin(index, 1); Bin1D biny = m_mask_data.getAxisBin(index, 1);
// setting mask to the data starting from last shape added // setting mask to the data starting from last shape added
bool is_masked(false); bool is_masked(false);
for (size_t i_shape = m_shapes.size(); i_shape > 0; --i_shape) { for (size_t k = m_stack.size(); k > 0; --k) {
const IShape2D* const shape = m_shapes[i_shape - 1]; const MaskPattern* const pat = m_stack[k - 1];
if (shape->contains(binx, biny)) { if (pat->shape->contains(binx, biny)) {
if (m_mask_of_shape[i_shape - 1]) if (pat->doMask)
is_masked = true; 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 break; // index is covered by the shape, stop looking further
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
class Histogram2D; class Histogram2D;
class IAxis; class IAxis;
class IShape2D; class IShape2D;
class MaskPattern;
template <class T> template <class T>
class Powerfield; class Powerfield;
...@@ -65,10 +66,12 @@ public: ...@@ -65,10 +66,12 @@ public:
private: private:
void process_masks(); void process_masks();
// primary data:
#ifndef SWIG #ifndef SWIG
OwningVector<IShape2D> m_shapes; OwningVector<MaskPattern> m_stack;
#endif #endif
std::vector<bool> m_mask_of_shape;
// cached secondary data:
Powerfield<bool> m_mask_data; Powerfield<bool> m_mask_data;
int m_number_of_masked_channels; int m_number_of_masked_channels;
}; };
......
...@@ -1884,6 +1884,16 @@ C++ includes: LLData.h ...@@ -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 // File: classOffSpecularCoordinates.xml
%feature("docstring") OffSpecularCoordinates " %feature("docstring") OffSpecularCoordinates "
......
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