Skip to content

Comments

Fix LAS specification violations#366

Merged
JanuszBedkowski merged 9 commits intoMapsHD:mainfrom
bloom256:fix/laz-spec-compliance
Feb 19, 2026
Merged

Fix LAS specification violations#366
JanuszBedkowski merged 9 commits intoMapsHD:mainfrom
bloom256:fix/laz-spec-compliance

Conversation

@bloom256
Copy link
Collaborator

Summary

Fix LAS specification violations and reduce memory usage when exporting LAZ files in core/include/export_laz.h.

Fixes #352
Fixes #358

Changes

LAS spec compliance fixes

  • Fix float scale factor: constexpr float scale = 0.0001f produced 0.000099999997474 in the header due to single-precision limitations. Changed to double.
  • Fix bounding box in exportLaz(): Manual min/max computation from raw doubles didn't match quantized coordinates written to the file, causing points to fall outside the header bounding box. Replaced with laszip_update_inventory().
  • Fix bounding box in save_processed_pc(): adjustHeader() only transformed 2 of 8 AABB corners, producing an incorrect bounding box when the pose contains rotation. Removed adjustHeader() and replaced with laszip_update_inventory().
  • Set return fields: return_number and number_of_returns were 0, which is invalid per LAS 1.2 spec (valid range: 1-5). Set both to 1 (single return).

High memory usage fix

  • Add LazWriter helper class: RAII wrapper around the laszip writer lifecycle (open, writePoint, close). Centralizes LAZ writing logic so multiple callers share the same correct implementation.
  • Refactor exportLaz() to use LazWriter: Signature unchanged — all 22 callers across 13 files are unaffected.
  • Refactor save_all_to_las() to stream via LazWriter: Previously copied the entire point cloud into three temporary vectors (pointcloud, intensity, timestamps) before writing. For 218M points this duplicated ~7 GB in memory. Now streams points directly to laszip one at a time — only one point in flight instead of all points buffered.

lasinfo64 report — before

  scale factor x y z:         0.000099999997474 0.000099999997474 0.000099999997474
  offset x y z:               0 0 0
  min x y z:                  -554.883007132173816 -355.845426140132588 230.440027620015343
  max x y z:                  796.307733734780186 57.01202975172562 412.955472548385046
WARNING: stored resolution of min_x not compatible with x_offset and x_scale_factor: -554.883007132173816
WARNING: stored resolution of min_y not compatible with y_offset and y_scale_factor: -355.845426140132588
WARNING: stored resolution of min_z not compatible with z_offset and z_scale_factor: 230.440027620015343
WARNING: stored resolution of max_x not compatible with x_offset and x_scale_factor: 796.307733734780186
WARNING: stored resolution of max_y not compatible with y_offset and y_scale_factor: 57.01202975172562
WARNING: stored resolution of max_z not compatible with z_offset and z_scale_factor: 412.955472548385046
  return_number       0          0
  number_of_returns   0          0
  gps_time 1756111314071322144440057856.000000 1756115495286343064304484352.000000
WARNING: 2 points outside of header bounding box
WARNING: for return 1 real number of points by return (0) is different from header entry (218337242).
WARNING: there are 218337242 points with return number 0
WARNING: there are 218337242 points with a number of returns of given pulse of 0
WARNING: real max x larger than header max x by 0.000046
WARNING: real min z smaller than header min z by 0.000033

lasinfo64 report — after

  file source ID:             4711
  global_encoding:            1
  version major.minor:        1.2
  point data format:          1
  point data record length:   28
  number of point records:    218337242
  number of points by return: 218337242 0 0 0 0
  scale factor x y z:         0.0001 0.0001 0.0001
  offset x y z:               0 0 0
  min x y z:                  -554.8830 -355.8454 230.4400
  max x y z:                  796.3077 57.0120 412.9555
  return_number       1          1
  number_of_returns   1          1
  gps_time 1756111314071322144440057856.000000 1756115495286343064304484352.000000

Zero warnings. (GPS timestamp scaling is a known issue tracked separately.)

@JanuszBedkowski JanuszBedkowski merged commit 2deb4d8 into MapsHD:main Feb 19, 2026
6 checks passed
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.

High memory usage when exporting LAZ files Bug: Output LAZ files are not valid per LAS specification

2 participants