Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
Representation of a multi-dimensional grid which contains axis information. More...
#include <GridContainer.h>
Classes | |
class | iter |
Class to iterate through the GridContainer cells. More... | |
Public Types | |
typedef GridCellManagerTraits< GridCellManager >::data_type | cell_type |
The type of the values stored in the grid cells. | |
typedef decltype(ptr_test< GridCellManagerTraits< GridCellManager > >(nullptr)) | pointer_type |
Pointer type. | |
typedef decltype(ref_test< GridCellManagerTraits< GridCellManager > >(nullptr)) | reference_type |
Reference type. | |
typedef std::tuple< GridAxis< AxesTypes >... > | AxesTuple |
The type of the tuple keeping the axes of the grid. | |
template<int I> | |
using | axis_type = typename std::tuple_element< I, std::tuple< AxesTypes... > >::type |
typedef iter< cell_type, pointer_type, reference_type > | iterator |
typedef iter< cell_type const, pointer_type const, reference_type const > | const_iterator |
Public Member Functions | |
GridContainer (GridAxis< AxesTypes >... axes) | |
Constructs a GridContainer with the given axes. | |
GridContainer (std::tuple< GridAxis< AxesTypes >... > axes_tuple) | |
Constructs a GridContainer with the given axes. | |
template<typename... Args> | |
GridContainer (std::tuple< GridAxis< AxesTypes >... > axes_tuple, Args &&... args) | |
GridContainer (GridContainer< GridCellManager, AxesTypes... > &&)=default | |
Default move constructor and move assignment operator. | |
GridContainer & | operator= (GridContainer< GridCellManager, AxesTypes... > &&)=default |
GridContainer (const GridContainer< GridCellManager, AxesTypes... > &)=delete | |
GridContainer & | operator= (const GridContainer< GridCellManager, AxesTypes... > &)=delete |
GridContainer | copy () const |
But if needed be, allow explicit copies. | |
virtual | ~GridContainer ()=default |
Default destructor. | |
template<int I> | |
const GridAxis< axis_type< I > > & | getAxis () const |
const std::tuple< GridAxis< AxesTypes >... > & | getAxesTuple () const |
Returns a tuple containing the information of all the grid axes. | |
iterator | begin () |
Returns an iterator to the first cell of the grid. | |
const_iterator | begin () const |
Returns an iterator to the first cell of the grid. | |
const_iterator | cbegin () |
Returns a constant iterator to the first cell of the grid. | |
iterator | end () |
Returns an iterator to the cell after the last of the grid. | |
const_iterator | end () const |
Returns an iterator to the cell after the last of the grid. | |
const_iterator | cend () |
Returns a constant iterator to the cell after the last of the grid. | |
size_t | size () const |
Returns the total number of cells of the grid. | |
const reference_type | operator() (decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) const |
reference_type | operator() (decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) |
(decltype(std::declval<GridAxis<AxesTypes>>().size())...) const | |
const reference_type | at (decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) const |
reference_type | at (decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) |
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > | infimum (const AxesTypes... coordinates) const |
Returns the grid indexes to the greatest knot less or equal to the given coordinates. | |
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > | infimum (const std::tuple< AxesTypes... > &coordinates) const |
template<int I> | |
GridContainer< GridCellManager, AxesTypes... > | fixAxisByIndex (size_t index) |
Returns a slice of the grid based on an axis index. | |
template<int I> | |
const GridContainer< GridCellManager, AxesTypes... > | fixAxisByIndex (size_t index) const |
const version of the fixAxisByIndex(size_t) method | |
template<int I> | |
GridContainer< GridCellManager, AxesTypes... > | fixAxisByValue (const axis_type< I > &value) |
Returns a slice of the grid based on an axis value. | |
template<int I> | |
const GridContainer< GridCellManager, AxesTypes... > | fixAxisByValue (const axis_type< I > &value) const |
const version of the fixAxisByValue(const axis_type<I>&) method | |
GridCellManager & | getCellManager () |
const GridCellManager & | getCellManager () const |
Static Public Member Functions | |
static constexpr size_t | axisNumber () |
Returns the number of axes of the grid (dimensionality) | |
Private Types | |
typedef GridCellManagerTraits< GridCellManager >::iterator | cell_manager_iter_type |
Private Member Functions | |
GridContainer () | |
GridContainer (const GridContainer< GridCellManager, AxesTypes... > &other, size_t axis, size_t index) | |
Slice constructor. | |
template<int I> | |
const GridAxis< axis_type< I > > & | getOriginalAxis () const |
Static Private Member Functions | |
template<typename GCM > | |
static cell_type * | ptr_test (...) |
template<typename GCM > | |
static GCM::pointer_type | ptr_test (typename GCM::pointer_type *) |
template<typename GCM > | |
static cell_type & | ref_test (...) |
template<typename GCM > | |
static GCM::reference_type | ref_test (typename GCM::reference_type *) |
Private Attributes | |
std::tuple< GridAxis< AxesTypes >... > | m_axes |
A tuple containing the axes of the grid. | |
GridIndexHelper< AxesTypes... > | m_index_helper {m_axes} |
A helper class used for calculations of the axes indices. | |
std::tuple< GridAxis< AxesTypes >... > | m_axes_fixed {m_axes} |
a tuple containing the original axes of the full grid, if this grid is a slice | |
GridIndexHelper< AxesTypes... > | m_index_helper_fixed {m_axes_fixed} |
a helper class for calculations of the original axes indices | |
std::map< size_t, size_t > | m_fixed_indices {} |
A map containing the axes which have been fixed, if this grid is a slice. | |
std::shared_ptr< GridCellManager > | m_cell_manager |
A pointer to the data of the grid. | |
Representation of a multi-dimensional grid which contains axis information.
The GridContainer class represents the notion of a multi-dimensional grid, each axis of is represented by an GridAxis object. Note that this class is not a mathematical tool, but it focuses on providing fast access to the grid cells and axis information in an efficient way.
In fact, the GridContainer class delegates the handling of the grid cell values to an instance of a GridCellManager object. The type of this object is given as a template parameter and it can be any type (including mathematical representations of grids from other libraries). To reduce the requirements on the GridCellManager type, the GridContainer class does not access it directly, but it uses the GridCellManagerTraits. This allows to use as GridCellManager even classes of third party libraries, by defining a specialization of GridCellManagerTraits (for more information refer to the documentation of GridCellManagerTraits).
The axis information of the GridContainer can be accessed by using the method getAxis(). This method gets one integer template parameter, which defines which axis information will be returned. Note that it is zero based. For example, the information of the third axis can be accessed with the following command:
The cell values (both for reading and writing) can be accessed in two ways. Either with the parenthesis operator, which gets as parameters the coordinates of the cell, or by using the iterator returned by the begin() method.
Accessing the grid by using the iterator is optimized for speed and is the recommended way for traversing through the grid. This way of iteration implies no performance penalty for the axis information management and it is almost as fast as iterating through the GridCellManager containing the data. If the axis information is required, it can be retrieved by using the iterator.axisIndex() and iterator.axisValue() methods (with the implied performance penalty).
Slicing the grid is supported by two ways. The iterator.fixAxisIndex() and iterator.fixAxisValue() methods modify the way an iterator traverses through a grid object. The GridContainer.fixAxisIndex() and GridContainer.fisAxisValue() methods return grid objects representing silces of the original grid. Note that these slices share the same underling data with the original grid and any modifications will be reflected. For more information see the documentation of the related methods.
GridCellManager | The class to which the handling of the cell values is delegated |
AxesTypes | The types of the grid axes |
Definition at line 97 of file GridContainer.h.
typedef std::tuple<GridAxis<AxesTypes>...> Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::AxesTuple |
The type of the tuple keeping the axes of the grid.
Definition at line 125 of file GridContainer.h.
using Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::axis_type = typename std::tuple_element<I, std::tuple<AxesTypes...> >::type |
Definition at line 129 of file GridContainer.h.
|
private |
Definition at line 104 of file GridContainer.h.
typedef GridCellManagerTraits<GridCellManager>::data_type Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::cell_type |
The type of the values stored in the grid cells.
Definition at line 100 of file GridContainer.h.
typedef iter<cell_type const, pointer_type const, reference_type const> Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::const_iterator |
Definition at line 136 of file GridContainer.h.
typedef iter<cell_type, pointer_type, reference_type> Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::iterator |
Definition at line 135 of file GridContainer.h.
typedef decltype(ptr_test<GridCellManagerTraits<GridCellManager>>(nullptr)) Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::pointer_type |
Pointer type.
Definition at line 120 of file GridContainer.h.
typedef decltype(ref_test<GridCellManagerTraits<GridCellManager>>(nullptr)) Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::reference_type |
Reference type.
Definition at line 122 of file GridContainer.h.
|
explicit |
Constructs a GridContainer with the given axes.
The GridCellManager type must be given as a template parameter and an instance of it will be created by using the GridCellManagerTraits.factory() method.
axes | the GridAxises describing the axes of the grid |
|
explicit |
Constructs a GridContainer with the given axes.
The GridCellManager type must be given as a template parameter and an instance of it will be created by using the GridCellManagerTraits.factory() method.
axes_tuple | the GridAxises describing the axes of the grid |
Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::GridContainer | ( | std::tuple< GridAxis< AxesTypes >... > | axes_tuple, |
Args &&... | args | ||
) |
Forward parameters to the GridCellManager factory
|
default |
Default move constructor and move assignment operator.
|
delete |
|
virtualdefault |
Default destructor.
|
private |
Default constructor
|
private |
Slice constructor.
This constructor creates a GridContainer which represents a slice of the given one. It is private and it should be used only by the fixAxisByIndex and fixAxisByValue methods.
other | The original grid |
axis | The axis to fix (zero based) |
index | The index to fix the axis to (zero based) |
reference_type Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::at | ( | decltype(std::declval< GridAxis< AxesTypes > >().size())... | indices | ) |
const reference_type Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::at | ( | decltype(std::declval< GridAxis< AxesTypes > >().size())... | indices | ) | const |
Returns a reference to the grid cell for the given axes indices, to be used both for reading and writing. This method is the bound-checked alternative of the parenthesis operator. Note that if the caller can guarantee that the indices will be in range, the parenthesis operator is a better choice, because it will be faster.
indices | The indices of the axes |
Elements::Exception | if any of the indices is out of range |
|
staticconstexpr |
Returns the number of axes of the grid (dimensionality)
iterator Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::begin | ( | ) |
Returns an iterator to the first cell of the grid.
const_iterator Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::begin | ( | ) | const |
Returns an iterator to the first cell of the grid.
const_iterator Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::cbegin | ( | ) |
Returns a constant iterator to the first cell of the grid.
const_iterator Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::cend | ( | ) |
Returns a constant iterator to the cell after the last of the grid.
GridContainer Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::copy | ( | ) | const |
But if needed be, allow explicit copies.
iterator Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::end | ( | ) |
Returns an iterator to the cell after the last of the grid.
const_iterator Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::end | ( | ) | const |
Returns an iterator to the cell after the last of the grid.
GridContainer< GridCellManager, AxesTypes... > Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::fixAxisByIndex | ( | size_t | index | ) |
Returns a slice of the grid based on an axis index.
The returned GridContainer has the same number of axes with the original, with the fixed axis having a single value. The two grids (original and shared) share the same data and any modifications are reflected to both.
I | the (zero based) index of the axis to fix |
index | the index (zero based) to fix the axis to |
Elements::Exception | if the given index is out of the bounds of the axis |
Elements::Exception | if the grid container is a slice and has this axis already fixed |
const GridContainer< GridCellManager, AxesTypes... > Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::fixAxisByIndex | ( | size_t | index | ) | const |
const version of the fixAxisByIndex(size_t) method
Important note: Because the returned GridContainer shares the same underlying data with the original one, the returned object is a constant grid (othewise it could be used for modifying the original object, which is constant). This, with combination that the GridContainer does not have a copy constructor (to avoid performance pitfalls), does not allow for creating a new object from the returned rvalue. For example the following are wrong:
All the above will try to create a new GridContainer object by using the deleted copy constructor, which will result to the compilation failing with the related message.
The way to use the object returned by this method is to assign a constant reference to it. This action will extend the life of the temporary rvalue object to the lifetime of the reference. For example:
GridContainer< GridCellManager, AxesTypes... > Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::fixAxisByValue | ( | const axis_type< I > & | value | ) |
Returns a slice of the grid based on an axis value.
The returned GridContainer has the same number of axes with the original, with the fixed axis having a single value. The two grids (original and shared) share the same data and any modifications are reflected to both.
I | the (zero based) index of the axis to fix |
value | the value to fix the axis to |
Elements::Exception | if the axis does not contain the given value |
Elements::Exception | if the grid container is a slice and has this axis already fixed |
const GridContainer< GridCellManager, AxesTypes... > Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::fixAxisByValue | ( | const axis_type< I > & | value | ) | const |
const version of the fixAxisByValue(const axis_type<I>&) method
Important note: Because the returned GridContainer shares the same underlying data with the original one, the returned object is a constant grid (othewise it could be used for modifying the original object, which is constant). This, with combination that the GridContainer does not have a copy constructor (to avoid performance pitfalls), does not allow for creating a new object from the returned rvalue. For example the following are wrong:
All the above will try to create a new GridContainer object by using the deleted copy constructor, which will result to the compilation failing with the related message.
The way to use the object returned by this method is to assign a constant reference to it. This action will extend the life of the temporary rvalue object to the lifetime of the reference. For example:
const std::tuple< GridAxis< AxesTypes >... > & Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::getAxesTuple | ( | ) | const |
Returns a tuple containing the information of all the grid axes.
Referenced by boost::serialization::save_construct_data(), and boost::serialization::save_construct_data().
const GridAxis< axis_type< I > > & Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::getAxis | ( | ) | const |
Returns the information of a specific axis.
I | The (zero based) index of the axis |
|
inline |
Definition at line 371 of file GridContainer.h.
References Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::m_cell_manager.
Referenced by boost::serialization::save_construct_data().
|
inline |
Definition at line 375 of file GridContainer.h.
References Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::m_cell_manager.
|
private |
Returns the original axis. This behaves the same like the getAxis() with exception the case that the grid is a slice. In that case, it will return the original axes and not the single value fixed ones.
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::infimum | ( | const AxesTypes... | coordinates | ) | const |
Returns the grid indexes to the greatest knot less or equal to the given coordinates.
coordinates | The coordinates |
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::infimum | ( | const std::tuple< AxesTypes... > & | coordinates | ) | const |
reference_type Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::operator() | ( | decltype(std::declval< GridAxis< AxesTypes > >().size())... | indices | ) |
(decltype(std::declval<GridAxis<AxesTypes>>().size())...) const
(decltype(std::declval<GridAxis<AxesTypes>>().size())...) const
const reference_type Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::operator() | ( | decltype(std::declval< GridAxis< AxesTypes > >().size())... | indices | ) | const |
Returns a reference to the grid cell for the given axes indices, to be used both for reading and writing. This method is not bound-checked and out of range indices cause undefined behavior. If the caller cannot guarantee that the indices will be in range, the method at() can be used, which has the same behavior but performs out of range checks.
indices | The indices of the axes |
|
delete |
|
default |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
size_t Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::size | ( | ) | const |
Returns the total number of cells of the grid.
|
private |
A tuple containing the axes of the grid.
Definition at line 381 of file GridContainer.h.
|
private |
a tuple containing the original axes of the full grid, if this grid is a slice
Definition at line 385 of file GridContainer.h.
|
private |
A pointer to the data of the grid.
Definition at line 391 of file GridContainer.h.
Referenced by Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::getCellManager(), and Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes >::getCellManager().
|
private |
A map containing the axes which have been fixed, if this grid is a slice.
Definition at line 389 of file GridContainer.h.
|
private |
A helper class used for calculations of the axes indices.
Definition at line 383 of file GridContainer.h.
|
private |
a helper class for calculations of the original axes indices
Definition at line 387 of file GridContainer.h.