Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lanelet2_map_validator): move headers to include/ #144

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions map/autoware_lanelet2_map_validator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ autoware_package()
ament_auto_find_build_dependencies()
find_package(nlohmann_json REQUIRED)

include_directories(
src
)

file(GLOB_RECURSE autoware_lanelet2_map_validator_lib_src
src/common/*.cpp
src/validators/*.cpp
)

ament_auto_add_library(autoware_lanelet2_map_validator_lib SHARED
${autoware_lanelet2_map_validator_lib_src}
)

ament_auto_add_executable(autoware_lanelet2_map_validator src/main.cpp)
add_dependencies(autoware_lanelet2_map_validator autoware_lanelet2_map_validator_lib)
target_include_directories(
autoware_lanelet2_map_validator_lib PUBLIC
src/include
)

ament_auto_add_executable(autoware_lanelet2_map_validator
src/main.cpp
)

target_link_libraries(autoware_lanelet2_map_validator
autoware_lanelet2_map_validator_lib
nlohmann_json
Expand Down
2 changes: 1 addition & 1 deletion map/autoware_lanelet2_map_validator/src/common/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/cli.hpp"
#include "lanelet2_map_validator/cli.hpp"

namespace po = boost::program_options;

Expand Down
44 changes: 27 additions & 17 deletions map/autoware_lanelet2_map_validator/src/common/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/validation.hpp"
#include "lanelet2_map_validator/validation.hpp"

#include <autoware_lanelet2_extension/projection/mgrs_projector.hpp>
#include <autoware_lanelet2_extension/projection/transverse_mercator_projector.hpp>
Expand All @@ -27,31 +27,42 @@ namespace autoware
namespace validation
{

std::unique_ptr<lanelet::Projector> getProjector(const MetaConfig & config)
std::unique_ptr<lanelet::Projector> getProjector(
const std::string & projector_type, const lanelet::GPSPoint & origin)

{
const auto & val_config = config.command_line_config.validationConfig;
if (config.projector_type == projector_names::mgrs) {
if (projector_type == projector_names::mgrs) {
return std::make_unique<lanelet::projection::MGRSProjector>();
} else if (config.projector_type == projector_names::transverse_mercator) {
}
if (projector_type == projector_names::transverse_mercator) {
return std::make_unique<lanelet::projection::TransverseMercatorProjector>(
lanelet::Origin{val_config.origin});
} else if (config.projector_type == projector_names::utm) {
return std::make_unique<lanelet::projection::UtmProjector>(lanelet::Origin{val_config.origin});
lanelet::Origin{origin});
}
if (projector_type == projector_names::utm) {
return std::make_unique<lanelet::projection::UtmProjector>(lanelet::Origin{origin});
}
return std::make_unique<lanelet::projection::MGRSProjector>();
return nullptr;
TaikiYamada4 marked this conversation as resolved.
Show resolved Hide resolved
}

std::vector<lanelet::validation::DetectedIssues> validateMap(const MetaConfig & config)
std::vector<lanelet::validation::DetectedIssues> validateMap(
const std::string & projector_type, const std::string & map_file,
const lanelet::validation::ValidationConfig & val_config)
{
const auto & cm_config = config.command_line_config;
const auto & val_config = config.command_line_config.validationConfig;

std::vector<lanelet::validation::DetectedIssues> issues;
lanelet::LaneletMapPtr map;
lanelet::LaneletMapPtr map{nullptr};
lanelet::validation::Strings errors;
try {
const auto & projector = getProjector(config);
map = lanelet::load(cm_config.mapFile, *projector, &errors);
const auto projector = getProjector(projector_type, val_config.origin);
if (!projector) {
errors.push_back("No valid map projection type specified!");
} else {
map = lanelet::load(map_file, *projector, &errors);
}
if (map) {
appendIssues(issues, lanelet::validation::validateMap(*map, val_config));
} else {
errors.push_back("Failed to load map!");
}
if (!errors.empty()) {
issues.emplace_back("general", utils::transform(errors, [](auto & error) {
return lanelet::validation::Issue(
Expand All @@ -65,7 +76,6 @@ std::vector<lanelet::validation::DetectedIssues> validateMap(const MetaConfig &
}));
}

appendIssues(issues, lanelet::validation::validateMap(*map, val_config));
TaikiYamada4 marked this conversation as resolved.
Show resolved Hide resolved
return issues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef COMMON__CLI_HPP_
#define COMMON__CLI_HPP_
#ifndef LANELET2_MAP_VALIDATOR__CLI_HPP_
#define LANELET2_MAP_VALIDATOR__CLI_HPP_

#include <boost/program_options.hpp>

Expand Down Expand Up @@ -42,4 +42,4 @@ MetaConfig parseCommandLine(int argc, const char * argv[]);
} // namespace autoware
} // namespace lanelet

#endif // COMMON__CLI_HPP_
#endif // LANELET2_MAP_VALIDATOR__CLI_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef COMMON__UTILS_HPP_
#define COMMON__UTILS_HPP_
#ifndef LANELET2_MAP_VALIDATOR__UTILS_HPP_
#define LANELET2_MAP_VALIDATOR__UTILS_HPP_

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>
Expand Down Expand Up @@ -80,4 +80,4 @@ void checkPrimitivesType(
} // namespace autoware
} // namespace lanelet

#endif // COMMON__UTILS_HPP_
#endif // LANELET2_MAP_VALIDATOR__UTILS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef COMMON__VALIDATION_HPP_
#define COMMON__VALIDATION_HPP_
#ifndef LANELET2_MAP_VALIDATOR__VALIDATION_HPP_
#define LANELET2_MAP_VALIDATOR__VALIDATION_HPP_

#include "common/cli.hpp"
#include "common/utils.hpp"
#include "lanelet2_map_validator/cli.hpp"
#include "lanelet2_map_validator/utils.hpp"

#include <lanelet2_io/Io.h>
#include <lanelet2_projection/UTM.h>
Expand All @@ -25,6 +25,7 @@

#include <memory>
#include <regex>
#include <string>
#include <vector>

namespace
Expand All @@ -43,10 +44,13 @@ namespace autoware
{
namespace validation
{
std::unique_ptr<lanelet::Projector> getProjector(const MetaConfig & config);
std::vector<lanelet::validation::DetectedIssues> validateMap(const MetaConfig & config);
std::unique_ptr<lanelet::Projector> getProjector(
const std::string & projector_type, const lanelet::GPSPoint & origin);
std::vector<lanelet::validation::DetectedIssues> validateMap(
const std::string & projector_type, const std::string & map_file,
const lanelet::validation::ValidationConfig & val_config);
} // namespace validation
} // namespace autoware
} // namespace lanelet

#endif // COMMON__VALIDATION_HPP_
#endif // LANELET2_MAP_VALIDATOR__VALIDATION_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VALIDATORS__CROSSWALK__MISSING_REGULATORY_ELEMENTS_FOR_CROSSWALKS_HPP_
#define VALIDATORS__CROSSWALK__MISSING_REGULATORY_ELEMENTS_FOR_CROSSWALKS_HPP_
#ifndef LANELET2_MAP_VALIDATOR__VALIDATORS__CROSSWALK__MISSING_REGULATORY_ELEMENTS_FOR_CROSSWALKS_HPP_ // NOLINT
#define LANELET2_MAP_VALIDATOR__VALIDATORS__CROSSWALK__MISSING_REGULATORY_ELEMENTS_FOR_CROSSWALKS_HPP_ // NOLINT

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>
Expand All @@ -36,4 +36,6 @@ class MissingRegulatoryElementsForCrosswalksValidator : public lanelet::validati
} // namespace validation
} // namespace lanelet

#endif // VALIDATORS__CROSSWALK__MISSING_REGULATORY_ELEMENTS_FOR_CROSSWALKS_HPP_
// clang-format off
#endif // LANELET2_MAP_VALIDATOR__VALIDATORS__CROSSWALK__MISSING_REGULATORY_ELEMENTS_FOR_CROSSWALKS_HPP_ // NOLINT
// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VALIDATORS__CROSSWALK__REGULATORY_ELEMENT_DETAILS_FOR_CROSSWALKS_HPP_
#define VALIDATORS__CROSSWALK__REGULATORY_ELEMENT_DETAILS_FOR_CROSSWALKS_HPP_
#ifndef LANELET2_MAP_VALIDATOR__VALIDATORS__CROSSWALK__REGULATORY_ELEMENT_DETAILS_FOR_CROSSWALKS_HPP_ // NOLINT
#define LANELET2_MAP_VALIDATOR__VALIDATORS__CROSSWALK__REGULATORY_ELEMENT_DETAILS_FOR_CROSSWALKS_HPP_ // NOLINT

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>
Expand All @@ -36,4 +36,6 @@ class RegulatoryElementsDetailsForCrosswalksValidator : public lanelet::validati
} // namespace validation
} // namespace lanelet

#endif // VALIDATORS__CROSSWALK__REGULATORY_ELEMENT_DETAILS_FOR_CROSSWALKS_HPP_
// clang-format off
#endif // LANELET2_MAP_VALIDATOR__VALIDATORS__CROSSWALK__REGULATORY_ELEMENT_DETAILS_FOR_CROSSWALKS_HPP_ // NOLINT
// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VALIDATORS__STOP_LINE__MISSING_REGULATORY_ELEMENTS_FOR_STOP_LINES_HPP_
#define VALIDATORS__STOP_LINE__MISSING_REGULATORY_ELEMENTS_FOR_STOP_LINES_HPP_
#ifndef LANELET2_MAP_VALIDATOR__VALIDATORS__STOP_LINE__MISSING_REGULATORY_ELEMENTS_FOR_STOP_LINES_HPP_ // NOLINT
#define LANELET2_MAP_VALIDATOR__VALIDATORS__STOP_LINE__MISSING_REGULATORY_ELEMENTS_FOR_STOP_LINES_HPP_ // NOLINT

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>
Expand All @@ -36,4 +36,6 @@ class MissingRegulatoryElementsForStopLinesValidator : public lanelet::validatio
} // namespace validation
} // namespace lanelet

#endif // VALIDATORS__STOP_LINE__MISSING_REGULATORY_ELEMENTS_FOR_STOP_LINES_HPP_
// clang-format off
#endif // LANELET2_MAP_VALIDATOR__VALIDATORS__STOP_LINE__MISSING_REGULATORY_ELEMENTS_FOR_STOP_LINES_HPP_ // NOLINT
// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VALIDATORS__TRAFFIC_LIGHT__MISSING_REGULATORY_ELEMENTS_FOR_TRAFFIC_LIGHTS_HPP_
#define VALIDATORS__TRAFFIC_LIGHT__MISSING_REGULATORY_ELEMENTS_FOR_TRAFFIC_LIGHTS_HPP_
#ifndef LANELET2_MAP_VALIDATOR__VALIDATORS__TRAFFIC_LIGHT__MISSING_REGULATORY_ELEMENTS_FOR_TRAFFIC_LIGHTS_HPP_ // NOLINT
#define LANELET2_MAP_VALIDATOR__VALIDATORS__TRAFFIC_LIGHT__MISSING_REGULATORY_ELEMENTS_FOR_TRAFFIC_LIGHTS_HPP_ // NOLINT

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>
Expand All @@ -39,4 +39,6 @@ class MissingRegulatoryElementsForTrafficLightsValidator : public lanelet::valid
} // namespace validation
} // namespace lanelet

#endif // VALIDATORS__TRAFFIC_LIGHT__MISSING_REGULATORY_ELEMENTS_FOR_TRAFFIC_LIGHTS_HPP_
// clang-format off
#endif // LANELET2_MAP_VALIDATOR__VALIDATORS__TRAFFIC_LIGHT__MISSING_REGULATORY_ELEMENTS_FOR_TRAFFIC_LIGHTS_HPP_ // NOLINT
// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VALIDATORS__TRAFFIC_LIGHT__REGULATORY_ELEMENT_DETAILS_FOR_TRAFFIC_LIGHTS_HPP_
#define VALIDATORS__TRAFFIC_LIGHT__REGULATORY_ELEMENT_DETAILS_FOR_TRAFFIC_LIGHTS_HPP_
#ifndef LANELET2_MAP_VALIDATOR__VALIDATORS__TRAFFIC_LIGHT__REGULATORY_ELEMENT_DETAILS_FOR_TRAFFIC_LIGHTS_HPP_ // NOLINT
#define LANELET2_MAP_VALIDATOR__VALIDATORS__TRAFFIC_LIGHT__REGULATORY_ELEMENT_DETAILS_FOR_TRAFFIC_LIGHTS_HPP_ // NOLINT

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>
Expand Down Expand Up @@ -43,4 +43,6 @@ class RegulatoryElementsDetailsForTrafficLightsValidator : public lanelet::valid
} // namespace validation
} // namespace lanelet

#endif // VALIDATORS__TRAFFIC_LIGHT__REGULATORY_ELEMENT_DETAILS_FOR_TRAFFIC_LIGHTS_HPP_
// clang-format off
#endif // LANELET2_MAP_VALIDATOR__VALIDATORS__TRAFFIC_LIGHT__REGULATORY_ELEMENT_DETAILS_FOR_TRAFFIC_LIGHTS_HPP_ // NOLINT
// clang-format on
29 changes: 20 additions & 9 deletions map/autoware_lanelet2_map_validator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/cli.hpp"
#include "common/utils.hpp"
#include "common/validation.hpp"
#include "lanelet2_validation/Validation.h"
#include "lanelet2_map_validator/cli.hpp"
#include "lanelet2_map_validator/utils.hpp"
#include "lanelet2_map_validator/validation.hpp"

#include <nlohmann/json.hpp>

#include <lanelet2_validation/Validation.h>

#include <filesystem>
#include <fstream>
#include <iomanip>
Expand All @@ -35,12 +36,19 @@ using json = nlohmann::json;
#define NORMAL_RED "\033[31m"
#define FONT_RESET "\033[0m"

lanelet::validation::ValidationConfig replace_validator(
const lanelet::validation::ValidationConfig & input, const std::string & validator_name)
{
auto temp = input;
temp.checksFilter = validator_name;
return temp;
}

void process_requirements(
json json_config, const lanelet::autoware::validation::MetaConfig & validator_config)
{
uint64_t warning_count = 0;
uint64_t error_count = 0;
lanelet::autoware::validation::MetaConfig temp_validator_config = validator_config;

for (auto & requirement : json_config["requirements"]) {
std::string id = requirement["id"];
Expand All @@ -50,11 +58,12 @@ void process_requirements(
std::map<std::string, bool> temp_validation_results;

for (auto & validator : requirement["validators"]) {
std::string validator_name = validator["name"];
temp_validator_config.command_line_config.validationConfig.checksFilter = validator_name;
const std::string validator_name = validator["name"];

std::vector<lanelet::validation::DetectedIssues> temp_issues =
lanelet::autoware::validation::validateMap(temp_validator_config);
lanelet::autoware::validation::validateMap(
validator_config.projector_type, validator_config.command_line_config.mapFile,
replace_validator(validator_config.command_line_config.validationConfig, validator_name));

if (temp_issues.empty()) {
// Validator passed
Expand Down Expand Up @@ -176,7 +185,9 @@ int main(int argc, char * argv[])
input_file >> json_config;
process_requirements(json_config, meta_config);
} else {
auto issues = lanelet::autoware::validation::validateMap(meta_config);
auto issues = lanelet::autoware::validation::validateMap(
meta_config.projector_type, meta_config.command_line_config.mapFile,
meta_config.command_line_config.validationConfig);
lanelet::validation::printAllIssues(issues);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/utils.hpp"
#include "validators/crosswalk/missing_regulatory_elements_for_crosswalks.hpp"
#include "lanelet2_map_validator/utils.hpp"
#include "lanelet2_map_validator/validators/crosswalk/missing_regulatory_elements_for_crosswalks.hpp"

#include <range/v3/view/filter.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "validators/crosswalk/regulatory_element_details_for_crosswalks.hpp"
#include "lanelet2_map_validator/validators/crosswalk/regulatory_element_details_for_crosswalks.hpp"

#include "common/utils.hpp"
#include "lanelet2_map_validator/utils.hpp"

#include <autoware_lanelet2_extension/regulatory_elements/crosswalk.hpp>
#include <range/v3/view/filter.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "validators/stop_line/missing_regulatory_elements_for_stop_lines.hpp"
#include "lanelet2_map_validator/validators/stop_line/missing_regulatory_elements_for_stop_lines.hpp"

#include "common/utils.hpp"
#include "lanelet2_map_validator/utils.hpp"

#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "validators/traffic_light/missing_regulatory_elements_for_traffic_lights.hpp"
#include "lanelet2_map_validator/validators/traffic_light/missing_regulatory_elements_for_traffic_lights.hpp"

#include "common/utils.hpp"
#include "lanelet2_map_validator/utils.hpp"

#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
Expand Down
Loading
Loading