13 #include <OpenMS/config.h>
32 struct RangeIntensity;
43 RangeBase(
const double single): min_(single), max_(single)
49 RangeBase(
const double min,
const double max): min_(min), max_(max)
51 if (min_ > max_)
throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Invalid initialization of range");
96 return uint8_t(min_ <= value) & uint8_t(value <= max_);
116 if (max_ < min) max_ = min;
123 if (min_ > max) min_ = max;
142 min_ = std::min(min_, other.
min_);
143 max_ = std::max(max_, other.
max_);
149 min_ = std::min(min_, value);
150 max_ = std::max(max_, value);
158 if (isEmpty())
return;
170 if (min_ == max_) extendLeftRight(min_span / 2);
181 if (isEmpty())
return;
184 min_ = std::max(min_, other.
min_);
185 max_ = std::min(max_, other.
max_);
195 if (isEmpty())
return;
200 if (getSpan() > sandbox.
getSpan())
202 max_ = min_ + sandbox.
getSpan();
204 if (min_ < sandbox.
min_)
206 shift(sandbox.
min_ - min_);
208 else if (max_ > sandbox.
max_)
210 shift(sandbox.
max_ - max_);
227 if (isEmpty())
return;
228 const double dist = max_ - min_;
229 const double extension = dist * (factor - 1) / 2;
238 if (isEmpty())
return;
247 if (isEmpty())
return nan(
"");
248 return min_ + (max_ - min_) / 2.0;
255 if (isEmpty())
return nan(
"");
261 return min_ == rhs.
min_ && max_ == rhs.
max_;
271 if (isEmpty())
return {std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max()};
278 double min_ = std::numeric_limits<double>::max();
279 double max_ = std::numeric_limits<double>::lowest();
291 using RangeBase::operator=;
352 using RangeBase::operator=;
412 using RangeBase::operator=;
471 using RangeBase::operator=;
548 template<
typename... RangeBases>
561 using T_BASE = std::decay_t<decltype(*base)>;
562 equal &= ((T_BASE&)rhs == (T_BASE&)*
this);
576 template<
typename... RangeBasesOther>
581 using T_BASE = std::decay_t<decltype(*base)>;
584 base->operator=((T_BASE&)rhs);
596 template<
typename... RangeBasesOther>
601 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
610 template<
typename... RangeBasesOther>
615 using T_BASE = std::decay_t<decltype(*base)>;
618 base->extend((T_BASE&)rhs);
629 template<
typename... RangeBasesOther>
634 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
654 for_each_base_([&](
auto* base) { base->minSpanIfSingular(min_span); });
663 template<
typename... RangeBasesOther>
668 using T_BASE = std::decay_t<decltype(*base)>;
671 const auto& rhs_base = (T_BASE&)rhs;
672 if (! rhs_base.isEmpty()) base->
pushInto(rhs_base);
684 template<
typename... RangeBasesOther>
689 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
698 template<
typename... RangeBasesOther>
703 using T_BASE = std::decay_t<decltype(*base)>;
706 const auto& rhs_base = (T_BASE&)rhs;
707 if (! rhs_base.isEmpty()) base->
clampTo(rhs_base);
719 template<
typename... RangeBasesOther>
724 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
734 using Base = std::decay_t<decltype(*base)>;
735 if (base->DIM == dim) r_base = (Base*)
this;
738 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
748 using Base = std::decay_t<decltype(*base)>;
749 if (base->DIM == dim) r_base = (Base*)
this;
752 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
759 constexpr
size_t total {
sizeof...(RangeBases)};
777 template<
typename... RangeBasesOther>
780 bool contained =
true;
781 bool has_overlap =
false;
783 using T_BASE = std::decay_t<decltype(*base)>;
787 if (((T_BASE&)rhs).isEmpty())
return;
788 if (base->contains((T_BASE&)rhs))
return;
810 if constexpr (std::is_base_of_v<RangeRT, ThisRangeType>) this->
RangeRT::clear();
813 if constexpr (std::is_base_of_v<RangeMZ, ThisRangeType>) this->
RangeMZ::clear();
827 assert(
false &&
"This should never be reached. Did you forget to implement a new DIM_UNIT?");
840 template<
typename Visitor>
843 (void(visitor(
static_cast<RangeBases*
>(
this))), ...);
846 template<
typename Visitor>
849 (void(visitor(
static_cast<const RangeBases*
>(
this))), ...);
853 template<
typename Visitor>
856 (void(visitor(
static_cast<const RangeBases*
>(
nullptr))), ...);
860 template<
typename... Range>
869 template<
typename... RangeBases>
Invalid range exception.
Definition: Exception.h:257
Definition: RangeManager.h:871
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:883
typename RangeManager< RangeBases... >::ThisRangeType ThisRangeType
Definition: RangeManager.h:873
virtual void updateRanges()=0
ThisRangeType & getRange()
get mutable range, provided for efficiency reasons (avoid updateRanges(), if only minor changes were ...
Definition: RangeManager.h:889
virtual ~RangeManagerContainer()=default
D'tor.
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:550
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:685
bool assignUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:577
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:729
bool pushIntoUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:664
bool clampToUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:699
HasRangeType hasRange() const
is any/some/all dimension in this range populated?
Definition: RangeManager.h:757
RangeBase & getRangeForDim(MSDim dim)
obtain a range dimension at runtime using dim
Definition: RangeManager.h:743
bool operator==(const RangeManager &rhs) const
Definition: RangeManager.h:557
void for_each_base_(Visitor &&visitor)
use fold expression to iterate over all RangeBases of RangeManager and apply a lambda (Visitor) for e...
Definition: RangeManager.h:841
void for_each_base_(Visitor &&visitor) const
.. and a const version
Definition: RangeManager.h:847
ThisRangeType & clear(const DIM_UNIT range)
Definition: RangeManager.h:805
void clampTo(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:720
void scaleBy(const double factor)
calls RangeBase::scale() for each dimension
Definition: RangeManager.h:639
void minSpanIfSingular(const double min_span)
If any dimension is a single point, e.g. min==max, then extend this dimension by min_span / 2 on eith...
Definition: RangeManager.h:652
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:597
bool extendUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:611
void clearRanges()
Resets all ranges.
Definition: RangeManager.h:798
void printRange(std::ostream &out) const
print each dimension (base classes) to a stream
Definition: RangeManager.h:833
void extend(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:630
bool operator!=(const RangeManager &rhs) const
Definition: RangeManager.h:567
bool containsAll(const RangeManager< RangeBasesOther... > &rhs) const
Definition: RangeManager.h:778
static void static_for_each_base_(Visitor &&visitor)
use fold expression to iterate over all RangeBases of RangeManager and apply a lambda (Visitor) for e...
Definition: RangeManager.h:854
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:63
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
DIM
Definition: DimMapper.h:601
MSDim
Dimensions of data acquisition for MS data.
Definition: RangeManager.h:23
DIM_UNIT
Definition: CommonEnums.h:20
@ IM_VSSC
volt-second per square centimeter (i.e. 1/K_0)
@ FAIMS_CV
FAIMS compensation voltage.
@ IM_MS
ion mobility milliseconds
HasRangeType
Enum listing state of dimensions (RangeBases)
Definition: RangeManager.h:527
@ ALL
all dimensions are filled
@ SOME
some dimensions are empty, some are filled
@ NONE
all dimensions are empty (=cleared)
Base class for a simple range with minimum and maximum.
Definition: RangeManager.h:37
double max_
Definition: RangeManager.h:279
double getSpan() const
Definition: RangeManager.h:253
RangeBase(const double single)
Cutom C'tor which sets the range to a singular point.
Definition: RangeManager.h:43
RangeBase(const RangeBase &rhs)=default
Copy C'tor.
void setMin(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:113
RangeBase & operator=(RangeBase &&rhs) noexcept=default
Move assignment (seems useless, but is required for completeness in derived classes' move c'tor)
std::pair< double, double > getNonEmptyRange() const
Return the current range, or (if empty) a full range (-1e308, 1e308).
Definition: RangeManager.h:268
void scaleBy(const double factor)
Scale the range of the dimension by a factor. A factor > 1 increases the range; factor < 1 decreases ...
Definition: RangeManager.h:225
RangeBase & operator=(const RangeBase &rhs)=default
Assignment operator.
void minSpanIfSingular(const double min_span)
If the current range is a single point, e.g. min==max, then extend the range by min_span / 2 on eithe...
Definition: RangeManager.h:168
void pushInto(const RangeBase &sandbox)
Definition: RangeManager.h:193
void shift(const double distance)
Definition: RangeManager.h:236
~RangeBase() noexcept=default
D'tor.
bool contains(const double value) const
is value within [min, max]?
Definition: RangeManager.h:94
double center() const
Definition: RangeManager.h:245
RangeBase()=default
C'tor: initialize with empty range.
void extend(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:147
void extendLeftRight(const double by)
Definition: RangeManager.h:156
RangeBase(RangeBase &&rhs) noexcept=default
Move C'tor (seems useless, but is required for completeness in derived classes' move c'tor)
bool contains(const RangeBase &inner_range) const
is the range inner_range within [min, max]?
Definition: RangeManager.h:100
void clampTo(const RangeBase &other)
Definition: RangeManager.h:179
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:127
void clear()
make the range empty, i.e. isEmpty() will be true
Definition: RangeManager.h:82
void setMax(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:120
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:88
double min_
Definition: RangeManager.h:278
RangeBase(const double min, const double max)
Definition: RangeManager.h:49
bool operator==(const RangeBase &rhs) const
Definition: RangeManager.h:259
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:133
void extend(const RangeBase &other)
ensure the range includes the range of other
Definition: RangeManager.h:140
Definition: RangeManager.h:406
void setMinIntensity(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:421
double getMinIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:433
void extendIntensity(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:446
bool containsIntensity(const double value) const
is value within [min, max]?
Definition: RangeManager.h:452
double getMaxIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:439
bool containsIntensity(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:458
void setMaxIntensity(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:427
Definition: RangeManager.h:346
bool containsMZ(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:398
void setMaxMZ(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:367
void extendMZ(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:386
void setMinMZ(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:361
double getMaxMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:379
double getMinMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:373
bool containsMZ(const double value) const
is value within [min, max]?
Definition: RangeManager.h:392
Definition: RangeManager.h:466
bool containsMobility(const double value) const
is value within [min, max]?
Definition: RangeManager.h:511
void extendMobility(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:505
double getMinMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:492
bool containsMobility(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:517
double getMaxMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:498
void setMinMobility(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:480
void setMaxMobility(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:486
Definition: RangeManager.h:285
bool containsRT(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:337
void extendRT(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:325
double getMaxRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:318
void setMaxRT(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:306
void setMinRT(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:300
double getMinRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:312
bool containsRT(const double value) const
is value within [min, max]?
Definition: RangeManager.h:331