Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

At triangulation step we must check that active neighbors are bipolar #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/surface_nets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t, std::uint64_t> active_cube_to_vertex_index_map{};
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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],
Expand Down