39 return img.saveToFile(file);
61 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 67 out << size_x << size_y << x_min << x_max << y_min << y_max
69 ASSERT_(size_x * size_y == map.size());
71 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 72 out.
WriteBuffer(&map[0],
sizeof(map[0]) * size_x * size_y);
78 out << insertionOptions.mapAltitude << insertionOptions.useMapAltitude
79 << insertionOptions.maxDistanceInsertion
80 << insertionOptions.maxOccupancyUpdateCertainty
81 << insertionOptions.considerInvalidRangesAsFreeSpace
82 << insertionOptions.decimation
83 << insertionOptions.horizontalTolerance;
86 out << (
int32_t)likelihoodOptions.likelihoodMethod
87 << likelihoodOptions.LF_stdHit << likelihoodOptions.LF_zHit
88 << likelihoodOptions.LF_zRandom << likelihoodOptions.LF_maxRange
89 << likelihoodOptions.LF_decimation
90 << likelihoodOptions.LF_maxCorrsDistance
91 << likelihoodOptions.LF_alternateAverageMethod
92 << likelihoodOptions.MI_exponent << likelihoodOptions.MI_skip_rays
93 << likelihoodOptions.MI_ratio_max_distance
94 << likelihoodOptions.rayTracing_useDistanceFilter
95 << likelihoodOptions.rayTracing_decimation
96 << likelihoodOptions.rayTracing_stdHit
97 << likelihoodOptions.consensus_takeEachRange
98 << likelihoodOptions.consensus_pow << likelihoodOptions.OWA_weights
99 << likelihoodOptions.enableLikelihoodCache;
102 out << genericMapParams;
105 out << insertionOptions.CFD_features_gaussian_size
106 << insertionOptions.CFD_features_median_size;
109 out << insertionOptions.wideningBeamsWithDistance;
130 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 131 const uint8_t MyBitsPerCell = 8;
133 const uint8_t MyBitsPerCell = 16;
140 in >> bitsPerCellStream;
146 float new_x_min, new_x_max, new_y_min, new_y_max;
147 float new_resolution;
151 in >> new_size_x >> new_size_y >> new_x_min >> new_x_max >>
152 new_y_min >> new_y_max >> new_resolution;
155 new_x_min, new_x_max, new_y_min, new_y_max, new_resolution,
158 ASSERT_(size_x * size_y == map.size());
160 if (bitsPerCellStream == MyBitsPerCell)
163 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 164 in.ReadBuffer(&map[0],
sizeof(map[0]) * map.size());
166 in.ReadBufferFixEndianness(&map[0], map.size());
172 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 174 ASSERT_(bitsPerCellStream == 16);
175 std::vector<uint16_t> auxMap(map.size());
176 in.ReadBuffer(&auxMap[0],
sizeof(auxMap[0]) * auxMap.size());
178 size_t i, N = map.size();
181 for (i = 0; i < N; i++) *ptrTrg++ = (*ptrSrc++) >> 8;
184 ASSERT_(bitsPerCellStream == 8);
185 std::vector<uint8_t> auxMap(map.size());
186 in.ReadBuffer(&auxMap[0],
sizeof(auxMap[0]) * auxMap.size());
188 size_t i, N = map.size();
191 for (i = 0; i < N; i++) *ptrTrg++ = (*ptrSrc++) << 8;
199 size_t i, N = map.size();
201 for (i = 0; i < N; i++)
211 precomputedLikelihoodToBeRecomputed =
true;
216 in >> insertionOptions.mapAltitude >>
217 insertionOptions.useMapAltitude >>
218 insertionOptions.maxDistanceInsertion >>
219 insertionOptions.maxOccupancyUpdateCertainty >>
220 insertionOptions.considerInvalidRangesAsFreeSpace >>
221 insertionOptions.decimation >>
222 insertionOptions.horizontalTolerance;
227 likelihoodOptions.likelihoodMethod =
229 in >> likelihoodOptions.LF_stdHit >>
230 likelihoodOptions.LF_zHit >> likelihoodOptions.LF_zRandom >>
231 likelihoodOptions.LF_maxRange >>
232 likelihoodOptions.LF_decimation >>
233 likelihoodOptions.LF_maxCorrsDistance >>
234 likelihoodOptions.LF_alternateAverageMethod >>
235 likelihoodOptions.MI_exponent >>
236 likelihoodOptions.MI_skip_rays >>
237 likelihoodOptions.MI_ratio_max_distance >>
238 likelihoodOptions.rayTracing_useDistanceFilter >>
239 likelihoodOptions.rayTracing_decimation >>
240 likelihoodOptions.rayTracing_stdHit >>
241 likelihoodOptions.consensus_takeEachRange >>
242 likelihoodOptions.consensus_pow >>
243 likelihoodOptions.OWA_weights >>
244 likelihoodOptions.enableLikelihoodCache;
248 in >> genericMapParams;
251 bool disableSaveAs3DObject;
252 in >> disableSaveAs3DObject;
253 genericMapParams.enableSaveAs3DObject =
254 !disableSaveAs3DObject;
260 in >> insertionOptions.CFD_features_gaussian_size >>
261 insertionOptions.CFD_features_median_size;
266 in >> insertionOptions.wideningBeamsWithDistance;
285 const std::string& file,
float resolution,
float xCentralPixel,
291 if (!imgFl.loadFromFile(file, 0))
return false;
294 return loadFromBitmap(imgFl, resolution, xCentralPixel, yCentralPixel);
309 precomputedLikelihoodToBeRecomputed =
true;
314 if (size_x != bmpWidth || size_y != bmpHeight)
317 if (xCentralPixel < -1 || yCentralPixel <= -1)
319 xCentralPixel = imgFl.
getWidth() / 2.0f;
320 yCentralPixel = imgFl.
getHeight() / 2.0f;
324 float new_x_max = (imgFl.
getWidth() - xCentralPixel) * resolution;
325 float new_x_min = -xCentralPixel * resolution;
326 float new_y_max = (imgFl.
getHeight() - yCentralPixel) * resolution;
327 float new_y_min = -yCentralPixel * resolution;
329 setSize(new_x_min, new_x_max, new_y_min, new_y_max, resolution);
333 for (
size_t x = 0;
x < bmpWidth;
x++)
334 for (
size_t y = 0;
y < bmpHeight;
y++)
337 f = std::max(0.01f, f);
359 unsigned int i,
n, Ay1, Ay2;
366 unsigned int lx1 = img1.getWidth();
367 unsigned int ly1 = img1.getHeight();
369 unsigned int lx2 = img2.getWidth();
370 unsigned int ly2 = img2.getHeight();
376 Ay2 = (ly1 - ly2) / 2;
381 Ay1 = (ly2 - ly1) / 2;
386 img.resize(lx1 + lx2 + 1, max(ly1, ly2), 3,
true);
388 0, 0,
img.getWidth() - 1,
img.getHeight() - 1,
390 img.drawImage(0, Ay1, img1);
391 img.drawImage(lx1 + 1, Ay2, img2);
396 TColor lineColor = TColor::black();
397 for (i = 0; i <
n; i++)
400 px = m1->
x2idx(corrs[i].this_x);
401 py = Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y);
402 img.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
403 img.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
406 px = lx1 + 1 + m2->
x2idx(corrs[i].other_x);
407 py = Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y);
408 img.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
409 img.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
414 for (i = 0; i <
n; i++)
422 m1->
x2idx(corrs[i].this_x),
424 Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y),
425 lx1 + 1 + m2->
x2idx(corrs[i].other_x),
426 Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y), lineColor);
429 return img.saveToFile(fileName.c_str());
446 unsigned int i, Ay1, Ay2;
453 #ifdef MRPT_OS_WINDOWS 469 Ay2 = (ly1 - ly2) / 2;
474 Ay1 = (ly2 - ly1) / 2;
479 emf.drawImage(0, Ay1, img1);
480 emf.drawImage(lx1 + 1, Ay2, img2);
484 const unsigned int n = corrs.size();
485 lineColor = TColor::black();
486 for (i = 0; i <
n; i++)
489 px = m1->
x2idx(corrs[i].this_x);
490 py = Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y);
491 emf.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
492 emf.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
495 px = lx1 + 1 + m2->
x2idx(corrs[i].other_x);
496 py = Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y);
497 emf.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
498 emf.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
523 for (i = 0; i <
n; i++)
528 m1->
x2idx(corrs[i].this_x) - 10,
529 Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y) - 25, str,
533 lx1 + 1 + m2->
x2idx(corrs[i].other_x) - 10,
534 Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y) - 25, str,
550 saveAsBitmapFile(fil);
554 LIMITS(0, 0) = x_min;
555 LIMITS(0, 1) = x_max;
556 LIMITS(0, 2) = y_min;
557 LIMITS(0, 3) = y_max;
558 LIMITS.saveToTextFile(
560 "% Grid limits: [x_min x_max y_min y_max]\n");
A namespace of pseudo-random numbers genrators of diferent distributions.
float getAsFloat(unsigned int col, unsigned int row, unsigned int channel) const
Returns the contents of a given pixel at the desired channel, in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
unsigned __int16 uint16_t
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
static bool saveAsBitmapTwoMapsWithCorrespondences(const std::string &fileName, const COccupancyGridMap2D *m1, const COccupancyGridMap2D *m2, const mrpt::utils::TMatchingPairList &corrs)
Saves a composite image with two gridmaps and lines representing a set of correspondences between the...
A class for storing images as grayscale or RGB bitmaps.
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >...
TLikelihoodMethod
The type for selecting a likelihood computation method.
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
void getAsImage(utils::CImage &img, bool verticalFlip=false, bool forceRGB=false, bool tricolor=false) const
Returns the grid as a 8-bit graylevel image, where each pixel is a cell (output image is RGB only if ...
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
bool saveAsBitmapFile(const std::string &file) const
Saves the gridmap as a graphical file (BMP,PNG,...).
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
bool loadFromBitmapFile(const std::string &file, float resolution, float xCentralPixel=-1, float yCentralPixel=-1)
Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
size_t getHeight() const override
Returns the height of the image in pixels.
This namespace contains representation of robot actions and observations.
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
static bool saveAsEMFTwoMapsWithCorrespondences(const std::string &fileName, const COccupancyGridMap2D *m1, const COccupancyGridMap2D *m2, const mrpt::utils::TMatchingPairList &corrs)
Saves a composite image with two gridmaps and numbers for the correspondences between them...
A class for storing an occupancy grid map.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool loadFromBitmap(const mrpt::utils::CImage &img, float resolution, float xCentralPixel=-1, float yCentralPixel=-1)
Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
uint16_t cellTypeUnsigned
This class is a "CSerializable" wrapper for "CMatrixFloat".
unsigned __int32 uint32_t
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
int16_t cellType
The type of the map cells:
int x2idx(float x) const
Transform a coordinate value into a cell index.
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
fixed floating point 'f'