Go to the documentation of this file.
27 virtual unsigned int getSizeX()
const = 0;
28 virtual unsigned int getSizeY()
const = 0;
29 virtual float getCellAsFloat(
unsigned int cx,
unsigned int cy)
const = 0;
47 return const_cast<std::vector<T>&
>(
m_map);
56 double x_min = -10.,
double x_max = 10.,
double y_min = -10.,
57 double y_max = 10.,
double resolution = 0.1)
59 setSize(x_min, x_max, y_min, y_max, resolution);
75 const double x_min,
const double x_max,
const double y_min,
76 const double y_max,
const double resolution,
77 const T* fill_value =
nullptr)
109 inline void fill(
const T& value)
111 for (
auto it =
m_map.begin(); it !=
m_map.end(); ++it) *it = value;
118 double new_x_min,
double new_x_max,
double new_y_min,
double new_y_max,
119 const T& defaultValueNewCells,
double additionalMarginMeters = 2.0)
132 if (additionalMarginMeters > 0)
135 new_x_min = floor(new_x_min - additionalMarginMeters);
137 new_x_max = ceil(new_x_max + additionalMarginMeters);
139 new_y_min = floor(new_y_min - additionalMarginMeters);
141 new_y_max = ceil(new_y_max + additionalMarginMeters);
167 typename std::vector<T> new_map;
168 new_map.resize(new_size_x * new_size_y, defaultValueNewCells);
172 typename std::vector<T>::iterator itSrc, itDst;
177 (new_map.begin() + extra_x_izq +
178 (y + extra_y_arr) * new_size_x);
179 x <
m_size_x; ++x, ++itSrc, ++itDst)
203 const int cx =
x2idx(x);
204 const int cy =
y2idx(y);
205 if (cx < 0 || cx >=
static_cast<int>(
m_size_x))
return nullptr;
206 if (cy < 0 || cy >=
static_cast<int>(
m_size_y))
return nullptr;
212 const int cx =
x2idx(x);
213 const int cy =
y2idx(y);
214 if (cx < 0 || cx >=
static_cast<int>(
m_size_x))
return nullptr;
215 if (cy < 0 || cy >=
static_cast<int>(
m_size_y))
return nullptr;
233 inline const T*
cellByIndex(
unsigned int cx,
unsigned int cy)
const
264 inline int xy2idx(
double x,
double y)
const
271 inline void idx2cxcy(
int idx,
int& cx,
int& cy)
const
302 if (
m_map.empty())
return;
303 const T* c = &
m_map[0];
304 for (
size_t cy = 0; cy <
m_size_y; cy++)
305 for (
size_t cx = 0; cx <
m_size_x; cx++) m(cy, cx) = *c++;
318 unsigned int getSizeX()
const override {
return m_obj.getSizeX(); }
319 unsigned int getSizeY()
const override {
return m_obj.getSizeY(); }
320 float getCellAsFloat(
321 unsigned int cx,
unsigned int cy)
const override
323 return m_obj.cell2float(
324 m_obj.m_map[cx + cy * m_obj.getSizeX()]);
328 aux_saver aux(*
this);
329 return aux.saveToTextFile(fileName);
333 template <
class STREAM>
338 out.template WriteAs<uint32_t>(
m_size_x).template WriteAs<uint32_t>(
341 template <
class STREAM>
344 if (!cast_from_float)
351 float xmin, xmax, ymin, ymax, res;
352 in >> xmin >> xmax >> ymin >> ymax >> res;
359 m_size_x = in.template ReadAs<uint32_t>();
360 m_size_y = in.template ReadAs<uint32_t>();
void idx2cxcy(int idx, int &cx, int &cy) const
Transform a global (linear) cell index value into its corresponding (x,y) cell indexes.
virtual unsigned int getSizeX() const =0
size_t getSizeY() const
Returns the vertical size of grid map in cells count.
double getYMin() const
Returns the "y" coordinate of top side of grid map.
virtual float getCellAsFloat(unsigned int cx, unsigned int cy) const =0
virtual float cell2float(const T &) const
The user must implement this in order to provide "saveToTextFile" a way to convert each cell into a n...
virtual void resize(double new_x_min, double new_x_max, double new_y_min, double new_y_max, const T &defaultValueNewCells, double additionalMarginMeters=2.0)
Changes the size of the grid, maintaining previous contents.
double getXMax() const
Returns the "x" coordinate of right side of grid map.
virtual unsigned int getSizeY() const =0
T * cellByPos(double x, double y)
Returns a pointer to the contents of a cell given by its coordinates, or nullptr if it is out of the ...
mrpt::vision::TStereoCalibResults out
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::vector< T > m_map
The cells
int x2idx(double x) const
Transform a coordinate values into cell indexes.
double getXMin() const
Returns the "x" coordinate of left side of grid map.
size_t getSizeX() const
Returns the horizontal size of grid map in cells count.
int round(const T value)
Returns the closer integer (int) to x.
int xy2idx(double x, double y) const
double getYMax() const
Returns the "y" coordinate of bottom side of grid map.
void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const T *fill_value=nullptr)
Changes the size of the grid, ERASING all previous contents.
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point.
bool saveToTextFile(const std::string &fileName) const
double getResolution() const
Returns the resolution of the grid map.
int y2idx(double y) const
void getAsMatrix(MAT &m) const
Get the entire grid as a matrix.
void dyngridcommon_writeToStream(STREAM &out) const
CDynamicGrid(double x_min=-10., double x_max=10., double y_min=-10., double y_max=10., double resolution=0.1)
Constructor.
double idx2y(int cy) const
bool saveToTextFile(const std::string &fileName) const
Saves a float representation of the grid (via "cell2float()") to a text file.
void fill(const T &value)
Fills all the cells with the same value.
T * cellByIndex(unsigned int cx, unsigned int cy)
Returns a pointer to the contents of a cell given by its cell indexes, or nullptr if it is out of the...
const T * cellByPos(double x, double y) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
A 2D grid of dynamic size which stores any kind of data at each cell.
void dyngridcommon_readFromStream(STREAM &in, bool cast_from_float=false)
const T * cellByIndex(unsigned int cx, unsigned int cy) const
Returns a pointer to the contents of a cell given by its cell indexes, or nullptr if it is out of the...
std::vector< T > & m_map_castaway_const() const
Used only from logically const method that really need to modify the object.
void clear()
Erase the contents of all the cells.
virtual ~CDynamicGrid()=default
Destructor.
Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sat Jun 27 14:00:59 UTC 2020 | |