Template Class CDynamicGrid3D

Class Documentation

template<class T, class coord_t = double>
class CDynamicGrid3D

A 3D rectangular grid of dynamic size which stores any kind of data at each voxel.

Template Parameters:

T – The type of each voxel in the grid.

Direct and range-based access to data

inline const grid_data_t &data() const
inline iterator begin()
inline iterator end()
inline const_iterator begin() const
inline const_iterator end() const

Public Types

using grid_data_t = std::vector<T>
using iterator = typename grid_data_t::iterator
using const_iterator = typename grid_data_t::const_iterator

Public Functions

inline CDynamicGrid3D(coord_t x_min = -1.0, coord_t x_max = 1.0, coord_t y_min = -1.0, coord_t y_max = +1.0, coord_t z_min = -1.0, coord_t z_max = 1.0, coord_t resolution_xy = 0.5, coord_t resolution_z = 0.5)

Constructor

inline virtual void resize(coord_t new_x_min, coord_t new_x_max, coord_t new_y_min, coord_t new_y_max, coord_t new_z_min, coord_t new_z_max, const T &defaultValueNewCells, coord_t additionalMarginMeters = 2)

Changes the size of the grid, maintaining previous contents.

See also

setSize

inline virtual void setSize(const coord_t x_min, const coord_t x_max, const coord_t y_min, const coord_t y_max, const coord_t z_min, const coord_t z_max, const coord_t resolution_xy, const coord_t resolution_z_ = -1.0, const T *fill_value = nullptr)

Changes the size of the grid, ERASING all previous contents. If fill_value is left as nullptr, the contents of cells may be undefined (some will remain with their old values, the new ones will have the default voxel value, but the location of old values may change wrt their old places). If fill_value is not nullptr, it is assured that all cells will have a copy of that value after resizing. If resolution_z<0, the same resolution will be used for all dimensions x,y,z as given in resolution_xy

See also

resize, fill

inline virtual void clear()

Erase the contents of all the cells, setting them to their default values (default ctor).

inline void fill(const T &value)

Fills all the cells with the same value

inline bool isOutOfBounds(const int cx, const int cy, const int cz) const
inline size_t cellAbsIndexFromCXCYCZ(const int cx, const int cy, const int cz) const

Gets the absolute index of a voxel in the linear container m_map[] from its cx,cy,cz indices, or -1 if out of map bounds (in any dimension).

See also

x2idx(), y2idx(), z2idx()

inline T *cellByPos(coord_t x, coord_t y, coord_t z)

Returns a pointer to the contents of a voxel given by its coordinates, or nullptr if it is out of the map extensions.

inline const T *cellByPos(coord_t x, coord_t y, coord_t z) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline T &cellRefByPos(coord_t x, coord_t y, coord_t z)

Like cellByPos() but returns a reference

Throws:

std::out_of_range – if out of grid limits.

inline const T &cellRefByPos(coord_t x, coord_t y, coord_t z) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline T *cellByIndex(unsigned int cx, unsigned int cy, unsigned int cz)

Returns a pointer to the contents of a voxel given by its voxel indexes, or nullptr if it is out of the map extensions.

inline const T *cellByIndex(unsigned int cx, unsigned int cy, unsigned int cz) const
inline const T *cellByIndex(size_t cidx) const

Returns a pointer to the contents of a voxel given by its absolute voxel index, or nullptr if it is out of range.

inline T *cellByIndex(size_t cidx)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline size_t getSizeX() const
inline size_t getSizeY() const
inline size_t getSizeZ() const
inline size_t getVoxelCount() const
inline coord_t getXMin() const
inline coord_t getXMax() const
inline coord_t getYMin() const
inline coord_t getYMax() const
inline coord_t getZMin() const
inline coord_t getZMax() const
inline coord_t getResolutionXY() const
inline coord_t getResolutionZ() const
inline int x2idx(coord_t x) const

Transform a coordinate values into voxel indexes

inline int y2idx(coord_t y) const
inline int z2idx(coord_t z) const
inline coord_t idx2x(int cx) const

Transform a voxel index into a coordinate value of the voxel central point

inline coord_t idx2y(int cy) const
inline coord_t idx2z(int cz) const
template<class ARCHIVE>
inline void dyngridcommon_writeToStream(ARCHIVE &out) const

Serialization of all parameters, except the contents of each voxel (responsibility of the derived class)

template<class ARCHIVE>
inline void dyngridcommon_readFromStream(ARCHIVE &in)

Serialization of all parameters, except the contents of each voxel (responsibility of the derived class)

Public Static Attributes

static const size_t INVALID_VOXEL_IDX = size_t(-1)

Protected Functions

inline std::vector<T> &m_map_castaway_const() const

Used only from logically const method that really need to modify the object

Protected Attributes

mutable grid_data_t m_map

The cells

coord_t m_x_min
coord_t m_x_max
coord_t m_y_min
coord_t m_y_max
coord_t m_z_min
coord_t m_z_max
coord_t m_resolution_xy
coord_t m_resolution_z
size_t m_size_x
size_t m_size_y
size_t m_size_z
size_t m_size_x_times_y