# mit-spark/kimera-vio architecture

> Architecture diagram of the GitHub repository mit-spark/kimera-vio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mit-spark/kimera-vio
- Repository: https://github.com/mit-spark/kimera-vio

## Overview

##### Main Components
- Sensors & Data Input: Indicate two primary sensor inputs—cameras (Stereo/Mono) and IMU. Show that raw sensor data is first ingested by one or more DataProvider modules.
- DataProvider Module: Include components such as EurocDataProvider, KittiDataProvider, and specialized modules for stereo, mono, or RGBD data. Represent the role of this component in pre-processing and interfacing raw sensor data with the remaining pipeline.
- Frontend Processing:
- Feature Detection & Optical Flow: Highlight modules for feature detection (including the adaptive non-max suppression portion found under “feature-detector”) and optical-flow computation.
- Vision-IMU Frontend: Show modules like MonoVisionImuFrontend, StereoVisionImuFrontend, and RgbdVisionImuFrontend which combine visual measurements and inertial data.
- Tracker & Undistorter: Represent related components (e.g., Tracker, UndistorterRectifier) that work in the image-processing chain.
- Inertial (IMU) Frontend: Represent the “imu-frontend” module that processes IMU data separately before (or in parallel with) fusion.
- Pipeline Integration:
- Pipeline Modules: Illustrate how data flows from the various frontends into unified pipelines. There are distinct pipelines such as MonoImuPipeline, StereoImuPipeline, and RgbdImuPipeline that aggregate the pre-processed data.
- Queue Synchronizer: Since the pipeline must coordinate inputs (image, IMU, etc.), include a representation of queues and synchronizers as depicted by the log outputs (e.g., “stereo_frontend_input_queue”).
- Backend Optimization:
- Regular VIO Backend: Include the backend components that handle the optimization (as found under “backend”), factor graph management, and modules dedicated to regularization.
- Loop Closure Detector: Represent modules responsible for loop closure detection as an optional but significant sub-system.
- Initialization & Calibration: Separate the “initial” module components (i.e., InitializationBackend, CrossCorrTimeAligner, OnlineGravityAlignment) that manage system initialization and sensor calibration.
- Mesh & 3D Reconstruction: Show the mesh-related modules (under “mesh”) that construct 3D representations and possibly optimize them.
- Visualization & Logging:
- Visualizer: Represent the visual output modules (such as OpenCvDisplay, PangolinDisplay, Visualizer3D) that provide realtime feedback.
- Logger: Include a logging subsystem that records runtime data, as seen in the detailed logging provided in the README.
- Parameter & Configuration Management:
- YAML Parameters: Utilize the “params” folder to indicate that a range of YAML configurations are used (for Backend, Frontend, IMU, cameras, etc.).
- Gflags: Note that runtime parameters are also managed via Gflags (as described in the README). Represent these as configuration inputs into modules.

##### Relationships and Interactions
- Synchronization & Queues: Emphasize that the system design includes asynchronous processing using named queues between modules (for example between the DataProvider and Frontend, and between Frontend and Backend).

##### Architectural Patterns and Design Principles
- Modular, Layered Architecture: Emphasize the separation of concerns between data ingestion, processing, optimization, and visualization.
- Plugin & Factory Design: Many modules (e.g., different VIO backends or frontend detectors) are instantiated via factories (as evidenced by files like “VioBackendFactory.h” and “MesherFactory.h”).
- Real-Time Processing: Highlight that modules communicate via well-defined interfaces and queues to provide sequential or parallel processing (as noted in the “parallel_run” flag and unit testing details).

##### Putting It All Together—Step-by-Step
1. Two main sensor blocks labeled “Cameras (stereo/mono)” and “IMU”.
3. From DataProvider, split the flow into:
- “Frontend Processing” (showing sub-modules for feature detection, optical flow, and image preprocessing).
- “IMU Frontend” (processing inertial data).
4. Merge these flows into the “Pipeline Module” block:
- Inside this block, illustrate the synchronization mechanism (queues and synchronizers).
5. Unified pipeline to the “Backend” block:
- Inside the Backend, detail the “Regular VIO Backend”, and include a side-branch for “Loop Closure Detection” or graph optimization (using Kimera-RPGO).
- “Mesh & 3D Reconstruction Module” for optional 3D mapping.
- “Visualizer & Logger” blocks that provide user feedback and data logging.
8. Optionally, include external “Dependencies & Libraries” such as GTSAM, OpenCV, and others that support underlying functionalities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Sensor Input"
        C["Cameras (stereo/mono)"]:::sensor
        I["IMU"]:::sensor
    end

    C --> DP
    I --> DP

    DP["DataProvider Modules"]:::dataprovider

    DP --> FP
    DP --> IF

    subgraph "Frontend Processing"
        FP1["Feature Detection & Optical Flow"]:::frontend
        FP2["Vision-IMU Frontend"]:::frontend
        FP3["Tracker & Undistorter"]:::frontend
        FP --> FP1
        FP --> FP2
        FP --> FP3
    end

    IF["IMU Frontend"]:::imu

    FP1 --> PIPELINE["Pipeline Synchronization"]:::pipeline
    FP2 --> PIPELINE
    FP3 --> PIPELINE
    IF  --> PIPELINE

    PIPELINE --> BE["Regular VIO Backend"]:::backend
    BE --> LC["Loop Closure Detector"]:::backend

    BE --> MESH["Mesh & 3D Reconstruction"]:::mesh
    BE --> VIS["Visualization & Logging"]:::visualization

    INIT["Initialization & Calibration"]:::initial

    CONFIG["Configuration (YAML/gflags)"]:::config
    CONFIG --- DP
    CONFIG --- FP1
    CONFIG --- IF
    CONFIG --- PIPELINE
    CONFIG --- BE
    CONFIG --- INIT

    click DP "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/dataprovider"
    click FP1 "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/frontend/feature-detector"
    click FP2 "https://github.com/mit-spark/kimera-vio/blob/master/include/kimera-vio/frontend/MonoVisionImuFrontend.h"
    click FP3 "https://github.com/mit-spark/kimera-vio/blob/master/include/kimera-vio/frontend/Tracker.h"
    click IF "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/imu-frontend"
    click PIPELINE "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/pipeline"
    click BE "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/backend"
    click LC "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/loopclosure"
    click INIT "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/initial"
    click MESH "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/mesh"
    click VIS "https://github.com/mit-spark/kimera-vio/tree/master/include/kimera-vio/visualizer"
    click CONFIG "https://github.com/mit-spark/kimera-vio/tree/master/params"

    classDef sensor fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef dataprovider fill:#ccf2ff,stroke:#333,stroke-width:2px;
    classDef frontend fill:#cce6ff,stroke:#333,stroke-width:2px;
    classDef imu fill:#cdf0ea,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#e6ccb2,stroke:#333,stroke-width:2px;
    classDef backend fill:#ffd1d1,stroke:#333,stroke-width:2px;
    classDef mesh fill:#d1ffd1,stroke:#333,stroke-width:2px;
    classDef visualization fill:#fff1b6,stroke:#333,stroke-width:2px;
    classDef initial fill:#e8d0ff,stroke:#333,stroke-width:2px;
    classDef config fill:#ecd9ff,stroke:#333,stroke-width:2px;
```
