Skip to content

Conversation

@chrisjcc
Copy link

@chrisjcc chrisjcc commented May 22, 2025

This PR introduces initial Python bindings for libOpenDRIVE using Pybind11, enabling Python access to the core data structures and mesh representations. The following key components were added or updated:

Pybind11 Integration

  • Added pybind11 as a submodule via .gitmodules
  • Updated CMakeLists.txt to include and configure Pybind11
  • Implemented core bindings in bindings/bindings.cpp
  • Added pyproject.toml and setup.py for building and installing the Python package

Bindings Coverage

  • Exposed OpenDRIVE types including: Road, Junction, Lane, LaneSection, and various mesh objects
  • Verified object accessibility via dir(opendrive)

Tests

  • Added test_opendrivemap.py and test_binding.py with coverage of map structure, mesh components, and routing graph
  • All tests pass (7 passed, 2 skipped due to missing mesh vertices)

Miscellaneous

  • Updated README with installation and usage instructions

Test

Test results below,

python -m pytest -v tests/test_opendrivemap.py
===================================================================== test session starts =====================================================================
platform darwin -- Python 3.11.5, pytest-8.2.2, pluggy-1.5.0 -- /Users/christiancontrerascampana/anaconda3/bin/python
cachedir: .pytest_cache
rootdir: /Users/christiancontrerascampana/Desktop/project/pybind_libOpenDRIVE/baseline/libOpenDRIVE
configfile: pyproject.toml
plugins: anyio-4.3.0
collected 1 item

tests/test_opendrivemap.py::test_basic_opendrivemap_check PASSED [100%]

====================================================================== 1 passed in 0.03s ======================================================================

python -m pytest -v tests/test_binding.py

===================================================================== test session starts =====================================================================
platform darwin -- Python 3.11.5, pytest-8.2.2, pluggy-1.5.0 -- /Users/christiancontrerascampana/anaconda3/bin/python
cachedir: .pytest_cache
rootdir: /Users/christiancontrerascampana/Desktop/project/pybind_libOpenDRIVE/baseline/libOpenDRIVE
configfile: pyproject.toml
plugins: anyio-4.3.0
collected 9 items

tests/test_binding.py::test_opendrive_map_attributes PASSED [ 11%]
tests/test_binding.py::test_roads PASSED [ 22%]
tests/test_binding.py::test_junctions PASSED [ 33%]
tests/test_binding.py::test_road_network_mesh PASSED [ 44%]
tests/test_binding.py::test_lanes_mesh PASSED [ 55%]
tests/test_binding.py::test_roadmarks_mesh PASSED [ 66%]
tests/test_binding.py::test_road_objects_mesh SKIPPED (No vertices in road_objects_mesh) [ 77%]
tests/test_binding.py::test_road_signals_mesh SKIPPED (No vertices in road_signals_mesh) [ 88%]
tests/test_binding.py::test_routing_graph PASSED [100%]

================================================================ 7 passed, 2 skipped in 0.59s =================================================================
(bas

Output

Once pip is installed can import as follows:

import opendrive
dir(opendrive)

['ContactPoint', 'Crossfall', 'CrossfallSide', 'CubicSpline', 'End', 'EulerAnglesToMatrix', 'HeightOffset', 'Junction', 'JunctionConnection', 'JunctionController', 'JunctionLaneLink', 'JunctionPriority', 'Lane', 'LaneKey', 'LaneSection', 'LaneValidityRecord', 'LanesMesh', 'Line3D', 'Mat3D', 'MatVecMultiplication', 'Mesh3D', 'None', 'OpenDriveMap', 'ROADMARK_WEIGHT_BOLD_WIDTH', 'ROADMARK_WEIGHT_STANDARD_WIDTH', 'RefLine', 'Road', 'RoadLink', 'RoadLinkType', 'RoadMark', 'RoadMarkGroup', 'RoadMarksLine', 'RoadNeighbor', 'RoadNetworkMesh', 'RoadObject', 'RoadObjectCorner', 'RoadObjectCornerType', 'RoadObjectOutline', 'RoadObjectRepeat', 'RoadObjectsMesh', 'RoadSignal', 'RoadSignalsMesh', 'RoadmarksMesh', 'RoadsMesh', 'RoutingGraph', 'RoutingGraphEdge', 'Side_Both', 'Side_Left', 'Side_Right', 'SpeedRecord', 'Start', 'Type_Junction', 'Type_Local_AbsZ', 'Type_Local_RelZ', 'Type_None', 'Type_Road', 'Vec1D', 'Vec2D', 'Vec3D', 'WeightedLaneKey', 'XmlNode', 'XmlParseResult', 'doc', 'file', 'loader', 'name', 'package', 'spec', 'add', 'crossProduct', 'euclDistance', 'mut', 'norm', 'normalize', 'sign', 'squaredNorm', 'sub']

pageldev and others added 4 commits January 19, 2025 22:18
* feat(pybind11): add initial Pybind11 integration and Python build setup

- Added .gitmodules to include pybind11 as a submodule
- Updated CMakeLists.txt to support Pybind11 bindings
- Implemented initial C++ bindings in bindings/bindings.cpp
- Added pyproject.toml and setup.py for Python packaging

* Update to include bindings for junction, lane, lane section

* Add binding for several modules

* Remove unneeded for-loop

* Updates required to enable test script to work

* Minor fix with binding module name

* Update README to include instructions on how to install Python bindings with pybind11
@chrisjcc
Copy link
Author

@pageldev I recall there’s been interest in making pybinding available for libOpenDrive. I've included installation instructions in the README as an optional step.

@chrisjcc
Copy link
Author

@pageldev updated to be in synch with the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants