# crrel/points2grid architecture

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

- Interactive diagram: https://gitdiagram.com/crrel/points2grid
- Repository: https://github.com/crrel/points2grid

## Overview

##### Project type and purpose
- points2grid is a command-line tool and C++ library for generating Digital Elevation Models (DEMs) from point clouds using a local gridding algorithm.
- It reads LAS or text point‐cloud files, computes elevation statistics per grid cell (bin), and writes out a raster grid, with optional null‐value filling.

##### File structure
- Top-level:
- apps/points2grid.cpp – the CLI entry point
- /points2grid/ – public headers for the core library
- src/ – implementation of core modules
- scripts/ – build and test helper scripts
- test/ – unit and integration tests
- CMakeLists.txt, INSTALL.md, .travis.yml – build & CI
- Core library modules in include/points2grid:
- Global.hpp – global configuration & constants
- GridPoint, GridMap, GridFile – in-memory grid structures & I/O
- Interpolation, CoreInterp, InCoreInterp, OutCoreInterp – algorithm implementations
- lasfile.hpp – LAS reader (self-contained)
- config.h.in, export.hpp – build/config exports
- Build & deployment: CMake-based, CI via Travis, bash wrapper in scripts.

##### README for additional insights
- Describes algorithm (bin radius, IDW, null filling)
- Mentions optional PDAL writer integration (extension point)
- Usage is purely CLI driven; no external services required.

a. Main components
- User & CLI layer (points2grid executable)
- Configuration loader (Global)
- Input module (LAS/Text reader)
- Core algorithm modules (Interpolation, CoreInterp, InCoreInterp, OutCoreInterp)
- Data models (GridPoint, GridMap)
- Output module (GridFile writer)
- Optional extension adapter (PDAL writer)
- Build/Test harness (CMake, scripts, test suite)
b. Relationships & interactions
- CLI → reads user parameters → calls Configuration loader
- CLI → invokes Input module → streams point data into memory
- CLI → passes data + config → Core algorithm modules → populate GridMap
- Core modules → optionally hand off to null‐fill routine → update GridMap
- GridMap → passed to Output module → writes DEM to disk
- Tests & scripts → call CLI and library APIs → verify correctness
c. Architectural patterns & design principles
- Modular layering: separation of CLI, config, I/O, algorithm, and data structures
- Single‐responsibility for each module (e.g., lasfile only reads, GridFile only writes)
- Clear public API surface in include/points2grid
- Build‐time configuration via CMake, header templating (config.h.in)
d. Key technologies & frameworks
- C++ (core language)
- CMake (build, configuration)
- Bash scripts (automation)
- Travis CI (.travis.yml)
- Self-contained LAS reader (no external LAS dependency)
- Optional PDAL integration point

##### Detail without overcomplicating
- How build scripts and CMake generate the config headers used at compile time
- A small inset illustrating the null‐filling window sizes (3×3,5×5,7×7) as part of the algorithm block

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI[/ "points2grid executable" \/]:::cli
    end

    %% Configuration Layer
    subgraph "Configuration"
        Global["Global (Config loader)"]:::config
    end

    %% I/O Layer
    subgraph "I/O Modules"
        LAS["lasfile.hpp (LAS/Text reader)"]:::io
    end

    %% Algorithm Layer
    subgraph "Algorithm Modules"
        InterpBase["Interpolation (Base)"]:::algo
        CoreInterp["CoreInterp (Interface)"]:::algo
        InCore["InCoreInterp"]:::algo
        OutCore["OutCoreInterp"]:::algo
        NullFill["Null-Filling (3×3,5×5,7×7)"]:::algo
    end

    %% Data Model Layer
    subgraph "Data Models"
        GridPt["GridPoint"]:::data
        GridMap["GridMap"]:::data
    end

    %% Output Layer
    subgraph "Output"
        GridFile["GridFile (Writer)"]:::io
        PDAL["PDAL Writer Adapter (optional)"]:::io
    end

    %% Build/Test Infrastructure
    subgraph "Build & Test"
        CMake["CMakeLists.txt"]:::infra
        ConfigH["config.h.in"]:::infra
        ExportH["export.hpp"]:::infra
        Scripts["build_and_test.sh"]:::infra
        Travis[".travis.yml"]:::infra
        Tests["test/ (unit & integration)"]:::infra
    end

    %% Data Flow
    CLI -->|"params"| Global
    CLI -->|"point stream"| LAS
    Global -->|"radius parameter"| InterpBase
    LAS -->|"raw points"| InCore
    LAS -->|"raw points"| OutCore
    InterpBase --> CoreInterp
    CoreInterp --> InCore
    CoreInterp --> OutCore
    InCore --> NullFill
    OutCore --> NullFill
    NullFill --> GridMap
    GridMap -->|"grid matrix"| GridFile
    GridFile -->|"DEM output"| PDAL

    %% Tests & Build
    Scripts --> CMake
    CMake --> ConfigH
    CMake --> ExportH
    Scripts --> Tests
    Travis --> Scripts
    Tests --> CLI
    Tests -->|"APIs"| InterpBase
    Tests --> GridMap

    %% Click Events
    click CLI "https://github.com/crrel/points2grid/blob/master/apps/points2grid.cpp"
    click Global "https://github.com/crrel/points2grid/blob/master/include/points2grid/Global.hpp"
    click LAS "https://github.com/crrel/points2grid/blob/master/include/points2grid/lasfile.hpp"
    click InterpBase "https://github.com/crrel/points2grid/blob/master/include/points2grid/Interpolation.hpp"
    click InterpBase "https://github.com/crrel/points2grid/blob/master/_src/Interpolation.cpp"
    click InCore "https://github.com/crrel/points2grid/blob/master/include/points2grid/InCoreInterp.hpp"
    click InCore "https://github.com/crrel/points2grid/blob/master/src/InCoreInterp.cpp"
    click OutCore "https://github.com/crrel/points2grid/blob/master/include/points2grid/OutCoreInterp.hpp"
    click OutCore "https://github.com/crrel/points2grid/blob/master/src/OutCoreInterp.cpp"
    click CoreInterp "https://github.com/crrel/points2grid/blob/master/include/points2grid/CoreInterp.hpp"
    click GridPt "https://github.com/crrel/points2grid/blob/master/include/points2grid/GridPoint.hpp"
    click GridMap "https://github.com/crrel/points2grid/blob/master/include/points2grid/GridMap.hpp"
    click GridMap "https://github.com/crrel/points2grid/blob/master/src/GridMap.cpp"
    click GridFile "https://github.com/crrel/points2grid/blob/master/include/points2grid/GridFile.hpp"
    click GridFile "https://github.com/crrel/points2grid/blob/master/src/GridFile.cpp"
    click CMake "https://github.com/crrel/points2grid/blob/master/CMakeLists.txt"
    click ConfigH "https://github.com/crrel/points2grid/blob/master/include/points2grid/config.h.in"
    click ExportH "https://github.com/crrel/points2grid/blob/master/include/points2grid/export.hpp"
    click Scripts "https://github.com/crrel/points2grid/blob/master/scripts/build_and_test.sh"
    click Travis "https://github.com/crrel/points2grid/blob/master/.travis.yml"
    click Tests "https://github.com/crrel/points2grid/tree/master/test/"

    %% Styles
    classDef cli fill:#f9f,stroke:#333,stroke-width:2px
    classDef config fill:#ff9,stroke:#333,stroke-width:2px
    classDef io fill:#9cf,stroke:#333,stroke-width:2px
    classDef algo fill:#9f9,stroke:#333,stroke-width:2px
    classDef data fill:#ccc,stroke:#333,stroke-width:2px
    classDef infra fill:#eee,stroke:#333,stroke-width:2px
```
