EleFits  5.3.0
A modern C++ API on top of CFITSIO
Loading...
Searching...
No Matches
Public Types | Static Public Attributes | Related Functions | List of all members
Raster< T, N, THolder > Class Template Reference

#include <Raster.h>

Detailed Description

template<typename T, long N, typename THolder>
class Euclid::Fits::Raster< T, N, THolder >

Data 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
THolderThe 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:

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.

Template specialization PtrRaster
Raster which points to some external data (THolder = T*). More...
Template specialization VecRaster
Raster which owns a data vector (THolder = std::vector<T>). More...
Satisfies `ContiguousContainer` requirements
A contiguous container is a standard container whose elements are stored contiguously in memory.
Satisfies `VectorArithmetic` requirements
Implements vector space arithmetic operators (uppercase letters are for vectors, lowercase letters are for scalars):
  • Vector-additive: V += U, W = V + U, V += U, W = V - U;
  • Scalar-additive: V += a, V = U + a, V = a + U, V -= a, V = U + a, V = a - U;
  • Scalar-multiplicative: V *= a, V = U * a, V = a * U, V /= a, V = U / a;
  • Incrementation if enabled (for integral value types by default): V++, ++V, V–, –V.
See also
Position for details on the fixed- and variable-dimension cases.
makeRaster() for creation shortcuts.
Example
// Read/write PtrRaster
float data[] = {1, 2, 3, 4, 5, 6};
PtrRaster<float> ptrRaster(shape, data);
// Read-only PtrRaster
const float cData[] = {1, 2, 3, 4, 5, 6};
PtrRaster<const float> cPtrRaster(shape, cData);
// Read/write VecRaster
VecRaster<float> vecRaster(shape, std::move(vec));
// Read-only VecRaster
VecRaster<const float> cVecRaster(shape, std::move(cVec));
n-dimensional pixel position or image shape, i.e. set of integer coordinates.
Definition: Position.h:51
const Position< N > & shape() const
Get the raster shape.
T move(T... args)
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.
Examples
EleFitsTutorial.cpp.

Public Types

using Value = T
 The pixel value type.
 
- Public Types inherited from DataContainer< T, THolder, Raster< T, N, THolder > >
using Container = typename Holder::Container
 The concrete container type.
 
using Holder = THolder
 The concrete data holder type.
 
- Public Types inherited from ContiguousContainerMixin< T, TDerived >
using const_iterator = const T *
 The constant value iterator.
 
using const_reference = const T &
 The constant value reference.
 
using difference_type = std::ptrdiff_t
 The iterator difference type.
 
using iterator = T *
 The value iterator.
 
using reference = T &
 The value reference.
 
using size_type = std::size_t
 The underlying container size type.
 
using value_type = T
 The value type.
 

Static Public Attributes

static constexpr long Dim = N
 The dimension template parameter. More...
 

Public Member Functions

Construction
 Raster (Position< N > shape)
 Constructor. More...
 
template<typename U >
 Raster (Position< N > shape, U *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 > &region) 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 > &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.
 
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, THolder, Raster< T, N, THolder > >
 DataContainer (TSize s=0, std::remove_const_t< T > *d=nullptr)
 Construct from a size and non-constant data.
 
 DataContainer (TSize s, const T *d)
 Construct from a size and constant data.
 
 DataContainer (TIterator begin, TIterator end)
 Iterator-based constructor.
 
 DataContainer (std::initializer_list< T > values)
 Value list constructor.
 
 DataContainer (TArg0 arg0, TArgs &&... args)
 Forwarding constructor.
 
T * data ()
 
const std::decay_t< Container > & container () const
 Access the container in read-only mode.
 
ContainermoveTo (Container &destination)
 Move the container. More...
 
- Public Member Functions inherited from ContiguousContainerMixin< T, TDerived >
bool empty () 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 TRaster >
constexpr long bitpix (const TRaster &)
 Get the BITPIX value of a given raster.
 
template<typename T , typename... Longs>
PtrRaster< T, sizeof...(Longs)> makeRaster (T *data, Longs... shape)
 
template<typename TContainer , typename... Longs>
Raster< typename TContainer::value_type, sizeof...(Longs), DataContainerHolder< typename TContainer::value_type, TContainer > > makeRaster (TContainer &&data, Longs... shape)
 Shortcut to create a raster from a shape and data without specifying the template parameters. More...
 

The documentation for this class was generated from the following file: