# tecartlab/headroom architecture

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

- Interactive diagram: https://gitdiagram.com/tecartlab/headroom
- Repository: https://github.com/tecartlab/headroom

## Overview

#### Purpose and Runtime

HeadRoom is a native openFrameworks Kinect tracking server. A dedicated host captures one Kinect, derives metric body/head/eye/gaze data in a floor-referenced Cartesian space, exposes calibration, and streams results to network clients. It targets macOS, Windows, and Linux; Kinect capture relies on libfreenect/ofxKinect. Build/application wiring is in `HeadRoom.xcodeproj/project.pbxproj`, `addons.make`, and `src/main.cpp`.

#### Application Lifecycle and UI

`src/main.cpp` launches the openFrameworks application; `src/ofApp.h` and `src/ofApp.cpp` are the central lifecycle owner for setup, per-frame update, drawing, calibration interaction, and subsystem orchestration. This is a desktop processing service with an operator-facing visualization/calibration UI, not a web application. `src/Properties.h` and `src/Properties.cpp` likely centralize runtime-adjustable settings consumed by the app and tracking pipeline.

#### Capture-Space Calibration and Geometry

Calibration establishes the transform from Kinect sensor coordinates to floor-based metric coordinates, including sensor box, frustum, and a configured gaze target. Geometry primitives support those calculations and visualization:

- `src/Frustum.h`, `src/Frustum.cpp`
- `src/Planef.h`, `src/Planef.cpp`
- `src/Grid.h`, `src/Grid.cpp`

`src/OrthoCamera.h` and `src/OrthoCamera.cpp`, plus advanced camera variants, provide calibrated scene inspection rather than tracking semantics. The calibrated coordinate boundary is critical: raw Kinect observations enter sensor space; exported positions and dimensions are transformed into the shared floor reference frame.

#### Blob Extraction and Persistent Tracking

The tracking core separates per-frame detection from identity continuity:

- `src/BlobFinder.h`, `src/BlobFinder.cpp`
- `src/BlobTracker.h`, `src/BlobTracker.cpp`
- `src/TrackedBlob.h`, `src/TrackedBlob.cpp`

Blob finding produces body/head candidates from Kinect-derived spatial data. `BlobTracker` associates candidates across frames and maintains stable blob IDs/sorted positions. `TrackedBlob` is the likely per-person state carrier for body bounds, height, head points, and eye/gaze-derived outputs. This stage feeds only transformed, metric tracking records to network publication.

#### Mesh and Spatial Data Representation

`src/CaptureMeshArray.h` and `src/CaptureMeshArray.cpp` represent captured spatial/mesh data used by the analysis or visualization path. `src/Linef.h` and `src/Linef.cpp` provide custom geometric line operations used alongside planes/frusta. These components form the boundary between Kinect point/depth-derived geometry and higher-level blobs/tracked people.

#### Network Discovery, Sessions, and Streaming

Networking is split between protocol/session management and client-facing transport:

- `src/TrackingNetworkManager.h`, `src/TrackingNetworkManager.cpp`
- `src/TrackingClient.h`, `src/TrackingClient.cpp`

The server broadcasts OSC discovery announcements to UDP port 43500 and listens on its configured server port (default 43600). Clients request a handshake, receive calibration messages, then renew update requests roughly every 10 seconds. Registered clients receive continuous per-frame OSC tracking messages for approximately 11 seconds per renewal; inactive clients are removed. The manager should own discovery, handshake/update control flow, registration, and broadcast/exit behavior, while `TrackingClient` represents client endpoint/session state.

#### External Contracts

The public OSC contract has two payload families: calibration (`/ks/server/calib/trans`, `frustum`, `sensorbox`, `gazepoint`) and ordered frame streams (`/ks/server/track/frame`, body/head/eye records, `framedone`). Consumers depend on frame numbers, stable blob IDs, server ID, metric units, and the framing markers to reconstruct each update atomically. Runtime dependencies include openFrameworks, libfreenect/ofxKinect, and the external `ofxGuiExtended` addon.

Main entry points: [`src/Frustum.cpp`](https://github.com/tecartlab/headroom/blob/master/src/Frustum.cpp) (Floor-space calibration), [`src/TrackingNetworkManager.cpp`](https://github.com/tecartlab/headroom/blob/master/src/TrackingNetworkManager.cpp) (Tracking network manager), [`src/ofApp.cpp`](https://github.com/tecartlab/headroom/blob/master/src/ofApp.cpp) (Lifecycle & operator UI), [`src/BlobFinder.cpp`](https://github.com/tecartlab/headroom/blob/master/src/BlobFinder.cpp) (Blob extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Host Runtime"]
  node_entry["Application entry<br/>openFrameworks bootstrap<br/>[main.cpp]"]
  node_app["Lifecycle &amp; operator UI<br/>application controller<br/>[ofApp.cpp]"]
  node_properties["Runtime properties<br/>settings<br/>[Properties.cpp]"]
  node_kinect{{"Kinect capture<br/>capture dependency"}}
  node_build["Build wiring<br/>project configuration<br/>[project.pbxproj]"]
end

subgraph group_geometry["Calibration &amp; Geometry"]
  node_calibration["Floor-space calibration<br/>coordinate transform<br/>[Frustum.cpp]"]
  node_plane["Plane geometry<br/>geometry primitive<br/>[Planef.cpp]"]
  node_grid["Floor grid<br/>calibration visualization<br/>[Grid.cpp]"]
  node_inspection_camera["Scene inspection camera<br/>orthographic camera<br/>[OrthoCamera.cpp]"]
end

subgraph group_tracking["Tracking Pipeline"]
  node_capture_mesh["Capture mesh data<br/>spatial representation"]
  node_blob_finder["Blob extraction<br/>per-frame detector<br/>[BlobFinder.cpp]"]
  node_blob_tracker["Persistent blob tracking<br/>identity association<br/>[BlobTracker.cpp]"]
  node_tracked_blob["Tracked person state<br/>tracking record<br/>[TrackedBlob.cpp]"]
end

subgraph group_network["OSC Server"]
  node_network_manager["Tracking network manager<br/>OSC server manager"]
  node_tracking_client["Client session<br/>registered endpoint<br/>[TrackingClient.cpp]"]
  node_osc_clients{{"OSC consumers<br/>external clients"}}
end

node_entry -->|"launches"| node_app
node_build -->|"builds"| node_entry
node_app -->|"uses"| node_properties
node_kinect -->|"raw spatial data"| node_capture_mesh
node_app -->|"configures"| node_calibration
node_properties -->|"calibration settings"| node_calibration
node_plane -->|"supports"| node_calibration
node_calibration -->|"visualizes floor space"| node_grid
node_calibration -->|"sets inspection view"| node_inspection_camera
node_capture_mesh -->|"spatial candidates"| node_blob_finder
node_calibration -->|"metric coordinate space"| node_blob_finder
node_blob_finder -->|"per-frame candidates"| node_blob_tracker
node_blob_tracker -->|"stable identities"| node_tracked_blob
node_tracked_blob -->|"metric tracking records"| node_network_manager
node_app -->|"orchestrates per frame"| node_network_manager
node_network_manager -->|"registers and expires"| node_tracking_client
node_osc_clients -->|"UDP discovery and handshake"| node_network_manager
node_network_manager -->|"calibration and framed OSC stream"| node_osc_clients

click node_entry "https://github.com/tecartlab/headroom/blob/master/src/main.cpp"
click node_app "https://github.com/tecartlab/headroom/blob/master/src/ofApp.cpp"
click node_properties "https://github.com/tecartlab/headroom/blob/master/src/Properties.cpp"
click node_calibration "https://github.com/tecartlab/headroom/blob/master/src/Frustum.cpp"
click node_plane "https://github.com/tecartlab/headroom/blob/master/src/Planef.cpp"
click node_grid "https://github.com/tecartlab/headroom/blob/master/src/Grid.cpp"
click node_inspection_camera "https://github.com/tecartlab/headroom/blob/master/src/OrthoCamera.cpp"
click node_capture_mesh "https://github.com/tecartlab/headroom/blob/master/src/CaptureMeshArray.cpp"
click node_blob_finder "https://github.com/tecartlab/headroom/blob/master/src/BlobFinder.cpp"
click node_blob_tracker "https://github.com/tecartlab/headroom/blob/master/src/BlobTracker.cpp"
click node_tracked_blob "https://github.com/tecartlab/headroom/blob/master/src/TrackedBlob.cpp"
click node_network_manager "https://github.com/tecartlab/headroom/blob/master/src/TrackingNetworkManager.cpp"
click node_tracking_client "https://github.com/tecartlab/headroom/blob/master/src/TrackingClient.cpp"
click node_build "https://github.com/tecartlab/headroom/blob/master/HeadRoom.xcodeproj/project.pbxproj"

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_entry,node_app,node_properties,node_kinect,node_build toneBlue
class node_calibration,node_plane,node_grid,node_inspection_camera toneAmber
class node_capture_mesh,node_blob_finder,node_blob_tracker,node_tracked_blob toneMint
class node_network_manager,node_tracking_client,node_osc_clients toneRose
```

## Components

### Host Runtime

- [Application entry](https://github.com/tecartlab/headroom/blob/master/src/main.cpp): openFrameworks bootstrap · `src/main.cpp`
- [Lifecycle & operator UI](https://github.com/tecartlab/headroom/blob/master/src/ofApp.cpp): application controller · Owns setup, frame updates, drawing, calibration interaction, and orchestration. · `src/ofApp.cpp`
- [Runtime properties](https://github.com/tecartlab/headroom/blob/master/src/Properties.cpp): settings · `src/Properties.cpp`
- **Kinect capture**: capture dependency · Raw sensor/depth observations from libfreenect/ofxKinect.
- [Build wiring](https://github.com/tecartlab/headroom/blob/master/HeadRoom.xcodeproj/project.pbxproj): project configuration · Configures the native application and addon dependencies. · `HeadRoom.xcodeproj/project.pbxproj`

### Calibration & Geometry

- [Floor-space calibration](https://github.com/tecartlab/headroom/blob/master/src/Frustum.cpp): coordinate transform · Converts sensor observations into shared floor-referenced metric coordinates. · `src/Frustum.cpp`
- [Plane geometry](https://github.com/tecartlab/headroom/blob/master/src/Planef.cpp): geometry primitive · `src/Planef.cpp`
- [Floor grid](https://github.com/tecartlab/headroom/blob/master/src/Grid.cpp): calibration visualization · `src/Grid.cpp`
- [Scene inspection camera](https://github.com/tecartlab/headroom/blob/master/src/OrthoCamera.cpp): orthographic camera · Provides calibrated operator scene inspection. · `src/OrthoCamera.cpp`

### Tracking Pipeline

- [Capture mesh data](https://github.com/tecartlab/headroom/blob/master/src/CaptureMeshArray.cpp): spatial representation · Represents Kinect-derived spatial and mesh data. · `src/CaptureMeshArray.cpp`
- [Blob extraction](https://github.com/tecartlab/headroom/blob/master/src/BlobFinder.cpp): per-frame detector · Produces body and head candidates from spatial data. · `src/BlobFinder.cpp`
- [Persistent blob tracking](https://github.com/tecartlab/headroom/blob/master/src/BlobTracker.cpp): identity association · Associates candidates across frames and maintains stable IDs. · `src/BlobTracker.cpp`
- [Tracked person state](https://github.com/tecartlab/headroom/blob/master/src/TrackedBlob.cpp): tracking record · Carries body, head, eye, and gaze-derived metric state. · `src/TrackedBlob.cpp`

### OSC Server

- [Tracking network manager](https://github.com/tecartlab/headroom/blob/master/src/TrackingNetworkManager.cpp): OSC server manager · Owns discovery, handshake, client renewal, and frame broadcast. · `src/TrackingNetworkManager.cpp`
- [Client session](https://github.com/tecartlab/headroom/blob/master/src/TrackingClient.cpp): registered endpoint · Tracks endpoint state and expiring update subscription. · `src/TrackingClient.cpp`
- **OSC consumers**: external clients · Consume atomic framed tracking updates and calibration payloads.

## Connections

- Application entry → Lifecycle & operator UI: launches
- Build wiring → Application entry: builds
- Lifecycle & operator UI → Runtime properties: uses
- Kinect capture → Capture mesh data: raw spatial data
- Lifecycle & operator UI → Floor-space calibration: configures
- Runtime properties → Floor-space calibration: calibration settings
- Plane geometry → Floor-space calibration: supports
- Floor-space calibration → Floor grid: visualizes floor space
- Floor-space calibration → Scene inspection camera: sets inspection view
- Capture mesh data → Blob extraction: spatial candidates
- Floor-space calibration → Blob extraction: metric coordinate space
- Blob extraction → Persistent blob tracking: per-frame candidates
- Persistent blob tracking → Tracked person state: stable identities
- Tracked person state → Tracking network manager: metric tracking records
- Lifecycle & operator UI → Tracking network manager: orchestrates per frame
- Tracking network manager → Client session: registers and expires
- OSC consumers → Tracking network manager: UDP discovery and handshake
- Tracking network manager → OSC consumers: calibration and framed OSC stream
