Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
# SPDX-FileCopyrightText: (c) 2025-2026 Trailblaze Software, all rights reserved
# SPDX-License-Identifier: MIT

name: Multi-platform Build
name: Build and Test
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 5
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release, Debug, Profile]
cpp_compiler: [g++, clang++, cl]
include:
- os: windows-latest
cpp_compiler: cl
- os: ubuntu-latest
cpp_compiler: g++
- os: ubuntu-latest
cpp_compiler: clang++
exclude:
- os: windows-latest
cpp_compiler: g++
- os: windows-latest
cpp_compiler: clang++
- os: ubuntu-latest
cpp_compiler: cl
- os: windows-latest
build_type: Profile
- name: Ubuntu GCC Release
os: ubuntu-24.04
cxx: g++-14
build-type: Release
- name: Ubuntu GCC Debug
os: ubuntu-24.04
cxx: g++-14
build-type: Debug
- name: Ubuntu Clang Release
os: ubuntu-24.04
cxx: clang++-18
build-type: Release
- name: Ubuntu Clang Debug
os: ubuntu-24.04
cxx: clang++-18
build-type: Debug
- name: macOS Release
os: macos-14
cxx: clang++
build-type: Release
- name: macOS Debug
os: macos-14
cxx: clang++
build-type: Debug
- name: Windows MSVC Release
os: windows-latest
cxx: cl
build-type: Release
- name: Windows MSVC Debug
os: windows-latest
cxx: cl
build-type: Debug
steps:
- uses: actions/checkout@v4
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> \
"$GITHUB_OUTPUT"
- name: Configure CMake
- name: Install GCC 14
if: matrix.cxx == 'g++-14'
run: sudo apt-get update && sudo apt-get install -y g++-14
- name: Install Clang 18
if: matrix.cxx == 'clang++-18'
run: sudo apt-get update && sudo apt-get install -y clang-18
- name: Configure
env:
CXX: ${{ matrix.cxx }}
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }}
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DLASPP_BUILD_TESTS=ON -DLASPP_BUILD_BENCHMARK=OFF -DLASPP_AGGRESSIVE_OPTIMIZATIONS=OFF

- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 2
run: cmake --build build --config ${{ matrix.build-type }} --parallel
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --output-on-failure --build-config ${{ matrix.build_type }}
run: ctest --test-dir build --output-on-failure --build-config ${{ matrix.build-type }}
42 changes: 42 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-FileCopyrightText: (c) 2025-2026 Trailblaze Software, all rights reserved
# SPDX-License-Identifier: MIT

name: Sanitizers
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
asan-ubsan:
name: ${{ matrix.name }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- name: GCC ASan+UBSan
cxx: g++-14
- name: Clang ASan+UBSan
cxx: clang++-18
steps:
- uses: actions/checkout@v4
- name: Install GCC
if: matrix.cxx == 'g++-14'
run: sudo apt-get update && sudo apt-get install -y g++-14
- name: Install Clang
if: matrix.cxx == 'clang++-18'
run: sudo apt-get update && sudo apt-get install -y clang-18
- name: Configure
env:
CXX: ${{ matrix.cxx }}
run: >
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DLASPP_BUILD_TESTS=ON -DLASPP_BUILD_BENCHMARK=OFF -DLASPP_AGGRESSIVE_OPTIMIZATIONS=OFF -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-sanitize-recover=all" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined"

- name: Build
run: cmake --build build --parallel
- name: Test
env:
ASAN_OPTIONS: detect_leaks=1:halt_on_error=1
UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1
run: ctest --test-dir build --output-on-failure
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ if(LASPP_BUILD_TESTS)
${LASZIP_WRAPPER_SOURCES}
PROPERTIES COMPILE_FLAGS
"-Wno-old-style-cast -Wno-shadow -Wno-sign-conversion \
-Wno-conversion -Wno-useless-cast")
-Wno-conversion -Wno-useless-cast -Wno-deprecated-declarations")
else()
set_source_files_properties(
${LASZIP_WRAPPER_SOURCES}
PROPERTIES COMPILE_FLAGS
"-Wno-old-style-cast -Wno-shadow -Wno-sign-conversion \
-Wno-conversion")
-Wno-conversion -Wno-deprecated-declarations")
endif()

link_target_to_laszip(test_laszip_interop)
Expand Down
3 changes: 2 additions & 1 deletion cmake/SetupLaszip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function(setup_laszip)
# Quiet warnings coming from LASzip itself.
if(NOT MSVC)
# Common flags for both GCC and Clang
set(_common_flags -Wno-format -Wno-format-security -Wno-switch)
set(_common_flags -Wno-format -Wno-format-security -Wno-switch
-Wno-deprecated-declarations -fno-sanitize=undefined)
# GCC-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND _common_flags -Wno-maybe-uninitialized
Expand Down
2 changes: 1 addition & 1 deletion license_header.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SPDX-FileCopyrightText: (c) 2024 Trailblaze Software, all rights reserved
SPDX-FileCopyrightText: (c) 2025-2026 Trailblaze Software, all rights reserved
SPDX-License-Identifier: MIT
75 changes: 67 additions & 8 deletions src/las_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class LASReader {
std::vector<LASVLRWithGlobalOffset> m_vlr_headers;
std::vector<LASEVLRWithGlobalOffset> m_evlr_headers;

// Optional progress callback: called with fraction [0,1] as chunks are processed.
// Serialised under m_progress_mutex so callers do not need to provide a
// thread-safe callback.
std::function<void(double)> m_progress_callback;
mutable std::mutex m_progress_mutex;

// Unified I/O helper: zero-copy view for memory-mapped path, owned buffer for stream path.
// The returned object is non-copyable; its `data` span is always valid for its lifetime.
struct ReadBuffer {
Expand Down Expand Up @@ -288,6 +294,13 @@ class LASReader {

const LASHeader& header() const { return m_header; }

// Set a progress callback that will be called with fraction [0,1] during
// read_chunks / read_chunks_list. Invocations are serialised under a mutex
// so the callback does not need to be thread-safe.
void set_progress_callback(std::function<void(double)> cb) {
m_progress_callback = std::move(cb);
}

const std::vector<LASVLRWithGlobalOffset>& vlr_headers() const { return m_vlr_headers; }
const std::vector<LASEVLRWithGlobalOffset>& evlr_headers() const { return m_evlr_headers; }

Expand Down Expand Up @@ -340,7 +353,11 @@ class LASReader {
const auto* las_point =
reinterpret_cast<const PointType*>(buf.data.data() + i * point_record_length);
copy_if_possible<LASPointFormat0>(*las_point, points[i]);
copy_if_possible<LASPointFormat6>(*las_point, points[i]);
copy_if_possible<GPSTime>(*las_point, points[i]);
copy_if_possible<ColorData>(*las_point, points[i]);
copy_if_possible<NIRData>(*las_point, points[i]);
copy_if_possible<WavePacketData>(*las_point, points[i]);
}
}

Expand Down Expand Up @@ -404,7 +421,9 @@ class LASReader {
size_t file_data_offset = header().offset_to_point_data() + compressed_start_offset;
auto buf = get_bytes(file_data_offset, total_compressed_size);

utilities::parallel_for(size_t{0}, chunk_indices.size(), [&](size_t idx) {
size_t chunks_done = 0;
const size_t total_chunks = chunk_indices.size();
utilities::parallel_for(size_t{0}, total_chunks, [&](size_t idx) {
size_t chunk_index = chunk_indices[idx];
size_t start_offset = chunk_table.chunk_offset(chunk_index) - compressed_start_offset;
size_t compressed_chunk_size = chunk_table.compressed_chunk_size(chunk_index);
Expand All @@ -415,16 +434,24 @@ class LASReader {
chunk_table.decompressed_chunk_offsets()[chunk_indexes.first];
size_t n_points = chunk_table.points_per_chunk()[chunk_index];
if (chunk_index == 0) {
LASPP_ASSERT_EQ(point_offset, 0u);
LASPP_ASSERT_EQ(point_offset, 0U);
}
m_laz_reader->decompress_chunk(compressed_chunk,
output_location.subspan(point_offset, n_points));

if (m_progress_callback) {
std::lock_guard<std::mutex> lock(m_progress_mutex);
size_t done = ++chunks_done;
m_progress_callback(static_cast<double>(done) / static_cast<double>(total_chunks));
}
});
} else {
// Stream-based path: read chunks in parallel (with mutex protection) and decompress.
// This overlaps I/O and decompression - while one thread decompresses, others can read.
std::mutex stream_mutex;
utilities::parallel_for(size_t{0}, chunk_indices.size(), [&](size_t idx) {
size_t chunks_done = 0;
const size_t total_chunks = chunk_indices.size();
utilities::parallel_for(size_t{0}, total_chunks, [&](size_t idx) {
size_t chunk_index = chunk_indices[idx];
size_t file_data_offset =
header().offset_to_point_data() + chunk_table.chunk_offset(chunk_index);
Expand All @@ -443,17 +470,28 @@ class LASReader {
chunk_table.decompressed_chunk_offsets()[chunk_indexes.first];
size_t n_points = chunk_table.points_per_chunk()[chunk_index];
if (chunk_index == 0) {
LASPP_ASSERT_EQ(point_offset, 0u);
LASPP_ASSERT_EQ(point_offset, 0U);
}
m_laz_reader->decompress_chunk(std::span<const std::byte>(compressed_buffer),
output_location.subspan(point_offset, n_points));

if (m_progress_callback) {
std::lock_guard<std::mutex> lock(m_progress_mutex);
size_t done = ++chunks_done;
m_progress_callback(static_cast<double>(done) / static_cast<double>(total_chunks));
}
});
}
return output_location.subspan(0, total_n_points);
}
LASPP_ASSERT(chunk_indexes.first == 0);
LASPP_ASSERT(chunk_indexes.second == 1);
return read_chunk(output_location, 0);
auto result = read_chunk(output_location, 0);
if (m_progress_callback) {
std::lock_guard<std::mutex> lock(m_progress_mutex);
m_progress_callback(1.0);
}
return result;
}

std::vector<std::byte> read_vlr_data(const LASVLRWithGlobalOffset& vlr) {
Expand Down Expand Up @@ -547,20 +585,30 @@ class LASReader {
if (m_mapped_file.has_value()) {
// Memory-mapped path: get_bytes is zero-copy and thread-safe.
// Decompress all chunks in parallel — each call uses only local state.
utilities::parallel_for(size_t{0}, chunk_indices.size(), [&](size_t i) {
size_t chunks_done = 0;
const size_t total_chunks = chunk_indices.size();
utilities::parallel_for(size_t{0}, total_chunks, [&](size_t i) {
const size_t chunk_idx = chunk_indices[i];
const size_t file_data_offset =
header().offset_to_point_data() + chunk_table.chunk_offset(chunk_idx);
auto buf = get_bytes(file_data_offset, chunk_table.compressed_chunk_size(chunk_idx));
m_laz_reader->decompress_chunk(
buf.data,
output_location.subspan(output_offsets[i], points_per_chunk_vec[chunk_idx]));

if (m_progress_callback) {
std::lock_guard<std::mutex> lock(m_progress_mutex);
size_t done = ++chunks_done;
m_progress_callback(static_cast<double>(done) / static_cast<double>(total_chunks));
}
});
} else {
// Stream-based path: read chunks in parallel (with mutex protection) and decompress.
// This overlaps I/O and decompression - while one thread decompresses, others can read.
std::mutex stream_mutex;
utilities::parallel_for(size_t{0}, chunk_indices.size(), [&](size_t i) {
size_t chunks_done = 0;
const size_t total_chunks = chunk_indices.size();
utilities::parallel_for(size_t{0}, total_chunks, [&](size_t i) {
const size_t chunk_idx = chunk_indices[i];
const size_t file_data_offset =
header().offset_to_point_data() + chunk_table.chunk_offset(chunk_idx);
Expand All @@ -578,6 +626,12 @@ class LASReader {
m_laz_reader->decompress_chunk(
std::span<const std::byte>(compressed_buffer),
output_location.subspan(output_offsets[i], points_per_chunk_vec[chunk_idx]));

if (m_progress_callback) {
std::lock_guard<std::mutex> lock(m_progress_mutex);
size_t done = ++chunks_done;
m_progress_callback(static_cast<double>(done) / static_cast<double>(total_chunks));
}
});
}

Expand All @@ -586,7 +640,12 @@ class LASReader {
// For non-LAZ files, there's only one chunk
LASPP_ASSERT(chunk_indices.size() == 1 && chunk_indices[0] == 0,
"Non-LAZ files should only have chunk index 0");
return read_chunk<T>(output_location, 0);
auto result = read_chunk<T>(output_location, 0);
if (m_progress_callback) {
std::lock_guard<std::mutex> lock(m_progress_mutex);
m_progress_callback(1.0);
}
return result;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/laz/integer_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class IntegerEncoder {

if (k < 32) {
if (k == 0) {
m_symbol_encoders->encode(stream, k, static_cast<uint32_t>(integer));
m_symbol_encoders->encode(stream, k, static_cast<uint_fast16_t>(integer));
return;
}
if (integer < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/laz/rgb12_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class RGB12EncoderT {
uint8_t cur[6];
to_bytes(color_data, cur);

uint32_t sym = 0;
uint_fast16_t sym = 0;
sym |= (last[0] != cur[0]) ? (1u << 0u) : 0u;
sym |= (last[1] != cur[1]) ? (1u << 1u) : 0u;
sym |= (last[2] != cur[2]) ? (1u << 2u) : 0u;
Expand Down
Loading
Loading