template class mrpt::containers::CDynamicGrid3D

Overview

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

Parameters:

T

The type of each voxel in the grid.

#include <mrpt/containers/CDynamicGrid3D.h>

template <class T, class coord_t = double>
class CDynamicGrid3D
{
public:
    // construction

    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
        );

    // methods

    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
        );

    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
        );

    virtual void clear();
    void fill(const T& value);
    size_t cellAbsIndexFromCXCYCZ(const int cx, const int cy, const int cz) const;
    T* cellByPos(coord_t x, coord_t y, coord_t z);
    const T* cellByPos(coord_t x, coord_t y, coord_t z) const;
    T& cellRefByPos(coord_t x, coord_t y, coord_t z);
    const T& cellRefByPos(coord_t x, coord_t y, coord_t z) const;
    T* cellByIndex(unsigned int cx, unsigned int cy, unsigned int cz);
    const T* cellByIndex(size_t cidx) const;
    T* cellByIndex(size_t cidx);
    int x2idx(coord_t x) const;
    coord_t idx2x(int cx) const;

    template <class ARCHIVE>
    void dyngridcommon_writeToStream(ARCHIVE& out) const;

    template <class ARCHIVE>
    void dyngridcommon_readFromStream(ARCHIVE& in);
};

// direct descendants

class CRandomFieldGridMap3D;

Construction

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.

Methods

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

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

virtual void clear()

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

void fill(const T& value)

Fills all the cells with the same value.

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()

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.

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.

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

Like cellByPos() but returns a reference.

Parameters:

std::out_of_range

if out of grid limits.

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.

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.

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.

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.

int x2idx(coord_t x) const

Transform a coordinate values into voxel indexes.

coord_t idx2x(int cx) const

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

template <class ARCHIVE>
void dyngridcommon_writeToStream(ARCHIVE& out) const

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

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

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