extract explicit mesh with topology information from implicit surfaces with boolean operations, and do surface/volume integrating on them.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
8.4 KiB

#include <process.hpp>
#include <prim_gen.hpp>
#include <connect_by_topo.hpp>
#include <post_topo.hpp>
ISNP_API void build_implicit_network_by_blobtree(const s_settings& settings,
const baked_blobtree_t& tree,
stl_vector_mp<Eigen::Vector3d>& output_vertices,
stl_vector_mp<uint32_t>& output_polygon_faces,
stl_vector_mp<uint32_t>& output_vertex_counts_of_face)
{
// load LUT for implicit arrangement
load_lut();
scene_bg_mesh_info_t scene_bg_mesh_info{};
stl_vector_mp<std::array<uint32_t, 4>> tetrahedrons{};
stl_vector_mp<uint32_t> tetrahedron_active_subface_start_index{};
stl_vector_mp<uint32_t> active_subface_indices{};
stl_vector_mp<arrangement_t> tetrahedron_arrangements{};
flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>> zero_vertex_to_incident_tet_mapping{};
stl_vector_mp<Eigen::Vector3d> iso_pts{};
stl_vector_mp<iso_vertex_t> iso_verts{};
stl_vector_mp<polygon_face_t> iso_faces{};
// primitive generation
{
Eigen::MatrixXd vertex_infos{};
flat_hash_map_mp<uint32_t, uint32_t> vertex_indices_mapping{};
{
flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>> vertex_to_tet_mapping{};
{
stl_vector_mp<grid_region> vertex_exist_regions{};
extract_vertex_infos(settings, tree, scene_bg_mesh_info, vertex_infos);
pair_tetrahedron(scene_bg_mesh_info, tetrahedrons, vertex_to_tet_mapping);
}
filter_tet_by_subface(vertex_to_tet_mapping,
vertex_infos,
vertex_indices_mapping,
tetrahedrons,
tetrahedron_active_subface_start_index,
active_subface_indices,
zero_vertex_to_incident_tet_mapping);
}
auto tet_active_subface_counts = compute_implicit_arrangements(vertex_infos,
vertex_indices_mapping,
tetrahedrons,
tetrahedron_active_subface_start_index,
active_subface_indices,
tetrahedron_arrangements);
extract_iso_mesh(tet_active_subface_counts,
tetrahedron_arrangements,
scene_bg_mesh_info,
tetrahedrons,
tetrahedron_active_subface_start_index,
active_subface_indices,
vertex_infos,
vertex_indices_mapping,
iso_pts,
iso_verts,
iso_faces);
}
// connect components by topology
stl_vector_mp<uint32_t> patch_of_face(iso_faces.size());
stl_vector_mp<uint32_t> shell_of_half_patch{};
stl_vector_mp<uint32_t> component_of_patch{};
stl_vector_mp<stl_vector_mp<uint32_t>> patches{};
stl_vector_mp<stl_list_mp<iso_edge_t>> chains{};
stl_vector_mp<stl_vector_mp<uint32_t>> shells{};
stl_vector_mp<stl_vector_mp<uint32_t>> components{};
{
{
stl_vector_mp<stl_vector_mp<uint32_t>> edges_of_iso_face{};
stl_vector_mp<iso_edge_t> iso_edges{};
compute_patch_edges(iso_faces, edges_of_iso_face, iso_edges);
compute_patches(edges_of_iso_face, iso_edges, iso_faces, patches, patch_of_face);
compute_chains(iso_verts.size(), iso_edges, chains);
}
stl_vector_mp<stl_vector_mp<uint32_t>> half_patch_adj_list(2 * patches.size());
for (size_t i = 0; i < chains.size(); ++i)
compute_patch_order(tetrahedrons,
chains[i].front(),
iso_verts,
iso_faces,
tetrahedron_arrangements,
tetrahedron_active_subface_start_index,
active_subface_indices,
zero_vertex_to_incident_tet_mapping,
patch_of_face,
half_patch_adj_list);
compute_shells_and_components(half_patch_adj_list, shells, shell_of_half_patch, components, component_of_patch);
}
// mixed topology connection and post process
if (components.size() == 1) // no nesting problem, each shell is an arrangement cell
{
output_vertices = std::move(iso_pts);
for (const auto& half_patch : shells[1]) {
for (const auto& face_id : patches[half_patch / 2]) {
const auto& face = iso_faces[face_id];
output_polygon_faces.insert(output_polygon_faces.end(),
std::make_move_iterator(face.vertex_indices.begin()),
std::make_move_iterator(face.vertex_indices.end()));
output_vertex_counts_of_face.emplace_back(face.vertex_indices.size());
}
}
} else {
stl_vector_mp<stl_vector_mp<uint32_t>> arrangement_cells{};
{
stl_vector_mp<std::pair<uint32_t, uint32_t>> shell_links{};
topo_ray_shooting(scene_bg_mesh_info,
tetrahedrons,
tetrahedron_arrangements,
iso_verts,
iso_faces,
patches,
patch_of_face,
shells,
shell_of_half_patch,
components,
component_of_patch,
shell_links);
compute_arrangement_cells(static_cast<uint32_t>(shells.size()), shell_links, arrangement_cells);
}
{
stl_vector_mp<uint32_t> shell_to_cell(shells.size());
for (uint32_t i = 0; i < arrangement_cells.size(); i++) {
for (auto shell : arrangement_cells[i]) shell_to_cell[shell] = i;
}
dynamic_bitset_mp<> active_cell_label{};
{
stl_vector_mp<dynamic_bitset_mp<>> cell_primitive_signs(tree.primitives.size(),
dynamic_bitset_mp<>(arrangement_cells.size()));
{
stl_vector_mp<dynamic_bitset_mp<>> cell_subface_signs(tree.subfaces.size(),
dynamic_bitset_mp<>(arrangement_cells.size()));
propagate_subface_labels(tree,
iso_faces,
patches,
arrangement_cells,
shell_of_half_patch,
shells,
shell_to_cell,
cell_subface_signs);
transform_subface_to_primitive_labels(tree, cell_subface_signs, cell_primitive_signs);
}
active_cell_label = filter_cells_by_boolean(tree, cell_primitive_signs);
}
filter_polygon_faces(iso_faces,
patches,
arrangement_cells,
shell_of_half_patch,
shells,
shell_to_cell,
active_cell_label,
output_polygon_faces,
output_vertex_counts_of_face);
filter_active_vertices(output_vertices, output_polygon_faces);
}
}
}