Browse Source

temporary push

V2
Zhicheng Wang 6 days ago
parent
commit
c54c300fa6
  1. 9
      network_process/src/connect_by_topo/patch_connectivity.cpp
  2. 26
      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. 8
      network_process/src/post_topo/patch_propagation.cpp
  5. 10
      network_process/src/process.cpp
  6. 53
      shared_module/container/wrapper/flat_index_group.hpp

9
network_process/src/connect_by_topo/patch_connectivity.cpp

@ -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);

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

@ -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);

8
network_process/src/post_topo/patch_propagation.cpp

@ -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++) {

10
network_process/src/process.cpp

@ -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

53
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())}; }
const flat_index_group& parent_group{};
};
auto group_indices() const { return group_index_looper{*this}; }
struct group_looper {
auto begin() const
{ {
for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) { return std::next(parent_group.index_group.begin(), *(parent_group.start_indices.begin() + group_idx));
for (uint32_t elem_idx = 0; elem_idx < start_indices[group_idx + 1] - start_indices[group_idx]; ++elem_idx) {
f(group_idx, elem_idx, index_group[start_indices[group_idx] + elem_idx]);
}
}
} }
// f(group_index, group_start_index, group_end_index) auto end() const
template <typename F>
inline void group_foreach(F&& f) const
{ {
for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) { return std::next(parent_group.index_group.begin(), *(parent_group.start_indices.begin() + group_idx + 1));
f(group_idx, start_indices[group_idx], start_indices[group_idx + 1]);
}
} }
// f(element_index_in_group, element) const flat_index_group& parent_group{};
template <typename F> const uint32_t group_idx{};
inline void loop_on_group(uint32_t group_idx, F&& f) const };
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
{ {
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));
f(elem_idx, index_group[start_indices[group_idx] + elem_idx]);
} }
inline auto group_end(uint32_t group_idx) const
{
return std::next(index_group.begin(), *(start_indices.begin() + group_idx + 1));
} }
}; };
Loading…
Cancel
Save