From c54c300fa6e601325b57972c33a2d4314679f000 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang <1627343141@qq.com> Date: Wed, 16 Jul 2025 18:38:14 +0800 Subject: [PATCH] temporary push --- .../connect_by_topo/patch_connectivity.cpp | 23 ++++---- .../topo_ray_shooting/find_extermal_edges.hpp | 30 +++++----- .../src/post_topo/filter_polygon_faces.cpp | 28 ++++++--- .../src/post_topo/patch_propagation.cpp | 14 ++--- network_process/src/process.cpp | 24 ++++---- .../container/wrapper/flat_index_group.hpp | 57 ++++++++++++------- 6 files changed, 101 insertions(+), 75 deletions(-) diff --git a/network_process/src/connect_by_topo/patch_connectivity.cpp b/network_process/src/connect_by_topo/patch_connectivity.cpp index 8b5bb2c..3307aaa 100644 --- a/network_process/src/connect_by_topo/patch_connectivity.cpp +++ b/network_process/src/connect_by_topo/patch_connectivity.cpp @@ -44,7 +44,7 @@ void compute_patch_edges(const stl_vector_mp& patch_faces, void compute_patches(const stl_vector_mp>& edges_of_face, const stl_vector_mp& patch_edges, const stl_vector_mp& patch_faces, - flat_index_group& patches, + flat_index_group& patches, stl_vector_mp& patch_of_face_mapping) { stl_vector_mp visited_face(edges_of_face.size(), false); @@ -84,9 +84,9 @@ void compute_chains(size_t iso_vert_count, size_t patch_count, stl_vector_mp& patch_of_face, stl_vector_mp& patch_edges, - flat_index_group& chains, + flat_index_group& chains, stl_vector_mp& chain_representative_headers, - flat_index_group& chain_of_patch) + flat_index_group& chain_of_patch) { stl_vector_mp> non_manifold_edges_of_vert{}; stl_vector_mp non_manifold_edges{}; @@ -209,9 +209,9 @@ void compute_chains(size_t iso_vert_count, } void compute_shells_and_components(const stl_vector_mp>& half_patch_adj_list, - flat_index_group& shells, + flat_index_group& shells, stl_vector_mp& shell_of_half_patch, - flat_index_group& components, + flat_index_group& components, stl_vector_mp& component_of_patch) { const auto num_patch = half_patch_adj_list.size() / 2; @@ -298,7 +298,7 @@ void compute_shells_and_components(const stl_vector_mp>& void compute_arrangement_cells(uint32_t num_shell, const stl_vector_mp>& shell_links, - flat_index_group& arrangement_cells) + flat_index_group& arrangement_cells) { // build shell adjacency list 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.start_indices.reserve(arrangement_cells.size() + 1); 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()) { sink_free_cells.start_indices.emplace_back(static_cast(sink_free_cells.index_group.size())); } - for (auto i = range_start; i < range_end; ++i) { - if (arrangement_cells.index_group[i] < num_shell) { - sink_free_cells.index_group.emplace_back(arrangement_cells.index_group[i]); - } + + for (auto shell_index : arrangement_cells.group(cell_index)) { + 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.start_indices.shrink_to_fit(); std::swap(arrangement_cells, sink_free_cells); diff --git a/network_process/src/connect_by_topo/topo_ray_shooting/find_extermal_edges.hpp b/network_process/src/connect_by_topo/topo_ray_shooting/find_extermal_edges.hpp index 8541c70..0eed8aa 100644 --- a/network_process/src/connect_by_topo/topo_ray_shooting/find_extermal_edges.hpp +++ b/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 stl_vector_mp &iso_verts, const stl_vector_mp &iso_faces, - const flat_index_group &patches, - const flat_index_group &components, + const flat_index_group &patches, + const flat_index_group &components, const stl_vector_mp &component_of_patch, const flat_hash_map_mp &next_vert, // 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); // stl_vector_mp 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]; auto &u1 = extremal_edge_of_component[2 * component_id]; auto &u2 = extremal_edge_of_component[2 * component_id + 1]; - for (uint32_t i = range_start; i < range_end; ++i) { - const auto &fId = patches.index_group[i]; - for (const auto &tet_face : iso_faces[fId].headers) iso_face_id_of_tet_face.try_emplace(tet_face, fId); - for (const auto vId : iso_faces[fId].vertex_indices) { - if (!is_iso_vert_visited[vId]) { - is_iso_vert_visited[vId] = true; - const auto &vert = iso_verts[vId]; + for (auto face_index : patches.group(patch_index)) { + for (const auto &tet_face : iso_faces[face_index].headers) + iso_face_id_of_tet_face.try_emplace(tet_face, face_index); + for (const auto vertex_index : iso_faces[face_index].vertex_indices) { + if (!is_iso_vert_visited[vertex_index]) { + is_iso_vert_visited[vertex_index] = true; + const auto &vert = iso_verts[vertex_index]; if (vert.header.minimal_simplex_flag == 2) { // edge iso-vertex const auto v1 = vert.simplex_vertex_indices[0]; 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 - iso_vert_on_v_v_next[v1] = vId; + iso_vert_on_v_v_next[v1] = vertex_index; // fill map iso_vId_compId_of_tet_vert.try_emplace( 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 // update extremal edge if (u1.valid == 0) { @@ -73,15 +73,15 @@ static inline void find_extremal_edges( } } // 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 iso_vId_compId_of_tet_vert.try_emplace( 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}); } } } } } - }); + } } \ No newline at end of file diff --git a/network_process/src/post_topo/filter_polygon_faces.cpp b/network_process/src/post_topo/filter_polygon_faces.cpp index 2653764..ce0ecfe 100644 --- a/network_process/src/post_topo/filter_polygon_faces.cpp +++ b/network_process/src/post_topo/filter_polygon_faces.cpp @@ -2,6 +2,10 @@ #include +struct chain_end_vertex_header { + uint8_t neighbor_chain_count{}; +}; + // =========================================================================================================== 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& faces, +void transfer_active_prims(const baked_blobtree_t& tree, + const stl_vector_mp& faces, const flat_index_group& patches, const flat_index_group& chain_of_patch, const dynamic_bitset_mp<>& active_patch_label, @@ -53,9 +58,17 @@ void transfer_active_prims(const stl_vector_mp& faces, stl_vector_mp& output_vertex_counts_of_face, stl_vector_mp& output_parametric_planes) { + flat_hash_map_mp 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(); if (active_patch_index != dynamic_bitset_mp<>::npos) { do { + // const auto subface_index = faces[patches.] + // 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 // so we need to flip its vertex order here @@ -66,25 +79,26 @@ void transfer_active_prims(const stl_vector_mp& faces, // (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 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; output_vertex_counts_of_face.emplace_back(face_vertices.size()); output_polygon_faces.insert(output_polygon_faces.end(), std::make_move_iterator(face_vertices.rbegin()), std::make_move_iterator(face_vertices.rend())); - }); + } } 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; output_vertex_counts_of_face.emplace_back(face_vertices.size()); output_polygon_faces.insert(output_polygon_faces.end(), std::make_move_iterator(face_vertices.begin()), std::make_move_iterator(face_vertices.end())); - }); + } } - chain_of_patch.loop_on_group(active_patch_index, - [&](uint32_t _, uint32_t chain_index) { active_chain_label[chain_index].set(); }); + for (auto chain_index : chain_of_patch.group(active_patch_index)) { + + } active_patch_index = active_patch_label.find_next(active_patch_index); } while (active_patch_index != dynamic_bitset_mp<>::npos); diff --git a/network_process/src/post_topo/patch_propagation.cpp b/network_process/src/post_topo/patch_propagation.cpp index 4698a07..9963844 100644 --- a/network_process/src/post_topo/patch_propagation.cpp +++ b/network_process/src/post_topo/patch_propagation.cpp @@ -5,10 +5,10 @@ void propagate_subface_labels(const baked_blobtree_t& tree, const stl_vector_mp& faces, - const flat_index_group& patches, - const flat_index_group& arrangement_cells, + const flat_index_group& patches, + const flat_index_group& arrangement_cells, const stl_vector_mp& shell_of_half_patch, - const flat_index_group& shells, + const flat_index_group& shells, const stl_vector_mp& shell_to_cell, stl_vector_mp>& cell_subface_signs) { @@ -29,8 +29,8 @@ void propagate_subface_labels(const baked_blobtree_t& tree, visited_cells[cell_index] = true; cell_neighbors_map.clear(); - arrangement_cells.loop_on_group(cell_index, [&](uint32_t _, uint32_t shell_index) { - shells.loop_on_group(shell_index, [&](uint32_t _, uint32_t half_patch_index) { + for (auto shell_index : arrangement_cells.group(cell_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; // 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 @@ -57,8 +57,8 @@ void propagate_subface_labels(const baked_blobtree_t& tree, } cell_indices_of_inactive_subfaces[subface_label].clear(); } - }); - }); + } + } // fetch inactive subface index for (uint32_t subface_index = 0; subface_index < num_subface; subface_index++) { diff --git a/network_process/src/process.cpp b/network_process/src/process.cpp index 69420b3..035c9a3 100644 --- a/network_process/src/process.cpp +++ b/network_process/src/process.cpp @@ -71,13 +71,13 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& stl_vector_mp patch_of_face(iso_faces.size()); stl_vector_mp shell_of_half_patch{}; stl_vector_mp component_of_patch{}; - flat_index_group patches{}; - flat_index_group chains{}; - flat_index_group shells{}; - flat_index_group components{}; - flat_index_group arrangement_cells{}; + flat_index_group patches{}; + flat_index_group chains{}; + flat_index_group shells{}; + flat_index_group components{}; + flat_index_group arrangement_cells{}; stl_vector_mp shell_to_cell{}; - flat_index_group chain_of_patch{}; + flat_index_group chain_of_patch{}; { stl_vector_mp chain_representative_headers{}; { @@ -94,7 +94,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& chain_of_patch); } stl_vector_mp> 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, chain_representative_headers[chain_index], iso_verts, @@ -105,7 +105,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& 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); 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()); - arrangement_cells.foreach ([&shell_to_cell](uint32_t cell_index, uint32_t _, uint32_t shell_index) { - shell_to_cell[shell_index] = cell_index; - }); + for (auto cell_index : arrangement_cells.group_indices()) { + for (auto shell_index : arrangement_cells.group(cell_index)) { shell_to_cell[shell_index] = cell_index; } + } } // 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<> patch_sign_label(patches.size(), false); - + filter_polygon_faces(iso_faces, patches, arrangement_cells, diff --git a/shared_module/container/wrapper/flat_index_group.hpp b/shared_module/container/wrapper/flat_index_group.hpp index f9494d2..c95080a 100644 --- a/shared_module/container/wrapper/flat_index_group.hpp +++ b/shared_module/container/wrapper/flat_index_group.hpp @@ -1,6 +1,7 @@ #pragma once -#include "../stl_alias.hpp" +#include "container/stl_alias.hpp" +#include "iterator/counting_iterator.hpp" struct flat_index_group { stl_vector_mp 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; } - // f(group_index, element_index_in_group, elemenet) - template - inline void foreach (F&& f) const - { - 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) { - f(group_idx, elem_idx, index_group[start_indices[group_idx] + elem_idx]); - } + struct group_index_looper { + auto begin() const { return counting_iterator{0}; } + + auto end() const { return counting_iterator{static_cast(parent_group.size())}; } + + const flat_index_group& parent_group{}; + }; + + 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) - template - inline void group_foreach(F&& f) const - { - for (uint32_t group_idx = 0; group_idx < size(); ++group_idx) { - f(group_idx, start_indices[group_idx], start_indices[group_idx + 1]); + auto end() const + { + return std::next(parent_group.index_group.begin(), *(parent_group.start_indices.begin() + 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{0}; } + + inline auto group_index_iter_end() const { return counting_iterator{static_cast(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) - template - inline void loop_on_group(uint32_t group_idx, F&& f) const + inline auto group_end(uint32_t group_idx) const { - for (uint32_t elem_idx = 0; elem_idx < start_indices[group_idx + 1] - start_indices[group_idx]; ++elem_idx) { - f(elem_idx, index_group[start_indices[group_idx] + elem_idx]); - } + return std::next(index_group.begin(), *(start_indices.begin() + group_idx + 1)); } }; \ No newline at end of file