OctoMap Python Bindings (cmeel)

1.10.0 · active · verified Wed Apr 15

cmeel-octomap provides efficient Python bindings for the OctoMap library, a probabilistic 3D mapping framework based on octrees. It enables users to build, query, and manage 3D occupancy maps in Python. The current version is 1.10.0, with updates typically aligned with upstream OctoMap releases or cmeel improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an OctoMap, insert occupied and free points, and query their occupancy status. It highlights basic map manipulation and information retrieval.

from octomap import OcTree, Point3D

# Create an OcTree with a resolution of 0.1 meters
tree = OcTree(0.1)

# Insert some occupied points
tree.insert_point(Point3D(0.0, 0.0, 0.0), occupied=True)
tree.insert_point(Point3D(0.1, 0.0, 0.0), occupied=True)
tree.insert_point(Point3D(0.5, 0.5, 0.5), occupied=True)

# Insert a free point (clears any occupied status at this node)
tree.insert_point(Point3D(0.0, 0.1, 0.0), occupied=False)

# Query occupancy of points
is_occupied_000 = tree.is_node_occupied(Point3D(0.0, 0.0, 0.0))
is_occupied_055 = tree.is_node_occupied(Point3D(0.5, 0.5, 0.5))
is_occupied_001 = tree.is_node_occupied(Point3D(0.0, 0.0, 1.0))

print(f"Point (0,0,0) is occupied: {is_occupied_000}")
print(f"Point (0.5,0.5,0.5) is occupied: {is_occupied_055}")
print(f"Point (0,0,1) is occupied: {is_occupied_001} (outside inserted points)")

# Get the total number of occupied nodes
print(f"Total occupied nodes: {tree.num_occupied_nodes}")

# You can also save and load the map (uncomment to run)
# tree.write_binary("my_octomap.bt")
# loaded_tree = OcTree("my_octomap.bt")
# print(f"Loaded tree has {loaded_tree.num_occupied_nodes} occupied nodes.")

view raw JSON →