Browse Source

temporary push

V2
Zhicheng Wang 6 days ago
parent
commit
c54c300fa6
  1. 23
      network_process/src/connect_by_topo/patch_connectivity.cpp
  2. 30
      network_process/src/connect_by_topo/topo_ray_shooting/find_extermal_edges.hpp
  3. 28
      network_process/src/post_topo/filter_polygon_faces.cpp
  4. 14
      network_process/src/post_topo/patch_propagation.cpp
  5. 24
      network_process/src/process.cpp
  6. 57
      shared_module/container/wrapper/flat_index_group.hpp

23
network_process/src/connect_by_topo/patch_connectivity.cpp

@ -44,7 +44,7 @@ void compute_patch_edges(const stl_vector_mp<polygon_face_t>& patch_faces,
void compute_patches(const stl_vector_mp<stl_vector_mp<uint32_t>>& edges_of_face, void compute_patches(const stl_vector_mp<stl_vector_mp<uint32_t>>& edges_of_face,
const stl_vector_mp<iso_edge_t>& patch_edges, const stl_vector_mp<iso_edge_t>& patch_edges,
const stl_vector_mp<polygon_face_t>& patch_faces, const stl_vector_mp<polygon_face_t>& patch_faces,
flat_index_group& patches, flat_index_group& patches,
stl_vector_mp<uint32_t>& patch_of_face_mapping) stl_vector_mp<uint32_t>& patch_of_face_mapping)
{ {
stl_vector_mp<bool> visited_face(edges_of_face.size(), false); stl_vector_mp<bool> visited_face(edges_of_face.size(), false);
@ -84,9 +84,9 @@ void compute_chains(size_t iso_vert_count,
size_t patch_count, size_t patch_count,
stl_vector_mp<uint32_t>& patch_of_face, stl_vector_mp<uint32_t>& patch_of_face,
stl_vector_mp<iso_edge_t>& patch_edges, stl_vector_mp<iso_edge_t>& patch_edges,
flat_index_group& chains, flat_index_group& chains,
stl_vector_mp<iso_edge_t>& chain_representative_headers, stl_vector_mp<iso_edge_t>& chain_representative_headers,
flat_index_group& chain_of_patch) flat_index_group& chain_of_patch)
{ {
stl_vector_mp<stl_vector_mp<uint32_t>> non_manifold_edges_of_vert{}; stl_vector_mp<stl_vector_mp<uint32_t>> non_manifold_edges_of_vert{};
stl_vector_mp<uint32_t> non_manifold_edges{}; stl_vector_mp<uint32_t> non_manifold_edges{};
@ -209,9 +209,9 @@ void compute_chains(size_t iso_vert_count,
} }
void compute_shells_and_components(const stl_vector_mp<stl_vector_mp<uint32_t>>& half_patch_adj_list, void compute_shells_and_components(const stl_vector_mp<stl_vector_mp<uint32_t>>& half_patch_adj_list,
flat_index_group& shells, flat_index_group& shells,
stl_vector_mp<uint32_t>& shell_of_half_patch, stl_vector_mp<uint32_t>& shell_of_half_patch,
flat_index_group& components, flat_index_group& components,
stl_vector_mp<uint32_t>& component_of_patch) stl_vector_mp<uint32_t>& component_of_patch)
{ {
const auto num_patch = half_patch_adj_list.size() / 2; const auto num_patch = half_patch_adj_list.size() / 2;
@ -298,7 +298,7 @@ void compute_shells_and_components(const stl_vector_mp<stl_vector_mp<uint32_t>>&
void compute_arrangement_cells(uint32_t num_shell, void compute_arrangement_cells(uint32_t num_shell,
const stl_vector_mp<std::pair<uint32_t, uint32_t>>& shell_links, const stl_vector_mp<std::pair<uint32_t, uint32_t>>& shell_links,
flat_index_group& arrangement_cells) flat_index_group& arrangement_cells)
{ {
// build shell adjacency list // build shell adjacency list
uint32_t sink_shell = num_shell; uint32_t sink_shell = num_shell;
@ -347,16 +347,15 @@ void compute_arrangement_cells(uint32_t
sink_free_cells.index_group.reserve(arrangement_cells.index_group.size()); sink_free_cells.index_group.reserve(arrangement_cells.index_group.size());
sink_free_cells.start_indices.reserve(arrangement_cells.size() + 1); sink_free_cells.start_indices.reserve(arrangement_cells.size() + 1);
sink_free_cells.start_indices.emplace_back(0); sink_free_cells.start_indices.emplace_back(0);
sink_free_cells.group_foreach([&](uint32_t group_idx, uint32_t range_start, uint32_t range_end) { for (auto cell_index : arrangement_cells.group_indices()) {
if (sink_free_cells.index_group.size() > sink_free_cells.start_indices.back()) { if (sink_free_cells.index_group.size() > sink_free_cells.start_indices.back()) {
sink_free_cells.start_indices.emplace_back(static_cast<uint32_t>(sink_free_cells.index_group.size())); sink_free_cells.start_indices.emplace_back(static_cast<uint32_t>(sink_free_cells.index_group.size()));
} }
for (auto i = range_start; i < range_end; ++i) {
if (arrangement_cells.index_group[i] < num_shell) { for (auto shell_index : arrangement_cells.group(cell_index)) {
sink_free_cells.index_group.emplace_back(arrangement_cells.index_group[i]); if (shell_index < num_shell) sink_free_cells.index_group.emplace_back(shell_index);
}
} }
}); }
sink_free_cells.index_group.shrink_to_fit(); sink_free_cells.index_group.shrink_to_fit();
sink_free_cells.start_indices.shrink_to_fit(); sink_free_cells.start_indices.shrink_to_fit();
std::swap(arrangement_cells, sink_free_cells); std::swap(arrangement_cells, sink_free_cells);

30
network_process/src/connect_by_topo/topo_ray_shooting/find_extermal_edges.hpp

@ -7,8 +7,8 @@ static inline void find_extremal_edges(
const scene_bg_mesh_info_t &scene_bg_mesh_info, const scene_bg_mesh_info_t &scene_bg_mesh_info,
const stl_vector_mp<iso_vertex_t> &iso_verts, const stl_vector_mp<iso_vertex_t> &iso_verts,
const stl_vector_mp<polygon_face_t> &iso_faces, const stl_vector_mp<polygon_face_t> &iso_faces,
const flat_index_group &patches, const flat_index_group &patches,
const flat_index_group &components, const flat_index_group &components,
const stl_vector_mp<uint32_t> &component_of_patch, const stl_vector_mp<uint32_t> &component_of_patch,
const flat_hash_map_mp<compact_bg_mesh_coord_t, compact_bg_mesh_coord_t> &next_vert, const flat_hash_map_mp<compact_bg_mesh_coord_t, compact_bg_mesh_coord_t> &next_vert,
// extremal edge of component i is stored at position [2*i], [2*i+1] // extremal edge of component i is stored at position [2*i], [2*i+1]
@ -26,17 +26,17 @@ static inline void find_extremal_edges(
iso_vId_compId_of_tet_vert.reserve(iso_faces.size() / 2); iso_vId_compId_of_tet_vert.reserve(iso_faces.size() / 2);
// //
stl_vector_mp<bool> is_iso_vert_visited(iso_verts.size(), false); stl_vector_mp<bool> is_iso_vert_visited(iso_verts.size(), false);
patches.group_foreach([&](uint32_t patch_index, uint32_t range_start, uint32_t range_end) { for (auto patch_index : patches.group_indices()) {
uint32_t component_id = component_of_patch[patch_index]; uint32_t component_id = component_of_patch[patch_index];
auto &u1 = extremal_edge_of_component[2 * component_id]; auto &u1 = extremal_edge_of_component[2 * component_id];
auto &u2 = extremal_edge_of_component[2 * component_id + 1]; auto &u2 = extremal_edge_of_component[2 * component_id + 1];
for (uint32_t i = range_start; i < range_end; ++i) { for (auto face_index : patches.group(patch_index)) {
const auto &fId = patches.index_group[i]; for (const auto &tet_face : iso_faces[face_index].headers)
for (const auto &tet_face : iso_faces[fId].headers) iso_face_id_of_tet_face.try_emplace(tet_face, fId); iso_face_id_of_tet_face.try_emplace(tet_face, face_index);
for (const auto vId : iso_faces[fId].vertex_indices) { for (const auto vertex_index : iso_faces[face_index].vertex_indices) {
if (!is_iso_vert_visited[vId]) { if (!is_iso_vert_visited[vertex_index]) {
is_iso_vert_visited[vId] = true; is_iso_vert_visited[vertex_index] = true;
const auto &vert = iso_verts[vId]; const auto &vert = iso_verts[vertex_index];
if (vert.header.minimal_simplex_flag == 2) { // edge iso-vertex if (vert.header.minimal_simplex_flag == 2) { // edge iso-vertex
const auto v1 = vert.simplex_vertex_indices[0]; const auto v1 = vert.simplex_vertex_indices[0];
const auto v2 = vert.simplex_vertex_indices[1]; const auto v2 = vert.simplex_vertex_indices[1];
@ -54,11 +54,11 @@ static inline void find_extremal_edges(
} }
} }
// record an iso-vert on edge v1 -> v2 // record an iso-vert on edge v1 -> v2
iso_vert_on_v_v_next[v1] = vId; iso_vert_on_v_v_next[v1] = vertex_index;
// fill map // fill map
iso_vId_compId_of_tet_vert.try_emplace( iso_vId_compId_of_tet_vert.try_emplace(
simplified_vertex_header_t{vert.header.volume_index, vert.header.local_vertex_index}, simplified_vertex_header_t{vert.header.volume_index, vert.header.local_vertex_index},
component_header_t{vId, component_id}); component_header_t{vertex_index, component_id});
} else if (next_vert.at(v2) == v1) { // on tree edge v2 -> v1 } else if (next_vert.at(v2) == v1) { // on tree edge v2 -> v1
// update extremal edge // update extremal edge
if (u1.valid == 0) { if (u1.valid == 0) {
@ -73,15 +73,15 @@ static inline void find_extremal_edges(
} }
} }
// record an iso-vert on v2 -> v1 // record an iso-vert on v2 -> v1
iso_vert_on_v_v_next[v2] = vId; iso_vert_on_v_v_next[v2] = vertex_index;
// fill map // fill map
iso_vId_compId_of_tet_vert.try_emplace( iso_vId_compId_of_tet_vert.try_emplace(
simplified_vertex_header_t{vert.header.volume_index, vert.header.local_vertex_index}, simplified_vertex_header_t{vert.header.volume_index, vert.header.local_vertex_index},
component_header_t{vId, component_id}); component_header_t{vertex_index, component_id});
} }
} }
} }
} }
} }
}); }
} }

28
network_process/src/post_topo/filter_polygon_faces.cpp

@ -2,6 +2,10 @@
#include <post_topo.hpp> #include <post_topo.hpp>
struct chain_end_vertex_header {
uint8_t neighbor_chain_count{};
};
// =========================================================================================================== // ===========================================================================================================
void collect_active_prims(const flat_index_group& patches, void collect_active_prims(const flat_index_group& patches,
@ -44,7 +48,8 @@ void collect_active_prims(const flat_index_group& patches,
} }
} }
void transfer_active_prims(const stl_vector_mp<polygon_face_t>& faces, void transfer_active_prims(const baked_blobtree_t& tree,
const stl_vector_mp<polygon_face_t>& faces,
const flat_index_group& patches, const flat_index_group& patches,
const flat_index_group& chain_of_patch, const flat_index_group& chain_of_patch,
const dynamic_bitset_mp<>& active_patch_label, const dynamic_bitset_mp<>& active_patch_label,
@ -53,9 +58,17 @@ void transfer_active_prims(const stl_vector_mp<polygon_face_t>& faces,
stl_vector_mp<uint32_t>& output_vertex_counts_of_face, stl_vector_mp<uint32_t>& output_vertex_counts_of_face,
stl_vector_mp<parametric_plane>& output_parametric_planes) stl_vector_mp<parametric_plane>& output_parametric_planes)
{ {
flat_hash_map_mp<uint32_t, chain_end_vertex_header> chain_end_vertex_headers{};
const auto& subfaces = tree.subfaces;
output_polygon_faces.reserve(faces.size());
output_vertex_counts_of_face.reserve(faces.size() * 3);
output_parametric_planes.resize(subfaces.size());
auto active_patch_index = active_patch_label.find_first(); auto active_patch_index = active_patch_label.find_first();
if (active_patch_index != dynamic_bitset_mp<>::npos) { if (active_patch_index != dynamic_bitset_mp<>::npos) {
do { do {
// const auto subface_index = faces[patches.]
// NOTE: since patch inside the sdf should be oriented counterclockwise when viewed from inside // NOTE: since patch inside the sdf should be oriented counterclockwise when viewed from inside
// i.e. it is viewed to be clockwise when viewed from outside // i.e. it is viewed to be clockwise when viewed from outside
// so we need to flip its vertex order here // so we need to flip its vertex order here
@ -66,25 +79,26 @@ void transfer_active_prims(const stl_vector_mp<polygon_face_t>& faces,
// (i.e. clockwise), then its normal should point to the other side of that surface, which is the // (i.e. clockwise), then its normal should point to the other side of that surface, which is the
// outside of that surface, so it is also right // outside of that surface, so it is also right
if (!patch_sign_label[active_patch_index]) { if (!patch_sign_label[active_patch_index]) {
patches.loop_on_group(active_patch_index, [&](uint32_t _, uint32_t face_index) { for (auto face_index : patches.group(active_patch_index)) {
const auto& face_vertices = faces[face_index].vertex_indices; const auto& face_vertices = faces[face_index].vertex_indices;
output_vertex_counts_of_face.emplace_back(face_vertices.size()); output_vertex_counts_of_face.emplace_back(face_vertices.size());
output_polygon_faces.insert(output_polygon_faces.end(), output_polygon_faces.insert(output_polygon_faces.end(),
std::make_move_iterator(face_vertices.rbegin()), std::make_move_iterator(face_vertices.rbegin()),
std::make_move_iterator(face_vertices.rend())); std::make_move_iterator(face_vertices.rend()));
}); }
} else { } else {
patches.loop_on_group(active_patch_index, [&](uint32_t _, uint32_t face_index) { for (auto face_index : patches.group(active_patch_index)) {
const auto& face_vertices = faces[face_index].vertex_indices; const auto& face_vertices = faces[face_index].vertex_indices;
output_vertex_counts_of_face.emplace_back(face_vertices.size()); output_vertex_counts_of_face.emplace_back(face_vertices.size());
output_polygon_faces.insert(output_polygon_faces.end(), output_polygon_faces.insert(output_polygon_faces.end(),
std::make_move_iterator(face_vertices.begin()), std::make_move_iterator(face_vertices.begin()),
std::make_move_iterator(face_vertices.end())); std::make_move_iterator(face_vertices.end()));
}); }
} }
chain_of_patch.loop_on_group(active_patch_index, for (auto chain_index : chain_of_patch.group(active_patch_index)) {
[&](uint32_t _, uint32_t chain_index) { active_chain_label[chain_index].set(); });
}
active_patch_index = active_patch_label.find_next(active_patch_index); active_patch_index = active_patch_label.find_next(active_patch_index);
} while (active_patch_index != dynamic_bitset_mp<>::npos); } while (active_patch_index != dynamic_bitset_mp<>::npos);

14
network_process/src/post_topo/patch_propagation.cpp

@ -5,10 +5,10 @@
void propagate_subface_labels(const baked_blobtree_t& tree, void propagate_subface_labels(const baked_blobtree_t& tree,
const stl_vector_mp<polygon_face_t>& faces, const stl_vector_mp<polygon_face_t>& faces,
const flat_index_group& patches, const flat_index_group& patches,
const flat_index_group& arrangement_cells, const flat_index_group& arrangement_cells,
const stl_vector_mp<uint32_t>& shell_of_half_patch, const stl_vector_mp<uint32_t>& shell_of_half_patch,
const flat_index_group& shells, const flat_index_group& shells,
const stl_vector_mp<uint32_t>& shell_to_cell, const stl_vector_mp<uint32_t>& shell_to_cell,
stl_vector_mp<dynamic_bitset_mp<>>& cell_subface_signs) stl_vector_mp<dynamic_bitset_mp<>>& cell_subface_signs)
{ {
@ -29,8 +29,8 @@ void propagate_subface_labels(const baked_blobtree_t& tree,
visited_cells[cell_index] = true; visited_cells[cell_index] = true;
cell_neighbors_map.clear(); cell_neighbors_map.clear();
arrangement_cells.loop_on_group(cell_index, [&](uint32_t _, uint32_t shell_index) { for (auto shell_index : arrangement_cells.group(cell_index)) {
shells.loop_on_group(shell_index, [&](uint32_t _, uint32_t half_patch_index) { for (auto half_patch_index : shells.group(shell_index)) {
auto subface_label = faces[patches.index_group[patches.start_indices[half_patch_index / 2]]].subface_index; auto subface_label = faces[patches.index_group[patches.start_indices[half_patch_index / 2]]].subface_index;
// CAUTION: we assume that the sign is 1 when the surface is inside the sdf before // CAUTION: we assume that the sign is 1 when the surface is inside the sdf before
// but in blobtree we assume that the sign is 0 when the surface is inside the sdf // but in blobtree we assume that the sign is 0 when the surface is inside the sdf
@ -57,8 +57,8 @@ void propagate_subface_labels(const baked_blobtree_t& tree,
} }
cell_indices_of_inactive_subfaces[subface_label].clear(); cell_indices_of_inactive_subfaces[subface_label].clear();
} }
}); }
}); }
// fetch inactive subface index // fetch inactive subface index
for (uint32_t subface_index = 0; subface_index < num_subface; subface_index++) { for (uint32_t subface_index = 0; subface_index < num_subface; subface_index++) {

24
network_process/src/process.cpp

@ -71,13 +71,13 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
stl_vector_mp<uint32_t> patch_of_face(iso_faces.size()); 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> shell_of_half_patch{};
stl_vector_mp<uint32_t> component_of_patch{}; stl_vector_mp<uint32_t> component_of_patch{};
flat_index_group patches{}; flat_index_group patches{};
flat_index_group chains{}; flat_index_group chains{};
flat_index_group shells{}; flat_index_group shells{};
flat_index_group components{}; flat_index_group components{};
flat_index_group arrangement_cells{}; flat_index_group arrangement_cells{};
stl_vector_mp<uint32_t> shell_to_cell{}; stl_vector_mp<uint32_t> shell_to_cell{};
flat_index_group chain_of_patch{}; flat_index_group chain_of_patch{};
{ {
stl_vector_mp<iso_edge_t> chain_representative_headers{}; stl_vector_mp<iso_edge_t> chain_representative_headers{};
{ {
@ -94,7 +94,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
chain_of_patch); chain_of_patch);
} }
stl_vector_mp<stl_vector_mp<uint32_t>> half_patch_adj_list(2 * chains.size()); stl_vector_mp<stl_vector_mp<uint32_t>> half_patch_adj_list(2 * chains.size());
chains.group_foreach([&](uint32_t chain_index, uint32_t _, uint32_t __) { for (auto chain_index : chains.group_indices()) {
compute_patch_order(tetrahedrons, compute_patch_order(tetrahedrons,
chain_representative_headers[chain_index], chain_representative_headers[chain_index],
iso_verts, iso_verts,
@ -105,7 +105,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
zero_vertex_to_incident_tet_mapping, zero_vertex_to_incident_tet_mapping,
patch_of_face, patch_of_face,
half_patch_adj_list); half_patch_adj_list);
}); }
compute_shells_and_components(half_patch_adj_list, shells, shell_of_half_patch, components, component_of_patch); compute_shells_and_components(half_patch_adj_list, shells, shell_of_half_patch, components, component_of_patch);
if (components.size() == 1) // no nesting problem, each shell is an arrangement cell if (components.size() == 1) // no nesting problem, each shell is an arrangement cell
@ -134,9 +134,9 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
} }
shell_to_cell.resize(arrangement_cells.size()); shell_to_cell.resize(arrangement_cells.size());
arrangement_cells.foreach ([&shell_to_cell](uint32_t cell_index, uint32_t _, uint32_t shell_index) { for (auto cell_index : arrangement_cells.group_indices()) {
shell_to_cell[shell_index] = cell_index; for (auto shell_index : arrangement_cells.group(cell_index)) { shell_to_cell[shell_index] = cell_index; }
}); }
} }
// post process // post process
@ -162,7 +162,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
} }
dynamic_bitset_mp<> active_patch_label(patches.size(), false); dynamic_bitset_mp<> active_patch_label(patches.size(), false);
dynamic_bitset_mp<> patch_sign_label(patches.size(), false); dynamic_bitset_mp<> patch_sign_label(patches.size(), false);
filter_polygon_faces(iso_faces, filter_polygon_faces(iso_faces,
patches, patches,
arrangement_cells, arrangement_cells,

57
shared_module/container/wrapper/flat_index_group.hpp

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "../stl_alias.hpp" #include "container/stl_alias.hpp"
#include "iterator/counting_iterator.hpp"
struct flat_index_group { struct flat_index_group {
stl_vector_mp<uint32_t> index_group{}; /// a list of indices in the group stl_vector_mp<uint32_t> index_group{}; /// a list of indices in the group
@ -8,32 +9,44 @@ struct flat_index_group {
inline size_t size() const { return start_indices.size() - 1; } inline size_t size() const { return start_indices.size() - 1; }
// f(group_index, element_index_in_group, elemenet) struct group_index_looper {
template <typename F> auto begin() const { return counting_iterator<uint32_t>{0}; }
inline void foreach (F&& f) const
{ auto end() const { return counting_iterator<uint32_t>{static_cast<uint32_t>(parent_group.size())}; }
for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) {
for (uint32_t elem_idx = 0; elem_idx < start_indices[group_idx + 1] - start_indices[group_idx]; ++elem_idx) { const flat_index_group& parent_group{};
f(group_idx, elem_idx, index_group[start_indices[group_idx] + elem_idx]); };
}
auto group_indices() const { return group_index_looper{*this}; }
struct group_looper {
auto begin() const
{
return std::next(parent_group.index_group.begin(), *(parent_group.start_indices.begin() + group_idx));
} }
}
// f(group_index, group_start_index, group_end_index) auto end() const
template <typename F> {
inline void group_foreach(F&& f) const return std::next(parent_group.index_group.begin(), *(parent_group.start_indices.begin() + group_idx + 1));
{
for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) {
f(group_idx, start_indices[group_idx], start_indices[group_idx + 1]);
} }
const flat_index_group& parent_group{};
const uint32_t group_idx{};
};
auto group(uint32_t group_idx) const { return group_looper{*this, group_idx}; }
inline auto group_index_iter_begin() const { return counting_iterator<uint32_t>{0}; }
inline auto group_index_iter_end() const { return counting_iterator<uint32_t>{static_cast<uint32_t>(size())}; }
inline auto group_begin(uint32_t group_idx) const
{
return std::next(index_group.begin(), *(start_indices.begin() + group_idx));
} }
// f(element_index_in_group, element) inline auto group_end(uint32_t group_idx) const
template <typename F>
inline void loop_on_group(uint32_t group_idx, F&& f) const
{ {
for (uint32_t elem_idx = 0; elem_idx < start_indices[group_idx + 1] - start_indices[group_idx]; ++elem_idx) { return std::next(index_group.begin(), *(start_indices.begin() + group_idx + 1));
f(elem_idx, index_group[start_indices[group_idx] + elem_idx]);
}
} }
}; };
Loading…
Cancel
Save