6#define _USE_MATH_DEFINES
19#if defined (YARP_HAS_ZLIB)
31#define DEG2RAD M_PI/180.0
35#define RAD2DEG 180.0/M_PI
43 if (
found != std::string::npos) {
47 if (
found != std::string::npos) {
77 for (
size_t y = 0; y <
m_height; y++) {
78 for (
size_t x = 0; x <
m_width; x++) {
84 for (
size_t y = 0; y <
m_height; y++) {
85 for (
size_t x = 0; x <
m_width; x++) {
103 m_occupied_thresh = 0.80;
104 m_free_thresh = 0.20;
105 for (
size_t y = 0; y <
m_height; y++)
107 for (
size_t x = 0; x <
m_width; x++)
113#if defined (YARP_HAS_ZLIB)
114 m_compressed_data_over_network =
true;
116 m_compressed_data_over_network =
false;
192 for (
size_t y = 0; y <
m_height; y++)
194 for (
size_t x = 0; x <
m_width; x++)
207 yError() <<
"The size of given image does not correspond to the current map. Use method setSize() first.";
210 for (
size_t y = 0; y <
m_height; y++)
212 for (
size_t x = 0; x <
m_width; x++)
224 for (
size_t y = 0; y <
m_height; y++)
226 for (
size_t x = 0; x <
m_width; x++)
241 for (
size_t y = 0; y <
m_height; y++)
243 for (
size_t x = 0; x <
m_width; x++)
315 if (line.find(
"origin") != std::string::npos)
317 std::replace(line.begin(), line.end(),
',',
' ');
318 std::replace(line.begin(), line.end(),
'[',
'(');
319 std::replace(line.begin(), line.end(),
']',
')');
335 if (
bbb.check(
"image:") ==
false) {
yError() <<
"missing image";
ret =
false; }
339 if (
bbb.check(
"resolution:") ==
false) {
yError() <<
"missing resolution";
ret =
false; }
340 resolution =
bbb.find(
"resolution:").asFloat64();
342 if (
bbb.check(
"origin:") ==
false) {
yError() <<
"missing origin";
ret =
false; }
343 Bottle* b =
bbb.find(
"origin:").asList();
351 if (
bbb.check(
"occupied_thresh:"))
352 {m_occupied_thresh =
bbb.find(
"occupied_thresh:").asFloat64();}
354 if (
bbb.check(
"free_thresh:"))
355 {m_free_thresh =
bbb.find(
"free_thresh:").asFloat64();}
399 for (
size_t y = 0; y <
m_height; y++)
401 for (
size_t x = 0; x <
m_width; x++)
408 for (
size_t y = 0; y <
m_height; y++)
410 for (
size_t x = 0; x <
m_width; x++)
412 m_map_occupancy.
safePixel(x, y) = PixelToCellOccupancyData(
ros_img.safePixel(x, y));
418 yError() <<
"MapGrid2D::loadFromFile() Size of YARP map and ROS do not match";
429 double resolution = 0;
455 for (
size_t y = 0; y <
m_height; y++)
457 for (
size_t x = 0; x <
m_width; x++)
459 m_map_occupancy.
safePixel(x, y) = PixelToCellOccupancyData(
ros_img.safePixel(x, y));
464 for (
size_t y = 0; y < (
size_t)(m_map_occupancy.
height()); y++)
466 for (
size_t x = 0; x < (
size_t)(m_map_occupancy.
width()); x++)
473 else {
yError() <<
"Unreachable";}
496 for (
size_t y = 0; y <
m_height; y++)
498 for (
size_t x = 0; x <
m_width; x++)
505 for (
size_t y = 0; y < (
size_t)(m_map_flags.
height()); y++)
507 for (
size_t x = 0; x < (
size_t)(m_map_flags.
width()); x++)
528 m_occupied_thresh = 0.80;
529 m_free_thresh = 0.20;
538 if (
mapfile.check(
"resolution"))
675 return (254 - (
cellin * 254 / 100));
695 else if (
pixin != (
unsigned char)(-1))
769 if (left > (
int)this->
width()) {
772 if (right > (
int)this->
width()) {
775 if (top > (
int)this->
height()) {
778 if (bottom > (
int)this->
height()) {
794 for (
int i=left, x=0;
i<right;
i++, x++)
802 this->m_width=m_map_occupancy.
width();
803 this->m_height=m_map_occupancy.
height();
840 yaml_file <<
"occupied_thresh: " << m_occupied_thresh <<
'\n';
841 yaml_file <<
"free_thresh: " << m_free_thresh <<
'\n';
850 for (
size_t y = 0; y <
m_height; y++)
852 for (
size_t x = 0; x <
m_width; x++)
896 m_compressed_data_over_network =
connection.expectInt8();
900 if (m_compressed_data_over_network)
902#if defined (YARP_HAS_ZLIB)
935 unsigned char* mem = m_map_occupancy.
getRawImage();
971 connection.appendInt8(m_compressed_data_over_network);
973 if (m_compressed_data_over_network)
975#if defined (YARP_HAS_ZLIB)
1005 unsigned char* mem = m_map_occupancy.
getRawImage();
1030 yWarning() <<
"MapGrid2D::setOrigin() requested is not inside map!";
1045 yWarning() <<
"MapGrid2D::setOrigin() requested is not inside map!";
1060 if (resolution <= 0)
1062 yError() <<
"MapGrid2D::setResolution() invalid value:" << resolution;
1081 yError() <<
"MapGrid2D::setMapName() invalid map name";
1092 if (x <= 0 && y <= 0)
1094 yError() <<
"MapGrid2D::setSize() invalid size";
1099 yError() <<
"MapGrid2D::setSize() invalid map resolution.";
1110 if (x == 0 && y == 0)
1112 yError() <<
"MapGrid2D::setSize() invalid size";
1115 m_map_occupancy.
resize(x, y);
1116 m_map_flags.
resize(x, y);
1117 m_map_occupancy.
zero();
1140 yError() <<
"Invalid cell requested " <<
cell.x <<
" " <<
cell.y;
1151 yError() <<
"Invalid cell requested " <<
cell.x <<
" " <<
cell.y;
1162 yError() <<
"Invalid cell requested " <<
cell.x <<
" " <<
cell.y;
1180 yError() <<
"Invalid cell requested " <<
cell.x <<
" " <<
cell.y;
1199 yError() <<
"The size of given occupancy grid does not correspond to the current map. Use method setSize() first.";
1202 m_map_occupancy = image;
1208 image = m_map_occupancy;
1214 for (
size_t y = 0; y <
m_height; y++)
1216 for (
size_t x = 0; x <
m_width; x++)
1231#if defined (YARP_HAS_ZLIB)
1232 m_compressed_data_over_network = val;
1235 yWarning() <<
"Zlib library not found, unable to set compression";
#define BOTTLE_TAG_FLOAT64
#define BOTTLE_TAG_STRING
static std::string extractExtensionFromFile(std::string full_filename)
static std::string extractPathFromFile(std::string full_filename)
contains the definition of a map type
bool isInsideMap(XYCell cell) const
Checks if a cell is inside the map.
MapGrid2DOrigin m_origin
pose of the map frame w.r.t. the bottom left corner of the map image
double m_resolution
meters/pixel
void setOrigin(double x_init, double y_init, double t_init)
void getSize_in_cells(size_t &x, size_t &y) const
Returns the size of the map in cells.
bool getMapFlag(XYCell cell, map_flags &flag) const
Get the flag of a specific cell of the map.
void clearMapTemporaryFlags()
Clear map temporary flags, such as: MAP_CELL_TEMPORARY_OBSTACLE, MAP_CELL_ENLARGED_OBSTACLE etc.
bool isIdenticalTo(const MapGrid2D &otherMap) const
Checks is two maps are identical.
bool getMapImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) const
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
size_t height() const
Retrieves the map height, expressed in cells.
bool setResolution(double resolution)
Sets the resolution of the map, i.e.
bool setOrigin(double x, double y, double theta)
Sets the origin of the map reference frame (according to ROS convention)
bool getOccupancyGrid(yarp::sig::ImageOf< yarp::sig::PixelMono > &image) const
std::string getMapName() const
Retrieves the map name.
bool setSize_in_cells(size_t x, size_t y)
Sets the size of the map in cells.
bool enable_map_compression_over_network(bool val)
void getOrigin(double &x, double &y, double &theta) const
Retrieves the origin of the map reference frame (according to ROS convention)
bool setMapImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
bool setMapName(std::string map_name)
Sets the map name.
bool setMapFlag(XYCell cell, map_flags flag)
Set the flag of a specific cell of the map.
bool crop(int left, int top, int right, int bottom)
Modifies the map, cropping pixels at the boundaries.
bool isKeepOut(XYCell cell) const
Checks if a specific cell of the map is marked as keep-out.
bool isFree(XYCell cell) const
Checks if a specific cell of the map is free, i.e.
bool isNotFree(XYCell cell) const
Checks if a specific cell of the map contains is not free.
size_t width() const
Retrieves the map width, expressed in cells.
void getSize_in_meters(double &x, double &y) const
Returns the size of the map in meters, according to the current map resolution.
bool enlargeObstacles(double size)
Performs the obstacle enlargement operation.
bool setOccupancyData(XYCell cell, double occupancy)
Set the occupancy data of a specific cell of the map.
bool loadFromFile(std::string map_filename)
Loads a yarp map file from disk.
bool setSize_in_meters(double x, double y)
Sets the size of the map in meters, according to the current map resolution.
yarp::sig::PixelMono CellOccupancyData
bool setOccupancyGrid(yarp::sig::ImageOf< yarp::sig::PixelMono > &image)
bool saveToFile(std::string map_filename) const
Store a yarp map file to disk.
bool getOccupancyData(XYCell cell, double &occupancy) const
Retrieves the occupancy data of a specific cell of the map.
bool isWall(XYCell cell) const
Checks if a specific cell of the map contains a wall.
@ MAP_CELL_TEMPORARY_OBSTACLE
@ MAP_CELL_ENLARGED_OBSTACLE
void getResolution(double &resolution) const
Retrieves the resolution of the map, i.e.
A simple collection of objects that can be described and transmitted in a portable way.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
An interface for reading from a network connection.
An interface for writing to a network connection.
A class for storing options and configuration information.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual yarp::conf::float32_t asFloat32() const
Get 32-bit floating point value.
T & safePixel(size_t x, size_t y)
T & pixel(size_t x, size_t y)
void setQuantum(size_t imgQuantum)
size_t width() const
Gets width of image in pixels.
unsigned char * getRawImage() const
Access to the internal image buffer.
bool copy(const Image &alt)
Copy operator.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
void zero()
Set all pixels to 0.
size_t height() const
Gets height of image in pixels.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)