Skip to content

Latest commit

 

History

History
84 lines (66 loc) · 2.54 KB

README.md

File metadata and controls

84 lines (66 loc) · 2.54 KB

libOpenDRIVE

libOpenDRIVE is a lightweight, fast C++ library providing OpenDRIVE file parsing and 3D model generation.

It's dependency-free, small and includes a web-based viewer. It can be easily integrated in other projects and can be compiled to a WebAssembly library. A core function is the parsing of OpenDRIVE files and the generation of 3D models. The library targets OpenDRIVE version 1.4.

Example

Here's an example of how code using libOpenDRIVE looks; it opens an xodr file, iterates over the elements of the road network and generates lanes meshes.

#include "OpenDriveMap.h"
#include "Lanes.h"
#include "Road.h"

#include <memory>
#include <stdio.h>

int main(void)
{
    odr::OpenDriveMap odr("data.xodr");
    for (std::shared_ptr<odr::Road> road : odr.get_roads())
    {
        printf("road: %s, length: %.2f\n", road->id.c_str(), road->length);
        for (std::shared_ptr<odr::LaneSection> lanesec : road->get_lanesections())
        {
            for (std::shared_ptr<odr::Lane> lane : lanesec->get_lanes())
            {
                auto lane_mesh = lane->get_mesh(lanesec->s0, lanesec->get_end(), 0.1);
            }
        }
    }
    return 0;
}

Viewer

To use the included viewer first build the WebAssembly library and then run a webserver in the Viewer/ directory (e.g. python3 -m http.server). Or you can test the viewer online.

viewer-demo

Build

To build the library simply run:

mkdir build && cd build
cmake ..
make

This also builds an executable to test the library:

./build/test-xodr Viewer/data.xodr

WebAssembly

Install emsdk and run the following commands to build the WebAssembly library:

mkdir build && cd build
emcmake cmake ..
emmake make

cp ModuleOpenDrive.* ../Viewer

Javascript Example

fetch("./data.xodr").then((file_data) => {
    file_data.text().then((file_text) => {
        odr_map_config = {
            with_lateralProfile : PARAMS.lateralProfile,
            with_laneHeight : PARAMS.laneHeight,
            with_road_objects : false,
            center_map : true,
            abs_z_for_for_local_road_obj_outline : true
        };
        ModuleOpenDrive['FS_createDataFile'](".", "data.xodr", file_text, true, true);
        OpenDriveMap = new ModuleOpenDrive.OpenDriveMap("./data.xodr", odr_map_config);
    });
});