YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MapGrid2D.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_MAPGRID2D_H
7#define YARP_DEV_MAPGRID2D_H
8
9#include <yarp/dev/api.h>
10
12#include <yarp/os/Portable.h>
13
14#include <yarp/sig/Image.h>
15
17
18#include <yarp/math/Vec2D.h>
19
20#include <string>
21
25namespace yarp::dev::Nav2D {
27{
28public:
31 // typedef yarp::math::Vec2D<int> XYCell;
32 // typedef yarp::math::Vec2D<double> XYWorld;
33
35 {
36 MAP_CELL_FREE = 0,
37 MAP_CELL_KEEP_OUT = 1,
38 MAP_CELL_TEMPORARY_OBSTACLE = 2,
39 MAP_CELL_ENLARGED_OBSTACLE = 3,
40 MAP_CELL_WALL = 4,
41 MAP_CELL_UNKNOWN = 5
42 };
43
44private:
45 // those two always have the same size
48
49 double m_occupied_thresh;
50 double m_free_thresh;
51
52 // std::vector<map_link> links_to_other_maps;
53
54private:
55 bool m_compressed_data_over_network;
56
57public:
58 bool enable_map_compression_over_network(bool val);
59
60private:
61 // performs an obstacles enlargement on the specified cell.
62 void enlargeCell(XYCell cell);
63
64 // conversion from pixel color to CellFlagData (yarp format) and viceversa
65 CellFlagData PixelToCellFlagData(const yarp::sig::PixelRgb& pixin) const;
66 yarp::sig::PixelRgb CellFlagDataToPixel(const CellFlagData& cellin) const;
67
68 // conversion from pixel color to CellOccupancyData (occupancy grid, ros format) and viceversa
69 CellOccupancyData PixelToCellOccupancyData(const yarp::sig::PixelMono& pixin) const;
70 yarp::sig::PixelMono CellOccupancyDataToPixel(const CellOccupancyData& cellin) const;
71
72 // internal methods to read a map from file, either in yarp or ROS format
73 bool loadMapYarpOnly(std::string yarp_img_filename);
74 bool loadMapROSOnly(std::string ros_yaml_filename);
75 bool loadROSParams(std::string ros_yaml_filename, std::string& pgm_occ_filename, double& resolution, double& orig_x, double& orig_y, double& orig_t);
76 bool loadMapYarpAndRos(std::string yarp_img_filename, std::string ros_yaml_filename);
77 bool parseMapParameters(const yarp::os::Property& mapfile);
78
79public:
80 MapGrid2D();
81 virtual ~MapGrid2D();
82
88 bool isWall(XYCell cell) const;
89
95 bool isFree(XYCell cell) const;
96
102 bool isNotFree(XYCell cell) const;
103
110 bool isKeepOut(XYCell cell) const;
111
117 bool getMapFlag(XYCell cell, map_flags& flag) const;
118
124 bool setMapFlag(XYCell cell, map_flags flag);
125
129 void clearMapTemporaryFlags();
130
136 bool setOccupancyData(XYCell cell, double occupancy);
137
143 bool getOccupancyData(XYCell cell, double& occupancy) const;
144
145 bool setMapImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image);
146 bool getMapImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image) const;
147 bool setOccupancyGrid(yarp::sig::ImageOf<yarp::sig::PixelMono>& image);
148 bool getOccupancyGrid(yarp::sig::ImageOf<yarp::sig::PixelMono>& image) const;
149
155 bool setOrigin(double x, double y, double theta);
156
161 void getOrigin(double& x, double& y, double& theta) const;
162
168 bool setResolution(double resolution);
169
174 void getResolution(double& resolution) const;
175
181 bool setSize_in_meters(double x, double y);
182
188 bool setSize_in_cells(size_t x, size_t y);
189
194 void getSize_in_meters(double& x, double& y) const;
195
200 void getSize_in_cells(size_t& x, size_t& y) const;
201
206 size_t width() const;
207
212 size_t height() const;
213
219 bool setMapName(std::string map_name);
220
225 std::string getMapName() const;
226
227 //------------------------------utility functions-------------------------------
228
234 bool crop(int left, int top, int right, int bottom);
235
236#if 0
242 bool isInsideMap(XYCell cell) const;
243
249 bool isInsideMap(XYWorld world) const;
250#endif
251
256 bool isIdenticalTo(const MapGrid2D& otherMap) const;
257
265 bool enlargeObstacles(double size);
266
267 //-------------------------------file access functions-------------------------------
268
274 bool loadFromFile(std::string map_filename);
275
281 bool saveToFile(std::string map_filename) const;
282
283 /*
284 * Read vector from a connection.
285 * return true iff a vector was read correctly
286 */
287 bool read(yarp::os::ConnectionReader& connection) override;
288
293 bool write(yarp::os::ConnectionWriter& connection) const override;
294};
295} // namespace yarp::dev::Nav2D
296
297#endif // YARP_DEV_MAPGRID2D_H
yarp::sig::PixelMono CellFlagData
Definition MapGrid2D.h:29
yarp::sig::PixelMono CellOccupancyData
Definition MapGrid2D.h:30
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
A class for storing options and configuration information.
Definition Property.h:33
Typed image class.
Definition Image.h:605
#define YARP_dev_API
Definition api.h:18