11 #include <OpenMS/config.h>
33 struct RangeIntensity;
90 return uint8_t(min_ <= value) & uint8_t(value <= max_);
137 min_ = std::min(min_, other.
min_);
138 max_ = std::max(max_, other.
max_);
144 min_ = std::min(min_, value);
145 max_ = std::max(max_, value);
153 if (isEmpty())
return;
165 if (min_ == max_) extendLeftRight(min_span / 2);
176 if (isEmpty())
return;
179 min_ = std::max(min_, other.
min_);
180 max_ = std::min(max_, other.
max_);
190 if (isEmpty())
return;
195 if (getSpan() > sandbox.
getSpan())
197 max_ = min_ + sandbox.
getSpan();
199 if (min_ < sandbox.
min_)
201 shift(sandbox.
min_ - min_);
203 else if (max_ > sandbox.
max_)
205 shift(sandbox.
max_ - max_);
224 if (isEmpty())
return;
225 const double dist = max_ - min_;
226 const double extension = dist * (factor - 1) / 2;
235 if (isEmpty())
return;
244 if (isEmpty())
return nan(
"");
245 return min_ + (max_ - min_) / 2.0;
252 if (isEmpty())
return nan(
"");
258 return min_ == rhs.
min_ && max_ == rhs.
max_;
268 if (isEmpty())
return {std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max()};
269 else return {min_, max_};
274 double min_ = std::numeric_limits<double>::max();
275 double max_ = std::numeric_limits<double>::lowest();
538 template<
typename... RangeBases>
550 using T_BASE = std::decay_t<decltype(*base)>;
551 equal &= ((T_BASE&) rhs == (T_BASE&) *
this);
565 template <
typename... RangeBasesOther>
570 using T_BASE = std::decay_t<decltype(*base)>;
573 base->operator=((T_BASE&) rhs);
585 template<
typename... RangeBasesOther>
590 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION ,
"No assignment took place (no dimensions in common!);");
599 template<
typename... RangeBasesOther>
604 using T_BASE = std::decay_t<decltype(*base)>;
607 base->extend((T_BASE&) rhs);
618 template<
typename... RangeBasesOther>
623 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
631 base->scaleBy(factor);
646 base->minSpanIfSingular(min_span);
656 template<
typename... RangeBasesOther>
661 using T_BASE = std::decay_t<decltype(*base)>;
664 const auto& rhs_base = (T_BASE&)rhs;
665 if (!rhs_base.isEmpty()) base->
pushInto(rhs_base);
677 template<
typename... RangeBasesOther>
682 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
691 template<
typename... RangeBasesOther>
696 using T_BASE = std::decay_t<decltype(*base)>;
699 const auto& rhs_base = (T_BASE&)rhs;
700 if (!rhs_base.isEmpty()) base->
clampTo(rhs_base);
712 template<
typename... RangeBasesOther>
717 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
727 using Base = std::decay_t<decltype(*base)>;
728 if (base->DIM == dim)
729 r_base = (Base*)
this;
732 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
742 using Base = std::decay_t<decltype(*base)>;
743 if (base->DIM == dim)
744 r_base = (Base*)
this;
747 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
754 constexpr
size_t total{
sizeof...(RangeBases)};
757 count += !base->isEmpty();
774 template<
typename... RangeBasesOther>
777 bool contained =
true;
778 bool has_overlap =
false;
780 using T_BASE = std::decay_t<decltype(*base)>;
784 if (((T_BASE&)rhs).isEmpty())
return;
785 if (base->contains((T_BASE&) rhs))
return;
809 if constexpr (std::is_base_of_v<RangeRT, ThisRangeType>) this->
RangeRT::clear();
812 if constexpr (std::is_base_of_v<RangeMZ, ThisRangeType>) this->
RangeMZ::clear();
825 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:252
Definition: RangeManager.h:872
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:884
typename RangeManager< RangeBases... >::ThisRangeType ThisRangeType
Definition: RangeManager.h:874
virtual void updateRanges()=0
ThisRangeType & getRange()
get mutable range, provided for efficiency reasons (avoid updateRanges(), if only minor changes were ...
Definition: RangeManager.h:890
virtual ~RangeManagerContainer()=default
D'tor.
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:540
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:678
bool assignUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:566
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:722
bool pushIntoUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:657
bool clampToUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:692
HasRangeType hasRange() const
is any/some/all dimension in this range populated?
Definition: RangeManager.h:752
RangeBase & getRangeForDim(MSDim dim)
obtain a range dimension at runtime using dim
Definition: RangeManager.h:737
bool operator==(const RangeManager &rhs) const
Definition: RangeManager.h:546
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:804
void clampTo(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:713
void scaleBy(const double factor)
calls RangeBase::scale() for each dimension
Definition: RangeManager.h:628
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:643
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:586
bool extendUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:600
void clearRanges()
Resets all ranges.
Definition: RangeManager.h:795
void printRange(std::ostream &out) const
print each dimension (base classes) to a stream
Definition: RangeManager.h:831
void extend(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:619
bool operator!=(const RangeManager &rhs) const
Definition: RangeManager.h:556
bool containsAll(const RangeManager< RangeBasesOther... > &rhs) const
Definition: RangeManager.h:775
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:62
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
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:24
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:517
@ 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:38
double max_
Definition: RangeManager.h:275
double getSpan() const
Definition: RangeManager.h:250
RangeBase(const RangeBase &rhs)=default
Copy C'tor.
void setMin(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:106
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:265
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:222
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:163
void pushInto(const RangeBase &sandbox)
Definition: RangeManager.h:188
void shift(const double distance)
Definition: RangeManager.h:233
~RangeBase() noexcept=default
D'tor.
bool contains(const double value) const
is value within [min, max]?
Definition: RangeManager.h:88
double center() const
Definition: RangeManager.h:242
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:142
void extendLeftRight(const double by)
Definition: RangeManager.h:151
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:94
void clampTo(const RangeBase &other)
Definition: RangeManager.h:174
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:122
void clear()
make the range empty, i.e. isEmpty() will be true
Definition: RangeManager.h:76
void setMax(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:114
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:82
double min_
Definition: RangeManager.h:274
RangeBase(const double min, const double max)
Definition: RangeManager.h:45
bool operator==(const RangeBase &rhs) const
Definition: RangeManager.h:256
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:128
void extend(const RangeBase &other)
ensure the range includes the range of other
Definition: RangeManager.h:135
Definition: RangeManager.h:398
void setMinIntensity(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:412
double getMinIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:424
void extendIntensity(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:437
bool containsIntensity(const double value) const
is value within [min, max]?
Definition: RangeManager.h:443
double getMaxIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:430
bool containsIntensity(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:449
void setMaxIntensity(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:418
Definition: RangeManager.h:340
bool containsMZ(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:391
void setMaxMZ(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:360
void extendMZ(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:379
void setMinMZ(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:354
double getMaxMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:372
double getMinMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:366
bool containsMZ(const double value) const
is value within [min, max]?
Definition: RangeManager.h:385
Definition: RangeManager.h:457
bool containsMobility(const double value) const
is value within [min, max]?
Definition: RangeManager.h:501
void extendMobility(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:495
double getMinMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:482
bool containsMobility(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:507
double getMaxMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:488
void setMinMobility(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:470
void setMaxMobility(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:476
Definition: RangeManager.h:280
bool containsRT(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:331
void extendRT(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:319
double getMaxRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:312
void setMaxRT(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:300
void setMinRT(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:294
double getMinRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:306
bool containsRT(const double value) const
is value within [min, max]?
Definition: RangeManager.h:325