Skip to main content

Python binding of the OctoMap library with bundled shared libraries.

Project description

PyOctoMap

OctoMap Core

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 Silicon arm64), 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 ros branch, 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 (cp38cp313), 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 voxel
  • CountingOcTree – integer hit counters per voxel
  • OcTreeStamped – 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 colors
  • OcTreeStamped.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:

Demo Visualizations

3D OctoMap Scene Visualization:

OctoMap Demo Scene

Occupancy Grid Visualization:

Occupancy Grid

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyoctomap-1.2.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyoctomap-1.2.0-cp313-cp313-manylinux_2_28_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pyoctomap-1.2.0-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyoctomap-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyoctomap-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyoctomap-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl (10.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyoctomap-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyoctomap-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl (9.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyoctomap-1.2.0-cp310-cp310-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyoctomap-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl (9.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

pyoctomap-1.2.0-cp39-cp39-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pyoctomap-1.2.0-cp38-cp38-manylinux_2_28_x86_64.whl (10.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

pyoctomap-1.2.0-cp38-cp38-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

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

Hashes for pyoctomap-1.2.0.tar.gz
Algorithm Hash digest
SHA256 17c78604945e70188ae2d4c3cd7f778815dd065e772db73f97faffa84a859a70
MD5 c5a6c960e267d70dec46f4d862a705f0
BLAKE2b-256 c0b26300024be3a6c4de46492a51fab563270a58dac7539e537310109db2715d

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5f9026a8508251b0ca0c755cdf5f809507a06ced4ff5325fac7f2875a7f4fe53
MD5 eba81a2616e008f0349a6dfbe0b5facf
BLAKE2b-256 0b97456e25ef1d7cd18f1446d4ef51bc1f36afbd8eeef86fa92a5e15e929cf7a

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 958dc9360ec1e11b07ac0d08c8fe8dc9a8f1b16343f64c08dad96f25299e1329
MD5 acc1e302c1d4ee914c1c82226a2687b0
BLAKE2b-256 f98d60142d005c110a425c51bf15095d8006280652514be57c8519d844208858

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ed070a9c5734daa130ae90e8de763d8256a1e95c901fff6f08e5c34714ee19f0
MD5 76628041f3cea13cd54621e5b45b8ff2
BLAKE2b-256 40225b81b22b7d67c2268ab6d608758e648b9a31fa6a0ca3ab6bf0b715db97f1

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e38267c45de85e97cffdfc0487100f522716bfec5663e50418b6d738c081d15f
MD5 ff1e49f1f80db3610772188ae5f44be7
BLAKE2b-256 fb966c8ac27e69aa92e603fb4ec6d8922084bfada8d4e92d934cec1420090ab7

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5169ff2ed6bd2ef554a5edb7e7b0d561c0b92654b8372036dd5205b36560f1d4
MD5 6659198ee8459c254ac3a1b9d5095165
BLAKE2b-256 b13e1b64bfe48ccdf88472e3381a44bc3a569d15c545811baeaa087902aecaed

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bedd7966b80998424936cb447be50a7622ac485fa8855ee76515bfd57148a5a9
MD5 5f9d0856ce0cf493b55fcee15ae5d7fb
BLAKE2b-256 1656662c02a38924daf0afbc7f2528ee523b84babe4b9689eaea73094be7739c

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 425128836d74d621d49a8e9e19c6048ebbf83ce04f53b91009d6728a02d8543c
MD5 e25de73a246dd49dc2a0a9e86f59e055
BLAKE2b-256 0eac542003998e6b8d7d25cf6df7ffbe118d9db8d23bf2dff55f313c31933466

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1bf6daeb8ff574060757fa78c537027c9faeb6d2eabe58360002609d17790d6f
MD5 e7928fa66a1716f0bee744701c6539a9
BLAKE2b-256 423e5005f5855424ec9201619cd99e732e3237d7004ff1b55ae4658c1a988392

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b979d3caf16366d2749ecd678556b69228ddb9ffc47edb5f4dc144a17361e593
MD5 5a48eafb886c3e5f00266ae556b29d36
BLAKE2b-256 44e5fca4dff4510551fc08ef585924f97734ab28a79f6492c27934c325cce605

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6943eebad112e9fecb2605154d873c532f844ecb0684a39439a8de74310d953
MD5 f242ac664d017f39614450d865c01f55
BLAKE2b-256 7b94698b11b7a8519c5bd827b61a29c493cc278d130e8a442bda322096fa7674

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 93f854236d874398c90744d90f9205c83a84e11784d11d1f7dd6c1fea49db0a4
MD5 c8f0c5a61a8c8fed53ac591b2cd1f8a0
BLAKE2b-256 c822e1f460e26b9cdef4d6eacff81cd6a2b5a61fac63dcef297e6d6aaa4bc0e9

See more details on using hashes here.

File details

Details for the file pyoctomap-1.2.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyoctomap-1.2.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e77cb9cfbc333be1d7784fbb6fa03ec28db5a88e443a55a2cc813c41155010c
MD5 f0e0ac92e69858898e8f42a40cc6cff5
BLAKE2b-256 f46b51869d4da7f633bc7b556d2bf1dd60fdcb48d2a80e4f7175ae2b189faad1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page