From dbe38edf029653d4fda710a9088cb809321f3368 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Thu, 28 Nov 2024 12:50:24 +0100 Subject: [PATCH 1/8] switching initial_polygon_iedge_intersections and calculate_edge_intersection_time to epeck resolving potential non-convex partitions --- .../kinetic_partition.cpp | 5 +- .../include/CGAL/KSP/debug.h | 151 ++++++++++-------- .../include/CGAL/KSP_3/Data_structure.h | 59 +++---- .../include/CGAL/KSP_3/Finalizer.h | 16 +- .../include/CGAL/KSP_3/Initializer.h | 53 +++--- .../include/CGAL/KSP_3/Support_plane.h | 40 +++-- .../include/CGAL/Kinetic_space_partition_3.h | 11 +- 7 files changed, 177 insertions(+), 158 deletions(-) diff --git a/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp b/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp index dafdd2fb4787..6b1e39b34fb7 100644 --- a/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp +++ b/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp @@ -18,7 +18,7 @@ using Timer = CGAL::Real_timer; int main(int argc, char** argv) { // Reading polygons from file - std::string input_filename = (argc > 1 ? argv[1] : "data/test-4-rnd-polygons-4-6.off"); + std::string input_filename = (argc > 1 ? argv[1] : "data/issue_8624 - Copy.off"); std::ifstream input_file(input_filename); std::vector input_vertices; @@ -35,7 +35,7 @@ int main(int argc, char** argv) std::cout << "--- INPUT STATS: \n* number of polygons: " << input_faces.size() << std::endl; // Parameters. - const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 1); + const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 2); // Initialization of Kinetic_space_partition_3 object. // 'debug' set to true exports intermediate results into files in the working directory. @@ -45,6 +45,7 @@ int main(int argc, char** argv) // Providing input polygons. ksp.insert(input_vertices, input_faces); + Timer timer; timer.start(); diff --git a/Kinetic_space_partition/include/CGAL/KSP/debug.h b/Kinetic_space_partition/include/CGAL/KSP/debug.h index d2f8b408ea37..6177e94f9298 100644 --- a/Kinetic_space_partition/include/CGAL/KSP/debug.h +++ b/Kinetic_space_partition/include/CGAL/KSP/debug.h @@ -50,6 +50,11 @@ get_idx_color(std::size_t idx) { static_cast(rand.get_int(32, 192))); } +CGAL::IO::Color get_color(std::size_t idx) { + CGAL::Random rand(static_cast(idx)); + return CGAL::IO::Color(rand.get_int(32, 192), rand.get_int(32, 192), rand.get_int(32, 192)); +} + template void dump_intersection_edges(const DS& data, const std::string tag = std::string()) { @@ -110,12 +115,12 @@ void dump_2d_surface_mesh( using Mesh = CGAL::Surface_mesh; using Face_index = typename Mesh::Face_index; using Vertex_index = typename Mesh::Vertex_index; - using Int_map = typename Mesh::template Property_map; + using Int_map = typename Mesh::template Property_map; Mesh mesh; - Int_map red = mesh.template add_property_map("red", 0).first; - Int_map green = mesh.template add_property_map("green", 0).first; - Int_map blue = mesh.template add_property_map("blue", 0).first; + Int_map red = mesh.template add_property_map("red", 0).first; + Int_map green = mesh.template add_property_map("green", 0).first; + Int_map blue = mesh.template add_property_map("blue", 0).first; std::vector vertices; std::vector map_vertices; @@ -332,7 +337,7 @@ class Saver { { } void initialize(std::stringstream& stream) const { - stream.precision(20); + stream.precision(17); } void export_points_2( @@ -495,7 +500,8 @@ class Saver { stream << polygon.size() << " "; for (std::size_t j = 0; j < polygon.size(); ++j) stream << i++ << " "; - stream << get_idx_color(polygon_id) << std::endl; + auto col = get_idx_color(polygon_id); + stream << int(col.r()) << " " << int(col.g()) << " " << int(col.b()) << std::endl; ++polygon_id; } save(stream, file_name + ".ply"); @@ -528,7 +534,8 @@ class Saver { stream << polygon.size() << " "; for (std::size_t j = 0; j < polygon.size(); ++j) stream << i++ << " "; - stream << get_idx_color(region_id) << std::endl; + auto col = get_idx_color(region_id); + stream << int(col.r()) << " " << int(col.g()) << " " << int(col.b()) << std::endl; } ++region_id; } @@ -700,17 +707,16 @@ class Saver { const std::size_t size) const { stream << - "ply" + std::string(_NL_) + "" << - "format ascii 1.0" + std::string(_NL_) + "" << - "element vertex " << size << "" + std::string(_NL_) + "" << - "property double x" + std::string(_NL_) + "" << - "property double y" + std::string(_NL_) + "" << - "property double z" + std::string(_NL_) + "" << - "property uchar red" + std::string(_NL_) + "" << - "property uchar green" + std::string(_NL_) + "" << - "property uchar blue" + std::string(_NL_) + "" << - "property uchar alpha" + std::string(_NL_) + "" << - "end_header" + std::string(_NL_) + ""; + "ply" << std::endl << + "format ascii 1.0" << std::endl << + "element vertex " << size << std::endl << + "property double x" << std::endl << + "property double y" << std::endl << + "property double z" << std::endl << + "property uchar red" << std::endl << + "property uchar green" << std::endl << + "property uchar blue" << std::endl << + "end_header" << std::endl; } void add_ply_header_normals( @@ -718,16 +724,16 @@ class Saver { const std::size_t size) const { stream << - "ply" + std::string(_NL_) + "" << - "format ascii 1.0" + std::string(_NL_) + "" << - "element vertex " << size << "" + std::string(_NL_) + "" << - "property double x" + std::string(_NL_) + "" << - "property double y" + std::string(_NL_) + "" << - "property double z" + std::string(_NL_) + "" << - "property double nx" + std::string(_NL_) + "" << - "property double ny" + std::string(_NL_) + "" << - "property double nz" + std::string(_NL_) + "" << - "end_header" + std::string(_NL_) + ""; + "ply" << std::endl << + "format ascii 1.0" << std::endl << + "element vertex " << size << std::endl << + "property double x" << std::endl << + "property double y" << std::endl << + "property double z" << std::endl << + "property double nx" << std::endl << + "property double ny" << std::endl << + "property double nz" << std::endl << + "end_header" << std::endl; } void add_ply_header_normals_colors( @@ -735,20 +741,19 @@ class Saver { const std::size_t size) const { stream << - "ply" + std::string(_NL_) + "" << - "format ascii 1.0" + std::string(_NL_) + "" << - "element vertex " << size << "" + std::string(_NL_) + "" << - "property double x" + std::string(_NL_) + "" << - "property double y" + std::string(_NL_) + "" << - "property double z" + std::string(_NL_) + "" << - "property double nx" + std::string(_NL_) + "" << - "property double ny" + std::string(_NL_) + "" << - "property double nz" + std::string(_NL_) + "" << - "property uchar red" + std::string(_NL_) + "" << - "property uchar green" + std::string(_NL_) + "" << - "property uchar blue" + std::string(_NL_) + "" << - "property uchar alpha" + std::string(_NL_) + "" << - "end_header" + std::string(_NL_) + ""; + "ply" << std::endl << + "format ascii 1.0" << std::endl << + "element vertex " << size << std::endl << + "property double x" << std::endl << + "property double y" << std::endl << + "property double z" << std::endl << + "property double nx" << std::endl << + "property double ny" << std::endl << + "property double nz" << std::endl << + "property uchar red" << std::endl << + "property uchar green" << std::endl << + "property uchar blue" << std::endl << + "end_header" << std::endl; } void add_ply_header_regions( @@ -775,19 +780,19 @@ class Saver { const std::size_t num_faces) const { stream << - "ply" + std::string(_NL_) + "" << - "format ascii 1.0" + std::string(_NL_) + "" << - "element vertex " << num_vertices << "" + std::string(_NL_) + "" << - "property double x" + std::string(_NL_) + "" << - "property double y" + std::string(_NL_) + "" << - "property double z" + std::string(_NL_) + "" << - "element face " << num_faces << "" + std::string(_NL_) + "" << - "property list uchar int vertex_indices" + std::string(_NL_) + "" << - "property uchar red" + std::string(_NL_) + "" << - "property uchar green" + std::string(_NL_) + "" << - "property uchar blue" + std::string(_NL_) + "" << - "property uchar alpha" + std::string(_NL_) + "" << - "end_header" + std::string(_NL_) + ""; + "ply" << std::endl << + "format ascii 1.0" << std::endl << + "element vertex " << num_vertices << std::endl << + "property double x" << std::endl << + "property double y" << std::endl << + "property double z" << std::endl << + "element face " << num_faces << std::endl << + "property list uchar int vertex_indices" << std::endl << + "property uchar red" << std::endl << + "property uchar green" << std::endl << + "property uchar blue" << std::endl << + "property uchar alpha" << std::endl << + "end_header" << std::endl; } void add_ply_header_mesh_no_color( @@ -796,15 +801,15 @@ class Saver { const std::size_t num_faces) const { stream << - "ply" + std::string(_NL_) + "" << - "format ascii 1.0" + std::string(_NL_) + "" << - "element vertex " << num_vertices << "" + std::string(_NL_) + "" << - "property double x" + std::string(_NL_) + "" << - "property double y" + std::string(_NL_) + "" << - "property double z" + std::string(_NL_) + "" << - "element face " << num_faces << "" + std::string(_NL_) + "" << - "property list ushort int vertex_indices" + std::string(_NL_) + "" << - "end_header" + std::string(_NL_) + ""; + "ply" << std::endl << + "format ascii 1.0" << std::endl << + "element vertex " << num_vertices << std::endl << + "property double x" << std::endl << + "property double y" << std::endl << + "property double z" << std::endl << + "element face " << num_faces << std::endl << + "property list ushort int vertex_indices" << std::endl << + "end_header" << std::endl; } }; @@ -1015,14 +1020,22 @@ void dump_points(const std::vector& pts, const std::vector template void dump_ifaces(const DS& data, const std::string tag = std::string()) { + + using From_exact = CGAL::Cartesian_converter; + From_exact from_exact; // write all polygons into a separate ply with support plane index and iface index - for (std::size_t sp_idx = data.number_of_support_planes(); sp_idx++;) { + for (std::size_t sp_idx = 0; sp_idx < data.number_of_support_planes(); sp_idx++) { for (typename DS::IFace f : data.support_plane(sp_idx).ifaces()) { - Saver saver; std::vector > pts(1); - for (auto v : data.igraph().face(f).vertices) - pts.back().push_back(data.igraph().point_3(v)); - saver.export_polygon_soup_3(pts, tag + "-" + std::to_string(sp_idx) + "-" + std::to_string(f)); + std::vector cols; + cols.push_back(get_color(std::size_t(f))); + Saver saver; + for (auto v : data.igraph().face(f).vertices) { + typename DS::IkPoint_3 ip = data.igraph().point_3(v); + Point_3 p = from_exact(ip); + pts.back().push_back(p); + } + saver.export_polygon_soup_3(pts, cols, tag + "-" + std::to_string(sp_idx) + "-" + std::to_string(f)); } } } diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Data_structure.h b/Kinetic_space_partition/include/CGAL/KSP_3/Data_structure.h index 7ba219c5fa6d..85c93daeb05a 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Data_structure.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Data_structure.h @@ -409,11 +409,11 @@ class Data_structure { else event.face = faces.first; - for (std::size_t i = 0; i < sp.data().original_directions.size(); i++) { - if (source_idx == uninitialized && sp.data().original_directions[i] > to_source) + for (std::size_t i = 0; i < sp.data().exact_directions.size(); i++) { + if (source_idx == uninitialized && sp.data().exact_directions[i] > to_source2) source_idx = i; - if (target_idx == uninitialized && sp.data().original_directions[i] > to_target) + if (target_idx == uninitialized && sp.data().exact_directions[i] > to_target2) target_idx = i; } @@ -452,7 +452,7 @@ class Data_structure { // Shooting rays to find intersection with line of IEdge typename Intersection_kernel::Line_3 l3 = m_intersection_graph.line_3(edge); - const typename Intersection_kernel::Line_2 l = sp.to_2d(l3); + const typename Intersection_kernel::Line_2 l = typename Intersection_kernel::Line_2(s2, t2); for (std::size_t i = 0; i < num; i++) { std::size_t idx = (i + source_idx) % sp.data().original_directions.size(); const auto result = CGAL::intersection(l, sp.data().original_rays[idx]); @@ -465,8 +465,6 @@ class Data_structure { if (CGAL::assign(p, result)) { IkFT l = CGAL::approximate_sqrt(sp.data().original_vectors[idx].squared_length()); - IkFT l2 = from_exact(CGAL::approximate_sqrt((p - sp.data().original_rays[idx].point(0)).squared_length())); - IkFT l3 = (p - sp.data().original_rays[idx].point(0)) * sp.data().original_rays[idx].to_vector(); time[i] = l3; CGAL_assertion(0 <= time[i]); @@ -483,39 +481,39 @@ class Data_structure { // Source edge time std::size_t adjacent = (source_idx + sp.data().original_vertices.size() - 1) % sp.data().original_vertices.size(); - Vector_2 dir = sp.data().original_vertices[source_idx] - sp.data().original_vertices[adjacent]; + IkVector_2 dir = sp.data().exact_vertices[source_idx] - sp.data().exact_vertices[adjacent]; dir = dir / CGAL::approximate_sqrt(dir * dir); // Orthogonal direction matching the direction of the adjacent vertices - dir = Vector_2(dir.y(), -dir.x()); + dir = IkVector_2(dir.y(), -dir.x()); // Moving speed matches the speed of adjacent vertices - FT speed = (dir * sp.data().original_vectors[source_idx]); + IkFT speed = (dir * sp.data().original_rays[source_idx].to_vector()); if (speed < 0) speed = -speed; // Distance from edge to endpoint of iedge - FT dist = (s - sp.data().original_vertices[source_idx]) * dir; + IkFT dist = (s2 - sp.data().exact_vertices[source_idx]) * dir; edge_time[0] = dist / speed; // Target edge time - adjacent = (target_idx + sp.data().original_vertices.size() - 1) % sp.data().original_vertices.size(); - dir = sp.data().original_vertices[target_idx] - sp.data().original_vertices[adjacent]; + adjacent = (target_idx + sp.data().exact_vertices.size() - 1) % sp.data().exact_vertices.size(); + dir = sp.data().exact_vertices[target_idx] - sp.data().exact_vertices[adjacent]; dir = dir / CGAL::approximate_sqrt(dir * dir); // Orthogonal direction matching the direction of the adjacent vertices - dir = Vector_2(dir.y(), -dir.x()); + dir = IkVector_2(dir.y(), -dir.x()); // Moving speed matches the speed of adjacent vertices - speed = (dir * sp.data().original_vectors[target_idx]); + speed = (dir * sp.data().original_rays[target_idx].to_vector()); if (speed < 0) speed = -speed; // Distance from edge to endpoint of iedge - dist = (t - sp.data().original_vertices[target_idx]) * dir; + dist = (t2 - sp.data().exact_vertices[target_idx]) * dir; edge_time[1] = dist / speed; @@ -565,6 +563,7 @@ class Data_structure { for (IEdge edge : border) { Face_event fe; IkFT t = calculate_edge_intersection_time(sp_idx, edge, fe); + if (t > 0) { queue.push(fe); } @@ -912,8 +911,8 @@ class Data_structure { } } - void add_input_polygon( const std::size_t support_plane_idx, const std::vector& input_indices, const std::vector& polygon) { - std::vector< std::pair > points; + void add_input_polygon( const std::size_t support_plane_idx, const std::vector& input_indices, const std::vector& polygon) { + std::vector< std::pair > points; points.reserve(polygon.size()); for (const auto& point : polygon) { points.push_back(std::make_pair(point, true)); @@ -921,9 +920,10 @@ class Data_structure { CGAL_assertion(points.size() == polygon.size()); preprocess(points); + sort_points_by_direction(points); support_plane(support_plane_idx). - add_input_polygon(points, input_indices); + add_input_polygon(points, input_indices); for (const std::size_t input_index : input_indices) { m_input_polygon_map[input_index] = support_plane_idx; m_sp2input_polygon[support_plane_idx].insert(input_index); @@ -976,14 +976,17 @@ class Data_structure { const auto& q = points[i].first; const auto& r = points[ip].first; - Vector_2 vec1(q, r); - Vector_2 vec2(q, p); + using Vector = typename CGAL::Kernel_traits::type::Vector_2; + using Direction = typename CGAL::Kernel_traits::type::Direction_2; + + Vector vec1(q, r); + Vector vec2(q, p); vec1 = KSP::internal::normalize(vec1); vec2 = KSP::internal::normalize(vec2); - const Direction_2 dir1(vec1); - const Direction_2 dir2(vec2); - const FT angle = KSP::internal::angle_2(dir1, dir2); + const Direction dir1(vec1); + const Direction dir2(vec2); + const auto angle = KSP::internal::angle_2(dir1, dir2); if (angle > min_angle) polygon.push_back(points[i]); } @@ -993,9 +996,10 @@ class Data_structure { template void sort_points_by_direction(std::vector& points) const { + From_exact from_exact; FT x = FT(0), y = FT(0); FT num = 0; for (const auto& pair : points) { - const auto& point = pair.first; + const auto& point = from_exact(pair.first); x += point.x(); y += point.y(); num += 1; @@ -1006,8 +1010,8 @@ class Data_structure { std::sort(points.begin(), points.end(), [&](const Pair& a, const Pair& b) -> bool { - const Segment_2 sega(mid, a.first); - const Segment_2 segb(mid, b.first); + const Segment_2 sega(mid, from_exact(a.first)); + const Segment_2 segb(mid, from_exact(b.first)); return ( Direction_2(sega) < Direction_2(segb) ); }); } @@ -1395,10 +1399,9 @@ class Data_structure { return support_plane(support_plane_idx).to_2d(point_3); } -/* IkPoint_2 to_2d(const std::size_t support_plane_idx, const IkPoint_3& point_3) const { return support_plane(support_plane_idx).to_2d(point_3); - }*/ + } Point_2 point_2(const PVertex& pvertex) const { return support_plane(pvertex).point_2(pvertex.second); diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Finalizer.h b/Kinetic_space_partition/include/CGAL/KSP_3/Finalizer.h index 8b1c033e8b44..caa0b566ba8b 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Finalizer.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Finalizer.h @@ -117,6 +117,13 @@ class Finalizer { merge_facets_connected_components(); +/* + if (m_parameters.debug) { + for (std::size_t sp = 0; sp < m_data.number_of_support_planes(); sp++) { + dump_2d_surface_mesh(m_data, sp, m_data.prefix() + "after-merge-sp" + std::to_string(sp)); + } + }*/ + create_volumes(); if (m_parameters.debug) { @@ -336,13 +343,10 @@ class Finalizer { } // Propagate both queues if volumes on either side of the pface are not segmented. - for (std::size_t i = 0; i < 2; i++) { - if (volume_indices[i] != uninitialized) { - while (!queue[i].empty()) { + for (std::size_t i = 0; i < 2; i++) + if (volume_indices[i] != uninitialized) + while (!queue[i].empty()) propagate_volume(queue[i], volume_indices[i], volumes, map_volumes); - } - } - } } void propagate_volume(std::queue >& queue, std::size_t volume_index, std::vector& volumes, std::map >& map_volumes) { diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h index 74b29a5d4611..aa057c46dfb1 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h @@ -402,7 +402,6 @@ class Initializer { typename Intersection_kernel::Point_2 a(sp.to_2d(m_data.point_3(m_data.source(pair.second[0])))); typename Intersection_kernel::Point_2 b(sp.to_2d(m_data.point_3(m_data.target(pair.second[0])))); typename Intersection_kernel::Line_2 exact_line(a, b); - Line_2 l = from_exact(exact_line); typename Intersection_kernel::Vector_2 ldir = exact_line.to_vector(); ldir = (typename Intersection_kernel::FT(1.0) / CGAL::approximate_sqrt(ldir * ldir)) * ldir; @@ -413,35 +412,33 @@ class Initializer { typename Intersection_kernel::FT emin = (std::numeric_limits::max)(); typename Intersection_kernel::FT emax = -(std::numeric_limits::max)(); FT min_speed = (std::numeric_limits::max)(), max_speed = -(std::numeric_limits::max)(); - - CGAL::Oriented_side last_side = l.oriented_side(sp.data().original_vertices.back()); + CGAL::Oriented_side last_side = exact_line.oriented_side(sp.data().exact_vertices.back()); Point_2 minp, maxp; typename Intersection_kernel::Point_2 eminp, emaxp; // Map polygon to line and get min&max projection for (std::size_t v = 0; v < sp.data().original_vertices.size(); v++) { - const Point_2& p = sp.data().original_vertices[v]; - - CGAL::Oriented_side s = l.oriented_side(p); + CGAL::Oriented_side s = exact_line.oriented_side(sp.data().exact_vertices[v]); if (last_side != s) { // Fetch former point to add segment. - const Point_2& prev = sp.data().original_vertices[(v + sp.data().original_vertices.size() - 1) % sp.data().original_vertices.size()]; + auto eprev = sp.data().exact_vertices[(v + sp.data().exact_vertices.size() - 1) % sp.data().exact_vertices.size()]; const Vector_2 edge_dir = sp.original_edge_direction((v + sp.data().original_vertices.size() - 1) % sp.data().original_vertices.size(), v); - typename Intersection_kernel::Segment_2 seg(to_exact(prev), to_exact(p)); + + typename Intersection_kernel::Segment_2 seg(eprev, sp.data().exact_vertices[v]); const auto result = CGAL::intersection(seg, exact_line); + typename Intersection_kernel::Point_2 intersection; if (result && CGAL::assign(intersection, result)) { typename Intersection_kernel::FT eproj = (intersection - exact_line.point()) * ldir; - //FT proj = to_inexact(eproj); + if (eproj < emin) { eminp = intersection; emin = eproj; minp = from_exact(intersection); //min = proj; - typename Intersection_kernel::FT p = dir * edge_dir; - assert(p != 0); - min_speed = CGAL::approximate_sqrt(edge_dir * edge_dir) / from_exact(p); + FT p = dir * edge_dir; + min_speed = CGAL::approximate_sqrt(edge_dir * edge_dir) / p; } if (emax < eproj) { emaxp = intersection; @@ -449,7 +446,7 @@ class Initializer { maxp = from_exact(intersection); //max = proj; typename Intersection_kernel::FT p = dir * edge_dir; - assert(p != 0); + CGAL_assertion(p != 0); max_speed = CGAL::approximate_sqrt(edge_dir * edge_dir) / from_exact(p); } } @@ -499,7 +496,7 @@ class Initializer { typename Intersection_graph::Kinetic_interval& kinetic_interval = m_data.igraph().kinetic_interval(e, sp_idx); crossing_iedges.push_back(e); - if (emin > s) { + if (emin > s || (min_speed != min_speed)) { typename Intersection_kernel::FT bary_edge_exact = (emin - s) / (t - s); FT bary_edge = from_exact((emin - s) / (t - s)); CGAL_assertion(bary_edge_exact >= 0); @@ -511,7 +508,7 @@ class Initializer { kinetic_interval.push_back(std::pair(0, 0)); } - if (t > emax) { + if (t > emax || (max_speed != max_speed)) { typename Intersection_kernel::FT bary_edge_exact = (emax - s) / (t - s); FT bary_edge = from_exact((emax - s) / (t - s)); CGAL_assertion(0 <= bary_edge_exact && bary_edge_exact <= 1); @@ -665,7 +662,7 @@ class Initializer { } void add_input_polygons() { - using Polygon_2 = std::vector; + using Polygon_2 = std::vector; using Indices = std::vector; std::map< std::size_t, std::pair > polygons; @@ -689,20 +686,19 @@ class Initializer { } template - void convert_polygon(const std::size_t support_plane_idx, const PointRange& polygon_3, std::vector& polygon_2) { + void convert_polygon(const std::size_t support_plane_idx, const PointRange& polygon_3, std::vector& polygon_2) { polygon_2.clear(); polygon_2.reserve(polygon_3.size()); + To_exact to_exact; for (const auto& point : polygon_3) { - const Point_3 converted(static_cast(point.x()), static_cast(point.y()), static_cast(point.z())); - - polygon_2.push_back(m_data.support_plane(support_plane_idx).to_2d(converted)); + polygon_2.push_back(m_data.support_plane(support_plane_idx).to_2d(to_exact(point))); } CGAL_assertion(polygon_2.size() == polygon_3.size()); } - void preprocess_polygons(std::map< std::size_t, std::pair, std::vector > >& polygons) { + void preprocess_polygons(std::map< std::size_t, std::pair, std::vector > >& polygons) { std::size_t input_index = 0; - std::vector polygon_2; + std::vector polygon_2; std::vector input_indices; for (std::size_t i = 0; i < m_input_polygons.size(); i++) { bool is_added = true; @@ -729,8 +725,8 @@ class Initializer { } } - void merge_polygons(const std::size_t support_plane_idx, const std::vector& polygon_a, std::vector& polygon_b) { - const bool is_debug = false; + void merge_polygons(const std::size_t support_plane_idx, const std::vector& polygon_a, std::vector& polygon_b) { + const bool is_debug = true; CGAL_assertion(support_plane_idx >= 6); if (is_debug) { std::cout << std::endl << "support plane idx: " << support_plane_idx << std::endl; @@ -743,18 +739,19 @@ class Initializer { } // Create the merged polygon. - std::vector merged; + std::vector merged; create_merged_polygon(points, merged); if (is_debug) { std::cout << "merged polygon: " << std::endl; + From_exact from_exact; for (std::size_t i = 0; i < merged.size(); ++i) { const std::size_t ip = (i + 1) % merged.size(); const auto& p = merged[i]; const auto& q = merged[ip]; std::cout << "2 " << - m_data.to_3d(support_plane_idx, p) << " " << - m_data.to_3d(support_plane_idx, q) << std::endl; + m_data.to_3d(support_plane_idx, from_exact(p)) << " " << + m_data.to_3d(support_plane_idx, from_exact(q)) << std::endl; } } @@ -762,7 +759,7 @@ class Initializer { polygon_b = merged; } - void create_merged_polygon(const std::vector& points, std::vector& merged) const { + void create_merged_polygon(const std::vector& points, std::vector& merged) const { merged.clear(); CGAL::convex_hull_2(points.begin(), points.end(), std::back_inserter(merged)); diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Support_plane.h b/Kinetic_space_partition/include/CGAL/KSP_3/Support_plane.h index b15330727372..3ce90c8c7a76 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Support_plane.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Support_plane.h @@ -119,8 +119,10 @@ class Support_plane { std::vector iedges; std::vector original_vertices; + std::vector exact_vertices; std::vector original_vectors; std::vector original_directions; + std::vector exact_directions; std::vector original_rays; FT distance_tolerance; @@ -345,11 +347,12 @@ class Support_plane { CGAL_assertion(is_valid_polygon(points)); To_exact to_exact; + From_exact from_exact; CGAL_assertion(points.size() >= 3); std::vector tris(points.size() - 2); for (std::size_t i = 2; i < points.size(); i++) - tris[i - 2] = Triangle_2(points[0].first, points[i - 1].first, points[i].first); + tris[i - 2] = Triangle_2(from_exact(points[0].first), from_exact(points[i - 1].first), from_exact(points[i].first)); m_data->centroid = CGAL::centroid(tris.begin(), tris.end(), CGAL::Dimension_tag<2>()); @@ -358,22 +361,23 @@ class Support_plane { CGAL_assertion(n >= 3); vertices.reserve(n); m_data->original_vertices.resize(n); + m_data->exact_vertices.resize(n); m_data->original_vectors.resize(n); m_data->original_directions.resize(n); + m_data->exact_directions.resize(n); m_data->original_rays.resize(n); FT sum_length = FT(0); - std::vector directions; + std::vector directions; directions.reserve(n); - std::vector > dir_vec; + std::vector > dir_vec; FT num = 0; for (const auto& pair : points) { const auto& point = pair.first; - directions.push_back(Vector_2(m_data->centroid, point)); - const FT length = static_cast( - CGAL::approximate_sqrt(CGAL::abs(directions.back() * directions.back()))); + directions.push_back(typename Intersection_kernel::Vector_2(to_exact(m_data->centroid), point)); + const FT length = CGAL::sqrt(CGAL::abs(from_exact(directions.back() * directions.back()))); sum_length += length; num += 1; } @@ -382,21 +386,23 @@ class Support_plane { dir_vec.reserve(n); for (std::size_t i = 0; i < n; i++) - dir_vec.push_back(std::pair(i, directions[i])); + dir_vec.push_back(std::pair(i, directions[i])); std::sort(dir_vec.begin(), dir_vec.end(), - [&](const std::pair& a, - const std::pair& b) -> bool { + [&](const std::pair& a, + const std::pair& b) -> bool { return a.second < b.second; }); for (std::size_t i = 0; i < n; ++i) { const auto& point = points[dir_vec[i].first].first; - const auto vi = m_data->mesh.add_vertex(point); - m_data->original_vertices[i] = point; - m_data->original_vectors[i] = directions[dir_vec[i].first] / sum_length; - m_data->original_directions[i] = Direction_2(directions[dir_vec[i].first]); - m_data->original_rays[i] = typename Intersection_kernel::Ray_2(to_exact(point), to_exact(m_data->original_vectors[i])); + const auto vi = m_data->mesh.add_vertex(from_exact(point)); + m_data->original_vertices[i] = from_exact(point); + m_data->exact_vertices[i] = point; + m_data->original_vectors[i] = from_exact(directions[dir_vec[i].first]) / sum_length; + m_data->original_directions[i] = Direction_2(from_exact(directions[dir_vec[i].first])); + m_data->exact_directions[i] = dir_vec[i].second; + m_data->original_rays[i] = typename Intersection_kernel::Ray_2(point, directions[dir_vec[i].first] / sum_length); m_data->v_original_map[vi] = true; vertices.push_back(vi); } @@ -448,20 +454,22 @@ class Support_plane { template bool is_simple_polygon(const std::vector& points) const { + From_exact from_exact; std::vector polygon; polygon.reserve(points.size()); for (const auto& pair : points) - polygon.push_back(pair.first); + polygon.push_back(from_exact(pair.first)); CGAL_assertion(polygon.size() == points.size()); return CGAL::is_simple_2(polygon.begin(), polygon.end()); } template bool is_convex_polygon(const std::vector& points) const { + From_exact from_exact; std::vector polygon; polygon.reserve(points.size()); for (const auto& pair : points) - polygon.push_back(pair.first); + polygon.push_back(from_exact(pair.first)); CGAL_assertion(polygon.size() == points.size()); return CGAL::is_convex_2(polygon.begin(), polygon.end()); } diff --git a/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h b/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h index e76a9b26cf15..3fa3ce4c371a 100644 --- a/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h +++ b/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h @@ -432,7 +432,7 @@ class Kinetic_space_partition_3 { m_input2regularized.push_back(m_input_planes.size()); m_regularized2input.push_back(std::vector()); m_regularized2input.back().push_back(p); - m_input_planes.push_back(to_exact(pl)); + m_input_planes.push_back(exact_pl); m_input_centroids.push_back(c); m_input_polygons.push_back(std::vector(ch.size())); @@ -491,7 +491,7 @@ class Kinetic_space_partition_3 { m_parameters.max_octree_node_size = parameters::choose_parameter( parameters::get_parameter(np, internal_np::max_octree_node_size), 40); - std::cout.precision(20); + std::cout.precision(17); if (m_input_polygons.size() == 0) { std::cout << "Warning: Your input is empty!"; return; @@ -581,12 +581,6 @@ class Kinetic_space_partition_3 { finalization_time = 0; conformal_time = 0; - /* - if (m_parameters.debug) - if (boost::filesystem::is_directory("volumes/")) - for (boost::filesystem::directory_iterator end_dir_it, it("volumes/"); it != end_dir_it; ++it) - boost::filesystem::remove_all(it->path());*/ - for (std::size_t idx : m_partitions) { Sub_partition& partition = m_partition_nodes[idx]; timer.reset(); @@ -618,7 +612,6 @@ class Kinetic_space_partition_3 { if (m_parameters.verbose) { std::cout << "* propagation finished" << std::endl; - std::cout << "* number of events handled: " << m_num_events << std::endl; } if (m_parameters.verbose) { From 90cb053a6d37811c5adcc793b75720a9528bb798 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Thu, 28 Nov 2024 14:43:58 +0100 Subject: [PATCH 2/8] revert changes to example --- .../examples/Kinetic_space_partition/kinetic_partition.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp b/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp index 6b1e39b34fb7..dafdd2fb4787 100644 --- a/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp +++ b/Kinetic_space_partition/examples/Kinetic_space_partition/kinetic_partition.cpp @@ -18,7 +18,7 @@ using Timer = CGAL::Real_timer; int main(int argc, char** argv) { // Reading polygons from file - std::string input_filename = (argc > 1 ? argv[1] : "data/issue_8624 - Copy.off"); + std::string input_filename = (argc > 1 ? argv[1] : "data/test-4-rnd-polygons-4-6.off"); std::ifstream input_file(input_filename); std::vector input_vertices; @@ -35,7 +35,7 @@ int main(int argc, char** argv) std::cout << "--- INPUT STATS: \n* number of polygons: " << input_faces.size() << std::endl; // Parameters. - const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 2); + const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 1); // Initialization of Kinetic_space_partition_3 object. // 'debug' set to true exports intermediate results into files in the working directory. @@ -45,7 +45,6 @@ int main(int argc, char** argv) // Providing input polygons. ksp.insert(input_vertices, input_faces); - Timer timer; timer.start(); From 52c166871ecdc36365b23b1cea314fc9488d8a63 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Thu, 28 Nov 2024 14:45:56 +0100 Subject: [PATCH 3/8] removed unused variable --- .../include/CGAL/Kinetic_space_partition_3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h b/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h index 3fa3ce4c371a..adc9caf86834 100644 --- a/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h +++ b/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h @@ -606,7 +606,7 @@ class Kinetic_space_partition_3 { // Propagation. Propagation propagation(*partition.m_data, m_parameters); - std::size_t m_num_events = propagation.propagate(k); + propagation.propagate(k); partition_time += timer.time(); From 7533828c78a49bf6e38cb4b799585524e9888f8c Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Thu, 28 Nov 2024 15:06:18 +0100 Subject: [PATCH 4/8] added test --- .../include/CGAL/KSP_3/Initializer.h | 3 - .../include/CGAL/Kinetic_space_partition_3.h | 4 +- .../Kinetic_space_partition/CMakeLists.txt | 2 +- .../data/issue_8624.off | 777 ++++++++++++++++++ .../Kinetic_space_partition/issue_8624.cpp | 80 ++ 5 files changed, 860 insertions(+), 6 deletions(-) create mode 100644 Kinetic_space_partition/test/Kinetic_space_partition/data/issue_8624.off create mode 100644 Kinetic_space_partition/test/Kinetic_space_partition/issue_8624.cpp diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h index aa057c46dfb1..944d6e8ca230 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h @@ -436,7 +436,6 @@ class Initializer { eminp = intersection; emin = eproj; minp = from_exact(intersection); - //min = proj; FT p = dir * edge_dir; min_speed = CGAL::approximate_sqrt(edge_dir * edge_dir) / p; } @@ -444,9 +443,7 @@ class Initializer { emaxp = intersection; emax = eproj; maxp = from_exact(intersection); - //max = proj; typename Intersection_kernel::FT p = dir * edge_dir; - CGAL_assertion(p != 0); max_speed = CGAL::approximate_sqrt(edge_dir * edge_dir) / from_exact(p); } } diff --git a/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h b/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h index adc9caf86834..c414ec4a88fa 100644 --- a/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h +++ b/Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h @@ -1267,12 +1267,12 @@ class Kinetic_space_partition_3 { if (pos && neg) { std::cout << "face is not convex" << std::endl; - exit(1); + CGAL_assertion(false); } if (!pos && !neg) { std::cout << "face is degenerated" << std::endl; - exit(1); + CGAL_assertion(false); } if (neg) { diff --git a/Kinetic_space_partition/test/Kinetic_space_partition/CMakeLists.txt b/Kinetic_space_partition/test/Kinetic_space_partition/CMakeLists.txt index 39ac1e88597d..038b9fa4615b 100644 --- a/Kinetic_space_partition/test/Kinetic_space_partition/CMakeLists.txt +++ b/Kinetic_space_partition/test/Kinetic_space_partition/CMakeLists.txt @@ -19,7 +19,7 @@ if(Boost_FOUND) message(STATUS "Found Eigen") include(CGAL_Eigen_support) - set(targets kinetic_3d_test_all) + set(targets kinetic_3d_test_all issue_8624) set(project_linked_libraries) set(project_compilation_definitions) diff --git a/Kinetic_space_partition/test/Kinetic_space_partition/data/issue_8624.off b/Kinetic_space_partition/test/Kinetic_space_partition/data/issue_8624.off new file mode 100644 index 000000000000..67cd2a1b0d00 --- /dev/null +++ b/Kinetic_space_partition/test/Kinetic_space_partition/data/issue_8624.off @@ -0,0 +1,777 @@ +OFF +620 155 0 +868.585 442.974 10 +871.72 445.821 10 +871.72 445.821 -10 +868.585 442.974 -10 +871.138 444.964 10 +879.142 451.345 10 +879.142 451.345 -10 +871.138 444.964 -10 +878.286 450.795 10 +881.048 454.343 10 +881.048 454.343 -10 +878.286 450.795 -10 +880.519 454.396 10 +882.228 450.947 10 +882.228 450.947 -10 +880.519 454.396 -10 +886.03 449.396 10 +890.121 458.086 10 +890.121 458.086 -10 +886.03 449.396 -10 +887.322 458.699 10 +881.556 460.73 10 +881.556 460.73 -10 +887.322 458.699 -10 +882.339 460.955 10 +878.71 456.409 10 +878.71 456.409 -10 +882.339 460.955 -10 +879.495 456.639 10 +873.633 458.623 10 +873.633 458.623 -10 +879.495 456.639 -10 +872.369 457.733 10 +873.136 456.477 10 +873.136 456.477 -10 +872.369 457.733 -10 +873.329 457.114 10 +869.874 455.517 10 +869.874 455.517 -10 +873.329 457.114 -10 +867.498 452.88 10 +864.051 451.791 10 +864.051 451.791 -10 +867.498 452.88 -10 +864.938 452.277 10 +861.298 450.817 10 +861.298 450.817 -10 +864.938 452.277 -10 +852.179 454.854 10 +851.232 458.959 10 +851.232 458.959 -10 +852.179 454.854 -10 +851.176 463.954 10 +841.842 461.31 10 +841.842 461.31 -10 +851.176 463.954 -10 +842.736 456.409 10 +844.684 455.598 10 +844.684 455.598 -10 +842.736 456.409 -10 +844.552 456.166 10 +841.806 453.036 10 +841.806 453.036 -10 +844.552 456.166 -10 +840.485 445.346 10 +842.819 442.364 10 +842.819 442.364 -10 +840.485 445.346 -10 +846.529 445.694 10 +847.927 447.809 10 +847.927 447.809 -10 +846.529 445.694 -10 +847.187 447.578 10 +861.395 441.911 10 +861.395 441.911 -10 +847.187 447.578 -10 +861.718 435.388 10 +862.046 431.559 10 +862.046 431.559 -10 +861.718 435.388 -10 +861.51 431.979 10 +872.554 433.721 10 +872.554 433.721 -10 +861.51 431.979 -10 +872.226 433.171 10 +870.515 438.04 10 +870.515 438.04 -10 +872.226 433.171 -10 +871.166 437.689 10 +869.365 437.241 10 +869.365 437.241 -10 +871.166 437.689 -10 +869.925 436.867 10 +868.881 443.805 10 +868.881 443.805 -10 +869.925 436.867 -10 +897.095 457.032 10 +897.879 452.662 10 +897.879 452.662 -10 +897.095 457.032 -10 +897.997 453.609 10 +897.26 451.982 10 +897.26 451.982 -10 +897.997 453.609 -10 +897.829 452.782 10 +893.076 448.257 10 +893.076 448.257 -10 +897.829 452.782 -10 +893.505 449.097 10 +892.824 444.106 10 +892.824 444.106 -10 +893.505 449.097 -10 +892.549 444.966 10 +893.782 443.654 10 +893.782 443.654 -10 +892.549 444.966 -10 +893.088 443.663 10 +896.956 447.574 10 +896.956 447.574 -10 +893.088 443.663 -10 +896.113 447.126 10 +898.564 447.591 10 +898.564 447.591 -10 +896.113 447.126 -10 +897.956 447.984 10 +898.281 446.621 10 +898.281 446.621 -10 +897.956 447.984 -10 +897.685 446.969 10 +901.213 447.988 10 +901.213 447.988 -10 +897.685 446.969 -10 +900.108 448.061 10 +904.091 450.431 10 +904.091 450.431 -10 +900.108 448.061 -10 +874.111 467.179 10 +873.942 457.959 10 +873.942 457.959 -10 +874.111 467.179 -10 +873.484 458.637 10 +880.013 456.15 10 +880.013 456.15 -10 +873.484 458.637 -10 +879.279 455.905 10 +882.992 461.795 10 +882.992 461.795 -10 +879.279 455.905 -10 +882.783 460.876 10 +881.895 468.477 10 +881.895 468.477 -10 +882.783 460.876 -10 +882.446 468.062 10 +873.609 466.597 10 +873.609 466.597 -10 +882.446 468.062 -10 +902.925 438.952 10 +901.118 449.001 10 +901.118 449.001 -10 +902.925 438.952 -10 +901.699 448.6 10 +892.423 446.892 10 +892.423 446.892 -10 +901.699 448.6 -10 +894.032 443.388 10 +892.896 443.195 10 +892.896 443.195 -10 +894.032 443.388 -10 +893.305 443.772 10 +894.364 437.533 10 +894.364 437.533 -10 +893.305 443.772 -10 +887.964 452.307 10 +886.501 450.39 10 +886.501 450.39 -10 +887.964 452.307 -10 +886.372 451.038 10 +889.325 449.332 10 +889.325 449.332 -10 +886.372 451.038 -10 +888.416 449.736 10 +893.486 448.093 10 +893.486 448.093 -10 +888.416 449.736 -10 +892.565 448.021 10 +895.803 449.666 10 +895.803 449.666 -10 +892.565 448.021 -10 +895.528 448.97 10 +895.012 450.389 10 +895.012 450.389 -10 +895.528 448.97 -10 +894.696 449.806 10 +898.725 450.742 10 +898.725 450.742 -10 +894.696 449.806 -10 +898.318 450.135 10 +897.114 457.602 10 +897.114 457.602 -10 +898.318 450.135 -10 +897.676 457.242 10 +893.714 456.145 10 +893.714 456.145 -10 +897.676 457.242 -10 +889.625 458.651 10 +887.521 451.429 10 +887.521 451.429 -10 +889.625 458.651 -10 +842.941 456.869 10 +840.675 453.689 10 +840.675 453.689 -10 +842.941 456.869 -10 +840.505 454.293 10 +848.102 451.048 10 +848.102 451.048 -10 +840.505 454.293 -10 +847.483 450.77 10 +848.797 454.684 10 +848.797 454.684 -10 +847.483 450.77 -10 +849.106 454.034 10 +842.183 456.638 10 +842.183 456.638 -10 +849.106 454.034 -10 +880.808 468.873 10 +882.269 462.532 10 +882.269 462.532 -10 +880.808 468.873 -10 +891.45 449.017 10 +886.364 450.967 10 +886.364 450.967 -10 +891.45 449.017 -10 +845.731 452.492 10 +846.332 455.986 10 +846.332 455.986 -10 +845.731 452.492 -10 +846.745 455.535 10 +843.652 455.275 10 +843.652 455.275 -10 +846.745 455.535 -10 +844.311 455.79 10 +843.256 452.688 10 +843.256 452.688 -10 +844.311 455.79 -10 +842.919 453.198 10 +846.314 452.948 10 +846.314 452.948 -10 +842.919 453.198 -10 +901.523 459.934 10 +906.476 453.647 10 +906.476 453.647 -10 +901.523 459.934 -10 +869.438 440.281 10 +870.133 435.658 10 +870.133 435.658 -10 +869.438 440.281 -10 +870.133 435.658 10 +871.019 435.806 10 +871.019 435.806 -10 +870.133 435.658 -10 +871.019 435.806 10 +871.265 433.517 10 +871.265 433.517 -10 +871.019 435.806 -10 +871.265 433.517 10 +862.057 432.051 10 +862.057 432.051 -10 +871.265 433.517 -10 +862.057 432.051 10 +861.741 434.244 10 +861.741 434.244 -10 +862.057 432.051 -10 +861.741 434.244 10 +862.598 434.384 10 +862.598 434.384 -10 +861.741 434.244 -10 +862.598 434.384 10 +861.231 443.29 10 +861.231 443.29 -10 +862.598 434.384 -10 +861.231 443.29 10 +858.98 444.392 10 +858.98 444.392 -10 +861.231 443.29 -10 +858.98 444.392 10 +858.507 443.132 10 +858.507 443.132 -10 +858.98 444.392 -10 +858.507 443.132 10 +854.315 444.757 10 +854.315 444.757 -10 +858.507 443.132 -10 +854.315 444.757 10 +854.713 445.837 10 +854.713 445.837 -10 +854.315 444.757 -10 +854.713 445.837 10 +854.289 446.01 10 +854.289 446.01 -10 +854.713 445.837 -10 +854.289 446.01 10 +853.889 444.922 10 +853.889 444.922 -10 +854.289 446.01 -10 +853.889 444.922 10 +849.736 446.532 10 +849.736 446.532 -10 +853.889 444.922 -10 +849.736 446.532 10 +850.139 447.714 10 +850.139 447.714 -10 +849.736 446.532 -10 +850.139 447.714 10 +847.908 448.63 10 +847.908 448.63 -10 +850.139 447.714 -10 +847.908 448.63 10 +845.946 447.151 10 +845.946 447.151 -10 +847.908 448.63 -10 +845.946 447.151 10 +846.766 446.064 10 +846.766 446.064 -10 +845.946 447.151 -10 +846.766 446.064 10 +842.506 442.73 10 +842.506 442.73 -10 +846.766 446.064 -10 +842.506 442.73 10 +841.171 444.471 10 +841.171 444.471 -10 +842.506 442.73 -10 +841.171 444.471 10 +841.864 444.992 10 +841.864 444.992 -10 +841.171 444.471 -10 +841.864 444.992 10 +837.66 450.279 10 +837.66 450.279 -10 +841.864 444.992 -10 +837.66 450.279 10 +841.787 453.697 10 +841.787 453.697 -10 +837.66 450.279 -10 +841.787 453.697 10 +842.252 455.222 10 +842.252 455.222 -10 +841.787 453.697 -10 +842.252 455.222 10 +842.038 455.287 10 +842.038 455.287 -10 +842.252 455.222 -10 +842.038 455.287 10 +842.378 456.299 10 +842.378 456.299 -10 +842.038 455.287 -10 +842.378 456.299 10 +842.853 456.136 10 +842.853 456.136 -10 +842.378 456.299 -10 +842.853 456.136 10 +842.071 461.494 10 +842.071 461.494 -10 +842.853 456.136 -10 +842.071 461.494 10 +848.285 462.661 10 +848.285 462.661 -10 +842.071 461.494 -10 +848.285 462.661 10 +848.196 463.135 10 +848.196 463.135 -10 +848.285 462.661 -10 +848.196 463.135 10 +850.743 463.613 10 +850.743 463.613 -10 +848.196 463.135 -10 +850.743 463.613 10 +851.562 458.36 10 +851.562 458.36 -10 +850.743 463.613 -10 +851.562 458.36 10 +850.212 458.143 10 +850.212 458.143 -10 +851.562 458.36 -10 +850.212 458.143 10 +850.628 455.916 10 +850.628 455.916 -10 +850.212 458.143 -10 +850.628 455.916 10 +862.426 451.139 10 +862.426 451.139 -10 +850.628 455.916 -10 +862.426 451.139 10 +862.436 451.286 10 +862.436 451.286 -10 +862.426 451.139 -10 +862.436 451.286 10 +864.092 451.433 10 +864.092 451.433 -10 +862.436 451.286 -10 +864.092 451.433 10 +864.001 452.143 10 +864.001 452.143 -10 +864.092 451.433 -10 +864.001 452.143 10 +865.049 452.275 10 +865.049 452.275 -10 +864.001 452.143 -10 +865.049 452.275 10 +865.148 451.49 10 +865.148 451.49 -10 +865.049 452.275 -10 +865.148 451.49 10 +871.873 457.056 10 +871.873 457.056 -10 +865.148 451.49 -10 +871.873 457.056 10 +873.835 458.548 10 +873.835 458.548 -10 +871.873 457.056 -10 +873.835 458.548 10 +874.247 460.088 10 +874.247 460.088 -10 +873.835 458.548 -10 +874.247 460.088 10 +873.75 460.267 10 +873.75 460.267 -10 +874.247 460.088 -10 +873.75 460.267 10 +874.083 461.293 10 +874.083 461.293 -10 +873.75 460.267 -10 +874.083 461.293 10 +874.475 461.16 10 +874.475 461.16 -10 +874.083 461.293 -10 +874.475 461.16 10 +874.191 466.565 10 +874.191 466.565 -10 +874.475 461.16 -10 +874.191 466.565 10 +880.947 467.519 10 +880.947 467.519 -10 +874.191 466.565 -10 +880.947 467.519 10 +880.801 468.386 10 +880.801 468.386 -10 +880.947 467.519 -10 +880.801 468.386 10 +882.894 468.654 10 +882.894 468.654 -10 +880.801 468.386 -10 +882.894 468.654 10 +883.766 463.197 10 +883.766 463.197 -10 +882.894 468.654 -10 +883.766 463.197 10 +882.319 462.953 10 +882.319 462.953 -10 +883.766 463.197 -10 +882.319 462.953 10 +882.725 460.694 10 +882.725 460.694 -10 +882.319 462.953 -10 +882.725 460.694 10 +894.534 456.209 10 +894.534 456.209 -10 +882.725 460.694 -10 +894.534 456.209 10 +894.525 456.384 10 +894.525 456.384 -10 +894.534 456.209 -10 +894.525 456.384 10 +896.128 456.578 10 +896.128 456.578 -10 +894.525 456.384 -10 +896.128 456.578 10 +896.091 456.885 10 +896.091 456.885 -10 +896.128 456.578 -10 +896.091 456.885 10 +897.169 457.035 10 +897.169 457.035 -10 +896.091 456.885 -10 +897.169 457.035 10 +897.241 456.619 10 +897.241 456.619 -10 +897.169 457.035 -10 +897.241 456.619 10 +901.566 459.979 10 +901.566 459.979 -10 +897.241 456.619 -10 +901.566 459.979 10 +905.82 454.744 10 +905.82 454.744 -10 +901.566 459.979 -10 +905.82 454.744 10 +906.374 455.235 10 +906.374 455.235 -10 +905.82 454.744 -10 +906.374 455.235 10 +907.888 453.524 10 +907.888 453.524 -10 +906.374 455.235 -10 +907.888 453.524 10 +903.631 450.089 10 +903.631 450.089 -10 +907.888 453.524 -10 +903.631 450.089 10 +902.81 451.122 10 +902.81 451.122 -10 +903.631 450.089 -10 +902.81 451.122 10 +900.909 449.502 10 +900.909 449.502 -10 +902.81 451.122 -10 +900.909 449.502 10 +902.231 440.596 10 +902.231 440.596 -10 +900.909 449.502 -10 +902.231 440.596 10 +903.107 440.726 10 +903.107 440.726 -10 +902.231 440.596 -10 +903.107 440.726 10 +903.439 438.561 10 +903.439 438.561 -10 +903.107 440.726 -10 +903.439 438.561 10 +894.229 437.091 10 +894.229 437.091 -10 +903.439 438.561 -10 +894.229 437.091 10 +893.897 439.256 10 +893.897 439.256 -10 +894.229 437.091 -10 +893.897 439.256 10 +894.766 439.395 10 +894.766 439.395 -10 +893.897 439.256 -10 +894.766 439.395 10 +893.095 448.477 10 +893.095 448.477 -10 +894.766 439.395 -10 +893.095 448.477 10 +891.024 449.302 10 +891.024 449.302 -10 +893.095 448.477 -10 +891.024 449.302 10 +890.547 448.022 10 +890.547 448.022 -10 +891.024 449.302 -10 +890.547 448.022 10 +886.357 449.641 10 +886.357 449.641 -10 +890.547 448.022 -10 +886.357 449.641 10 +886.919 451.003 10 +886.919 451.003 -10 +886.357 449.641 -10 +886.919 451.003 10 +886.529 451.164 10 +886.529 451.164 -10 +886.919 451.003 -10 +886.529 451.164 10 +886.017 449.926 10 +886.017 449.926 -10 +886.529 451.164 -10 +886.017 449.926 10 +881.895 451.431 10 +881.895 451.431 -10 +886.017 449.926 -10 +881.895 451.431 10 +882.338 452.688 10 +882.338 452.688 -10 +881.895 451.431 -10 +882.338 452.688 10 +879.892 453.549 10 +879.892 453.549 -10 +882.338 452.688 -10 +879.892 453.549 10 +877.953 452.092 10 +877.953 452.092 -10 +879.892 453.549 -10 +877.953 452.092 10 +878.727 451.063 10 +878.727 451.063 -10 +877.953 452.092 -10 +878.727 451.063 10 +875.334 448.269 10 +875.334 448.269 -10 +878.727 451.063 -10 +875.334 448.269 10 +874.474 449.339 10 +874.474 449.339 -10 +875.334 448.269 -10 +874.474 449.339 10 +874.085 449.038 10 +874.085 449.038 -10 +874.474 449.339 -10 +874.085 449.038 10 +874.945 447.968 10 +874.945 447.968 -10 +874.085 449.038 -10 +874.945 447.968 10 +871.482 445.258 10 +871.482 445.258 -10 +874.945 447.968 -10 +871.482 445.258 10 +870.634 446.255 10 +870.634 446.255 -10 +871.482 445.258 -10 +870.634 446.255 10 +868.777 444.675 10 +868.777 444.675 -10 +870.634 446.255 -10 +868.777 444.675 10 +869.438 440.281 10 +869.438 440.281 -10 +868.777 444.675 -10 +4 0 1 2 3 +4 4 5 6 7 +4 8 9 10 11 +4 12 13 14 15 +4 16 17 18 19 +4 20 21 22 23 +4 24 25 26 27 +4 28 29 30 31 +4 32 33 34 35 +4 36 37 38 39 +4 40 41 42 43 +4 44 45 46 47 +4 48 49 50 51 +4 52 53 54 55 +4 56 57 58 59 +4 60 61 62 63 +4 64 65 66 67 +4 68 69 70 71 +4 72 73 74 75 +4 76 77 78 79 +4 80 81 82 83 +4 84 85 86 87 +4 88 89 90 91 +4 92 93 94 95 +4 96 97 98 99 +4 100 101 102 103 +4 104 105 106 107 +4 108 109 110 111 +4 112 113 114 115 +4 116 117 118 119 +4 120 121 122 123 +4 124 125 126 127 +4 128 129 130 131 +4 132 133 134 135 +4 136 137 138 139 +4 140 141 142 143 +4 144 145 146 147 +4 148 149 150 151 +4 152 153 154 155 +4 156 157 158 159 +4 160 161 162 163 +4 164 165 166 167 +4 168 169 170 171 +4 172 173 174 175 +4 176 177 178 179 +4 180 181 182 183 +4 184 185 186 187 +4 188 189 190 191 +4 192 193 194 195 +4 196 197 198 199 +4 200 201 202 203 +4 204 205 206 207 +4 208 209 210 211 +4 212 213 214 215 +4 216 217 218 219 +4 220 221 222 223 +4 224 225 226 227 +4 228 229 230 231 +4 232 233 234 235 +4 236 237 238 239 +4 240 241 242 243 +4 244 245 246 247 +4 248 249 250 251 +4 252 253 254 255 +4 256 257 258 259 +4 260 261 262 263 +4 264 265 266 267 +4 268 269 270 271 +4 272 273 274 275 +4 276 277 278 279 +4 280 281 282 283 +4 284 285 286 287 +4 288 289 290 291 +4 292 293 294 295 +4 296 297 298 299 +4 300 301 302 303 +4 304 305 306 307 +4 308 309 310 311 +4 312 313 314 315 +4 316 317 318 319 +4 320 321 322 323 +4 324 325 326 327 +4 328 329 330 331 +4 332 333 334 335 +4 336 337 338 339 +4 340 341 342 343 +4 344 345 346 347 +4 348 349 350 351 +4 352 353 354 355 +4 356 357 358 359 +4 360 361 362 363 +4 364 365 366 367 +4 368 369 370 371 +4 372 373 374 375 +4 376 377 378 379 +4 380 381 382 383 +4 384 385 386 387 +4 388 389 390 391 +4 392 393 394 395 +4 396 397 398 399 +4 400 401 402 403 +4 404 405 406 407 +4 408 409 410 411 +4 412 413 414 415 +4 416 417 418 419 +4 420 421 422 423 +4 424 425 426 427 +4 428 429 430 431 +4 432 433 434 435 +4 436 437 438 439 +4 440 441 442 443 +4 444 445 446 447 +4 448 449 450 451 +4 452 453 454 455 +4 456 457 458 459 +4 460 461 462 463 +4 464 465 466 467 +4 468 469 470 471 +4 472 473 474 475 +4 476 477 478 479 +4 480 481 482 483 +4 484 485 486 487 +4 488 489 490 491 +4 492 493 494 495 +4 496 497 498 499 +4 500 501 502 503 +4 504 505 506 507 +4 508 509 510 511 +4 512 513 514 515 +4 516 517 518 519 +4 520 521 522 523 +4 524 525 526 527 +4 528 529 530 531 +4 532 533 534 535 +4 536 537 538 539 +4 540 541 542 543 +4 544 545 546 547 +4 548 549 550 551 +4 552 553 554 555 +4 556 557 558 559 +4 560 561 562 563 +4 564 565 566 567 +4 568 569 570 571 +4 572 573 574 575 +4 576 577 578 579 +4 580 581 582 583 +4 584 585 586 587 +4 588 589 590 591 +4 592 593 594 595 +4 596 597 598 599 +4 600 601 602 603 +4 604 605 606 607 +4 608 609 610 611 +4 612 613 614 615 +4 616 617 618 619 \ No newline at end of file diff --git a/Kinetic_space_partition/test/Kinetic_space_partition/issue_8624.cpp b/Kinetic_space_partition/test/Kinetic_space_partition/issue_8624.cpp new file mode 100644 index 000000000000..1a3ddb7fc1e1 --- /dev/null +++ b/Kinetic_space_partition/test/Kinetic_space_partition/issue_8624.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include + +using EPICK = CGAL::Exact_predicates_inexact_constructions_kernel; +using EPECK = CGAL::Exact_predicates_exact_constructions_kernel; + +using Kernel = EPICK; +using FT = typename Kernel::FT; +using Point_3 = typename Kernel::Point_3; + +using Surface_mesh = CGAL::Surface_mesh; +using KSP = CGAL::Kinetic_space_partition_3; +using Timer = CGAL::Real_timer; + +int main(int argc, char** argv) +{ + // Reading polygons from file + std::string input_filename = (argc > 1 ? argv[1] : "data/issue_8624.off"); + std::ifstream input_file(input_filename); + + std::vector input_vertices; + std::vector > input_faces; + + if (CGAL::IO::read_polygon_soup(input_filename, input_vertices, input_faces)) { + std::cout << "* reading the file: " << input_filename << "!" << std::endl; + input_file.close(); + } else { + std::cerr << "ERROR: can't read the file " << input_filename << "!" << std::endl; + return EXIT_FAILURE; + } + + std::cout << "--- INPUT STATS: \n* number of polygons: " << input_faces.size() << std::endl; + + // Parameters. + const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 1); + + // Initialization of Kinetic_space_partition_3 object. + // 'debug' set to true exports intermediate results into files in the working directory. + // The resulting volumes are exported into a volumes folder, if the folder already exists. + KSP ksp(CGAL::parameters::verbose(true).debug(false)); + + // Providing input polygons. + ksp.insert(input_vertices, input_faces); + + Timer timer; + timer.start(); + + // 'initialize' creates the intersection graph that is used for the partition. + ksp.initialize(CGAL::parameters::bbox_dilation_ratio(1.1).reorient_bbox(false)); + + // Creating the partition with allowing up to 'k' intersections for each kinetic polygon. + ksp.partition(k); + + timer.stop(); + const FT time = static_cast(timer.time()); + + // Access the kinetic partition via linear cell complex. + typedef CGAL::Linear_cell_complex_traits<3, EPECK> LCC_Traits; + CGAL::Linear_cell_complex_for_combinatorial_map<3, 3, LCC_Traits, typename KSP::Linear_cell_complex_min_items> lcc; + ksp.get_linear_cell_complex(lcc); + + std::vector cells = { 0, 2, 3 }, count; + count = lcc.count_cells(cells); + + assert(count[0] != 0); + assert(count[2] != 0); + assert(count[3] != 0); + + if (count[0] == 0 || count[2] == 0 || count[3] == 0) + return EXIT_FAILURE; + + std::cout << "For k = " << k << ":\n" << " vertices: " << count[0] << "\n faces: " << count[2] << "\n volumes: " << count[3] << std::endl; + + std::cout << "\n3D kinetic partition created in " << time << " seconds!" << std::endl; + + return EXIT_SUCCESS; +} From d01979f5ef8fe89126818ca8737a4c34fbda13b4 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Thu, 28 Nov 2024 16:07:51 +0100 Subject: [PATCH 5/8] using std::isnan --- Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h index 944d6e8ca230..563d5528d01f 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h @@ -493,7 +493,7 @@ class Initializer { typename Intersection_graph::Kinetic_interval& kinetic_interval = m_data.igraph().kinetic_interval(e, sp_idx); crossing_iedges.push_back(e); - if (emin > s || (min_speed != min_speed)) { + if (emin > s || std::isnan(min_speed)) { typename Intersection_kernel::FT bary_edge_exact = (emin - s) / (t - s); FT bary_edge = from_exact((emin - s) / (t - s)); CGAL_assertion(bary_edge_exact >= 0); @@ -505,7 +505,7 @@ class Initializer { kinetic_interval.push_back(std::pair(0, 0)); } - if (t > emax || (max_speed != max_speed)) { + if (t > emax || std::isnan(max_speed)) { typename Intersection_kernel::FT bary_edge_exact = (emax - s) / (t - s); FT bary_edge = from_exact((emax - s) / (t - s)); CGAL_assertion(0 <= bary_edge_exact && bary_edge_exact <= 1); From f3be6c2930d02ee88a462ef6991c55535c29f0f3 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Mon, 2 Dec 2024 08:51:26 +0100 Subject: [PATCH 6/8] bugfix --- Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h index 563d5528d01f..f3e5550a4d9c 100644 --- a/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h +++ b/Kinetic_space_partition/include/CGAL/KSP_3/Initializer.h @@ -493,7 +493,7 @@ class Initializer { typename Intersection_graph::Kinetic_interval& kinetic_interval = m_data.igraph().kinetic_interval(e, sp_idx); crossing_iedges.push_back(e); - if (emin > s || std::isnan(min_speed)) { + if (emin > s || std::isinf(min_speed)) { typename Intersection_kernel::FT bary_edge_exact = (emin - s) / (t - s); FT bary_edge = from_exact((emin - s) / (t - s)); CGAL_assertion(bary_edge_exact >= 0); @@ -505,7 +505,7 @@ class Initializer { kinetic_interval.push_back(std::pair(0, 0)); } - if (t > emax || std::isnan(max_speed)) { + if (t > emax || std::isinf(max_speed)) { typename Intersection_kernel::FT bary_edge_exact = (emax - s) / (t - s); FT bary_edge = from_exact((emax - s) / (t - s)); CGAL_assertion(0 <= bary_edge_exact && bary_edge_exact <= 1); From 9ccc744da1fdb68492b89080acbfa564e38a8015 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Mon, 9 Dec 2024 10:03:01 +0100 Subject: [PATCH 7/8] updated parameters in doc --- .../Kinetic_surface_reconstruction.txt | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Kinetic_surface_reconstruction/doc/Kinetic_surface_reconstruction/Kinetic_surface_reconstruction.txt b/Kinetic_surface_reconstruction/doc/Kinetic_surface_reconstruction/Kinetic_surface_reconstruction.txt index 99ee35539955..c9fc03d1c5b4 100644 --- a/Kinetic_surface_reconstruction/doc/Kinetic_surface_reconstruction/Kinetic_surface_reconstruction.txt +++ b/Kinetic_surface_reconstruction/doc/Kinetic_surface_reconstruction/Kinetic_surface_reconstruction.txt @@ -156,11 +156,11 @@ Foam_box 444 -6,5 +6.4 -3,3 +3.4 -9,8 +9.9 @@ -172,17 +172,17 @@ Lans 169 -3.334 +3.338 330 1.175 -26,3 +27,2 -9,4 +11,1 -35,7 +38,4 @@ -194,17 +194,17 @@ Meeting Room 777 -29.605 +29.737 -2.867 +2.876 -11.819 +11.839 -37,1 +41,4 -93,4 +100,7 -131,1 +142,1 @@ -216,17 +216,17 @@ Full Thing 1.790 -21.804 +21.845 -2.655 +2.656 -12.984 +12.980 -8,6 +9,9 -238,8 +279,8 -248,2 +289,7 @@ -246,9 +246,9 @@ Hilbert cube 0,6 -10,5 +10,2 -11,1 +10,9 @@ -262,15 +262,15 @@ Asian Dragon 101.651 -10.209 +11.158 -34.237 +35.776 -31,2 +31,7 -757,5 +869,9 -790,7 +903,5 @@ -282,17 +282,17 @@ Building_C 172 -3.432 +3.468 -369 +370 -1.457 +1.468 -40,1 +41,9 -12,3 +14,5 -52,4 +56,5
From c5500d972bf6762227752f720bfb730c107e1624 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Mon, 9 Dec 2024 11:06:43 +0100 Subject: [PATCH 8/8] plugin bugfix --- .../Plugins/Point_set/Kinetic_surface_reconstruction_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab/demo/Lab/Plugins/Point_set/Kinetic_surface_reconstruction_plugin.cpp b/Lab/demo/Lab/Plugins/Point_set/Kinetic_surface_reconstruction_plugin.cpp index f3d9561abda6..9ef3b7a5f0c5 100644 --- a/Lab/demo/Lab/Plugins/Point_set/Kinetic_surface_reconstruction_plugin.cpp +++ b/Lab/demo/Lab/Plugins/Point_set/Kinetic_surface_reconstruction_plugin.cpp @@ -363,7 +363,7 @@ private Q_SLOTS: void onVisibilityChanged(bool) { if (!dock_widget->isVisible()) return; - std::cout << "in visibility changed" << std::endl; + onItemIndexSelected(scene->mainSelectionIndex()); } private: