20 #ifndef MIRTK_DataSelection_H 21 #define MIRTK_DataSelection_H 23 #include "mirtk/Object.h" 25 #include "mirtk/UnorderedSet.h" 26 #include "mirtk/Algorithm.h" 29 namespace mirtk {
namespace data {
32 typedef UnorderedSet<int> Selection;
50 virtual Selection
Evaluate(
const Array<double> &values)
const = 0;
59 typedef SharedPtr<const Selector> SelectorPointer;
60 typedef List<SelectorPointer> SelectorList;
65 mirtkAttributeMacro(SelectorList, Criteria);
72 return static_cast<int>(_Criteria.size());
78 auto it = _Criteria.begin();
79 for (
int pos = 0; pos < i; ++pos) ++it;
84 void Push(
const SelectorPointer &criterium)
86 _Criteria.push_back(criterium);
99 virtual Selection
Evaluate(
const Array<double> &values)
const 101 if (_Criteria.empty())
return Selection();
102 auto criterium = _Criteria.begin();
103 auto selection = (*criterium)->Evaluate(values);
104 while (++criterium != _Criteria.end()) {
105 selection =
Intersection(selection, (*criterium)->Evaluate(values));
120 virtual Selection
Evaluate(
const Array<double> &values)
const 123 for (
auto criterium : _Criteria) {
124 auto ids = criterium->Evaluate(values);
125 for (
auto id : ids) {
126 selection.insert(
id);
142 virtual Selection
Evaluate(
const Array<double> &values)
const 145 selection.reserve(values.size());
146 const int n =
static_cast<int>(values.size());
147 for (
int id = 0;
id < n; ++id) {
148 if (this->Select(values[
id])) {
149 selection.insert(
id);
156 virtual bool Select(
double)
const = 0;
170 mirtkObjectMacro(
Equal);
173 mirtkPublicAttributeMacro(
double, Value);
178 Equal(
double value) : _Value(value) {}
183 return fequal(value, _Value);
194 mirtkPublicAttributeMacro(
double, Value);
204 return !
fequal(value, _Value);
215 mirtkPublicAttributeMacro(
double, Threshold);
220 LessThan(
double threshold) : _Threshold(threshold) {}
225 return value < _Threshold;
236 mirtkPublicAttributeMacro(
double, Threshold);
246 return value <= _Threshold;
257 mirtkPublicAttributeMacro(
double, Threshold);
267 return value > _Threshold;
278 mirtkPublicAttributeMacro(
double, Threshold);
288 return value >= _Threshold;
295 #endif // MIRTK_DataSelection_H virtual ~Selector()
Destructor.
Select data points with a value equal the specified value.
GreaterOrEqual(double threshold)
Constructor.
Select data points with a value greater than the specified threshold.
int NumberOfCriteria() const
Number of data selection criteria.
virtual bool Select(double value) const
Evaluate criterium for given data value.
UnorderedSet< T > Intersection(const UnorderedSet< T > &a, const UnorderedSet< T > &b)
Select data points with a value less than the specified threshold.
GreaterThan(double threshold)
Constructor.
virtual bool Select(double value) const
Evaluate criterium for given data value.
Base class of data selection criteria.
SelectorPointer Criterium(int i) const
Get n-th data selection criterium.
MIRTKCU_API bool fequal(double a, double b, double tol=1e-12)
virtual bool Select(double value) const
Evaluate criterium for given data value.
virtual Selection Evaluate(const Array< double > &values) const
Run selection query and return IDs of selected data points.
Select data points a value different from the specified value.
Equal(double value)
Constructor.
virtual Selection Evaluate(const Array< double > &values) const
Run selection query and return IDs of selected data points.
virtual Selection Evaluate(const Array< double > &values) const
Run selection query and return IDs of selected data points.
Combine one or more data selection criteria using a logical AND.
virtual bool Select(double value) const
Evaluate criterium for given data value.
virtual bool Select(double value) const
Evaluate criterium for given data value.
virtual Selection Evaluate(const Array< double > &values) const =0
Combine one or more data selection criteria using a logical operator.
LessOrEqual(double threshold)
Constructor.
Select data points with a value less than or equal the specified threshold.
Select data points with a value greater than or equal the specified threshold.
Base class of data selectors.
NotEqual(double value)
Constructor.
virtual bool Select(double value) const
Evaluate criterium for given data value.
void Push(const SelectorPointer &criterium)
Add data selection criterium.
LessThan(double threshold)
Constructor.
Combine one or more data selection criteria using a logical OR.