diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index b2758f6b0081f49cc582cb0c8bd046d2019305d3..2a1815eef6903f5637fe693d3c76663226e7b1b2 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -3,21 +3,6 @@ ADD_EXECUTABLE(dijkstra_test dijkstra_test.cpp) # link necessary libraries TARGET_LINK_LIBRARIES(dijkstra_test ${PROJECT_NAME}) -# create an example application -#ADD_EXECUTABLE(opendrive_test opendrive_test.cpp) -# link necessary libraries -#TARGET_LINK_LIBRARIES(opendrive_test ${PROJECT_NAME}) - -# create an example application -#ADD_EXECUTABLE(opendrive_build_road_test opendrive_build_road_test.cpp) -# link necessary libraries -#TARGET_LINK_LIBRARIES(opendrive_build_road_test ${PROJECT_NAME}) - -# create an example application -#ADD_EXECUTABLE(osm_test osm_test.cpp) -# link necessary libraries -#TARGET_LINK_LIBRARIES(osm_test ${PROJECT_NAME}) - # create an example application ADD_EXECUTABLE(build_from_scratch_test build_from_scratch_test.cpp) # link necessary libraries @@ -27,3 +12,8 @@ TARGET_LINK_LIBRARIES(build_from_scratch_test ${PROJECT_NAME}) ADD_EXECUTABLE(opendrive_import_test opendrive_import_test.cpp) # link necessary libraries TARGET_LINK_LIBRARIES(opendrive_import_test ${PROJECT_NAME}) + +# create an example application +ADD_EXECUTABLE(osm_import_test osm_import_test.cpp) +# link necessary libraries +TARGET_LINK_LIBRARIES(osm_import_test ${PROJECT_NAME}) diff --git a/src/examples/osm_import_test.cpp b/src/examples/osm_import_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d314800a7dc2395594417d7ba207365f846bf629 --- /dev/null +++ b/src/examples/osm_import_test.cpp @@ -0,0 +1,43 @@ +#include "road_map.h" +#include "exceptions.h" + +#include <iostream> + +//const std::string osm_file="/home/shernand/Downloads/test_osm.osm"; +const std::string osm_file="/home/shernand/Downloads/test_osm2.osm"; + +int main(int argc, char *argv[]) +{ + try{ + CRoadMap map,new_map; + Eigen::MatrixXi connectivity; + std::vector<unsigned int> id_map,new_path,old_path; + std::vector<double> x,y,heading; + + map.load_osm(osm_file); + + map.get_lane_geometry(x,y,heading); + for(unsigned int i=0;i<x.size();i++) + std::cout << x[i] << "," << y[i] << "," << heading[i] << std::endl; + + return 0; + +// old_path.push_back(3); +// old_path.push_back(4); + old_path.push_back(22); +// old_path.push_back(10); + new_path=map.get_path_sub_roadmap(old_path,new_map); + + new_map.get_segment_connectivity(connectivity,id_map); + for(unsigned int i=0;i<id_map.size();i++) + std::cout << i << " -> " << id_map[i] << " "; + std::cout << std::endl; + std::cout << "Initial connectivity:" << std::endl; + std::cout << connectivity << std::endl; + } + catch (CException &e) + { + std::cout << "[Exception caught] : " << e.what() << std::endl; + } + return 0; +} diff --git a/src/road_map.cpp b/src/road_map.cpp index e412b3622f78f982d87044839f5f3c9e278f9774..07d0603e00db83e2db79ecaa5bcf2b78dc051c1a 100644 --- a/src/road_map.cpp +++ b/src/road_map.cpp @@ -4,6 +4,8 @@ #include "opendrive/opendrive_road_segment.h" #include "opendrive/opendrive_junction.h" +#include "osm/osm_map.h" + #include <sys/types.h> #include <sys/stat.h> #include <chrono> @@ -372,6 +374,14 @@ void CRoadMap::save_opendrive(const std::string &filename) } } +void CRoadMap::load_osm(const std::string &filename) +{ + COSMMap road_map; + + road_map.load(filename); + road_map.convert(*this); +} + void CRoadMap::set_resolution(double resolution) { this->resolution=resolution;