Python binding of the OctoMap library with bundled shared libraries.
Project description
PyOctoMap
A comprehensive Python wrapper for the OctoMap C++ library, providing efficient 3D occupancy mapping capabilities for robotics and computer vision applications. This modernized binding offers enhanced performance, bundled shared libraries for easy deployment, and seamless integration with the Python scientific ecosystem.
Features
- 3D Occupancy Mapping: Efficient octree-based 3D occupancy mapping
- Probabilistic Updates: Stochastic occupancy updates with uncertainty handling
- Path Planning: Ray casting and collision detection
- File Operations: Save/load octree data in binary format
- Cross-Platform: Pre-built wheels for Linux (
x86_64) and macOS (Apple Siliconarm64), with Windows compatibility via WSL
Installation
Quick Install (Recommended)
Install from PyPI (pre-built manylinux wheel when available):
pip install pyoctomap
🚀 ROS Integration: ROS/ROS2 integration is currently being developed on the
rosbranch, featuring ROS2 message support and real-time point cloud processing.
Building from Source
📋 Prerequisites: See Build System Documentation for detailed system dependencies and troubleshooting guide.
If you need to build from source or create custom wheels locally, we provide a cibuildwheel setup. First, ensure you have the repository cloned:
Linux / WSL / macOS:
# Clone the repository with submodules
git clone --recursive https://github.com/Spinkoo/pyoctomap.git
cd pyoctomap
To build locally using cibuildwheel:
pip install cibuildwheel
cibuildwheel --platform linux # or macos
The CI build automatically creates wheels for Python 3.8-3.13 (cp38–cp313), properly bundling all required C++ libraries.
📋 Google Colab Users: See Build System Documentation for detailed Colab installation instructions.
Quick Start
Basic Usage
import pyoctomap
import numpy as np
# Create an octree with 0.1m resolution
tree = pyoctomap.OcTree(0.1)
# Add occupied points
tree.updateNode([1.0, 2.0, 3.0], True)
tree.updateNode([1.1, 2.1, 3.1], True)
# Add free space
tree.updateNode([0.5, 0.5, 0.5], False)
# Check occupancy
node = tree.search([1.0, 2.0, 3.0])
if node and tree.isNodeOccupied(node):
print("Point is occupied!")
# Save to file
tree.write("my_map.bt")
Tree Families Overview
PyOctoMap provides multiple octree variants from a single package:
OcTree– standard probabilistic occupancy tree (most users start here)ColorOcTree– occupancy + RGB color per voxelCountingOcTree– integer hit counters per voxelOcTreeStamped– occupancy with per-node timestamps for temporal mapping
See the API Reference for a detailed comparison table and full method documentation.
Color Occupancy Mapping (ColorOcTree)
import pyoctomap
import numpy as np
tree = pyoctomap.ColorOcTree(0.1)
coord = [1.0, 1.0, 1.0]
tree.updateNode(coord, True)
tree.setNodeColor(coord, 255, 0, 0) # R, G, B (0-255)
Dynamic Mapping and Point Cloud Insertion
Batch Operations (Summary)
For large point clouds, use the unified insertPointCloud method:
OcTree.insertPointCloud(points, origin, max_range=-1.0, lazy_eval=False, discretize=False)ColorOcTree.insertPointCloud(points, sensor_origin=None, ..., colors=colors)— also sets per-point colorsOcTreeStamped.insertPointCloud(points, sensor_origin=None, ..., timestamps=ts)— also sets per-node timestamps
For extremely fast readout of the internal state into NumPy arrays without iteration, use extractPointCloud():
OcTree.extractPointCloud()->(occupied_points, empty_points)ColorOcTree.extractPointCloud()->(occupied_points, empty_points, colors)CountingOcTree.extractPointCloud()->(coords, counts)OcTreeStamped.extractPointCloud()->(occupied_points, empty_points, timestamps)
See the Performance Guide for practical batch sizing and resolution recommendations.
Examples
See runnable demos in the examples directory:
- examples/basic_test.py — smoke test for core API
- examples/demo_occupancy_grid.py — build and visualize a 2D occupancy grid
- examples/demo_octomap_open3d.py — visualize octomap data with Open3D
- examples/sequential_occupancy_grid_demo.py — comprehensive sequential occupancy grid with Open3D visualization
- examples/test_sequential_occupancy_grid.py — comprehensive test suite for all occupancy grid methods
Demo Visualizations
3D OctoMap Scene Visualization:
Occupancy Grid Visualization:
Advanced Usage
Room Mapping with Ray Casting
import pyoctomap
import numpy as np
# Create octree
tree = pyoctomap.OcTree(0.05) # 5cm resolution
sensor_origin = np.array([2.0, 2.0, 1.5])
# Add walls with ray casting
wall_points = []
for x in np.arange(0, 4.0, 0.05):
for y in np.arange(0, 4.0, 0.05):
wall_points.append([x, y, 0]) # Floor
wall_points.append([x, y, 3.0]) # Ceiling
# Use batch insertion for better performance
wall_points = np.array(wall_points)
tree.insertPointCloud(wall_points, sensor_origin, lazy_eval=True)
tree.updateInnerOccupancy()
print(f"Tree size: {tree.size()} nodes")
Path Planning
import pyoctomap
import numpy as np
# Create an octree for path planning
tree = pyoctomap.OcTree(0.1) # 10cm resolution
# Add some obstacles to the map
obstacles = [
[1.0, 1.0, 0.5], # Wall at (1,1)
[1.5, 1.5, 0.5], # Another obstacle
[2.0, 1.0, 0.5], # Wall at (2,1)
]
for obstacle in obstacles:
tree.updateNode(obstacle, True)
def is_path_clear(start, end, tree):
"""Efficient ray casting for path planning using OctoMap's built-in castRay"""
start = np.array(start, dtype=np.float64)
end = np.array(end, dtype=np.float64)
# Calculate direction vector
direction = end - start
ray_length = np.linalg.norm(direction)
if ray_length == 0:
return True, None
# Normalize direction
direction = direction / ray_length
# Use OctoMap's efficient castRay method
end_point = np.zeros(3, dtype=np.float64)
hit = tree.castRay(start, direction, end_point,
ignoreUnknownCells=True,
maxRange=ray_length)
if hit:
# Ray hit an obstacle - path is blocked
return False, end_point
else:
# No obstacle found - path is clear
return True, None
# Check if path is clear
start = [0.5, 2.0, 0.5]
end = [2.0, 2.0, 0.5]
clear, obstacle = is_path_clear(start, end, tree)
if clear:
print("✅ Path is clear!")
else:
print(f"❌ Path blocked at: {obstacle}")
# Advanced path planning with multiple waypoints
def plan_path(waypoints, tree):
"""Plan a path through multiple waypoints using ray casting"""
path_clear = True
obstacles = []
for i in range(len(waypoints) - 1):
start = waypoints[i]
end = waypoints[i + 1]
clear, obstacle = is_path_clear(start, end, tree)
if not clear:
path_clear = False
obstacles.append((i, i+1, obstacle))
return path_clear, obstacles
# Example: Plan path through multiple waypoints
waypoints = [
[0.0, 0.0, 0.5],
[1.0, 1.0, 0.5],
[2.0, 2.0, 0.5],
[3.0, 3.0, 0.5]
]
path_clear, obstacles = plan_path(waypoints, tree)
if path_clear:
print("✅ Complete path is clear!")
else:
print(f"❌ Path blocked at segments: {obstacles}")
Dynamic Environment Mapping & Iterators
For more complete examples on:
- dynamic environment mapping,
- iterator usage (
begin_tree,begin_leafs,begin_leafs_bbx),
refer to the API Reference and example scripts in the examples directory.
Requirements
- Python 3.8+
- NumPy
- Cython (for building from source)
Optional for visualization:
- matplotlib (for 2D plotting)
- open3d (for 3D visualization)
Documentation
- Complete API Reference - Detailed API documentation
- Build System - Prerequisites, build process, and troubleshooting
- File Format Guide - Supported file formats
- Performance Guide - Optimization tips and benchmarks
- Troubleshooting - Common issues and solutions
- Wheel Technology - Library bundling details
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Acknowledgments
- Previous work:
wkentaro/octomap-python- This project builds upon and modernizes the original Python bindings - Core library: OctoMap - An efficient probabilistic 3D mapping framework based on octrees
- Build system: Built with Cython for seamless Python-C++ integration and performance
- Visualization: Open3D - Used for 3D visualization capabilities in demonstration scripts
- Research support: Development of this enhanced Python wrapper was supported by the French National Research Agency (ANR) under the France 2030 program, specifically the IRT Nanoelec project (ANR-10-AIRT-05), advancing robotics and 3D mapping research capabilities.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyoctomap-1.2.0.tar.gz.
File metadata
- Download URL: pyoctomap-1.2.0.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17c78604945e70188ae2d4c3cd7f778815dd065e772db73f97faffa84a859a70
|
|
| MD5 |
c5a6c960e267d70dec46f4d862a705f0
|
|
| BLAKE2b-256 |
c0b26300024be3a6c4de46492a51fab563270a58dac7539e537310109db2715d
|
File details
Details for the file pyoctomap-1.2.0-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 10.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f9026a8508251b0ca0c755cdf5f809507a06ced4ff5325fac7f2875a7f4fe53
|
|
| MD5 |
eba81a2616e008f0349a6dfbe0b5facf
|
|
| BLAKE2b-256 |
0b97456e25ef1d7cd18f1446d4ef51bc1f36afbd8eeef86fa92a5e15e929cf7a
|
File details
Details for the file pyoctomap-1.2.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
958dc9360ec1e11b07ac0d08c8fe8dc9a8f1b16343f64c08dad96f25299e1329
|
|
| MD5 |
acc1e302c1d4ee914c1c82226a2687b0
|
|
| BLAKE2b-256 |
f98d60142d005c110a425c51bf15095d8006280652514be57c8519d844208858
|
File details
Details for the file pyoctomap-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 10.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed070a9c5734daa130ae90e8de763d8256a1e95c901fff6f08e5c34714ee19f0
|
|
| MD5 |
76628041f3cea13cd54621e5b45b8ff2
|
|
| BLAKE2b-256 |
40225b81b22b7d67c2268ab6d608758e648b9a31fa6a0ca3ab6bf0b715db97f1
|
File details
Details for the file pyoctomap-1.2.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e38267c45de85e97cffdfc0487100f522716bfec5663e50418b6d738c081d15f
|
|
| MD5 |
ff1e49f1f80db3610772188ae5f44be7
|
|
| BLAKE2b-256 |
fb966c8ac27e69aa92e603fb4ec6d8922084bfada8d4e92d934cec1420090ab7
|
File details
Details for the file pyoctomap-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5169ff2ed6bd2ef554a5edb7e7b0d561c0b92654b8372036dd5205b36560f1d4
|
|
| MD5 |
6659198ee8459c254ac3a1b9d5095165
|
|
| BLAKE2b-256 |
b13e1b64bfe48ccdf88472e3381a44bc3a569d15c545811baeaa087902aecaed
|
File details
Details for the file pyoctomap-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bedd7966b80998424936cb447be50a7622ac485fa8855ee76515bfd57148a5a9
|
|
| MD5 |
5f9d0856ce0cf493b55fcee15ae5d7fb
|
|
| BLAKE2b-256 |
1656662c02a38924daf0afbc7f2528ee523b84babe4b9689eaea73094be7739c
|
File details
Details for the file pyoctomap-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 9.9 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
425128836d74d621d49a8e9e19c6048ebbf83ce04f53b91009d6728a02d8543c
|
|
| MD5 |
e25de73a246dd49dc2a0a9e86f59e055
|
|
| BLAKE2b-256 |
0eac542003998e6b8d7d25cf6df7ffbe118d9db8d23bf2dff55f313c31933466
|
File details
Details for the file pyoctomap-1.2.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bf6daeb8ff574060757fa78c537027c9faeb6d2eabe58360002609d17790d6f
|
|
| MD5 |
e7928fa66a1716f0bee744701c6539a9
|
|
| BLAKE2b-256 |
423e5005f5855424ec9201619cd99e732e3237d7004ff1b55ae4658c1a988392
|
File details
Details for the file pyoctomap-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 9.9 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b979d3caf16366d2749ecd678556b69228ddb9ffc47edb5f4dc144a17361e593
|
|
| MD5 |
5a48eafb886c3e5f00266ae556b29d36
|
|
| BLAKE2b-256 |
44e5fca4dff4510551fc08ef585924f97734ab28a79f6492c27934c325cce605
|
File details
Details for the file pyoctomap-1.2.0-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6943eebad112e9fecb2605154d873c532f844ecb0684a39439a8de74310d953
|
|
| MD5 |
f242ac664d017f39614450d865c01f55
|
|
| BLAKE2b-256 |
7b94698b11b7a8519c5bd827b61a29c493cc278d130e8a442bda322096fa7674
|
File details
Details for the file pyoctomap-1.2.0-cp38-cp38-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93f854236d874398c90744d90f9205c83a84e11784d11d1f7dd6c1fea49db0a4
|
|
| MD5 |
c8f0c5a61a8c8fed53ac591b2cd1f8a0
|
|
| BLAKE2b-256 |
c822e1f460e26b9cdef4d6eacff81cd6a2b5a61fac63dcef297e6d6aaa4bc0e9
|
File details
Details for the file pyoctomap-1.2.0-cp38-cp38-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyoctomap-1.2.0-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e77cb9cfbc333be1d7784fbb6fa03ec28db5a88e443a55a2cc813c41155010c
|
|
| MD5 |
f0e0ac92e69858898e8f42a40cc6cff5
|
|
| BLAKE2b-256 |
f46b51869d4da7f633bc7b556d2bf1dd60fdcb48d2a80e4f7175ae2b189faad1
|