# unknownfreeoccupied/ufomap architecture

> Architecture diagram of the GitHub repository unknownfreeoccupied/ufomap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unknownfreeoccupied/ufomap
- Repository: https://github.com/unknownfreeoccupied/ufomap

## Overview

#### Purpose and Top-Level Shape
UFOMap is a C++ probabilistic 3D volumetric mapping framework. Its core represents unknown, free, and occupied space in an octree-backed map; optional ROS packages expose mapping, serialization, visualization, and service interfaces. The standalone library is under `ufomap/`; ROS integration is under `ufomap_ros/`.

#### Core Map Model
The principal public API is the map subsystem, centered on octree storage and occupancy semantics:
- `ufomap/include/ufo/map/octree.h`
- `ufomap/include/ufo/map/occupancy_map_base.h`
- `ufomap/include/ufo/map/occupancy_map.h`

`OccupancyMap` builds on the generic octree/node model to store probabilistic occupancy while retaining explicit unknown regions. Colored occupancy is a specialization in `ufomap/include/ufo/map/occupancy_map_color.h`, implemented by `ufomap/src/map/occupancy_map_color.cpp`.

#### Spatial Encoding, Nodes, and Traversal
Spatial hierarchy and addressing are separate from occupancy policy:
- `ufomap/include/ufo/map/code.h`
- `ufomap/include/ufo/map/key.h`
- `ufomap/include/ufo/map/octree_node.h`

Keys/codes identify cells in the octree; node types carry tree state. Iterator families provide map/octree traversal, including nearest-oriented queries:
- `ufomap/include/ufo/map/iterator/occupancy_map.h`
- `ufomap/include/ufo/map/iterator/octree.h`
- `ufomap/include/ufo/map/iterator/occupancy_map_nearest.h`

This boundary lets planning or collision consumers query hierarchical map content without owning map-update mechanics.

#### Geometry and Collision Boundary
A geometry module supplies typed primitives, bounding-volume abstractions, and collision checks used to query map-adjacent spatial regions:
- `ufomap/include/ufo/geometry/bounding_volume.h`
- `ufomap/include/ufo/geometry/collision_checks.h`
- `ufomap/src/geometry/collision_checks.cpp`

Supported query shapes include AABBs, OBBs, rays, frusta, capsules, and others. Math primitives underpin both geometry and mapping:
- `ufomap/include/ufo/math/vector3.h`
- `ufomap/include/ufo/math/quaternion.h`
- `ufomap/include/ufo/math/pose6.h`

#### Map Input and Update Path
Point-cloud data is the main library-level mapping input:
- `ufomap/include/ufo/map/point_cloud.h`
- `ufomap/include/ufo/map/occupancy_map.h`
- `ufomap/src/map/occupancy_map.cpp`

The primary flow is point cloud plus sensor pose/ray information into occupancy updates, producing free/occupied voxel evidence and preserving unobserved cells as unknown. Consumers then traverse or spatially query the resulting hierarchy.

#### ROS Runtime Integration
ROS packages form an adapter layer around the C++ map rather than a separate mapping implementation. `ufomap_mapping` provides the operational server/node:
- `ufomap_ros/ufomap_mapping/src/server_node.cpp`
- `ufomap_ros/ufomap_mapping/src/server.cpp`
- `ufomap_ros/ufomap_mapping/include/ufomap_mapping/server.h`

It is launched through `ufomap_ros/ufomap_mapping/launch/server.launch` and has runtime-configurable server behavior in `ufomap_ros/ufomap_mapping/cfg/Server.cfg`. This is the primary ROS process entry point.

#### ROS Data, Services, and Visualization
ROS message definitions serialize maps and geometry across ROS topic boundaries:
- `ufomap_ros/ufomap_msgs/msg/UFOMap.msg`
- `ufomap_ros/ufomap_msgs/msg/UFOMapStamped.msg`
- `ufomap_ros/ufomap_msgs/src/conversions.cpp`

Service contracts support map retrieval, persistence, reset, and volume clearing:
- `ufomap_ros/ufomap_srvs/srv/GetMap.srv`
- `ufomap_ros/ufomap_srvs/srv/SaveMap.srv`
- `ufomap_ros/ufomap_srvs/srv/ClearVolume.srv`

RViz visualization is a plugin consuming the ROS-facing map representation:
- `ufomap_ros/ufomap_rviz_plugins/src/ufomap_display.cpp`
- `ufomap_ros/ufomap_rviz_plugins/plugin_description.xml`

#### Build and Packaging
The core library uses CMake and exports a package configuration through `ufomap/CMakeLists.txt` and `ufomap/cmake/ufomapConfig.cmake.in`. ROS components are separately packaged as catkin-style packages via their `CMakeLists.txt` and `package.xml` files. Material runtime dependencies are ROS (mapping server, messages, services, RViz) and RViz for visualization; no external hosted service is indicated.

Main entry points: [`ufomap/include/ufo/map/occupancy_map.h`](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map.h) (Occupancy map), [`ufomap_ros/ufomap_mapping/src/server_node.cpp`](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_mapping/src/server_node.cpp) (Mapping server), [`ufomap/include/ufo/map/octree.h`](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/octree.h) (Octree), [`ufomap/include/ufo/math/vector3.h`](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/math/vector3.h) (Math primitives)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["C++ Core"]
  node_math["Math primitives<br/>[vector3.h]"]
  node_geometry["Geometry &amp; collision<br/>spatial queries<br/>[collision_checks.h]"]
  node_addressing["Cell keys &amp; codes<br/>spatial encoding<br/>[code.h]"]
  node_octree_nodes["Octree nodes<br/>tree state<br/>[octree_node.h]"]
  node_octree[("Octree<br/>hierarchical storage<br/>[octree.h]")]
  node_occupancy_base["Occupancy map base<br/>occupancy policy"]
  node_occupancy_map[("Occupancy map<br/>public map API<br/>[occupancy_map.h]")]
  node_color_map["Colored occupancy map<br/>map specialization"]
  node_point_cloud["Point cloud input<br/>mapping input<br/>[point_cloud.h]"]
  node_traversal["Map traversal &amp; nearest queries<br/>iterator API"]
end

subgraph group_ros["ROS Integration"]
  node_ros_launch["ROS server launch<br/>process entry point<br/>[server.launch]"]
  node_mapping_server{{"Mapping server<br/>ROS node<br/>[server_node.cpp]"}}
  node_ros_messages["Map ROS messages<br/>serialization contracts<br/>[UFOMap.msg]"]
  node_ros_services["Map ROS services<br/>service contracts<br/>[GetMap.srv]"]
  node_rviz["RViz map display<br/>RViz plugin<br/>[ufomap_display.cpp]"]
end

node_math -->|"underpins"| node_geometry
node_math -->|"poses and vectors"| node_occupancy_map
node_addressing -->|"addresses cells"| node_octree
node_octree_nodes -->|"stores tree state"| node_octree
node_octree -->|"backs hierarchy"| node_occupancy_base
node_occupancy_base -->|"base policy"| node_occupancy_map
node_occupancy_map -->|"specialized as"| node_color_map
node_point_cloud -->|"ray-based updates"| node_occupancy_map
node_occupancy_map -->|"queried through"| node_traversal
node_geometry -->|"spatial query regions"| node_traversal
node_ros_launch -->|"starts"| node_mapping_server
node_mapping_server -->|"updates and serves"| node_occupancy_map
node_mapping_server -->|"publishes / serializes"| node_ros_messages
node_ros_services -->|"controls and retrieves"| node_mapping_server
node_ros_messages -->|"visualized by"| node_rviz

click node_math "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/math/vector3.h"
click node_geometry "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/geometry/collision_checks.h"
click node_addressing "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/code.h"
click node_octree_nodes "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/octree_node.h"
click node_octree "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/octree.h"
click node_occupancy_base "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map_base.h"
click node_occupancy_map "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map.h"
click node_color_map "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map_color.h"
click node_point_cloud "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/point_cloud.h"
click node_traversal "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/iterator/occupancy_map_nearest.h"
click node_ros_launch "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_mapping/launch/server.launch"
click node_mapping_server "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_mapping/src/server_node.cpp"
click node_ros_messages "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_msgs/msg/UFOMap.msg"
click node_ros_services "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_srvs/srv/GetMap.srv"
click node_rviz "https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_rviz_plugins/src/ufomap_display.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_math,node_geometry,node_addressing,node_octree_nodes,node_octree,node_occupancy_base,node_occupancy_map,node_color_map,node_point_cloud,node_traversal toneBlue
class node_ros_launch,node_mapping_server,node_ros_messages,node_ros_services,node_rviz toneAmber
```

## Components

### C++ Core

Standalone probabilistic volumetric mapping library.

- [Math primitives](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/math/vector3.h): math · `ufomap/include/ufo/math/vector3.h`
- [Geometry & collision](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/geometry/collision_checks.h): spatial queries · Bounding volumes and collision checks for map-adjacent regions. · `ufomap/include/ufo/geometry/collision_checks.h`
- [Cell keys & codes](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/code.h): spatial encoding · `ufomap/include/ufo/map/code.h`
- [Octree nodes](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/octree_node.h): tree state · `ufomap/include/ufo/map/octree_node.h`
- [Octree](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/octree.h): hierarchical storage · `ufomap/include/ufo/map/octree.h`
- [Occupancy map base](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map_base.h): occupancy policy · `ufomap/include/ufo/map/occupancy_map_base.h`
- [Occupancy map](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map.h): public map API · Stores probabilistic free and occupied evidence while retaining unknown space. · `ufomap/include/ufo/map/occupancy_map.h`
- [Colored occupancy map](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/occupancy_map_color.h): map specialization · `ufomap/include/ufo/map/occupancy_map_color.h`
- [Point cloud input](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/point_cloud.h): mapping input · `ufomap/include/ufo/map/point_cloud.h`
- [Map traversal & nearest queries](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap/include/ufo/map/iterator/occupancy_map_nearest.h): iterator API · Hierarchical and nearest-oriented occupancy queries. · `ufomap/include/ufo/map/iterator/occupancy_map_nearest.h`

### ROS Integration

ROS adapters, runtime server, contracts, and visualization.

- [ROS server launch](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_mapping/launch/server.launch): process entry point · `ufomap_ros/ufomap_mapping/launch/server.launch`
- [Mapping server](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_mapping/src/server_node.cpp): ROS node · Operational ROS adapter around the C++ occupancy map. · `ufomap_ros/ufomap_mapping/src/server_node.cpp`
- [Map ROS messages](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_msgs/msg/UFOMap.msg): serialization contracts · Map and geometry representation crossing ROS topic boundaries. · `ufomap_ros/ufomap_msgs/msg/UFOMap.msg`
- [Map ROS services](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_srvs/srv/GetMap.srv): service contracts · Retrieve, save, reset, and clear map volumes. · `ufomap_ros/ufomap_srvs/srv/GetMap.srv`
- [RViz map display](https://github.com/unknownfreeoccupied/ufomap/blob/master/ufomap_ros/ufomap_rviz_plugins/src/ufomap_display.cpp): RViz plugin · `ufomap_ros/ufomap_rviz_plugins/src/ufomap_display.cpp`

## Connections

- Math primitives → Geometry & collision: underpins
- Math primitives → Occupancy map: poses and vectors
- Cell keys & codes → Octree: addresses cells
- Octree nodes → Octree: stores tree state
- Octree → Occupancy map base: backs hierarchy
- Occupancy map base → Occupancy map: base policy
- Occupancy map → Colored occupancy map: specialized as
- Point cloud input → Occupancy map: ray-based updates · Sensor pose and point data produce free and occupied evidence.
- Occupancy map → Map traversal & nearest queries: queried through
- Geometry & collision → Map traversal & nearest queries: spatial query regions
- ROS server launch → Mapping server: starts
- Mapping server → Occupancy map: updates and serves
- Mapping server → Map ROS messages: publishes / serializes
- Map ROS services → Mapping server: controls and retrieves
- Map ROS messages → RViz map display: visualized by
