30 #ifndef _MIRA_GRIDMAP_IO_H_ 31 #define _MIRA_GRIDMAP_IO_H_ 33 #include <opencv2/highgui/highgui.hpp> 39 namespace mira {
namespace maps {
46 template<
typename Reflector>
49 r.member(
"Image",
image,
"Filename of the map image");
50 r.member(
"CellSize",
cellSize,
"Resolution of the map in [m/cell]");
51 r.member(
"Offset",
offset,
"Offset of the origin of the image [cells]",
Point2i(0, 0));
62 template<
typename Reflector>
66 r.member(
"Frame",
frame,
"Frame ID of the map",
"MapFrame");
75 template<
typename Reflector>
79 r.member(
"Channel",
channel,
"The channel name where to publish the map");
85 template<
typename T,
int Channels>
90 foreach(Pixel& p, img) {
91 for (
int i = 0; i < Channels; ++i)
92 p[i] = std::min(p[i], truncateTo);
102 p = std::min(p, truncateTo);
111 template<
typename T,
int Channels = 1>
115 T truncateTo = std::numeric_limits<T>::max())
118 cv::flip(img.
getMat(), flipped, 0);
130 template<
typename T,
int Channels = 1>
134 T truncateTo = std::numeric_limits<T>::max())
137 if ( !boost::filesystem::exists(path) )
138 MIRA_THROW(XFileNotFound,
"The map '" << path.string() <<
"' does not exist");
140 Img<> data(cv::imread(path.string()));
141 if ( data.isEmpty() )
142 MIRA_THROW(XIO,
"The map '" << path.string() <<
"' could not be loaded");
144 return loadGridMapFromImage<T, Channels>(data, cellSize, offset, truncateTo);
150 template<
typename T,
int Channels = 1>
152 T truncateTo = std::numeric_limits<T>::max())
154 return loadGridMapFromFile<T, Channels>(info.
image, info.
cellSize, info.
offset, truncateTo);
161 template<
typename T,
int Channels = 1>
163 T truncateTo = std::numeric_limits<T>::max())
172 return loadGridMap<T, Channels>(info, truncateTo);
178 template<
typename T,
int Channels>
181 bool fullImagePath =
true)
183 if(!filename.has_extension())
184 filename.replace_extension(
".png");
188 cv::flip(map, flipped, 0);
189 cv::imwrite(filename.string(), flipped);
192 Path xmlFilename = filename;
193 xmlFilename.replace_extension(
".xml");
199 info.
image = filename.string();
201 info.
image = filename.filename().string();
Point2i offset
Definition: GridMapIO.h:56
static void truncate(Img< T, 1 > &img, T truncateTo)
Definition: GridMapIO.h:100
void saveToFile(const Path &filename, const std::string &encoding="UTF-8", bool resolve=true) const
A struct representing some information about a grid map and an additional frame.
Definition: GridMapIO.h:60
void reflect(Reflector &r)
Definition: GridMapIO.h:76
Definition: GridMapIO.h:86
void deserialize(const std::string &name, T &value)
boost::filesystem::path Path
void reflect(Reflector &r)
Definition: GridMapIO.h:63
Path resolvePath(const Path &path, bool makeAbsolute=true)
A struct representing some information about a grid map and an additional channel.
Definition: GridMapIO.h:73
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Point2i getMapOffset() const
Provided for backward compatibility. Use getOffset() instead.
Definition: GridMap.h:133
void loadFromFile(const Path &filename, bool resolve=true)
void serialize(const std::string &name, const T &value, const std::string &comment="")
static void truncate(Img< T, Channels > &img, T truncateTo)
Definition: GridMapIO.h:88
#define MIRA_THROW(ex, msg)
GridMap< T, Channels > loadGridMap(const GridMapInfo &info, T truncateTo=std::numeric_limits< T >::max())
Loads the image specified by info as map.
Definition: GridMapIO.h:151
void saveGridMapToFile(Path filename, const GridMap< T, Channels > &map, bool fullImagePath=true)
Saves the specified grid map as image + description xml.
Definition: GridMapIO.h:179
static Img< T, TChannels > convertFrom(const cv::Mat &other, bool alwaysCopy=false)
void reflect(Reflector &r)
Definition: GridMapIO.h:47
std::string frame
Definition: GridMapIO.h:69
std::string channel
Definition: GridMapIO.h:82
float getCellSize() const
Returns the size of each cell in meter.
Definition: GridMap.h:126
const cv::Mat & getMat() const
float cellSize
Definition: GridMapIO.h:55
A struct representing some information about a grid map.
Definition: GridMapIO.h:44
std::string image
Definition: GridMapIO.h:54
GridMap< T, Channels > loadGridMapFromFile(const Path &filename, float cellSize, const Point2i &offset, T truncateTo=std::numeric_limits< T >::max())
Loads the specified image file as grid map.
Definition: GridMapIO.h:131
GridMap< T, Channels > loadGridMapFromImage(const Img<> &img, float cellSize, const Point2i &offset, T truncateTo=std::numeric_limits< T >::max())
Loads the specified image as grid map.
Definition: GridMapIO.h:112