EleFits  4.0.1
A modern C++ API on top of CFitsIO
Public Types | Static Public Attributes | List of all members
Euclid::Fits::Raster< T, n > Class Template Referenceabstract

#include <Raster.h>

Class Description

template<typename T, long n = 2>
class Euclid::Fits::Raster< T, n >

Raster of a n-dimensional image (2D by default).

Template Parameters
TThe value type, which can be const-qualified for read-only rasters
nThe 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:

There are two ways of defining the dimension of a Raster:

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:

Position<2> shape { 2, 3 };
// Read/write Raster
float data[] = { 1, 2, 3, 4, 5, 6 };
Raster<float> raster(shape, data);
// Read-only Raster
const float cData[] = { 1, 2, 3, 4, 5, 6 };
Raster<const float> cRaster(shape, cData);
// Read/write VecRaster
VecRaster<float> vecRaster(shape, std::move(vec));
// Read-only VecRaster
VecRaster<const float> cVecRaster(shape, std::move(cVec));

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.

Note
Why "raster" and not simply image or array? Mostly for disambiguation purpose: "image" refers to the extension type, while "array" has already several meanings in C/C++. 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.
See also
Position for details on the fixed- and variable-dimension cases.
makeRaster() for creation shortcuts.
Inheritance diagram for Euclid::Fits::Raster< T, n >:
[legend]

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 > &region) const
 Create a slice from a given region. More...
 
template<long m = 2>
PtrRaster< T, m > slice (const Region< n > &region)
 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 > &region) 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...
 

The documentation for this class was generated from the following file:
std::move
T move(T... args)
Euclid::Fits::Raster::shape
const Position< n > & shape() const
Get the raster shape.
std::vector
STL class.
Euclid::Fits::Raster::data
const T * data() const
Const pointer to the first data element.