# mavis-slam/openmavis architecture

> Architecture diagram of the GitHub repository mavis-slam/openmavis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mavis-slam/openmavis
- Repository: https://github.com/mavis-slam/openmavis

## Overview

##### Project type and purpose
- Type: Native C++ library + command-line and ROS executables for Visual-Inertial SLAM.

##### Major subsystems (to represent as top-level “blocks”)
A. Input / Data Acquisition
- Sensor Drivers & Readers
- Examples folder contains demo executables for Monocular, Stereo, RGB-D, Multi-Inertial, etc.
- ROS nodes (optional) under Examples/ROS.
- Preprocessor
- Image rectification (online/offline), timestamp alignment (evaluation scripts).
- IMU pre-integration module (`include/ImuTypes`, `src/ImuTypes.cc`).

B. Front-End Tracking
- Feature Extraction: ORBextractor (`include/ORBextractor`, `src/ORBextractor.cc`).
- Feature Matching: ORBmatcher (`include/ORBmatcher`, `src/ORBmatcher.cc`).
- Pose Estimation & Frame Integration: `src/Tracking.cc`, handles multi-camera pose via geometric camera models (`include/CameraModels/…`).

C. Map Management
- Points (`include/MapPoint`, `src/MapPoint.cc`), KeyFrames (`include/KeyFrame`, `src/KeyFrame.cc`), Map database (`include/KeyFrameDatabase`, `src/KeyFrameDatabase.cc`).
- Local Mapping thread (`include/LocalMapping`, `src/LocalMapping.cc`).
- Loop Closing thread (`include/LoopClosing`, `src/LoopClosing.cc`).

D. Back-End Optimization
- IMU pre-integration & optimization (SE2(3) formulation).
- Graph optimization using modified g2o (`Thirdparty/g2o`).
- Pose graph solver (`include/Optimizer`, `src/Optimizer.cc`).
- Sim3 solver for scale loop closure (`include/Sim3Solver`, `src/Sim3Solver.cc`).

E. Database & Place Recognition
- Vocabulary & Bag-of-Words (`Vocabulary/ORBvoc.txt`, Thirdparty/DBoW2).
- Enables relocalization and loop detection.

F. Visualization & Output
- Pangolin-based viewer (`include/Viewer`, `src/Viewer.cc`).
- FrameDrawer, MapDrawer (`include/FrameDrawer`, `include/MapDrawer`).
- Trajectory output and evaluation scripts (`evaluation/`).

G. Configuration & Build
- CMakeLists.txt, build scripts (`build.sh`, `build_ros.sh`).
- Settings files (`*.yaml` in Examples/**).

##### Interactions and data flow
1) **Sensors → Preprocessor**
- Images + IMU → camera model rectification, timestamp sync.
2) **Preprocessor → Front-End**
- Undistorted images fed to ORB feature extractor.
- IMU measurements passed to IMU pre-integration.
3) **Front-End ↔ Map Database**
- Tracks features → proposes new KeyFrames → stores in Map.
4) **Front-End → Back-End**
- Feeds KeyFrames & IMU factors to optimizer.
5) **Back-End → Map Database**
- Adjusts poses & map points (global BA, loop closure).
6) **Map Database → Visualization**
- Updated map & camera poses rendered.
7) **Database → Place Recognition**
- Loop detection queries Bag-of-Words database.
8) **Optional ROS Interface**
- Wrap the above as ROS nodes → topics/services.

##### Architectural patterns & design principles
- **Modular threads**: tracking, local mapping, loop closing, optimization, rendering run in parallel.
- **Front-End / Back-End decoupling**: real-time tracking vs. batch graph optimization.
- **Plug-in sensors**: easily swap Monocular / Stereo / RGB-D / Multi-camera modules by selecting the proper Example executable and YAML.
- **Third-party isolation**: DBoW2, g2o, Eigen, Pangolin, OpenCV are isolated in `Thirdparty` or via CMake.

##### Be as detailed as necessary
- Threads or modules (Tracking, LocalMapping, LoopClosing, Viewer).
- Configuration files (.yaml) feeding into examples.
- Essential architectural elements—don’t worry about minor utility classes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input / Data Acquisition
    subgraph "Input / Data Acquisition"
        direction TB
        CAM["Camera Array"]:::external
        IMU["IMU"]:::external
        Examples["Examples Executables"]:::acq
        Pre["Preprocessor\n(Image Rectification,\nTimestamp Sync)"]:::acq
    end

    %% Front-End Tracking
    subgraph "Front-End Tracking"
        direction TB
        FE["Feature Extraction\nORBextractor"]:::frontend
        FM["Feature Matching\nORBmatcher"]:::frontend
        TR["Pose Estimation\nTracking"]:::frontend
    end

    %% Map Management
    subgraph "Map Management"
        direction TB
        MP["Map Points"]:::storage
        KF["KeyFrames"]:::storage
        DB["KeyFrame Database"]:::storage
        LM["Local Mapping\nThread"]:::storage
        LC["Loop Closing\nThread"]:::storage
    end

    %% Back-End Optimization
    subgraph "Back-End Optimization"
        direction TB
        G2O["g2o Graph Optimizer"]:::thirdparty
        OPT["Optimizer"]:::backend
        SIM3["Sim3Solver"]:::backend
    end

    %% Database & Place Recognition
    subgraph "Database & Place Recognition"
        direction TB
        VOC["Vocabulary\nORBvoc.txt"]:::storage
        DBoW2["DBoW2 Library"]:::thirdparty
    end

    %% Visualization & Output
    subgraph "Visualization & Output"
        direction TB
        VW["Viewer"]:::vis
        FD["FrameDrawer"]:::vis
        MD["MapDrawer"]:::vis
        EVAL["Evaluation Scripts"]:::vis
    end

    %% Configuration & Build
    subgraph "Configuration & Build"
        direction TB
        CMAKE["CMakeLists.txt"]:::config
        BS["build.sh\nbuild_ros.sh"]:::config
        CFG["YAML Config Files"]:::config
    end

    %% Data Flows
    CAM -->|images| Pre
    IMU -->|IMU data| Pre
    Examples --> CAM
    Examples --> IMU
    Pre -->|undistorted images| FE
    Pre -->|pre-integrated IMU| TR

    FE -->|features| TR
    TR -->|keyframes & map points| MP
    TR -->|keyframes & map points| KF
    MP --> DB
    KF --> DB
    DB --> LM
    DB --> LC
    TR -->|factors| OPT
    OPT -->|optimized poses| DB
    G2O --> OPT
    SIM3 --> OPT

    DB -->|loop queries| DBoW2
    DBoW2 --> VOC

    DB -->|map & poses| VW
    VW --> FD
    VW --> MD
    DB --> EVAL

    CFG --> Examples
    CMAKE --> CFG
    BS --> CMAKE

    %% Click Events
    click Examples "https://github.com/mavis-slam/openmavis/tree/master/Examples/"
    click Pre "https://github.com/mavis-slam/openmavis/blob/master/include/ImuTypes.h"
    click Pre "https://github.com/mavis-slam/openmavis/blob/master/src/ImuTypes.cc"
    click FE "https://github.com/mavis-slam/openmavis/blob/master/include/ORBextractor.h"
    click FE "https://github.com/mavis-slam/openmavis/blob/master/src/ORBextractor.cc"
    click FM "https://github.com/mavis-slam/openmavis/blob/master/include/ORBmatcher.h"
    click FM "https://github.com/mavis-slam/openmavis/blob/master/src/ORBmatcher.cc"
    click TR "https://github.com/mavis-slam/openmavis/blob/master/src/Tracking.cc"
    click TR "https://github.com/mavis-slam/openmavis/blob/master/include/Tracking.h"
    click TR "https://github.com/mavis-slam/openmavis/tree/master/include/CameraModels/"
    click TR "https://github.com/mavis-slam/openmavis/tree/master/src/CameraModels/"
    click MP "https://github.com/mavis-slam/openmavis/blob/master/include/MapPoint.h"
    click MP "https://github.com/mavis-slam/openmavis/blob/master/src/MapPoint.cc"
    click KF "https://github.com/mavis-slam/openmavis/blob/master/include/KeyFrame.h"
    click KF "https://github.com/mavis-slam/openmavis/blob/master/src/KeyFrame.cc"
    click DB "https://github.com/mavis-slam/openmavis/blob/master/include/KeyFrameDatabase.h"
    click DB "https://github.com/mavis-slam/openmavis/blob/master/src/KeyFrameDatabase.cc"
    click LM "https://github.com/mavis-slam/openmavis/blob/master/include/LocalMapping.h"
    click LM "https://github.com/mavis-slam/openmavis/blob/master/src/LocalMapping.cc"
    click LC "https://github.com/mavis-slam/openmavis/blob/master/include/LoopClosing.h"
    click LC "https://github.com/mavis-slam/openmavis/blob/master/src/LoopClosing.cc"
    click G2O "https://github.com/mavis-slam/openmavis/tree/master/Thirdparty/g2o/"
    click OPT "https://github.com/mavis-slam/openmavis/blob/master/include/Optimizer.h"
    click OPT "https://github.com/mavis-slam/openmavis/blob/master/src/Optimizer.cc"
    click SIM3 "https://github.com/mavis-slam/openmavis/blob/master/include/Sim3Solver.h"
    click SIM3 "https://github.com/mavis-slam/openmavis/blob/master/src/Sim3Solver.cc"
    click VOC "https://github.com/mavis-slam/openmavis/blob/master/Vocabulary/ORBvoc.txt.tar.gz"
    click VOC "https://github.com/mavis-slam/openmavis/blob/master/include/ORBVocabulary.h"
    click DBoW2 "https://github.com/mavis-slam/openmavis/tree/master/Thirdparty/DBoW2/"
    click VW "https://github.com/mavis-slam/openmavis/blob/master/include/Viewer.h"
    click VW "https://github.com/mavis-slam/openmavis/blob/master/src/Viewer.cc"
    click FD "https://github.com/mavis-slam/openmavis/blob/master/include/FrameDrawer.h"
    click FD "https://github.com/mavis-slam/openmavis/blob/master/src/FrameDrawer.cc"
    click MD "https://github.com/mavis-slam/openmavis/blob/master/include/MapDrawer.h"
    click MD "https://github.com/mavis-slam/openmavis/blob/master/src/MapDrawer.cc"
    click EVAL "https://github.com/mavis-slam/openmavis/tree/master/evaluation/"
    click CMAKE "https://github.com/mavis-slam/openmavis/blob/master/CMakeLists.txt"
    click BS "https://github.com/mavis-slam/openmavis/blob/master/build.sh"
    click BS "https://github.com/mavis-slam/openmavis/blob/master/build_ros.sh"
    click CFG "https://github.com/mavis-slam/openmavis/blob/master/Examples/Monocular-Inertial/EuRoC.yaml"

    %% Styles
    classDef acq fill:#cbeafe,stroke:#1f78b4,stroke-width:2px
    classDef frontend fill:#dafbe1,stroke:#33a02c,stroke-width:2px
    classDef storage fill:#f4e1ff,stroke:#6a0dad,stroke-width:2px
    classDef backend fill:#ffe5b4,stroke:#ff7f00,stroke-width:2px
    classDef thirdparty fill:#e0e0e0,stroke:#7f7f7f,stroke-width:2px
    classDef vis fill:#ffe4e1,stroke:#d62728,stroke-width:2px
    classDef config fill:#f0f0f0,stroke:#555555,stroke-width:2px
    classDef external fill:#e0f7fa,stroke:#00796b,stroke-width:2px,stroke-dasharray: 5 5
```
