ug4
ug::Raster< T, TDIM > Class Template Reference

Generic raster for arbitrary dimensions. More...

#include <raster.h>

Classes

class  Coordinate
 
class  MultiIndex
 

Public Member Functions

void blur (T alpha, size_t iterations)
 blurs (smoothens) the values by repeatedly averaging between direct neighbors More...
 
void create ()
 creates the raster. Call this method after 'set_num_nodes' has been called for each dimension. More...
 
int dim () const
 
const Coordinateextension () const
 returns the extension of the raster More...
 
number extension (int dim) const
 returns the extension of the raster for the given dimension More...
 
interpolate (const Coordinate &coord, int order) const
 interpolates the value with the given order at the given coordinate More...
 
interpolate_at_cursor (int order) const
 interpolates the value with the given order at the cursor position More...
 
void load_from_asc (const char *filename)
 
const Coordinatemin_corner () const
 returns the min-corner of the raster More...
 
number min_corner (int dim) const
 returns the coordinate of the min-corner of the raster for the given dimension More...
 
no_data_value () const
 returns the value that shall be considered 'no-data-value' More...
 
T & node_value (const MultiIndex &mi)
 returns the value at the given multi-index (read/write) More...
 
node_value (const MultiIndex &mi) const
 returns the value at the given multi-index (read only) More...
 
const MultiIndexnum_nodes () const
 returns the number of nodes for each dimension in a multi-index. More...
 
size_t num_nodes (int dim) const
 returns the number of nodes in the specified dimension More...
 
size_t num_nodes_total () const
 returns the total number of nodes in the raster More...
 
Rasteroperator= (const Raster &raster)
 
 Raster ()
 Creates an empty raster that has to be initialized before use. More...
 
 Raster (const MultiIndex &numNodes)
 Creates a new raster with the specified number of nodes. More...
 
 Raster (const MultiIndex &numNodes, const Coordinate &extension, const Coordinate &minCorner=Coordinate(0))
 Creates a new raster with the specified number of nodes and the specified extension. More...
 
 Raster (const Raster &raster)
 Creates the new raster by copying the contents of the given raster. More...
 
template<class TKernel >
TKernel::result_t run_on_all ()
 Creates and runs the specified kernel on all nodes and returns its result. More...
 
template<class TKernel >
void run_on_all (TKernel &kernel)
 Runs the specified kernel on all nodes. More...
 
template<class TKernel >
TKernel::result_t run_on_nbrs (const MultiIndex &center)
 Creates and runs the specified kernel on all direct neighbors of a node and returns its result. More...
 
template<class TKernel >
void run_on_nbrs (const MultiIndex &center, TKernel &kernel)
 Runs the specified kernel on all direct neighbors of a node. More...
 
void save_to_asc (const char *filename) const
 
selected_node_value () const
 returns the value of the selected node More...
 
void set_no_data_value (T val)
 sets the value that shall be considered as 'no-data-value' More...
 
void set_num_nodes (const MultiIndex &mi)
 
void set_num_nodes (int dim, size_t num)
 sets the number of nodes that shall be used by the raster. More...
 
void set_selected_node_value (T val)
 sets the value of the selected node More...
 
 ~Raster ()
 
void set_min_corner (int dim, number coord)
 sets the min corner of the raster. Used for interpolation at cursor. More...
 
void set_min_corner (const Coordinate &coord)
 sets the min corner of the raster. Used for interpolation at cursor. More...
 
void set_extension (int dim, number ext)
 sets the extension of the raster. Used for interpolation at cursor. More...
 
void set_extension (const Coordinate &coord)
 sets the extension of the raster. Used for interpolation at cursor. More...
 
void select_node (int dim, size_t index)
 Select a node. 'selected_node_value' provides read/write access to the selected node. More...
 
void select_node (const MultiIndex &mi)
 Select a node. 'selected_node_value' provides read/write access to the selected node. More...
 
void set_cursor (int dim, number coord)
 Set the coordinate of the cursor. The cursor can be used to interpolate values. More...
 
void set_cursor (const Coordinate &coord)
 Set the coordinate of the cursor. The cursor can be used to interpolate values. More...
 

Private Member Functions

size_t data_index (const MultiIndex &mi, int curDim=TDIM - 1, size_t curVal=0) const
 
interpolate_linear (const MultiIndex &minNodeInd, Coordinate &localCoord, int curDim=TDIM) const
 
template<class TKernel >
void run_on_all (const MultiIndex &start, TKernel &kernel, int curDim)
 
template<class TKernel >
void run_on_nbrs (const MultiIndex &center, TKernel &kernel, int curDim)
 
void update_cell_extension ()
 
void update_cell_extension (int dim)
 
void update_num_nodes_total ()
 

Private Attributes

Coordinate m_cellExtension
 
Coordinate m_cursor
 
T * m_data
 
Coordinate m_extension
 
Coordinate m_minCorner
 
m_noDataValue
 
MultiIndex m_numNodes
 
size_t m_numNodesTotal
 
MultiIndex m_selNode
 

Detailed Description

template<class T, int TDIM>
class ug::Raster< T, TDIM >

Generic raster for arbitrary dimensions.

The raster provides access to raster-data in arbitrary dimensions. Common use cases are e.g. 1d/2d/3d image data or density distributions.

A raster consists of regularily distributed nodes, which form a structured d-dimensional grid. The space in between those nodes can be interpreted as cells. Through 'min_corner' and 'extension' the spacial properties of the raster are defined. A point in d-dimensional space can thus be mapped to a cell in the raster. This is, e.g., used for interpolation algorithms.

Values are stored in nodes. Direct access to the data in such nodes is provided as well as interpolation algorithms that provide values at arbitrary points in d-dimensional space.

To ease usage, e.g., in scripting languages, the raster provides a 'selected_node' and a 'cursor'. The first is an index to a currently selected node, the latter is a point in space at which interpolation can be performed. The usage of both is of course optional. The value of the selected_node can be accessed through 'selected_node_value'. The value at the cursor can be interpolated through 'interpolate_at_cursor'. Please note, that the more flexible methods 'node_value(MultiIndex)' and 'interpolate(Coordinate)' are recommended for most use cases.

Parameters
TThe template parameter 'T' specifies the underlying data-type. It has to support the following operations, if 'interpolate' shall be used:
  • T& operator += (const T&)
  • T& operator -= (const T&)
  • T& operator *= (number) It furthermore has to support std::numeric_limits<T>::max()

Constructor & Destructor Documentation

◆ Raster() [1/4]

template<class T , int TDIM>
ug::Raster< T, TDIM >::Raster

Creates an empty raster that has to be initialized before use.

Use the methods 'load_from_asc' or instead 'set_num_nodes', 'create', 'set_extension', and 'set_min_corner' to initialize the raster.

References ug::Raster< T, TDIM >::update_cell_extension(), and ug::Raster< T, TDIM >::update_num_nodes_total().

◆ Raster() [2/4]

template<class T , int TDIM>
ug::Raster< T, TDIM >::Raster ( const Raster< T, TDIM > &  raster)

◆ Raster() [3/4]

template<class T , int TDIM>
ug::Raster< T, TDIM >::Raster ( const MultiIndex numNodes)

Creates a new raster with the specified number of nodes.

Internally calls 'set_num_nodes' and 'create'. The ruster can thus be used right after construction. The extension is chosen to be numNodes[d]-1 in each dimension, i.e., the distance between neighbored nodes is '1' by default. The min-corner is at the origin. You may change those through 'set_extension' and 'set_min_corner'.

References ug::Raster< T, TDIM >::create(), ug::Raster< T, TDIM >::m_extension, ug::Raster< T, TDIM >::update_cell_extension(), and ug::Raster< T, TDIM >::update_num_nodes_total().

◆ Raster() [4/4]

template<class T , int TDIM>
ug::Raster< T, TDIM >::Raster ( const MultiIndex numNodes,
const Coordinate extension,
const Coordinate minCorner = Coordinate(0) 
)

Creates a new raster with the specified number of nodes and the specified extension.

Internally calls 'set_num_nodes', 'create', 'set_extension', and 'set_min_corner. 'minCorner' is optional and defaults to the origin.

References ug::Raster< T, TDIM >::create(), ug::Raster< T, TDIM >::update_cell_extension(), and ug::Raster< T, TDIM >::update_num_nodes_total().

◆ ~Raster()

template<class T , int TDIM>
ug::Raster< T, TDIM >::~Raster

Member Function Documentation

◆ blur()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::blur ( alpha,
size_t  iterations 
)

blurs (smoothens) the values by repeatedly averaging between direct neighbors

References alpha.

◆ create()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::create

creates the raster. Call this method after 'set_num_nodes' has been called for each dimension.

Referenced by ug::Raster< T, TDIM >::Raster().

◆ data_index()

template<class T , int TDIM>
size_t ug::Raster< T, TDIM >::data_index ( const MultiIndex mi,
int  curDim = TDIM - 1,
size_t  curVal = 0 
) const
private

◆ dim()

template<class T , int TDIM>
int ug::Raster< T, TDIM >::dim

◆ extension() [1/2]

template<class T , int TDIM>
const Raster< T, TDIM >::Coordinate & ug::Raster< T, TDIM >::extension

returns the extension of the raster

◆ extension() [2/2]

template<class T , int TDIM>
number ug::Raster< T, TDIM >::extension ( int  dim) const

returns the extension of the raster for the given dimension

References dim.

◆ interpolate()

template<class T , int TDIM>
T ug::Raster< T, TDIM >::interpolate ( const Coordinate coord,
int  order 
) const

interpolates the value with the given order at the given coordinate

References UG_THROW.

◆ interpolate_at_cursor()

template<class T , int TDIM>
T ug::Raster< T, TDIM >::interpolate_at_cursor ( int  order) const

interpolates the value with the given order at the cursor position

◆ interpolate_linear()

template<class T , int TDIM>
T ug::Raster< T, TDIM >::interpolate_linear ( const MultiIndex minNodeInd,
Coordinate localCoord,
int  curDim = TDIM 
) const
private

◆ load_from_asc()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::load_from_asc ( const char *  filename)

◆ min_corner() [1/2]

template<class T , int TDIM>
const Raster< T, TDIM >::Coordinate & ug::Raster< T, TDIM >::min_corner

returns the min-corner of the raster

◆ min_corner() [2/2]

template<class T , int TDIM>
number ug::Raster< T, TDIM >::min_corner ( int  dim) const

returns the coordinate of the min-corner of the raster for the given dimension

References dim.

◆ no_data_value()

template<class T , int TDIM>
T ug::Raster< T, TDIM >::no_data_value

◆ node_value() [1/2]

template<class T , int TDIM>
T & ug::Raster< T, TDIM >::node_value ( const MultiIndex mi)

◆ node_value() [2/2]

template<class T , int TDIM>
T ug::Raster< T, TDIM >::node_value ( const MultiIndex mi) const

returns the value at the given multi-index (read only)

◆ num_nodes() [1/2]

template<class T , int TDIM>
const Raster< T, TDIM >::MultiIndex & ug::Raster< T, TDIM >::num_nodes

returns the number of nodes for each dimension in a multi-index.

◆ num_nodes() [2/2]

template<class T , int TDIM>
size_t ug::Raster< T, TDIM >::num_nodes ( int  dim) const

returns the number of nodes in the specified dimension

References dim.

◆ num_nodes_total()

template<class T , int TDIM>
size_t ug::Raster< T, TDIM >::num_nodes_total

returns the total number of nodes in the raster

Referenced by ug::Raster< T, TDIM >::Raster().

◆ operator=()

◆ run_on_all() [1/3]

template<class T , int TDIM>
template<class TKernel >
TKernel::result_t ug::Raster< T, TDIM >::run_on_all

Creates and runs the specified kernel on all nodes and returns its result.

The class TKernel has to feature a default constructor, a typedef 'result_t', and a method 'result_t result() const'.

Like all kernels, it furthermore has to specify a method

void operator () (Raster<T, TDIM>& raster,
const typename Raster<T, TDIM>::MultiIndex& cur);
value_type & operator()(size_t r, size_t c)

◆ run_on_all() [2/3]

template<class T , int TDIM>
template<class TKernel >
void ug::Raster< T, TDIM >::run_on_all ( const MultiIndex start,
TKernel &  kernel,
int  curDim 
)
private

◆ run_on_all() [3/3]

template<class T , int TDIM>
template<class TKernel >
void ug::Raster< T, TDIM >::run_on_all ( TKernel &  kernel)

Runs the specified kernel on all nodes.

TKernel can either be a function or a class with an 'operator()'. The signature should be as follows:

void Func (Raster<T, TDIM>& raster,
const typename Raster<T, TDIM>::MultiIndex& cur);

or

void operator () (Raster<T, TDIM>& raster,
const typename Raster<T, TDIM>::MultiIndex& cur);

◆ run_on_nbrs() [1/3]

template<class T , int TDIM>
template<class TKernel >
TKernel::result_t ug::Raster< T, TDIM >::run_on_nbrs ( const MultiIndex center)

Creates and runs the specified kernel on all direct neighbors of a node and returns its result.

The class TKernel has to feature a default constructor, a typedef 'result_t', and a method 'result_t result() const'.

Like all kernels, it furthermore has to specify a method

void operator () (Raster<T, TDIM>& raster,
const typename Raster<T, TDIM>::MultiIndex& cur);

◆ run_on_nbrs() [2/3]

template<class T , int TDIM>
template<class TKernel >
void ug::Raster< T, TDIM >::run_on_nbrs ( const MultiIndex center,
TKernel &  kernel 
)

Runs the specified kernel on all direct neighbors of a node.

TKernel can either be a function or a class with an 'operator()'. The signature should be as follows:

void Func (Raster<T, TDIM>& raster,
const typename Raster<T, TDIM>::MultiIndex& cur);

or

void operator () (Raster<T, TDIM>& raster,
const typename Raster<T, TDIM>::MultiIndex& cur);

◆ run_on_nbrs() [3/3]

template<class T , int TDIM>
template<class TKernel >
void ug::Raster< T, TDIM >::run_on_nbrs ( const MultiIndex center,
TKernel &  kernel,
int  curDim 
)
private

◆ save_to_asc()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::save_to_asc ( const char *  filename) const

References STA_ERR_WHERE, and UG_COND_THROW.

◆ select_node() [1/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::select_node ( const MultiIndex mi)

Select a node. 'selected_node_value' provides read/write access to the selected node.

◆ select_node() [2/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::select_node ( int  dim,
size_t  index 
)

Select a node. 'selected_node_value' provides read/write access to the selected node.

References dim.

◆ selected_node_value()

template<class T , int TDIM>
T ug::Raster< T, TDIM >::selected_node_value

returns the value of the selected node

◆ set_cursor() [1/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_cursor ( const Coordinate coord)

Set the coordinate of the cursor. The cursor can be used to interpolate values.

◆ set_cursor() [2/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_cursor ( int  dim,
number  coord 
)

Set the coordinate of the cursor. The cursor can be used to interpolate values.

References dim.

◆ set_extension() [1/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_extension ( const Coordinate coord)

sets the extension of the raster. Used for interpolation at cursor.

◆ set_extension() [2/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_extension ( int  dim,
number  ext 
)

sets the extension of the raster. Used for interpolation at cursor.

References dim.

◆ set_min_corner() [1/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_min_corner ( const Coordinate coord)

sets the min corner of the raster. Used for interpolation at cursor.

◆ set_min_corner() [2/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_min_corner ( int  dim,
number  coord 
)

sets the min corner of the raster. Used for interpolation at cursor.

References dim.

◆ set_no_data_value()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_no_data_value ( val)

sets the value that shall be considered as 'no-data-value'

◆ set_num_nodes() [1/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_num_nodes ( const MultiIndex mi)

◆ set_num_nodes() [2/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_num_nodes ( int  dim,
size_t  num 
)

sets the number of nodes that shall be used by the raster.

At least one node is required per dimension. After having set all node-numbers, one should call 'create' to actually create the grid.

References dim.

◆ set_selected_node_value()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::set_selected_node_value ( val)

sets the value of the selected node

◆ update_cell_extension() [1/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::update_cell_extension
private

◆ update_cell_extension() [2/2]

template<class T , int TDIM>
void ug::Raster< T, TDIM >::update_cell_extension ( int  dim)
private

References dim.

◆ update_num_nodes_total()

template<class T , int TDIM>
void ug::Raster< T, TDIM >::update_num_nodes_total
private

Member Data Documentation

◆ m_cellExtension

template<class T , int TDIM>
Coordinate ug::Raster< T, TDIM >::m_cellExtension
private

◆ m_cursor

template<class T , int TDIM>
Coordinate ug::Raster< T, TDIM >::m_cursor
private

◆ m_data

template<class T , int TDIM>
T* ug::Raster< T, TDIM >::m_data
private

◆ m_extension

template<class T , int TDIM>
Coordinate ug::Raster< T, TDIM >::m_extension
private

◆ m_minCorner

template<class T , int TDIM>
Coordinate ug::Raster< T, TDIM >::m_minCorner
private

◆ m_noDataValue

template<class T , int TDIM>
T ug::Raster< T, TDIM >::m_noDataValue
private

◆ m_numNodes

template<class T , int TDIM>
MultiIndex ug::Raster< T, TDIM >::m_numNodes
private

◆ m_numNodesTotal

template<class T , int TDIM>
size_t ug::Raster< T, TDIM >::m_numNodesTotal
private

◆ m_selNode

template<class T , int TDIM>
MultiIndex ug::Raster< T, TDIM >::m_selNode
private

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