From 08827c075a0780835a0422592961ecb702aa2d04 Mon Sep 17 00:00:00 2001 From: s0nofab1t Date: Thu, 16 Jul 2026 18:16:54 +0200 Subject: [PATCH 1/2] Moved map downloader etc. to new submodule tridap Signed-off-by: s0nofab1t --- CMakeLists.txt | 8 +- include/adore_map/border.hpp | 2 +- include/adore_map/border_spline.hpp | 3 +- include/adore_map/bounding_box.hpp | 85 ---- include/adore_map/config.hpp | 53 --- include/adore_map/curl_wrapper.hpp | 89 ----- include/adore_map/helpers.hpp | 3 +- include/adore_map/json_file_helpers.hpp | 91 ----- include/adore_map/lane.hpp | 2 +- include/adore_map/lat_long_conversions.hpp | 2 +- include/adore_map/map.hpp | 2 - include/adore_map/map_cache.hpp | 437 --------------------- include/adore_map/map_downloader.hpp | 208 ---------- include/adore_map/map_loader.hpp | 4 +- include/adore_map/map_point.hpp | 2 + include/adore_map/r2s_parser.h | 14 +- include/adore_map/traffic_light.hpp | 1 - include/adore_map/xcache.hpp | 114 ------ package.xml | 5 +- src/bounding_box.cpp | 102 ----- src/config.cpp | 46 --- src/curl_wrapper.cpp | 202 ---------- src/lane.cpp | 2 - src/lat_long_conversions.cpp | 2 +- src/map_downloader.cpp | 255 ------------ src/map_loader.cpp | 12 +- src/r2s_parser.cpp | 14 +- src/road_graph.cpp | 1 - src/route.cpp | 1 - test/map_download_cache_test.cpp | 32 +- 30 files changed, 54 insertions(+), 1740 deletions(-) delete mode 100644 include/adore_map/bounding_box.hpp delete mode 100644 include/adore_map/config.hpp delete mode 100644 include/adore_map/curl_wrapper.hpp delete mode 100644 include/adore_map/json_file_helpers.hpp delete mode 100644 include/adore_map/map_cache.hpp delete mode 100644 include/adore_map/map_downloader.hpp delete mode 100644 include/adore_map/xcache.hpp delete mode 100644 src/bounding_box.cpp delete mode 100644 src/config.cpp delete mode 100644 src/curl_wrapper.cpp delete mode 100644 src/map_downloader.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b2a6045..73ccb4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,11 +11,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(ament_cmake REQUIRED) find_package(OpenDrive REQUIRED) find_package(adore_math REQUIRED) +find_package(adore_tridap REQUIRED) find_package(OpenCV REQUIRED) find_package(PROJ REQUIRED) find_package(Eigen3 REQUIRED) -find_package(CURL REQUIRED) -find_package(caches CONFIG REQUIRED) if(CMAKE_BUILD_TYPE STREQUAL "Release") add_compile_options(-O3) @@ -41,10 +40,9 @@ target_link_libraries(${PROJECT_NAME} PUBLIC OpenDrive::OpenDrive adore_math::adore_math + adore_tridap::adore_tridap PROJ::proj Eigen3::Eigen - CURL::libcurl - caches::caches # Add ${OpenCV_LIBS} here if you have compiled OpenCV dependencies. ) @@ -86,7 +84,7 @@ install(EXPORT export_${PROJECT_NAME} # ament exports for ROS 2 packages ament_export_include_directories(include) -ament_export_dependencies(OpenDrive PROJ adore_math OpenCV Eigen3 caches) +ament_export_dependencies(OpenDrive PROJ adore_math adore_tridap OpenCV Eigen3) ament_export_targets(export_${PROJECT_NAME}) ament_package() diff --git a/include/adore_map/border.hpp b/include/adore_map/border.hpp index a6664e4..f428aa9 100644 --- a/include/adore_map/border.hpp +++ b/include/adore_map/border.hpp @@ -28,6 +28,7 @@ namespace adore { namespace map { + struct Border { @@ -95,6 +96,5 @@ void process_center( Borders& borders ); void set_parent_id( Borders& borders, size_t parent_id ); - } // namespace map } // namespace adore diff --git a/include/adore_map/border_spline.hpp b/include/adore_map/border_spline.hpp index 62b8930..378aeea 100644 --- a/include/adore_map/border_spline.hpp +++ b/include/adore_map/border_spline.hpp @@ -27,9 +27,9 @@ namespace adore { - namespace map { + class BorderSpline { private: @@ -249,6 +249,5 @@ class BorderSpline } }; - } // namespace map } // namespace adore diff --git a/include/adore_map/bounding_box.hpp b/include/adore_map/bounding_box.hpp deleted file mode 100644 index 4419eff..0000000 --- a/include/adore_map/bounding_box.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include - -/** - * @brief Class representing a bounding box for spatial queries - */ -class BoundingBox -{ -public: - - /** @brief Parameterized constructor for BoundingBox: takes min and max latitude and longitude, and a coordinate reference system (CRS) - * @param[in] min_lat Minimum latitude of the bounding box - * @param[in] min_lon Minimum longitude of the bounding box - * @param[in] max_lat Maximum latitude of the bounding box - * @param[in] max_lon Maximum longitude of the bounding box - * @param[in] crs Coordinate reference system (e.g., "EPSG:4326") - * @details The constructor performs a sanity check on the provided coordinates to ensure they form a valid bounding box. - */ - BoundingBox( const double min_lat, const double min_lon, const double max_lat, const double max_lon, const std::string& crs ); - - /** @brief Parameterized constructor for BoundingBox: takes a vector of coordinates and a coordinate reference system (CRS) - * @param[in] coords A vector of doubles representing the bounding box coordinates in the order: min_lat, min_lon, max_lat, max_lon - * @param[in] crs Coordinate reference system (e.g., "EPSG:4326") - * @details The constructor performs a sanity check on the provided coordinates to ensure they form a valid bounding box. - */ - BoundingBox( const std::vector& coords, const std::string& crs ); - - // Getters for the bounding box coordinates and CRS - inline const double get_min_lat() const { return min_lat; } - inline const double get_min_lon() const { return min_lon; } - inline const double get_max_lat() const { return max_lat; } - inline const double get_max_lon() const { return max_lon; } - inline const std::string& get_crs() const { return crs; } - - /** @brief Convert the bounding box to a string representation - * @details The string representation is formatted for use in query parameters, - * excluding the "bbox=" prefix. - */ - std::string to_string() const; - - /** @brief Convert the bounding box to a query string format - */ - std::string to_query_string() const; - -private: - - /** @brief Checks a bounding box given as four coordinates for sanity and returns a BoundingBox object - * @details First coordinate pair for lower left corner, second coordinate pair for upper right corner - * @details Validates the provided coordinates and constructs a BoundingBox object - * @note The \ref target_srs parameter is used to set the coordinate reference system of the bounding box - * @param[in] coords A vector of doubles representing the bounding box coordinates - * @param[in] target_srs The target spatial reference system - * @return A BoundingBox object representing the parsed bounding box - */ - static void sanity_check_bounding_box( const std::vector& coords, - const std::string& target_srs ); - - // Coordinates for the bounding box and the coordinate reference system (CRS) - // The coordinates are in the order: min_lat, min_lon, max_lat, max_lon - // CRS is a string representing the coordinate reference system (e.g., "EPSG:4326") - // This class can be used to define a bounding box for spatial queries - // or to specify the area of interest for map loading operations - // The coordinates are typically in decimal degrees for geographic coordinates - // or in meters for projected coordinates, depending on the CRS used - const double min_lat; - const double min_lon; - const double max_lat; - const double max_lon; - const std::string crs; // Coordinate Reference System - constexpr static int precision = 6; -}; diff --git a/include/adore_map/config.hpp b/include/adore_map/config.hpp deleted file mode 100644 index 9c21a26..0000000 --- a/include/adore_map/config.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include -#include "adore_map/bounding_box.hpp" - -/** - * @brief Class to handle the configuration for the map downloader, stored in a JSON file - */ -class Config -{ -public: - - const nlohmann::json props; - const std::string server_url; - const std::string project_name; - const std::string target_srs; - const BoundingBox bbox; - const std::string username; - const std::string password; - const std::string layer_name_reference_lines; - const std::string layer_name_lane_borders; - const std::string reference_line_filename; - const std::string lane_border_filename; - - /** @brief Parameterized constructor that initializes the configuration from a JSON file - * @param[in] filename Path to the JSON file - */ - Config( const std::string& filename ); - -private: - - /** @brief Loads configuration from a JSON file and returns an nlohmann::json object - * @details This function reads a JSON file and returns an nlohmann::json object - * representing the key-value pairs of the configuration. It also prints out - * the loaded configuration for verification. - * @param[in] filename The path to the JSON file - * @return An nlohmann::json object containing the loaded configuration - */ - static nlohmann::json load_config( const std::string& filename ); -}; diff --git a/include/adore_map/curl_wrapper.hpp b/include/adore_map/curl_wrapper.hpp deleted file mode 100644 index 6f9b070..0000000 --- a/include/adore_map/curl_wrapper.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include -#include - -/** - * @brief A wrapper class for cURL to manage initialization and cleanup in a RAII manner. - * @details This class encapsulates a cURL easy handle and manages its lifecycle. It also handles - * global initialization and cleanup of the cURL library if specified. The class provides - * methods to set common cURL options and a write callback for handling response data. - */ -class CurlWrapper { -public: - - /** @brief Factory method to create a CurlWrapper instance - * @param[in] global_init If true, performs global cURL initialization - * @param[in] global_cleanup If true, will perform global cURL cleanup in the destructor - * @param[in] debug_mode If true, enables debug output - * @return std::unique_ptr A unique pointer to the created CurlWrapper instance - */ - static std::unique_ptr make( const bool global_init = false, const bool global_cleanup = false, - const bool debug_mode = false ); - - /** @brief Destructor for CurlWrapper - * @details Cleans up the cURL easy handle and performs global cleanup if specified. - */ - ~CurlWrapper(); - - /** @brief cURL write callback function - * @param[in] ptr Pointer to the data received from cURL - * @param[in] size Size of each data element - * @param[in] nmemb Number of data elements - * @param[out] userdata Pointer to the user data (in this case, a std::string) - * @return Number of bytes written - */ - static size_t write_callback( char* ptr, size_t size, size_t nmemb, void* userdata ); - - /** @brief Sets general cURL options including authentication and write callback - * @param[in] username The username for authentication - * @param[in] password The password for authentication - * @return CURLcode indicating the result of setting options - */ - CURLcode set_general_options( const std::string& username, const std::string& password ); - - /** @brief Sets the URL for the cURL request - * @param[in] url The URL to set - * @return CURLcode indicating the result of setting the URL - */ - CURLcode set_url( const std::string& url ); - - /** @brief Performs the cURL request - * @return CURLcode indicating the result of the perform operation - */ - CURLcode perform(); - - /** @brief Downloads data from the specified URL - * @param[in] url The URL to download data from - * @return CURLcode indicating the result of the download operation - */ - CURLcode download( const std::string& url ); - - // Getters - - inline std::string& get_read_buffer() { return read_buffer; } - inline CURL* get_curl() { return curl; } - -private: - - /** @brief Private constructor for CurlWrapper - */ - explicit CurlWrapper( CURL* curl, const bool global_cleanup = false, const bool debug = false ); - CURL* curl; - std::string read_buffer; - const bool global_cleanup; - const bool debug_mode; -}; diff --git a/include/adore_map/helpers.hpp b/include/adore_map/helpers.hpp index af1a076..7c65a98 100644 --- a/include/adore_map/helpers.hpp +++ b/include/adore_map/helpers.hpp @@ -34,7 +34,7 @@ remove_duplicate_points( std::vector& points ) namespace r2s { -/** @brief Rounds a double to six decimal places. +/** @brief Rounds a double to six decimal places */ inline static double round_to_six_decimal_places( const double number ) { @@ -42,5 +42,4 @@ round_to_six_decimal_places( const double number ) { } } // namespace r2s - } // namespace adore diff --git a/include/adore_map/json_file_helpers.hpp b/include/adore_map/json_file_helpers.hpp deleted file mode 100644 index f430306..0000000 --- a/include/adore_map/json_file_helpers.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include -#include -#include - -/** - * @brief Helper class for saving and loading JSON files. If a context string is provided, - * it is used in error messages to indicate the calling context. - */ -class JsonFileHelpers -{ -public: - - JsonFileHelpers() = delete; // Delete the default constructor to prevent instantiation - - /** @brief Saves the given JSON data to a file - * @param[in] json_data The JSON data to save - * @param[in] filename The name of the file to save the JSON data to - * @param[in] context An optional string to provide (calling) context in error messages - */ - static void - save( const nlohmann::json& json_data, const std::string& filename, - const std::string& context = "" ) - { - std::ofstream file( filename ); - if( file.is_open() ) - { - try - { - file << json_data; - } - catch( const std::exception& e ) - { - std::cerr << ( context.empty() ? "JsonFileHelpers::save" : context ) - << ": Error writing JSON data to file " << filename << ": " << e.what() << std::endl; - throw std::runtime_error( "Error writing JSON data to file " + filename + ": " + e.what() ); - } - } - else - { - std::cerr << ( context.empty() ? "JsonFileHelpers::save" : context ) - << ": Failed to open JSON file for writing: " << filename << std::endl; - throw std::runtime_error( "Failed to open JSON file for writing: " + filename ); - } - } - - /** @brief Loads JSON data from a file - * @param[in] filename The name of the file to load the JSON data from - * @param[out] json_data The JSON object to load the data into - * @param[in] context An optional string to provide (calling) context in error messages - */ - static void - load( const std::string& filename, nlohmann::json& json_data, - const std::string& context = "" ) - { - std::ifstream file( filename ); - if( file.is_open() ) - { - try - { - json_data = nlohmann::json::parse( file ); - file.close(); - } - catch( const nlohmann::json::parse_error& e ) - { - std::cerr << ( context.empty() ? "JsonFileHelpers::load" : context ) << ": JSON parse error in file " - << filename << ": " << e.what() << std::endl; - throw std::runtime_error( "JSON parse error in file " + filename + ": " + e.what() ) ; - } - } - else - { - std::cerr << ( context.empty() ? "JsonFileHelpers::load" : context ) << ": Failed to open JSON file: " << filename << std::endl; - throw std::runtime_error( "Failed to open JSON file: " + filename ); - } - } -}; diff --git a/include/adore_map/lane.hpp b/include/adore_map/lane.hpp index 9d1141a..73e382c 100644 --- a/include/adore_map/lane.hpp +++ b/include/adore_map/lane.hpp @@ -29,6 +29,7 @@ namespace adore { namespace map { + enum LaneMaterial { asphalt, @@ -125,6 +126,5 @@ struct Road } }; - } // namespace map } // namespace adore diff --git a/include/adore_map/lat_long_conversions.hpp b/include/adore_map/lat_long_conversions.hpp index a14e002..071f9be 100644 --- a/include/adore_map/lat_long_conversions.hpp +++ b/include/adore_map/lat_long_conversions.hpp @@ -26,7 +26,6 @@ namespace adore namespace map { - // Function to execute a shell command and capture its output std::string execute_shell_command( const std::string& command ); @@ -38,5 +37,6 @@ std::vector convert_utm_to_lat_lon_python( double utm_x, double utm_y, i // Function to convert Latitude and Longitude UTM coordinates std::vector convert_lat_lon_to_utm( double lat, double lon ); std::vector convert_lat_lon_to_utm_python( double lat, double lon ); + } // namespace map } // namespace adore diff --git a/include/adore_map/map.hpp b/include/adore_map/map.hpp index d10a4e2..9b478f7 100644 --- a/include/adore_map/map.hpp +++ b/include/adore_map/map.hpp @@ -37,7 +37,6 @@ namespace adore namespace map { - // The Map class definition class Map { @@ -265,6 +264,5 @@ get_map_distance( const MapPoint& start_point, const MapPoint& end_point, const return total_distance; } - } // namespace map } // namespace adore diff --git a/include/adore_map/map_cache.hpp b/include/adore_map/map_cache.hpp deleted file mode 100644 index 6baec75..0000000 --- a/include/adore_map/map_cache.hpp +++ /dev/null @@ -1,437 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include -#include -#include -#include -#include "caches/lru_cache_policy.hpp" -#include "adore_map/xcache.hpp" -#include "adore_map/json_file_helpers.hpp" - -// Alias for an easy class typing -template -using lru_cache_t = typename caches::fixed_sized_cache; - -template -using lru_xcache_t = typename caches::XCache; - -/** - * @brief MapCache is a two-level cache system with RAM and disk caching for map data. - * @note This class uses LRU cache policy for both RAM and disk caches. - * @note The disk cache stores map data as files in a specified directory, with filenames - * corresponding to unique keys. The RAM cache holds the actual map data in memory for quick access. - * @details The MapCache class provides a two-level caching mechanism for map data, utilizing - * both RAM and disk storage. It employs LRU (Least Recently Used) cache policy for both - * levels of caching to optimize data retrieval and storage efficiency. Items evicted from RAM - * cache will be inserted into disk cache and items on disk will be inserted back to - * RAM cache upon lookup. Cache contents are saved to disk upon exit (by the destructor), - * and reloaded for the next session (by the constructor). All of these transitions are transparent - * to users. - */ -class MapCache -{ -public: - - /** @brief Default MapCache constructor - * @details This constructor initializes an empty MapCache with default parameters - * @note A directory for disk cache must be set up later using set_up_file_cache_path() before using the cache. - */ - MapCache() : my_file_cache_path( "" ), ram_cache_size( 64 ), disk_cache_size( 256 ), entry_count( 0 ), - on_final_clear( false ), is_active( true ), debug_mode( false ), - ram_cache( ram_cache_size, caches::LRUCachePolicy(), - [this]( const std::string& key, - const lru_cache_t::value_type& value_handle ) - { - this->on_erase_callback_for_ram_cache( key, value_handle ); - }), - disk_cache( disk_cache_size, caches::LRUCachePolicy(), - [this]( const std::string& key, - const lru_cache_t::value_type& value_handle ) - { - this->on_erase_callback_for_disk_cache( key, value_handle ); - }) - { - }; - - /** @brief MapCache constructor - * @param[in] file_cache_path Path to the directory where disk cache files will be stored - * @param[in] ram_cache_size Maximum size of the RAM cache (in number of entries) - * @param[in] disk_cache_size Maximum size of the disk cache (in number of entries) - * @param[in] active Boolean flag to activate or deactivate the cache - * @param[in] debug_mode Boolean flag to enable or disable debug mode - */ - MapCache( const std::string& file_cache_path, const std::size_t ram_cache_size = 64, - const std::size_t disk_cache_size = 256, const bool active = true, const bool debug_mode = false ) : - my_file_cache_path( file_cache_path ), ram_cache_size( ram_cache_size ), - disk_cache_size( disk_cache_size ), entry_count( 0 ), on_final_clear( false ), - is_active( active ), debug_mode( debug_mode ), - ram_cache( ram_cache_size, caches::LRUCachePolicy(), - [this]( const std::string& key, - const lru_cache_t::value_type& value_handle ) - { - this->on_erase_callback_for_ram_cache( key, value_handle ); - }), - disk_cache( disk_cache_size, caches::LRUCachePolicy(), - [this]( const std::string& key, - const lru_cache_t::value_type& value_handle ) - { - this->on_erase_callback_for_disk_cache( key, value_handle ); - }) - { - set_up_file_cache_path( file_cache_path ); - } - - /** @brief MapCache destructor - * @details The destructor saves all cache entries to disk by invoking the onEraseCallback - * for each entry in the disk cache. - */ - ~MapCache() - { - // Save all cache entries to disk (via onEraseCallback) - on_final_clear = true; - if( debug_mode ) - { - // Debugging line to see the final clear operation - std::cout << "MapCache::~MapCache: Final clear operation, saving disk cache entries to " - << my_file_cache_path << "cached.map" << std::endl; - } - std::cout << "MapCache::~MapCache: disk cache size: " << disk_cache.Size() << std::endl; - } - - /** @brief Set up the file cache path - * @note As a side effect, this method also loads any existing cache entries from the specified directory into the disk cache. - * @param[in] file_cache_path New path to the directory where disk cache files will be stored - */ - void - set_up_file_cache_path( const std::string& file_cache_path ) - { - my_file_cache_path = file_cache_path; - // Ensure the cache directory exists - if( my_file_cache_path.empty() ) - { - my_file_cache_path = "cache/"; // Use forward slash for cross-platform compatibility - if( debug_mode ) - { - // Debugging line to see the cache path being used - std::cout << "MapCache::set_up_file_cache_path: " << my_file_cache_path << std::endl; - // Debugging line to see the current working directory - std::cout << "MapCache::set_up_file_cache_path: Current working directory: " << std::filesystem::current_path() << std::endl; - } - } - if( !std::filesystem::is_directory( my_file_cache_path ) ) - { - if( debug_mode ) - { - std::cout << "MapCache::set_up_file_cache_path: file cache path does not exist: " << my_file_cache_path << std::endl; - std::cout << "MapCache::set_up_file_cache_path: Creating cache directory at " << my_file_cache_path << std::endl; - } - if( !std::filesystem::create_directories( my_file_cache_path ) ) - { - std::cerr << "MapCache::set_up_file_cache_path: Failed to create cache directory: " << my_file_cache_path << '\n'; - } - } - if( !my_file_cache_path.empty() && my_file_cache_path.back() != '/' ) - { - my_file_cache_path += "/"; - } - if( std::ifstream( my_file_cache_path + "cached.map" ) ) - { - std::ifstream file( my_file_cache_path + "cached.map" ); - if( !file.is_open() ) - { - std::cerr << "MapCache::set_up_file_cache_path: Failed to open cached.map for reading: " - << my_file_cache_path + "cached.map" << std::endl; - return; - } - std::string key; - int value; - if( debug_mode ) - { - std::cout << "MapCache::set_up_file_cache_path: Loading previous disk cache contents from " - << my_file_cache_path + "cached.map" << std::endl; - } - while( file >> key >> value ) - { - if( entry_count >= disk_cache_size ) - { - // Cache too small to hold previous contents - break; - } - if( debug_mode ) - { - std::cout << "MapCache::set_up_file_cache_path: Putting key = " << key << " with entry number = " << entry_count - << " into disk cache." << std::endl; - } - disk_cache.Put( key, value ); - entry_count++; - } - file.close(); - // Delete previous copy of the cached.map file if it exists - std::remove( ( my_file_cache_path + "cached.map.backup" ).c_str() ); - // Rename the current cached.map file to cached.map.backup as a backup - if( std::rename( ( my_file_cache_path + "cached.map" ).c_str(), - ( my_file_cache_path + "cached.map.backup" ).c_str() ) != 0 ) - { - std::cerr << "MapCache::set_up_file_cache_path: Failed to rename cached.map to cached.map.backup." << std::endl; - } - } - else - { - if( debug_mode ) - { - // Debugging line to see that no previous cache was found - std::cout << "MapCache::set_up_file_cache_path: MapCache: No previous cache found, fresh start (file cache path: " << - my_file_cache_path << ")." << std::endl; - } - } - if( debug_mode ) - { - // Debugging line to see file_cache_path - std::cout << "MapCache::set_up_file_cache_path: Still using file cache path: " << my_file_cache_path << std::endl; - } - } - - /** @brief Put a map data entry into the cache - * @param[in] key Unique key identifying the map data - * @param[in] value JSON object representing the map data - */ - void - put( const std::string& key, const nlohmann::json& value ) - { - if( is_active == false ) - { - std::cerr << "MapCache::put: Cache is not active, cannot put item." << std::endl; - return; - } - ram_cache.Put( key, value ); - if( disk_cache.TryGet( key ).second ) - { - if( debug_mode ) - { - // Debugging line to see the key being put into cache - std::cout << "MapCache::put: Map already exists in disk cache, skipping put operation." << std::endl; - } - return; - } - disk_cache.Put( key, entry_count ); - if( debug_mode ) - { - // Debugging line to see the file_cache_path and entry_count - std::cout << "MapCache::put: file_cache_path: " << my_file_cache_path << ", entry_count: " - << entry_count << std::endl; - std::cout << "MapCache::put: Saving entry to disk cache at " << my_file_cache_path - << "cache.entry_" << entry_count << ".json" << std::endl; - std::cout << "MapCache::put: Disk cache size: " << disk_cache.Size() << std::endl; - } - JsonFileHelpers::save( value, my_file_cache_path + "cache.entry_" + std::to_string( entry_count++ ) - + ".json", "MapCache::put" ); - } - - /** @brief Try to get a map data entry from the cache - * @param[in] key Unique key identifying the map data - * @return A shared pointer to the JSON object (or nullptr if not found) - */ - lru_cache_t::value_type - try_get( const std::string& key ) - { - if( is_active == false ) - { - std::cerr << "MapCache::try_get: Cache is not active, cannot get item.\n"; - return nullptr; - } - // If the key is empty, return a nullptr - if( key.empty() ) - { - return nullptr; - } - // First, check the RAM cache - std::pair::value_type, bool> ram_pair = ram_cache.TryGet( key ); - if( ram_pair.second ) - { - assert( ram_pair.first.get() != nullptr ); - return ram_pair.first; - } - // If not found in RAM cache, check the disk cache - std::pair::value_type, bool> disk_pair = disk_cache.TryGet( key ); - if( !disk_pair.second ) - { // Give up if not found in disk cache - if( debug_mode ) - { - // Debugging line to see that the key was not found in cache - std::cout << "MapCache::try_get: Key not found in cache: " << key << std::endl; - // Debugging line to see the file_cache_path - std::cout << "MapCache::try_get: file_cache_path: " << my_file_cache_path << std::endl; - } - return nullptr; - } - else - { - assert( disk_pair.first.get() != nullptr ); - // If found in disk cache, load the value from the file - if( debug_mode ) - { - // Debugging line to see the file_cache_path and entryCount - std::cout << "MapCache::try_get: file_cache_path: " << my_file_cache_path - << ", loaded entryCount: " << *disk_pair.first << std::endl; - std::cout << "MapCache::try_get: Saving entry to disk cache at " - << my_file_cache_path << "cache.entry_" << *disk_pair.first << ".json" << std::endl; - } - // Load the JSON data from the file - std::string filename = my_file_cache_path + "cache.entry_" + std::to_string( *disk_pair.first ) + ".json"; - std::shared_ptr json_data_ptr = std::make_shared(); - // Load the JSON data from the file - JsonFileHelpers::load( filename, *json_data_ptr, "MapCache::try_get" ); - // Insert item back into RAM cache - ram_cache.Put( key, *json_data_ptr ); - return json_data_ptr; - } - } - - /** @brief Turn off the cache - * @details When the cache is turned off, no cache operations will be performed. - */ - void - turn_off() - { - is_active = false; - if( debug_mode ) - { - // Debugging line - std::cout << "MapCache::turn_off: Cache is turned off, no cache operations will be performed." << std::endl; - } - } - - /** @brief Turn on the cache - * @details When the cache is turned on, cache operations will be performed. - */ - void - turn_on() - { - is_active = true; - if( debug_mode ) - { - // Debugging line - std::cout << "MapCache::turn_on: Cache is turned on, cache operations will be performed." << std::endl; - } - } - - /** @brief Returns whether the cache is active */ - inline const bool - is_cache_active() const { return is_active; } - - /** @brief set debug mode - * @param[in] is_debug_mode Boolean flag to enable or disable debug mode - * @details When debug mode is turned on, debugging messages will be sent to stdout. - */ - void - set_debug_mode( const bool& is_debug_mode ) - { - debug_mode = is_debug_mode; - if( debug_mode ) - { - std::cout << "MapCache::set_debug_mode: debug mode is turned on, debugging messages will be sent to stdout." - << std::endl; - } - } - -private: - - /** @brief Callback function invoked when an entry is evicted from the RAM cache - * @param[in] key Unique key identifying the map data - * @param[in] value_handle Shared pointer to the JSON object representing the map data - */ - void - on_erase_callback_for_ram_cache( const std::string& key, - const lru_cache_t::value_type& value_handle ) - { - if( disk_cache.TryGet( key ).second || entry_count >= disk_cache_size ) - { - if( debug_mode ) - { - // Debugging line to see the key being skipped for disk cache - std::cout << "MapCache::on_erase_callback_for_ram_cache: Disk cache full or map already exists in disk cache, " - << "skipping put operation." - << std::endl; - } - return; - } - // If the key is not already in disk cache, put it into disk cache and save the file - disk_cache.Put( key, entry_count ); - if( debug_mode ) - { - // Debugging line to see the file_cache_path and entryCount - std::cout << "MapCache::on_erase_callback_for_ram_cache: Saving entry to disk cache at " << my_file_cache_path - << "cache.entry_" << entry_count << ".json" << std::endl; - } - JsonFileHelpers::save( *value_handle, my_file_cache_path + "cache.entry_" + std::to_string( entry_count++ ) - + ".json", "MapCache::on_erase_callback_for_ram_cache" ); - } - - /** @brief Callback function invoked when an entry is evicted from the disk cache - * @param[in] key Unique key identifying the map data - * @param[in] value_handle Shared pointer to the integer representing the entry number - */ - void - on_erase_callback_for_disk_cache( const std::string& key, - const lru_cache_t::value_type& value_handle ) - { - if( on_final_clear ) - { - // If on_final_clear is true, we want to keep the file and also save the key-value pair - std::cout << "MapCache::on_erase_callback_for_disk_cache: Keeping cache entry for key: " << key << std::endl; - std::string filename = my_file_cache_path + "cached.map"; - if( debug_mode ) - { - // Debugging line to see the file_cache_path - std::cout << "MapCache::on_erase_callback_for_disk_cache: file_cache_path: " << my_file_cache_path << std::endl; - } - std::ofstream file( filename, std::ios::app ); - if( file.is_open() ) - { - file << key << " " << *value_handle << "\n"; // Save the key-value pair - file.close(); - } - else - { - std::cerr << "MapCache::on_erase_callback_for_disk_cache: Failed to open file for saving cache entry: " - << filename << std::endl; - } - } - else - { - // If on_final_clear is false, remove the file from disk - if( debug_mode ) - { - // Debugging line to see the key being erased from disk cache - std::cout << "MapCache::on_erase_callback_for_disk_cache: Erasing cache entry for key: " << key << std::endl; - std::cout << "MapCache::on_erase_callback_for_disk_cache: Removing entry from disk cache at " - << my_file_cache_path << "cache.entry_" << *value_handle << ".json" << std::endl; - } - std::remove( ( my_file_cache_path + "cache.entry_" + std::to_string( *value_handle ) + ".json" ).c_str() ); - entry_count--; - } - } - - std::string my_file_cache_path; - const size_t ram_cache_size; - const size_t disk_cache_size; - std::size_t entry_count; - bool on_final_clear; - bool is_active; - bool debug_mode; - lru_cache_t ram_cache; - lru_xcache_t disk_cache; -}; diff --git a/include/adore_map/map_downloader.hpp b/include/adore_map/map_downloader.hpp deleted file mode 100644 index 0c5acf7..0000000 --- a/include/adore_map/map_downloader.hpp +++ /dev/null @@ -1,208 +0,0 @@ - -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include -#include -#include "adore_map/map_cache.hpp" -#include "adore_map/curl_wrapper.hpp" -#include "adore_map/config.hpp" -#include "adore_map/bounding_box.hpp" - -/** - * @brief Class with caching capabilities for downloading map data from a WFS server - * @details This class provides methods to download map data from a specified server and project, - * with support for caching the downloaded data both in memory and on disk. It uses cURL - * for HTTP requests and nlohmann::json for handling JSON data. The class allows for easy - * retrieval of map data in JSON format. - */ -class MapDownloader -{ -public: - - /** @brief Constructor for MapDownloader using a configuration object - * @param[in] cfg Configuration object containing server and project details - * @param[in] file_cache_path Path to the directory for caching map layer data - */ - MapDownloader( const Config& cfg, const std::string& file_cache_path = "" ); - - /** @brief Parameterized constructor for MapDownloader - * @param[in] server_url URL of the map server - * @param[in] username Username for authentication - * @param[in] password Password for authentication - * @param[in] project_name Name of the project on the map server - * @param[in] srs_name Name of the spatial reference system (e.g., "EPSG:25832") - * @param[in] bounding_box Bounding box for the map layer data request - * @param[in] file_cache_path Path to the directory for caching map layer data - * @param[in] curl_global_init Boolean flag to indicate whether to perform global cURL initialization - * @param[in] curl_global_cleanup Boolean flag to indicate whether to perform global cURL cleanup in the destructor - * @param[in] debug_mode Boolean flag to enable or disable debug mode - */ - MapDownloader( const std::string& server_url, const std::string& username, const std::string& password, - const std::string& project_name, const std::string& srs_name, const BoundingBox& bounding_box, - const std::string& file_cache_path = "", const bool curl_global_init = false, - const bool curl_global_cleanup = false, const bool debug_mode = false ); - - /** @brief Downloads data for a specific map layer - * @param[in] layer_name Name of the layer to download - * @return true if the download is successful, false otherwise - */ - bool download( const std::string& layer_name ); - - /** @brief Downloads data for a specific map layer within a bounding box - * @param[in] layer_name Name of the layer to download - * @param[in] bounding_box Bounding box for the map layer data request - * @return true if the download is successful, false otherwise - */ - bool download( const std::string& layer_name, const BoundingBox& bounding_box ); - - /** @brief Pretty prints the map layer data stored in json_data - */ - void pretty_print(); - - /** @brief Unloads the map layer data from memory - * @details Clears the read buffer of the internal curl wrapper and the internal JSON data - */ - void unload(); - - /** @brief Saves the map layer data stored in json_data to a file - * @param[in] filename The name of the file to save the map layer data to - */ - void save( const std::string& filename ); - - /** @brief Loads the map layer data from a file into member variable json_data - * @param[in] filename The name of the file to load the map layer data from - */ - void load( const std::string& fileName ); - - /** @brief Turns off the map cache - * @details Disables caching of map layer data in the MapCache instance - */ - void turn_off_cache(); - - /** @brief Turns on the map cache - * @details Enables caching of map layer data in the MapCache instance - */ - void turn_on_cache(); - - /** @brief Returns whether the cache is active */ - inline const bool is_cache_active() const { return map_cache.is_cache_active(); } - - // Versions with more parameters for flexibility - - /** @brief Downloads data for a specific map layer within a bounding box - * @param[in] server_url URL of the map server - * @param[in] project_name Name of the project on the map server - * @param[in] srs_name Name of the spatial reference system (e.g., "EPSG:25832") - * @param[in] layer_name Name of the layer to download - * @param[in] bounding_box Bounding box for the map layer data request - * @return true if the download is successful, false otherwise - */ - bool download( const std::string& server_url, const std::string& project_name, - const std::string& srs_name, const std::string& layer_name, const BoundingBox& bounding_box ); - - /** @brief Unloads the map layer data from memory - * @details Clears the internal read buffer of the curl wrapper and the given JSON data - * @param[in] json_data JSON object to be cleared - */ - void unload( nlohmann::json& json_data ); - - /** @brief Pretty prints the map layer data from a given JSON object - * @param[in] json_data JSON object to be pretty printed - */ - static void pretty_print( const nlohmann::json& json_data ); - - /** @brief Saves the map layer data from a given JSON object to a file - * @param[in] json_data JSON object containing the map layer data - * @param[in] filename Name of the file to save the map layer data to - */ - static void save( const nlohmann::json& json_data, const std::string& filename ); - - /** @brief Loads the map layer data from a file into a given JSON object - * @param[in] filename Name of the file to load the map layer data from - * @param[out] json_data JSON object to populate with the map layer data - */ - static void load( const std::string& filename, nlohmann::json& json_data ); - - // Getters for member variables - - inline const std::string& get_read_buffer() const { return curl_wrapper->get_read_buffer(); } - inline const std::string& get_server_url() const { return server_url; } - inline const BoundingBox& get_bounding_box() const { return bounding_box; } - inline const std::string& get_project_name() const { return project_name; } - inline const std::string& get_srs_name() const { return srs_name; } - inline const nlohmann::json& get_json_data() const { return json_data; } - inline nlohmann::json& get_json_data() { return json_data; }; - inline const MapCache& get_map_cache() const { return map_cache; } - -private: - - /** @brief Downloads data as JSON for a specific map layer - * @param[in] layer_name Name of the layer to download - * @return true if the download is successful, false otherwise - */ - bool download_as_json( const std::string& layer_name ); - - /** @brief Downloads data as JSON for a specific layer within a bounding box - * @param[in] layer_name Name of the layer to download - * @param[in] bounding_box Bounding box for the map layer data request - * @return true if the download is successful, false otherwise - */ - bool download_as_json( const std::string& layer_name, const BoundingBox& bounding_box ); - - /** @brief Downloads map layer data as JSON - * @param[in] server_url URL of the map server - * @param[in] project_name Name of the project on the map server - * @param[in] srs_name Name of the spatial reference system (e.g., "EPSG:25832") - * @param[in] layer_name Name of the layer to download - * @param[in] bounding_box Bounding box for the map layer data request - * @return CURLcode indicating the result of the operation - */ - bool download_as_json( const std::string& server_url, const std::string& project_name, - const std::string& srs_name, const std::string& layer_name, const BoundingBox& bounding_box ); - - /** @brief Parses JSON data from the internal read buffer and populates the internal JSON data object */ - void parse_json(); - - /** @brief Parses JSON data from a string and populates the internal JSON data object - * @param[in] json_str JSON string to be parsed - */ - void parse_json( const std::string& json_str ); - - /** @brief Parses JSON data from the internal read buffer and populates the provided JSON data object - * @param[out] json_data JSON data object to be populated with the parsed data - */ - void parse_json( nlohmann::json& json_data ); - - /** @brief Parses JSON data from a string - * @param[in] json_str JSON string to be parsed - * @param[out] json_data JSON data object to be populated - */ - static void parse_json( const std::string& json_string, nlohmann::json& json_data ); - - /** @brief Saves the map layer data stored in json_data to a file - * @param[in] filename Name of the file to save the map data to - */ - void save_json( const std::string& filename ); - - std::unique_ptr curl_wrapper; - const std::string server_url; - const std::string project_name; - const std::string srs_name; - const BoundingBox bounding_box; - const bool debug_mode; // Flag to enable or disable debug mode - nlohmann::json json_data; - MapCache map_cache; // Instance of MapCache for caching map data -}; diff --git a/include/adore_map/map_loader.hpp b/include/adore_map/map_loader.hpp index 54bb02d..1bcee60 100644 --- a/include/adore_map/map_loader.hpp +++ b/include/adore_map/map_loader.hpp @@ -17,7 +17,7 @@ #include "adore_map/map.hpp" #include "adore_map/r2s_parser.h" -#include "adore_map/map_downloader.hpp" +#include "adore_tridap/map_downloader.hpp" #include "OpenDriveMap.h" #include "RoutingGraph.h" @@ -55,7 +55,7 @@ class MapLoader * @param[in] ignore_non_driving Boolean flag to indicate whether non-driving lanes should be ignored in the resulting Map * @return A Map object constructed from the downloaded map data */ - static Map download_from_wfs( MapDownloader& downloader, const std::string& reference_lines_layer_name, + static Map download_from_wfs( tridap::MapDownloader& downloader, const std::string& reference_lines_layer_name, const std::string& lane_borders_layer_name, bool allow_lane_changes = true, bool ignore_non_driving = false ); private: diff --git a/include/adore_map/map_point.hpp b/include/adore_map/map_point.hpp index 2523fa5..b4bedca 100644 --- a/include/adore_map/map_point.hpp +++ b/include/adore_map/map_point.hpp @@ -23,6 +23,7 @@ namespace adore { namespace map { + struct MapPoint { MapPoint( double x, double y, size_t parent_id ) : @@ -69,5 +70,6 @@ struct MapPoint }; // using MapPointPtr = std::shared_ptr; + } // namespace map } // namespace adore diff --git a/include/adore_map/r2s_parser.h b/include/adore_map/r2s_parser.h index a48a818..ae4c919 100644 --- a/include/adore_map/r2s_parser.h +++ b/include/adore_map/r2s_parser.h @@ -21,8 +21,8 @@ #include #include #include -#include "adore_map/map_downloader.hpp" #include "adore_map/helpers.hpp" +#include "adore_tridap/map_downloader.hpp" namespace adore { @@ -113,42 +113,42 @@ std::vector load_border_data_from_r2sr_file( const std::string& * @param[in] layer_name Name of the WFS layer to load reference lines from * @return A vector of BorderDataR2SR objects representing the loaded reference lines */ -std::vector download_reference_lines( MapDownloader& downloader, const std::string& layer_name ); +std::vector download_reference_lines( tridap::MapDownloader& downloader, const std::string& layer_name ); /** @brief Load reference lines from a JSON file using MapDownloader * @param[in] downloader Reference to the MapDownloader instance * @param[in] file_name Name of the file to load reference lines from * @return A vector of BorderDataR2SR objects representing the loaded reference lines */ -std::vector load_reference_lines_from_json_file( MapDownloader& downloader, const std::string& file_name ); +std::vector load_reference_lines_from_json_file( tridap::MapDownloader& downloader, const std::string& file_name ); /** @brief Parse reference lines from the JSON data in MapDownloader * @note Assumes that the JSON data has already been loaded into the MapDownloader * @param[in] downloader Reference to the MapDownloader instance * @return A vector of BorderDataR2SR objects parsed from the JSON data */ -std::vector parse_reference_lines( MapDownloader& downloader ); +std::vector parse_reference_lines( tridap::MapDownloader& downloader ); /** @brief Load lane borders from a WFS layer using MapDownloader * @param[in] downloader Reference to the MapDownloader instance * @param[in] layer_name Name of the WFS layer to load lane borders from * @return A vector of BorderDataR2SL objects representing the loaded lane borders */ -std::vector download_lane_borders( MapDownloader& downloader, const std::string& layer_name ); +std::vector download_lane_borders( tridap::MapDownloader& downloader, const std::string& layer_name ); /** @brief Load lane borders from a JSON file using MapDownloader * @param[in] downloader Reference to the MapDownloader instance * @param[in] file_name Name of the file to load lane borders from * @return A vector of BorderDataR2SL objects representing the loaded lane borders */ -std::vector load_lane_borders_from_json_file( MapDownloader& downloader, const std::string& file_name ); +std::vector load_lane_borders_from_json_file( tridap::MapDownloader& downloader, const std::string& file_name ); /** @brief Parse lane borders from the JSON data in MapDownloader * @note Assumes that the JSON data has already been loaded into the MapDownloader * @param[in] downloader Reference to the MapDownloader instance * @return A vector of BorderDataR2SL objects parsed from the JSON data */ -std::vector parse_lane_borders( MapDownloader& downloader ); +std::vector parse_lane_borders( tridap::MapDownloader& downloader ); // Print utility functions for debugging void print_string( const std::string& string_to_print ); diff --git a/include/adore_map/traffic_light.hpp b/include/adore_map/traffic_light.hpp index 8de872b..12fd25d 100644 --- a/include/adore_map/traffic_light.hpp +++ b/include/adore_map/traffic_light.hpp @@ -21,7 +21,6 @@ namespace adore namespace map { - struct TrafficLight { std::vector control_points; diff --git a/include/adore_map/xcache.hpp b/include/adore_map/xcache.hpp deleted file mode 100644 index 2438283..0000000 --- a/include/adore_map/xcache.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#pragma once -#include -#include - -namespace caches -{ - -/** - * @brief XCache is a fixed sized cache that can be used with different policy types (e.g. LRU, FIFO, LFU). - * @note This class e(x)tends the class fixed_sized_(cache) to provide a custom cache implementation - * @tparam Key Type of a key (should be hashable) - * @tparam Value Type of a value stored in the cache - * @tparam Policy Type of a policy to be used with the cache - * @tparam HashMap Type of a hashmap to use for cache operations. Should have std::unordered_map - * compatible interface - */ -template class Policy = NoCachePolicy, - typename HashMap = std::unordered_map>> -class XCache : public caches::fixed_sized_cache -{ -public: - using base_type = caches::fixed_sized_cache; - using typename base_type::map_type; - using typename base_type::value_type; - using typename base_type::iterator; - using typename base_type::const_iterator; - using typename base_type::operation_guard; - using typename base_type::on_erase_cb; - - /** @brief XCache constructor - * @throw std::invalid_argument - * @param[in] max_size Maximum size of the cache - * @param[in] policy Cache policy to use - * @param[in] on_erase on_erase_cb function to be called when cache's element get erased - */ - explicit - XCache( size_t max_size, const Policy& policy = Policy{}, - on_erase_cb on_erase = []( const Key &, const value_type & ) {}, - const bool debug = false - ) - : base_type( max_size, policy, on_erase ), debug_mode( debug ) {} - - /** @brief XCache destructor - */ - ~XCache() - { - // Debugging line to see the cache being cleared - if( debug_mode ) - { - std::cout << "XCache::~XCache: size = " << base_type::Size() << std::endl; - std::cout << "XCache::~XCache: Cache gets cleared." << std::endl; - } - clear(); - if( debug_mode ) - { - std::cout << "XCache::~XCache: Cache cleared, size now = " << base_type::Size() << std::endl; - } - } - - /** @brief Erase all elements in the cache - * @details This method erases all elements in the cache and thereby calls the on_erase_callback - * for each element. - */ - void - clear() - { - // Collect iterators to all elements in the cache - std::vector elems; - for( const_iterator it = base_type::begin(); it != base_type::end(); ) - { - elems.push_back( it++ ); - } - // Sort the iterators to the elements in the order they were added to the cache (oldest first) - // This ensures that the order of entries in cached.map stays the same if no new entries have been added - std::sort( elems.begin(), elems.end(), []( const_iterator a, const_iterator b ) - { - return *a->second < *b->second; // Ascending order based on value - } ); - - operation_guard lock{ safe_op }; - for( const_iterator elem : elems ) { - if( debug_mode ) - { - std::cout << "XCache::clear: Erasing element with key: " << elem->first << std::endl; - } - base_type::Erase( elem ); - if( debug_mode ) - { - std::cout << "XCache::clear: Erased element." << std::endl; - } - } - - elems.clear(); - } -private: - - mutable std::mutex safe_op; - const bool debug_mode; -}; - -} // Namespace caches diff --git a/package.xml b/package.xml index b3f8192..e13ccf4 100644 --- a/package.xml +++ b/package.xml @@ -6,13 +6,10 @@ DLR-TS TODO: License declaration ament_cmake - caches adore_math + adore_tridap libproj-dev libOpenDrive - - libcurl - ament_lint_auto ament_lint_common diff --git a/src/bounding_box.cpp b/src/bounding_box.cpp deleted file mode 100644 index 9599f9d..0000000 --- a/src/bounding_box.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#include -#include -#include -#include "adore_map/bounding_box.hpp" - - -// Parameterized constructor for BoundingBox: takes min and max latitude and longitude, and a coordinate reference system (CRS) -// The constructor performs a sanity check on the provided coordinates to ensure they form a valid bounding box -BoundingBox::BoundingBox( const double min_lat, const double min_lon, const double max_lat, const double max_lon, const std::string& crs ) - : min_lat( min_lat ), min_lon( min_lon ), max_lat( max_lat ), max_lon( max_lon ), crs( crs ) -{ - std::vector coords = { min_lat, min_lon, max_lat, max_lon }; - sanity_check_bounding_box( coords, crs ); -} - -// Parameterized constructor for BoundingBox: takes a vector of coordinates and a coordinate reference system (CRS) -// The constructor performs a sanity check on the provided coordinates to ensure they form a valid bounding box -BoundingBox::BoundingBox( const std::vector& coords, const std::string& crs ) - : min_lat( coords[0] ), min_lon( coords[1] ), max_lat( coords[2] ), max_lon( coords[3] ), crs( crs ) -{ - sanity_check_bounding_box( coords, crs ); -} - -// Convert the bounding box to a string representation -// The string representation is formatted for use in query parameters, excluding the "bbox=" prefix -std::string -BoundingBox::to_string() const -{ - std::string result = to_query_string(); - std::string::size_type i = result.find( "&bbox=" ); - - if( i != std::string::npos ) - { - result.erase(i, 6); - } - return result; -} - -// Convert the bounding box to a query string format -std::string -BoundingBox::to_query_string() const -{ - std::stringstream stream; - stream << std::fixed << std::setprecision( precision ) << min_lat; - const std::string min_lat_str = stream.str(); - stream.str( "" ); - stream << std::fixed << std::setprecision( precision ) << min_lon; - const std::string min_lon_str = stream.str(); - stream.str( "" ); - stream << std::fixed << std::setprecision( precision ) << max_lat; - const std::string max_lat_str = stream.str(); - stream.str( "" ); - stream << std::fixed << std::setprecision( precision ) << max_lon; - const std::string max_lon_str = stream.str(); - return "&bbox=" + min_lat_str + "," + min_lon_str + "," + - max_lat_str + "," + max_lon_str + "," + crs; -} - -// Static method to check a bounding box given as four coordinates for sanity and returns a BoundingBox object -// First coordinate pair for lower left corner, second coordinate pair for upper right corner -// Validates the provided coordinates and constructs a BoundingBox object -// The target_srs parameter is used to set the coordinate reference system of the bounding box -void -BoundingBox::sanity_check_bounding_box( const std::vector& coords, - const std::string& target_srs ) -{ - if( coords.empty() ) - { - std::cerr << "BoundingBox::sanity_check_bounding_box: Error: Empty coordinate vector." << std::endl; - throw std::invalid_argument( "Empty coordinate vector." ); - } - if( coords.size() != 4 ) - { - std::cerr << "BoundingBox::sanity_check_bounding_box: Error: Invalid coordinate vector. " - << "Expected 4 values, got " << coords.size() << "." << std::endl; - throw std::invalid_argument( "Invalid coordinate vector." ); - } - if( coords[0] >= coords[2] || coords[1] >= coords[3] ) - { - std::cerr << "BoundingBox::sanity_check_bounding_box: Error: Invalid bounding box coordinates. " - << "Minimum coordinates must be less than maximum coordinates." << std::endl; - throw std::invalid_argument( "Invalid bounding box coordinates." ); - } - if( target_srs.empty() ) - { - std::cerr << "BoundingBox::sanity_check_bounding_box: Error: Empty target SRS." << std::endl; - throw std::invalid_argument( "Empty target SRS." ); - } -} diff --git a/src/config.cpp b/src/config.cpp deleted file mode 100644 index 47a18d1..0000000 --- a/src/config.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#include "adore_map/config.hpp" -#include "adore_map/bounding_box.hpp" -#include "adore_map/json_file_helpers.hpp" - -Config::Config( const std::string& filename ) : - props( load_config( filename ) ), - server_url( props[ "url" ] ), - project_name( props[ "project_name" ] ), - target_srs( props[ "target_srs" ] ), - bbox( BoundingBox( props[ "bbox" ], target_srs ) ), - username( props[ "username" ] ), - password( props[ "password" ] ), - layer_name_reference_lines( props[ "reference_lines" ] ), - layer_name_lane_borders( props[ "laneborders" ] ), - reference_line_filename( props[ "output" ].get() + ".rjson" ), - lane_border_filename( props[ "output" ].get() + ".ljson" ) -{ -} - -// Static method to load configuration from a JSON file and returns an nlohmann::json object -nlohmann::json -Config::load_config( const std::string& filename ) -{ - nlohmann::json config; - - JsonFileHelpers::load( filename, config, "Config::load_config" ); - std::cout << "Config::load_config: Loaded configuration from " << filename << ":" << std::endl; - for( auto& el : config.items() ) - { - std::cout << el.key() << " = " << el.value() << std::endl; - } - return config; -} diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp deleted file mode 100644 index 34b9ce0..0000000 --- a/src/curl_wrapper.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#include -#include -#include "adore_map/curl_wrapper.hpp" - -// Static factory method to create a CurlWrapper instance with optional global initialization and cleanup -std::unique_ptr -CurlWrapper::make( const bool global_init, const bool global_cleanup, const bool debug_mode ) -{ - if( global_init ) - { - static std::once_flag once_flag; - std::call_once( once_flag, - [ debug_mode ]() - { - if( debug_mode ) - { - std::cout << "CurlWrapper::make: Performing one time global curl initialization..." << std::endl; - } - auto result = curl_global_init( CURL_GLOBAL_DEFAULT ); - if( debug_mode ) - { - if( result == CURLE_OK ) - { - std::cout << "CurlWrapper::make: Global curl initialization done." << std::endl; - } - else - { - std::cerr << "CurlWrapper::make: Global curl initialization failed: " - + std::string( curl_easy_strerror( result ) ) << std::endl; - } - } - } ); - } - if( debug_mode ) - { - std::cout << "CurlWrapper::make: Creating curl instance..." << std::endl; - } - CURL* curl = curl_easy_init(); - if( debug_mode ) - { - if( curl ) - { - std::cout << "CurlWrapper::make: curl instance created." << std::endl; - } - else - { - std::cerr << "CurlWrapper::make: Failed to create curl instance." << std::endl; - } - } - if( !curl ) - { - return nullptr; - } - return std::unique_ptr( new CurlWrapper( curl, global_cleanup, debug_mode ) ); -} - -// Destructor for CurlWrapper that cleans up the cURL easy handle and performs global cleanup -// if specified -CurlWrapper::~CurlWrapper() -{ - if( curl ) - { - if( debug_mode ) - { - std::cout << "CurlWrapper::~CurlWrapper: Cleaning up curl..." << std::endl; - } - curl_easy_cleanup( curl ); - if( debug_mode ) - { - std::cout << "CurlWrapper::~CurlWrapper: curl cleaned up." << std::endl; - } - } - if( global_cleanup ) - { - if( debug_mode ) - { - std::cout << "CurlWrapper::~CurlWrapper: Performing global curl cleanup..." << std::endl; - } - curl_global_cleanup(); - if( debug_mode ) - { - std::cout << "CurlWrapper::~CurlWrapper: Global curl cleanup done." << std::endl; - } - } -} - -// Static cURL write callback function that returns the number of bytes written -size_t -CurlWrapper::write_callback( char* ptr, size_t size, size_t nmemb, void* userdata ) -{ - // Cast userdata to std::string pointer and append the received data - ( (std::string*) userdata )->append( ptr, size * nmemb ); - return size * nmemb; -} - -// Sets general cURL options including authentication and write callback and returns -// a CURLcode indicating the result of setting options -CURLcode -CurlWrapper::set_general_options( const std::string& username, const std::string& password ) -{ - CURLcode ret = curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, CurlWrapper::write_callback ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::set_general_options: Failed to set write callback: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - return ret; - } - ret = curl_easy_setopt( curl, CURLOPT_USERAGENT, "libcurl-agent/1.0" ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::set_general_options: Failed to set user agent: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - return ret; - } - ret = curl_easy_setopt( curl, CURLOPT_USERNAME, username.c_str() ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::set_general_options: Failed to set username: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - return ret; - } - ret = curl_easy_setopt( curl, CURLOPT_PASSWORD, password.c_str() ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::set_general_options: Failed to set password: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - return ret; - } - ret = curl_easy_setopt( curl, CURLOPT_WRITEDATA, &read_buffer ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::set_general_options: Failed to set write data: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - } - return ret; -} - -// Sets the URL for the cURL request and returns a CURLcode indicating the result of setting the URL -CURLcode -CurlWrapper::set_url( const std::string& url ) -{ - CURLcode ret = curl_easy_setopt( curl, CURLOPT_URL, url.c_str() ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::set_url: Failed to set URL: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - } - return ret; -} - -// Performs the cURL request and returns a CURLcode indicating the result of the perform operation -CURLcode CurlWrapper::perform() -{ - CURLcode ret = curl_easy_perform( curl ); - if( ret != CURLE_OK ) - { - std::cerr << "CurlWrapper::perform: cURL error: " - + std::string( curl_easy_strerror( ret ) ) << std::endl; - } - return ret; -} - -// Downloads data from the specified URL using cURL and returns a CURLcode indicating the result of the operation -CURLcode -CurlWrapper::download( const std::string& url ) -{ - CURLcode ret = set_url( url ); - if( ret != CURLE_OK ) - { - return ret; - } - read_buffer.clear(); // Clear previous data - ret = perform(); - if( ret != CURLE_OK ) - { - return ret; - } - if( read_buffer.empty() ) - { - std::cerr << "CurlWrapper::download: No data received from server for URL: " << url << std::endl; - return CURLE_RECV_ERROR; // Return an error if no data was received - } - - return CURLE_OK; -} - -// The constructor is private to enforce the use of the static factory method for creating instances of CurlWrapper -CurlWrapper::CurlWrapper( CURL* curl, const bool global_cleanup, const bool debug_mode ) : - curl( curl ), global_cleanup( global_cleanup ), debug_mode( debug_mode ) {} diff --git a/src/lane.cpp b/src/lane.cpp index 04c535a..1b07c63 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -14,12 +14,10 @@ #include "adore_map/lane.hpp" namespace adore - { namespace map { - double Lane::get_width( double s ) const { diff --git a/src/lat_long_conversions.cpp b/src/lat_long_conversions.cpp index 25eb901..3b76aab 100644 --- a/src/lat_long_conversions.cpp +++ b/src/lat_long_conversions.cpp @@ -40,7 +40,6 @@ namespace adore namespace map { - std::string execute_shell_command( const std::string& command ) { @@ -294,5 +293,6 @@ convert_lat_lon_to_utm_python( double lat, double lon ) return output; } + } // namespace map } // namespace adore diff --git a/src/map_downloader.cpp b/src/map_downloader.cpp deleted file mode 100644 index c68cc26..0000000 --- a/src/map_downloader.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -#include -#include "adore_map/map_downloader.hpp" -#include "adore_map/json_file_helpers.hpp" - -// Convenience constructor, using only a configuration object / file cache path string, and reasonable default values -MapDownloader::MapDownloader( const Config& cfg, const std::string& file_cache_path ) : server_url( cfg.server_url ), - project_name( cfg.project_name ), srs_name( cfg.target_srs ), bounding_box( cfg.bbox ), debug_mode( false ) -{ - map_cache.set_debug_mode( debug_mode ); - map_cache.set_up_file_cache_path( file_cache_path ); - curl_wrapper = CurlWrapper::make( false, false, debug_mode ); - if( curl_wrapper ) - { - curl_wrapper->set_general_options( cfg.username, cfg.password ); - } -} - -// Parameterized constructor for MapDownloader -MapDownloader::MapDownloader( const std::string& server_url, const std::string& username, - const std::string& password, const std::string& project_name, const std::string& srs_name, - const BoundingBox& bounding_box, const std::string& file_cache_path, const bool curl_global_init, - const bool curl_global_cleanup, const bool debug_mode ) : server_url( server_url ), project_name( project_name ), - srs_name( srs_name ), bounding_box( bounding_box ), debug_mode( debug_mode ) -{ - map_cache.set_debug_mode( debug_mode ); - map_cache.set_up_file_cache_path( file_cache_path ); - curl_wrapper = CurlWrapper::make( curl_global_init, curl_global_cleanup, debug_mode ); - if( curl_wrapper ) - { - curl_wrapper->set_general_options( username, password ); - } -} - -// Downloads map data for a specific layer -bool -MapDownloader::download( const std::string& layer_name ) -{ - return download_as_json( layer_name ); -} - -// Downloads map data for a specific layer within a bounding box -bool -MapDownloader::download( const std::string& layer_name, const BoundingBox& bounding_box ) -{ - return download_as_json( layer_name, bounding_box ); -} - -// Downloads map data for a specific layer within a bounding box (flexible version) -bool -MapDownloader::download( const std::string& server_url, const std::string& project_name, - const std::string& srs_name, const std::string& layer_name, const BoundingBox& bounding_box ) -{ - return download_as_json( server_url, project_name, srs_name, layer_name, bounding_box ); -} - -// Downloads map data as JSON for a specific layer (private version) -bool -MapDownloader::download_as_json( const std::string& layer_name ) -{ - return download_as_json( server_url, project_name, srs_name, layer_name, bounding_box ); -} - -// Downloads map data as JSON for a specific layer within a bounding box (private version) -bool -MapDownloader::download_as_json( const std::string& layer_name, const BoundingBox& bounding_box ) -{ - return download_as_json( server_url, project_name, srs_name, layer_name, bounding_box ); -} - -// Downloads map data as JSON (private flexible version) -bool -MapDownloader::download_as_json( const std::string& server_url, - const std::string& project_name, const std::string& srs_name, const std::string& layer_name, - const BoundingBox& bounding_box ) -{ - // Construct a unique key for the cache based on the request parameters (incl. bounding box and its CRS) - std::string url_key = server_url + project_name + "/" + layer_name + "&" + bounding_box.to_string(); - // Check if the map is already in the cache - auto cached_map = map_cache.try_get( url_key ); - if( cached_map != nullptr ) - { - // If the map is found in the cache, load it from there - json_data = *cached_map; - if( debug_mode ) - { - // Debugging line to see the key being requested from cache - std::cout << "MapDownloader::download_as_json: Map found in cache for key: " << url_key << std::endl; - // Debugging line to see the JSON data being pretty printed - std::cout << "MapDownloader::download_as_json: Pretty printing cached map data." << std::endl; - pretty_print( json_data ); - } - return true; - } - // Loading a map as JSON from a WFS (Web Feature Service) server - // Using cURL to perform the HTTP request and retrieve the JSON data - if( curl_wrapper ) - { - assert( curl_wrapper->get_curl() != nullptr ); // by this point curl must be initialized - // Set cURL options - std::string url = server_url + project_name + "/ows?service=WFS&version=1.1.0&request=GetFeature&typeName=" - + layer_name + "&outputFormat=application/json" + bounding_box.to_query_string() + "&srsName=" + srs_name; - if( debug_mode ) - { - // Debugging line to see the constructed URL - std::cout << "MapDownloader::download_as_json: Constructed URL: " << url << std::endl; - } - if( curl_wrapper->download( url ) != CURLE_OK ) - { - std::cerr << "MapDownloader::download_as_json: cURL download failed for URL: " << url << std::endl; - return false; - } - parse_json(); // parse into member json_data - // Put the map into the cache - map_cache.put( url_key, json_data ); - if( debug_mode ) - { - // Debugging line to see the key being saved to cache - std::cout << "MapDownloader::download_as_json: Map put into cache for key: " << url_key << std::endl; - } - // Since the map was successfully downloaded and parsed, return true - return true; - } - std::cerr << "MapDownloader::download_as_json: cURL wrapper and cURL are not initialized." << std::endl; - return false; // Return false if cURL is not initialized -} - -// Unloads the map data from memory -void -MapDownloader::unload() -{ - curl_wrapper->get_read_buffer().clear(); // Clear the read buffer - json_data.clear(); // Clear the JSON data as well -} - -// Unloads the map data from memory (more flexible version) -void -MapDownloader::unload( nlohmann::json& json_data ) -{ - curl_wrapper->get_read_buffer().clear(); // Clear the read buffer - json_data.clear(); // Clear the JSON data as well -} - -// Parses JSON data from the internal read buffer and populates the internal JSON data object -void -MapDownloader::parse_json() -{ - parse_json( curl_wrapper->get_read_buffer(), json_data ); -} - -// Parses JSON data from a string and populates the internal JSON data object -void -MapDownloader::parse_json( const std::string& json_str ) -{ - parse_json( json_str, json_data ); -} - -// Parses JSON data from the internal read buffer and populates the provided JSON data object -void -MapDownloader::parse_json( nlohmann::json& json_data ) -{ - parse_json( curl_wrapper->get_read_buffer(), json_data ); -} - -// Parses JSON data from a string -// Populates the provided json_data object with the parsed data -void -MapDownloader::parse_json( const std::string& json_str, nlohmann::json& json_data ) -{ - json_data = nlohmann::json::parse( json_str ); -} - -// Pretty prints the map data stored in json_data -void -MapDownloader::pretty_print() -{ - pretty_print( json_data ); -} - -// Pretty prints the map data from a given JSON object -void -MapDownloader::pretty_print( const nlohmann::json& json_data ) -{ - if( json_data.empty() ) - { - std::cerr << "MapDownloader::pretty_print_map: No map data to pretty print." << std::endl; - return; - } - std::cout << json_data.dump( 4 ) << std::endl; // pretty print the json data -} - -// Saves the map data stored in json_data to a file -void -MapDownloader::save( const std::string& filename ) -{ - save_json( filename ); -} - -// Saves the map data from a given JSON object to a file -void -MapDownloader::save( const nlohmann::json& json_data, const std::string& filename ) -{ - JsonFileHelpers::save( json_data, filename, "MapDownloader::save_map( json_data, filename )" ); -} - -// Saves the map data stored in json_data to a file -void -MapDownloader::save_json( const std::string& filename ) -{ - JsonFileHelpers::save( json_data, filename, "MapDownloader::save_json( filename )" ); -} - -// Loads the map data from a file into member variable json_data -void -MapDownloader::load( const std::string& filename ) -{ - JsonFileHelpers::load( filename, json_data, "MapDownloader::load_map( filename )" ); -} - -// Loads the map data from a file into a given JSON object -void -MapDownloader::load( const std::string& filename, nlohmann::json& json_data ) -{ - JsonFileHelpers::load( filename, json_data, "MapDownloader::load_map( filename, json_data )" ); -} - -// Delegatory methods to turn off and on the cache -// These methods call the corresponding methods on the MapCache instance -// to disable or enable caching of map data, respectively - -// Turns off the map cache -void -MapDownloader::turn_off_cache() -{ - map_cache.turn_off(); -} - -// Turns on the map cache -void -MapDownloader::turn_on_cache() -{ - map_cache.turn_on(); -} diff --git a/src/map_loader.cpp b/src/map_loader.cpp index f6c17c2..aa1e62e 100644 --- a/src/map_loader.cpp +++ b/src/map_loader.cpp @@ -17,6 +17,7 @@ namespace adore { namespace map { + Map MapLoader::load_from_file( const std::string& map_file_location, bool allow_lane_changes, bool ignore_non_driving ) { @@ -57,22 +58,23 @@ MapLoader::load_from_r2s_file( const std::string& map_file_location, bool allow_ { Map map; - auto border_data_r2sr = adore::r2s::load_border_data_from_r2sr_file( map_file_location ); - auto border_data_r2sl = adore::r2s::load_border_data_from_r2sl_file( map_file_location ); + auto border_data_r2sr = r2s::load_border_data_from_r2sr_file( map_file_location ); + auto border_data_r2sl = r2s::load_border_data_from_r2sl_file( map_file_location ); create_from_r2s( map, border_data_r2sr, border_data_r2sl, allow_lane_changes ); return map; } +// Downloads map data from a WFS server and constructs a Map object Map -MapLoader::download_from_wfs( MapDownloader& downloader, const std::string& reference_lines_layer_name, +MapLoader::download_from_wfs( tridap::MapDownloader& downloader, const std::string& reference_lines_layer_name, const std::string& lane_borders_layer_name, bool allow_lane_changes, bool /*ignore_non_driving*/ ) { Map map; - auto border_data_r2sr = adore::r2s::download_reference_lines( downloader, reference_lines_layer_name ); - auto border_data_r2sl = adore::r2s::download_lane_borders( downloader, lane_borders_layer_name ); + auto border_data_r2sr = r2s::download_reference_lines( downloader, reference_lines_layer_name ); + auto border_data_r2sl = r2s::download_lane_borders( downloader, lane_borders_layer_name ); create_from_r2s( map, border_data_r2sr, border_data_r2sl, allow_lane_changes ); diff --git a/src/r2s_parser.cpp b/src/r2s_parser.cpp index b1333ff..38f83ed 100644 --- a/src/r2s_parser.cpp +++ b/src/r2s_parser.cpp @@ -190,7 +190,7 @@ load_border_data_from_r2sr_file( const std::string& file_name ) // Load reference lines from a WFS layer using MapDownloader std::vector -download_reference_lines( MapDownloader& downloader, const std::string& layer_name ) +download_reference_lines( tridap::MapDownloader& downloader, const std::string& layer_name ) { std::vector reference_lines; // Load reference lines from WFS @@ -202,8 +202,9 @@ download_reference_lines( MapDownloader& downloader, const std::string& layer_na return parse_reference_lines( downloader ); } +// Load reference lines from a JSON file using MapDownloader std::vector -load_reference_lines_from_json_file( MapDownloader& downloader, const std::string& file_name ) +load_reference_lines_from_json_file( tridap::MapDownloader& downloader, const std::string& file_name ) { std::vector reference_lines; // Load reference lines from JSON file @@ -214,7 +215,7 @@ load_reference_lines_from_json_file( MapDownloader& downloader, const std::strin // Parse reference lines from the JSON data of a MapDownloader // Assumes that the map has already been downloaded or loaded via MapDownloader::load_map( filename ) std::vector -parse_reference_lines( MapDownloader& downloader ) +parse_reference_lines( tridap::MapDownloader& downloader ) { std::vector reference_lines; nlohmann::json& json_data = downloader.get_json_data(); @@ -341,7 +342,7 @@ parse_reference_lines( MapDownloader& downloader ) // Load lane borders from a WFS layer using MapDownloader std::vector -download_lane_borders( MapDownloader& downloader, const std::string& layer_name ) +download_lane_borders( tridap::MapDownloader& downloader, const std::string& layer_name ) { std::vector lane_borders; // Load lane borders from WFS @@ -353,8 +354,9 @@ download_lane_borders( MapDownloader& downloader, const std::string& layer_name return parse_lane_borders( downloader ); } +// Load lane borders from a JSON file using MapDownloader std::vector -load_lane_borders_from_json_file( MapDownloader& downloader, const std::string& file_name ) +load_lane_borders_from_json_file( tridap::MapDownloader& downloader, const std::string& file_name ) { std::vector lane_borders; // Load lane borders from JSON file @@ -365,7 +367,7 @@ load_lane_borders_from_json_file( MapDownloader& downloader, const std::string& // Parse lane borders from the JSON data of a MapDownloader // Assumes that the map has already been downloaded or loaded via MapDownloader::load_map( filename ) std::vector -parse_lane_borders( MapDownloader& downloader ) +parse_lane_borders( tridap::MapDownloader& downloader ) { std::vector lane_borders; nlohmann::json& json_data = downloader.get_json_data(); diff --git a/src/road_graph.cpp b/src/road_graph.cpp index cff630d..c0b8e45 100644 --- a/src/road_graph.cpp +++ b/src/road_graph.cpp @@ -18,7 +18,6 @@ namespace adore namespace map { - bool RoadGraph::add_connection( Connection connection ) { diff --git a/src/route.cpp b/src/route.cpp index 6aa95bf..b9b9a0a 100644 --- a/src/route.cpp +++ b/src/route.cpp @@ -203,6 +203,5 @@ Route::initialize_reference_line() } } - } // namespace map } // namespace adore diff --git a/test/map_download_cache_test.cpp b/test/map_download_cache_test.cpp index 2cf041a..56a7614 100644 --- a/test/map_download_cache_test.cpp +++ b/test/map_download_cache_test.cpp @@ -22,7 +22,7 @@ #include "adore_map/map.hpp" #include "adore_map/map_loader.hpp" #include "adore_map/road_graph.hpp" -#include "adore_map/config.hpp" +#include "adore_tridap/config_map_downloader.hpp" #ifndef ADORE_MAP_TEST_DATA_DIR // Fallback – will be overridden from CMake for real tests. @@ -52,6 +52,10 @@ get_test_map_r2s_file_cache_path() std::stringstream* buffer; std::streambuf* sbuf; +using namespace adore::map; +using namespace adore::r2s; +using namespace adore::tridap; + // Test fixture for MapDownloadCache tests, with setup and teardown to suppress output during tests // All tests use a local file cache, so no actual downloading from a server is performed // Tests focus on verifying that the caching mechanism correctly saves and loads map data, @@ -122,9 +126,9 @@ class MapDownloadCacheTest : public testing::Test // Basic smoke test: we can load the map and it has roads, lanes and a lane graph. TEST_F( MapDownloadCacheTest, loaded_map_has_roads_lanes_and_graph ) { - Config cfg( get_test_map_r2s_cfg_path() ); + ConfigMapDownloader cfg( get_test_map_r2s_cfg_path() ); MapDownloader map_downloader( cfg, get_test_map_r2s_file_cache_path() ); - adore::map::Map map = adore::map::MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, + Map map = MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, cfg.layer_name_lane_borders, false ); // Structural checks @@ -156,9 +160,9 @@ TEST_F( MapDownloadCacheTest, loaded_map_has_roads_lanes_and_graph ) // Check that all lane-graph connections refer to lanes that actually exist in the map. TEST_F( MapDownloadCacheTest, lane_graph_connections_reference_existing_lanes ) { - Config cfg( get_test_map_r2s_cfg_path() ); + ConfigMapDownloader cfg( get_test_map_r2s_cfg_path() ); MapDownloader map_downloader( cfg, get_test_map_r2s_file_cache_path() ); - adore::map::Map map = adore::map::MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, + Map map = MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, cfg.layer_name_lane_borders, false ); for( const auto& connection : map.lane_graph.all_connections ) @@ -171,9 +175,9 @@ TEST_F( MapDownloadCacheTest, lane_graph_connections_reference_existing_lanes ) // Ensure that the quadtree actually contains points from at least one loaded lane. TEST_F( MapDownloadCacheTest, quadtree_contains_points_from_lanes ) { - Config cfg( get_test_map_r2s_cfg_path() ); + ConfigMapDownloader cfg( get_test_map_r2s_cfg_path() ); MapDownloader map_downloader( cfg, get_test_map_r2s_file_cache_path() ); - adore::map::Map map = adore::map::MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, + Map map = MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, cfg.layer_name_lane_borders, false ); // Pick any lane. @@ -197,19 +201,19 @@ TEST_F( MapDownloadCacheTest, quadtree_contains_points_from_lanes ) // Ensure that the reference line and lane border data loaded from WFS matches the data loaded from files (which had been downloaded by a Python program). TEST_F( MapDownloadCacheTest, results_comparable_to_legacy_results ) { - Config cfg( get_test_map_r2s_cfg_path() ); + ConfigMapDownloader cfg( get_test_map_r2s_cfg_path() ); MapDownloader map_downloader( cfg, get_test_map_r2s_file_cache_path() ); - adore::map::Map map = adore::map::MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, + Map map = MapLoader::download_from_wfs( map_downloader, cfg.layer_name_reference_lines, cfg.layer_name_lane_borders, false ); // Load reference line and lane border data from CSV files created using a Python downloader and the R2S parser // (the legacy methods for loading map data). These files were created from the same source as the WFS data, so they should match. - auto border_data_r2sr_from_file = adore::r2s::load_border_data_from_r2sr_file( get_test_map_r2s_r2sr_path() ); + auto border_data_r2sr_from_file = load_border_data_from_r2sr_file( get_test_map_r2s_r2sr_path() ); // The same path is passed to the next method since the method will change the suffix to .r2sl internally - auto border_data_r2sl_from_file = adore::r2s::load_border_data_from_r2sl_file( get_test_map_r2s_r2sr_path() ); + auto border_data_r2sl_from_file = load_border_data_from_r2sl_file( get_test_map_r2s_r2sr_path() ); - auto border_data_r2sr_from_wfs = adore::r2s::download_reference_lines( map_downloader, cfg.layer_name_reference_lines ); - auto border_data_r2sl_from_wfs = adore::r2s::download_lane_borders( map_downloader, cfg.layer_name_lane_borders ); + auto border_data_r2sr_from_wfs = download_reference_lines( map_downloader, cfg.layer_name_reference_lines ); + auto border_data_r2sl_from_wfs = download_lane_borders( map_downloader, cfg.layer_name_lane_borders ); // Next line uses operator!= defined in BorderDataR2SR, which uses a tolerance for comparing x and y coordinates EXPECT_FALSE( border_data_r2sr_from_file != border_data_r2sr_from_wfs ) @@ -221,7 +225,7 @@ TEST_F( MapDownloadCacheTest, results_comparable_to_legacy_results ) TEST_F( MapDownloadCacheTest, files_match_after_saving_loading_and_saving_again ) { - Config cfg( get_test_map_r2s_cfg_path() ); + ConfigMapDownloader cfg( get_test_map_r2s_cfg_path() ); MapDownloader map_downloader( cfg, get_test_map_r2s_file_cache_path() ); // Load the first map layer as JSON: layer name is that for reference lines From c181e44f0cabca5c3c1a2a72c22faff7da046a00 Mon Sep 17 00:00:00 2001 From: s0nofab1t Date: Fri, 17 Jul 2026 13:47:39 +0200 Subject: [PATCH 2/2] Updated README.md Signed-off-by: s0nofab1t --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5a846d6..b731056 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Map Library for Autonomous Vehicles ## Overview -The **Map Library** provides tools for handling map data in autonomous vehicle simulations. It includes modules for lane and route management, spatial querying using quadtree structures, geographic coordinate conversions. The library is designed for efficiency and integration with autonomous vehicle systems. +The **Map Library** provides tools for handling map data in autonomous vehicle simulations. It includes modules for lane and route management, spatial querying using quadtree structures, geographic coordinate conversions. The library is designed for efficiency and integration with autonomous vehicle systems. --- @@ -12,8 +12,8 @@ The **Map Library** provides tools for handling map data in autonomous vehicle - Support for geospatial data handling and storage. - **Quadtree Spatial Indexing**: - Efficient spatial querying. -- **Map Parsing and Loading**: - - Tools for loading and parsing maps, including Road2Simulation (R2S) format support. +- **Map Parsing, Downloading and Loading**: + - Tools for downloading or loading and parsing maps, including Road2Simulation (R2S) format support. - **Geographic Conversions**: - Latitude/longitude to UTM coordinate transformations. @@ -38,7 +38,7 @@ The **Map Library** provides tools for handling map data in autonomous vehicle ### Map Loader **File:** `map_loader.hpp` -- Handles the loading of map data from external files or formats. +- Handles the download of map data from a Web Feature Service (WFS), and the loading of map data from external files or formats. - Includes support for parsing the Road2Simulation (R2S) format. ### Map Point