YARP
Yet Another Robot Platform
MapGrid2D.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #define _USE_MATH_DEFINES
10 
11 #include <yarp/dev/MapGrid2D.h>
12 
13 #include <yarp/os/Bottle.h>
16 #include <yarp/os/LogStream.h>
17 #include <yarp/sig/ImageFile.h>
18 #include <algorithm>
19 #include <fstream>
20 #include <cmath>
21 
22 using namespace yarp::dev;
23 using namespace yarp::dev::Nav2D;
24 using namespace yarp::sig;
25 using namespace yarp::os;
26 using namespace yarp::math;
27 using namespace std;
28 
29 #ifndef DEG2RAD
30 #define DEG2RAD M_PI/180.0
31 #endif
32 
33 #ifndef RAD2DEG
34 #define RAD2DEG 180.0/M_PI
35 #endif
36 
37 //helper functions
38 string extractPathFromFile(string full_filename)
39 {
40  size_t found;
41  found = full_filename.find_last_of('/');
42  if (found != string::npos) return full_filename.substr(0, found)+"/";
43  found = full_filename.find_last_of('\\');
44  if (found != string::npos) return full_filename.substr(0, found)+"\\";
45  return full_filename;
46 }
47 
48 string extractExtensionFromFile(string full_filename)
49 {
50  int start = full_filename.length() - 3;
51  return full_filename.substr(start, 3);
52 }
53 
54 
55 bool MapGrid2D::isIdenticalTo(const MapGrid2D& other) const
56 {
57  if (m_map_name != other.m_map_name) return false;
58  if (m_origin != other.m_origin) return false;
59  if (m_resolution != other.m_resolution) return false;
60  if (m_width != other.width()) return false;
61  if (m_height != other.height()) return false;
62  for (size_t y = 0; y < m_height; y++) for (size_t x = 0; x < m_width; x++)
63  if (m_map_occupancy.safePixel(x, y) != other.m_map_occupancy.safePixel(x, y)) return false;
64  for (size_t y = 0; y < m_height; y++) for (size_t x = 0; x < m_width; x++)
65  if (m_map_flags.safePixel(x, y) != other.m_map_flags.safePixel(x, y)) return false;
66  return true;
67 }
68 
70 {
71  m_resolution = 1.0; //each pixel corresponds to 1 m
72  m_width = 2;
73  m_height = 2;
74  m_map_occupancy.setQuantum(1); //we do not want extra padding in map images
75  m_map_flags.setQuantum(1);
76  m_map_occupancy.resize(m_width, m_height);
77  m_map_flags.resize(m_width, m_height);
78  m_occupied_thresh = 0.80;
79  m_free_thresh = 0.20;
80  for (size_t y = 0; y < m_height; y++)
81  {
82  for (size_t x = 0; x < m_width; x++)
83  {
84  m_map_occupancy.safePixel(x, y) = 0;
85  m_map_flags.safePixel(x, y) = MapGrid2D::map_flags::MAP_CELL_FREE;
86  }
87  }
88 }
89 
90 MapGrid2D::~MapGrid2D() = default;
91 
92 bool MapGrid2D::isNotFree(XYCell cell) const
93 {
94  if (isInsideMap(cell))
95  {
96  if (m_map_occupancy.safePixel(cell.x, cell.y) != 0) return true;
97  if (m_map_flags.safePixel(cell.x, cell.y) == MapGrid2D::map_flags::MAP_CELL_KEEP_OUT) return true;
98  if (m_map_flags.safePixel(cell.x, cell.y) == MapGrid2D::map_flags::MAP_CELL_TEMPORARY_OBSTACLE) return true;
99  if (m_map_flags.safePixel(cell.x, cell.y) == MapGrid2D::map_flags::MAP_CELL_ENLARGED_OBSTACLE) return true;
100  }
101  return false;
102 }
103 
104 bool MapGrid2D::isFree(XYCell cell) const
105 {
106  if (isInsideMap(cell))
107  {
108  if (m_map_occupancy.safePixel(cell.x, cell.y) == 0 &&
109  m_map_flags.safePixel(cell.x, cell.y) == MapGrid2D::map_flags::MAP_CELL_FREE)
110  return true;
111  }
112  return false;
113 }
114 
115 bool MapGrid2D::isKeepOut(XYCell cell) const
116 {
117  if (isInsideMap(cell))
118  {
119  if (m_map_flags.safePixel(cell.x, cell.y) == MapGrid2D::map_flags::MAP_CELL_KEEP_OUT)
120  return true;
121  }
122  return false;
123 }
124 
125 bool MapGrid2D::isWall(XYCell cell) const
126 {
127  if (isInsideMap(cell))
128  {
129  // if (m_map_occupancy.safePixel(cell.x, cell.y) == 0)
130  // return true;
131  if (m_map_flags.safePixel(cell.x, cell.y) == MapGrid2D::map_flags::MAP_CELL_WALL)
132  return true;
133  }
134  return false;
135 }
136 
137 size_t MapGrid2D::height() const
138 {
139  return m_height;
140 }
141 
142 size_t MapGrid2D::width() const
143 {
144  return m_width;
145 }
146 
148 {
149  image.setQuantum(1);
150  image.resize(m_width, m_height);
151  image.zero();
152  for (size_t y = 0; y < m_height; y++)
153  {
154  for (size_t x = 0; x < m_width; x++)
155  {
156  image.safePixel(x, y) = CellDataToPixel(m_map_flags.safePixel(x, y));
157  }
158  }
159  return true;
160 }
161 
163 {
164  if (image.width() != m_width ||
165  image.height() != m_height)
166  {
167  yError() << "The size of given iamge does not correspond to the current map. Use method setSize() first.";
168  return false;
169  }
170  for (size_t y = 0; y < m_height; y++)
171  {
172  for (size_t x = 0; x < m_width; x++)
173  {
174  m_map_flags.safePixel(x, y) = PixelToCellData(image.safePixel(x, y));
175  }
176  }
177  return true;
178 }
179 
181 {
182  if (size <= 0)
183  {
184  for (size_t y = 0; y < m_height; y++)
185  {
186  for (size_t x = 0; x < m_width; x++)
187  {
188  if (this->m_map_flags.safePixel(x, y) == MapGrid2D::map_flags::MAP_CELL_ENLARGED_OBSTACLE)
189  {
190  this->m_map_flags.safePixel(x, y) = MapGrid2D::map_flags::MAP_CELL_FREE;
191  }
192  }
193  }
194  return true;
195  }
196  auto repeat_num = (size_t)(std::ceil(size/ m_resolution));
197  for (size_t repeat = 0; repeat < repeat_num; repeat++)
198  {
199  //contains the cells to be enlarged;
200  std::vector<XYCell> list_of_cells;
201  for (size_t y = 0; y < m_height; y++)
202  {
203  for (size_t x = 0; x < m_width; x++)
204  {
205  //this check could be optimized...
206  if (this->m_map_flags.safePixel(x, y) == MAP_CELL_KEEP_OUT ||
207  this->m_map_flags.safePixel(x, y) == MAP_CELL_ENLARGED_OBSTACLE ||
208  this->m_map_flags.safePixel(x, y) == MAP_CELL_WALL ||
209  this->m_map_flags.safePixel(x, y) == MAP_CELL_UNKNOWN ||
210  this->m_map_flags.safePixel(x, y) == MAP_CELL_TEMPORARY_OBSTACLE)
211  {
212  list_of_cells.emplace_back(x, y);
213  }
214  }
215  }
216 
217  //process each cell of the list and enlarges it
218  for (auto& list_of_cell : list_of_cells)
219  {
220  enlargeCell(list_of_cell);
221  }
222  }
223  return true;
224 }
225 
226 void MapGrid2D::enlargeCell(XYCell cell)
227 {
228  size_t i = cell.x;
229  size_t j = cell.y;
230  size_t il = cell.x > 1 ? cell.x - 1 : 0;
231  size_t ir = cell.x + 1 < (m_width)-1 ? cell.x + 1 : (m_width)-1;
232  size_t ju = cell.y > 1 ? cell.y - 1 : 0;
233  size_t jd = cell.y + 1 < (m_height)-1 ? cell.y + 1 : (m_height)-1;
234 
235  if (m_map_flags.pixel(il, j) == MAP_CELL_FREE) m_map_flags.pixel(il, j) = MAP_CELL_ENLARGED_OBSTACLE;
236  if (m_map_flags.pixel(ir, j) == MAP_CELL_FREE) m_map_flags.pixel(ir, j) = MAP_CELL_ENLARGED_OBSTACLE;
237  if (m_map_flags.pixel(i, ju) == MAP_CELL_FREE) m_map_flags.pixel(i, ju) = MAP_CELL_ENLARGED_OBSTACLE;
238  if (m_map_flags.pixel(i, jd) == MAP_CELL_FREE) m_map_flags.pixel(i, jd) = MAP_CELL_ENLARGED_OBSTACLE;
239  if (m_map_flags.pixel(il, ju) == MAP_CELL_FREE) m_map_flags.pixel(il, ju) = MAP_CELL_ENLARGED_OBSTACLE;
240  if (m_map_flags.pixel(il, jd) == MAP_CELL_FREE) m_map_flags.pixel(il, jd) = MAP_CELL_ENLARGED_OBSTACLE;
241  if (m_map_flags.pixel(ir, ju) == MAP_CELL_FREE) m_map_flags.pixel(ir, ju) = MAP_CELL_ENLARGED_OBSTACLE;
242  if (m_map_flags.pixel(ir, jd) == MAP_CELL_FREE) m_map_flags.pixel(ir, jd) = MAP_CELL_ENLARGED_OBSTACLE;
243 }
244 
245 bool MapGrid2D::loadROSParams(string ros_yaml_filename, string& pgm_occ_filename, double& resolution, double& orig_x, double& orig_y, double& orig_t )
246 {
247  std::string file_string;
248  std::ifstream file;
249  file.open(ros_yaml_filename.c_str());
250  if (!file.is_open())
251  {
252  yError() << "failed to open file" << ros_yaml_filename;
253  return false;
254  }
255 
256  string line;
257  while (getline(file, line))
258  {
259  if (line.find("origin") != std::string::npos)
260  {
261  std::replace(line.begin(), line.end(), ',', ' ');
262  std::replace(line.begin(), line.end(), '[', '(');
263  std::replace(line.begin(), line.end(), ']', ')');
264  /*
265  auto it = line.find('[');
266  if (it != string::npos) line.replace(it, 1, "(");
267  it = line.find(']');
268  if(it != string::npos) line.replace(it, 1, ")");*/
269  }
270  file_string += (line + '\n');
271  }
272  file.close();
273 
274  bool ret = true;
275  Bottle bbb;
276  bbb.fromString(file_string);
277  string debug_s = bbb.toString();
278 
279  if (bbb.check("image:") == false) { yError() << "missing image"; ret = false; }
280  pgm_occ_filename = bbb.find("image:").asString();
281  //ppm_flg_filename = (pgm_occ_filename.substr(0, pgm_occ_filename.size()-4))+"_yarpflags"+".ppm";
282 
283  if (bbb.check("resolution:") == false) { yError() << "missing resolution"; ret = false; }
284  resolution = bbb.find("resolution:").asFloat64();
285 
286  if (bbb.check("origin:") == false) { yError() << "missing origin"; ret = false; }
287  Bottle* b = bbb.find("origin:").asList();
288  if (b)
289  {
290  orig_x = b->get(0).asFloat64();
291  orig_y = b->get(1).asFloat64();
292  orig_t = b->get(2).asFloat64() * RAD2DEG;
293  }
294 
295  if (bbb.check("occupied_thresh:"))
296  {m_occupied_thresh = bbb.find("occupied_thresh:").asFloat64();}
297 
298  if (bbb.check("free_thresh:"))
299  {m_free_thresh = bbb.find("free_thresh:").asFloat64();}
300 
301  return ret;
302 }
303 
304 bool MapGrid2D::loadMapYarpAndRos(string yarp_filename, string ros_yaml_filename)
305 {
308  bool b1 = yarp::sig::file::read(yarp_img, yarp_filename);
309  if (b1 == false)
310  {
311  yError() << "Unable to load map data" << yarp_filename;
312  return false;
313  }
314  string pgm_occ_filename;
315  double resolution=0;
316  double orig_x = 0;
317  double orig_y = 0;
318  double orig_t = 0;
319  bool b2 = loadROSParams(ros_yaml_filename, pgm_occ_filename, resolution, orig_x, orig_y, orig_t);
320  if (b2 == false)
321  {
322  yError() << "Unable to ros params from" << ros_yaml_filename;
323  return false;
324  }
325  string path = extractPathFromFile(ros_yaml_filename);
326  string extension = extractExtensionFromFile(pgm_occ_filename);
327  string pgm_occ_filename_with_path = path + pgm_occ_filename;
328  bool b3 = yarp::sig::file::read(ros_img, pgm_occ_filename_with_path);
329  if (b3 == false)
330  {
331  yError() << "Unable to load occupancy grid file:" << pgm_occ_filename_with_path;
332  return false;
333  }
334 
335  if (yarp_img.width() == ros_img.width() && yarp_img.height() == ros_img.height())
336  {
337  //Everything ok, proceed to internal assignments
338  setSize_in_cells(yarp_img.width(), yarp_img.height());
339  m_resolution = resolution;
340  m_origin.setOrigin(orig_x,orig_y,orig_t);
341 
342  //set YARPS stuff
343  for (size_t y = 0; y < m_height; y++)
344  {
345  for (size_t x = 0; x < m_width; x++)
346  {
347  m_map_flags.safePixel(x, y) = PixelToCellData(yarp_img.safePixel(x, y));
348  }
349  }
350 
351  //set ROS Stuff
352  for (size_t y = 0; y < m_height; y++)
353  {
354  for (size_t x = 0; x < m_width; x++)
355  {
356  yarp::sig::PixelRgb pix_occ = ros_img.safePixel(x, y);
357  if (pix_occ.r == 205 && pix_occ.g == 205 && pix_occ.b == 205)
358  {
359  //m_map_occupancy.safePixel(x, y) = -1;
360  m_map_occupancy.safePixel(x, y) = 255;
361  }
362  else
363  {
364  int color_avg = (pix_occ.r + pix_occ.g + pix_occ.b) / 3;
365  auto occ = (unsigned char)((254 - color_avg) / 254.0);
366  m_map_occupancy.safePixel(x, y) = occ * 100;
367  }
368  }
369  }
370  }
371  else
372  {
373  yError() << "MapGrid2D::loadFromFile() Size of YARP map and ROS do not match";
374  return false;
375  }
376 
377  return true;
378 }
379 
380 bool MapGrid2D::loadMapROSOnly(string ros_yaml_filename)
381 {
383  string pgm_occ_filename;
384  double resolution = 0;
385  double orig_x = 0;
386  double orig_y = 0;
387  double orig_t = 0;
388  bool b2 = loadROSParams(ros_yaml_filename, pgm_occ_filename, resolution, orig_x, orig_y, orig_t);
389  if (b2 == false)
390  {
391  yError() << "Unable to ros params from" << ros_yaml_filename;
392  return false;
393  }
394  string path = extractPathFromFile(ros_yaml_filename);
395  string extension = extractExtensionFromFile(pgm_occ_filename);
396  string pgm_occ_filename_with_path = path + pgm_occ_filename;
397  bool b3 = yarp::sig::file::read(ros_img, pgm_occ_filename_with_path);
398  if (b3 == false)
399  {
400  yError() << "Unable to load occupancy grid file:" << pgm_occ_filename;
401  return false;
402  }
403 
404  //Everything ok, proceed to internal assignments
405  setSize_in_cells(ros_img.width(), ros_img.height());
406  m_resolution = resolution;
407  m_origin.setOrigin(orig_x, orig_y, orig_t);
408 
409  //set ROS Stuff
410  for (size_t y = 0; y < m_height; y++)
411  {
412  for (size_t x = 0; x < m_width; x++)
413  {
414  yarp::sig::PixelRgb pix_occ = ros_img.safePixel(x, y);
415  if (pix_occ.r == 205 && pix_occ.g == 205 && pix_occ.b == 205)
416  {
417  //m_map_occupancy.safePixel(x, y) = -1;
418  m_map_occupancy.safePixel(x, y) = 255;
419  }
420  else
421  {
422  int color_avg = (pix_occ.r + pix_occ.g + pix_occ.b) / 3;
423  auto occ = (unsigned char)((254 - color_avg) / 254.0);
424  m_map_occupancy.safePixel(x, y) = occ * 100;
425  }
426  }
427  }
428 
429  //generate YARP stuff from ROS Stuff
430  for (size_t y = 0; y < (size_t)(m_map_occupancy.height()); y++)
431  {
432  for (size_t x = 0; x < (size_t)(m_map_occupancy.width()); x++)
433  {
434  yarp::sig::PixelMono pix_occ = m_map_occupancy.safePixel(x, y);
435  if (pix_occ == 0) m_map_flags.safePixel(x, y) = MAP_CELL_FREE;
436  else if (pix_occ >= 200) m_map_flags.safePixel(x, y) = MAP_CELL_WALL;
437  else m_map_flags.safePixel(x, y) = MAP_CELL_UNKNOWN;
438  }
439  }
440  return true;
441 }
442 
443 bool MapGrid2D::loadMapYarpOnly(string yarp_filename)
444 {
446  bool b1 = yarp::sig::file::read(yarp_img, yarp_filename);
447  if (b1 == false)
448  {
449  yError() << "Unable to load map" << yarp_filename;
450  return false;
451  }
452  //Everything ok, proceed to internal assignments
453  setSize_in_cells(yarp_img.width(), yarp_img.height());
454  //m_resolution = resolution; //????
455  //m_origin.x = orig_x; //????
456  //m_origin.y = orig_y; //????
457  //m_origin.theta = orig_t; //????
458 
459  //set YARPS stuff
460  for (size_t y = 0; y < m_height; y++)
461  {
462  for (size_t x = 0; x < m_width; x++)
463  {
464  m_map_flags.safePixel(x, y) = PixelToCellData(yarp_img.safePixel(x, y));
465  }
466  }
467 
468  //generate ROS stuff from YARP Stuff
469  for (size_t y = 0; y < (size_t)(m_map_flags.height()); y++)
470  {
471  for (size_t x = 0; x < (size_t)(m_map_flags.width()); x++)
472  {
473  yarp::sig::PixelMono pix_flg = m_map_flags.safePixel(x, y);
474 
475  if (pix_flg == MAP_CELL_FREE) m_map_occupancy.safePixel(x, y) = 0;//@@@SET HERE
476  else if (pix_flg == MAP_CELL_KEEP_OUT) m_map_occupancy.safePixel(x, y) = 0;//@@@SET HERE
477  else if (pix_flg == MAP_CELL_TEMPORARY_OBSTACLE) m_map_occupancy.safePixel(x, y) = 0;//@@@SET HERE
478  else if (pix_flg == MAP_CELL_ENLARGED_OBSTACLE) m_map_occupancy.safePixel(x, y) = 0;//@@@SET HERE
479  else if (pix_flg == MAP_CELL_WALL) m_map_occupancy.safePixel(x, y) = 100;//@@@SET HERE
480  else if (pix_flg == MAP_CELL_UNKNOWN) m_map_occupancy.safePixel(x, y) = 255;//@@@SET HERE
481  else m_map_occupancy.safePixel(x, y) = 255;//@@@SET HERE
482  }
483  }
484  m_occupied_thresh = 0.80; //@@@SET HERE
485  m_free_thresh = 0.20;//@@@SET HERE
486  return true;
487 }
488 
489 bool MapGrid2D::parseMapParameters(const Property& mapfile)
490 {
491  //Map parameters.
492  //these values can eventually override values previously assigned
493  //(e.g. ROS values found in yaml data)
494  if (mapfile.check("resolution"))
495  {
496  m_resolution = mapfile.find("resolution").asFloat32();
497  }
498  if (mapfile.check("origin"))
499  {
500  Bottle* b = mapfile.find("origin").asList();
501  if (b)
502  {
503  m_origin.setOrigin(b->get(0).asFloat32(),
504  b->get(1).asFloat32(),
505  b->get(2).asFloat32());
506  }
507  }
508 
509  return true;
510 }
511 
512 bool MapGrid2D::loadFromFile(std::string map_file_with_path)
513 {
514  Property mapfile_prop;
515  string mapfile_path = extractPathFromFile(map_file_with_path);
516  if (mapfile_prop.fromConfigFile(map_file_with_path) == false)
517  {
518  yError() << "Unable to open .map description file:" << map_file_with_path;
519  return false;
520  }
521 
522  if (mapfile_prop.check("MapName") ==false)
523  {
524  yError() << "Unable to find 'MapName' parameter inside:" << map_file_with_path;
525  return false;
526  }
527  m_map_name = mapfile_prop.find("MapName").asString();
528 
529  bool YarpMapDataFound = false;
530  string ppm_flg_filename;
531  if (mapfile_prop.check("YarpMapData") == false)
532  {
533  yWarning() << "Unable to find 'YarpMapData' parameter inside:" << map_file_with_path;
534  YarpMapDataFound = false;
535  }
536  else
537  {
538  ppm_flg_filename = mapfile_prop.find("YarpMapData").asString();
539  YarpMapDataFound = true;
540  }
541 
542  bool RosMapDataFound = false;
543  string yaml_filename;
544  if (mapfile_prop.check("RosMapData") == false)
545  {
546  yWarning() << "Unable to find 'RosMapData' parameter inside:" << map_file_with_path;
547  RosMapDataFound = false;
548  }
549  else
550  {
551  yaml_filename = mapfile_prop.find("RosMapData").asString();
552  RosMapDataFound = true;
553  }
554 
555  m_width = -1;
556  m_height = -1;
557  string yarp_flg_filename_with_path = mapfile_path + ppm_flg_filename;
558  string ros_yaml_filename_with_path = mapfile_path + yaml_filename;
559  if (YarpMapDataFound && RosMapDataFound)
560  {
561  //yarp and ros
562  yDebug() << "Opening files: "<< yarp_flg_filename_with_path << " and " << ros_yaml_filename_with_path;
563  return this->loadMapYarpAndRos(yarp_flg_filename_with_path, ros_yaml_filename_with_path) &&
564  this->parseMapParameters(mapfile_prop);
565  }
566  else if (!YarpMapDataFound && RosMapDataFound)
567  {
568  //only ros
569  yDebug() << "Opening file:" << ros_yaml_filename_with_path;
570  return this->loadMapROSOnly(ros_yaml_filename_with_path) &&
571  this->parseMapParameters(mapfile_prop);
572  }
573  else if (YarpMapDataFound && !RosMapDataFound)
574  {
575  //only yarp
576  yDebug() << "Opening file:" << yarp_flg_filename_with_path;
577  return this->loadMapYarpOnly(yarp_flg_filename_with_path) &&
578  this->parseMapParameters(mapfile_prop);
579  }
580  else
581  {
582  yError() << "Critical error: unable to find neither 'RosMapData' nor 'YarpMapData' inside:" << map_file_with_path;
583  return false;
584  }
585  return true;
586 }
587 
588 MapGrid2D::CellData MapGrid2D::PixelToCellData(const yarp::sig::PixelRgb& pixin) const
589 {
590  if (pixin.r == 0 && pixin.g == 0 && pixin.b == 0) return MAP_CELL_WALL;
591  else if (pixin.r == 205 && pixin.g == 205 && pixin.b == 205) return MAP_CELL_UNKNOWN;
592  else if (pixin.r == 254 && pixin.g == 254 && pixin.b == 254) return MAP_CELL_FREE;
593  else if (pixin.r == 255 && pixin.g == 0 && pixin.b == 0) return MAP_CELL_KEEP_OUT;
594  return MAP_CELL_UNKNOWN;
595 }
596 
597 yarp::sig::PixelRgb MapGrid2D::CellDataToPixel(const MapGrid2D::CellData& pixin) const
598 {
599  yarp::sig::PixelRgb pixout_flg;
600  if (pixin == MAP_CELL_WALL) { pixout_flg.r = 0; pixout_flg.g = 0; pixout_flg.b = 0;}
601  else if (pixin == MAP_CELL_UNKNOWN) { pixout_flg.r = 205; pixout_flg.g = 205; pixout_flg.b = 205; }
602  else if (pixin == MAP_CELL_FREE) { pixout_flg.r = 254; pixout_flg.g = 254; pixout_flg.b = 254; }
603  else if (pixin == MAP_CELL_KEEP_OUT) { pixout_flg.r = 255; pixout_flg.g = 0; pixout_flg.b = 0; }
604  else if (pixin == MAP_CELL_ENLARGED_OBSTACLE) { pixout_flg.r = 255; pixout_flg.g = 200; pixout_flg.b = 0; }
605  else if (pixin == MAP_CELL_TEMPORARY_OBSTACLE) { pixout_flg.r = 100; pixout_flg.g = 100; pixout_flg.b = 200; }
606  else
607  {
608  //invalid
609  pixout_flg.r = 200; pixout_flg.g = 0; pixout_flg.b = 200;
610  }
611  return pixout_flg;
612 }
613 
614 bool MapGrid2D::crop (int left, int top, int right, int bottom)
615 {
616  if (top < 0)
617  {
618  for (size_t j=0;j<height();j++){
619  for (size_t i=0;i<width();i++){
620  yarp::sig::PixelMono pix = m_map_occupancy.safePixel(i,j);
621  if ( pix != 255)
622  {
623  top = j;
624  goto topFound;
625  }
626  }
627  }
628  }
629  topFound:
630 
631  if (bottom < 0)
632  {
633  for (int j=height()-1; j>0; j--){
634  for (int i=width()-1; i>0 ;i--){
635  yarp::sig::PixelMono pix = m_map_occupancy.safePixel(i,j);
636  if ( pix != 255)
637  {
638  bottom = j+1;
639  goto bottomFound;
640  }
641  }
642  }
643  }
644  bottomFound:
645 
646  if (left<0)
647  {
648  for (size_t i=0;i<width();i++){
649  for (size_t j=0;j<height();j++){
650  yarp::sig::PixelMono pix = m_map_occupancy.safePixel(i,j);
651  if ( pix != 255)
652  {
653  left = i;
654  goto leftFound;
655  }
656  }
657  }
658  }
659  leftFound:
660 
661  if (right<0)
662  {
663  for (size_t i=width()-1;i>0;i--){
664  for (size_t j=0;j<height();j++){
665  yarp::sig::PixelMono pix = m_map_occupancy.safePixel(i,j);
666  if ( pix != 255)
667  {
668  right = i;
669  goto rightFound;
670  }
671  }
672  }
673  }
674  rightFound:
675 
676  if (left > (int)this->width()) return false;
677  if (right > (int)this->width()) return false;
678  if (top > (int)this->height()) return false;
679  if (bottom > (int)this->height()) return false;
680 
681  yarp::sig::ImageOf<CellData> new_map_occupancy;
682  yarp::sig::ImageOf<CellData> new_map_flags;
683 
684  new_map_occupancy.setQuantum(1);
685  new_map_flags.setQuantum(1);
686  new_map_occupancy.resize(right-left,bottom-top);
687  new_map_flags.resize(right-left,bottom-top);
688 
689 // size_t original_width = m_map_occupancy.width();
690  size_t original_height = m_map_occupancy.height();
691 
692  for (int j=top, y=0; j<bottom; j++, y++)
693  for (int i=left, x=0; i<right; i++, x++)
694  {
695  new_map_occupancy.safePixel(x,y) = m_map_occupancy.safePixel(i,j);
696  new_map_flags.safePixel(x,y) = m_map_flags.safePixel(i,j);
697  }
698  m_map_occupancy.copy(new_map_occupancy);
699  m_map_flags.copy(new_map_flags);
700  this->m_width=m_map_occupancy.width();
701  this->m_height=m_map_occupancy.height();
702  yDebug() << m_origin.get_x() << m_origin.get_y();
703  double new_x0 = m_origin.get_x() +(left*m_resolution);
704  double new_y0 = m_origin.get_y() +(double(original_height)-double(bottom))*m_resolution;
705  m_origin.setOrigin(new_x0,new_y0, m_origin.get_theta());
706  return true;
707 }
708 
709 bool MapGrid2D::saveToFile(std::string map_file_with_path) const
710 {
711  std::string yarp_filename = this->getMapName() + "_yarpflags.ppm";
712  std::string yaml_filename = this->getMapName() + "_grid.yaml";
713  std::string pgm_occ_filename = this->getMapName() + "_grid.pgm";
714 
715  std::ofstream map_file;
716  map_file.open(map_file_with_path.c_str());
717  if (!map_file.is_open())
718  {
719  return false;
720  }
721  map_file << "MapName: "<< this->getMapName() << endl;
722  map_file << "YarpMapData: "<< yarp_filename << endl;
723  map_file << "RosMapData: "<< yaml_filename << endl;
724  map_file.close();
725 
726  std::ofstream yaml_file;
727  yaml_file.open(yaml_filename.c_str());
728  if (!yaml_file.is_open())
729  {
730  return false;
731  }
732  yaml_file << "image: " << pgm_occ_filename << endl;
733  yaml_file << "resolution: " << m_resolution << endl;
734  yaml_file << "origin: [ " << m_origin.get_x() << " " << m_origin.get_y() << " " << m_origin.get_theta() << " ]"<< endl;
735  yaml_file << "negate: 0" << endl;
736  yaml_file << "occupied_thresh: " << m_occupied_thresh << endl;
737  yaml_file << "free_thresh: " << m_free_thresh << endl;
738 
739  yaml_file.close();
740 
743 
744  img_flg.resize(m_width, m_height);
745  img_occ.resize(m_width, m_height);
746  for (size_t y = 0; y < m_height; y++)
747  {
748  for (size_t x = 0; x < m_width; x++)
749  {
750  yarp::sig::PixelMono pix = m_map_flags.safePixel(x, y);
751  yarp::sig::PixelMono pix_occ = m_map_occupancy.safePixel(x,y);
752  yarp::sig::PixelMono pix_occ_out;
753  if (pix_occ == 255) pix_occ_out = 205;
754  else pix_occ_out = 254-(pix_occ*254/100);
755  img_flg.safePixel(x, y) = CellDataToPixel(pix);
756  img_occ.safePixel(x, y) = pix_occ_out;
757  }
758  }
759 
760  //std::string ppm_flg_filename = (pgm_occ_filename.substr(0, pgm_occ_filename.size() - 4)) + "_yarpflags" + ".ppm";
761  std::string ppm_flg_filename = yarp_filename;
762  bool ret = true;
763  ret &= yarp::sig::file::write(img_occ, pgm_occ_filename);
764  ret &= yarp::sig::file::write(img_flg, ppm_flg_filename);
765  return ret;
766 }
767 
769 {
770  // auto-convert text mode interaction
771  connection.convertTextMode();
772 
773  connection.expectInt32();
774  connection.expectInt32();
775 
776  connection.expectInt32();
777  m_width = connection.expectInt32();
778  connection.expectInt32();
779  m_height = connection.expectInt32();
780  connection.expectInt32();
781  double x0 = connection.expectFloat64();
782  connection.expectInt32();
783  double y0 = connection.expectFloat64();
784  connection.expectInt32();
785  double theta0 = connection.expectFloat64();
786  m_origin.setOrigin(x0,y0,theta0);
787  connection.expectInt32();
788  m_resolution = connection.expectFloat64();
789  connection.expectInt32();
790  int siz = connection.expectInt32();
791  char buff[255]; memset(buff, 0, 255);
792  connection.expectBlock((char*)buff, siz);
793  m_map_name = buff;
794  m_map_occupancy.resize(m_width, m_height);
795  m_map_flags.resize(m_width, m_height);
796  bool ok = true;
797  unsigned char *mem = nullptr;
798  size_t memsize = 0;
799  connection.expectInt32();
800  memsize = connection.expectInt32();
801  if (memsize != m_map_occupancy.getRawImageSize()) { return false; }
802  mem = m_map_occupancy.getRawImage();
803  ok &= connection.expectBlock((char*)mem, memsize);
804  connection.expectInt32();
805  memsize = connection.expectInt32();
806  if (memsize != m_map_flags.getRawImageSize()) { return false; }
807  mem = m_map_flags.getRawImage();
808  ok &= connection.expectBlock((char*)mem, memsize);
809  if (!ok) return false;
810 
811  return !connection.isError();
812 }
813 
815 {
816  connection.appendInt32(BOTTLE_TAG_LIST);
817  connection.appendInt32(9);
818  connection.appendInt32(BOTTLE_TAG_INT32);
819  connection.appendInt32(m_width);
820  connection.appendInt32(BOTTLE_TAG_INT32);
821  connection.appendInt32(m_height);
822  connection.appendInt32(BOTTLE_TAG_FLOAT64);
823  connection.appendFloat64(m_origin.get_x());
824  connection.appendInt32(BOTTLE_TAG_FLOAT64);
825  connection.appendFloat64(m_origin.get_y());
826  connection.appendInt32(BOTTLE_TAG_FLOAT64);
827  connection.appendFloat64(m_origin.get_theta());
828  connection.appendInt32(BOTTLE_TAG_FLOAT64);
829  connection.appendFloat64(m_resolution);
830  connection.appendInt32(BOTTLE_TAG_STRING);
831  connection.appendString(m_map_name);
832 
833  unsigned char *mem = nullptr;
834  int memsize = 0;
835  mem = m_map_occupancy.getRawImage();
836  memsize = m_map_occupancy.getRawImageSize();
837  connection.appendInt32(BOTTLE_TAG_BLOB);
838  connection.appendInt32(memsize);
839  connection.appendExternalBlock((char*)mem, memsize);
840  mem = m_map_flags.getRawImage();
841  memsize = m_map_flags.getRawImageSize();
842  connection.appendInt32(BOTTLE_TAG_BLOB);
843  connection.appendInt32(memsize);
844  connection.appendExternalBlock((char*)mem, memsize);
845 
846  connection.convertTextMode();
847  return !connection.isError();
848 }
849 
850 bool MapGrid2D::setOrigin(double x, double y, double theta)
851 {
852  //the given x and y are referred to the bottom left corner, pointing outwards.
853  //To check if it is inside the map, I have to convert it to a cell with x and y referred to the upper left corner, pointing inwards
854  if (m_resolution<=0)
855  {
856  yWarning() << "MapGrid2D::setOrigin() requested is not inside map!";
857  return false;
858  }
859 
860  int xc = (int)(x/ m_resolution);
861  int yc = (int)(y / m_resolution);
862 
863  XYCell orig(-xc, (m_height-1) + yc);
864  if (isInsideMap(orig))
865  {
866  m_origin.setOrigin(x,y, theta);
867  return true;
868  }
869  else
870  {
871  yWarning() << "MapGrid2D::setOrigin() requested is not inside map!";
872  m_origin.setOrigin(x, y, theta);
873  return true;
874  }
875 }
876 
877 void MapGrid2D::getOrigin(double& x, double& y, double& theta) const
878 {
879  x = m_origin.get_x();
880  y = m_origin.get_y();
881  theta = m_origin.get_theta();
882 }
883 
884 bool MapGrid2D::setResolution(double resolution)
885 {
886  if (resolution <= 0)
887  {
888  yError() << "MapGrid2D::setResolution() invalid value:" << resolution;
889  return false;
890  }
891  m_resolution = resolution;
892  return true;
893 }
894 
895 void MapGrid2D::getResolution(double& resolution) const
896 {
897  resolution = m_resolution;
898 }
899 
900 bool MapGrid2D::setMapName(std::string map_name)
901 {
902  if (map_name != "")
903  {
904  m_map_name = map_name;
905  return true;
906  }
907  yError() << "MapGrid2D::setMapName() invalid map name";
908  return false;
909 }
910 
911 std::string MapGrid2D::getMapName() const
912 {
913  return m_map_name;
914 }
915 
916 bool MapGrid2D::setSize_in_meters(double x, double y)
917 {
918  if (x <= 0 && y <= 0)
919  {
920  yError() << "MapGrid2D::setSize() invalid size";
921  return false;
922  }
923  if (m_resolution <= 0)
924  {
925  yError() << "MapGrid2D::setSize() invalid map resolution.";
926  return false;
927  }
928  auto w = (size_t)(x/m_resolution);
929  auto h = (size_t)(y/m_resolution);
930  setSize_in_cells(w,h);
931  return true;
932 }
933 
934 bool MapGrid2D::setSize_in_cells(size_t x, size_t y)
935 {
936  if (x == 0 && y == 0)
937  {
938  yError() << "MapGrid2D::setSize() invalid size";
939  return false;
940  }
941  m_map_occupancy.resize(x, y);
942  m_map_flags.resize(x, y);
943  m_map_occupancy.zero();
944  m_map_flags.zero();
945  m_width = x;
946  m_height = y;
947  return true;
948 }
949 
950 void MapGrid2D::getSize_in_meters(double& x, double& y) const
951 {
952  x = m_width* m_resolution;
953  y = m_height* m_resolution;
954 }
955 
956 void MapGrid2D::getSize_in_cells(size_t&x, size_t& y) const
957 {
958  x = m_width;
959  y = m_height;
960 }
961 
963 {
964  if (isInsideMap(cell) == false)
965  {
966  yError() << "Invalid cell requested " << cell.x << " " << cell.y;
967  return false;
968  }
969  m_map_flags.safePixel(cell.x, cell.y) = flag;
970  return true;
971 }
972 
973 bool MapGrid2D::getMapFlag(XYCell cell, map_flags& flag) const
974 {
975  if (isInsideMap(cell) == false)
976  {
977  yError() << "Invalid cell requested " << cell.x << " " << cell.y;
978  return false;
979  }
980  flag = (MapGrid2D::map_flags) m_map_flags.safePixel(cell.x, cell.y);
981  return true;
982 }
983 
984 bool MapGrid2D::setOccupancyData(XYCell cell, double occupancy)
985 {
986  if (isInsideMap(cell) == false)
987  {
988  yError() << "Invalid cell requested " << cell.x << " " << cell.y;
989  return false;
990  }
991  m_map_occupancy.safePixel(cell.x, cell.y) = (yarp::sig::PixelMono)(occupancy);
992  return true;
993 }
994 
995 bool MapGrid2D::getOccupancyData(XYCell cell, double& occupancy) const
996 {
997  if (isInsideMap(cell) == false)
998  {
999  yError() << "Invalid cell requested " << cell.x << " " << cell.y;
1000  return false;
1001  }
1002  if (m_map_occupancy.safePixel(cell.x, cell.y)==255)
1003  {
1004  occupancy =-1;
1005  }
1006  else
1007  {
1008  occupancy = m_map_occupancy.safePixel(cell.x, cell.y);
1009  }
1010  return true;
1011 }
1012 
1014 {
1015  if ((size_t) image.width() != m_width ||
1016  (size_t) image.height() != m_height)
1017  {
1018  yError() << "The size of given occupancy grid does not correspond to the current map. Use method setSize() first.";
1019  return false;
1020  }
1021  m_map_occupancy = image;
1022  return true;
1023 }
1024 
1026 {
1027  image = m_map_occupancy;
1028  return true;
1029 }
LogStream.h
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
MapGrid2D.h
contains the definition of a map type
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
yarp::sig::PixelRgb::g
unsigned char g
Definition: Image.h:455
yarp::sig::file::read
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:827
yarp::dev::Nav2D::MapGrid2D::setMapImage
bool setMapImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
Definition: MapGrid2D.cpp:162
yarp::sig
Signal processing.
Definition: Image.h:25
yarp::dev::Nav2D::MapGrid2DInfo::m_resolution
double m_resolution
meters/pixel
Definition: MapGrid2DInfo.h:59
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
yarp::dev::Nav2D::MapGrid2D::setMapName
bool setMapName(std::string map_name)
Sets the map name.
Definition: MapGrid2D.cpp:900
yarp::math::Vec2D::x
T x
Definition: Vec2D.h:27
yarp::os::ConnectionWriter::appendFloat64
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
yarp::dev::Nav2D::MapGrid2D::isKeepOut
bool isKeepOut(XYCell cell) const
Checks if a specific cell of the map is marked as keep-out.
Definition: MapGrid2D.cpp:115
ConnectionWriter.h
yarp::dev::Nav2D::MapGrid2D::setOccupancyData
bool setOccupancyData(XYCell cell, double occupancy)
Set the occupancy data of a specific cell of the map.
Definition: MapGrid2D.cpp:984
yarp::dev::Nav2D::MapGrid2D::~MapGrid2D
virtual ~MapGrid2D()
BOTTLE_TAG_STRING
#define BOTTLE_TAG_STRING
Definition: Bottle.h:28
yarp::dev::Nav2D::MapGrid2D::isIdenticalTo
bool isIdenticalTo(const MapGrid2D &otherMap) const
Checks is two maps are identical.
Definition: MapGrid2D.cpp:55
yarp::os::Bottle::fromString
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:207
yarp::os::Value::asFloat32
virtual yarp::conf::float32_t asFloat32() const
Get 32-bit floating point value.
Definition: Value.cpp:219
yarp::os::Property::find
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1034
yarp::dev::Nav2D::MapGrid2D::crop
bool crop(int left, int top, int right, int bottom)
Modifies the map, cropping pixels at the boundaries.
Definition: MapGrid2D.cpp:614
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::Nav2D::MapGrid2D::setSize_in_meters
bool setSize_in_meters(double x, double y)
Sets the size of the map in meters, according to the current map resolution.
Definition: MapGrid2D.cpp:916
yarp::math
Definition: FrameTransform.h:18
yError
#define yError(...)
Definition: Log.h:282
yarp::os::Bottle::find
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Bottle.cpp:290
yarp::math::Vec2D
Definition: Vec2D.h:26
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
BOTTLE_TAG_INT32
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
yarp::sig::PixelRgb::b
unsigned char b
Definition: Image.h:456
yarp::sig::ImageOf< PixelRgb >
yarp::dev::Nav2D::MapGrid2D::getOccupancyData
bool getOccupancyData(XYCell cell, double &occupancy) const
Retrieves the occupancy data of a specific cell of the map.
Definition: MapGrid2D.cpp:995
yarp::dev::Nav2D::MapGrid2D::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: MapGrid2D.cpp:768
yarp::dev::Nav2D::MapGrid2D::enlargeObstacles
bool enlargeObstacles(double size)
Performs the obstacle enlargement operation.
Definition: MapGrid2D.cpp:180
yarp::dev::Nav2D::MapGrid2D::getMapImage
bool getMapImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) const
Definition: MapGrid2D.cpp:147
yarp::dev::Nav2D::MapGrid2D::getMapName
std::string getMapName() const
Retrieves the map name.
Definition: MapGrid2D.cpp:911
yarp::sig::ImageOf::safePixel
T & safePixel(size_t x, size_t y)
Definition: Image.h:679
yarp::os::Bottle::check
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Bottle.cpp:280
yarp::dev::Nav2D::MapGrid2D::CellData
yarp::sig::PixelMono CellData
Definition: MapGrid2D.h:34
yarp::os::ConnectionReader::expectFloat64
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::dev::Nav2D::MapGrid2D::setOrigin
bool setOrigin(double x, double y, double theta)
Sets the origin of the map reference frame (according to ROS convention)
Definition: MapGrid2D.cpp:850
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::dev::Nav2D::MapGrid2D::width
size_t width() const
Retrieves the map width, expressed in cells.
Definition: MapGrid2D.cpp:142
yarp::sig::PixelMono
unsigned char PixelMono
Monochrome pixel type.
Definition: Image.h:436
yarp::os::Bottle::get
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:249
yarp::dev::Nav2D::MapGrid2D::setSize_in_cells
bool setSize_in_cells(size_t x, size_t y)
Sets the size of the map in cells.
Definition: MapGrid2D.cpp:934
yarp::dev::Nav2D::MapGrid2D
Definition: MapGrid2D.h:32
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::dev::Nav2D::MapGrid2D::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
Definition: MapGrid2D.cpp:814
yarp::dev::Nav2D::MapGrid2D::getSize_in_meters
void getSize_in_meters(double &x, double &y) const
Returns the size of the map in meters, according to the current map resolution.
Definition: MapGrid2D.cpp:950
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
yarp::os::Value::asString
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
extractPathFromFile
string extractPathFromFile(string full_filename)
Definition: MapGrid2D.cpp:38
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::dev::Nav2D::MapGrid2D::map_flags
map_flags
Definition: MapGrid2D.h:39
yWarning
#define yWarning(...)
Definition: Log.h:271
yarp::dev::Nav2D::MapGrid2D::getOrigin
void getOrigin(double &x, double &y, double &theta) const
Retrieves the origin of the map reference frame (according to ROS convention)
Definition: MapGrid2D.cpp:877
yarp::os::Property::check
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1024
yarp::dev::Nav2D::MapGrid2D::getOccupancyGrid
bool getOccupancyGrid(yarp::sig::ImageOf< yarp::sig::PixelMono > &image) const
Definition: MapGrid2D.cpp:1025
yarp::dev::Nav2D
Definition: ILocalization2D.h:21
yarp::dev::Nav2D::MapGrid2D::setResolution
bool setResolution(double resolution)
Sets the resolution of the map, i.e.
Definition: MapGrid2D.cpp:884
ImageFile.h
yarp::dev::Nav2D::MapGrid2D::getSize_in_cells
void getSize_in_cells(size_t &x, size_t &y) const
Returns the size of the map in cells.
Definition: MapGrid2D.cpp:956
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::dev::Nav2D::MapGrid2D::loadFromFile
bool loadFromFile(std::string map_filename)
Loads a yarp map file from disk.
Definition: MapGrid2D.cpp:512
yarp::dev::Nav2D::MapGrid2D::saveToFile
bool saveToFile(std::string map_filename) const
Store a yarp map file to disk.
Definition: MapGrid2D.cpp:709
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
yarp::dev::Nav2D::MapGrid2DInfo::m_map_name
std::string m_map_name
Definition: MapGrid2DInfo.h:58
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
BOTTLE_TAG_BLOB
#define BOTTLE_TAG_BLOB
Definition: Bottle.h:29
yarp::dev::Nav2D::MapGrid2D::isNotFree
bool isNotFree(XYCell cell) const
Checks if a specific cell of the map contains is not free.
Definition: MapGrid2D.cpp:92
BOTTLE_TAG_FLOAT64
#define BOTTLE_TAG_FLOAT64
Definition: Bottle.h:27
extractExtensionFromFile
string extractExtensionFromFile(string full_filename)
Definition: MapGrid2D.cpp:48
RAD2DEG
#define RAD2DEG
Definition: MapGrid2D.cpp:34
yarp::os::Property::fromConfigFile
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
Definition: Property.cpp:1081
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::sig::PixelRgb
Packed RGB pixel type.
Definition: Image.h:453
yarp::os::ConnectionWriter::appendString
virtual void appendString(const char *str, const char terminate='\n') final
Send a character sequence to the network connection.
Definition: ConnectionWriter.h:131
yarp::dev::Nav2D::MapGrid2D::getMapFlag
bool getMapFlag(XYCell cell, map_flags &flag) const
Get the flag of a specific cell of the map.
Definition: MapGrid2D.cpp:973
yarp::dev::Nav2D::MapGrid2D::isFree
bool isFree(XYCell cell) const
Checks if a specific cell of the map is free, i.e.
Definition: MapGrid2D.cpp:104
yDebug
#define yDebug(...)
Definition: Log.h:237
yarp::os::Value::asList
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:243
yarp::os::ConnectionWriter::appendExternalBlock
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
yarp::dev::Nav2D::MapGrid2DInfo::m_origin
MapGrid2DOrigin m_origin
pose of the map frame w.r.t. the bottom left corner of the map image
Definition: MapGrid2DInfo.h:60
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::dev::Nav2D::MapGrid2D::setMapFlag
bool setMapFlag(XYCell cell, map_flags flag)
Set the flag of a specific cell of the map.
Definition: MapGrid2D.cpp:962
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971
yarp::dev::Nav2D::MapGrid2D::height
size_t height() const
Retrieves the map height, expressed in cells.
Definition: MapGrid2D.cpp:137
yarp::dev::Nav2D::MapGrid2D::isWall
bool isWall(XYCell cell) const
Checks if a specific cell of the map contains a wall.
Definition: MapGrid2D.cpp:125
yarp::os::Value::asFloat64
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:225
yarp::dev::Nav2D::MapGrid2D::MapGrid2D
MapGrid2D()
Definition: MapGrid2D.cpp:69
yarp::dev::Nav2D::MapGrid2D::getResolution
void getResolution(double &resolution) const
Retrieves the resolution of the map, i.e.
Definition: MapGrid2D.cpp:895
Bottle.h
yarp::math::Vec2D::y
T y
Definition: Vec2D.h:31
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
ConnectionReader.h
yarp::sig::PixelRgb::r
unsigned char r
Definition: Image.h:454
yarp::dev::Nav2D::MapGrid2D::setOccupancyGrid
bool setOccupancyGrid(yarp::sig::ImageOf< yarp::sig::PixelMono > &image)
Definition: MapGrid2D.cpp:1013