libOpenDRIVE icon indicating copy to clipboard operation
libOpenDRIVE copied to clipboard

Feat/pybind11 (#1)

Open chrisjcc opened this issue 8 months ago • 2 comments

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']

chrisjcc avatar May 22 '25 13:05 chrisjcc

@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 avatar Jun 22 '25 12:06 chrisjcc

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

chrisjcc avatar Sep 26 '25 20:09 chrisjcc