Skip to content

feat(lidar): read LAS and LAZ tiles into the scene's world frame (p7-s3) (#243) - #492

Merged
JArmandoAnaya merged 3 commits into
mainfrom
feat/243-p7-s3-lidar-kernel
Jul 29, 2026
Merged

JArmandoAnaya merged 3 commits into
mainfrom
feat/243-p7-s3-lidar-kernel

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

The kernel half of #243 (p7-s3): a new roadmaker::lidar module that reads
ASPRS point clouds, moves them into the scene's world frame, and fits their
ground into the scene height field. Follows ADR-0011 (#491), which ruled that
RoadMaker reads LAS itself rather than through PDAL — PDAL hard-requires PROJ
9.0, GDAL 3.8 and libgeotiff, the dependency ADR-0010 declined two days ago.

The editor half — the point-cloud reference layer, the points render path and the
two menu entries — follows in its own PR.

What landed

Reader ASPRS LAS 1.0–1.4, point record formats 0–10, and LAZ
New dependency laz-perf 3.4.0 (Apache-2.0), decoding the compressed chunk stream and nothing else
CRS out of LASF_Projection records — GeoKey directory (34735) or OGC WKT (2112) — through the same bounded family the GIS importer uses
Refusals, by name LAS 1.5+ (#490), a CRS outside the family (#485), a format this build does not read
Python rm.lidar beside rm.gis, plus python/examples/lidar_import.py

Three things that are load-bearing rather than incidental

Coordinates are floats relative to a double origin. At a UTM northing near
5.8 × 10⁶ m a float's quantum is about half a metre, so a cloud held in absolute
floats would terrace itself into visible steps.

Decimation is decided from the header, before a single point is read. A tile
too large to hold is also too large to read and then thin. The stride is
deterministic — every nth point — and the ratio is always reported, because a
cloud silently reduced to a twelfth of itself looks like a sparse survey rather
than a truncated one.

The ground fit takes the mean of the returns a tile classified as bare ground,
and only falls back to the lowest return when it classified none. The minimum
exists to reject roofs and canopy and pays for that with half a cell of downhill
bias on a slope; where the file has already done that work, there is nothing left
for it to buy. Which estimator ran is always named in a diagnostic — they
disagree under a bridge.

Reuse rather than a second implementation

The GeoTIFF GeoKey directory reader moves out of geotiff.cpp into gis_common,
so a raster and a lidar tile describing the same place cannot disagree about what
it is. No public API change; crs_transform's refusal message and its #485
citation stay identical across all three importers.

laz-perf is built from source, not through its own CMake

Upstream's CMakeLists.txt declares an explicit SHARED target and adds
benchmarks, tools and install rules unguarded, and its test path runs a
configure-time file(DOWNLOAD). So it is taken with the repo's existing
SOURCE_SUBDIR cmake-disabled idiom and compiled into a small rm_lazperf
target with upstream's own LAZPERF_VENDORED macro. Pinned by tag + URL_HASH,
with its THIRD_PARTY_LICENSES.md row in the same commit.

Fixtures are committed, and one of them is a trap for this reader

scripts/gen_lidar_fixtures.py writes them with the standard library alone, in
the same place as the GIS fixtures — Amsterdam, UTM 31N — so a false easting or a
wrong central meridian cannot hide at (0, 0), and so the two importers can be
checked against each other. EveryFixtureIsPresent is itself a test.

amsterdam_tile.laz needs the codec, so a small standalone tool writes it. That
tool deliberately does not link roadmaker::core — a fixture generated by
the reader under test would bake that reader's mistakes into the fixture, and the
comparison would then agree with both of them.

That tool also had a real bug worth recording: laz-perf's writer emits its own
header and only its own VLRs, so the first version of it silently produced a
.laz with no coordinate system at all — and the suite passed anyway,
because it compared coordinates and classification but not CRS. It was found by
running the worked example, not by the tests. Both halves are fixed: the tool
splices the projection records back in (correcting the absolute chunk-table
offset as it does), and LazDecodesIdenticallyToLas now asserts CRS equality and
non-emptiness.

Verification

  • cmake --build --preset ci-macos (-Werror) clean; ctest --preset ci-macos
    2616/2616.
  • pytest python/tests 381 passed, 1 skipped; python/examples/lidar_import.py
    runs end to end.
  • ASan + UBSan over core and editor test binaries: 1537 + 1077 tests,
    zero sanitizer findings.
  • scripts/gen_lidar_fixtures.py is idempotent — re-running leaves the tree clean.
  • git ls-files '*.cpp' '*.hpp' | xargs clang-format --dry-run --Werror clean
    (CI's exact command).

Sabotage matrix — six neutralisations, each rebuilt and re-run

Every sabotage is a runtime neutralisation rather than a deletion, and every run
echoes the build's exit code, so a sabotage that failed to compile cannot report
green off a stale binary.

# Neutralised Gate that fired
1 classification read unmasked on formats 0–5 LegacyFormatsMaskTheClassificationBits, ClassificationSurvivesTheFormatPromotion
2 the read budget ignored (stride forced to 1) DecimationHonoursTheBudgetAndSaysSo
3 xyz holds absolute floats (origin forced to 0) DetailFinerThanAFloatsQuantumSurvivesTheRead
4 the classified path takes the lowest return, not the mean TheClassifiedFitReadsTheMeanOfItsPost_NotTheLowestReturn
5 empty posts written as zero instead of interpolated EmptyCellsAreInterpolatedNeverWrittenAsZero, TurningClassificationOffChangesTheAnswerWhereItShould
6 a compressed tile loses its CRS LazDecodesIdenticallyToLas

Sabotages 3 and 4 passed on the first attempt, which is the useful part of
the run: two rules this PR describes as load-bearing were not pinned by anything.
Both gates in the table are new, and the second commit explains why each earlier
test was blind:

  • 3 — the fixture tile's 5 m lattice is exactly representable in an
    absolute float at UTM magnitude, because the quantum there is exactly 0.5 m.
    A new precision_probe.las carries centimetre offsets, which are not.
  • 4 — the min estimator's error is about half a cell of grade, exactly the
    slack a binning fit's tests have to allow. The new gate is exact instead: with
    a 5 m lattice under 10 m posts every interior post collects the same 2×2 block,
    so the mean lands 0.175 m below the plane and the minimum 0.350 m below it.
    It asserts the mean's offset rather than no offset, because that residual is
    the nearest-post tie rule's and not the estimator's.

Part of #243. Pillar P7, epic #256.

A new kernel module, `roadmaker::lidar`, imports ASPRS point clouds and
fits their ground into the scene's height field.

It reads LAS 1.0-1.4 and LAZ itself rather than through PDAL, because
PDAL hard-requires PROJ 9.0, GDAL 3.8 and libgeotiff -- the dependency
ADR-0010 declined two days ago. ADR-0011 records that ruling; the only
new dependency here is laz-perf 3.4.0 (Apache-2.0), which decodes the
compressed chunk stream and does nothing else.

Three things in the design are load-bearing rather than incidental:

- Coordinates are floats RELATIVE to a double origin. At a UTM northing
  near 5.8e6 m a float's quantum is about half a metre, so a cloud held
  in absolute floats would terrace itself into visible steps.

- Decimation is decided from the header, before a single point is read:
  a tile too large to hold is also too large to read and then thin. The
  stride is deterministic and the ratio is always reported, because a
  cloud silently reduced to a twelfth of itself looks like a sparse
  survey rather than a truncated one.

- The ground fit takes the MEAN of the returns a tile classified as bare
  ground, and only falls back to the lowest return when it classified
  none. The minimum exists to reject roofs and canopy and pays for it
  with half a cell of downhill bias on a slope; where the file has
  already done that work, there is nothing left for it to buy.

The CRS comes out of the LAS `LASF_Projection` records through the same
bounded family the GIS importer uses -- the GeoTIFF GeoKey reader is
lifted out of geotiff.cpp into gis_common so a raster and a tile
describing the same place can never disagree -- and anything outside
that family is refused by name, citing #485.

Fixtures are generated by a standard-library-only script and committed,
so a reader is never checked against bytes the same test just built.
`amsterdam_tile.laz` needs the codec, so a small standalone tool writes
it; that tool deliberately does not link roadmaker::core, and it splices
the source's projection records back in because laz-perf's writer emits
only its own -- the first version of it silently produced a .laz with no
coordinate system at all, and the suite passed anyway.

Closes part of #243.
Neutralising each load-bearing rule in turn and re-running showed two of
them were not actually pinned by anything.

The offset representation. Forcing the cloud origin to zero -- holding
absolute coordinates in the floats, the exact defect the design exists to
avoid -- left the whole suite green. The reason is arithmetic, not luck:
at a northing of 5 803 000 a float's quantum is exactly 0.5 m, and the
fixture tile's coordinates are all multiples of 5, so they survive an
absolute float untouched. `precision_probe.las` carries centimetre
offsets instead, which no float at that magnitude can hold.

The ground estimator. Swapping the classified path back to the lowest
return also left the suite green, because the error it introduces is
about half a cell of grade -- which is exactly the slack a binning fit's
tests have to allow. The new gate is exact rather than tolerant, and it
can be: with a 5 m lattice under 10 m posts every interior post collects
the same 2x2 block, so the mean lands 0.175 m below the plane and the
minimum 0.350 m below it. Both are constants, and asserting the first to
a millimetre rejects the second outright.

Asserting the mean's offset rather than asserting no offset at all is
deliberate: the residual is the nearest-post TIE RULE's, not the
estimator's, and a test that claimed zero would be wrong about which
part of the code it was describing.

Also samples inside the tile in the worked example. It was reading the
scene origin, a kilometre away, and reporting the field's clamped edge.
std::any_of and std::min arrive transitively through libc++ on macOS, so
a clean local build was not evidence the include was there. Linux clang
found it. Also adds <cstddef> to the fixture tool, which had the same
shape of omission and is EXCLUDE_FROM_ALL, so CI would never have said.
@JArmandoAnaya
JArmandoAnaya merged commit 2fda009 into main Jul 29, 2026
15 checks passed
@JArmandoAnaya
JArmandoAnaya deleted the feat/243-p7-s3-lidar-kernel branch July 29, 2026 04:37
JArmandoAnaya added a commit that referenced this pull request Jul 29, 2026
Both arrive transitively through libc++ on macOS and not through Linux
clang, which is exactly how #492 shipped a green local build that broke
CI on the same class of omission.
JArmandoAnaya added a commit that referenced this pull request Jul 29, 2026
…(p7-s3) (#243) (#493)

* feat(editor): see a lidar tile in the scene, and turn it into ground (p7-s3)

The editor half of #243. A point cloud becomes the third
ReferenceLayerKind, imported with File > Import > Point Cloud... and
turned into terrain with Edit > Terrain > Seed from Point Cloud...

Everything Layer 2 already guarantees is inherited unchanged: the
relative-path contract, re-derivation when the frame changes, the
per-entry sidecar tolerance, and the ruling that adding a layer is not
an undoable command. Seeding terrain is, and goes through the same
edit::set_terrain_field the DEM and elevation-raster paths use, so it is
one undo entry.

Two things a cloud does NOT inherit from an imagery underlay:

- It is not flattened. Vectors and rasters are backdrops drawn at a
  fixed height; a cloud has real Z and draws depth-sorted with the
  scene, because its heights are why it was imported at all.

- Its vertices stay in the cloud's own frame, with the origin carried as
  the draw's single instance matrix. Baking the origin into the vertex
  buffer would put a scene-scale value back into a float and reintroduce
  the terracing the offset representation exists to prevent -- the same
  defect the kernel guards, one layer further out.

THE PRIMITIVE PATH IS NOW A SWITCH. Drawing points needed a third
PrimitiveKind, and the renderer chose its GL primitive with a two-way
ternary: `kind == Triangles ? kTriangles : kLines`. A third enumerator
added without touching that line would have drawn the cloud as LINE
SEGMENTS BETWEEN CONSECUTIVE POINTS -- silently, no warning, no error.
Both that site and the two-way branch in the layer bounds are switches
now, and a named test pins each.

THE SIDECAR'S `kind` STOPS BEING A BOOL. It is the same enum the runtime
uses, so a third spelling cannot exist in one and not the other. Older
sidecars carry only "vector" and "raster" and load unchanged; an unknown
spelling still reads as a raster with a warning rather than dropping the
layer.

ALSO WIRES UP A PATH THAT SHIPPED DEAD. Document::refit_reference_layers()
was added by #242 and called from nowhere: reopening a scene re-derived
its layers, but changing the georeference LIVE left them over the wrong
ground. GW-2 step 31 asks a hand-runner to check exactly that, and its
pass criterion already said a build which mishandles it fails the run --
so the gap was written down before it was closed. #243 would otherwise
have added a third layer kind inheriting the same dead path.

GW-2 gains steps 34-37 and three pass criteria, the sharpest being that
the cloud and the imagery must land on each other: they are read by
different parsers but share one CrsTransform, so a visible offset
between them is a projection bug and this is the cheapest place in the
workflow to notice one.

Closes #243.

* test(editor): include <filesystem> and <algorithm> explicitly

Both arrive transitively through libc++ on macOS and not through Linux
clang, which is exactly how #492 shipped a green local build that broke
CI on the same class of omission.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant