From c15c75fa1a79af09962c7221d0900ff342ca4bef Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 20 May 2016 16:53:19 +0200 Subject: [PATCH] Do not protect outside the domain! --- .../CGAL/Mesh_3/polylines_to_protect.h | 51 ++++++++++++------- .../internal/Mesh_3/Graph_manipulations.h | 8 +-- .../CGAL/internal/Mesh_3/split_in_polylines.h | 11 +++- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h b/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h index 21a37973c5e..f10b721f2e6 100644 --- a/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h +++ b/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h @@ -117,22 +117,35 @@ polylines_to_protect(const CGAL::Image_3& cgal_image, const Point_3& p01 = get<1>(square[0][1]); const Point_3& p11 = get<1>(square[1][1]); + const bool out00 = null(get<2>(square[0][0])); + const bool out10 = null(get<2>(square[1][0])); + const bool out01 = null(get<2>(square[0][1])); + const bool out11 = null(get<2>(square[1][1])); + // // Protect the edges of the cube // - if(pix00[axis_xx] == 0) { + if(pix00[axis_xx] == 0 && + ! ( out00 && out01 ) ) + { g_manip.try_add_edge(g_manip.get_vertex(p00), g_manip.get_vertex(p01)); } - if(pix11[axis_xx] == image_dims[axis_xx]-1) { + if(pix11[axis_xx] == image_dims[axis_xx]-1 && + ! ( out10 && out11 ) ) + { g_manip.try_add_edge(g_manip.get_vertex(p10), g_manip.get_vertex(p11)); } - if(pix00[axis_yy] == 0) { + if(pix00[axis_yy] == 0 && + ! ( out00 && out10 ) ) + { g_manip.try_add_edge(g_manip.get_vertex(p00), g_manip.get_vertex(p10)); } - if(pix11[axis_yy] == image_dims[axis_yy]-1) { + if(pix11[axis_yy] == image_dims[axis_yy]-1 && + ! ( out01 && out11 ) ) + { g_manip.try_add_edge(g_manip.get_vertex(p01), g_manip.get_vertex(p11)); } @@ -151,10 +164,10 @@ polylines_to_protect(const CGAL::Image_3& cgal_image, case_4: // case 4 or case 2-2 ++case4; - vertex_descriptor left = g_manip.split(p00, p01); - vertex_descriptor right = g_manip.split(p10, p11); - vertex_descriptor top = g_manip.split(p01, p11); - vertex_descriptor bottom = g_manip.split(p00, p10); + vertex_descriptor left = g_manip.split(p00, p01, out00, out01); + vertex_descriptor right = g_manip.split(p10, p11, out10, out11); + vertex_descriptor top = g_manip.split(p01, p11, out01, out11); + vertex_descriptor bottom = g_manip.split(p00, p10, out00, out10); vertex_descriptor vmid = g_manip.get_vertex(midpoint(p00, p11)); g_manip.try_add_edge(left , vmid); g_manip.try_add_edge(right , vmid); @@ -176,10 +189,10 @@ case_4: assert(get<2>(square[0][1]) != get<2>(square[0][0])); assert(get<2>(square[0][1]) != get<2>(square[1][1])); ++case121; - vertex_descriptor left = g_manip.split(p00, p01); - vertex_descriptor right = g_manip.split(p10, p11); - vertex_descriptor top = g_manip.split(p01, p11); - vertex_descriptor bottom = g_manip.split(p00, p10); + vertex_descriptor left = g_manip.split(p00, p01, out00, out01); + vertex_descriptor right = g_manip.split(p10, p11, out10, out11); + vertex_descriptor top = g_manip.split(p01, p11, out01, out11); + vertex_descriptor bottom = g_manip.split(p00, p10, out00, out10); Point_3 inter_left = p00 + (1./3.) * (p11 - p00); Point_3 inter_right = p00 + (2./3.) * (p11 - p00); vertex_descriptor v_int_left = g_manip.get_vertex(inter_left); @@ -211,9 +224,9 @@ case_4: Point_3 midright = midpoint(p10, p11); Point_3 inter = midleft + (2./3)*(midright-midleft); vertex_descriptor v_inter = g_manip.get_vertex(inter); - vertex_descriptor right = g_manip.split(p10, p11); - vertex_descriptor top = g_manip.split(p01, p11); - vertex_descriptor bottom = g_manip.split(p00, p10); + vertex_descriptor right = g_manip.split(p10, p11, out10, out11); + vertex_descriptor top = g_manip.split(p01, p11, out01, out11); + vertex_descriptor bottom = g_manip.split(p00, p10, out00, out10); g_manip.try_add_edge(top, v_inter); g_manip.try_add_edge(bottom, v_inter); g_manip.try_add_edge(right, v_inter); @@ -248,8 +261,8 @@ case_4: ++case22; assert(get<2>(square[1][0])==get<2>(square[1][1])); assert(get<2>(square[1][0])!=get<2>(square[0][1])); - vertex_descriptor top = g_manip.split(p01, p11); - vertex_descriptor bottom = g_manip.split(p00, p10); + vertex_descriptor top = g_manip.split(p01, p11, out01, out11); + vertex_descriptor bottom = g_manip.split(p00, p10, out00, out10); g_manip.try_add_edge(top, bottom); } else { // Else diagonal case case 2-2 @@ -293,7 +306,7 @@ case_4: assert(get<2>(square[1][0]) != get<2>(square[0][0])); assert(get<2>(square[1][1]) == get<2>(square[0][0])); assert(get<2>(square[0][1]) == get<2>(square[0][0])); - vertex_descriptor bottom = g_manip.split(p00, p10); + vertex_descriptor bottom = g_manip.split(p00, p10, out00, out10); vertex_descriptor old = bottom; Point_3 inter; @@ -309,7 +322,7 @@ case_4: old = v_int; } - vertex_descriptor right = g_manip.split(p10, p11); + vertex_descriptor right = g_manip.split(p10, p11, out10, out11); g_manip.try_add_edge(v_int, right); } } diff --git a/Mesh_3/include/CGAL/internal/Mesh_3/Graph_manipulations.h b/Mesh_3/include/CGAL/internal/Mesh_3/Graph_manipulations.h index dc07c34b541..af3a0cd4342 100644 --- a/Mesh_3/include/CGAL/internal/Mesh_3/Graph_manipulations.h +++ b/Mesh_3/include/CGAL/internal/Mesh_3/Graph_manipulations.h @@ -56,7 +56,9 @@ struct Graph_manipulations } } - vertex_descriptor split(const Point_3& a, const Point_3& b) { + vertex_descriptor split(const Point_3& a, const Point_3& b, + bool a_is_outside, bool b_is_outside) + { const Point_3 mid = a < b ? midpoint(a, b) : midpoint(b, a); vertex_descriptor vmid = get_vertex(mid); typename std::map::iterator @@ -72,8 +74,8 @@ struct Graph_manipulations remove_edge(edge, g); if(!b) { // The edge was already here. - try_add_edge(va, vmid); - try_add_edge(vb, vmid); + if(!a_is_outside) try_add_edge(va, vmid); + if(!b_is_outside) try_add_edge(vb, vmid); return vmid; } } diff --git a/Mesh_3/include/CGAL/internal/Mesh_3/split_in_polylines.h b/Mesh_3/include/CGAL/internal/Mesh_3/split_in_polylines.h index 36c17c780ff..3e4309188e3 100644 --- a/Mesh_3/include/CGAL/internal/Mesh_3/split_in_polylines.h +++ b/Mesh_3/include/CGAL/internal/Mesh_3/split_in_polylines.h @@ -73,9 +73,16 @@ void split_in_polylines(Graph& G, Kernel) vertex_descriptor v = *it; bool split = false; - if(out_degree(v,G) > 2) { + const std::size_t out_degree_v_G = out_degree(v,G); + + if(out_degree_v_G == 0) { + remove_vertex(v, G); + continue; + } + + if(out_degree_v_G > 2) { split = true; - } else if(out_degree(v, G) == 2) { + } else if(out_degree_v_G == 2) { out_edge_iterator out_edge_it, out_edges_end; boost::tie(out_edge_it, out_edges_end) = out_edges(v, G);