9 #define _USE_MATH_DEFINES
24 CDynamicGrid3D(
double x_min=-1.0,
double x_max=1.0,
double y_min=-1.0,
double y_max=+1.0,
double z_min=-1.0,
double z_max=1.0,
double resolution_xy=0.5,
double resolution_z=0.5) :
27 setSize(x_min,x_max,y_min,y_max,z_min, z_max, resolution_xy, resolution_z);
34 double new_x_min,
double new_x_max,
35 double new_y_min,
double new_y_max,
36 double new_z_min,
double new_z_max,
37 const T& defaultValueNewCells,
double additionalMarginMeters = 2.0)
56 if (additionalMarginMeters>0)
58 if (new_x_min<
m_x_min) new_x_min = floor(new_x_min - additionalMarginMeters);
59 if (new_x_max>
m_x_max) new_x_max = ceil(new_x_max + additionalMarginMeters);
60 if (new_y_min<
m_y_min) new_y_min = floor(new_y_min - additionalMarginMeters);
61 if (new_y_max>
m_y_max) new_y_max = ceil(new_y_max + additionalMarginMeters);
62 if (new_z_min<
m_z_min) new_z_min = floor(new_z_min - additionalMarginMeters);
63 if (new_z_max>
m_z_max) new_z_max = ceil(new_z_max + additionalMarginMeters);
88 size_t new_size_x_times_y = new_size_x*new_size_y;
91 typename std::vector<T> new_map;
92 new_map.resize(new_size_x*new_size_y*new_size_z, defaultValueNewCells);
101 for (
x = 0, itSrc = (
m_map.begin() +
y*
m_size_x+
z*
m_size_x_times_y), itDst = (new_map.begin() + extra_x_izq + (
y + extra_y_arr)*new_size_x + (
z+extra_z_top)*new_size_x_times_y );
103 ++
x, ++itSrc, ++itDst)
136 const double x_min,
const double x_max,
137 const double y_min,
const double y_max,
138 const double z_min,
const double z_max,
139 const double resolution_xy,
const double resolution_z_=-1.0,
140 const T * fill_value = NULL)
142 const double resolution_z = resolution_z_ > 0.0 ? resolution_z_ : resolution_xy;
149 m_x_max = x_min + resolution_xy*
round((x_max-x_min) / resolution_xy);
150 m_y_max = y_min + resolution_xy*
round((y_max-y_min)/ resolution_xy);
151 m_z_max = z_min + resolution_z*
round((z_max-z_min) / resolution_z);
185 return (cx<0 || cx >=
static_cast<int>(
m_size_x)) ||
186 (cy<0 || cy >=
static_cast<int>(
m_size_y)) ||
187 (cz<0 || cz >=
static_cast<int>(
m_size_z));
214 inline T*
cellByIndex(
unsigned int cx,
unsigned int cy,
unsigned int cz )
223 inline const T*
cellByIndex(
unsigned int cx,
unsigned int cy,
unsigned int cz )
const
274 in >> nX >> nY >> nZ;
276 m_map.resize(nX*nY*nZ);
A 3D rectangular grid of dynamic size which stores any kind of data at each voxel.
double getResolutionXY() const
const T * cellByIndex(unsigned int cx, unsigned int cy, unsigned int cz) const
Returns a pointer to the contents of a voxel given by its voxel indexes, or NULL if it is out of the ...
double idx2z(int cz) const
std::vector< T > & m_map_castaway_const() const
Used only from logically const method that really need to modify the object.
double idx2x(int cx) const
Transform a voxel index into a coordinate value of the voxel central point.
std::vector< T > m_map
The cells.
void fill(const T &value)
Fills all the cells with the same value.
static const size_t INVALID_VOXEL_IDX
int z2idx(double z) const
int x2idx(double x) const
Transform a coordinate values into voxel indexes.
T * cellByPos(double x, double y, double z)
Returns a pointer to the contents of a voxel given by its coordinates, or NULL if it is out of the ma...
int y2idx(double y) const
void dyngridcommon_writeToStream(mrpt::utils::CStream &out) const
Serialization of all parameters, except the contents of each voxel (responsability of the derived cla...
virtual void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double z_min, const double z_max, const double resolution_xy, const double resolution_z_=-1.0, const T *fill_value=NULL)
Changes the size of the grid, ERASING all previous contents.
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,...
size_t getVoxelCount() const
double getResolutionZ() const
virtual void clear()
Erase the contents of all the cells, setting them to their default values (default ctor).
double idx2y(int cy) const
CDynamicGrid3D(double x_min=-1.0, double x_max=1.0, double y_min=-1.0, double y_max=+1.0, double z_min=-1.0, double z_max=1.0, double resolution_xy=0.5, double resolution_z=0.5)
Constructor.
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 NULL if it is out of the ...
bool isOutOfBounds(const int cx, const int cy, const int cz) const
const T * cellByPos(double x, double y, double z) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void dyngridcommon_readFromStream(mrpt::utils::CStream &in)
Serialization of all parameters, except the contents of each voxel (responsability of the derived cla...
virtual void resize(double new_x_min, double new_x_max, double new_y_min, double new_y_max, double new_z_min, double new_z_max, const T &defaultValueNewCells, double additionalMarginMeters=2.0)
Changes the size of the grid, maintaining previous contents.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
GLsizei const GLfloat * value
int round(const T value)
Returns the closer integer (int) to x.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int32 uint32_t