|
ug4
|
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 | |
| void | create () |
| creates the raster. Call this method after 'set_num_nodes' has been called for each dimension. | |
| int | dim () const |
| const Coordinate & | extension () const |
| returns the extension of the raster | |
| number | extension (int dim) const |
| returns the extension of the raster for the given dimension | |
| T | interpolate (const Coordinate &coord, int order) const |
| interpolates the value with the given order at the given coordinate | |
| T | interpolate_at_cursor (int order) const |
| interpolates the value with the given order at the cursor position | |
| void | load_from_asc (const char *filename) |
| const Coordinate & | min_corner () const |
| returns the min-corner of the raster | |
| number | min_corner (int dim) const |
| returns the coordinate of the min-corner of the raster for the given dimension | |
| T | no_data_value () const |
| returns the value that shall be considered 'no-data-value' | |
| T & | node_value (const MultiIndex &mi) |
| returns the value at the given multi-index (read/write) | |
| T | node_value (const MultiIndex &mi) const |
| returns the value at the given multi-index (read only) | |
| const MultiIndex & | num_nodes () const |
| returns the number of nodes for each dimension in a multi-index. | |
| size_t | num_nodes (int dim) const |
| returns the number of nodes in the specified dimension | |
| size_t | num_nodes_total () const |
| returns the total number of nodes in the raster | |
| Raster & | operator= (const Raster &raster) |
| Raster () | |
| Creates an empty raster that has to be initialized before use. | |
| Raster (const MultiIndex &numNodes) | |
| Creates a new raster with the specified number of nodes. | |
| 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. | |
| Raster (const Raster &raster) | |
| Creates the new raster by copying the contents of the given raster. | |
| template<class TKernel > | |
| TKernel::result_t | run_on_all () |
| Creates and runs the specified kernel on all nodes and returns its result. | |
| template<class TKernel > | |
| void | run_on_all (TKernel &kernel) |
| Runs the specified kernel on all nodes. | |
| template<class TKernel > | |
| TKernel::result_t | run_on_nbrs (const MultiIndex ¢er) |
| Creates and runs the specified kernel on all direct neighbors of a node and returns its result. | |
| template<class TKernel > | |
| void | run_on_nbrs (const MultiIndex ¢er, TKernel &kernel) |
| Runs the specified kernel on all direct neighbors of a node. | |
| void | save_to_asc (const char *filename) const |
| T | selected_node_value () const |
| returns the value of the selected node | |
| void | set_no_data_value (T val) |
| sets the value that shall be considered as 'no-data-value' | |
| 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. | |
| void | set_selected_node_value (T val) |
| sets the value of the selected node | |
| ~Raster () | |
| void | set_min_corner (int dim, number coord) |
| sets the min corner of the raster. Used for interpolation at cursor. | |
| void | set_min_corner (const Coordinate &coord) |
| sets the min corner of the raster. Used for interpolation at cursor. | |
| void | set_extension (int dim, number ext) |
| sets the extension of the raster. Used for interpolation at cursor. | |
| void | set_extension (const Coordinate &coord) |
| sets the extension of the raster. Used for interpolation at cursor. | |
| void | select_node (int dim, size_t index) |
| Select a node. 'selected_node_value' provides read/write access to the selected node. | |
| void | select_node (const MultiIndex &mi) |
| Select a node. 'selected_node_value' provides read/write access to the selected node. | |
| void | set_cursor (int dim, number coord) |
| Set the coordinate of the cursor. The cursor can be used to interpolate values. | |
| void | set_cursor (const Coordinate &coord) |
| Set the coordinate of the cursor. The cursor can be used to interpolate values. | |
Private Member Functions | |
| size_t | data_index (const MultiIndex &mi, int curDim=TDIM - 1, size_t curVal=0) const |
| T | 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 ¢er, 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 |
| T | m_noDataValue |
| MultiIndex | m_numNodes |
| size_t | m_numNodesTotal |
| MultiIndex | m_selNode |
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.
| T | The template parameter 'T' specifies the underlying data-type. It has to support the following operations, if 'interpolate' shall be used:
|
| 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.
| ug::Raster< T, TDIM >::Raster | ( | const Raster< T, TDIM > & | raster | ) |
Creates the new raster by copying the contents of the given raster.
| 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'.
| 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.
| ug::Raster< T, TDIM >::~Raster | ( | ) |
References ug::Raster< T, TDIM >::m_data.
| void ug::Raster< T, TDIM >::blur | ( | T | alpha, |
| size_t | iterations | ||
| ) |
blurs (smoothens) the values by repeatedly averaging between direct neighbors
References ug::Raster< T, TDIM >::run_on_all().
| void ug::Raster< T, TDIM >::create | ( | ) |
creates the raster. Call this method after 'set_num_nodes' has been called for each dimension.
References ug::Raster< T, TDIM >::m_data, ug::Raster< T, TDIM >::num_nodes_total(), and ug::Raster< T, TDIM >::update_num_nodes_total().
Referenced by ug::Raster< T, TDIM >::load_from_asc(), ug::Raster< T, TDIM >::operator=(), and ug::Raster< number, dim - 1 >::run_on_all().
|
private |
| int ug::Raster< T, TDIM >::dim | ( | ) | const |
Referenced by ug::Raster< T, TDIM >::extension(), ug::Raster< T, TDIM >::min_corner(), ug::Raster< T, TDIM >::select_node(), ug::Raster< number, dim - 1 >::selected_node_value(), ug::Raster< T, TDIM >::set_cursor(), ug::Raster< T, TDIM >::set_extension(), ug::Raster< T, TDIM >::set_min_corner(), and ug::Raster< T, TDIM >::update_cell_extension().
| const Raster< T, TDIM >::Coordinate & ug::Raster< T, TDIM >::extension | ( | ) | const |
returns the extension of the raster
References ug::Raster< T, TDIM >::m_extension.
Referenced by ug::Raster< T, TDIM >::load_from_asc().
| number ug::Raster< T, TDIM >::extension | ( | int | dim | ) | const |
returns the extension of the raster for the given dimension
References ug::Raster< T, TDIM >::dim(), and ug::Raster< T, TDIM >::m_extension.
| 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::Raster< T, TDIM >::interpolate_linear(), ug::Raster< T, TDIM >::m_cellExtension, ug::Raster< T, TDIM >::m_minCorner, ug::Raster< T, TDIM >::m_noDataValue, ug::Raster< T, TDIM >::node_value(), ug::Raster< T, TDIM >::num_nodes(), and UG_THROW.
Referenced by ug::Raster< T, TDIM >::interpolate_at_cursor().
| T ug::Raster< T, TDIM >::interpolate_at_cursor | ( | int | order | ) | const |
interpolates the value with the given order at the cursor position
References ug::Raster< T, TDIM >::interpolate(), and ug::Raster< T, TDIM >::m_cursor.
|
private |
References ug::Raster< T, TDIM >::interpolate_linear(), and ug::Raster< T, TDIM >::node_value().
Referenced by ug::Raster< T, TDIM >::interpolate(), and ug::Raster< T, TDIM >::interpolate_linear().
| void ug::Raster< T, TDIM >::load_from_asc | ( | const char * | filename | ) |
References ug::Raster< T, TDIM >::create(), ug::Raster< T, TDIM >::extension(), ug::FindFileInStandardPaths(), LFA_CHECK_DIM, LFA_ERR_WHERE, ug::Raster< T, TDIM >::m_data, ug::Raster< T, TDIM >::m_numNodes, name, ug::Raster< T, TDIM >::set_extension(), ug::Raster< T, TDIM >::set_min_corner(), ug::Raster< T, TDIM >::set_no_data_value(), ug::Raster< T, TDIM >::set_num_nodes(), ug::ToLower(), UG_COND_THROW, and UG_THROW.
| const Raster< T, TDIM >::Coordinate & ug::Raster< T, TDIM >::min_corner | ( | ) | const |
returns the min-corner of the raster
References ug::Raster< T, TDIM >::m_minCorner.
Referenced by ug::Raster< T, TDIM >::save_to_asc().
| 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 ug::Raster< T, TDIM >::dim(), and ug::Raster< T, TDIM >::m_minCorner.
| T ug::Raster< T, TDIM >::no_data_value | ( | ) | const |
returns the value that shall be considered 'no-data-value'
References ug::Raster< T, TDIM >::m_noDataValue.
Referenced by ug::raster_kernels::Count< T, TDIM >::operator()(), ug::raster_kernels::Sum< T, TDIM >::operator()(), ug::raster_kernels::Blur< T, TDIM >::operator()(), and ug::Raster< T, TDIM >::save_to_asc().
| T & ug::Raster< T, TDIM >::node_value | ( | const MultiIndex & | mi | ) |
returns the value at the given multi-index (read/write)
References ug::Raster< T, TDIM >::data_index(), and ug::Raster< T, TDIM >::m_data.
Referenced by ug::Raster< T, TDIM >::interpolate(), ug::Raster< T, TDIM >::interpolate_linear(), ug::raster_kernels::Count< T, TDIM >::operator()(), ug::raster_kernels::Sum< T, TDIM >::operator()(), ug::raster_kernels::Blur< T, TDIM >::operator()(), ug::Raster< T, TDIM >::selected_node_value(), and ug::Raster< T, TDIM >::set_selected_node_value().
| T ug::Raster< T, TDIM >::node_value | ( | const MultiIndex & | mi | ) | const |
returns the value at the given multi-index (read only)
References ug::Raster< T, TDIM >::data_index(), and ug::Raster< T, TDIM >::m_data.
| const Raster< T, TDIM >::MultiIndex & ug::Raster< T, TDIM >::num_nodes | ( | ) | const |
returns the number of nodes for each dimension in a multi-index.
References ug::Raster< T, TDIM >::m_numNodes.
Referenced by ug::Raster< T, TDIM >::interpolate(), ug::Raster< T, TDIM >::run_on_all(), ug::Raster< T, TDIM >::run_on_nbrs(), ug::Raster< T, TDIM >::save_to_asc(), and ug::Raster< T, TDIM >::update_num_nodes_total().
| size_t ug::Raster< T, TDIM >::num_nodes | ( | int | dim | ) | const |
returns the number of nodes in the specified dimension
| size_t ug::Raster< T, TDIM >::num_nodes_total | ( | ) | const |
returns the total number of nodes in the raster
Referenced by ug::Raster< T, TDIM >::create().
| Raster< T, TDIM > & ug::Raster< T, TDIM >::operator= | ( | const Raster< T, TDIM > & | raster | ) |
References ug::Raster< T, TDIM >::create(), ug::Raster< T, TDIM >::m_cursor, ug::Raster< T, TDIM >::m_extension, ug::Raster< T, TDIM >::m_minCorner, ug::Raster< T, TDIM >::m_noDataValue, ug::Raster< T, TDIM >::m_numNodes, ug::Raster< T, TDIM >::m_selNode, ug::Raster< T, TDIM >::update_cell_extension(), and ug::Raster< T, TDIM >::update_num_nodes_total().
| 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
References ug::Raster< T, TDIM >::run_on_all().
Referenced by ug::Raster< T, TDIM >::blur(), ug::Raster< T, TDIM >::run_on_all(), ug::Raster< T, TDIM >::run_on_all(), and ug::Raster< T, TDIM >::run_on_all().
|
private |
References ug::Raster< T, TDIM >::num_nodes(), and ug::Raster< T, TDIM >::run_on_all().
| 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:
or
References ug::Raster< T, TDIM >::run_on_all().
| 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
References ug::Raster< T, TDIM >::run_on_nbrs().
Referenced by ug::Raster< T, TDIM >::run_on_nbrs(), ug::Raster< T, TDIM >::run_on_nbrs(), and ug::Raster< T, TDIM >::run_on_nbrs().
| 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:
or
References ug::Raster< T, TDIM >::run_on_nbrs().
|
private |
References ug::Raster< T, TDIM >::num_nodes(), and ug::Raster< T, TDIM >::run_on_nbrs().
| void ug::Raster< T, TDIM >::save_to_asc | ( | const char * | filename | ) | const |
| void ug::Raster< T, TDIM >::select_node | ( | const MultiIndex & | mi | ) |
Select a node. 'selected_node_value' provides read/write access to the selected node.
References ug::Raster< T, TDIM >::m_selNode.
| 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 ug::Raster< T, TDIM >::dim(), and ug::Raster< T, TDIM >::m_selNode.
| T ug::Raster< T, TDIM >::selected_node_value | ( | ) | const |
returns the value of the selected node
References ug::Raster< T, TDIM >::m_selNode, and ug::Raster< T, TDIM >::node_value().
| void ug::Raster< T, TDIM >::set_cursor | ( | const Coordinate & | coord | ) |
Set the coordinate of the cursor. The cursor can be used to interpolate values.
References ug::Raster< T, TDIM >::m_cursor.
| 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 ug::Raster< T, TDIM >::dim(), and ug::Raster< T, TDIM >::m_cursor.
| void ug::Raster< T, TDIM >::set_extension | ( | const Coordinate & | coord | ) |
sets the extension of the raster. Used for interpolation at cursor.
References ug::Raster< T, TDIM >::m_extension, and ug::Raster< T, TDIM >::update_cell_extension().
| void ug::Raster< T, TDIM >::set_extension | ( | int | dim, |
| number | ext | ||
| ) |
sets the extension of the raster. Used for interpolation at cursor.
References ug::Raster< T, TDIM >::dim(), ug::Raster< T, TDIM >::m_extension, and ug::Raster< T, TDIM >::update_cell_extension().
Referenced by ug::Raster< T, TDIM >::load_from_asc().
| void ug::Raster< T, TDIM >::set_min_corner | ( | const Coordinate & | coord | ) |
sets the min corner of the raster. Used for interpolation at cursor.
References ug::Raster< T, TDIM >::m_minCorner.
| 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 ug::Raster< T, TDIM >::dim(), and ug::Raster< T, TDIM >::m_minCorner.
Referenced by ug::Raster< T, TDIM >::load_from_asc().
| void ug::Raster< T, TDIM >::set_no_data_value | ( | T | val | ) |
sets the value that shall be considered as 'no-data-value'
References ug::Raster< T, TDIM >::m_noDataValue.
Referenced by ug::Raster< T, TDIM >::load_from_asc().
| void ug::Raster< T, TDIM >::set_num_nodes | ( | const MultiIndex & | mi | ) |
| 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.
Referenced by ug::Raster< T, TDIM >::load_from_asc().
| void ug::Raster< T, TDIM >::set_selected_node_value | ( | T | val | ) |
sets the value of the selected node
References ug::Raster< T, TDIM >::m_selNode, and ug::Raster< T, TDIM >::node_value().
|
private |
References ug::Raster< T, TDIM >::update_cell_extension().
Referenced by ug::Raster< number, dim - 1 >::blur(), ug::Raster< T, TDIM >::operator=(), ug::Raster< number, dim - 1 >::run_on_all(), ug::Raster< T, TDIM >::set_extension(), ug::Raster< T, TDIM >::set_extension(), and ug::Raster< T, TDIM >::update_cell_extension().
|
private |
|
private |
References ug::Raster< T, TDIM >::m_numNodesTotal, and ug::Raster< T, TDIM >::num_nodes().
Referenced by ug::Raster< number, dim - 1 >::blur(), ug::Raster< T, TDIM >::create(), ug::Raster< number, dim - 1 >::extension(), ug::Raster< number, dim - 1 >::interpolate_at_cursor(), ug::Raster< T, TDIM >::operator=(), ug::Raster< number, dim - 1 >::run_on_all(), and ug::Raster< number, dim - 1 >::selected_node_value().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Referenced by ug::Raster< T, TDIM >::data_index(), ug::Raster< number, dim - 1 >::interpolate_at_cursor(), ug::Raster< T, TDIM >::load_from_asc(), ug::Raster< T, TDIM >::num_nodes(), ug::Raster< T, TDIM >::operator=(), ug::Raster< number, dim - 1 >::selected_node_value(), and ug::Raster< T, TDIM >::update_cell_extension().
|
private |
|
private |