From 1cc00a32eb102772278f85e8e611f3a66040345b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 5 Mar 2021 14:52:25 +0100 Subject: [PATCH] Move LAS code from item to plugin to prevent BOOL declaration to conflict with the one form lib3mf. --- Polyhedron/demo/Polyhedron/CMakeLists.txt | 17 -------- .../demo/Polyhedron/Plugins/IO/CMakeLists.txt | 13 +++++++ .../Polyhedron/Plugins/IO/LAS_io_plugin.cpp | 39 +++++++++++++++---- .../Scene_points_with_normal_item.cpp | 37 ------------------ .../Scene_points_with_normal_item.h | 4 -- 5 files changed, 45 insertions(+), 65 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index 0bb7d129c9e..af1cc39a9f6 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -338,23 +338,6 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND) PUBLIC CGAL::Eigen3_support) endif() - find_package(LASLIB) - set_package_properties( - LASLIB PROPERTIES - DESCRIPTION "A library for some I/O." - PURPOSE "Requiered for reading or writing LAS files.") - - include(CGAL_LASLIB_support) - if(TARGET CGAL::LASLIB_support) - target_link_libraries(scene_points_with_normal_item - PUBLIC CGAL::LASLIB_support) - if(MSVC) - target_compile_definitions( - scene_points_with_normal_item - PUBLIC "-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS") - endif() - endif() - if(TBB_FOUND) target_link_libraries(scene_points_with_normal_item PUBLIC CGAL::TBB_support) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt index bed7401d8dc..5ac22254a05 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt @@ -1,5 +1,13 @@ include(polyhedron_demo_macros) +find_package(LASLIB) +set_package_properties( + LASLIB PROPERTIES + DESCRIPTION "A library for some I/O." + PURPOSE "Requiered for reading or writing LAS files.") + +include(CGAL_LASLIB_support) + polyhedron_demo_plugin(gocad_plugin GOCAD_io_plugin KEYWORDS Viewer) target_link_libraries(gocad_plugin PUBLIC scene_surface_mesh_item) @@ -96,6 +104,11 @@ else() polyhedron_demo_plugin(las_plugin LAS_io_plugin KEYWORDS Viewer PointSetProcessing Classification) target_link_libraries(las_plugin PUBLIC scene_points_with_normal_item CGAL::LASLIB_support) target_compile_features(las_plugin PRIVATE ${needed_cxx_features}) + if(MSVC) + target_compile_definitions( + las_plugin + PUBLIC "-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS") + endif() else() message( STATUS diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/LAS_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/LAS_io_plugin.cpp index d0e616f2108..ee4b373b160 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/LAS_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/LAS_io_plugin.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include using namespace CGAL::Three; class Polyhedron_demo_las_plugin : @@ -35,12 +36,32 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene) { Scene_points_with_normal_item* item; item = new Scene_points_with_normal_item(); - if(!item->read_las_point_set(in)) + Q_ASSERT(item->point_set() != nullptr); + + item->point_set()->clear(); + + ok = CGAL::read_LAS (in, *(item->point_set())) && !item->isEmpty(); + if(ok) + { + std::cerr << item->point_set()->info(); + + if (!item->point_set()->has_normal_map()) { - delete item; - ok = false; - return QList(); + item->setRenderingMode(Points); } + else{ + item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode()); + } + if (item->point_set()->check_colors()) + std::cerr << "-> Point set has colors" << std::endl; + + item->invalidateOpenGLBuffers(); + } + if(!ok) + { + delete item; + return QList(); + } item->setName(fileinfo.completeBaseName()); ok = true; @@ -63,14 +84,18 @@ bool Polyhedron_demo_las_plugin::save(QFileInfo fileinfo,QList(item); + Scene_points_with_normal_item* point_set_item = + qobject_cast(item); if(!point_set_item) return false; std::ofstream out(fileinfo.filePath().toUtf8().data()); items.pop_front(); - return point_set_item->write_las_point_set(out); + Q_ASSERT(point_set_item->point_set() != nullptr); + + point_set_item->point_set()->reset_indices(); + + return CGAL::write_LAS(out, *(point_set_item->point_set())); } diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index 17789593d49..a1d7baf7cc9 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -547,43 +547,6 @@ void Scene_points_with_normal_item::selectDuplicates() Q_EMIT itemChanged(); } -#ifdef CGAL_LINKED_WITH_LASLIB -// Loads point set from .LAS file -bool Scene_points_with_normal_item::read_las_point_set(std::istream& stream) -{ - Q_ASSERT(d->m_points != NULL); - - d->m_points->clear(); - - bool ok = CGAL::read_LAS (stream, *(d->m_points)) && !isEmpty(); - - std::cerr << d->m_points->info(); - - if (!d->m_points->has_normal_map()) - { - setRenderingMode(Points); - } - else{ - setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode()); - } - if (d->m_points->check_colors()) - std::cerr << "-> Point set has colors" << std::endl; - - invalidateOpenGLBuffers(); - return ok; -} - -// Write point set to .LAS file -bool Scene_points_with_normal_item::write_las_point_set(std::ostream& stream) const -{ - Q_ASSERT(d->m_points != NULL); - - d->m_points->reset_indices(); - - return CGAL::write_LAS(stream, *(d->m_points)); -} - -#endif // LAS // Loads point set from .PLY file bool Scene_points_with_normal_item::read_ply_point_set(std::istream& stream) diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h index 31e7cfdb324..7594dba0ef4 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h @@ -50,10 +50,6 @@ public: QMenu* contextMenu() Q_DECL_OVERRIDE; // IO -#ifdef CGAL_LINKED_WITH_LASLIB - bool read_las_point_set(std::istream& in); - bool write_las_point_set(std::ostream& out) const; -#endif // LAS bool read_ply_point_set(std::istream& in); bool write_ply_point_set(std::ostream& out, bool binary) const; bool read_off_point_set(std::istream& in);