iLand
Public Member Functions | List of all members
Grid< T > Class Template Reference

Grid class (template). More...

#include <grid.h>

Public Member Functions

 Grid ()
 
 Grid (float cellsize, int sizex, int sizey)
 
 Grid (const QRectF rect_metric, const float cellsize)
 create from a metric rect More...
 
bool loadGridFromFile (const QString &fileName)
 load a grid from an ASCII grid file the coordinates and cell size remain as in the grid file. More...
 
 Grid (const Grid< T > &toCopy)
 
 ~Grid ()
 
void clear ()
 
bool setup (const float cellsize, const int sizex, const int sizey)
 
bool setup (const QRectF &rect, const double cellsize)
 
bool setup (const Grid< T > &source)
 
void initialize (const T &value)
 
void wipe ()
 write 0-bytes with memcpy to the whole area More...
 
void wipe (const T value)
 overwrite the whole area with "value" size of T must be the size of "int" ERRORNOUS!!! More...
 
void copy (const Grid< T > &source)
 copies the content of the source grid to this grid. More...
 
Grid< double > * toDouble () const
 create a double grid (same size as this grid) and convert this grid to double values. More...
 
int sizeX () const
 
int sizeY () const
 
float metricSizeX () const
 
float metricSizeY () const
 
QRectF metricRect () const
 get the metric rectangle of the grid More...
 
void setMetricRect (QRectF rect)
 set the metric rectangle. Use with care! No further checks are executed! More...
 
QRect rectangle () const
 get the rectangle of the grid in terms of indices More...
 
float cellsize () const
 get the length of one pixel of the grid More...
 
int count () const
 returns the number of elements of the grid More...
 
bool isEmpty () const
 returns false if the grid was not setup More...
 
const T & operator() (const int ix, const int iy) const
 access (const) with index variables. use int. More...
 
const T & operator() (const float x, const float y) const
 access (const) using metric variables. use float. More...
 
const T & operator[] (const QPoint &p) const
 access value of grid with a QPoint More...
 
T & operator[] (const int idx) const
 use the square brackets to access by index More...
 
T & operator[] (const QPointF &p)
 use the square bracket to access by QPointF More...
 
T & operator[] (const QPoint &p)
 use the square bracket to access by QPoint More...
 
T & valueAtIndex (const QPoint &pos)
 value at position defined by a QPoint defining the two indices (x,y) More...
 
T & valueAtIndex (const int ix, const int iy)
 const value at position defined by indices (x,y) More...
 
T & valueAtIndex (const int index)
 get a ref ot value at (one-dimensional) index 'index'. More...
 
int index (const int ix, const int iy)
 get the 0-based index of the cell with indices ix and iy. More...
 
int index (const QPoint &pos)
 get the 0-based index of the cell at 'pos'. More...
 
const T & constValueAtIndex (const QPoint &pos) const
 value at position defined by a (integer) QPoint More...
 
const T & constValueAtIndex (const int ix, const int iy) const
 value at position defined by a pair of integer coordinates More...
 
const T & constValueAtIndex (const int index) const
 value at position defined by the index within the grid More...
 
T & valueAt (const QPointF &posf)
 value at position defined by metric coordinates (QPointF) More...
 
const T & constValueAt (const QPointF &posf) const
 value at position defined by metric coordinates (QPointF) More...
 
T & valueAt (const float x, const float y)
 value at position defined by metric coordinates (x,y) More...
 
const T & constValueAt (const float x, const float y) const
 value at position defined by metric coordinates (x,y) More...
 
bool coordValid (const float x, const float y) const
 
bool coordValid (const QPointF &pos) const
 
QPoint indexAt (const QPointF &pos) const
 get index of value at position pos (metric) More...
 
QPoint indexOf (const int index) const
 get index (x/y) of the (linear) index 'index' (0..count-1) More...
 
bool isIndexValid (const QPoint &pos) const
 return true, if position is within the grid More...
 
bool isIndexValid (const int x, const int y) const
 return true, if index is within the grid More...
 
int index2 (int idx) const
 returns the index of an aligned grid (with the same size and matching origin) with the double cell size (e.g. to scale from a 10m grid to a 20m grid) More...
 
int index5 (int idx) const
 returns the index of an aligned grid (the same size) with the 5 times bigger cells (e.g. to scale from a 2m grid to a 10m grid) More...
 
int index10 (int idx) const
 returns the index of an aligned grid (the same size) with the 10 times bigger cells (e.g. to scale from a 2m grid to a 20m grid) More...
 
void validate (QPoint &pos) const
 force More...
 
QPointF cellCenterPoint (const QPoint &pos) const
 get the (metric) centerpoint of cell with index pos More...
 
QPointF cellCenterPoint (const int &index) const
 get the metric cell center point of the cell given by index 'index' More...
 
QPointF cellCenterPoint (T *ptr)
 get the metric cell center point of the cell given py the pointer More...
 
QRectF cellRect (const QPoint &pos) const
 get the metric rectangle of the cell with index @pos More...
 
T * begin () const
 get "iterator" pointer More...
 
T * end () const
 get iterator end-pointer More...
 
QPoint indexOf (const T *element) const
 retrieve index (x/y) of the pointer element. returns -1/-1 if element is not valid. More...
 
max () const
 retrieve the maximum value of a grid More...
 
min () const
 retrieve the minimum value of a grid More...
 
sum () const
 retrieve the sum of the grid More...
 
avg () const
 retrieve the average value of a grid More...
 
void add (const T &summand)
 
void multiply (const T &factor)
 
void limit (const T min_value, const T max_value)
 limit each cell value to (including) min_value and (including) max_value More...
 
Grid< T > averaged (const int factor, const int offsetx=0, const int offsety=0) const
 creates a grid with lower resolution and averaged cell values. More...
 
Grid< T > normalized (const T targetvalue) const
 normalized returns a normalized grid, in a way that the sum() = More...
 
T * ptr (int x, int y)
 get a pointer to the element indexed by "x" and "y" More...
 
double distance (const QPoint &p1, const QPoint &p2)
 distance (metric) between p1 and p2 More...
 
const QPoint randomPosition () const
 returns a (valid) random position within the grid More...
 
int floodFill (QPoint start, T old_color, T color, int max_fill=-1)
 applies a flood fill algorithm to the grid starting at 'start' fills the contingent area with value 'old_color' with 'color' (or stops when 'max_fill' pixels have been filled) returns the number of filled pixels More...
 

Detailed Description

template<class T>
class Grid< T >

Grid class (template).

Orientation The grid is oriented as typically coordinates on the northern hemisphere: higher y-values -> north, higher x-values-> east. The projection is reversed for drawing on screen (Viewport). N (0/2) (1/2) (2/2) W (0/1) (1/1) (2/1) E (0/0) (1/0) (2/0) S

Constructor & Destructor Documentation

◆ Grid() [1/4]

template<class T >
Grid< T >::Grid

◆ Grid() [2/4]

template<class T >
Grid< T >::Grid ( float  cellsize,
int  sizex,
int  sizey 
)
inline

◆ Grid() [3/4]

template<class T >
Grid< T >::Grid ( const QRectF  rect_metric,
const float  cellsize 
)
inline

create from a metric rect

◆ Grid() [4/4]

template<class T >
Grid< T >::Grid ( const Grid< T > &  toCopy)

◆ ~Grid()

template<class T >
Grid< T >::~Grid ( )
inline

Member Function Documentation

◆ add()

template<class T >
void Grid< T >::add ( const T &  summand)

◆ averaged()

template<class T >
Grid< T > Grid< T >::averaged ( const int  factor,
const int  offsetx = 0,
const int  offsety = 0 
) const

creates a grid with lower resolution and averaged cell values.

Parameters
factorfactor by which grid size is reduced (e.g. 3 -> 3x3=9 pixels are averaged to 1 result pixel)
offsetx,offsetystart averaging with an offset from 0/0 (e.g.: x=1, y=2, factor=3: -> 1/2-3/4 -> 0/0)
Returns
Grid with size sizeX()/factor x sizeY()/factor

◆ avg()

template<class T >
T Grid< T >::avg

retrieve the average value of a grid

◆ begin()

template<class T >
T * Grid< T >::begin ( ) const
inline

get "iterator" pointer

◆ cellCenterPoint() [1/3]

template<class T >
QPointF Grid< T >::cellCenterPoint ( const int &  index) const
inline

get the metric cell center point of the cell given by index 'index'

◆ cellCenterPoint() [2/3]

template<class T >
QPointF Grid< T >::cellCenterPoint ( const QPoint &  pos) const
inline

get the (metric) centerpoint of cell with index pos

get metric coordinates of the cells center

◆ cellCenterPoint() [3/3]

template<class T >
QPointF Grid< T >::cellCenterPoint ( T *  ptr)
inline

get the metric cell center point of the cell given py the pointer

◆ cellRect()

template<class T >
QRectF Grid< T >::cellRect ( const QPoint &  pos) const
inline

get the metric rectangle of the cell with index @pos

return coordinates of rect given by

Parameters
pos.

◆ cellsize()

template<class T >
float Grid< T >::cellsize ( ) const
inline

get the length of one pixel of the grid

◆ clear()

template<class T >
void Grid< T >::clear ( )
inline

◆ constValueAt() [1/2]

template<class T >
const T & Grid< T >::constValueAt ( const float  x,
const float  y 
) const

value at position defined by metric coordinates (x,y)

◆ constValueAt() [2/2]

template<class T >
const T & Grid< T >::constValueAt ( const QPointF &  posf) const

value at position defined by metric coordinates (QPointF)

◆ constValueAtIndex() [1/3]

template<class T >
const T & Grid< T >::constValueAtIndex ( const int  index) const
inline

value at position defined by the index within the grid

get a ref ot value at (one-dimensional) index 'index'.

◆ constValueAtIndex() [2/3]

template<class T >
const T & Grid< T >::constValueAtIndex ( const int  ix,
const int  iy 
) const
inline

value at position defined by a pair of integer coordinates

◆ constValueAtIndex() [3/3]

template<class T >
const T & Grid< T >::constValueAtIndex ( const QPoint &  pos) const
inline

value at position defined by a (integer) QPoint

◆ coordValid() [1/2]

template<class T >
bool Grid< T >::coordValid ( const float  x,
const float  y 
) const
inline

◆ coordValid() [2/2]

template<class T >
bool Grid< T >::coordValid ( const QPointF &  pos) const
inline

◆ copy()

template<class T >
void Grid< T >::copy ( const Grid< T > &  source)
inline

copies the content of the source grid to this grid.

no operation, if the grids are not of the same size.

◆ count()

template<class T >
int Grid< T >::count ( ) const
inline

returns the number of elements of the grid

◆ distance()

template<class T >
double Grid< T >::distance ( const QPoint &  p1,
const QPoint &  p2 
)
inline

distance (metric) between p1 and p2

◆ end()

template<class T >
T * Grid< T >::end ( ) const
inline

get iterator end-pointer

◆ floodFill()

template<class T >
int Grid< T >::floodFill ( QPoint  start,
old_color,
color,
int  max_fill = -1 
)

applies a flood fill algorithm to the grid starting at 'start' fills the contingent area with value 'old_color' with 'color' (or stops when 'max_fill' pixels have been filled) returns the number of filled pixels

◆ index() [1/2]

template<class T >
int Grid< T >::index ( const int  ix,
const int  iy 
)
inline

get the 0-based index of the cell with indices ix and iy.

◆ index() [2/2]

template<class T >
int Grid< T >::index ( const QPoint &  pos)
inline

get the 0-based index of the cell at 'pos'.

◆ index10()

template<class T >
int Grid< T >::index10 ( int  idx) const
inline

returns the index of an aligned grid (the same size) with the 10 times bigger cells (e.g. to scale from a 2m grid to a 20m grid)

◆ index2()

template<class T >
int Grid< T >::index2 ( int  idx) const
inline

returns the index of an aligned grid (with the same size and matching origin) with the double cell size (e.g. to scale from a 10m grid to a 20m grid)

◆ index5()

template<class T >
int Grid< T >::index5 ( int  idx) const
inline

returns the index of an aligned grid (the same size) with the 5 times bigger cells (e.g. to scale from a 2m grid to a 10m grid)

◆ indexAt()

template<class T >
QPoint Grid< T >::indexAt ( const QPointF &  pos) const
inline

get index of value at position pos (metric)

◆ indexOf() [1/2]

template<class T >
QPoint Grid< T >::indexOf ( const int  index) const
inline

get index (x/y) of the (linear) index 'index' (0..count-1)

◆ indexOf() [2/2]

template<class T >
QPoint Grid< T >::indexOf ( const T *  element) const
inline

retrieve index (x/y) of the pointer element. returns -1/-1 if element is not valid.

retrieve from the index from an element reversely from a pointer to that element.

The internal memory layout is (for dimx=6, dimy=3): 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Note: north and south are reversed, thus the item with index 0 is located in the south-western edge of the grid!

◆ initialize()

template<class T >
void Grid< T >::initialize ( const T &  value)
inline

◆ isEmpty()

template<class T >
bool Grid< T >::isEmpty ( ) const
inline

returns false if the grid was not setup

◆ isIndexValid() [1/2]

template<class T >
bool Grid< T >::isIndexValid ( const int  x,
const int  y 
) const
inline

return true, if index is within the grid

◆ isIndexValid() [2/2]

template<class T >
bool Grid< T >::isIndexValid ( const QPoint &  pos) const
inline

return true, if position is within the grid

◆ limit()

template<class T >
void Grid< T >::limit ( const T  min_value,
const T  max_value 
)

limit each cell value to (including) min_value and (including) max_value

◆ loadGridFromFile()

template<class T >
bool Grid< T >::loadGridFromFile ( const QString &  fileName)

load a grid from an ASCII grid file the coordinates and cell size remain as in the grid file.

◆ max()

template<class T >
T Grid< T >::max

retrieve the maximum value of a grid

◆ metricRect()

template<class T >
QRectF Grid< T >::metricRect ( ) const
inline

get the metric rectangle of the grid

◆ metricSizeX()

template<class T >
float Grid< T >::metricSizeX ( ) const
inline

◆ metricSizeY()

template<class T >
float Grid< T >::metricSizeY ( ) const
inline

◆ min()

template<class T >
T Grid< T >::min

retrieve the minimum value of a grid

◆ multiply()

template<class T >
void Grid< T >::multiply ( const T &  factor)

◆ normalized()

template<class T >
Grid< T > Grid< T >::normalized ( const T  targetvalue) const

normalized returns a normalized grid, in a way that the sum() =

Parameters
targetvalue.if the grid is empty or the sum is 0, no modifications are performed.

◆ operator()() [1/2]

template<class T >
const T & Grid< T >::operator() ( const float  x,
const float  y 
) const
inline

access (const) using metric variables. use float.

◆ operator()() [2/2]

template<class T >
const T & Grid< T >::operator() ( const int  ix,
const int  iy 
) const
inline

access (const) with index variables. use int.

◆ operator[]() [1/4]

template<class T >
T & Grid< T >::operator[] ( const int  idx) const
inline

use the square brackets to access by index

◆ operator[]() [2/4]

template<class T >
T & Grid< T >::operator[] ( const QPoint &  p)
inline

use the square bracket to access by QPoint

◆ operator[]() [3/4]

template<class T >
const T & Grid< T >::operator[] ( const QPoint &  p) const
inline

access value of grid with a QPoint

◆ operator[]() [4/4]

template<class T >
T & Grid< T >::operator[] ( const QPointF &  p)
inline

use the square bracket to access by QPointF

◆ ptr()

template<class T >
T * Grid< T >::ptr ( int  x,
int  y 
)
inline

get a pointer to the element indexed by "x" and "y"

◆ randomPosition()

template<class T >
const QPoint Grid< T >::randomPosition

returns a (valid) random position within the grid

◆ rectangle()

template<class T >
QRect Grid< T >::rectangle ( ) const
inline

get the rectangle of the grid in terms of indices

◆ setMetricRect()

template<class T >
void Grid< T >::setMetricRect ( QRectF  rect)
inline

set the metric rectangle. Use with care! No further checks are executed!

◆ setup() [1/3]

template<class T >
bool Grid< T >::setup ( const float  cellsize,
const int  sizex,
const int  sizey 
)

◆ setup() [2/3]

template<class T >
bool Grid< T >::setup ( const Grid< T > &  source)
inline

◆ setup() [3/3]

template<class T >
bool Grid< T >::setup ( const QRectF &  rect,
const double  cellsize 
)

◆ sizeX()

template<class T >
int Grid< T >::sizeX ( ) const
inline

◆ sizeY()

template<class T >
int Grid< T >::sizeY ( ) const
inline

◆ sum()

template<class T >
T Grid< T >::sum

retrieve the sum of the grid

◆ toDouble()

template<class T >
Grid< double > * Grid< T >::toDouble

create a double grid (same size as this grid) and convert this grid to double values.

NOTE: caller is responsible for freeing memory!

◆ validate()

template<class T >
void Grid< T >::validate ( QPoint &  pos) const
inline

force

Parameters
posto contain valid indices with respect to this grid. ensure that "pos" is a valid key. if out of range, pos is set to minimum/maximum values.

◆ valueAt() [1/2]

template<class T >
T & Grid< T >::valueAt ( const float  x,
const float  y 
)

value at position defined by metric coordinates (x,y)

◆ valueAt() [2/2]

template<class T >
T & Grid< T >::valueAt ( const QPointF &  posf)

value at position defined by metric coordinates (QPointF)

◆ valueAtIndex() [1/3]

template<class T >
T & Grid< T >::valueAtIndex ( const int  index)
inline

get a ref ot value at (one-dimensional) index 'index'.

◆ valueAtIndex() [2/3]

template<class T >
T & Grid< T >::valueAtIndex ( const int  ix,
const int  iy 
)
inline

const value at position defined by indices (x,y)

◆ valueAtIndex() [3/3]

template<class T >
T & Grid< T >::valueAtIndex ( const QPoint &  pos)
inline

value at position defined by a QPoint defining the two indices (x,y)

◆ wipe() [1/2]

template<class T >
void Grid< T >::wipe

write 0-bytes with memcpy to the whole area

◆ wipe() [2/2]

template<class T >
void Grid< T >::wipe ( const T  value)

overwrite the whole area with "value" size of T must be the size of "int" ERRORNOUS!!!


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