37 #include <OpenMS/config.h>
59 struct RangeIntensity;
116 return uint8_t(min_ <= value) & uint8_t(value <= max_);
163 min_ = std::min(min_, other.
min_);
164 max_ = std::max(max_, other.
max_);
170 min_ = std::min(min_, value);
171 max_ = std::max(max_, value);
179 if (isEmpty())
return;
191 if (min_ == max_) extendLeftRight(min_span / 2);
202 if (isEmpty())
return;
205 min_ = std::max(min_, other.
min_);
206 max_ = std::min(max_, other.
max_);
216 if (isEmpty())
return;
221 if (getSpan() > sandbox.
getSpan())
223 max_ = min_ + sandbox.
getSpan();
225 if (min_ < sandbox.
min_)
227 shift(sandbox.
min_ - min_);
229 else if (max_ > sandbox.
max_)
231 shift(sandbox.
max_ - max_);
250 if (isEmpty())
return;
251 const double dist = max_ - min_;
252 const double extension = dist * (factor - 1) / 2;
261 if (isEmpty())
return;
270 if (isEmpty())
return nan(
"");
271 return min_ + (max_ - min_) / 2.0;
278 if (isEmpty())
return nan(
"");
284 return min_ == rhs.
min_ && max_ == rhs.
max_;
294 if (isEmpty())
return {std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max()};
295 else return {min_, max_};
300 double min_ = std::numeric_limits<double>::max();
301 double max_ = std::numeric_limits<double>::lowest();
564 template<
typename... RangeBases>
576 using T_BASE = std::decay_t<decltype(*base)>;
577 equal &= ((T_BASE&) rhs == (T_BASE&) *
this);
591 template <
typename... RangeBasesOther>
596 using T_BASE = std::decay_t<decltype(*base)>;
599 base->operator=((T_BASE&) rhs);
611 template<
typename... RangeBasesOther>
616 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION ,
"No assignment took place (no dimensions in common!);");
625 template<
typename... RangeBasesOther>
630 using T_BASE = std::decay_t<decltype(*base)>;
633 base->extend((T_BASE&) rhs);
644 template<
typename... RangeBasesOther>
649 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
657 base->scaleBy(factor);
672 base->minSpanIfSingular(min_span);
682 template<
typename... RangeBasesOther>
687 using T_BASE = std::decay_t<decltype(*base)>;
690 const auto& rhs_base = (T_BASE&)rhs;
691 if (!rhs_base.isEmpty()) base->
pushInto(rhs_base);
703 template<
typename... RangeBasesOther>
708 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
717 template<
typename... RangeBasesOther>
722 using T_BASE = std::decay_t<decltype(*base)>;
725 const auto& rhs_base = (T_BASE&)rhs;
726 if (!rhs_base.isEmpty()) base->
clampTo(rhs_base);
738 template<
typename... RangeBasesOther>
743 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
753 using Base = std::decay_t<decltype(*base)>;
754 if (base->DIM == dim)
755 r_base = (Base*)
this;
758 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
768 using Base = std::decay_t<decltype(*base)>;
769 if (base->DIM == dim)
770 r_base = (Base*)
this;
773 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
780 constexpr
size_t total{
sizeof...(RangeBases)};
783 count += !base->isEmpty();
800 template<
typename... RangeBasesOther>
803 bool contained =
true;
804 bool has_overlap =
false;
806 using T_BASE = std::decay_t<decltype(*base)>;
810 if (((T_BASE&)rhs).isEmpty())
return;
811 if (base->contains((T_BASE&) rhs))
return;
835 if constexpr (std::is_base_of_v<RangeRT, ThisRangeType>) this->
RangeRT::clear();
838 if constexpr (std::is_base_of_v<RangeMZ, ThisRangeType>) this->
RangeMZ::clear();
851 assert(
false &&
"This should never be reached. Did you forget to implement a new DIM_UNIT?");
866 template<
typename Visitor>
869 (void(visitor(
static_cast<RangeBases*
>(
this))), ...);
872 template<
typename Visitor>
875 (void(visitor(
static_cast<const RangeBases*
>(
this))), ...);
879 template<
typename Visitor>
882 (void(visitor(
static_cast<const RangeBases*
>(
nullptr))), ...);
886 template<
typename... Range>
895 template <
typename ...RangeBases>
Invalid range exception.
Definition: Exception.h:278
Definition: RangeManager.h:898
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:910
typename RangeManager< RangeBases... >::ThisRangeType ThisRangeType
Definition: RangeManager.h:900
virtual void updateRanges()=0
ThisRangeType & getRange()
get mutable range, provided for efficiency reasons (avoid updateRanges(), if only minor changes were ...
Definition: RangeManager.h:916
virtual ~RangeManagerContainer()=default
D'tor.
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:566
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:704
bool assignUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:592
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:748
bool pushIntoUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:683
bool clampToUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:718
HasRangeType hasRange() const
is any/some/all dimension in this range populated?
Definition: RangeManager.h:778
RangeBase & getRangeForDim(MSDim dim)
obtain a range dimension at runtime using dim
Definition: RangeManager.h:763
bool operator==(const RangeManager &rhs) const
Definition: RangeManager.h:572
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:867
void for_each_base_(Visitor &&visitor) const
.. and a const version
Definition: RangeManager.h:873
ThisRangeType & clear(const DIM_UNIT range)
Definition: RangeManager.h:830
void clampTo(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:739
void scaleBy(const double factor)
calls RangeBase::scale() for each dimension
Definition: RangeManager.h:654
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:669
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:612
bool extendUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:626
void clearRanges()
Resets all ranges.
Definition: RangeManager.h:821
void printRange(std::ostream &out) const
print each dimension (base classes) to a stream
Definition: RangeManager.h:857
void extend(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:645
bool operator!=(const RangeManager &rhs) const
Definition: RangeManager.h:582
bool containsAll(const RangeManager< RangeBasesOther... > &rhs) const
Definition: RangeManager.h:801
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:880
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:88
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
DIM
Definition: DimMapper.h:627
MSDim
Dimensions of data acquisition for MS data.
Definition: RangeManager.h:50
DIM_UNIT
Definition: CommonEnums.h:46
@ 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:543
@ 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:64
double max_
Definition: RangeManager.h:301
double getSpan() const
Definition: RangeManager.h:276
RangeBase(const RangeBase &rhs)=default
Copy C'tor.
void setMin(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:132
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:291
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:248
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:189
void pushInto(const RangeBase &sandbox)
Definition: RangeManager.h:214
void shift(const double distance)
Definition: RangeManager.h:259
~RangeBase() noexcept=default
D'tor.
bool contains(const double value) const
is value within [min, max]?
Definition: RangeManager.h:114
double center() const
Definition: RangeManager.h:268
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:168
void extendLeftRight(const double by)
Definition: RangeManager.h:177
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:120
void clampTo(const RangeBase &other)
Definition: RangeManager.h:200
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:148
void clear()
make the range empty, i.e. isEmpty() will be true
Definition: RangeManager.h:102
void setMax(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:140
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:108
double min_
Definition: RangeManager.h:300
RangeBase(const double min, const double max)
Definition: RangeManager.h:71
bool operator==(const RangeBase &rhs) const
Definition: RangeManager.h:282
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:154
void extend(const RangeBase &other)
ensure the range includes the range of other
Definition: RangeManager.h:161
Definition: RangeManager.h:424
void setMinIntensity(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:438
double getMinIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:450
void extendIntensity(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:463
bool containsIntensity(const double value) const
is value within [min, max]?
Definition: RangeManager.h:469
double getMaxIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:456
bool containsIntensity(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:475
void setMaxIntensity(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:444
Definition: RangeManager.h:366
bool containsMZ(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:417
void setMaxMZ(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:386
void extendMZ(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:405
void setMinMZ(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:380
double getMaxMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:398
double getMinMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:392
bool containsMZ(const double value) const
is value within [min, max]?
Definition: RangeManager.h:411
Definition: RangeManager.h:483
bool containsMobility(const double value) const
is value within [min, max]?
Definition: RangeManager.h:527
void extendMobility(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:521
double getMinMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:508
bool containsMobility(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:533
double getMaxMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:514
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:306
bool containsRT(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:357
void extendRT(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:345
double getMaxRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:338
void setMaxRT(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:326
void setMinRT(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:320
double getMinRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:332
bool containsRT(const double value) const
is value within [min, max]?
Definition: RangeManager.h:351