diff --git a/Kinetic_surface_reconstruction/include/CGAL/Kinetic_surface_reconstruction_3.h b/Kinetic_surface_reconstruction/include/CGAL/Kinetic_surface_reconstruction_3.h index fda4baed868..caa18348c95 100644 --- a/Kinetic_surface_reconstruction/include/CGAL/Kinetic_surface_reconstruction_3.h +++ b/Kinetic_surface_reconstruction/include/CGAL/Kinetic_surface_reconstruction_3.h @@ -94,7 +94,10 @@ public: */ template Kinetic_surface_reconstruction_3(Point_range& points, - const NamedParameters& np = CGAL::parameters::default_values()) : m_points(points), m_ground_polygon_index(-1), m_kinetic_partition(np) {} + const NamedParameters& np = CGAL::parameters::default_values()) : m_points(points), m_ground_polygon_index(-1), m_kinetic_partition(np) { + m_verbose = parameters::choose_parameter(parameters::get_parameter(np, internal_np::verbose), false); + m_debug = parameters::choose_parameter(parameters::get_parameter(np, internal_np::debug), false); + } /*! \brief Detects shapes in the provided point cloud @@ -175,6 +178,8 @@ public: */ template std::size_t detect_planar_shapes(const CGAL_NP_CLASS& np = parameters::default_values()) { + m_verbose = parameters::choose_parameter(parameters::get_parameter(np, internal_np::verbose), m_verbose); + m_debug = parameters::choose_parameter(parameters::get_parameter(np, internal_np::debug), m_debug); if (m_verbose) std::cout << std::endl << "--- DETECTING PLANAR SHAPES: " << std::endl; @@ -346,7 +351,9 @@ public: } else edges[i] = m_face_neighbors_lcc[i]; } - std::cout << redirected << " faces redirected to below ground" << std::endl; + + if (m_verbose) + std::cout << redirected << " faces redirected to below ground" << std::endl; gc.solve(edges, m_face_area_lcc, m_cost_matrix, m_labels); @@ -400,13 +407,6 @@ public: gc.solve(m_face_neighbors_lcc, m_face_area_lcc, m_cost_matrix, m_labels); - std::size_t in = 0, out = 0; - for (std::size_t i : m_labels) - if (i == 0) out++; - else in++; - - std::cout << "total labels: " << m_labels.size() << " 0: " << out << " 1: " << in << std::endl; - reconstructed_model_polylist_lcc(pit, polyit, beta); } @@ -809,7 +809,8 @@ private: std::cout << "outside face" << std::endl; } - std::cout << "polygon regions " << polygon_regions.size() << std::endl; + if (m_verbose) + std::cout << "polygon regions " << polygon_regions.size() << std::endl; static bool saved = false; @@ -879,8 +880,7 @@ private: indices[j] = p.first->second; } - if (true) - std::reverse(indices.begin(), indices.end()); + std::reverse(indices.begin(), indices.end()); *polyit++ = std::move(indices); } @@ -2069,7 +2069,8 @@ private: cost_matrix[1][5] = 0; if (m_ground_polygon_index != -1 && ground) { - std::cout << "using estimated ground plane for reconstruction" << std::endl; + if (m_verbose) + std::cout << "using estimated ground plane for reconstruction" << std::endl; cost_matrix[0][0] = force; cost_matrix[0][1] = 0; cost_matrix[0][2] = 0; @@ -2082,25 +2083,6 @@ private: cost_matrix[1][4] = force; } } - -/* - void dump_volume(std::size_t i, const std::string& filename, const CGAL::Color &color) const { - std::vector faces; - m_kinetic_partition.faces(i, std::back_inserter(faces)); - - std::vector > pts(faces.size()); - std::vector col(faces.size(), color); - for (std::size_t j = 0; j < faces.size(); j++) { - m_kinetic_partition.vertices(faces[j], std::back_inserter(pts[j])); - } - - CGAL::KSR_3::dump_polygons(pts, col, filename); - } - - void dump_face(std::size_t i, const std::string& filename, const CGAL::Color& color) const { - std::vector face; - m_kinetic_partition.vertices(m_faces[i], std::back_inserter(face)); - }*/ }; } // namespace CGAL diff --git a/Kinetic_surface_reconstruction/test/Kinetic_surface_reconstruction/CMakeLists.txt b/Kinetic_surface_reconstruction/test/Kinetic_surface_reconstruction/CMakeLists.txt new file mode 100644 index 00000000000..4dacdb2739f --- /dev/null +++ b/Kinetic_surface_reconstruction/test/Kinetic_surface_reconstruction/CMakeLists.txt @@ -0,0 +1,39 @@ +# Created by the script cgal_create_CMakeLists. +# This is the CMake script for compiling a set of CGAL applications. + +cmake_minimum_required(VERSION 3.1...3.15) + +project(Kinetic_surface_reconstruction_Examples) + +set(CMAKE_CXX_STANDARD 17) + +find_package(CGAL REQUIRED COMPONENTS Core) +include(CGAL_CreateSingleSourceCGALProgram) + +find_package(Boost REQUIRED) +if(Boost_FOUND) + message(STATUS "Found Boost") + + find_package(Eigen3 3.1.0 REQUIRED) + if(Eigen3_FOUND) + message(STATUS "Found Eigen") + include(CGAL_Eigen_support) + + set(targets ksr_test) + + set(project_linked_libraries) + set(project_compilation_definitions) + + foreach(target ${targets}) + create_single_source_cgal_program("${target}.cpp") + if(TARGET ${target}) + target_link_libraries(${target} PUBLIC ${project_linked_libraries} CGAL::Eigen_support) + target_compile_definitions(${target} PUBLIC ${project_compilation_definitions}) + endif() + endforeach() + else() + message(ERROR "This program requires the Eigen library, and will not be compiled.") + endif() +else() + message(ERROR "This program requires the Boost library, and will not be compiled.") +endif() diff --git a/Kinetic_surface_reconstruction/test/Kinetic_surface_reconstruction/ksr_test.cpp b/Kinetic_surface_reconstruction/test/Kinetic_surface_reconstruction/ksr_test.cpp new file mode 100644 index 00000000000..5292b9b6e58 --- /dev/null +++ b/Kinetic_surface_reconstruction/test/Kinetic_surface_reconstruction/ksr_test.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using FT = typename Kernel::FT; +using Point_3 = typename Kernel::Point_3; +using Vector_3 = typename Kernel::Vector_3; +using Segment_3 = typename Kernel::Segment_3; + +using Point_set = CGAL::Point_set_3; +using Point_map = typename Point_set::Point_map; +using Normal_map = typename Point_set::Vector_map; + +using KSR = CGAL::Kinetic_surface_reconstruction_3; + +int main(const int argc, const char** argv) { + // Input. + + Point_set point_set; + CGAL::IO::read_point_set(CGAL::data_file_path("points_3/building.xyz"), point_set); + + auto param = CGAL::parameters::maximum_distance(0.05) + .maximum_angle(10) + .k_neighbors(12) + .minimum_region_size(50); + + // Algorithm. + KSR ksr(point_set, param); + + ksr.detection_and_partition(1, param); + + std::vector vtx; + std::vector > polylist; + + std::map external_nodes; + + bool failed = false; + + ksr.reconstruct(0.5, external_nodes, std::back_inserter(vtx), std::back_inserter(polylist)); + + if (vtx.size() != 10 && polylist.size() != 7) { + std::cerr << "reconstruction with external nodes set to outside provided wrong result: #vtx " << vtx.size() << " expected: 10, #polys: " << polylist.size() << " expected: 7" << std::endl; + failed = true; + } + + vtx.clear(); + polylist.clear(); + + ksr.reconstruct_with_ground(0.5, std::back_inserter(vtx), std::back_inserter(polylist)); + + if (vtx.size() != 22 && polylist.size() != 7) { + std::cerr << "reconstruction with ground set to outside provided wrong result: #vtx " << vtx.size() << " expected: 22, #polys: " << polylist.size() << " expected: 7" << std::endl; + failed = true; + } + + vtx.clear(); + polylist.clear(); + + ksr.reconstruct_with_ground(0.999, std::back_inserter(vtx), std::back_inserter(polylist)); + + if (vtx.size() != 0 && polylist.size() != 0) { + std::cerr << "reconstruction with high lambda provided wrong result: #vtx " << vtx.size() << " expected: 0, #polys: " << polylist.size() << " expected: 0" << std::endl; + failed = true; + } + + return failed ? EXIT_FAILURE : EXIT_SUCCESS; +}