# rjdmoore/fictrac architecture

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

- Interactive diagram: https://gitdiagram.com/rjdmoore/fictrac
- Repository: https://github.com/rjdmoore/fictrac

## Overview

FicTrac reconstructs an animal’s fictive path by tracking a patterned sphere in live camera frames or recorded video. The principal runtime is `fictrac`: it obtains frames, maps camera imagery into a tracking region, estimates sphere rotation, transforms motion into animal coordinates, and integrates position and heading. Configuration, camera calibration/remapping, visualization, and multiple output transports are supporting capabilities. Relationships are based on the README and SOURCE INDEX references; unsampled implementations limit certainty about some dispatch and output details.

Main entry points: [`src/Trackball.cpp`](https://github.com/rjdmoore/fictrac/blob/master/src/Trackball.cpp) (Sphere tracking), [`src/Recorder.cpp`](https://github.com/rjdmoore/fictrac/blob/master/src/Recorder.cpp) (Output recorder), [`src/FrameGrabber.cpp`](https://github.com/rjdmoore/fictrac/blob/master/src/FrameGrabber.cpp) (Frame acquisition), [`exec/fictrac.cpp`](https://github.com/rjdmoore/fictrac/blob/master/exec/fictrac.cpp) (Runtime entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Tracking runtime"]
  node_fictrac["Runtime entry<br/>[fictrac.cpp]"]
  node_tracker["Sphere tracking<br/>[Trackball.cpp]"]
  node_localiser["Rotation optimiser<br/>[Localiser.cpp]"]
  node_geometry["Motion geometry<br/>[geometry.cpp]"]
  node_logger["Logging<br/>[Logger.cpp]"]
end

subgraph group_vision["Camera and vision"]
  node_frames["Frame acquisition<br/>[FrameGrabber.cpp]"]
  node_frame_source["Frame source API<br/>[FrameSource.h]"]
  node_camera_drivers["Camera drivers<br/>[CVSource.cpp]"]
  node_camera_model["Camera models<br/>[CameraModel.cpp]"]
  node_remap["Image remapping<br/>[Remapper.cpp]"]
  node_camera_remap["Camera remapping<br/>[CameraRemap.cpp]"]
end

subgraph group_config["Configuration"]
  node_config_gui["Configuration GUI<br/>[ConfigGUI.cpp]"]
  node_config_parser["Config parser<br/>[ConfigParser.cpp]"]
  node_calibration["Camera calibration<br/>[SquareRT.cpp]"]
end

subgraph group_output["Data output"]
  node_recorder["Output recorder<br/>[Recorder.cpp]"]
  node_file_output["File output<br/>[FileRecorder.cpp]"]
  node_serial_output["Serial output<br/>[SerialRecorder.cpp]"]
  node_socket_output["Socket output<br/>[SocketRecorder.cpp]"]
  node_terminal_output["Terminal output<br/>[TermRecorder.cpp]"]
end

node_operator(("Experiment operator"))
node_camera(("Camera or video"))

node_operator -->|"starts"| node_fictrac
node_camera -->|"supplies frames"| node_frames
node_fictrac -->|"runs"| node_tracker
node_tracker -->|"grabs frames"| node_frames
node_frames -->|"uses API"| node_frame_source
node_frames -.->|"dispatches to"| node_camera_drivers
node_tracker -->|"optimises rotation"| node_localiser
node_tracker -->|"models camera"| node_camera_model
node_tracker -->|"remaps frames"| node_camera_remap
node_camera_remap -->|"extends"| node_remap
node_camera_remap -->|"maps coordinates"| node_camera_model
node_tracker -->|"uses geometry"| node_geometry
node_tracker -->|"reads settings"| node_config_parser
node_operator -.->|"configures"| node_config_gui
node_config_gui -->|"edits settings"| node_config_parser
node_config_gui -.->|"uses geometry"| node_calibration
node_tracker -->|"records results"| node_recorder
node_recorder -.->|"writes files"| node_file_output
node_recorder -.->|"sends serial"| node_serial_output
node_recorder -.->|"sends sockets"| node_socket_output
node_recorder -.->|"prints output"| node_terminal_output
node_fictrac -->|"logs events"| node_logger

click node_fictrac "https://github.com/rjdmoore/fictrac/blob/master/exec/fictrac.cpp"
click node_tracker "https://github.com/rjdmoore/fictrac/blob/master/src/Trackball.cpp"
click node_localiser "https://github.com/rjdmoore/fictrac/blob/master/src/Localiser.cpp"
click node_geometry "https://github.com/rjdmoore/fictrac/blob/master/src/geometry.cpp"
click node_frames "https://github.com/rjdmoore/fictrac/blob/master/src/FrameGrabber.cpp"
click node_frame_source "https://github.com/rjdmoore/fictrac/blob/master/include/FrameSource.h"
click node_camera_drivers "https://github.com/rjdmoore/fictrac/blob/master/src/CVSource.cpp"
click node_camera_model "https://github.com/rjdmoore/fictrac/blob/master/src/CameraModel.cpp"
click node_remap "https://github.com/rjdmoore/fictrac/blob/master/src/Remapper.cpp"
click node_camera_remap "https://github.com/rjdmoore/fictrac/blob/master/src/CameraRemap.cpp"
click node_config_gui "https://github.com/rjdmoore/fictrac/blob/master/src/ConfigGUI.cpp"
click node_config_parser "https://github.com/rjdmoore/fictrac/blob/master/src/ConfigParser.cpp"
click node_calibration "https://github.com/rjdmoore/fictrac/blob/master/src/SquareRT.cpp"
click node_recorder "https://github.com/rjdmoore/fictrac/blob/master/src/Recorder.cpp"
click node_file_output "https://github.com/rjdmoore/fictrac/blob/master/src/FileRecorder.cpp"
click node_serial_output "https://github.com/rjdmoore/fictrac/blob/master/src/SerialRecorder.cpp"
click node_socket_output "https://github.com/rjdmoore/fictrac/blob/master/src/SocketRecorder.cpp"
click node_terminal_output "https://github.com/rjdmoore/fictrac/blob/master/src/TermRecorder.cpp"
click node_logger "https://github.com/rjdmoore/fictrac/blob/master/src/Logger.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_fictrac,node_tracker,node_localiser,node_geometry,node_logger toneBlue
class node_frames,node_frame_source,node_camera_drivers,node_camera_model,node_remap,node_camera_remap toneAmber
class node_config_gui,node_config_parser,node_calibration toneMint
class node_recorder,node_file_output,node_serial_output,node_socket_output,node_terminal_output toneRose
class node_operator,node_camera toneIndigo
```

## Components

### Tracking runtime

- [Runtime entry](https://github.com/rjdmoore/fictrac/blob/master/exec/fictrac.cpp): `exec/fictrac.cpp`
- [Sphere tracking](https://github.com/rjdmoore/fictrac/blob/master/src/Trackball.cpp): `src/Trackball.cpp`
- [Rotation optimiser](https://github.com/rjdmoore/fictrac/blob/master/src/Localiser.cpp): `src/Localiser.cpp`
- [Motion geometry](https://github.com/rjdmoore/fictrac/blob/master/src/geometry.cpp): `src/geometry.cpp`
- [Logging](https://github.com/rjdmoore/fictrac/blob/master/src/Logger.cpp): `src/Logger.cpp`

### Camera and vision

- [Frame acquisition](https://github.com/rjdmoore/fictrac/blob/master/src/FrameGrabber.cpp): `src/FrameGrabber.cpp`
- [Frame source API](https://github.com/rjdmoore/fictrac/blob/master/include/FrameSource.h): `include/FrameSource.h`
- [Camera drivers](https://github.com/rjdmoore/fictrac/blob/master/src/CVSource.cpp): `src/CVSource.cpp`
- [Camera models](https://github.com/rjdmoore/fictrac/blob/master/src/CameraModel.cpp): `src/CameraModel.cpp`
- [Image remapping](https://github.com/rjdmoore/fictrac/blob/master/src/Remapper.cpp): `src/Remapper.cpp`
- [Camera remapping](https://github.com/rjdmoore/fictrac/blob/master/src/CameraRemap.cpp): `src/CameraRemap.cpp`

### Configuration

- [Configuration GUI](https://github.com/rjdmoore/fictrac/blob/master/src/ConfigGUI.cpp): `src/ConfigGUI.cpp`
- [Config parser](https://github.com/rjdmoore/fictrac/blob/master/src/ConfigParser.cpp): `src/ConfigParser.cpp`
- [Camera calibration](https://github.com/rjdmoore/fictrac/blob/master/src/SquareRT.cpp): `src/SquareRT.cpp`

### Data output

- [Output recorder](https://github.com/rjdmoore/fictrac/blob/master/src/Recorder.cpp): `src/Recorder.cpp`
- [File output](https://github.com/rjdmoore/fictrac/blob/master/src/FileRecorder.cpp): `src/FileRecorder.cpp`
- [Serial output](https://github.com/rjdmoore/fictrac/blob/master/src/SerialRecorder.cpp): `src/SerialRecorder.cpp`
- [Socket output](https://github.com/rjdmoore/fictrac/blob/master/src/SocketRecorder.cpp): `src/SocketRecorder.cpp`
- [Terminal output](https://github.com/rjdmoore/fictrac/blob/master/src/TermRecorder.cpp): `src/TermRecorder.cpp`

### Other components

- **Experiment operator**
- **Camera or video**

## Connections

- Experiment operator → Runtime entry: starts
- Camera or video → Frame acquisition: supplies frames
- Runtime entry → Sphere tracking: runs (evidence: `exec/fictrac.cpp`)
- Sphere tracking → Frame acquisition: grabs frames (evidence: `src/Trackball.cpp`)
- Frame acquisition → Frame source API: uses API
- Frame acquisition → Camera drivers: dispatches to
- Sphere tracking → Rotation optimiser: optimises rotation
- Sphere tracking → Camera models: models camera (evidence: `src/Trackball.cpp`)
- Sphere tracking → Camera remapping: remaps frames (evidence: `src/Trackball.cpp`)
- Camera remapping → Image remapping: extends
- Camera remapping → Camera models: maps coordinates
- Sphere tracking → Motion geometry: uses geometry (evidence: `src/Trackball.cpp`)
- Sphere tracking → Config parser: reads settings (evidence: `src/Trackball.cpp`)
- Experiment operator → Configuration GUI: configures
- Configuration GUI → Config parser: edits settings
- Configuration GUI → Camera calibration: uses geometry
- Sphere tracking → Output recorder: records results
- Output recorder → File output: writes files
- Output recorder → Serial output: sends serial
- Output recorder → Socket output: sends sockets
- Output recorder → Terminal output: prints output
- Runtime entry → Logging: logs events (evidence: `exec/fictrac.cpp`)
