# nicokiaru/limeseg architecture

> Architecture diagram of the GitHub repository nicokiaru/limeseg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nicokiaru/limeseg
- Repository: https://github.com/nicokiaru/limeseg

## Overview

##### Project Type and Purpose
– LimeSeg is a monolithic Java‐based plugin for the ImageJ/Fiji platform, implementing a modular 3D image‐segmentation algorithm (“SURFace ELements”).
– It provides both a Swing/JOGL GUI and a scripting interface (Groovy macros or IJ1 scripts), calls into a core optimizer, and offloads heavy compute to CUDA kernels.

##### File‐Structure Analysis
Top‐level build & CI:
- pom.xml (Maven build)
- .travis.yml, Travis scripts (CI)
Code and resources under src/main:
– java/eu/kiaru/limeseg/LimeSeg.java (entry point)
– commands/ (controller commands invoked by UI or scripts)
– gui/ (Swing + JOGL classes for 2D/3D rendering and tables)
– cudaHelper/ (GPU wrapper classes for FloatGpuArray, IntGpuArray, JNI utilities)
– opt/ (core segmentation optimizer, curvature computation, block of dots)
– struct/ (domain model: Cell, Vector3D, MeshConstructor, Skeleton2D)
– io/ (XML/PLY import‐export)
– ij1script/ (ImageJ1 scripting bridge)
– demos/ (demo scenarios)
Resources:
– CUDA kernels (.cu/.ptx under resources/CUDAkernels)
– shader source (GLSL under resources/shader)
– script templates (Groovy/.ijm)
Tests under src/test
update/jars: vendored ImageJ and third‐party dependencies

##### Architectural Patterns & Layers
– MVC‐like separation: gui (View) ↔ commands (Controller) ↔ core & struct (Model)
– Service layer: io and ij1script expose plugin functionality
– Infrastructure layer: cudaHelper + resources for GPU acceleration, external libraries via Maven/update jars

##### Main Components & Relationships
[Host/ImageJ Platform]
- Registers LimeSeg plugin, loads GUI or scripting hooks
[Presentation Layer]
- GUI classes (JFrameLimeSeg, JOGL3DCellRenderer, JTableCellsExplorer)
- Script templates & IJ1script bridge
↕
[Controller Layer]
- commands package – each user action or script command creates/invokes a Command object
↕
[Domain/Core Layer]
- LimeSeg.java orchestrates segmentation runs
- opt package – Optimizer, CurvaturesComputer, BlockOfDots
- struct package – in‐memory data models (Cell, MeshConstructor, Vector3D, etc.)
↕
[Infrastructure Layer]
- cudaHelper – loads kernels from resources, handles GPU memory buffers
- io – XML/PLY I/O
External libs – ImageJ, JOGL, Commons‐Math, Trove, etc.

[Auxiliary]
- demos – sample scenarios that exercise the system
- Travis CI & Maven – build, test, package

##### Key Technologies to Annotate
– Java 8+, Maven, Travis CI
– JOGL for OpenGL 3D rendering
– CUDA kernels via JNI wrappers
– Swing for controls, tables
– Groovy/.ijm script templates & ImageJ1 script bridge
– XML/PLY for persistence

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers top to bottom
    subgraph "Host / Platform"
        direction TB
        Host["ImageJ / Fiji Platform"]:::external
    end

    subgraph "Presentation Layer"
        direction TB
        subgraph "GUI (Swing + JOGL)"
            direction TB
            guiPkg["gui/"]:::ui
        end
        subgraph "Script Bridge"
            direction TB
            scriptPkg["ij1script/"]:::io
        end
    end

    subgraph "Controller Layer"
        direction TB
        commandsPkg["commands/"]:::core
    end

    subgraph "Core Domain & Optimizer"
        direction TB
        entry["LimeSeg.java"]:::core
        subgraph "opt package"
            direction TB
            optPkg["opt/"]:::core
        end
        subgraph "struct package"
            direction TB
            structPkg["struct/"]:::core
        end
    end

    subgraph "Infrastructure Layer"
        direction TB
        subgraph "GPU Helpers (JNI wrappers)"
            direction TB
            cudaPkg["cudaHelper/"]:::gpu
        end
        ioPkg["io/"]:::io
        subgraph "Resources"
            direction TB
            cudaRes["resources/CUDAkernels/"]:::gpu
            shaderRes["resources/shader/"]:::gpu
            scriptRes["resources/script-templates/LimeSeg/"]:::io
        end
    end

    subgraph "External Dependencies & CI"
        direction TB
        jars["update/jars/"]:::external
        pom["pom.xml"]:::external
        travis[".travis.yml"]:::external
        testHarness["SimpleIJLaunch.java"]:::external
    end

    %% Connections
    Host -->|"registers plugin"| guiPkg
    Host -->|"registers script methods"| scriptPkg

    guiPkg -->|"triggers"| commandsPkg
    scriptPkg -->|"invokes commands"| commandsPkg

    commandsPkg -->|"orchestrates"| entry
    entry -->|"uses"| optPkg
    entry -->|"manages data models"| structPkg

    optPkg -->|"calls GPU wrappers"| cudaPkg
    optPkg -->|"reads/writes mesh"| structPkg

    structPkg -->|"persist/load"| ioPkg
    ioPkg -->|"reads/writes XML/PLY"| structPkg

    cudaPkg -->|"loads kernels"| cudaRes
    cudaPkg -->|"uses shaders"| shaderRes

    entry -->|"uses script templates"| scriptRes

    entry -->|"build/test"| pom
    entry -->|"CI pipeline"| travis
    entry -->|"test harness"| testHarness

    %% External libs
    jars --> guiPkg
    jars --> commandsPkg
    jars --> entry
    jars --> optPkg
    jars --> structPkg
    jars --> cudaPkg
    jars --> ioPkg

    %% Click Events
    click guiPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/gui/"
    click scriptPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/ij1script/"
    click commandsPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/commands/"
    click entry "https://github.com/nicokiaru/limeseg/blob/master/src/main/java/eu/kiaru/limeseg/LimeSeg.java"
    click optPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/opt/"
    click structPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/struct/"
    click cudaPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/cudaHelper/"
    click ioPkg "https://github.com/nicokiaru/limeseg/tree/master/src/main/java/eu/kiaru/limeseg/io/"
    click cudaRes "https://github.com/nicokiaru/limeseg/tree/master/src/main/resources/CUDAkernels/"
    click shaderRes "https://github.com/nicokiaru/limeseg/tree/master/src/main/resources/shader/"
    click scriptRes "https://github.com/nicokiaru/limeseg/tree/master/src/main/resources/script-templates/LimeSeg/"
    click jars "https://github.com/nicokiaru/limeseg/tree/master/update/jars/"
    click pom "https://github.com/nicokiaru/limeseg/blob/master/pom.xml"
    click travis "https://github.com/nicokiaru/limeseg/blob/master/.travis.yml"
    click testHarness "https://github.com/nicokiaru/limeseg/blob/master/src/test/java/SimpleIJLaunch.java"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef core fill:#d4edda,stroke:#333,stroke-width:1px
    classDef gpu fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef io fill:#e2d4f2,stroke:#333,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#999,stroke-width:1px,stroke-dasharray: 2 2
```
