40 return img.saveToFile(file);
53 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 59 out << size_x << size_y << x_min << x_max << y_min << y_max << resolution;
60 ASSERT_(size_x * size_y == map.size());
62 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 63 out.
WriteBuffer(&map[0],
sizeof(map[0]) * size_x * size_y);
69 out << insertionOptions.mapAltitude << insertionOptions.useMapAltitude
70 << insertionOptions.maxDistanceInsertion
71 << insertionOptions.maxOccupancyUpdateCertainty
72 << insertionOptions.considerInvalidRangesAsFreeSpace
73 << insertionOptions.decimation << insertionOptions.horizontalTolerance;
76 out << (
int32_t)likelihoodOptions.likelihoodMethod
77 << likelihoodOptions.LF_stdHit << likelihoodOptions.LF_zHit
78 << likelihoodOptions.LF_zRandom << likelihoodOptions.LF_maxRange
79 << likelihoodOptions.LF_decimation
80 << likelihoodOptions.LF_maxCorrsDistance
81 << likelihoodOptions.LF_alternateAverageMethod
82 << likelihoodOptions.MI_exponent << likelihoodOptions.MI_skip_rays
83 << likelihoodOptions.MI_ratio_max_distance
84 << likelihoodOptions.rayTracing_useDistanceFilter
85 << likelihoodOptions.rayTracing_decimation
86 << likelihoodOptions.rayTracing_stdHit
87 << likelihoodOptions.consensus_takeEachRange
88 << likelihoodOptions.consensus_pow << likelihoodOptions.OWA_weights
89 << likelihoodOptions.enableLikelihoodCache;
92 out << genericMapParams;
95 out << insertionOptions.CFD_features_gaussian_size
96 << insertionOptions.CFD_features_median_size;
99 out << insertionOptions.wideningBeamsWithDistance;
117 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 118 const uint8_t MyBitsPerCell = 8;
120 const uint8_t MyBitsPerCell = 16;
127 in >> bitsPerCellStream;
133 float new_x_min, new_x_max, new_y_min, new_y_max;
134 float new_resolution;
138 in >> new_size_x >> new_size_y >> new_x_min >> new_x_max >>
139 new_y_min >> new_y_max >> new_resolution;
142 new_x_min, new_x_max, new_y_min, new_y_max, new_resolution,
145 ASSERT_(size_x * size_y == map.size());
147 if (bitsPerCellStream == MyBitsPerCell)
150 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 151 in.ReadBuffer(&map[0],
sizeof(map[0]) * map.size());
153 in.ReadBufferFixEndianness(&map[0], map.size());
159 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 161 ASSERT_(bitsPerCellStream == 16);
162 std::vector<uint16_t> auxMap(map.size());
163 in.ReadBuffer(&auxMap[0],
sizeof(auxMap[0]) * auxMap.size());
165 size_t i, N = map.size();
168 for (i = 0; i < N; i++) *ptrTrg++ = (*ptrSrc++) >> 8;
171 ASSERT_(bitsPerCellStream == 8);
172 std::vector<uint8_t> auxMap(map.size());
173 in.ReadBuffer(&auxMap[0],
sizeof(auxMap[0]) * auxMap.size());
175 size_t i, N = map.size();
178 for (i = 0; i < N; i++) *ptrTrg++ = (*ptrSrc++) << 8;
186 size_t i, N = map.size();
188 for (i = 0; i < N; i++)
198 precomputedLikelihoodToBeRecomputed =
true;
203 in >> insertionOptions.mapAltitude >>
204 insertionOptions.useMapAltitude >>
205 insertionOptions.maxDistanceInsertion >>
206 insertionOptions.maxOccupancyUpdateCertainty >>
207 insertionOptions.considerInvalidRangesAsFreeSpace >>
208 insertionOptions.decimation >>
209 insertionOptions.horizontalTolerance;
214 likelihoodOptions.likelihoodMethod =
216 in >> likelihoodOptions.LF_stdHit >>
217 likelihoodOptions.LF_zHit >> likelihoodOptions.LF_zRandom >>
218 likelihoodOptions.LF_maxRange >>
219 likelihoodOptions.LF_decimation >>
220 likelihoodOptions.LF_maxCorrsDistance >>
221 likelihoodOptions.LF_alternateAverageMethod >>
222 likelihoodOptions.MI_exponent >>
223 likelihoodOptions.MI_skip_rays >>
224 likelihoodOptions.MI_ratio_max_distance >>
225 likelihoodOptions.rayTracing_useDistanceFilter >>
226 likelihoodOptions.rayTracing_decimation >>
227 likelihoodOptions.rayTracing_stdHit >>
228 likelihoodOptions.consensus_takeEachRange >>
229 likelihoodOptions.consensus_pow >>
230 likelihoodOptions.OWA_weights >>
231 likelihoodOptions.enableLikelihoodCache;
235 in >> genericMapParams;
238 bool disableSaveAs3DObject;
239 in >> disableSaveAs3DObject;
240 genericMapParams.enableSaveAs3DObject =
241 !disableSaveAs3DObject;
247 in >> insertionOptions.CFD_features_gaussian_size >>
248 insertionOptions.CFD_features_median_size;
253 in >> insertionOptions.wideningBeamsWithDistance;
278 if (!imgFl.loadFromFile(file, 0))
return false;
281 return loadFromBitmap(imgFl,
res, xCentralPixel, yCentralPixel);
296 precomputedLikelihoodToBeRecomputed =
true;
301 if (size_x != bmpWidth || size_y != bmpHeight)
304 if (xCentralPixel < -1 || yCentralPixel <= -1)
306 xCentralPixel = imgFl.
getWidth() / 2.0f;
307 yCentralPixel = imgFl.
getHeight() / 2.0f;
311 float new_x_max = (imgFl.
getWidth() - xCentralPixel) *
res;
312 float new_x_min = -xCentralPixel *
res;
313 float new_y_max = (imgFl.
getHeight() - yCentralPixel) *
res;
314 float new_y_min = -yCentralPixel *
res;
316 setSize(new_x_min, new_x_max, new_y_min, new_y_max,
res);
320 for (
size_t x = 0;
x < bmpWidth;
x++)
321 for (
size_t y = 0;
y < bmpHeight;
y++)
324 f = std::max(0.01f, f);
346 unsigned int i,
n, Ay1, Ay2;
353 unsigned int lx1 = img1.getWidth();
354 unsigned int ly1 = img1.getHeight();
356 unsigned int lx2 = img2.getWidth();
357 unsigned int ly2 = img2.getHeight();
363 Ay2 = (ly1 - ly2) / 2;
368 Ay1 = (ly2 - ly1) / 2;
373 img.resize(lx1 + lx2 + 1, max(ly1, ly2), 3,
true);
375 0, 0,
img.getWidth() - 1,
img.getHeight() - 1,
377 img.drawImage(0, Ay1, img1);
378 img.drawImage(lx1 + 1, Ay2, img2);
383 TColor lineColor = TColor::black();
384 for (i = 0; i <
n; i++)
387 px = m1->
x2idx(corrs[i].this_x);
388 py = Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y);
389 img.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
390 img.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
393 px = lx1 + 1 + m2->
x2idx(corrs[i].other_x);
394 py = Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y);
395 img.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
396 img.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
401 for (i = 0; i <
n; i++)
409 m1->
x2idx(corrs[i].this_x),
411 Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y),
412 lx1 + 1 + m2->
x2idx(corrs[i].other_x),
413 Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y), lineColor);
416 return img.saveToFile(fileName.c_str());
433 unsigned int i, Ay1, Ay2;
456 Ay2 = (ly1 - ly2) / 2;
461 Ay1 = (ly2 - ly1) / 2;
466 emf.drawImage(0, Ay1, img1);
467 emf.drawImage(lx1 + 1, Ay2, img2);
471 const unsigned int n = corrs.size();
472 lineColor = TColor::black();
473 for (i = 0; i <
n; i++)
476 px = m1->
x2idx(corrs[i].this_x);
477 py = Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y);
478 emf.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
479 emf.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
482 px = lx1 + 1 + m2->
x2idx(corrs[i].other_x);
483 py = Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y);
484 emf.rectangle(px - 10, py - 10, px + 10, py + 10, lineColor);
485 emf.rectangle(px - 11, py - 11, px + 11, py + 11, lineColor);
510 for (i = 0; i <
n; i++)
515 m1->
x2idx(corrs[i].this_x) - 10,
516 Ay1 + ly1 - 1 - m1->
y2idx(corrs[i].this_y) - 25, str,
520 lx1 + 1 + m2->
x2idx(corrs[i].other_x) - 10,
521 Ay2 + ly2 - 1 - m2->
y2idx(corrs[i].other_y) - 25, str,
537 saveAsBitmapFile(fil);
541 LIMITS(0, 0) = x_min;
542 LIMITS(0, 1) = x_max;
543 LIMITS(0, 2) = y_min;
544 LIMITS(0, 3) = y_max;
545 LIMITS.saveToTextFile(
547 "% Grid limits: [x_min x_max y_min y_max]\n");
A namespace of pseudo-random numbers generators of diferent distributions.
unsigned __int16 uint16_t
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >...
int16_t cellType
The type of the map cells:
TLikelihoodMethod
The type for selecting a likelihood computation method.
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
size_t getHeight() const override
Returns the height of the image in pixels.
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
static bool saveAsEMFTwoMapsWithCorrespondences(const std::string &fileName, const COccupancyGridMap2D *m1, const COccupancyGridMap2D *m2, const mrpt::tfest::TMatchingPairList &corrs)
Saves a composite image with two gridmaps and numbers for the correspondences between them...
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.
static bool saveAsBitmapTwoMapsWithCorrespondences(const std::string &fileName, const COccupancyGridMap2D *m1, const COccupancyGridMap2D *m2, const mrpt::tfest::TMatchingPairList &corrs)
Saves a composite image with two gridmaps and lines representing a set of correspondences between the...
uint16_t cellTypeUnsigned
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERT_(f)
Defines an assertion mechanism.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
bool saveAsBitmapFile(const std::string &file) const
Saves the gridmap as a graphical file (BMP,PNG,...).
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
bool loadFromBitmap(const mrpt::img::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).
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).
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...
A class for storing an occupancy grid map.
void getAsImage(mrpt::img::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 ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
This class is a "CSerializable" wrapper for "CMatrixFloat".
unsigned __int32 uint32_t
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Functions for estimating the optimal transformation between two frames of references given measuremen...
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'
A class for storing images as grayscale or RGB bitmaps.