25 template <
class T,
class coord_t =
double>
30 using iterator =
typename grid_data_t::iterator;
35 coord_t x_min = -1.0, coord_t x_max = 1.0, coord_t y_min = -1.0,
36 coord_t y_max = +1.0, coord_t z_min = -1.0, coord_t z_max = 1.0,
37 coord_t resolution_xy = 0.5, coord_t resolution_z = 0.5)
41 x_min, x_max, y_min, y_max, z_min, z_max, resolution_xy,
49 coord_t new_x_min, coord_t new_x_max, coord_t new_y_min,
50 coord_t new_y_max, coord_t new_z_min, coord_t new_z_max,
51 const T& defaultValueNewCells, coord_t additionalMarginMeters = 2)
67 if (additionalMarginMeters > 0)
70 new_x_min = floor(new_x_min - additionalMarginMeters);
72 new_x_max = ceil(new_x_max + additionalMarginMeters);
74 new_y_min = floor(new_y_min - additionalMarginMeters);
76 new_y_max = ceil(new_y_max + additionalMarginMeters);
78 new_z_min = floor(new_z_min - additionalMarginMeters);
80 new_z_max = ceil(new_z_max + additionalMarginMeters);
118 size_t new_size_x_times_y = new_size_x * new_size_y;
123 new_size_x * new_size_y * new_size_z, defaultValueNewCells);
136 (new_map.begin() + extra_x_izq +
137 (y + extra_y_arr) * new_size_x +
138 (z + extra_z_top) * new_size_x_times_y);
139 x <
m_size_x; ++x, ++itSrc, ++itDst)
176 const coord_t x_min,
const coord_t x_max,
const coord_t y_min,
177 const coord_t y_max,
const coord_t z_min,
const coord_t z_max,
178 const coord_t resolution_xy,
const coord_t resolution_z_ = -1.0,
179 const T* fill_value =
nullptr)
181 const coord_t resolution_z =
182 resolution_z_ > 0 ? resolution_z_ : resolution_xy;
191 x_min + resolution_xy *
round((x_max - x_min) / resolution_xy);
193 y_min + resolution_xy *
round((y_max - y_min) / resolution_xy);
194 m_z_max = z_min + resolution_z *
round((z_max - z_min) / resolution_z);
223 inline void fill(
const T& value)
225 for (
auto it =
m_map.begin(); it !=
m_map.end(); ++it) *it = value;
232 return (cx < 0 || cx >= static_cast<int>(
m_size_x)) ||
233 (cy < 0 || cy >=
static_cast<int>(
m_size_y)) ||
234 (cz < 0 || cz >=
static_cast<int>(
m_size_z));
241 const int cx,
const int cy,
const int cz)
const 258 inline const T*
cellByPos(coord_t x, coord_t y, coord_t z)
const 271 if (!c)
throw std::out_of_range(
"cellRefByPos: Out of grid limits");
278 if (!c)
throw std::out_of_range(
"cellRefByPos: Out of grid limits");
285 inline T*
cellByIndex(
unsigned int cx,
unsigned int cy,
unsigned int cz)
292 unsigned int cx,
unsigned int cy,
unsigned int cz)
const 304 if (cidx >
m_map.size())
return nullptr;
310 if (cidx >
m_map.size())
return nullptr;
370 template <
class ARCHIVE>
376 .
template WriteAs<uint32_t>(
m_size_y)
377 .template WriteAs<uint32_t>(
m_size_z);
381 template <
class ARCHIVE>
387 m_size_x = in.template ReadAs<uint32_t>();
388 m_size_y = in.template ReadAs<uint32_t>();
389 m_size_z = in.template ReadAs<uint32_t>();
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 o...
std::vector< TCELL > grid_data_t
typename grid_data_t::const_iterator const_iterator
virtual void clear()
Erase the contents of all the cells, setting them to their default values (default ctor)...
void dyngridcommon_writeToStream(ARCHIVE &out) const
Serialization of all parameters, except the contents of each voxel (responsability of the derived cla...
void fill(const T &value)
Fills all the cells with the same value.
const T * cellByIndex(unsigned int cx, unsigned int cy, unsigned int cz) const
const_iterator begin() const
T * cellByIndex(size_t cidx)
coord_t idx2x(int cx) const
Transform a voxel index into a coordinate value of the voxel central point.
size_t getVoxelCount() const
typename grid_data_t::iterator iterator
static const size_t INVALID_VOXEL_IDX
grid_data_t m_map
The cells.
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).
const_iterator end() const
int y2idx(coord_t y) const
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.
bool isOutOfBounds(const int cx, const int cy, const int cz) const
A 3D rectangular grid of dynamic size which stores any kind of data at each voxel.
int x2idx(coord_t x) const
Transform a coordinate values into voxel indexes.
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 t...
coord_t getResolutionZ() const
coord_t idx2z(int cz) const
const T & cellRefByPos(coord_t x, coord_t y, coord_t z) const
const T * cellByPos(coord_t x, coord_t y, coord_t z) const
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.
coord_t idx2y(int cy) const
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...
mrpt::vision::TStereoCalibResults out
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.
int z2idx(coord_t z) const
void dyngridcommon_readFromStream(ARCHIVE &in)
Serialization of all parameters, except the contents of each voxel (responsability of the derived cla...
std::vector< T > & m_map_castaway_const() const
Used only from logically const method that really need to modify the object.
coord_t getResolutionXY() const
T & cellRefByPos(coord_t x, coord_t y, coord_t z)
Like cellByPos() but returns a reference.
int round(const T value)
Returns the closer integer (int) to x.