pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
pops::Raster< Number, Index > Class Template Reference

Representation of a raster image. More...

#include <raster.hpp>

Inheritance diagram for pops::Raster< Number, Index >:
Inheritance graph
[legend]

Public Types

typedef Number NumberType
 
typedef Index IndexType
 

Public Member Functions

 Raster ()
 
 Raster (const Raster &other)
 
 Raster (const Raster &other, Number value)
 Initialize size using another raster, but use given value. More...
 
 Raster (Raster &&other)
 
 Raster (Index rows, Index cols)
 
 Raster (Index rows, Index cols, Number value)
 
 Raster (Number *data, Index rows, Index cols)
 Use existing data storage. More...
 
 Raster (std::initializer_list< std::initializer_list< Number >> l)
 
 ~Raster ()
 
Index cols () const
 
Index rows () const
 
Number * data () noexcept
 Returns pointer for direct access the underlying array. More...
 
const Number * data () const noexcept
 Returns pointer for direct access the underlying array. More...
 
void fill (Number value)
 
void zero ()
 
template<class UnaryOperation >
void for_each (UnaryOperation op) const
 
const Number & operator() (Index row, Index col) const
 
Number & operator() (Index row, Index col)
 
Rasteroperator= (const Raster &other)
 
Rasteroperator= (Raster &&other)
 
template<typename OtherNumber >
Rasteroperator+= (OtherNumber value)
 
template<typename OtherNumber >
Rasteroperator-= (OtherNumber value)
 
template<typename OtherNumber >
Rasteroperator*= (OtherNumber value)
 
template<typename OtherNumber >
Rasteroperator/= (OtherNumber value)
 
template<typename OtherNumber >
std::enable_if< std::is_floating_point< Number >::value||std::is_same< Number, OtherNumber >::value, Raster & >::type operator+= (const Raster< OtherNumber > &image)
 
template<typename OtherNumber >
std::enable_if< std::is_floating_point< Number >::value||std::is_same< Number, OtherNumber >::value, Raster & >::type operator-= (const Raster< OtherNumber > &image)
 
template<typename OtherNumber >
std::enable_if< std::is_floating_point< Number >::value||std::is_same< Number, OtherNumber >::value, Raster & >::type operator*= (const Raster< OtherNumber > &image)
 
template<typename OtherNumber >
std::enable_if< std::is_floating_point< Number >::value||std::is_same< Number, OtherNumber >::value, Raster & >::type operator/= (const Raster< OtherNumber > &image)
 
bool operator== (const Raster &other) const
 
bool operator!= (const Raster &other) const
 

Protected Attributes

Index rows_
 
Index cols_
 
Number * data_
 
bool owns_
 

Friends

template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator+ (const Raster &raster, OtherNumber value)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator- (const Raster &raster, OtherNumber value)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator* (const Raster &raster, OtherNumber value)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator/ (const Raster &raster, OtherNumber value)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator+ (OtherNumber value, const Raster &raster)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator- (OtherNumber value, const Raster &raster)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator* (OtherNumber value, const Raster &raster)
 
template<typename OtherNumber >
std::enable_if< std::is_arithmetic< OtherNumber >::value, Raster >::type operator/ (OtherNumber value, const Raster &raster)
 
Raster pow (Raster image, double value)
 
Raster sqrt (Raster image)
 
std::ostream & operator<< (std::ostream &stream, const Raster &image)
 

Detailed Description

template<typename Number, typename Index = int>
class pops::Raster< Number, Index >

Representation of a raster image.

The object support raster algebra operations:

Raster<int> a = {{1, 2}, {3, 4}};
auto b = 2 * (a + 1);

The raster algebra operations sometimes overlap with matrix operations, e.g. for plus operator or multiplication by scalar. However, in some cases, the behavior is different, e.g., multiplication of the rasters results in a new raster with cell values which are result of multiplying cell values in the relevant positions of the two raster.

Raster<int> a = {{1, 2}, {3, 4}};
auto b = 2 * (a + 1);

The template parameter Number is the numerical type of the raster, typically int, float, or double.

The internal storage is directly accessible which comes with a great responsibility. Although for the computations themselves, direct access is not needed, it gives a lot of advantages when initializing the values as well as when putting them to some storage when the computation is done. The values need to be stored in one liner array with row-major oder, i.e. individual value can be accessed using the following:

row * total_number_of_columns + column

Operations involving raster and scalar preserve the type of the raster and don't produce a new type of raster based on the scalar type, i.e., a * 0.5 where a is an integral raster type results in the same integral raster type, not floating point raster type. This makes perations such as * and *= behave the same for scalars.

On the other hand, operations involving two rasters of different type resolve to their common type, specifically the common type of their scalars using std::common_type, i.e. a * b where a is an integral raster type and b is a floating raster type produce a floating raster type.

The Index template parameter is an signed or unsigned integer used for indexing of rows and columns. The default value is int because signed indices is the modern C++ practice and int is used in Rcpp.

Definition at line 97 of file raster.hpp.

Member Typedef Documentation

◆ IndexType

template<typename Number , typename Index = int>
typedef Index pops::Raster< Number, Index >::IndexType

Definition at line 108 of file raster.hpp.

◆ NumberType

template<typename Number , typename Index = int>
typedef Number pops::Raster< Number, Index >::NumberType

Definition at line 107 of file raster.hpp.

Constructor & Destructor Documentation

◆ Raster() [1/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( )
inline

Definition at line 110 of file raster.hpp.

◆ Raster() [2/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( const Raster< Number, Index > &  other)
inline

Definition at line 117 of file raster.hpp.

◆ Raster() [3/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( const Raster< Number, Index > &  other,
Number  value 
)
inline

Initialize size using another raster, but use given value.

The values in the other raster are not used.

Definition at line 129 of file raster.hpp.

◆ Raster() [4/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( Raster< Number, Index > &&  other)
inline

Definition at line 136 of file raster.hpp.

◆ Raster() [5/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( Index  rows,
Index  cols 
)
inline

Definition at line 144 of file raster.hpp.

◆ Raster() [6/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( Index  rows,
Index  cols,
Number  value 
)
inline

Definition at line 151 of file raster.hpp.

◆ Raster() [7/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( Number *  data,
Index  rows,
Index  cols 
)
inline

Use existing data storage.

Uses existing data and storage as is. No memory allocation is performed. The Raster object does not take ownership of the memory, so it can and must be managed in an appropriate way by the caller.

Definition at line 165 of file raster.hpp.

◆ Raster() [8/8]

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::Raster ( std::initializer_list< std::initializer_list< Number >>  l)
inline

Definition at line 171 of file raster.hpp.

◆ ~Raster()

template<typename Number , typename Index = int>
pops::Raster< Number, Index >::~Raster ( )
inline

Definition at line 186 of file raster.hpp.

Member Function Documentation

◆ cols()

template<typename Number , typename Index = int>
Index pops::Raster< Number, Index >::cols ( ) const
inline

Definition at line 193 of file raster.hpp.

Here is the caller graph for this function:

◆ data() [1/2]

template<typename Number , typename Index = int>
const Number* pops::Raster< Number, Index >::data ( ) const
inlinenoexcept

Returns pointer for direct access the underlying array.

Same as the non-const version but used when the object is const.

Definition at line 217 of file raster.hpp.

◆ data() [2/2]

template<typename Number , typename Index = int>
Number* pops::Raster< Number, Index >::data ( )
inlinenoexcept

Returns pointer for direct access the underlying array.

The values are stored in row-major order. See the class description for details.

Definition at line 208 of file raster.hpp.

Here is the caller graph for this function:

◆ fill()

template<typename Number , typename Index = int>
void pops::Raster< Number, Index >::fill ( Number  value)
inline

Definition at line 222 of file raster.hpp.

◆ for_each()

template<typename Number , typename Index = int>
template<class UnaryOperation >
void pops::Raster< Number, Index >::for_each ( UnaryOperation  op) const
inline

Definition at line 233 of file raster.hpp.

◆ operator!=()

template<typename Number , typename Index = int>
bool pops::Raster< Number, Index >::operator!= ( const Raster< Number, Index > &  other) const
inline

Definition at line 379 of file raster.hpp.

◆ operator()() [1/2]

template<typename Number , typename Index = int>
Number& pops::Raster< Number, Index >::operator() ( Index  row,
Index  col 
)
inline

Definition at line 243 of file raster.hpp.

◆ operator()() [2/2]

template<typename Number , typename Index = int>
const Number& pops::Raster< Number, Index >::operator() ( Index  row,
Index  col 
) const
inline

Definition at line 238 of file raster.hpp.

◆ operator*=() [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if< std::is_floating_point<Number>::value || std::is_same<Number, OtherNumber>::value, Raster&>::type pops::Raster< Number, Index >::operator*= ( const Raster< OtherNumber > &  image)
inline

Definition at line 342 of file raster.hpp.

◆ operator*=() [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
Raster& pops::Raster< Number, Index >::operator*= ( OtherNumber  value)
inline

Definition at line 292 of file raster.hpp.

◆ operator+=() [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if< std::is_floating_point<Number>::value || std::is_same<Number, OtherNumber>::value, Raster&>::type pops::Raster< Number, Index >::operator+= ( const Raster< OtherNumber > &  image)
inline

Definition at line 312 of file raster.hpp.

◆ operator+=() [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
Raster& pops::Raster< Number, Index >::operator+= ( OtherNumber  value)
inline

Definition at line 276 of file raster.hpp.

◆ operator-=() [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if< std::is_floating_point<Number>::value || std::is_same<Number, OtherNumber>::value, Raster&>::type pops::Raster< Number, Index >::operator-= ( const Raster< OtherNumber > &  image)
inline

Definition at line 327 of file raster.hpp.

◆ operator-=() [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
Raster& pops::Raster< Number, Index >::operator-= ( OtherNumber  value)
inline

Definition at line 284 of file raster.hpp.

◆ operator/=() [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if< std::is_floating_point<Number>::value || std::is_same<Number, OtherNumber>::value, Raster&>::type pops::Raster< Number, Index >::operator/= ( const Raster< OtherNumber > &  image)
inline

Definition at line 357 of file raster.hpp.

◆ operator/=() [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
Raster& pops::Raster< Number, Index >::operator/= ( OtherNumber  value)
inline

Definition at line 300 of file raster.hpp.

◆ operator=() [1/2]

template<typename Number , typename Index = int>
Raster& pops::Raster< Number, Index >::operator= ( const Raster< Number, Index > &  other)
inline

Definition at line 248 of file raster.hpp.

◆ operator=() [2/2]

template<typename Number , typename Index = int>
Raster& pops::Raster< Number, Index >::operator= ( Raster< Number, Index > &&  other)
inline

Definition at line 261 of file raster.hpp.

◆ operator==()

template<typename Number , typename Index = int>
bool pops::Raster< Number, Index >::operator== ( const Raster< Number, Index > &  other) const
inline

Definition at line 367 of file raster.hpp.

◆ rows()

template<typename Number , typename Index = int>
Index pops::Raster< Number, Index >::rows ( ) const
inline

Definition at line 198 of file raster.hpp.

Here is the caller graph for this function:

◆ zero()

template<typename Number , typename Index = int>
void pops::Raster< Number, Index >::zero ( )
inline

Definition at line 227 of file raster.hpp.

Friends And Related Function Documentation

◆ operator* [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator* ( const Raster< Number, Index > &  raster,
OtherNumber  value 
)
friend

Definition at line 424 of file raster.hpp.

◆ operator* [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator* ( OtherNumber  value,
const Raster< Number, Index > &  raster 
)
friend

Definition at line 477 of file raster.hpp.

◆ operator+ [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator+ ( const Raster< Number, Index > &  raster,
OtherNumber  value 
)
friend

Definition at line 394 of file raster.hpp.

◆ operator+ [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator+ ( OtherNumber  value,
const Raster< Number, Index > &  raster 
)
friend

Definition at line 454 of file raster.hpp.

◆ operator- [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator- ( const Raster< Number, Index > &  raster,
OtherNumber  value 
)
friend

Definition at line 409 of file raster.hpp.

◆ operator- [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator- ( OtherNumber  value,
const Raster< Number, Index > &  raster 
)
friend

Definition at line 462 of file raster.hpp.

◆ operator/ [1/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator/ ( const Raster< Number, Index > &  raster,
OtherNumber  value 
)
friend

Definition at line 439 of file raster.hpp.

◆ operator/ [2/2]

template<typename Number , typename Index = int>
template<typename OtherNumber >
std::enable_if<std::is_arithmetic<OtherNumber>::value, Raster>::type operator/ ( OtherNumber  value,
const Raster< Number, Index > &  raster 
)
friend

Definition at line 485 of file raster.hpp.

◆ operator<<

template<typename Number , typename Index = int>
std::ostream& operator<< ( std::ostream &  stream,
const Raster< Number, Index > &  image 
)
friend

Definition at line 508 of file raster.hpp.

◆ pow

template<typename Number , typename Index = int>
Raster pow ( Raster< Number, Index >  image,
double  value 
)
friend

Definition at line 497 of file raster.hpp.

◆ sqrt

template<typename Number , typename Index = int>
Raster sqrt ( Raster< Number, Index >  image)
friend

Definition at line 502 of file raster.hpp.

Member Data Documentation

◆ cols_

template<typename Number , typename Index = int>
Index pops::Raster< Number, Index >::cols_
protected

Definition at line 101 of file raster.hpp.

◆ data_

template<typename Number , typename Index = int>
Number* pops::Raster< Number, Index >::data_
protected

Definition at line 102 of file raster.hpp.

◆ owns_

template<typename Number , typename Index = int>
bool pops::Raster< Number, Index >::owns_
protected

Definition at line 104 of file raster.hpp.

◆ rows_

template<typename Number , typename Index = int>
Index pops::Raster< Number, Index >::rows_
protected

Definition at line 100 of file raster.hpp.


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