From 940e65784cd6237f5eea1022176392bd5c1d80db Mon Sep 17 00:00:00 2001 From: hootfat Date: Tue, 20 Aug 2024 22:01:14 +0200 Subject: [PATCH] At triangulation step we must check that active neighbors are bipolar --- src/surface_nets.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/surface_nets.cpp b/src/surface_nets.cpp index fea8ecc..fc4fc93 100644 --- a/src/surface_nets.cpp +++ b/src/surface_nets.cpp @@ -59,6 +59,15 @@ common::igl_triangle_mesh surface_nets( std::size_t k = (active_cube_index) / (grid.sx * grid.sy); return std::make_tuple(i, j, k); }; + + auto const is_scalar_positive = [](float scalar, float isovalue) -> bool { + return scalar >= isovalue; + }; + + auto const are_edge_scalars_bipolar = + [&is_scalar_positive](float scalar1, float scalar2, float isovalue) -> bool { + return is_scalar_positive(scalar1, isovalue) != is_scalar_positive(scalar2, isovalue); + }; // mapping from active cube indices to vertex indices of the generated mesh std::unordered_map active_cube_to_vertex_index_map{}; @@ -170,16 +179,6 @@ common::igl_triangle_mesh surface_nets( { 3u, 7u } }; - auto const is_scalar_positive = [](float scalar, float isovalue) -> bool - { - return scalar >= isovalue; - }; - - auto const are_edge_scalars_bipolar = [&is_scalar_positive](float scalar1, float scalar2, float isovalue) -> bool - { - return is_scalar_positive(scalar1, isovalue) != is_scalar_positive(scalar2, isovalue); - }; - bool const edge_bipolarity_array[12] = { are_edge_scalars_bipolar(voxel_corner_values[edges[0][0]], voxel_corner_values[edges[0][1]], isovalue), @@ -486,6 +485,10 @@ common::igl_triangle_mesh surface_nets( // look at each potentially generated quad for (std::size_t i = 0; i < 3; ++i) { + if (!are_edge_scalars_bipolar(edge_scalar_values[i][0], edge_scalar_values[i][1], isovalue)) { + continue; + } + auto const neighbor1 = get_active_cube_index( neighbor_grid_positions[quad_neighbors[i][0]][0], neighbor_grid_positions[quad_neighbors[i][0]][1],