40 return img.saveToFile(file);
63 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 69 out << size_x << size_y << x_min << x_max << y_min << y_max << resolution;
70 ASSERT_(size_x*size_y==map.size());
72 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 73 out.
WriteBuffer(&map[0],
sizeof(map[0])*size_x*size_y);
79 out << insertionOptions.mapAltitude
80 << insertionOptions.useMapAltitude
81 << insertionOptions.maxDistanceInsertion
82 << insertionOptions.maxOccupancyUpdateCertainty
83 << insertionOptions.considerInvalidRangesAsFreeSpace
84 << insertionOptions.decimation
85 << insertionOptions.horizontalTolerance;
88 out << (
int32_t)likelihoodOptions.likelihoodMethod
89 << likelihoodOptions.LF_stdHit
90 << likelihoodOptions.LF_zHit
91 << likelihoodOptions.LF_zRandom
92 << likelihoodOptions.LF_maxRange
93 << likelihoodOptions.LF_decimation
94 << likelihoodOptions.LF_maxCorrsDistance
95 << likelihoodOptions.LF_alternateAverageMethod
96 << likelihoodOptions.MI_exponent
97 << likelihoodOptions.MI_skip_rays
98 << likelihoodOptions.MI_ratio_max_distance
99 << likelihoodOptions.rayTracing_useDistanceFilter
100 << likelihoodOptions.rayTracing_decimation
101 << likelihoodOptions.rayTracing_stdHit
102 << likelihoodOptions.consensus_takeEachRange
103 << likelihoodOptions.consensus_pow
104 << likelihoodOptions.OWA_weights
105 << likelihoodOptions.enableLikelihoodCache;
108 out << genericMapParams;
111 out << insertionOptions.CFD_features_gaussian_size
112 << insertionOptions.CFD_features_median_size;
115 out << insertionOptions.wideningBeamsWithDistance;
137 # ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 138 const uint8_t MyBitsPerCell = 8;
140 const uint8_t MyBitsPerCell = 16;
147 in >> bitsPerCellStream;
148 else bitsPerCellStream = MyBitsPerCell;
151 float new_x_min,new_x_max,new_y_min,new_y_max;
152 float new_resolution;
156 in >> new_size_x >> new_size_y >> new_x_min >> new_x_max >> new_y_min >> new_y_max >> new_resolution;
158 setSize(new_x_min,new_x_max,new_y_min,new_y_max,new_resolution,0.5);
160 ASSERT_(size_x*size_y==map.size());
162 if (bitsPerCellStream==MyBitsPerCell)
165 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 166 in.ReadBuffer(&map[0],
sizeof(map[0])*map.size());
168 in.ReadBufferFixEndianness(&map[0], map.size());
174 # ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS 176 ASSERT_(bitsPerCellStream==16);
177 std::vector<uint16_t> auxMap( map.size() );
178 in.ReadBuffer(&auxMap[0],
sizeof(auxMap[0])*auxMap.size());
180 size_t i, N = map.size();
184 *ptrTrg++ = (*ptrSrc++) >> 8;
188 std::vector<uint8_t> auxMap( map.size() );
189 in.ReadBuffer(&auxMap[0],
sizeof(auxMap[0])*auxMap.size());
191 size_t i, N = map.size();
195 *ptrTrg++ = (*ptrSrc++) << 8;
202 size_t i, N = map.size();
216 precomputedLikelihoodToBeRecomputed =
true;
221 in >> insertionOptions.mapAltitude
222 >> insertionOptions.useMapAltitude
223 >> insertionOptions.maxDistanceInsertion
224 >> insertionOptions.maxOccupancyUpdateCertainty
225 >> insertionOptions.considerInvalidRangesAsFreeSpace
226 >> insertionOptions.decimation
227 >> insertionOptions.horizontalTolerance;
232 in >> likelihoodOptions.LF_stdHit
233 >> likelihoodOptions.LF_zHit
234 >> likelihoodOptions.LF_zRandom
235 >> likelihoodOptions.LF_maxRange
236 >> likelihoodOptions.LF_decimation
237 >> likelihoodOptions.LF_maxCorrsDistance
238 >> likelihoodOptions.LF_alternateAverageMethod
239 >> likelihoodOptions.MI_exponent
240 >> likelihoodOptions.MI_skip_rays
241 >> likelihoodOptions.MI_ratio_max_distance
242 >> likelihoodOptions.rayTracing_useDistanceFilter
243 >> likelihoodOptions.rayTracing_decimation
244 >> likelihoodOptions.rayTracing_stdHit
245 >> likelihoodOptions.consensus_takeEachRange
246 >> likelihoodOptions.consensus_pow
247 >> likelihoodOptions.OWA_weights
248 >> likelihoodOptions.enableLikelihoodCache;
252 in >> genericMapParams;
255 bool disableSaveAs3DObject;
256 in >> disableSaveAs3DObject;
257 genericMapParams.enableSaveAs3DObject = !disableSaveAs3DObject;
263 in >> insertionOptions.CFD_features_gaussian_size
264 >> insertionOptions.CFD_features_median_size;
269 in >> insertionOptions.wideningBeamsWithDistance;
295 if (!imgFl.loadFromFile(file,0))
299 return loadFromBitmap(imgFl,resolution, xCentralPixel, yCentralPixel);
312 precomputedLikelihoodToBeRecomputed =
true;
317 if (size_x!=bmpWidth || size_y!=bmpHeight)
320 if (xCentralPixel<-1 || yCentralPixel<=-1)
322 xCentralPixel = imgFl.
getWidth() / 2.0f;
323 yCentralPixel = imgFl.
getHeight() / 2.0f;
327 float new_x_max = (imgFl.
getWidth() - xCentralPixel) * resolution;
328 float new_x_min = - xCentralPixel * resolution;
329 float new_y_max = (imgFl.
getHeight() - yCentralPixel) * resolution;
330 float new_y_min = - yCentralPixel * resolution;
332 setSize(new_x_min,new_x_max,new_y_min,new_y_max,resolution);
336 for (
size_t x=0;
x<bmpWidth;
x++)
337 for (
size_t y=0;
y<bmpHeight;
y++)
340 f = std::max(0.01f,f);
366 unsigned int i,
n , Ay1, Ay2;
373 unsigned int lx1 = img1.getWidth();
374 unsigned int ly1 = img1.getHeight();
376 unsigned int lx2 = img2.getWidth();
377 unsigned int ly2 = img2.getHeight();
394 img.resize(lx1 + lx2 + 1, max(ly1,ly2), 3,
true );
395 img.filledRectangle(0,0,
img.getWidth()-1,
img.getHeight()-1, TColor::black );
396 img.drawImage(0,Ay1,img1);
397 img.drawImage(lx1+1,Ay2,img2);
402 TColor lineColor = TColor::black;
406 px = m1->
x2idx( corrs[i].this_x );
407 py = Ay1+ly1-1- m1->
y2idx( corrs[i].this_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);
412 px = lx1+1 + m2->
x2idx( corrs[i].other_x );
413 py = Ay2+ly2-1- m2->
y2idx( corrs[i].other_y );
414 img.rectangle(px-10,py-10,px+10,py+10,lineColor);
415 img.rectangle(px-11,py-11,px+11,py+11,lineColor);
428 m1->
x2idx( corrs[i].this_x ),
430 Ay1+ly1-1- m1->
y2idx( corrs[i].this_y ),
431 lx1+1+ m2->
x2idx( corrs[i].other_x ),
432 Ay2+ly2-1-m2->
y2idx( corrs[i].other_y ),
436 return img.saveToFile(fileName.c_str() );
455 unsigned int i, Ay1, Ay2;
463 #ifdef MRPT_OS_WINDOWS 490 emf.drawImage(0,Ay1,img1);
491 emf.drawImage(lx1+1,Ay2,img2);
495 const unsigned int n = corrs.size();
496 lineColor = TColor::black;
500 px = m1->
x2idx( corrs[i].this_x );
501 py = Ay1+ly1-1- m1->
y2idx( corrs[i].this_y );
502 emf.rectangle(px-10,py-10,px+10,py+10,lineColor);
503 emf.rectangle(px-11,py-11,px+11,py+11,lineColor);
506 px = lx1+1 + m2->
x2idx( corrs[i].other_x );
507 py = Ay2+ly2-1- m2->
y2idx( corrs[i].other_y );
508 emf.rectangle(px-10,py-10,px+10,py+10,lineColor);
509 emf.rectangle(px-11,py-11,px+11,py+11,lineColor);
539 m1->
x2idx( corrs[i].this_x ) - 10 ,
540 Ay1+ly1-1- m1->
y2idx( corrs[i].this_y ) - 25,
541 str, TColor::black );
544 lx1+1+ m2->
x2idx( corrs[i].other_x ) - 10,
545 Ay2+ly2-1-m2->
y2idx( corrs[i].other_y ) - 25,
563 saveAsBitmapFile( fil );
571 LIMITS.saveToTextFile( fil,
MATRIX_FORMAT_FIXED,
false ,
"% 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.
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
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.
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
TLikelihoodMethod
The type for selecting a likelihood computation method.
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 writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
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.
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
#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).
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).
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
uint16_t cellTypeUnsigned
This class is a "CSerializable" wrapper for "CMatrixFloat".
unsigned __int32 uint32_t
int16_t cellType
The type of the map cells:
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels.
int x2idx(float x) const
Transform a coordinate value into a cell index.
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const MRPT_OVERRIDE
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >...
fixed floating point 'f'
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels.