35 #ifndef OPENMS_MATH_MISC_LINEARINTERPOLATION_H 36 #define OPENMS_MATH_MISC_LINEARINTERPOLATION_H 74 template <
typename Key =
double,
typename Value = Key>
142 ValueType
value(KeyType arg_pos)
const 145 typedef typename container_type::difference_type DiffType;
150 KeyType frac = std::modf(pos, &left_key);
151 DiffType
const left = DiffType(left_key);
162 return data_[0] * (1 + frac);
168 DiffType
const back =
data_.size() - 1;
177 return data_[left] * (1 - frac);
183 return data_[left + 1] * frac +
data_[left] * (1 - frac);
191 void addValue(KeyType arg_pos, ValueType arg_value)
194 typedef typename container_type::difference_type DiffType;
199 KeyType
const frac = std::modf(pos, &left_key);
200 DiffType
const left = DiffType(left_key);
211 data_[0] += (1 + frac) * arg_value;
218 DiffType
const back =
data_.size() - 1;
227 data_[left] += (1 - frac) * arg_value;
234 data_[left + 1] += frac * arg_value;
235 data_[left] += (1 - frac) * arg_value;
268 return (
data_[0]) * (pos + 1.5);
283 if (left < size_ - 1)
286 return (
data_[left] -
data_[left - 1]) * factor + (
data_[left + 1] -
data_[left]) * (1. - factor);
291 if (left == size_ - 1)
293 return (
data_[left] -
data_[left - 1]) * factor + (-
data_[left]) * (1. - factor);
303 return (-
data_[left - 1]) * factor;
330 template <
typename SourceContainer>
339 return data_.empty();
418 void setMapping(KeyType
const & scale, KeyType
const & inside, KeyType
const & outside)
423 offset_ = outside - scale * inside;
432 void setMapping(KeyType
const & inside_low, KeyType
const & outside_low,
433 KeyType
const & inside_high, KeyType
const & outside_high)
435 if (inside_high != inside_low)
437 setMapping((outside_high - outside_low) / (inside_high - inside_low),
438 inside_low, outside_low);
488 #endif // OPENMS_MATH_MISC_LINEARINTERPOLATION_H void addValue(KeyType arg_pos, ValueType arg_value)
Performs linear resampling. The arg_value is split up and added to the data points around arg_pos...
Definition: LinearInterpolation.h:191
bool empty() const
Returns true if getData() is empty.
Definition: LinearInterpolation.h:337
KeyType index2key(KeyType pos) const
The transformation from "inside" to "outside" coordinates.
Definition: LinearInterpolation.h:365
std::vector< value_type > container_type
Definition: LinearInterpolation.h:85
void setScale(KeyType const &scale)
Accessor. "Scale" is the difference (in "outside" units) between consecutive entries in "Data"...
Definition: LinearInterpolation.h:383
KeyType const & getScale() const
Accessor. "Scale" is the difference (in "outside" units) between consecutive entries in "Data"...
Definition: LinearInterpolation.h:373
container_type ContainerType
Definition: LinearInterpolation.h:89
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
KeyType supportMax() const
Upper boundary of the support, in "outside" coordinates.
Definition: LinearInterpolation.h:466
~LinearInterpolation()
Destructor.
Definition: LinearInterpolation.h:134
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
KeyType const & getOffset() const
Accessor. "Offset" is the point (in "outside" units) which corresponds to "Data[0]".
Definition: LinearInterpolation.h:389
KeyType offset_
Definition: LinearInterpolation.h:476
KeyType outside_
Definition: LinearInterpolation.h:478
LinearInterpolation & operator=(LinearInterpolation const &arg)
Assignment operator.
Definition: LinearInterpolation.h:119
Provides access to linearly interpolated values (and derivatives) from discrete data points...
Definition: LinearInterpolation.h:75
ContainerType & getData()
Returns the internal random access container from which interpolated values are being sampled...
Definition: LinearInterpolation.h:314
ValueType value(KeyType arg_pos) const
Returns the interpolated value.
Definition: LinearInterpolation.h:142
ContainerType data_
Definition: LinearInterpolation.h:480
LinearInterpolation(LinearInterpolation const &arg)
Copy constructor.
Definition: LinearInterpolation.h:110
value_type ValueType
Definition: LinearInterpolation.h:87
KeyType const & getInsideReferencePoint() const
Accessor. See setMapping().
Definition: LinearInterpolation.h:448
Key key_type
Definition: LinearInterpolation.h:84
Value value_type
Definition: LinearInterpolation.h:82
ContainerType const & getData() const
Returns the internal random access container from which interpolated values are being sampled...
Definition: LinearInterpolation.h:320
KeyType inside_
Definition: LinearInterpolation.h:477
KeyType supportMin() const
Lower boundary of the support, in "outside" coordinates.
Definition: LinearInterpolation.h:460
LinearInterpolation(KeyType scale=1., KeyType offset=0.)
Constructors and destructor.
Definition: LinearInterpolation.h:101
key_type KeyType
Definition: LinearInterpolation.h:88
KeyType const & getOutsideReferencePoint() const
Accessor. See setMapping().
Definition: LinearInterpolation.h:454
void setMapping(KeyType const &inside_low, KeyType const &outside_low, KeyType const &inside_high, KeyType const &outside_high)
Specifies the mapping from "outside" to "inside" coordinates by the following data: ...
Definition: LinearInterpolation.h:432
ValueType derivative(KeyType arg_pos) const
Returns the interpolated derivative.
Definition: LinearInterpolation.h:245
void setData(SourceContainer const &data)
Assigns data to the internal random access container from which interpolated values are being sampled...
Definition: LinearInterpolation.h:331
void setMapping(KeyType const &scale, KeyType const &inside, KeyType const &outside)
Specifies the mapping from "outside" to "inside" coordinates by the following data: ...
Definition: LinearInterpolation.h:418
KeyType scale_
Definition: LinearInterpolation.h:475
KeyType key2index(KeyType pos) const
The transformation from "outside" to "inside" coordinates.
Definition: LinearInterpolation.h:350
void setOffset(KeyType const &offset)
Accessor. "Offset" is the point (in "outside" units) which corresponds to "Data[0]".
Definition: LinearInterpolation.h:400