CompositeMapReader composite_map_reader;
std::string error_message;
boost::shared_ptr<CompositeMap> composite_map(composite_map_reader.loadFile(error_message, file_path));
if (composite_map) {
for (auto it = composite_map->maps().begin(); it != composite_map->maps().end(); ++it) {
auto layer = *it;
std::string usage = layer->getUsage();
std::string type = layer->getType();
std::cout << "Layer Usage : " << usage << std::endl;
//get grid map layer
if (type == GridMapLayer::Type) {
auto grid_map = boost::dynamic_pointer_cast<GridMapLayer>(layer);
std::cout << "Map Position : (" << grid_map->getOrigin().x() << " , " <<
grid_map->getOrigin().y() << ")" <<std::endl;
std::cout << "Map Resolution : (" << grid_map->getResolution().x() <<
" , " << grid_map->getResolution().y() << ")" <<std::endl;
std::cout << "Map Dimension: (" << grid_map->getDimension().x() <<
" , " << grid_map->getDimension().y() << ")" <<std::endl;
std::cout << "Map Data:" << std::endl;
for (auto it = grid_map->mapData().begin(); it != grid_map->mapData().end(); ++it) {
std::cout << (int)*it << " " ;
}
std::cout << std::endl << std::endl;
}
//get line map layer
else if (type == LineMapLayer::Type) {
auto line_map = boost::dynamic_pointer_cast<LineMapLayer>(layer);
for (auto it = line_map->lines().begin(); it != line_map->lines().end(); ++it) {
auto line = it->second;
std::cout << "start: (" << line.start.x() << " , " << line.start.y() << ")" << std::endl;
std::cout << "end: (" << line.end.x() << " , " << line.end.y() << ")" << std::endl;
}
std::cout << std::endl;
}
//get pose map layer
else if (type == PoseMapLayer::Type) {
auto pose_map = boost::dynamic_pointer_cast<PoseMapLayer>(layer);
for (auto it = pose_map->poses().begin(); it != pose_map->poses().end(); ++it) {
auto pos = it->second;
std::cout << "Position : (" << pos.pose.x() << " , " << pos.pose.y() << ")" << std::endl;
}
std::cout << std::endl;
}
else if (type == PointsMapLayer::Type) {
//TODO: get Points map layer
std::cout << std::endl;
}
else {
//TODO: get unknown map layer
std::cout << std::endl;
}
} |