-
Notifications
You must be signed in to change notification settings - Fork 72
feat(lanelet2_extension): add multi osm parser #234
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,188 @@ | ||||||||||||||
// Copyright 2023 Autoware Foundation | ||||||||||||||
// | ||||||||||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
// you may not use this file except in compliance with the License. | ||||||||||||||
// You may obtain a copy of the License at | ||||||||||||||
// | ||||||||||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
// | ||||||||||||||
// Unless required by applicable law or agreed to in writing, software | ||||||||||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
// See the License for the specific language governing permissions and | ||||||||||||||
// limitations under the License. | ||||||||||||||
|
||||||||||||||
#ifndef LANELET2_EXTENSION__IO__AUTOWARE_MULTI_OSM_PARSER_HPP_ | ||||||||||||||
#define LANELET2_EXTENSION__IO__AUTOWARE_MULTI_OSM_PARSER_HPP_ | ||||||||||||||
|
||||||||||||||
#include "lanelet2_io/Exceptions.h" | ||||||||||||||
#include "lanelet2_io/io_handlers/Factory.h" | ||||||||||||||
#include "lanelet2_io/io_handlers/OsmFile.h" | ||||||||||||||
#include "lanelet2_io/io_handlers/OsmHandler.h" | ||||||||||||||
|
||||||||||||||
#include <boost/geometry/algorithms/is_valid.hpp> | ||||||||||||||
|
||||||||||||||
#include <lanelet2_core/geometry/LineString.h> | ||||||||||||||
#include <lanelet2_core/geometry/Polygon.h> | ||||||||||||||
|
||||||||||||||
#include <map> | ||||||||||||||
#include <memory> | ||||||||||||||
#include <string> | ||||||||||||||
#include <unordered_map> | ||||||||||||||
#include <utility> | ||||||||||||||
#include <vector> | ||||||||||||||
|
||||||||||||||
using std::string_literals::operator""s; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
|
||||||||||||||
namespace lanelet | ||||||||||||||
{ | ||||||||||||||
namespace io_handlers | ||||||||||||||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
{ | ||||||||||||||
|
||||||||||||||
class MultiOsmParser : public Parser | ||||||||||||||
{ | ||||||||||||||
public: | ||||||||||||||
using Parser::Parser; | ||||||||||||||
|
||||||||||||||
std::unique_ptr<LaneletMap> parse( | ||||||||||||||
const std::string & lanelet2_filename, ErrorMessages & errors) const override; | ||||||||||||||
|
||||||||||||||
std::unique_ptr<LaneletMap> parse( | ||||||||||||||
const std::vector<std::string> & lanelet2_filenames, ErrorMessages & errors) const; | ||||||||||||||
|
||||||||||||||
std::unique_ptr<LaneletMap> fromOsmFile(const osm::File & file, ErrorMessages & errors) const; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
std::unique_ptr<LaneletMap> fromOsmFile( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
const std::map<std::string, osm::File> & files_map, ErrorMessages & errors) const; | ||||||||||||||
|
||||||||||||||
static void parseVersions( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
const std::string & filename, std::string * format_version, std::string * map_version); | ||||||||||||||
|
||||||||||||||
static constexpr const char * extension() { return ".osm"; } | ||||||||||||||
|
||||||||||||||
static constexpr const char * name() { return "autoware_multi_osm_handler"; } | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
namespace | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
{ | ||||||||||||||
RegisterParser<MultiOsmParser> regParser; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
class MultiFileLoader | ||||||||||||||
{ | ||||||||||||||
public: | ||||||||||||||
static std::unique_ptr<LaneletMap> loadMap( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
const osm::File & file, const Projector & projector, ErrorMessages & errors) | ||||||||||||||
{ | ||||||||||||||
MultiFileLoader loader; | ||||||||||||||
loader.loadNodes(file.nodes, projector); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
loader.loadWays(file.ways); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
auto laneletsWithRelation = loader.loadLanelets(file.relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
auto areasWithRelation = loader.loadAreas(file.relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
loader.loadRegulatoryElements(file.relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
loader.addRegulatoryElements(laneletsWithRelation); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
loader.addRegulatoryElements(areasWithRelation); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Comment on lines
+82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
errors = std::move(loader.errors_); | ||||||||||||||
|
||||||||||||||
return std::make_unique<LaneletMap>( | ||||||||||||||
loader.lanelets_, loader.areas_, loader.regulatoryElements_, loader.polygons_, | ||||||||||||||
loader.lineStrings_, loader.points_); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
static std::unique_ptr<LaneletMap> loadMap( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
const std::map<std::string, osm::File> & files_map, const Projector & projector, | ||||||||||||||
ErrorMessages & errors) | ||||||||||||||
{ | ||||||||||||||
MultiFileLoader loader; | ||||||||||||||
|
||||||||||||||
std::for_each(files_map.begin(), files_map.end(), [&loader, &projector](const auto & file) { | ||||||||||||||
loader.loadNodes(file.second.nodes, projector); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
std::for_each(files_map.begin(), files_map.end(), [&loader](const auto & file) { | ||||||||||||||
loader.loadWays(file.second.ways); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
LaneletsWithRegulatoryElements laneletsWithRelation; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
for (const auto & file : files_map) { | ||||||||||||||
laneletsWithRelation = loader.loadLanelets(file.second.relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
AreasWithRegulatoryElements areasWithRelation; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
for (const auto & file : files_map) { | ||||||||||||||
areasWithRelation = loader.loadAreas(file.second.relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
for (const auto & file : files_map) { | ||||||||||||||
loader.loadRegulatoryElements(file.second.relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
loader.addRegulatoryElements(laneletsWithRelation); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
loader.addRegulatoryElements(areasWithRelation); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Comment on lines
+118
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
errors = std::move(loader.errors_); | ||||||||||||||
return std::make_unique<LaneletMap>( | ||||||||||||||
loader.lanelets_, loader.areas_, loader.regulatoryElements_, loader.polygons_, | ||||||||||||||
loader.lineStrings_, loader.points_); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private: | ||||||||||||||
std::vector<std::string> errors_; | ||||||||||||||
LaneletLayer::Map lanelets_; | ||||||||||||||
AreaLayer::Map areas_; | ||||||||||||||
RegulatoryElementLayer::Map regulatoryElements_; | ||||||||||||||
PolygonLayer::Map polygons_; | ||||||||||||||
LineStringLayer::Map lineStrings_; | ||||||||||||||
PointLayer::Map points_; | ||||||||||||||
|
||||||||||||||
public: | ||||||||||||||
template <typename PrimT> | ||||||||||||||
using PrimitiveWithRegulatoryElement = std::pair<PrimT, const osm::Relation *>; | ||||||||||||||
|
||||||||||||||
template <typename PrimT> | ||||||||||||||
using PrimitivesWithRegulatoryElement = std::vector<PrimitiveWithRegulatoryElement<PrimT>>; | ||||||||||||||
|
||||||||||||||
using AreasWithRegulatoryElements = PrimitivesWithRegulatoryElement<Area>; | ||||||||||||||
using LaneletsWithRegulatoryElements = PrimitivesWithRegulatoryElement<Lanelet>; | ||||||||||||||
|
||||||||||||||
MultiFileLoader() = default; | ||||||||||||||
|
||||||||||||||
void loadNodes(const lanelet::osm::Nodes & nodes, const Projector & projector); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
void loadWays(const lanelet::osm::Ways & ways); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
LaneletsWithRegulatoryElements loadLanelets(const lanelet::osm::Relations & relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
AreasWithRegulatoryElements loadAreas(const lanelet::osm::Relations & relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
void loadRegulatoryElements(const osm::Relations & relations); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
template <typename PrimT> | ||||||||||||||
void addRegulatoryElements(std::vector<std::pair<PrimT, const osm::Relation *>> & addTos); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
template <const char * Type> | ||||||||||||||
bool isType(const lanelet::osm::Relation & relation); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
static lanelet::AttributeMap getAttributes(const lanelet::osm::Attributes & osmAttributes); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
LineString3d getLaneletBorder(const osm::Relation & llElem, const std::string & role); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
LineStrings3d getLinestrings(const osm::Roles & roles, const std::string & roleName, Id refId); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
LineStrings3d getOuterRing(const osm::Relation & area); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
std::vector<LineStrings3d> getInnerRing(const osm::Relation & area); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
RuleParameterMap getRulesForRegulatoryElement(Id currElemId, const osm::Roles & roles); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
std::vector<LineStrings3d> assembleBoundary(LineStrings3d lineStrings, Id id); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
template <typename PrimT> | ||||||||||||||
PrimT getOrGetDummy( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
const typename std::unordered_map<Id, PrimT> & map, Id id, Id currentPrimitiveId); | ||||||||||||||
|
||||||||||||||
void parserError(Id id, const std::string & what); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
}; | ||||||||||||||
} // namespace | ||||||||||||||
} // namespace io_handlers | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
}; // namespace lanelet | ||||||||||||||
|
||||||||||||||
#endif // LANELET2_EXTENSION__IO__AUTOWARE_MULTI_OSM_PARSER_HPP_ |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -38,6 +38,14 @@ namespace lanelet::utils::conversion | |||
*/ | ||||
void toBinMsg(const lanelet::LaneletMapPtr & map, autoware_map_msgs::msg::LaneletMapBin * msg); | ||||
|
||||
/** | ||||
* [toBinMsg converts lanelet2 map to ROS message. Similar implementation to | ||||
* lanelet::io_handlers::BinHandler::write()] | ||||
* @param map [lanelet map data] | ||||
* @param msg [converted ROS message. Only "data" field is filled] | ||||
*/ | ||||
void toBinMsg(const lanelet::LaneletMapPtr & map, autoware_map_msgs::msg::LaneletMapBin * msg); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
||||
/** | ||||
* [fromBinMsg converts ROS message into lanelet2 data. Similar implementation | ||||
* to lanelet::io_handlers::BinHandler::parse()] | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using declarations in the global namespace in headers are prohibited