Skip to content

Commit

Permalink
[PSP3] Adapting to new LASTools version (branch 5.5) (#8448)
Browse files Browse the repository at this point in the history
Allowing use of official LAStools repository or CGAL's fork of LASlib

5.5-branch variant of  #8173 

## Release Management

* Affected package(s): PSP3, Point_set_3, Stream_support
* Issue(s) solved (if any): fix #8111
  • Loading branch information
sloriot authored Sep 6, 2024
2 parents 7425bc4 + e3b65d3 commit a27d129
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 48 deletions.
25 changes: 18 additions & 7 deletions Installation/cmake/modules/CGAL_LASLIB_support.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
if(LASLIB_FOUND AND NOT TARGET CGAL::LASLIB_support)
add_library(CGAL::LASLIB_support INTERFACE IMPORTED)
set_target_properties(CGAL::LASLIB_support PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_LASLIB"
INTERFACE_INCLUDE_DIRECTORIES "${LASLIB_INCLUDE_DIR};${LASZIP_INCLUDE_DIR}"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${LASLIB_INCLUDE_DIR};${LASZIP_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${LASLIB_LIBRARIES}")
if(LASLIB_FOUND)
if (NOT TARGET CGAL::LASLIB_support)
if (NOT TARGET LASlib)
# message(STATUS "Found using MODULE mode")
add_library(CGAL::LASLIB_support INTERFACE IMPORTED)
set_target_properties(CGAL::LASLIB_support PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_LASLIB"
INTERFACE_INCLUDE_DIRECTORIES "${LASLIB_INCLUDE_DIR}"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${LASLIB_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${LASLIB_LIBRARIES}")
else()
# message(STATUS "Found using CONFIG mode")
add_library(CGAL::LASLIB_support INTERFACE IMPORTED)
set_target_properties(CGAL::LASLIB_support PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "CGAL_LINKED_WITH_LASLIB")
target_link_libraries(CGAL::LASLIB_support INTERFACE LASlib)
endif()
endif()
endif()
23 changes: 19 additions & 4 deletions Installation/cmake/modules/FindLASLIB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
# first look in user defined locations
find_path(LASLIB_INCLUDE_DIR
NAMES lasreader.hpp
PATHS /usr/local/include/LASlib/
PATHS /usr/local/include/LASlib/
ENV LASLIB_INC_DIR
)

find_path(LASZIP_INCLUDE_DIR
NAMES mydefs.hpp
PATHS /usr/local/include/LASzip/
${LASLIB_INCLUDE_DIR}/../../LASzip/src
${LASLIB_INCLUDE_DIR}/../LASzip
${LASLIB_INCLUDE_DIR}
)

find_library(LASLIB_LIBRARIES
Expand All @@ -27,9 +29,22 @@ find_library(LASLIB_LIBRARIES
${LASLIB_INCLUDE_DIR}/../../lib
ENV LASLIB_LIB_DIR
)
if (NOT LASLIB_LIBRARIES)
#library was renamed in recent versions of LAStools
find_library(LASLIB_LIBRARIES
NAMES LASlib
PATHS ENV LD_LIBRARY_PATH
ENV LIBRARY_PATH
/usr/local/lib
${LASLIB_INCLUDE_DIR}/../../lib
ENV LASLIB_LIB_DIR
)
endif()

if(LASLIB_LIBRARIES AND LASLIB_INCLUDE_DIR)
if(LASLIB_LIBRARIES AND LASLIB_INCLUDE_DIR AND LASZIP_INCLUDE_DIR)
if (NOT ${LASLIB_INCLUDE_DIR} STREQUAL ${LASZIP_INCLUDE_DIR})
list(APPEND LASLIB_INCLUDE_DIR ${LASZIP_INCLUDE_DIR})
endif()
set(LASLIB_FOUND TRUE)
set(LASLIB_USE_FILE "UseLASLIB")
endif()

2 changes: 1 addition & 1 deletion Installation/cmake/modules/UseLASLIB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

add_definitions(-DCGAL_LINKED_WITH_LASLIB)

message(DEPRECATION "This file UseLASLIB.cmake is deprecated, and the imported target `CGAL::TBB_support` from CGAL_LASLIB_support.cmake should be used instead.")
message(DEPRECATION "This file UseLASLIB.cmake is deprecated, and the imported target `CGAL::LASLIB_support` from CGAL_LASLIB_support.cmake should be used instead.")
4 changes: 2 additions & 2 deletions Point_set_3/test/Point_set_3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ create_single_source_cgal_program("test_deprecated_io_ps.cpp")

#Use LAS
#disable if MSVC 2017
if(NOT MSVC_VERSION OR (MSVC_VERSION GREATER_EQUAL 1919 AND MSVC_VERSION LESS 1910))
if(NOT MSVC_VERSION OR MSVC_VERSION GREATER_EQUAL 1919 OR MSVC_VERSION LESS 1910)
find_package(LASLIB)
include(CGAL_LASLIB_support)
if (TARGET CGAL::LASLIB_support)
Expand All @@ -41,5 +41,5 @@ if(NOT MSVC_VERSION OR (MSVC_VERSION GREATER_EQUAL 1919 AND MSVC_VERSION LESS 1
message(STATUS "NOTICE : the LAS reader test requires LASlib and will not be compiled.")
endif()
else()
message(STATUS "NOTICE : the LAS reader does not work with Visual Studio 2017.")
message(STATUS "NOTICE : the LAS reader does not work with your version of Visual Studio 2017.")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ find_package(LASLIB)
include(CGAL_LASLIB_support)
if(TARGET CGAL::LASLIB_support)
create_single_source_cgal_program("read_las_example.cpp")
create_single_source_cgal_program("write_las_example.cpp")
target_link_libraries(read_las_example PRIVATE ${CGAL_libs} CGAL::LASLIB_support)
target_link_libraries(write_las_example PRIVATE ${CGAL_libs} CGAL::LASLIB_support)
else()
message(
STATUS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/property_map.h>
#include <CGAL/IO/read_las_points.h>
#include <CGAL/IO/write_las_points.h>

#include <utility>
#include <vector>
#include <fstream>

// types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef std::array<unsigned short, 4> Color;
typedef std::pair<Point, Color> PointWithColor;

int main(int argc, char*argv[])
{
const char* fname = "colored_points.las";

std::ofstream os(fname, std::ios::binary);

std::vector<PointWithColor> points; // store points
points.push_back(std::make_pair(Point(0, 0, 0), Color{ 65535, 0, 0, 0 }));
points.push_back(std::make_pair(Point(1, 0, 0), Color{ 0, 65535, 0, 0 }));
points.push_back(std::make_pair(Point(0, 1, 0), Color{ 0, 0, 65535, 0 }));
points.push_back(std::make_pair(Point(1, 1, 0), Color{ 0, 65535, 65535, 0 }));
points.push_back(std::make_pair(Point(1, 1, 1), Color{ 65535, 65535, 0, 0 }));

// Writes a .las point set file with colors
if(!CGAL::IO::write_LAS_with_properties(os, points,
CGAL::IO::make_las_point_writer(CGAL::First_of_pair_property_map<PointWithColor>()),
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
CGAL::IO::LAS_property::R(),
CGAL::IO::LAS_property::G(),
CGAL::IO::LAS_property::B(),
CGAL::IO::LAS_property::I())))
{
std::cerr << "Error: cannot write file " << fname << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}
6 changes: 5 additions & 1 deletion Point_set_processing_3/include/CGAL/IO/read_las_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif

#define USE_AS_DLL
#define USE_AS_DLL 1
#include <lasreader_las.hpp>
#undef USE_AS_DLL

Expand Down Expand Up @@ -385,7 +385,11 @@ bool read_LAS_with_properties(std::istream& is,
if(!is)
return false;

#if LAS_TOOLS_VERSION < 240319
LASreaderLAS lasreader;
#else
LASreaderLAS lasreader(nullptr);
#endif
lasreader.open(is);

while(lasreader.read_point())
Expand Down
97 changes: 67 additions & 30 deletions Point_set_processing_3/include/CGAL/IO/write_las_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif

#define USE_AS_DLL
#define USE_AS_DLL 1
#include <lasdefinitions.hpp>
#include <lasreader_las.hpp>
#include <laswriter_las.hpp>
Expand Down Expand Up @@ -84,41 +84,41 @@ make_las_point_writer(PointMap point_map)
namespace internal {
namespace LAS {

inline void output_value(LASpoint& r, const unsigned short& v, LAS_property::Intensity&)
inline void output_value(LASpoint& r, const unsigned short& v, const LAS_property::Intensity&)
{ r.set_intensity(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Return_number&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Return_number&)
{ r.set_return_number(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Number_of_returns&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Number_of_returns&)
{ r.set_number_of_returns(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Scan_direction_flag&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Scan_direction_flag&)
{ r.set_scan_direction_flag(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Edge_of_flight_line&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Edge_of_flight_line&)
{ r.set_edge_of_flight_line(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Classification&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Classification&)
{ r.set_classification(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Synthetic_flag&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Synthetic_flag&)
{ r.set_synthetic_flag(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Keypoint_flag&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Keypoint_flag&)
{ r.set_keypoint_flag(v); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::Withheld_flag&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::Withheld_flag&)
{ r.set_withheld_flag(v); }
inline void output_value(LASpoint& r, const float& v, LAS_property::Scan_angle&)
inline void output_value(LASpoint& r, const float& v, const LAS_property::Scan_angle&)
{ r.set_scan_angle_rank(char(v)); }
inline void output_value(LASpoint& r, const unsigned char& v, LAS_property::User_data&)
inline void output_value(LASpoint& r, const unsigned char& v, const LAS_property::User_data&)
{ r.set_user_data(v); }
inline void output_value(LASpoint& r, const unsigned short& v, LAS_property::Point_source_ID&)
inline void output_value(LASpoint& r, const unsigned short& v, const LAS_property::Point_source_ID&)
{ r.set_point_source_ID(v); }
inline void output_value(LASpoint& r, const unsigned int& v, LAS_property::Deleted_flag&)
inline void output_value(LASpoint& r, const unsigned int& v, const LAS_property::Deleted_flag&)
{ r.set_deleted_flag(v); }
inline void output_value(LASpoint& r, const double& v, LAS_property::GPS_time&)
inline void output_value(LASpoint& r, const double& v, const LAS_property::GPS_time&)
{ r.set_gps_time(v); }
inline void output_value(LASpoint& r, const unsigned short& v, LAS_property::R&)
inline void output_value(LASpoint& r, const unsigned short& v, const LAS_property::R&)
{ r.set_R(v); }
inline void output_value(LASpoint& r, const unsigned short& v, LAS_property::G&)
inline void output_value(LASpoint& r, const unsigned short& v, const LAS_property::G&)
{ r.set_G(v); }
inline void output_value(LASpoint& r, const unsigned short& v, LAS_property::B&)
inline void output_value(LASpoint& r, const unsigned short& v, const LAS_property::B&)
{ r.set_B(v); }
inline void output_value(LASpoint& r, const unsigned short& v, LAS_property::I&)
inline void output_value(LASpoint& r, const unsigned short& v, const LAS_property::I&)
{ r.set_I(v); }

template <typename ForwardIterator>
Expand All @@ -134,20 +134,57 @@ namespace LAS {
output_value (point, get(current.first, *it), current.second);
}

template<typename Value, typename Tuple, std::size_t I>
void output_tuple(LASpoint& point, const Value& v, const Tuple& t, std::index_sequence<I>) {
output_value(point, std::get<I>(v), std::get<I>(t));
}

template<typename Value, typename Tuple, std::size_t I, std::size_t... Is>
void output_tuple(LASpoint& point, const Value& v, const Tuple& t, std::index_sequence<I, Is...>) {
output_value(point, std::get<I>(v), std::get<I>(t));
output_tuple(point, v, t, std::index_sequence<Is...>());
}

template <typename ForwardIterator,
typename PropertyMap,
typename T,
typename NextPropertyHandler,
typename ... PropertyHandler>
typename PropertyMap,
typename ... T>
void output_properties(LASpoint& point,
ForwardIterator it,
std::pair<PropertyMap, T>&& current,
NextPropertyHandler&& next,
PropertyHandler&& ... properties)
ForwardIterator it,
std::tuple<PropertyMap, T ...>&& current)
{
output_value (point, get(current.first, *it), current.second);
output_properties (point, it, std::forward<NextPropertyHandler>(next),
std::forward<PropertyHandler>(properties)...);
output_tuple(point, get(std::get<0>(current), *it), std::tuple<T ...>(), std::index_sequence_for<T ...>{});
}

template <typename ForwardIterator,
typename PropertyMap,
typename T,
typename NextPropertyHandler,
typename ... PropertyHandler>
void output_properties(LASpoint& point,
ForwardIterator it,
std::pair<PropertyMap, T>&& current,
NextPropertyHandler&& next,
PropertyHandler&& ... properties)
{
output_value(point, get(current.first, *it), current.second);
output_properties(point, it, std::forward<NextPropertyHandler>(next),
std::forward<PropertyHandler>(properties)...);
}

template <typename ForwardIterator,
typename PropertyMap,
typename ... T,
typename NextPropertyHandler,
typename ... PropertyHandler>
void output_properties(LASpoint& point,
ForwardIterator it,
std::tuple<PropertyMap, T ...>&& current,
NextPropertyHandler&& next,
PropertyHandler&& ... properties)
{
output_tuple(point, get(std::get<0>(current), *it), std::tuple<T ...>(), std::index_sequence_for<T ...>{});
output_properties(point, it, std::forward<NextPropertyHandler>(next),
std::forward<PropertyHandler>(properties)...);
}

} // namespace LAS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ create_single_source_cgal_program( "structuring_test.cpp" )

#Use LAS
#disable if MSVC 2017
if(NOT MSVC_VERSION OR (MSVC_VERSION GREATER_EQUAL 1919 AND MSVC_VERSION LESS 1910))
if(NOT MSVC_VERSION OR MSVC_VERSION GREATER_EQUAL 1919 OR MSVC_VERSION LESS 1910)
find_package(LASLIB)
include(CGAL_LASLIB_support)
if (TARGET CGAL::LASLIB_support)
Expand All @@ -49,7 +49,7 @@ if(NOT MSVC_VERSION OR (MSVC_VERSION GREATER_EQUAL 1919 AND MSVC_VERSION LESS 1
message(STATUS "NOTICE : the LAS reader test requires LASlib and will not be compiled.")
endif()
else()
message(STATUS "NOTICE : the LAS reader does not work with Visual Studio 2017.")
message(STATUS "NOTICE : the LAS reader does not work with your version of Visual Studio 2017.")
endif()

# Use Eigen
Expand Down
14 changes: 13 additions & 1 deletion Stream_support/test/Stream_support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ find_library(
NAMES 3MF
DOC "Path to the lib3MF library")

find_package(LASLIB QUIET)
include(CGAL_LASLIB_support)

# create a target per cppfile
file(
GLOB cppfiles
Expand All @@ -33,6 +36,15 @@ foreach(cppfile ${cppfiles})
)
endif()
else()
create_single_source_cgal_program("${cppfile}")
if("${cppfile}" STREQUAL "test_LAS.cpp")
if(TARGET CGAL::LASLIB_support)
create_single_source_cgal_program("test_LAS.cpp")
target_link_libraries(test_LAS PRIVATE CGAL::LASLIB_support)
else()
message(STATUS "NOTICE: Some tests require the LASlib library, and will not be compiled.")
endif()
else()
create_single_source_cgal_program("${cppfile}")
endif()
endif()
endforeach()
Binary file not shown.
Loading

0 comments on commit a27d129

Please sign in to comment.