EleFits
4.0.1
A modern C++ API on top of CFitsIO
|
#include <Raster.h>
Raster 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 |
A raster is a contiguous container for the pixel data of an image. It features access and view services.
This class is abstract, as the actual pixel container is not defined. Two concrete implementations are provided:
PtrRaster
doesn's itself own data: it is just a shell which stores a shape, and a pointer to some actual data;VecRaster
owns an std::vector
(and is compatible with move semantics, which allows borrowing the vector
).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 returned dimension is acceptable.
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()
.
Example usages:
The raster data can be viewed region-wise as a PtrRaster
, given that the region is contiguous in memory. Reading and writing non contiguous region is possible: see ImageRaster
.
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 Member Functions | |
Constructors, destructor. | |
virtual | ~Raster ()=default |
Destructor. | |
Raster (const Raster< T, n > &rhs)=default | |
Copy constructor. | |
Raster (Raster< T, n > &&rhs)=default | |
Move constructor. | |
Raster< T, n > & | operator= (const Raster< T, n > &rhs)=default |
Copy assignment. | |
Raster< T, n > & | operator= (Raster< T, n > &&rhs)=default |
Move assignment. | |
Raster (Position< n > rasterShape) | |
Create a raster with given shape. | |
Properties. | |
const Position< n > & | shape () const |
Get the raster shape. | |
Region< n > | domain () const |
Get raster domain. More... | |
long | dimension () const |
Dimension. More... | |
long | size () const |
Number of pixels. | |
template<long i> | |
long | length () const |
Length along given axis. | |
Element access. | |
const T * | data () const |
Const pointer to the first data element. | |
T * | data () |
Pointer to the first data element. | |
long | index (const Position< n > &pos) const |
Raw index of a position. | |
const T & | operator[] (const Position< n > &pos) const |
Pixel at given position. | |
T & | operator[] (const Position< n > &pos) |
Pixel at given position. | |
const T & | at (const Position< n > &pos) const |
Access the value at given position. More... | |
T & | at (const Position< n > &pos) |
Access the value at given position. More... | |
Views. | |
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. More... | |
const PtrRaster< const T, n > | section (long front, long back) const |
Create a section at given index. More... | |
PtrRaster< T, n > | section (long front, long back) |
Create a section at given index. More... | |
const PtrRaster< const T, n==-1 ? -1 :n - 1 > | section (long index) const |
Create a section at given index. More... | |
PtrRaster< T, n==-1 ? -1 :n - 1 > | section (long index) |
Create a section at given index. More... | |
template<long m = 2> | |
bool | isContiguous (const Region< n > ®ion) const |
Check whether a region is made of contiguous values in memory. More... | |
Static Public Attributes | |
static constexpr long | Dim = n |
The dimension template parameter. More... | |