#include <Raster.h>
Data of a n-dimensional image (2D by default).
T | The value type, which can be const -qualified for read-only rasters |
N | The dimension, which can be ≥ 0 for fixed dimension, or -1 for variable dimension |
TContainer | The underlying data container type |
A raster is a contiguous container for the pixel data of an image. It features access and view services.
There are two ways of defining the dimension of a Raster
:
N = -1
.In the former case, index and size computations are optimized, and the dimension is enforced. For example, it is not possible to read a 3D image HDU as a 2D Raster
– which is nice, because an exception will be raised early! In contrast, it is possible to read a 2D image HDU as a 3D Raster
of third axis lenght =1.
In the latter case, the dimension may vary or be deduced from the file, which is also nice sometimes but puts more responsibility on the shoulders of the user code, as it should check that the actual dimension is acceptable.
Raster
meets the ContiguousContainer
requirements, by extending DataContainer
(e.g. is iterable). Raster
ensures constant-time access to elements, whatever the dimension of the data, through subscipt operator Raster::operator[]()
. Bound checking and backward indexing (index <0) are enabled in Raster::at()
.
Raster
also implements some arithmetic operators by extending VectorArithmeticMixin
. For example, two rasters can be added, or a raster can be multiplied by a scalar.
The raster data can be viewed region-wise as a PtrRaster
, provided that the region is contiguous in memory. Reading and writing non contiguous region is possible: see ImageRaster
.
Raster
which points to some external data (TContainer
= T*
). More... Raster
which owns a data vector (TContainer
= std::vector<T>
). More...Position
for details on the fixed- and variable-dimension cases. makeRaster()
for creation shortcuts.NdArray
would have been an option, but every related class should have been prefixed with Nd
for homogeneity: NdPosition
, NdRegion
, VecNdArray
... From the cathodic television era, raster also historically carries the concept of contiguous pixels, is very common in the field of Earth observation, and also belongs to the Java library. All in all, Raster
seems to be a fair compromise. Public Types | |
using | Value = T |
The pixel value type. | |
Public Types inherited from DataContainer< T, TContainer, Raster< T, N, TContainer > > | |
using | Holder = DataContainerHolder< T, TContainer > |
The concrete data holder type. | |
Public Types inherited from ContiguousContainerMixin< T, TDerived > | |
using | value_type = T |
The value type. | |
using | reference = T & |
The value reference. | |
using | const_reference = const T & |
The constant value reference. | |
using | iterator = T * |
The value iterator. | |
using | const_iterator = const T * |
The constant value iterator. | |
using | difference_type = std::ptrdiff_t |
The iterator difference type. | |
using | size_type = std::size_t |
The underlying container size type. | |
Static Public Attributes | |
static constexpr long | Dim = N |
The dimension template parameter. More... | |
Public Member Functions | |
Construction | |
Raster (Position< N > shape) | |
Constructor. More... | |
Raster (Position< N > shape, T *data) | |
Constructor. More... | |
template<typename... Ts> | |
Raster (Position< N > shape, Ts &&... args) | |
Constructor. More... | |
Properties | |
const Position< N > & | shape () const |
Get the raster shape. | |
Region< N > | domain () const |
Get the raster domain. More... | |
long | dimension () const |
Get the actual dimension. More... | |
template<long I> | |
long | length () const |
Get the length along given axis. | |
Element access | |
long | index (const Position< N > &pos) const |
Compute the raw index of a given position. | |
const T & | operator[] (const Position< N > &pos) const |
Access the pixel value at given position. | |
T & | operator[] (const Position< N > &pos) |
Access the pixel value at given position. | |
const T & | at (const Position< N > &pos) const |
Access the pixel value at given position. More... | |
T & | at (const Position< N > &pos) |
Access the pixel value at given position. | |
Views | |
template<long M = 2> | |
bool | isContiguous (const Region< N > ®ion) const |
Check whether a region is made of contiguous values in memory. More... | |
template<long M = 2> | |
const PtrRaster< const T, M > | slice (const Region< N > ®ion) const |
Create a slice from a given region. More... | |
template<long M = 2> | |
PtrRaster< T, M > | slice (const Region< N > ®ion) |
Create a slice from a given region. | |
const PtrRaster< const T, N > | section (long front, long back) const |
Create a section between given indices. More... | |
PtrRaster< T, N > | section (long front, long back) |
Create a section between given indices. | |
const PtrRaster< const T, N==-1 ? -1 :N - 1 > | section (long index) const |
Create a section at given. | |
PtrRaster< T, N==-1 ? -1 :N - 1 > | section (long index) |
Create a section at given. | |
Public Member Functions inherited from DataContainer< T, TContainer, Raster< T, N, TContainer > > | |
T * | data () |
Inherit data holder's data() . | |
const T * | data () const |
Inherit data holder's data() . | |
const std::decay_t< TContainer > & | container () const |
Access the container in read-only mode. | |
std::vector< T > | vector () const |
Copy the container values into an std::vector . More... | |
TContainer & | moveTo (TContainer &destination) |
Move the container. More... | |
std::size_t | size () const |
Inherit data holder's size() . | |
Public Member Functions inherited from ContiguousContainerMixin< T, TDerived > | |
bool | emtpy () const |
Check whether the container is empty. More... | |
const T & | operator[] (size_type index) const |
Access the element with given index. | |
T & | operator[] (size_type index) |
Access the element with given index. | |
const_iterator | begin () const |
Iterator to the first element. | |
iterator | begin () |
Iterator to the first element. | |
const_iterator | cbegin () |
Iterator to the first element. | |
const_iterator | end () const |
Iterator to one past the last element. | |
iterator | end () |
Iterator to one past the last element. | |
const_iterator | cend () |
Iterator to one past the last element. | |
virtual bool | operator== (const TDerived &rhs) const |
Check equality. | |
bool | operator!= (const TDerived &rhs) const |
Check inequality. | |
Public Member Functions inherited from VectorArithmeticMixin< T, TDerived, Incrementable > | |
TDerived & | operator+= (const TDerived &rhs) |
V += U and W = V + U. | |
TDerived & | operator+= (const T &rhs) |
V += a, V = U + a, V = a + U. | |
TDerived & | operator-= (const TDerived &rhs) |
V -= U and W = V - U. | |
TDerived & | operator-= (const T &rhs) |
V -= a, V = U - a, V = a - U. | |
TDerived & | operator*= (const T &rhs) |
V *= a, V = U * a, V = a * U. | |
TDerived & | operator/= (const T &rhs) |
V /= a, V = U / a. | |
template<typename TFunc , typename... TContainers> | |
TDerived & | generate (TFunc &&func, const TContainers &... args) |
Generate values from a function with optional input containers. More... | |
template<typename TFunc , typename... TContainers> | |
TDerived & | apply (TFunc &&func, const TContainers &... args) |
Apply a function with optional input containers. More... | |
TDerived | operator+ () const |
Copy. | |
TDerived | operator- () const |
Compute the opposite. | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename TContainer , typename... Longs> | |
Raster< typename TContainer::value_type, sizeof...(Longs), TContainer > | makeRaster (TContainer &&data, Longs... shape) |
Shortcut to create a raster from a shape and data without specifying the template parameters. More... | |
template<typename T , typename... Longs> | |
PtrRaster< T, sizeof...(Longs)> | makeRaster (T *data, Longs... shape) |
Related Functions inherited from ContiguousContainerMixin< T, TDerived > | |
template<typename T , typename TDerived > | |
std::ostream & | operator<< (std::ostream &os, const ContiguousContainerMixin< T, TDerived > &container) |
Insert a ContiguousContainerMixin into an output stream. | |