# uditsinghparihar/g2o_tutorial architecture

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

- Interactive diagram: https://gitdiagram.com/uditsinghparihar/g2o_tutorial
- Repository: https://github.com/uditsinghparihar/g2o_tutorial

## Overview

##### Project type and purpose
- This is a tutorial codebase (“g2o_tutorial”) demonstrating graph-based SLAM formulations in Python. It covers two SLAM scenarios: Pose Graph SLAM (pgSlam) and Landmark SLAM (landmarkSlam).

##### File structure
- Top level:
- README.md, .gitignore
- pgSlam/ (Pose Graph SLAM module)
- landmarkSlam/ (Landmark SLAM module)
- Each module contains:
- A Python script (pgSlam.py or landmarkSlam.py) – end-to-end pipeline
- A Jupyter notebook (.ipynb) – stepwise, interactive version
- g2o files (noise.g2o, opt.g2o) – input to, and output from, the optimizer
- results/ folder – PNGs illustrating intermediate and final outputs

##### Key technical stack (from README)
- g2o (graph optimizer) – installed via binaries or built from source
- Python libraries: numpy, scipy, open3d, matplotlib, math

##### Main components
A. Data Generation
- Synthetic trajectory or cube+poses generator
- Outputs: raw odometry & landmark measurements
B. g2o File Writer
- Translates measurements into g2o format (.g2o files)
- noise.g2o (pre-optimization), opt.g2o (for results)
C. Graph Optimizer (g2o engine)
- Takes noise.g2o, runs optimization (EDGE_SE2 / EDGE_SE3, VERTEX_SE2 / VERTEX_SE3)
- Produces optimized graph (opt.g2o)
D. Result Parser & Visualizer
- Reads .g2o outputs
- Plots trajectories and landmark positions (matplotlib / open3d)
E. Notebooks (pgSlam.ipynb & landmarkSlam.ipynb)
- Interactive layer illustrating each sub-step, function by function
- Used for teaching and deeper inspection

##### Relationships & data flow
- Start → Data Generator → g2o File Writer → g2o Optimizer → Result Parser → Plotter
- Notebooks wrap this pipeline, calling the same underlying functions but in interactive order
- Two parallel pipelines (pgSlam vs. landmarkSlam), sharing almost identical flow but different measurement types

##### Architectural patterns & design principles
- Pipeline pattern: clear, linear data transformation stages
- Separation of concerns: generation, file generation, optimization engine, and visualization are decoupled
- Reusability: core functions in .py scripts are imported by notebooks

- Blue for data sources & generation
- Green for file I/O (g2o writer / parser)
- Orange for optimization engine
- Purple for visualization & notebooks

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Pose Graph SLAM Pipeline"
        direction TB
        PG_Data["Data Generation\n(Python: numpy, scipy)\npgSlam/pgSlam.py"]:::blue
        PG_Write["g2o File Writer\nnoise.g2o"]:::green
        PG_Optimize["Graph Optimizer\n(g2o C++ engine)"]:::orange
        PG_WriteOpt["Optimized g2o Output\nopt.g2o"]:::green
        PG_Visual["Result Parser & Visualizer\n(matplotlib/open3d)\npgSlam/results/"]:::purple

        PG_Data --> PG_Write
        PG_Write -->|"noise.g2o"| PG_Optimize
        PG_Optimize -->|"opt.g2o"| PG_WriteOpt
        PG_WriteOpt --> PG_Visual
    end

    subgraph "Landmark SLAM Pipeline"
        direction TB
        LM_Data["Data & Landmark Generation\n(Python: numpy, scipy)\nlandmarkSlam/landmarkSlam.py"]:::blue
        LM_Write["g2o File Writer\nnoise.g2o"]:::green
        LM_Optimize["Graph Optimizer\n(g2o C++ engine)"]:::orange
        LM_WriteOpt["Optimized g2o Output\nopt.g2o"]:::green
        LM_Visual["Result Parser & Visualizer\n(matplotlib/open3d)\nlandmarkSlam/results/"]:::purple

        LM_Data --> LM_Write
        LM_Write -->|"noise.g2o"| LM_Optimize
        LM_Optimize -->|"opt.g2o"| LM_WriteOpt
        LM_WriteOpt --> LM_Visual
    end

    subgraph "Notebooks (Interactive)"
        direction TB
        NB_PG["pgSlam.ipynb\n(wraps pipeline functions)"]:::purple
        NB_LM["landmarkSlam.ipynb\n(wraps pipeline functions)"]:::purple

        NB_PG --- PG_Data
        NB_PG --- PG_Write
        NB_PG --- PG_Optimize
        NB_PG --- PG_Visual

        NB_LM --- LM_Data
        NB_LM --- LM_Write
        NB_LM --- LM_Optimize
        NB_LM --- LM_Visual
    end

    classDef blue fill:#0000ff,stroke:#000,color:#fff;
    classDef green fill:#00ff00,stroke:#000,color:#000;
    classDef orange fill:#ffa500,stroke:#000,color:#000;
    classDef purple fill:#800080,stroke:#000,color:#fff;

    click PG_Data "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/pgSlam/pgSlam.py"
    click PG_Write "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/pgSlam/noise.g2o"
    click PG_WriteOpt "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/pgSlam/opt.g2o"
    click PG_Visual "https://github.com/uditsinghparihar/g2o_tutorial/tree/master/pgSlam/results/"
    click NB_PG "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/pgSlam/pgSlam.ipynb"

    click LM_Data "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/landmarkSlam/landmarkSlam.py"
    click LM_Write "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/landmarkSlam/noise.g2o"
    click LM_WriteOpt "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/landmarkSlam/opt.g2o"
    click LM_Visual "https://github.com/uditsinghparihar/g2o_tutorial/tree/master/landmarkSlam/results/"
    click NB_LM "https://github.com/uditsinghparihar/g2o_tutorial/blob/master/landmarkSlam/landmarkSlam.ipynb"
```
