# mr-mod/yaslicer architecture

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

- Interactive diagram: https://gitdiagram.com/mr-mod/yaslicer
- Repository: https://github.com/mr-mod/yaslicer

## Overview

##### Project type and purpose
- YaSlicer is a native C++ command-line tool (“Yet Another Slicer”) that generates 2D image slices (PNG) of 3D STL models for DLP/SLA 3D printers.
- It consists of a reusable “Common” static-library module plus a “Slicer” executable that implements GPU-accelerated rendering and multicore optimizations.

##### File structure
- Top-level directories:
- Common/ – cross-platform utilities, math, file I/O, image writing, rasterization and performance timers.
- Slicer/ – application code (main, CLI parsing, platform-specific GL context, renderer, shaders, job export).
- Solution & build scripts: Tools.sln, make.sh, .vcxproj files for Visual Studio, vcpkg integration.
- Platform abstraction: GlContext*.cpp/h for ANGLE (Windows), D3D9/11, Raspberry Pi, X11.
- Dependencies: Boost (CLI args, threading), glm (math), glew (GL loader), libpng (image output), ANGLE (D3D-backed GL).

##### Extract README insights
- Core features: fast slicing, large STL support, antialiasing toggle, printer profiles, simulation mode, PNG output, low dependency count.
- Requirements: Windows 64-bit, D3D9/11 drivers, Visual Studio 2017 + vcpkg.
- Usage: slicer.exe CLI → produces PNG slices and optional job files.

##### Main components & interactions
a. Components:
1. CLI Frontend – parses arguments, loads STL.
2. Model Loader (Common/Loaders) – reads binary STL into mesh data.
3. Geometry & Cache (Common/Geometry, Common/CacheOpt) – builds slice geometry, optimizes reuse.
5. GL Context Layer (Slicer/GlContext*) – abstracts platform-specific OpenGL/D3D initialization.
6. Shader Pipeline (Slicer/Shaders.h) – GPU programs for slicing and antialiasing.
7. Image Writer (Common/PngFile) – handles PNG output.
8. Job Exporter (Slicer/Utils) – optional Envisiontech job file generator.
9. Performance & Logging (Common/PerfTimer, Common/ErrorHandling).
10. External Dependencies – Boost, glm, glew, ANGLE, libpng.

b. Relationships & Data Flow:
- CLI Frontend → invokes Model Loader → mesh → Geometry & Cache → Renderer Core → submits to GL Context → Shader Pipeline → framebuffer → Image Writer → disk.
- Job Exporter listens to slice events to create job files.
- PerfTimer wrappers around heavy operations (load, render, write).
- ErrorHandling sits at subsystem boundaries.

c. Architectural patterns & principles:
- Layered architecture: Core logic depends on Common utilities; Slicer application sits above Common.
- Abstract factory / strategy for GL contexts (platform-specific implementations behind a common interface).
- Single responsibility in modules: loading, geometry, rendering, output.

d. Key technologies & libraries:
- C++17 (or C++14), Boost threads/CLI, glm for vector/math, OpenGL (via ANGLE/D3D), glew for GL extension loading, libpng for output.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Slicer Application Layer
    subgraph "Slicer Application"
        SF["CLI Frontend"]:::cli
        SF -->|parsesArgsAndLoadSTL| ML
        SF -->|invokeRenderer| RC
        subgraph "GL Context Layer"
            GCI["IGlContext"]:::api
            ANGLEImpl["GlContextANGLE"]:::platform
            RPIImpl["GlContextRPi"]:::platform
            X11Impl["GlContextX"]:::platform
            GCI --> ANGLEImpl
            GCI --> RPIImpl
            GCI --> X11Impl
        end
        RC["Renderer Core"]:::core
        RC -->|usesContext| GCI
        RC --> JE
        SP["Shader Pipeline"]:::core
        GCI -->|initContext| SP
        SP --> FB["Framebuffer"]
        FB --> IW
        JE["Job Exporter"]:::core
    end

    %% Common Library Layer
    subgraph "Common Library"
        ML["Model Loader"]:::core
        GC["Geometry & Cache"]:::core
        RAS["Rasterization Module"]:::core
        IW["Image Writer"]:::core
        PT["PerfTimer"]:::aux
        EH["ErrorHandling"]:::aux

        ML -->|loadMesh| GC
        GC -->|buildSlices| RAS
        RAS -->|sliceData| RC
        ML --> PT
        GC --> PT
        RAS --> PT
        IW --> PT
        ML --> EH
        GC --> EH
        RAS --> EH
        RC --> EH
    end

    %% External Dependencies
    subgraph "External Dependencies"
        BZ["Boost"]:::external
        GLM["glm"]:::external
        GLEW["glew"]:::external
        ANGLED["ANGLE"]:::external
        LIBPNG["libpng"]:::external
    end

    %% Dependency Links
    ML --> BZ
    GC --> GLM
    RC --> GLEW
    SP --> ANGLED
    IW --> LIBPNG

    %% Click Events
    click SF "https://github.com/mr-mod/yaslicer/blob/master/Slicer/Slicer.cpp"
    click ML "https://github.com/mr-mod/yaslicer/blob/master/Common/Loaders.cpp"
    click ML "https://github.com/mr-mod/yaslicer/blob/master/Common/Loaders.h"
    click GC "https://github.com/mr-mod/yaslicer/blob/master/Common/Geometry.cpp"
    click GC "https://github.com/mr-mod/yaslicer/blob/master/Common/Geometry.h"
    click GC "https://github.com/mr-mod/yaslicer/blob/master/Common/CacheOpt.cpp"
    click GC "https://github.com/mr-mod/yaslicer/blob/master/Common/CacheOpt.h"
    click RAS "https://github.com/mr-mod/yaslicer/blob/master/Common/Raster.cpp"
    click RAS "https://github.com/mr-mod/yaslicer/blob/master/Common/Raster.h"
    click RC "https://github.com/mr-mod/yaslicer/blob/master/Slicer/Renderer.cpp"
    click RC "https://github.com/mr-mod/yaslicer/blob/master/Slicer/Renderer.h"
    click GCI "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContext.h"
    click GCI "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContext.cpp"
    click ANGLEImpl "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContextANGLE.h"
    click ANGLEImpl "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContextANGLE.cpp"
    click RPIImpl "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContextRPi.h"
    click RPIImpl "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContextRPi.cpp"
    click X11Impl "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContextX.h"
    click X11Impl "https://github.com/mr-mod/yaslicer/blob/master/Slicer/GlContextX.cpp"
    click SP "https://github.com/mr-mod/yaslicer/blob/master/Slicer/Shaders.h"
    click IW "https://github.com/mr-mod/yaslicer/blob/master/Common/PngFile.cpp"
    click IW "https://github.com/mr-mod/yaslicer/blob/master/Common/PngFile.h"
    click JE "https://github.com/mr-mod/yaslicer/blob/master/Slicer/Utils.cpp"
    click JE "https://github.com/mr-mod/yaslicer/blob/master/Slicer/Utils.h"
    click PT "https://github.com/mr-mod/yaslicer/blob/master/Common/PerfTimer.cpp"
    click PT "https://github.com/mr-mod/yaslicer/blob/master/Common/PerfTimer.h"
    click EH "https://github.com/mr-mod/yaslicer/blob/master/Common/ErrorHandling.h"

    %% Styles
    classDef core fill:#92D1C2,stroke:#333,stroke-width:1px
    classDef platform fill:#F7B267,stroke:#333,stroke-width:1px
    classDef external fill:#A8D0E6,stroke:#333,stroke-width:1px,shape:cylinder
    classDef cli fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef aux fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef api fill:#FFCB9A,stroke:#333,stroke-width:1px
```
