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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 19 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ option(USE_VENDORED_LASZIP "Build by building and linking to the vendored LASZip

if (USE_VENDORED_LASZIP)
option(LASZIP_BUILD_STATIC "Build LASZip as static lib" ON)
set(LASZIP_VENDOR "LASzip-3.4.4")
add_subdirectory(src/vendor/${LASZIP_VENDOR})
set(LASZIP_VENDOR "LASzip-4f39c23907bb92cc583aa95bb2ace2ca4f6efdbe")
add_subdirectory(src/vendor/${LASZIP_VENDOR} EXCLUDE_FROM_ALL)
else()
find_package(LASzip MODULE REQUIRED)
endif()

pybind11_add_module(laszip
set(PY_MODULE_NAME laszip_core)

pybind11_add_module(${PY_MODULE_NAME}
src/laszip.cpp
src/laszip_error.h
src/lasunzipper.h
Expand All @@ -34,21 +36,29 @@ pybind11_add_module(laszip
src/python_ostreambuf.h)

if (USE_VENDORED_LASZIP)
target_compile_definitions(laszip PRIVATE USE_VENDORED_LASZIP)
target_include_directories(laszip
target_compile_definitions(${PY_MODULE_NAME} PRIVATE USE_VENDORED_LASZIP)
target_include_directories(${PY_MODULE_NAME}
PRIVATE
src/vendor/${LASZIP_VENDOR}/dll
src/vendor/${LASZIP_VENDOR}/include/laszip
)
target_link_libraries(laszip PRIVATE laszip_base)
set_target_properties(laszip
if (WIN32)
target_link_libraries(${PY_MODULE_NAME} PRIVATE laszip3)
else()
set_target_properties(laszip PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
target_link_libraries(${PY_MODULE_NAME} PRIVATE laszip)
endif()

set_target_properties(${PY_MODULE_NAME}
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
)
else()
target_link_libraries(laszip PRIVATE LASzip::LASzip)
target_link_libraries(${PY_MODULE_NAME} PRIVATE LASzip::LASzip)
endif()

install(TARGETS laszip DESTINATION laszip)
install(TARGETS ${PY_MODULE_NAME} DESTINATION laszip)
if (WIN32)
install(FILES ${LASZIP_DLL} DESTINATION laszip)
endif()

60 changes: 59 additions & 1 deletion cmake/PythonEnvHelper.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,64 @@
macro(ensure_pybind11_cmake_module_is_in_path)
# Get pybind11 major version
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-m" "pybind11" "--cmake"
COMMAND "${PYTHON_EXECUTABLE}" -m pybind11 --version
RESULT_VARIABLE _pyb_res
OUTPUT_VARIABLE _pyb_out
ERROR_VARIABLE _pyb_err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)

if(NOT _pyb_res EQUAL 0)
message(FATAL_ERROR
"Failed to run '${PYTHON_EXECUTABLE} -m pybind11 --version' (exit ${_pyb_res}). "
"Stderr: ${_pyb_err}"
)
endif()

set(_ver_str "${_pyb_out}")
# Try to capture major.minor.patch or major.minor or just major
set(_parsed FALSE)
string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" _m3 "${_ver_str}")
if(NOT "${_m3}" STREQUAL "")
set(_major "${CMAKE_MATCH_1}")
set(_minor "${CMAKE_MATCH_2}")
set(_patch "${CMAKE_MATCH_3}")
set(_parsed TRUE)
endif()

if(NOT _parsed)
string(REGEX MATCH "([0-9]+)\\.([0-9]+)" _m2 "${_ver_str}")
if(NOT "${_m2}" STREQUAL "")
set(_major "${CMAKE_MATCH_1}")
set(_minor "${CMAKE_MATCH_2}")
set(_patch "0")
set(_parsed TRUE)
endif()
endif()

if(NOT _parsed)
string(REGEX MATCH "([0-9]+)" _m1 "${_ver_str}")
if(NOT "${_m1}" STREQUAL "")
set(_major "${CMAKE_MATCH_1}")
set(_minor "0")
set(_patch "0")
set(_parsed TRUE)
endif()
endif()

if(NOT _parsed)
message(FATAL_ERROR "Could not parse pybind11 version from: '${_ver_str}'")
endif()

if (_major STREQUAL "3")
set(DIR_ARG "--cmakedir")
else()
set(DIR_ARG "--cmake")
endif()

execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-m" "pybind11" "${DIR_ARG}"
RESULT_VARIABLE _PYTHON_SUCCESS
OUTPUT_VARIABLE PYBIND11_CMAKE_MODULES_PATH
)
Expand Down
48 changes: 26 additions & 22 deletions src/laszip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class LasZipDll
std::unique_ptr<std::ostream> m_outputStream{nullptr};
};

PYBIND11_MODULE(laszip, m)
PYBIND11_MODULE(laszip_core, m)
{
py::register_exception<laszip_error>(m, "LaszipError");

Expand Down Expand Up @@ -268,8 +268,8 @@ PYBIND11_MODULE(laszip, m)

py::class_<LasZipDll>(m, "LasZipDll")
.def(py::init<>())
.def("open_reader", (bool (LasZipDll::*)(const char *))(&LasZipDll::open_reader))
.def("open_reader", (bool (LasZipDll::*)(py::object &))(&LasZipDll::open_reader))
.def("open_reader", (bool(LasZipDll::*)(const char *))(&LasZipDll::open_reader))
.def("open_reader", (bool(LasZipDll::*)(py::object &))(&LasZipDll::open_reader))
.def("header", &LasZipDll::header, py::return_value_policy::reference)
.def("point", &LasZipDll::point, py::return_value_policy::reference)
.def("read_point", &LasZipDll::read_point)
Expand All @@ -292,7 +292,8 @@ PYBIND11_MODULE(laszip, m)
.def_property(
"project_ID_GUID_data_4",
[](const laszip_header &header) { return py::str(header.project_ID_GUID_data_4, 8); },
[](laszip_header &header, const std::string &new_value) {
[](laszip_header &header, const std::string &new_value)
{
if (new_value.size() != 8)
{
throw std::invalid_argument("project_ID_GUID_data_4 must be 8 bytes long");
Expand All @@ -304,7 +305,8 @@ PYBIND11_MODULE(laszip, m)
.def_property(
"system_identifier",
[](const laszip_header &header) { return py::str(header.system_identifier, 32); },
[](laszip_header &header, const std::string &new_value) {
[](laszip_header &header, const std::string &new_value)
{
if (new_value.size() > 32)
{
throw std::invalid_argument("system_identifier cannot exceed 32 bytes");
Expand All @@ -315,7 +317,8 @@ PYBIND11_MODULE(laszip, m)
.def_property(
"generating_software",
[](const laszip_header &header) { return py::str(header.generating_software, 32); },
[](laszip_header &header, const std::string &new_value) {
[](laszip_header &header, const std::string &new_value)
{
if (new_value.size() > 32)
{
throw std::invalid_argument("generating_software cannot exceed 32 bytes");
Expand All @@ -332,9 +335,8 @@ PYBIND11_MODULE(laszip, m)
.def_readwrite("point_data_record_length", &laszip_header::point_data_record_length)
.def_readwrite("number_of_point_records", &laszip_header::number_of_point_records)
.def_property_readonly("number_of_points_by_return",
[](const laszip_header &header) {
return wrap_as_py_array(header.number_of_points_by_return, 5);
})
[](const laszip_header &header)
{ return wrap_as_py_array(header.number_of_points_by_return, 5); })
.def_readwrite("x_scale_factor", &laszip_header::x_scale_factor)
.def_readwrite("y_scale_factor", &laszip_header::y_scale_factor)
.def_readwrite("z_scale_factor", &laszip_header::z_scale_factor)
Expand All @@ -356,9 +358,9 @@ PYBIND11_MODULE(laszip, m)
.def_readwrite("number_of_extended_variable_length_records",
&laszip_header::number_of_extended_variable_length_records)
.def_readwrite("extended_number_of_point_records", &laszip_header::extended_number_of_point_records)
.def_property_readonly("extended_number_of_points_by_return", [](const laszip_header &header) {
return wrap_as_py_array(header.extended_number_of_points_by_return, 15);
});
.def_property_readonly("extended_number_of_points_by_return",
[](const laszip_header &header)
{ return wrap_as_py_array(header.extended_number_of_points_by_return, 15); });

py::class_<laszip_point>(m, "LasZipPoint")
.def(py::init<>())
Expand Down Expand Up @@ -431,17 +433,19 @@ PYBIND11_MODULE(laszip, m)
[](const laszip_point &point) { return wrap_as_py_array(point.rgb, 4); })
.def_property_readonly(
"wave_packet", [](const laszip_point &point) { return wrap_as_py_array(point.wave_packet, 4); })
.def_property_readonly("extra_bytes", [](const laszip_point &point) {
return wrap_as_py_array(point.extra_bytes, point.num_extra_bytes);
});
.def_property_readonly("extra_bytes",
[](const laszip_point &point)
{ return wrap_as_py_array(point.extra_bytes, point.num_extra_bytes); });

m.def("get_version", []() {
laszip_U8 major{0}, minor{0};
laszip_U16 revision{0};
laszip_U32 build{0};
m.def("get_version",
[]()
{
laszip_U8 major{0}, minor{0};
laszip_U16 revision{0};
laszip_U32 build{0};

laszip_get_version(&major, &minor, &revision, &build);
laszip_get_version(&major, &minor, &revision, &build);

return py::make_tuple(major, minor, revision, build);
});
return py::make_tuple(major, minor, revision, build);
});
}
2 changes: 1 addition & 1 deletion src/laszip/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .laszip import *
from .laszip_core import *
Empty file removed src/vendor/LASzip-3.4.4/README
Empty file.
Empty file.
45 changes: 0 additions & 45 deletions src/vendor/LASzip-3.4.4/docs/source/data.rst

This file was deleted.

16 changes: 0 additions & 16 deletions src/vendor/LASzip-3.4.4/docs/source/detail.rst

This file was deleted.

Loading
Loading