diff --git a/network_process/include/connect_by_topo/patch_connectivity.hpp b/network_process/include/connect_by_topo/patch_connectivity.hpp index 28bc754..6c9e19d 100644 --- a/network_process/include/connect_by_topo/patch_connectivity.hpp +++ b/network_process/include/connect_by_topo/patch_connectivity.hpp @@ -30,14 +30,20 @@ void compute_patches(const stl_vector_mp> &edges_of_face /** * @brief Group non-manifold iso-edges into chains * @param[in] iso_vert_count the count of iso-vertices. + * @param[in] patch_count the count of patches. + * @param[in] patch_of_face the mapping from face index to patch index. * @param[in] patch_edges the list of edges on the patch. * @param[out] chains non-manifold edges. * @param[out] chain_representative_headers the headers of edges in chains. + * @param[out] chain_of_patch the mapping from chain index to patch index. */ 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_t &chains, - stl_vector_mp &chain_representative_headers); + stl_vector_mp &chain_representative_headers, + flat_index_group_t &chain_of_patch); /** * @brief compute shells and connected components of isosurfaces, and build maps: half-patch --> shell, patch --> component diff --git a/network_process/src/connect_by_topo/patch_connectivity.cpp b/network_process/src/connect_by_topo/patch_connectivity.cpp index ef6eea6..bbf1d52 100644 --- a/network_process/src/connect_by_topo/patch_connectivity.cpp +++ b/network_process/src/connect_by_topo/patch_connectivity.cpp @@ -81,9 +81,12 @@ void compute_patches(const stl_vector_mp>& edges_of_face } 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_t& chains, - stl_vector_mp& chain_representative_headers) + stl_vector_mp& chain_representative_headers, + flat_index_group_t& chain_of_patch) { stl_vector_mp> non_manifold_edges_of_vert{}; stl_vector_mp non_manifold_edges{}; @@ -108,8 +111,9 @@ void compute_chains(size_t iso_vert_count, // 1. each chain can start from arbitary vertex of a non-manifold edge, and end at visited edge (i.e. a ring is built) or // singular vertex; // 2. along each chain, the neighboring patch does not change, otherwise a new chain is raised. - stl_vector_mp visited_edge(patch_edges.size(), false); - std::list chain_edges{}; + stl_vector_mp visited_edge(patch_edges.size(), false); + std::list chain_edges{}; + stl_vector_mp> split_chain_of_patch(patch_count); chains.index_group.reserve(non_manifold_edges.size() * 2); chains.start_indices.reserve(8); chain_representative_headers.reserve(8); @@ -118,17 +122,21 @@ void compute_chains(size_t iso_vert_count, // unvisited non-manifold iso-edge (not a boundary edge) // new chain chains.start_indices.emplace_back(static_cast(chains.index_group.size())); - auto& edge = patch_edges[i]; + auto chain_index = static_cast(chains.size()); + auto& edge = patch_edges[i]; + chain_edges.clear(); std::queue Q{}; Q.emplace(i); chain_edges.emplace_back(edge.v1); chain_edges.emplace_back(edge.v2); chain_representative_headers.emplace_back(edge); visited_edge[i] = true; - chain_edges.clear(); while (!Q.empty()) { const auto eId = Q.front(); Q.pop(); + for (const auto& header : patch_edges[eId].headers) { + split_chain_of_patch[patch_of_face[header.face_index]].emplace_back(chain_index); + } // v1 auto v = patch_edges[eId].v1; if (non_manifold_edges_of_vert[v].size() == 2) { @@ -185,6 +193,19 @@ void compute_chains(size_t iso_vert_count, chains.start_indices.emplace_back(static_cast(chains.index_group.size())); chains.start_indices.shrink_to_fit(); chains.index_group.shrink_to_fit(); + + { + size_t chain_patch_count{}; + for (const auto& chain_patches : split_chain_of_patch) { chain_patch_count += chain_patches.size(); } + chain_of_patch.index_group.reserve(chain_patch_count); + chain_of_patch.start_indices.reserve(split_chain_of_patch.size() + 1); + for (const auto& chain_patches : split_chain_of_patch) { + chain_of_patch.start_indices.emplace_back(static_cast(chain_of_patch.index_group.size())); + chain_of_patch.index_group.insert(chain_of_patch.index_group.end(), + std::make_move_iterator(chain_patches.begin()), + std::make_move_iterator(chain_patches.end())); + } + } } void compute_shells_and_components(const stl_vector_mp>& half_patch_adj_list, diff --git a/network_process/src/post_topo/filter_polygon_faces.cpp b/network_process/src/post_topo/filter_polygon_faces.cpp index 54e12e9..ca28a30 100644 --- a/network_process/src/post_topo/filter_polygon_faces.cpp +++ b/network_process/src/post_topo/filter_polygon_faces.cpp @@ -2,6 +2,12 @@ #include +// =========================================================================================================== + + + +// =========================================================================================================== + dynamic_bitset_mp<> filter_polygon_faces(const stl_vector_mp& faces, const flat_index_group_t& patches, const flat_index_group_t& arrangement_cells, @@ -13,6 +19,8 @@ dynamic_bitset_mp<> filter_polygon_faces(const stl_vector_mp& fa stl_vector_mp& output_vertex_counts_of_face) { dynamic_bitset_mp<> active_face_label(faces.size(), false); + dynamic_bitset_mp<> active_patch_label(patches.size(), false); + dynamic_bitset_mp<> patch_sign_label(patches.size(), false); output_polygon_faces.reserve(faces.size() * 3); output_vertex_counts_of_face.reserve(faces.size()); diff --git a/network_process/src/process.cpp b/network_process/src/process.cpp index 2221944..03190ae 100644 --- a/network_process/src/process.cpp +++ b/network_process/src/process.cpp @@ -68,24 +68,30 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& iso_faces); } // connect components by topology - // TODO: split headers of chains out, because it should not change during the chain - stl_vector_mp chain_representative_headers{}; - 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_t patches{}; - flat_index_group_t chains{}; - flat_index_group_t shells{}; - flat_index_group_t components{}; - flat_index_group_t arrangement_cells{}; - stl_vector_mp shell_to_cell{}; + 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_t patches{}; + flat_index_group_t chains{}; + flat_index_group_t shells{}; + flat_index_group_t components{}; + flat_index_group_t arrangement_cells{}; + stl_vector_mp shell_to_cell{}; + flat_index_group_t chain_of_patch{}; { + stl_vector_mp chain_representative_headers{}; { stl_vector_mp> edges_of_iso_face{}; stl_vector_mp 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, chain_representative_headers); + compute_chains(iso_verts.size(), + patches.size(), + patch_of_face, + iso_edges, + chains, + chain_representative_headers, + chain_of_patch); } stl_vector_mp> half_patch_adj_list(2 * chains.size()); chains.group_foreach([&](uint32_t chain_index, uint32_t _, uint32_t __) {