|
0.12.0
|
|
Freundlich's C++ toolkit |
A simple n-dimensional array.
fcppt::container::grid::object is a simple multi dimensional array similar to boost::multi_array. Let's first take a look at how to use a simple three dimensional grid of ints.
Grid uses fcppt::math::dim::object to specify its size and to obtain an element.
Internally, the grid uses a std::vector or a fcppt::container::raw_vector to linearly represent the grid. The iterators returned by the grid are iterators over that internal storage array, so they're not special in any way (other than begin random-access). This also means that iteration is...
...row-major for two-dimensional grids; this means that iteration begins at the top left with row 0, proceeds to the top right, then goes to the right of row 2 and so on.
Here is an example of each iteration method:
To get the position of an iterator, use fcppt::container::grid::iterator_position.
To resize a grid there are a couple of options. resize will resize the underlying container but leave the elements of the grid in an unspecific state.
There are two functions to preserve the current elements that will still fit into the grid after the resize: resize_preserve and resize_preserve_init .
resize_preserve only preserves the elements that still fit but doesn't initialize new elements. resize_preserve_init is like resize_preserve but will give all new elements a default value.
Here's an example:
Classes | |
| class | fcppt::container::grid::object< T, N, A > |
| A simple n dimensional arraySee the module description for more information. More... | |
Functions | |
| template<typename T , fcppt::container::grid::size_type N, typename A , typename Fn > | |
| void | fcppt::container::grid::fill (object< T, N, A > &g, Fn const &f) |
| Fills a grid using a functor. | |
| template<typename T , fcppt::container::grid::size_type N, typename A > | |
| bool | fcppt::container::grid::in_range (grid::object< T, N, A > const &_grid, typename grid::object< T, N, A >::dim const &_pos) |
Checks if the given position _pos is out of bounds. | |
| template<typename Grid , typename Vector , typename Interpolator > | |
| Grid::value_type const | fcppt::container::grid::interpolate (Grid const &grid, Vector const &floating_point_position, Interpolator const &interpolator) |
| Interpolates a value inside the grid cells. | |
| template<typename T , grid::size_type N> | |
| bool | fcppt::container::grid::is_square (grid::object< T, N > const &g) |
| Checks if a grid is a square or a rectangle. | |
| template<typename Grid , typename Iterator > | |
| Grid::dim const | fcppt::container::grid::iterator_position (Grid const &grid, Iterator const it) |
| Returns the position of an iterator. | |
| template<typename Ch , typename Traits , typename T , fcppt::container::grid::size_type N, typename A > | |
| std::basic_ostream< Ch, Traits > & | fcppt::container::grid::operator<< (std::basic_ostream< Ch, Traits > &_stream, grid::object< T, N, A > const &_object) |
| Outputs a grid. | |
| void fcppt::container::grid::fill | ( | object< T, N, A > & | g, |
| Fn const & | f | ||
| ) |
Fills a grid using a functor.
| Fn | A functor with the signature: grid::value_type(grid::dim) |
| bool fcppt::container::grid::in_range | ( | grid::object< T, N, A > const & | _grid, |
| typename grid::object< T, N, A >::dim const & | _pos | ||
| ) |
Checks if the given position _pos is out of bounds.
true if is not out of bounds, false otherwise. | Grid::value_type const fcppt::container::grid::interpolate | ( | Grid const & | grid, |
| Vector const & | floating_point_position, | ||
| Interpolator const & | interpolator | ||
| ) |
Interpolates a value inside the grid cells.
With grid::object alone, you can only access values at discrete points (since the object::dim type used to specify positions has an integral value_type).
Sometimes, however, you want to take a value in between the grid nodes. Think about a magnifying filter for textures, or drawing a line from one plot point to the next (in a one-dimensional grid). This is called interpolation, and it works in all dimensions.
To interpolate, you specify the grid, the floating_point_position and an interpolator. The latter will determine what kind of interpolation is used (linear, trigonometric, ...). You can choose one of the classes in fcppt::math::interpolation (the ones ending in _functor) or you can write your own interpolator class. It just needs an operator() looking like this:
The Vector template parameter determines which floating point type is used for calculations. Here's an example:
| bool fcppt::container::grid::is_square | ( | grid::object< T, N > const & | g | ) |
Checks if a grid is a square or a rectangle.
true of the grid is square, false otherwise | Grid::dim const fcppt::container::grid::iterator_position | ( | Grid const & | grid, |
| Iterator const | it | ||
| ) |
Returns the position of an iterator.
| std::basic_ostream< Ch, Traits>& fcppt::container::grid::operator<< | ( | std::basic_ostream< Ch, Traits > & | _stream, |
| grid::object< T, N, A > const & | _object | ||
| ) |
Outputs a grid.
Outputs the grid _object to _stream. Every level of the grid will be wrapped in parenthesis. So, for example, a two dimensional grid of size (n,m) will be written as ((x_0, y_0), (x_1, y_0), ..., (x_0, y_1), ..., (x_n, y_m)).
| T | Must be a type that has an appropriate operator<< |
| _stream | The stream to write to |
| _object | The grid to write |
1.8.2