# apburt/treeseg architecture

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

- Interactive diagram: https://gitdiagram.com/apburt/treeseg
- Repository: https://github.com/apburt/treeseg

## Overview

treeseg is a command-line toolkit and C++ library for extracting individual trees from forest lidar point clouds, with an optional RIEGL RXP converter. The principal workflow is organized around preparing point clouds, finding stems, segmenting stems, constructing crown volumes, and segmenting crowns; wood/leaf classification and cloud utilities are additional capabilities. The sampled sources show individual command behavior and calls into the shared library, but not a central workflow orchestrator, so links between separate commands are left unasserted. Some documented tutorial capabilities are represented by their source commands where available.

Main entry points: [`src/treeseg.cpp`](https://github.com/apburt/treeseg/blob/master/src/treeseg.cpp) (Point-cloud algorithms), [`src/sepwoodleaf.cpp`](https://github.com/apburt/treeseg/blob/master/src/sepwoodleaf.cpp) (Wood leaf command), [`src/rxp2pcd.cpp`](https://github.com/apburt/treeseg/blob/master/src/rxp2pcd.cpp) (RXP conversion), [`src/downsample.cpp`](https://github.com/apburt/treeseg/blob/master/src/downsample.cpp) (Downsampling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Cloud preparation"]
  node_rxp["RXP conversion<br/>[rxp2pcd.cpp]"]
  node_downsample["Downsampling<br/>[downsample.cpp]"]
  node_thin["Cloud thinning<br/>[thin.cpp]"]
  node_dtm["DTM slicing<br/>[getdtmslice.cpp]"]
  node_nearest["Nearest-neighbour tool"]
  node_plotcoords["Coordinate plotting<br/>[plotcoords.cpp]"]
  node_pcdtreesegtxt["PCD to text"]
  node_pcdxyztxt["XYZRGB to text"]
  node_txtpcd["Text to PCD"]
  node_rxptree["RXP tree conversion<br/>[rxp2tree.cpp]"]
end

subgraph group_tree["Tree extraction"]
  node_stemfind["Stem finding<br/>[findstems.cpp]"]
  node_stemsegment["Stem segmentation<br/>[segmentstem.cpp]"]
  node_crownvolume["Crown volume<br/>[getcrownvolume.cpp]"]
  node_crownsegment["Crown segmentation<br/>[segmentcrown.cpp]"]
end

subgraph group_classify["Wood leaf classification"]
  node_leafcommand["Wood leaf command<br/>[sepwoodleaf.cpp]"]
  node_leafmodel["GMM classification<br/>[leafsep.cpp]"]
  node_leafapi["Classification API<br/>[leafsep.h]"]
end

subgraph group_core["Shared point-cloud core"]
  node_library["Point-cloud algorithms<br/>[treeseg.cpp]"]
  node_api["Treeseg API<br/>[treeseg.h]"]
  node_pointtype["Point schema"]
end

node_user(("Lidar user"))

node_user -.->|"runs optionally"| node_rxp
node_user -.->|"runs tools"| node_downsample
node_user -.->|"runs workflow"| node_stemfind
node_user -.->|"runs workflow"| node_stemsegment
node_user -.->|"runs workflow"| node_crownvolume
node_user -.->|"runs workflow"| node_crownsegment
node_user -.->|"runs optionally"| node_leafcommand
node_rxp -.->|"uses API"| node_library
node_downsample -->|"calls algorithms"| node_library
node_thin -->|"calls algorithms"| node_library
node_dtm -->|"calls algorithms"| node_library
node_stemfind -->|"clusters and fits"| node_library
node_stemsegment -->|"filters and segments"| node_library
node_crownvolume -->|"measures and filters"| node_library
node_crownsegment -->|"segments and builds"| node_library
node_leafcommand -->|"segments regions"| node_library
node_leafcommand -->|"classifies clouds"| node_leafmodel
node_leafmodel -->|"implements API"| node_leafapi
node_leafapi -->|"includes"| node_api
node_api -->|"uses schema"| node_pointtype
node_nearest -->|"uses API"| node_library
node_pcdtreesegtxt -->|"uses API"| node_library
node_txtpcd -->|"uses API"| node_library

click node_rxp "https://github.com/apburt/treeseg/blob/master/src/rxp2pcd.cpp"
click node_downsample "https://github.com/apburt/treeseg/blob/master/src/downsample.cpp"
click node_thin "https://github.com/apburt/treeseg/blob/master/src/thin.cpp"
click node_dtm "https://github.com/apburt/treeseg/blob/master/src/getdtmslice.cpp"
click node_stemfind "https://github.com/apburt/treeseg/blob/master/src/findstems.cpp"
click node_stemsegment "https://github.com/apburt/treeseg/blob/master/src/segmentstem.cpp"
click node_crownvolume "https://github.com/apburt/treeseg/blob/master/src/getcrownvolume.cpp"
click node_crownsegment "https://github.com/apburt/treeseg/blob/master/src/segmentcrown.cpp"
click node_leafcommand "https://github.com/apburt/treeseg/blob/master/src/sepwoodleaf.cpp"
click node_leafmodel "https://github.com/apburt/treeseg/blob/master/src/leafsep.cpp"
click node_leafapi "https://github.com/apburt/treeseg/blob/master/include/leafsep.h"
click node_library "https://github.com/apburt/treeseg/blob/master/src/treeseg.cpp"
click node_api "https://github.com/apburt/treeseg/blob/master/include/treeseg.h"
click node_pointtype "https://github.com/apburt/treeseg/blob/master/include/treeseg_pointtype.h"
click node_nearest "https://github.com/apburt/treeseg/blob/master/src/nearestneighbour.cpp"
click node_plotcoords "https://github.com/apburt/treeseg/blob/master/src/plotcoords.cpp"
click node_pcdtreesegtxt "https://github.com/apburt/treeseg/blob/master/src/pcdPointTreeseg2txt.cpp"
click node_pcdxyztxt "https://github.com/apburt/treeseg/blob/master/src/pcdPointXYZRGB2txt.cpp"
click node_txtpcd "https://github.com/apburt/treeseg/blob/master/src/txtPointTreeseg2pcd.cpp"
click node_rxptree "https://github.com/apburt/treeseg/blob/master/src/rxp2tree.cpp"

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_rxp,node_downsample,node_thin,node_dtm,node_nearest,node_plotcoords,node_pcdtreesegtxt,node_pcdxyztxt,node_txtpcd,node_rxptree,node_user toneBlue
class node_stemfind,node_stemsegment,node_crownvolume,node_crownsegment toneAmber
class node_leafcommand,node_leafmodel,node_leafapi toneMint
class node_library,node_api,node_pointtype toneRose
```

## Components

### Cloud preparation

- [RXP conversion](https://github.com/apburt/treeseg/blob/master/src/rxp2pcd.cpp): `src/rxp2pcd.cpp`
- [Downsampling](https://github.com/apburt/treeseg/blob/master/src/downsample.cpp): `src/downsample.cpp`
- [Cloud thinning](https://github.com/apburt/treeseg/blob/master/src/thin.cpp): `src/thin.cpp`
- [DTM slicing](https://github.com/apburt/treeseg/blob/master/src/getdtmslice.cpp): `src/getdtmslice.cpp`
- [Nearest-neighbour tool](https://github.com/apburt/treeseg/blob/master/src/nearestneighbour.cpp): `src/nearestneighbour.cpp`
- [Coordinate plotting](https://github.com/apburt/treeseg/blob/master/src/plotcoords.cpp): `src/plotcoords.cpp`
- [PCD to text](https://github.com/apburt/treeseg/blob/master/src/pcdPointTreeseg2txt.cpp): `src/pcdPointTreeseg2txt.cpp`
- [XYZRGB to text](https://github.com/apburt/treeseg/blob/master/src/pcdPointXYZRGB2txt.cpp): `src/pcdPointXYZRGB2txt.cpp`
- [Text to PCD](https://github.com/apburt/treeseg/blob/master/src/txtPointTreeseg2pcd.cpp): `src/txtPointTreeseg2pcd.cpp`
- [RXP tree conversion](https://github.com/apburt/treeseg/blob/master/src/rxp2tree.cpp): `src/rxp2tree.cpp`

### Tree extraction

- [Stem finding](https://github.com/apburt/treeseg/blob/master/src/findstems.cpp): `src/findstems.cpp`
- [Stem segmentation](https://github.com/apburt/treeseg/blob/master/src/segmentstem.cpp): `src/segmentstem.cpp`
- [Crown volume](https://github.com/apburt/treeseg/blob/master/src/getcrownvolume.cpp): `src/getcrownvolume.cpp`
- [Crown segmentation](https://github.com/apburt/treeseg/blob/master/src/segmentcrown.cpp): `src/segmentcrown.cpp`

### Wood leaf classification

- [Wood leaf command](https://github.com/apburt/treeseg/blob/master/src/sepwoodleaf.cpp): `src/sepwoodleaf.cpp`
- [GMM classification](https://github.com/apburt/treeseg/blob/master/src/leafsep.cpp): `src/leafsep.cpp`
- [Classification API](https://github.com/apburt/treeseg/blob/master/include/leafsep.h): `include/leafsep.h`

### Shared point-cloud core

- [Point-cloud algorithms](https://github.com/apburt/treeseg/blob/master/src/treeseg.cpp): `src/treeseg.cpp`
- [Treeseg API](https://github.com/apburt/treeseg/blob/master/include/treeseg.h): `include/treeseg.h`
- [Point schema](https://github.com/apburt/treeseg/blob/master/include/treeseg_pointtype.h): `include/treeseg_pointtype.h`

### Other components

- **Lidar user**

## Connections

- Lidar user → RXP conversion: runs optionally
- Lidar user → Downsampling: runs tools
- Lidar user → Stem finding: runs workflow
- Lidar user → Stem segmentation: runs workflow
- Lidar user → Crown volume: runs workflow
- Lidar user → Crown segmentation: runs workflow
- Lidar user → Wood leaf command: runs optionally
- RXP conversion → Point-cloud algorithms: uses API (evidence: `src/rxp2pcd.cpp`)
- Downsampling → Point-cloud algorithms: calls algorithms (evidence: `src/downsample.cpp`)
- Cloud thinning → Point-cloud algorithms: calls algorithms (evidence: `src/thin.cpp`)
- DTM slicing → Point-cloud algorithms: calls algorithms (evidence: `src/getdtmslice.cpp`)
- Stem finding → Point-cloud algorithms: clusters and fits (evidence: `src/findstems.cpp`)
- Stem segmentation → Point-cloud algorithms: filters and segments (evidence: `src/segmentstem.cpp`)
- Crown volume → Point-cloud algorithms: measures and filters (evidence: `src/getcrownvolume.cpp`)
- Crown segmentation → Point-cloud algorithms: segments and builds (evidence: `src/segmentcrown.cpp`)
- Wood leaf command → Point-cloud algorithms: segments regions (evidence: `src/sepwoodleaf.cpp`)
- Wood leaf command → GMM classification: classifies clouds (evidence: `src/sepwoodleaf.cpp`)
- GMM classification → Classification API: implements API (evidence: `include/leafsep.h`)
- Classification API → Treeseg API: includes (evidence: `include/leafsep.h`)
- Treeseg API → Point schema: uses schema (evidence: `include/treeseg.h`)
- Nearest-neighbour tool → Point-cloud algorithms: uses API (evidence: `src/nearestneighbour.cpp`)
- PCD to text → Point-cloud algorithms: uses API (evidence: `src/pcdPointTreeseg2txt.cpp`)
- Text to PCD → Point-cloud algorithms: uses API (evidence: `src/txtPointTreeseg2pcd.cpp`)
