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;
132 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Empty or uninitalized range object. Did you forget to call updateRanges()?");
143 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Empty or uninitialized range object. Did you forget to call updateRanges()?");
152 min_ = std::min(min_, other.
min_);
153 max_ = std::max(max_, other.
max_);
159 min_ = std::min(min_, value);
160 max_ = std::max(max_, value);
168 if (isEmpty())
return;
180 if (min_ == max_) extendLeftRight(min_span / 2);
191 if (isEmpty())
return;
194 min_ = std::max(min_, other.
min_);
195 max_ = std::min(max_, other.
max_);
205 if (isEmpty())
return;
210 if (getSpan() > sandbox.
getSpan())
212 max_ = min_ + sandbox.
getSpan();
214 if (min_ < sandbox.
min_)
216 shift(sandbox.
min_ - min_);
218 else if (max_ > sandbox.
max_)
220 shift(sandbox.
max_ - max_);
237 if (isEmpty())
return;
238 const double dist = max_ - min_;
239 const double extension = dist * (factor - 1) / 2;
248 if (isEmpty())
return;
257 if (isEmpty())
return nan(
"");
258 return min_ + (max_ - min_) / 2.0;
265 if (isEmpty())
return nan(
"");
271 return min_ == rhs.
min_ && max_ == rhs.
max_;
281 if (isEmpty())
return {std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max()};
288 double min_ = std::numeric_limits<double>::max();
289 double max_ = std::numeric_limits<double>::lowest();
301 using RangeBase::operator=;
364 using RangeBase::operator=;
426 using RangeBase::operator=;
487 using RangeBase::operator=;
566 template<
typename... RangeBases>
579 using T_BASE = std::decay_t<decltype(*base)>;
580 equal &= ((T_BASE&)rhs == (T_BASE&)*
this);
594 template<
typename... RangeBasesOther>
599 using T_BASE = std::decay_t<decltype(*base)>;
602 base->operator=((T_BASE&)rhs);
614 template<
typename... RangeBasesOther>
619 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
628 template<
typename... RangeBasesOther>
633 using T_BASE = std::decay_t<decltype(*base)>;
636 base->extend((T_BASE&)rhs);
647 template<
typename... RangeBasesOther>
652 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
672 for_each_base_([&](
auto* base) { base->minSpanIfSingular(min_span); });
681 template<
typename... RangeBasesOther>
686 using T_BASE = std::decay_t<decltype(*base)>;
689 const auto& rhs_base = (T_BASE&)rhs;
690 if (! rhs_base.isEmpty()) base->
pushInto(rhs_base);
702 template<
typename... RangeBasesOther>
707 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
716 template<
typename... RangeBasesOther>
721 using T_BASE = std::decay_t<decltype(*base)>;
724 const auto& rhs_base = (T_BASE&)rhs;
725 if (! rhs_base.isEmpty()) base->
clampTo(rhs_base);
737 template<
typename... RangeBasesOther>
742 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
752 using Base = std::decay_t<decltype(*base)>;
753 if (base->DIM == dim) r_base = (Base*)
this;
756 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
766 using Base = std::decay_t<decltype(*base)>;
767 if (base->DIM == dim) r_base = (Base*)
this;
770 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
777 constexpr
size_t total {
sizeof...(RangeBases)};
795 template<
typename... RangeBasesOther>
798 bool contained =
true;
799 bool has_overlap =
false;
801 using T_BASE = std::decay_t<decltype(*base)>;
805 if (((T_BASE&)rhs).isEmpty())
return;
806 if (base->contains((T_BASE&)rhs))
return;
828 if constexpr (std::is_base_of_v<RangeRT, ThisRangeType>) this->
RangeRT::clear();
831 if constexpr (std::is_base_of_v<RangeMZ, ThisRangeType>) this->
RangeMZ::clear();
845 assert(
false &&
"This should never be reached. Did you forget to implement a new DIM_UNIT?");
858 template<
typename Visitor>
861 (void(visitor(
static_cast<RangeBases*
>(
this))), ...);
864 template<
typename Visitor>
867 (void(visitor(
static_cast<const RangeBases*
>(
this))), ...);
871 template<
typename Visitor>
874 (void(visitor(
static_cast<const RangeBases*
>(
nullptr))), ...);
878 template<
typename... Range>
887 template<
typename... RangeBases>
Invalid range exception.
Definition: Exception.h:257
Definition: RangeManager.h:889
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:901
typename RangeManager< RangeBases... >::ThisRangeType ThisRangeType
Definition: RangeManager.h:891
virtual void updateRanges()=0
ThisRangeType & getRange()
get mutable range, provided for efficiency reasons (avoid updateRanges(), if only minor changes were ...
Definition: RangeManager.h:907
virtual ~RangeManagerContainer()=default
D'tor.
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:568
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:703
bool assignUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:595
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:747
bool pushIntoUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:682
bool clampToUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:717
HasRangeType hasRange() const
is any/some/all dimension in this range populated?
Definition: RangeManager.h:775
RangeBase & getRangeForDim(MSDim dim)
obtain a range dimension at runtime using dim
Definition: RangeManager.h:761
bool operator==(const RangeManager &rhs) const
Definition: RangeManager.h:575
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:859
void for_each_base_(Visitor &&visitor) const
.. and a const version
Definition: RangeManager.h:865
ThisRangeType & clear(const DIM_UNIT range)
Definition: RangeManager.h:823
void clampTo(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:738
void scaleBy(const double factor)
calls RangeBase::scale() for each dimension
Definition: RangeManager.h:657
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:670
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:615
bool extendUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:629
void clearRanges()
Resets all ranges.
Definition: RangeManager.h:816
void printRange(std::ostream &out) const
print each dimension (base classes) to a stream
Definition: RangeManager.h:851
void extend(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:648
bool operator!=(const RangeManager &rhs) const
Definition: RangeManager.h:585
bool containsAll(const RangeManager< RangeBasesOther... > &rhs) const
Definition: RangeManager.h:796
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:872
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:64
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:545
@ 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:289
double getSpan() const
Definition: RangeManager.h:263
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:278
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:235
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:178
void pushInto(const RangeBase &sandbox)
Definition: RangeManager.h:203
void shift(const double distance)
Definition: RangeManager.h:246
~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:255
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:157
void extendLeftRight(const double by)
Definition: RangeManager.h:166
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:189
double getMin() const
Definition: RangeManager.h:128
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:288
RangeBase(const double min, const double max)
Definition: RangeManager.h:49
bool operator==(const RangeBase &rhs) const
Definition: RangeManager.h:269
double getMax() const
Definition: RangeManager.h:139
void extend(const RangeBase &other)
ensure the range includes the range of other
Definition: RangeManager.h:150
Definition: RangeManager.h:420
void setMinIntensity(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:435
double getMinIntensity() const
Definition: RangeManager.h:448
void extendIntensity(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:462
bool containsIntensity(const double value) const
is value within [min, max]?
Definition: RangeManager.h:468
double getMaxIntensity() const
Definition: RangeManager.h:455
bool containsIntensity(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:474
void setMaxIntensity(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:441
Definition: RangeManager.h:358
bool containsMZ(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:412
void setMaxMZ(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:379
void extendMZ(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:400
void setMinMZ(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:373
double getMaxMZ() const
Definition: RangeManager.h:393
double getMinMZ() const
Definition: RangeManager.h:386
bool containsMZ(const double value) const
is value within [min, max]?
Definition: RangeManager.h:406
Definition: RangeManager.h:482
bool containsMobility(const double value) const
is value within [min, max]?
Definition: RangeManager.h:529
void extendMobility(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:523
double getMinMobility() const
Definition: RangeManager.h:509
bool containsMobility(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:535
double getMaxMobility() const
Definition: RangeManager.h:516
void setMinMobility(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:496
void setMaxMobility(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:502
Definition: RangeManager.h:295
bool containsRT(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:349
void extendRT(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:337
double getMaxRT() const
Definition: RangeManager.h:330
void setMaxRT(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:316
void setMinRT(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:310
double getMinRT() const
Definition: RangeManager.h:323
bool containsRT(const double value) const
is value within [min, max]?
Definition: RangeManager.h:343