Go to the documentation of this file.
41 void COccupancyGridMap2D::TMapDefinition::loadFromConfigFile_map_specific(
47 sectionNamePrefix +
string(
"_creationOpts");
55 insertionOpts.loadFromConfigFile(
56 source, sectionNamePrefix +
string(
"_insertOpts"));
59 likelihoodOpts.loadFromConfigFile(
60 source, sectionNamePrefix +
string(
"_likelihoodOpts"));
63 void COccupancyGridMap2D::TMapDefinition::dumpToTextStream_map_specific(
64 std::ostream& out)
const
72 this->insertionOpts.dumpToTextStream(out);
73 this->likelihoodOpts.dumpToTextStream(out);
91 std::vector<float> COccupancyGridMap2D::entropyTable;
93 static const float MAX_H = 0.69314718055994531f;
98 COccupancyGridMap2D::get_logodd_lut()
106 COccupancyGridMap2D::COccupancyGridMap2D(
107 float min_x,
float max_x,
float min_y,
float max_y,
float res)
116 precomputedLikelihood(),
117 precomputedLikelihoodToBeRecomputed(true),
121 voroni_free_threshold(),
122 updateInfoChangeOnly(),
129 setSize(min_x, max_x, min_y, max_y,
res, 0.5f);
157 float xmin,
float xmax,
float ymin,
float ymax,
float res,
163 ASSERT_(xmax > xmin && ymax > ymin);
164 ASSERT_(default_value >= 0 && default_value <= 1);
187 #ifdef ROWSIZE_MULTIPLE_16
211 float new_x_min,
float new_x_max,
float new_y_min,
float new_y_max,
212 float new_cells_default_value,
bool additionalMargin) noexcept
214 unsigned int extra_x_izq = 0, extra_y_arr = 0, new_size_x = 0,
216 std::vector<cellType> new_map;
218 if (new_x_min > new_x_max)
221 "[COccupancyGridMap2D::resizeGrid] Warning!! Ignoring call, since: "
222 "x_min=%f x_max=%f\n",
223 new_x_min, new_x_max);
226 if (new_y_min > new_y_max)
229 "[COccupancyGridMap2D::resizeGrid] Warning!! Ignoring call, since: "
230 "y_min=%f y_max=%f\n",
231 new_y_min, new_y_max);
236 if (new_x_min >= x_min && new_y_min >= y_min && new_x_max <= x_max &&
241 precomputedLikelihoodToBeRecomputed =
true;
244 if (additionalMargin)
246 if (new_x_min < x_min) new_x_min = floor(new_x_min - 4);
247 if (new_x_max > x_max) new_x_max = ceil(new_x_max + 4);
248 if (new_y_min < y_min) new_y_min = floor(new_y_min - 4);
249 if (new_y_max > y_max) new_y_max = ceil(new_y_max + 4);
253 new_x_min =
min(new_x_min, x_min);
254 new_x_max = max(new_x_max, x_max);
255 new_y_min =
min(new_y_min, y_min);
256 new_y_max = max(new_y_max, y_max);
260 if (fabs(new_x_min / resolution -
round(new_x_min / resolution)) > 0.05f)
261 new_x_min = resolution *
round(new_x_min / resolution);
262 if (fabs(new_y_min / resolution -
round(new_y_min / resolution)) > 0.05f)
263 new_y_min = resolution *
round(new_y_min / resolution);
264 if (fabs(new_x_max / resolution -
round(new_x_max / resolution)) > 0.05f)
265 new_x_max = resolution *
round(new_x_max / resolution);
266 if (fabs(new_y_max / resolution -
round(new_y_max / resolution)) > 0.05f)
267 new_y_max = resolution *
round(new_y_max / resolution);
270 extra_x_izq =
round((x_min - new_x_min) / resolution);
271 extra_y_arr =
round((y_min - new_y_min) / resolution);
273 new_size_x =
round((new_x_max - new_x_min) / resolution);
274 new_size_y =
round((new_y_max - new_y_min) / resolution);
276 assert(new_size_x >= size_x + extra_x_izq);
278 #ifdef ROWSIZE_MULTIPLE_16
280 size_t old_new_size_x = new_size_x;
281 if (0 != (new_size_x % 16))
283 int size_x_incr = 16 - (new_size_x % 16);
285 new_x_max += size_x_incr * resolution;
287 new_size_x =
round((new_x_max - new_x_min) / resolution);
288 assert(0 == (new_size_x % 16));
292 new_map.resize(new_size_x * new_size_y, p2l(new_cells_default_value));
296 cellType* dest_ptr = &new_map[extra_x_izq + extra_y_arr * new_size_x];
298 size_t row_size = size_x *
sizeof(
cellType);
300 for (
size_t y = 0;
y < size_y;
y++)
302 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)
303 assert(dest_ptr + row_size - 1 <= &new_map[new_map.size() - 1]);
304 assert(src_ptr + row_size - 1 <= &map[map.size() - 1]);
306 memcpy(dest_ptr, src_ptr, row_size);
307 dest_ptr += new_size_x;
326 m_voronoi_diagram.clear();
371 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
372 unsigned int N = 256;
374 unsigned int N = 65536;
382 for (i = 0; i < N; i++)
388 if (i == 0 || i == (N - 1)) h = 0;
402 it !=
map.end(); ++it)
407 if (h < (
MAX_H - 0.001f))
439 if (
p == 0 ||
p == 1)
475 if (
static_cast<unsigned int>(
x) >=
size_x ||
476 static_cast<unsigned int>(
y) >=
size_y)
485 float old =
l2p(theCell);
486 float new_v = 1 / (1 + (1 -
v) * (1 - old) / (old *
v));
516 std::vector<cellType> newMap;
525 newMap.resize(newSizeX * newSizeY);
527 for (
int x = 0;
x < newSizeX;
x++)
529 for (
int y = 0;
y < newSizeY;
y++)
533 for (
int xx = 0; xx < downRatio; xx++)
534 for (
int yy = 0; yy < downRatio; yy++)
535 newCell +=
getCell(
x * downRatio + xx,
y * downRatio + yy);
537 newCell /= (downRatio * downRatio);
539 newMap[
x +
y * newSizeX] =
p2l(newCell);
561 params.offset_other_map_points,
params.decimation_other_map_points);
568 const size_t nLocalPoints = otherMap->
size();
569 std::vector<float> x_locals(nLocalPoints), y_locals(nLocalPoints),
570 z_locals(nLocalPoints);
572 const float sin_phi = sin(otherMapPose.
phi);
573 const float cos_phi = cos(otherMapPose.
phi);
575 size_t nOtherMapPointsWithCorrespondence =
577 size_t nTotalCorrespondences = 0;
578 float _sumSqrDist = 0;
581 const int cellsSearchRange =
585 correspondences.clear();
588 if (!nLocalPoints)
return;
593 float local_x_min = std::numeric_limits<float>::max();
594 float local_x_max = -std::numeric_limits<float>::max();
595 float local_y_min = std::numeric_limits<float>::max();
596 float local_y_max = -std::numeric_limits<float>::max();
603 for (
unsigned int localIdx =
params.offset_other_map_points;
604 localIdx < nLocalPoints;
605 localIdx +=
params.decimation_other_map_points)
608 const float xx = x_locals[localIdx] = otherMapPose.
x +
609 cos_phi * otherMap_pxs[localIdx] -
610 sin_phi * otherMap_pys[localIdx];
611 const float yy = y_locals[localIdx] = otherMapPose.
y +
612 sin_phi * otherMap_pxs[localIdx] +
613 cos_phi * otherMap_pys[localIdx];
614 z_locals[localIdx] = otherMap_pzs[localIdx];
617 local_x_min =
min(local_x_min, xx);
618 local_x_max = max(local_x_max, xx);
619 local_y_min =
min(local_y_min, yy);
620 local_y_max = max(local_y_max, yy);
625 if (local_x_min >
x_max || local_x_max < x_min || local_y_min >
y_max ||
632 for (
unsigned int localIdx =
params.offset_other_map_points;
633 localIdx < nLocalPoints;
634 localIdx +=
params.decimation_other_map_points)
637 float maxDistForCorrespondenceSquared =
641 const float x_local = x_locals[localIdx];
642 const float y_local = y_locals[localIdx];
643 const float z_local = z_locals[localIdx];
646 float min_dist = 1e6;
650 const int cx0 =
x2idx(x_local);
651 const int cy0 =
y2idx(y_local);
654 const int cx_min = max(0, cx0 - cellsSearchRange);
656 min(
static_cast<int>(
size_x) - 1, cx0 + cellsSearchRange);
657 const int cy_min = max(0, cy0 - cellsSearchRange);
659 min(
static_cast<int>(
size_y) - 1, cy0 + cellsSearchRange);
662 bool thisLocalHasCorr =
false;
665 for (
int cx = cx_min; cx <= cx_max; cx++)
667 for (
int cy = cy_min; cy <= cy_max; cy++)
673 const float residual_x =
idx2x(cx) - x_local;
674 const float residual_y =
idx2y(cy) - y_local;
677 maxDistForCorrespondenceSquared =
square(
678 params.maxAngularDistForCorrespondence *
679 params.angularDistPivotPoint.distanceTo(
681 params.maxDistForCorrespondence);
684 const float this_dist =
687 if (this_dist < maxDistForCorrespondenceSquared)
689 if (!
params.onlyKeepTheClosest)
692 nTotalCorrespondences++;
699 mp.
other_x = otherMap_pxs[localIdx];
700 mp.
other_y = otherMap_pys[localIdx];
701 mp.
other_z = otherMap_pzs[localIdx];
702 correspondences.push_back(mp);
707 if (this_dist < min_dist)
709 min_dist = this_dist;
714 closestCorr.
this_z = z_local;
716 closestCorr.
other_x = otherMap_pxs[localIdx];
717 closestCorr.
other_y = otherMap_pys[localIdx];
718 closestCorr.
other_z = otherMap_pzs[localIdx];
723 thisLocalHasCorr =
true;
730 if (
params.onlyKeepTheClosest &&
731 (min_dist < maxDistForCorrespondenceSquared))
733 nTotalCorrespondences++;
734 correspondences.push_back(closestCorr);
738 if (thisLocalHasCorr)
740 nOtherMapPointsWithCorrespondence++;
743 _sumSqrDist += min_dist;
748 extraResults.correspondencesRatio =
749 nOtherMapPointsWithCorrespondence /
750 static_cast<float>(nLocalPoints /
params.decimation_other_map_points);
751 extraResults.sumSqrDist = _sumSqrDist;
767 return e1.first > e2.first;
774 float x1,
float y1,
float x2,
float y2)
const
781 for (
int i = 0; i < nSteps; i++)
783 float x = x1 + (x2 - x1) * i /
static_cast<float>(nSteps);
784 float y = y1 + (y2 - y1) * i /
static_cast<float>(nSteps);
789 return sumCost /
static_cast<float>(nSteps);
static const cellType OCCGRID_CELLTYPE_MIN
Discrete to float conversion factors: The min/max values of the integer cell type,...
const mrpt::aligned_std_vector< float > & getPointsBufferRef_y() const
Provides a direct access to a read-only reference of the internal point buffer.
const mrpt::aligned_std_vector< float > & getPointsBufferRef_x() const
Provides a direct access to a read-only reference of the internal point buffer.
#define ASSERT_ABOVE_(__A, __B)
bool precomputedLikelihoodToBeRecomputed
size_t size() const
Returns the number of stored points in the map.
mrpt::math::TPose2D asTPose() const
static CLogOddsGridMapLUT< COccupancyGridMap2D::cellType > logodd_lut
virtual void determineMatching2D(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose2D &otherMapPose, mrpt::tfest::TMatchingPairList &correspondences, const TMatchingParams ¶ms, TMatchingExtraResults &extraResults) const override
See the base class for more details: In this class it is implemented as correspondences of the passed...
const Scalar * const_iterator
std::pair< double, mrpt::math::TPoint2D > TPairLikelihoodIndex
Auxiliary private class.
bool enabled
If set to false (default), this struct is not used.
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
double phi
Orientation (rads)
uint32_t size_x
The size of the grid in cells.
double mean_I
The target variable for mean information, defined as information per cell: mean_I(map) = I(map) / (ce...
static cellType p2l(const float p)
Scales a real valued probability in [0,1] to an integer representation of: log(p)-log(1-p) in the val...
float computePathCost(float x1, float y1, float x2, float y2) const
Compute the 'cost' of traversing a segment of the map according to the occupancy of traversed cells.
#define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS)
Registers one map class into TMetricMapInitializer factory.
GLsizei GLsizei GLuint * obj
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
void resizeGrid(float new_x_min, float new_x_max, float new_y_min, float new_y_max, float new_cells_default_value=0.5f, bool additionalMargin=true) noexcept
Change the size of gridmap, maintaining previous contents.
virtual ~COccupancyGridMap2D()
Destructor.
Parameters for CMetricMap::compute3DMatchingRatio()
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors.
virtual void internal_clear() override
Clear the map: It set all cells to their default occupancy value (0.5), without changing the resoluti...
Functions for estimating the optimal transformation between two frames of references given measuremen...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::maps::COccupancyGridMap2D::TInsertionOptions insertionOpts
Observations insertion options.
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
static float l2p(const cellType l)
Scales an integer representation of the log-odd into a real valued probability in [0,...
A structure for holding correspondences between two sets of points or points-like entities in 2D or 3...
#define ASSERT_(f)
Defines an assertion mechanism.
T square(const T x)
Inline function for the square of a number.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
bool operator<(const COccupancyGridMap2D::TPairLikelihoodIndex &e1, const COccupancyGridMap2D::TPairLikelihoodIndex &e2)
static std::vector< float > entropyTable
Internally used to speed-up entropy calculation.
This namespace contains representation of robot actions and observations.
const mrpt::aligned_std_vector< float > & getPointsBufferRef_z() const
Provides a direct access to a read-only reference of the internal point buffer.
bool m_is_empty
True upon construction; used by isEmpty()
GLsizei GLsizei GLchar * source
float idx2y(const size_t cy) const
float getCell(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.
float compute3DMatchingRatio(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, const TMatchingRatioParams ¶ms) const override
See docs in base class: in this class this always returns 0.
One static instance of this struct should exist in any class implementing CLogOddsGridMap2D to hold t...
void computeEntropy(TEntropyInfo &info) const
Computes the entropy and related values of this grid map.
#define ASSERT_BELOW_(__A, __B)
Declares a virtual base class for all metric maps storage classes.
void fill(float default_value=0.5f)
Fills all the cells with a default value.
double I_change
The cummulative change in Information: This is updated only from the "updateCell" method.
float getPos(float x, float y) const
Read the real valued [0,1] contents of a cell, given its coordinates.
float x_min
The limits of the grid in "units" (meters)
void setSize(float x_min, float x_max, float y_min, float y_max, float resolution, float default_value=0.5f)
Change the size of gridmap, erasing all its previous contents.
double H
The target variable for absolute entropy, computed as:
int round(const T value)
Returns the closer integer (int) to x.
This class allows loading and storing values and vectors of different types from a configuration text...
int16_t cellType
The type of the map cells:
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
int x2idx(float x) const
Transform a coordinate value into a cell index.
bool derivedFrom(const TRuntimeClassId *pBaseClass) const
unsigned long effectiveMappedCells
The mapped area in cells.
double I
The target variable for absolute "information", defining I(x) = 1 - H(x)
int cellsUpdated
The cummulative updated cells count: This is updated only from the "updateCell" method.
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
double mean_H
The target variable for mean entropy, defined as entropy per cell: mean_H(map) = H(map) / (cells)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
std::vector< cellType > map
Store of cell occupancy values.
Parameters for the determination of matchings between point clouds, etc.
Used for returning entropy related information.
float resolution
Cell size, i.e.
static double H(double p)
Entropy computation internal function:
double effectiveMappedArea
The target variable for the area of cells with information, i.e.
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
float getResolution() const
Returns the resolution of the grid map.
void freeMap()
Frees the dynamic memory buffers of map.
uint16_t cellTypeUnsigned
mrpt::containers::CDynamicGrid< uint8_t > m_basis_map
Used for Voronoi calculation.Same struct as "map", but contains a "0" if not a basis point.
bool isEmpty() const override
Returns true upon map construction or after calling clear(), the return changes to false upon success...
virtual const mrpt::rtti::TRuntimeClassId * GetRuntimeClass() const override
Returns information about the class of an object in runtime.
float idx2x(const size_t cx) const
Transform a cell index into a coordinate value.
mrpt::containers::CDynamicGrid< uint16_t > m_voronoi_diagram
Used to store the Voronoi diagram.
This base provides a set of functions for maths stuff.
A class for storing an occupancy grid map.
void clear()
Erase the contents of all the cells.
GLsizei const GLchar ** string
void subSample(int downRatio)
Performs a downsampling of the gridmap, by a given factor: resolution/=ratio.
mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions likelihoodOpts
Probabilistic observation likelihood options.
void updateCell(int x, int y, float v)
Performs the Bayesian fusion of a new observation of a cell.
static const cellType OCCGRID_CELLTYPE_MAX
struct mrpt::maps::COccupancyGridMap2D::TUpdateCellsInfoChangeOnly updateInfoChangeOnly
void copyMapContentFrom(const COccupancyGridMap2D &otherMap)
copy the gridmap contents, but not all the options, from another map instance
float min_x
See COccupancyGridMap2D::COccupancyGridMap2D.
GLenum const GLfloat * params
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |