CTL
0.6.1
Computed Tomography Library
|
The Range class holds start and end point of a value range (or interval) and provides a few convenience methods to operate on that range. More...
#include <range.h>
Public Member Functions | |
template<typename T1 , typename T2 , typename = typename std::enable_if<std::is_convertible<T1, T>::value && std::is_convertible<T2, T>::value>::type> | |
Range (T1 start, T2 end) | |
Constructs a Range representing the interval [start, end]. More... | |
template<typename T1 , typename T2 , typename = typename std::enable_if<std::is_convertible<T1, T>::value && std::is_convertible<T2, T>::value>::type> | |
Range (const std::pair< T1, T2 > &bounds) | |
Constructs a Range representing the interval [bounds.first, bounds.second]. More... | |
T & | start () |
Returns a (modifiable) reference to the start point of this range. | |
T & | end () |
Returns a (modifiable) reference to the end point of this range. | |
const T & | start () const |
Returns the start point of this range. | |
const T & | end () const |
Returns the end point of this range. | |
T | center () const |
Returns the center point of this range. More... | |
T | width () const |
Returns the width of the range (i.e. end - start). More... | |
T | spacing (uint nbSamples) const |
Returns the spacing that two sampling points would have if this range were divided into nbSamples equidistant sampling points. More... | |
std::vector< T > | linspace (uint nbSamples, bool endpoint=true) const |
Generates a vector with nbSamples points that are equally distributed across this range. More... | |
std::vector< T > | expspace (uint nbSamples, bool endpoint=true) const |
Generates a vector with nbSamples points that are distributed across this range with exponentially increasing distances. More... | |
std::pair< T, T > | toPair () const |
Returns the start and end point of the range as a std::pair. | |
Static Public Member Functions | |
static Range | fromCenterAndWidth (T center, T width) |
Creates a Range object describing an interval of width width centered at center. More... | |
static std::vector< T > | linspace (T from, T to, uint nbSamples, bool endpoint=true) |
Generates a vector with nbSamples points that are equally distributed across the range of [from, to]. More... | |
static std::vector< T > | expspace (T from, T to, uint nbSamples, bool endpoint=true) |
Generates a vector with nbSamples points that are distributed across the range of [from, to] with exponentially increasing distances. More... | |
Private Attributes | |
T | _data [2] |
Related Functions | |
(Note that these are not member functions.) | |
IndexRange | |
Alias for Range<unsigned int>. More... | |
SamplingRange | |
Alias for Range<float>. More... | |
The Range class holds start and end point of a value range (or interval) and provides a few convenience methods to operate on that range.
This class holds a start and end point (of same type) that are intended to describe an interval bounded by these two values. Besides its use as a pair-like container in several places throughout the CTL, the main purpose of this class lies in its convenience methods for creation of a vector of sampling points across the specified interval. Two different sampling patterns are available:
The template type for this class needs to satisfy basic mathematical operations, such as +, -, and /.
|
inline |
|
inline |
T CTL::Range< T >::center | ( | ) | const |
Returns the center point of this range.
This is computed (using operations of this range's value type) as: (start + end) / 2.
Example:
std::vector< T > CTL::Range< T >::expspace | ( | uint | nbSamples, |
bool | endpoint = true |
||
) | const |
Generates a vector with nbSamples points that are distributed across this range with exponentially increasing distances.
The start and end point of this range must be (strictly) larger than zero when using this method; throws an std::domain_error otherwise.
If nbSamples > 1 and endpoint = true, the last sample is end(). Otherwise, it is not included in the returned result.
Example:
|
static |
Generates a vector with nbSamples points that are distributed across the range of [from, to] with exponentially increasing distances.
from and to must be (strictly) larger than zero; throws an std::domain_error otherwise.
If nbSamples > 1 and endpoint = true, the last sample is to. Otherwise, it is not included in the returned result.
Same as Range<T>(from, to).expspace(nbSamples, endpoint).
Example:
|
static |
Creates a Range object describing an interval of width width centered at center.
The resulting Range has the following start and end points:
Mathematical operations are performed with the type of the Range.
Example:
std::vector< T > CTL::Range< T >::linspace | ( | uint | nbSamples, |
bool | endpoint = true |
||
) | const |
Generates a vector with nbSamples points that are equally distributed across this range.
If nbSamples > 1 and endpoint = true, the last sample is end(). Otherwise, it is not included in the returned result.
Example:
|
static |
Generates a vector with nbSamples points that are equally distributed across the range of [from, to].
If nbSamples > 1 and endpoint = true, the last sample is to. Otherwise, it is not included in the returned result.
Same as Range<T>(from, to).linspace(nbSamples, endpoint).
Example:
T CTL::Range< T >::spacing | ( | uint | nbSamples | ) | const |
Returns the spacing that two sampling points would have if this range were divided into nbSamples equidistant sampling points.
Returns zero for nbSamples <= 1.
Example:
T CTL::Range< T >::width | ( | ) | const |
|
related |
Alias for Range<unsigned int>.
This Range type is typically used to describe ranges/intervals of indices.
|
related |
Alias for Range<float>.
This Range type is typically used to describe ranges/intervals of sampling points.