# ctlab-itmo/livboc architecture

> Architecture diagram of the GitHub repository ctlab-itmo/livboc, 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/ctlab-itmo/livboc
- Repository: https://github.com/ctlab-itmo/livboc

## Overview

LIVBOC converts raster images into layered SVG artwork: contour extraction and color selection initialize vector shapes, which are optimized against the target and saved as SVG. `main.py` is the experiment entry point; `classes.py`, `functions.py`, and `utils.py` support the optimization workflow. DiffVG supplies differentiable rendering and SVG handling through its PyTorch interface and native renderer. The documented stages are clear, but unsampled LIVBOC implementation details limit attribution of some individual steps.

Main entry points: [`LIVBOC/main.py`](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/main.py) (Experiment runner), [`DiffVG/diffvg.cpp`](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/diffvg.cpp) (Differentiable renderer), [`DiffVG/pydiffvg/optimize_svg.py`](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/optimize_svg.py) (SVG optimizer), [`DiffVG/pydiffvg/render_pytorch.py`](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/render_pytorch.py) (PyTorch render interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Vectorization workflow"]
  node_runner["Experiment runner<br/>[main.py]"]
  node_contours["Contour extraction<br/>[functions.py]"]
  node_color_selection["Color selection<br/>[functions.py]"]
  node_shape_setup["Shape initialization<br/>[classes.py]"]
  node_workflow_utils["Workflow utilities<br/>[utils.py]"]
end

subgraph group_optimization["Optimization"]
  node_shape_alignment["Shape alignment<br/>[main.py]"]
  node_losses["Image and smoothness losses<br/>[smoothness_loss.py]"]
  node_svg_optimizer["SVG optimizer<br/>[optimize_svg.py]"]
end

subgraph group_diffvg["DiffVG rendering"]
  node_pytorch_renderer["PyTorch render interface<br/>[render_pytorch.py]"]
  node_native_renderer["Differentiable renderer<br/>[diffvg.cpp]"]
  node_scene["Scene and shapes<br/>[scene.h]"]
  node_geometry["Geometry and distance<br/>[compute_distance.h]"]
  node_render_support["Render support"]
end

subgraph group_formats["SVG and image I/O"]
  node_svg_parser["SVG parsing<br/>[parse_svg.py]"]
  node_svg_writer["SVG saving<br/>[save_svg.py]"]
end

node_user(("Experiment user"))
node_raster["Raster target"]
node_svg_result["SVG result"]

node_user -->|"configures run"| node_runner
node_raster -->|"provides target"| node_runner
node_runner -->|"extracts contours"| node_contours
node_runner -->|"selects colors"| node_color_selection
node_runner -.->|"initializes vectors"| node_shape_setup
node_runner -->|"uses utilities"| node_workflow_utils
node_runner -->|"optimizes vectors"| node_shape_alignment
node_runner -->|"computes losses"| node_losses
node_runner -->|"renders scene"| node_pytorch_renderer
node_shape_alignment -.->|"optimizes SVG"| node_svg_optimizer
node_pytorch_renderer -.->|"invokes renderer"| node_native_renderer
node_native_renderer -->|"uses scene data"| node_scene
node_native_renderer -->|"computes distances"| node_geometry
node_native_renderer -->|"uses support"| node_render_support
node_svg_parser -.->|"builds scenes"| node_scene
node_runner -->|"saves initialization"| node_svg_writer
node_runner -->|"exports artwork"| node_svg_result
node_svg_optimizer -.->|"writes optimized SVG"| node_svg_result

click node_runner "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/main.py"
click node_contours "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/functions.py"
click node_color_selection "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/functions.py"
click node_shape_setup "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/classes.py"
click node_workflow_utils "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/utils.py"
click node_shape_alignment "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/main.py"
click node_losses "https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/smoothness_loss.py"
click node_svg_optimizer "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/optimize_svg.py"
click node_pytorch_renderer "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/render_pytorch.py"
click node_native_renderer "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/diffvg.cpp"
click node_scene "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/scene.h"
click node_geometry "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/compute_distance.h"
click node_render_support "https://github.com/ctlab-itmo/livboc/tree/main/DiffVG"
click node_svg_parser "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/parse_svg.py"
click node_svg_writer "https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/save_svg.py"

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_runner,node_contours,node_color_selection,node_shape_setup,node_workflow_utils,node_user toneBlue
class node_shape_alignment,node_losses,node_svg_optimizer toneAmber
class node_pytorch_renderer,node_native_renderer,node_scene,node_geometry,node_render_support toneMint
class node_svg_parser,node_svg_writer toneRose
class node_raster,node_svg_result toneIndigo
```

## Components

### Vectorization workflow

- [Experiment runner](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/main.py): `LIVBOC/main.py`
- [Contour extraction](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/functions.py): `LIVBOC/functions.py`
- [Color selection](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/functions.py): `LIVBOC/functions.py`
- [Shape initialization](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/classes.py): `LIVBOC/classes.py`
- [Workflow utilities](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/utils.py): `LIVBOC/utils.py`

### Optimization

- [Shape alignment](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/main.py): `LIVBOC/main.py`
- [Image and smoothness losses](https://github.com/ctlab-itmo/livboc/blob/main/LIVBOC/smoothness_loss.py): `LIVBOC/smoothness_loss.py`
- [SVG optimizer](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/optimize_svg.py): `DiffVG/pydiffvg/optimize_svg.py`

### DiffVG rendering

- [PyTorch render interface](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/render_pytorch.py): `DiffVG/pydiffvg/render_pytorch.py`
- [Differentiable renderer](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/diffvg.cpp): `DiffVG/diffvg.cpp`
- [Scene and shapes](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/scene.h): `DiffVG/scene.h`
- [Geometry and distance](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/compute_distance.h): `DiffVG/compute_distance.h`
- [Render support](https://github.com/ctlab-itmo/livboc/tree/main/DiffVG): `DiffVG`

### SVG and image I/O

- [SVG parsing](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/parse_svg.py): `DiffVG/pydiffvg/parse_svg.py`
- [SVG saving](https://github.com/ctlab-itmo/livboc/blob/main/DiffVG/pydiffvg/save_svg.py): `DiffVG/pydiffvg/save_svg.py`

### Other components

- **Experiment user**
- **Raster target**
- **SVG result**

## Connections

- Experiment user → Experiment runner: configures run (evidence: `README.md`)
- Raster target → Experiment runner: provides target (evidence: `README.md`)
- Experiment runner → Contour extraction: extracts contours (evidence: `README.md`)
- Experiment runner → Color selection: selects colors (evidence: `README.md`)
- Experiment runner → Shape initialization: initializes vectors (evidence: `LIVBOC/main.py`)
- Experiment runner → Workflow utilities: uses utilities (evidence: `LIVBOC/main.py`)
- Experiment runner → Shape alignment: optimizes vectors (evidence: `README.md`)
- Experiment runner → Image and smoothness losses: computes losses (evidence: `LIVBOC/main.py`)
- Experiment runner → PyTorch render interface: renders scene (evidence: `LIVBOC/main.py`)
- Shape alignment → SVG optimizer: optimizes SVG
- PyTorch render interface → Differentiable renderer: invokes renderer
- Differentiable renderer → Scene and shapes: uses scene data (evidence: `DiffVG/diffvg.cpp`)
- Differentiable renderer → Geometry and distance: computes distances (evidence: `DiffVG/diffvg.cpp`)
- Differentiable renderer → Render support: uses support (evidence: `DiffVG/diffvg.cpp`)
- SVG parsing → Scene and shapes: builds scenes
- Experiment runner → SVG saving: saves initialization (evidence: `LIVBOC/main.py`)
- Experiment runner → SVG result: exports artwork (evidence: `README.md`)
- SVG optimizer → SVG result: writes optimized SVG
