libOpenDRIVE Documentation

repository·main·Indexed 19 days ago

https://github.com/pageldev/libopendrive

A lightweight, dependency-free C++ library for parsing OpenDRIVE (v1.4) files and generating 3D road network models. It provides functionality for road network analysis, 3D coordinate retrieval, lane attribute access, shortest-path routing via RoutingGraph, and road network mesh generation.

Tokens
698
Snippets
2
Records
3
Agent score
18%

What's inside libOpenDRIVE

  1. Overview of libOpenDRIVE

    main
    libOpenDRIVE is a lightweight, dependency-free, fast C++ library designed for parsing OpenDRIVE files (targeting version 1.4) and generating 3D models. It is intended for easy integration into other C++ projects for road network analysis and visualization.
  2. Build libOpenDRIVE as a static or shared library

    main

    The library builds as a static library by default. You can use CMake to configure the build process.

    Build as a static library (default)

    mkdir build
    cd build
    cmake ..
    make

    Build as a shared library

    To generate a shared library instead of a static one, pass the BUILD_SHARED_LIBS flag to CMake:

    cmake -DBUILD_SHARED_LIBS=ON ..
  3. Use libOpenDRIVE for OpenDRIVE parsing and analysis

    main

    You can use odr::OpenDriveMap to load an .xodr file and access its components. The library allows you to iterate through roads, retrieve 3D coordinates for specific points on a road, access lane attributes, perform routing via a shortest-path algorithm, and generate a road network mesh.

    // load map
    odr::OpenDriveMap odr_map("tests/test.xodr");
    
    // iterate roads
    for (odr::Road road : odr_map.get_roads())
        std::cout << "road: " << road.id << " length: " << road.length << std::endl;
    
    // get xyz point for road coordinates
    odr::Road odr_road = odr_map.get_road("17");
    odr::Vec3D pt_xyz = odr_road.get_xyz(2.1 /*s*/, 1.0 /*t*/, 0.0 /*h*/);
    
    // access road network attributes
    std::string lane_type = odr_road.get_lanesection(0.0).get_lane(-1).type;
    
    // use routing graph
    odr::RoutingGraph routing_graph = odr_map.get_routing_graph();
    odr::LaneKey from("17" /*road id*/, 0.0 /*lane section s0*/, 1 /*lane id*/);
    odr::LaneKey to("41", 0.0, -1);
    std::vector<odr::LaneKey> path = routing_graph.shortest_path(from, to);
    
    // get road network mesh
    odr::RoadNetworkMesh road_network_mesh = odr_map.get_road_network_mesh(0.1 /*eps*/);
    std::cout << road_network_mesh.get_mesh().get_obj() << std::endl;