9 typedef unsigned int uint;
41 template<
typename T1,
typename T2,
42 typename =
typename std::enable_if<std::is_convertible<T1, T>::value &&
43 std::is_convertible<T2, T>::value>::type>
54 template<
typename T1,
typename T2,
55 typename =
typename std::enable_if<std::is_convertible<T1, T>::value &&
56 std::is_convertible<T2, T>::value>::type>
57 Range(
const std::pair<T1, T2>& bounds)
58 : _data{ static_cast<T>(bounds.first), static_cast<T>(bounds.second) }
66 const T&
start()
const;
78 std::vector<T>
linspace(
uint nbSamples,
bool endpoint =
true)
const;
79 std::vector<T>
expspace(
uint nbSamples,
bool endpoint =
true)
const;
81 static std::vector<T>
linspace(T from, T to,
uint nbSamples,
bool endpoint =
true);
82 static std::vector<T>
expspace(T from, T to,
uint nbSamples,
bool endpoint =
true);
85 std::pair<T, T>
toPair()
const;
92 typedef Range<uint> IndexRange;
93 typedef Range<float> SamplingRange;
117 return Range<T>(center - width / T(2), center + width / T(2));
143 return (nbSamples > 1) ? (_data[1] - _data[0]) / T(nbSamples - 1)
205 return linspace(_data[0], _data[1], nbSamples, endpoint);
228 return expspace(_data[0], _data[1], nbSamples, endpoint);
249 std::vector<T> ret(nbSamples);
250 const T increment = (nbSamples > 1) ? (to - from) / T(nbSamples - endpoint)
253 std::generate(ret.begin(), ret.end(), [&idx, from, increment]
254 {
return from + T(idx++) * increment; });
279 if(from <= T(0) || to <= T(0))
280 throw std::domain_error(
"Range::expspace: Exponential sampling is not supported for " 281 "non-positive sampling points");
284 std::vector<T> ret(logVals.size());
286 std::transform(logVals.cbegin(), logVals.cend(), ret.begin(), [](
double val) {
287 constexpr
double roundIfInt = std::is_integral<T>::value ? 0.5 : 0.0;
288 return static_cast<T>(std::exp(val) + roundIfInt);
300 return { _data[0], _data[1] };
328 #endif // CTL_RANGE_H std::vector< T > linspace(uint nbSamples, bool endpoint=true) const
Generates a vector with nbSamples points that are equally distributed across this range.
Definition: range.h:203
T width() const
Returns the width of the range (i.e. end - start).
Definition: range.h:126
std::vector< T > expspace(uint nbSamples, bool endpoint=true) const
Generates a vector with nbSamples points that are distributed across this range with exponentially in...
Definition: range.h:226
std::pair< T, T > toPair() const
Returns the start and end point of the range as a std::pair.
Definition: range.h:298
T & end()
Returns a (modifiable) reference to the end point of this range.
Definition: range.h:157
T & start()
Returns a (modifiable) reference to the start point of this range.
Definition: range.h:151
Range(const std::pair< T1, T2 > &bounds)
Constructs a Range representing the interval [bounds.first, bounds.second].
Definition: range.h:57
T spacing(uint nbSamples) const
Returns the spacing that two sampling points would have if this range were divided into nbSamples equ...
Definition: range.h:141
unsigned int uint
Qt style alias for unsigned int.
Definition: modulelayout.h:6
Range(T1 start, T2 end)
Constructs a Range representing the interval [start, end].
Definition: range.h:44
T center() const
Returns the center point of this range.
Definition: range.h:187
static Range fromCenterAndWidth(T center, T width)
Creates a Range object describing an interval of width width centered at center.
Definition: range.h:115
The Range class holds start and end point of a value range (or interval) and provides a few convenien...
Definition: sparsevoxelvolume.h:12