Browse Source

revert to dense sample for primitive generation

V2-origin
Zhicheng Wang 3 days ago
parent
commit
81edca713d
  1. 8
      network_process/include/helper.hpp
  2. 39
      network_process/include/prim_gen.hpp
  3. 19
      network_process/src/prim_gen/comp_imp_arrange.cpp
  4. 77
      network_process/src/prim_gen/extract_mesh.cpp
  5. 8
      network_process/src/prim_gen/extract_vertex_infos.cpp
  6. 105
      network_process/src/prim_gen/filter_tet_by_subface.cpp
  7. 10
      network_process/src/process.cpp

8
network_process/include/helper.hpp

@ -4,14 +4,6 @@
#include <fwd_types.hpp> #include <fwd_types.hpp>
template <typename Index>
static inline auto find_subface_by_index(const stl_vector_mp<vert_face_info_t>& faces, Index subface_index)
{
return std::find_if(faces.begin(), faces.end(), [&](const vert_face_info_t& x) {
return x.subface_index == subface_index;
});
}
// compute barycentric coordinate of Point (intersection of three planes) // compute barycentric coordinate of Point (intersection of three planes)
// Point in tet cell // Point in tet cell
template <typename Scalar> template <typename Scalar>

39
network_process/include/prim_gen.hpp

@ -9,35 +9,36 @@
using grid_region = std::pair<Eigen::Vector<size_t, 3>, Eigen::Vector<size_t, 3>>; using grid_region = std::pair<Eigen::Vector<size_t, 3>, Eigen::Vector<size_t, 3>>;
void extract_vertex_infos(const s_settings& settings, void extract_vertex_infos(const s_settings& settings,
const baked_blobtree_t& tree, const baked_blobtree_t& tree,
scene_bg_mesh_info_t& scene_bg_mesh_info, scene_bg_mesh_info_t& scene_bg_mesh_info,
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, Eigen::Ref<Eigen::MatrixXd> vertex_infos);
stl_vector_mp<grid_region>& vertex_exist_regions);
void pair_tetrahedron(const scene_bg_mesh_info_t& scene_bg_mesh_info, void pair_tetrahedron(const scene_bg_mesh_info_t& scene_bg_mesh_info,
const stl_vector_mp<grid_region>& vertex_exist_regions,
stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& vertex_to_tet_mapping); flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& vertex_to_tet_mapping);
void filter_tet_by_subface(const flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& vertex_to_tet_mapping, void filter_tet_by_subface(const flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& vertex_to_tet_mapping,
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, Eigen::Ref<Eigen::MatrixXd> vertex_infos,
flat_hash_map_mp<uint32_t, uint32_t>& vertex_indices_mapping,
stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index, stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index,
stl_vector_mp<uint32_t>& active_subface_indices, stl_vector_mp<uint32_t>& active_subface_indices,
flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& zero_vertex_to_incident_tet_mapping); flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& zero_vertex_to_incident_tet_mapping);
// in turn: num_1_func, num_2_func, num_more_func // in turn: num_1_func, num_2_func, num_more_func
std::array<uint32_t, 3> compute_implicit_arrangements(const flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, std::array<uint32_t, 3> compute_implicit_arrangements(const Eigen::Ref<const Eigen::MatrixXd> vertex_infos,
const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, const flat_hash_map_mp<uint32_t, uint32_t>& vertex_indices_mapping,
const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index, const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index,
const stl_vector_mp<uint32_t>& active_subface_indices, const stl_vector_mp<uint32_t>& active_subface_indices,
stl_vector_mp<arrangement_t>& tetrahedron_arrangements); stl_vector_mp<arrangement_t>& tetrahedron_arrangements);
// extract iso-mesh (topology only) // extract iso-mesh (topology only)
void extract_iso_mesh(const std::array<uint32_t, 3>& tet_active_subface_counts, void extract_iso_mesh(const std::array<uint32_t, 3>& tet_active_subface_counts,
const stl_vector_mp<arrangement_t>& tetrahedron_arrangements, const stl_vector_mp<arrangement_t>& tetrahedron_arrangements,
const scene_bg_mesh_info_t& scene_bg_mesh_info, const scene_bg_mesh_info_t& scene_bg_mesh_info,
const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index, const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index,
const stl_vector_mp<uint32_t>& active_subface_indices, const stl_vector_mp<uint32_t>& active_subface_indices,
const flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, const Eigen::Ref<const Eigen::MatrixXd> vertex_infos,
stl_vector_mp<Eigen::Vector3d>& iso_pts, const flat_hash_map_mp<uint32_t, uint32_t>& vertex_indices_mapping,
stl_vector_mp<iso_vertex_t>& iso_verts, stl_vector_mp<Eigen::Vector3d>& iso_pts,
stl_vector_mp<polygon_face_t>& iso_faces); stl_vector_mp<iso_vertex_t>& iso_verts,
stl_vector_mp<polygon_face_t>& iso_faces);

19
network_process/src/prim_gen/comp_imp_arrange.cpp

@ -1,8 +1,8 @@
#include <prim_gen.hpp> #include <prim_gen.hpp>
#include <helper.hpp>
std::array<uint32_t, 3> compute_implicit_arrangements(const flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, std::array<uint32_t, 3> compute_implicit_arrangements(const Eigen::Ref<const Eigen::MatrixXd> vertex_infos,
const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, const flat_hash_map_mp<uint32_t, uint32_t>& vertex_indices_mapping,
const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index, const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index,
const stl_vector_mp<uint32_t>& active_subface_indices, const stl_vector_mp<uint32_t>& active_subface_indices,
stl_vector_mp<arrangement_t>& tetrahedron_arrangements) stl_vector_mp<arrangement_t>& tetrahedron_arrangements)
@ -19,19 +19,16 @@ std::array<uint32_t, 3> compute_implicit_arrangements(const flat_hash_map_mp<uin
for (size_t i = 0; i < tetrahedrons.size(); ++i) { for (size_t i = 0; i < tetrahedrons.size(); ++i) {
const auto& [tet_vert0, tet_vert1, tet_vert2, tet_vert3] = tetrahedrons[i]; const auto& [tet_vert0, tet_vert1, tet_vert2, tet_vert3] = tetrahedrons[i];
const auto &vert_faces0 = vertex_infos.at(tet_vert0), // auto vert_faces0 = vertex_infos.row(vertex_indices_mapping.at(tet_vert0)), //
vert_faces1 = vertex_infos.at(tet_vert1), // vert_faces1 = vertex_infos.row(vertex_indices_mapping.at(tet_vert1)), //
vert_faces2 = vertex_infos.at(tet_vert2), // vert_faces2 = vertex_infos.row(vertex_indices_mapping.at(tet_vert2)), //
vert_faces3 = vertex_infos.at(tet_vert3); vert_faces3 = vertex_infos.row(vertex_indices_mapping.at(tet_vert3));
auto subface_indices_start_iter = active_subface_indices.begin() + tetrahedron_active_subface_start_index[i]; auto subface_indices_start_iter = active_subface_indices.begin() + tetrahedron_active_subface_start_index[i];
auto subface_indices_end_iter = active_subface_indices.begin() + tetrahedron_active_subface_start_index[i + 1]; auto subface_indices_end_iter = active_subface_indices.begin() + tetrahedron_active_subface_start_index[i + 1];
planes.clear(); planes.clear();
for (auto iter = subface_indices_start_iter; iter != subface_indices_end_iter; ++iter) { for (auto iter = subface_indices_start_iter; iter != subface_indices_end_iter; ++iter) {
planes.emplace_back(plane_t{-find_subface_by_index(vert_faces0, *iter)->sdf_value, planes.emplace_back(plane_t{-vert_faces0[*iter], -vert_faces1[*iter], -vert_faces2[*iter], -vert_faces3[*iter]});
-find_subface_by_index(vert_faces1, *iter)->sdf_value,
-find_subface_by_index(vert_faces2, *iter)->sdf_value,
-find_subface_by_index(vert_faces3, *iter)->sdf_value});
} }
tetrahedron_arrangements.emplace_back(std::move(compute_arrangement(planes))); tetrahedron_arrangements.emplace_back(std::move(compute_arrangement(planes)));

77
network_process/src/prim_gen/extract_mesh.cpp

@ -1,17 +1,17 @@
#include <prim_gen.hpp> #include <prim_gen.hpp>
#include <helper.hpp> #include <helper.hpp>
#include "fwd_types.hpp"
void extract_iso_mesh(const std::array<uint32_t, 3>& tet_active_subface_counts, void extract_iso_mesh(const std::array<uint32_t, 3>& tet_active_subface_counts,
const stl_vector_mp<arrangement_t>& tetrahedron_arrangements, const stl_vector_mp<arrangement_t>& tetrahedron_arrangements,
const scene_bg_mesh_info_t& scene_bg_mesh_info, const scene_bg_mesh_info_t& scene_bg_mesh_info,
const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, const stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index, const stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index,
const stl_vector_mp<uint32_t>& active_subface_indices, const stl_vector_mp<uint32_t>& active_subface_indices,
const flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, const Eigen::MatrixXd& vertex_infos,
stl_vector_mp<Eigen::Vector3d>& iso_pts, const flat_hash_map_mp<uint32_t, uint32_t>& vertex_indices_mapping,
stl_vector_mp<iso_vertex_t>& iso_verts, stl_vector_mp<Eigen::Vector3d>& iso_pts,
stl_vector_mp<polygon_face_t>& iso_faces) stl_vector_mp<iso_vertex_t>& iso_verts,
stl_vector_mp<polygon_face_t>& iso_faces)
{ {
// estimate number of iso-verts and iso-faces // estimate number of iso-verts and iso-faces
const auto& [num_1_func, num_2_func, num_more_func] = tet_active_subface_counts; const auto& [num_1_func, num_2_func, num_more_func] = tet_active_subface_counts;
@ -120,8 +120,8 @@ void extract_iso_mesh(const std::array<uint32_t, 3>& tet
iso_vert.simplex_vertex_indices = {vId1, vId2}; iso_vert.simplex_vertex_indices = {vId1, vId2};
iso_vert.subface_indices = {implicit_pIds[0]}; iso_vert.subface_indices = {implicit_pIds[0]};
const auto f1 = find_subface_by_index(vertex_infos.at(vId1), implicit_pIds[0])->sdf_value; const auto f1 = vertex_infos(vertex_indices_mapping.at(vId1), implicit_pIds[0]);
const auto f2 = find_subface_by_index(vertex_infos.at(vId2), implicit_pIds[0])->sdf_value; const auto f2 = vertex_infos(vertex_indices_mapping.at(vId2), implicit_pIds[0]);
const auto coord = compute_barycentric_coords(f1, f2); const auto coord = compute_barycentric_coords(f1, f2);
iso_pts.emplace_back(coord[0] * get_vert_pos(vId1, scene_bg_mesh_info) iso_pts.emplace_back(coord[0] * get_vert_pos(vId1, scene_bg_mesh_info)
+ coord[1] * get_vert_pos(vId2, scene_bg_mesh_info)); + coord[1] * get_vert_pos(vId2, scene_bg_mesh_info));
@ -146,15 +146,16 @@ void extract_iso_mesh(const std::array<uint32_t, 3>& tet
iso_vert.subface_indices = {implicit_pIds[0], implicit_pIds[1]}; iso_vert.subface_indices = {implicit_pIds[0], implicit_pIds[1]};
// //
const auto &vert_face0 = vertex_infos.at(vIds3[0]), vert_face1 = vertex_infos.at(vIds3[1]), const auto &vert_face0 = vertex_infos.row(vertex_indices_mapping.at(vIds3[0])),
vert_face2 = vertex_infos.at(vIds3[2]); vert_face1 = vertex_infos.row(vertex_indices_mapping.at(vIds3[1])),
const auto f1 = std::array{find_subface_by_index(vert_face0, implicit_pIds[0])->sdf_value, vert_face2 = vertex_infos.row(vertex_indices_mapping.at(vIds3[2]));
find_subface_by_index(vert_face1, implicit_pIds[0])->sdf_value, const auto f1 = std::array{vert_face0(implicit_pIds[0]),
find_subface_by_index(vert_face2, implicit_pIds[0])->sdf_value}; vert_face1(implicit_pIds[0]),
const auto f2 = std::array{find_subface_by_index(vert_face0, implicit_pIds[1])->sdf_value, vert_face2(implicit_pIds[0])};
find_subface_by_index(vert_face1, implicit_pIds[1])->sdf_value, const auto f2 = std::array{vert_face0(implicit_pIds[1]),
find_subface_by_index(vert_face2, implicit_pIds[1])->sdf_value}; vert_face1(implicit_pIds[1]),
const auto coord = compute_barycentric_coords(f1, f2); vert_face2(implicit_pIds[1])};
const auto coord = compute_barycentric_coords(f1, f2);
iso_pts.emplace_back(coord[0] * get_vert_pos(vIds3[0], scene_bg_mesh_info) iso_pts.emplace_back(coord[0] * get_vert_pos(vIds3[0], scene_bg_mesh_info)
+ coord[1] * get_vert_pos(vIds3[1], scene_bg_mesh_info) + coord[1] * get_vert_pos(vIds3[1], scene_bg_mesh_info)
+ coord[2] * get_vert_pos(vIds3[2], scene_bg_mesh_info)); + coord[2] * get_vert_pos(vIds3[2], scene_bg_mesh_info));
@ -170,22 +171,22 @@ void extract_iso_mesh(const std::array<uint32_t, 3>& tet
iso_vert.simplex_vertex_indices = tetrahedrons[i]; iso_vert.simplex_vertex_indices = tetrahedrons[i];
iso_vert.subface_indices = implicit_pIds; iso_vert.subface_indices = implicit_pIds;
const auto &vert_face0 = vertex_infos.at(tetrahedrons[i][0]), const auto &vert_face0 = vertex_infos.row(vertex_indices_mapping.at(tetrahedrons[i][0])),
vert_face1 = vertex_infos.at(tetrahedrons[i][1]), vert_face1 = vertex_infos.row(vertex_indices_mapping.at(tetrahedrons[i][1])),
vert_face2 = vertex_infos.at(tetrahedrons[i][2]), vert_face2 = vertex_infos.row(vertex_indices_mapping.at(tetrahedrons[i][2])),
vert_face3 = vertex_infos.at(tetrahedrons[i][3]); vert_face3 = vertex_infos.row(vertex_indices_mapping.at(tetrahedrons[i][3]));
const auto f1 = std::array{find_subface_by_index(vert_face0, implicit_pIds[0])->sdf_value, const auto f1 = std::array{vert_face0(implicit_pIds[0]),
find_subface_by_index(vert_face1, implicit_pIds[0])->sdf_value, vert_face1(implicit_pIds[0]),
find_subface_by_index(vert_face2, implicit_pIds[0])->sdf_value, vert_face2(implicit_pIds[0]),
find_subface_by_index(vert_face3, implicit_pIds[0])->sdf_value}; vert_face3(implicit_pIds[0])};
const auto f2 = std::array{find_subface_by_index(vert_face0, implicit_pIds[1])->sdf_value, const auto f2 = std::array{vert_face0(implicit_pIds[1]),
find_subface_by_index(vert_face1, implicit_pIds[1])->sdf_value, vert_face1(implicit_pIds[1]),
find_subface_by_index(vert_face2, implicit_pIds[1])->sdf_value, vert_face2(implicit_pIds[1]),
find_subface_by_index(vert_face3, implicit_pIds[1])->sdf_value}; vert_face3(implicit_pIds[1])};
const auto f3 = std::array{find_subface_by_index(vert_face0, implicit_pIds[2])->sdf_value, const auto f3 = std::array{vert_face0(implicit_pIds[2]),
find_subface_by_index(vert_face1, implicit_pIds[2])->sdf_value, vert_face1(implicit_pIds[2]),
find_subface_by_index(vert_face2, implicit_pIds[2])->sdf_value, vert_face2(implicit_pIds[2]),
find_subface_by_index(vert_face3, implicit_pIds[2])->sdf_value}; vert_face3(implicit_pIds[2])};
const auto coord = compute_barycentric_coords(f1, f2, f3); const auto coord = compute_barycentric_coords(f1, f2, f3);
iso_pts.emplace_back(coord[0] * get_vert_pos(tetrahedrons[i][0], scene_bg_mesh_info) iso_pts.emplace_back(coord[0] * get_vert_pos(tetrahedrons[i][0], scene_bg_mesh_info)
+ coord[1] * get_vert_pos(tetrahedrons[i][1], scene_bg_mesh_info) + coord[1] * get_vert_pos(tetrahedrons[i][1], scene_bg_mesh_info)

8
network_process/src/prim_gen/extract_vertex_infos.cpp

@ -21,10 +21,10 @@ aabb_t mark_primitive_boundings(double aabb_margin, const baked_blobtree_t& tree
return scene_aabb; return scene_aabb;
} }
void extract_vertex_infos(const s_settings& settings, void extract_vertex_infos(const s_settings& settings,
const baked_blobtree_t& tree, const baked_blobtree_t& tree,
scene_bg_mesh_info_t& scene_bg_mesh_info, scene_bg_mesh_info_t& scene_bg_mesh_info,
Eigen::MatrixXd& vertex_infos) Eigen::Ref<Eigen::MatrixXd> vertex_infos)
{ {
stl_vector_mp<aabb_t> primitive_boundings{}; stl_vector_mp<aabb_t> primitive_boundings{};
stl_vector_mp<stl_vector_mp<uint32_t>> subface_active_vertices{}; stl_vector_mp<stl_vector_mp<uint32_t>> subface_active_vertices{};

105
network_process/src/prim_gen/filter_tet_by_subface.cpp

@ -1,36 +1,43 @@
#include <container/btree.hpp> #include <container/btree.hpp>
#include <prim_gen.hpp> #include <prim_gen.hpp>
#include "base/primitive.hpp"
struct packed_sign_counter { // struct packed_sign_counter {
uint8_t positive : 4; // uint8_t positive : 4;
uint8_t negative : 4; // uint8_t negative : 4;
inline packed_sign_counter& operator+=(const packed_sign_counter& rhs) // inline packed_sign_counter& operator+=(const packed_sign_counter& rhs)
{ // {
positive += rhs.positive; // positive += rhs.positive;
negative += rhs.negative; // negative += rhs.negative;
return *this; // return *this;
} // }
}; // };
void filter_tet_by_subface(const flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& vertex_to_tet_mapping, void filter_tet_by_subface(const flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& vertex_to_tet_mapping,
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos, Eigen::Ref<Eigen::MatrixXd> vertex_infos,
flat_hash_map_mp<uint32_t, uint32_t>& vertex_indices_mapping,
stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons, stl_vector_mp<std::array<uint32_t, 4>>& tetrahedrons,
stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index, stl_vector_mp<uint32_t>& tetrahedron_active_subface_start_index,
stl_vector_mp<uint32_t>& active_subface_indices, stl_vector_mp<uint32_t>& active_subface_indices,
flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& zero_vertex_to_incident_tet_mapping) flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>>& zero_vertex_to_incident_tet_mapping)
{ {
stl_vector_mp<btree_map_mp<uint32_t, packed_sign_counter>> sign_counts{}; using sign_count_buffer_t = Eigen::Vector<uint8_t, Eigen::Dynamic>;
stl_vector_mp<sign_count_buffer_t> sign_counts{};
dynamic_bitset_mp<> sign_count_initialized{};
sign_counts.resize(tetrahedrons.size()); sign_counts.resize(tetrahedrons.size());
sign_count_initialized.resize(tetrahedrons.size());
btree_map_mp<uint32_t, packed_sign_counter> temp_sign_counts{}; // the highest 4 bits as positive sign count, the lowest 4 bits as negative sign count
sign_count_buffer_t temp_sign_counts(vertex_infos.rows());
temp_sign_counts += temp_sign_counts;
for (const auto& [vertex_index, tet_indices] : vertex_to_tet_mapping) { for (const auto& [vertex_index, tet_indices] : vertex_to_tet_mapping) {
const auto& vertex_info = vertex_infos.at(vertex_index); auto vertex_info = vertex_infos.row(vertex_index);
temp_sign_counts.clear(); temp_sign_counts.setZero();
for (const auto& subface_info : vertex_info) { for (auto i = 0; i < vertex_info.size(); ++i) {
switch (subface_info.sdf_sign) { switch (sign_by_sdf(vertex_info[i])) {
case sign_t::zero: { case sign_t::zero: {
const auto& vertex_index_ = vertex_index; const auto& vertex_index_ = vertex_index;
const auto& tet_indices_ = tet_indices; const auto& tet_indices_ = tet_indices;
@ -39,60 +46,58 @@ void filter_tet_by_subface(const flat_hash_map_mp<uint32_t, stl_vector_mp<uint32
}); });
break; break;
} }
case sign_t::positive: temp_sign_counts[subface_info.subface_index].positive++; break; case sign_t::positive: temp_sign_counts[i] += 16; break;
case sign_t::negative: temp_sign_counts[subface_info.subface_index].negative++; break; case sign_t::negative: temp_sign_counts[i] += 1; break;
} }
} }
// broadcast sign counts of current vertex to all neighboring tetrahedrons // broadcast sign counts of current vertex to all neighboring tetrahedrons
for (const auto& [subface_index, counts] : temp_sign_counts) { for (const auto& tet_index : tet_indices) {
for (const auto& tet_index : tet_indices) { if (!sign_count_initialized[tet_index]) {
auto& tet_sign_counts = sign_counts[tet_index]; sign_counts[tet_index] = temp_sign_counts;
sign_count_initialized.set(tet_index);
auto [iter, is_new_item] = tet_sign_counts.try_emplace(subface_index, counts); } else {
if (!is_new_item) iter->second += counts; sign_counts[tet_index] += temp_sign_counts;
} }
} }
} }
// filter tetrahedrons' subfaces which have same but not 0 signs // filter tetrahedrons' subfaces which have same but not 0 signs
// and filter active terahedrons by the way
stl_vector_mp<std::array<uint32_t, 4>> filtered_tets{};
stl_vector_mp<uint32_t> filtered_active_vertices{};
filtered_tets.reserve(tetrahedrons.size());
filtered_active_vertices.reserve(tetrahedrons.size() * 4);
tetrahedron_active_subface_start_index.reserve(tetrahedrons.size() + 1); tetrahedron_active_subface_start_index.reserve(tetrahedrons.size() + 1);
active_subface_indices.reserve(tetrahedrons.size()); active_subface_indices.reserve(tetrahedrons.size());
tetrahedron_active_subface_start_index.emplace_back(0); tetrahedron_active_subface_start_index.emplace_back(0);
for (const auto& tet_info : sign_counts) { for (auto i = 0; i < tetrahedrons.size(); ++i) {
for (const auto& [subface_index, counts] : tet_info) { const auto& tet_info = sign_counts[i];
if (counts.positive < 4 && counts.negative < 4) active_subface_indices.emplace_back(subface_index); for (auto j = 0; j < tet_info.size(); ++j) {
auto sign = tet_info[j];
if ((sign & 0x0F) < 4 && (sign >> 4) < 4) { active_subface_indices.emplace_back(j); }
} }
tetrahedron_active_subface_start_index.emplace_back(active_subface_indices.size()); if (active_subface_indices.size() > tetrahedron_active_subface_start_index.back()) {
} tetrahedron_active_subface_start_index.emplace_back(active_subface_indices.size());
active_subface_indices.shrink_to_fit();
stl_vector_mp<std::array<uint32_t, 4>> filtered_tets{};
stl_vector_mp<uint32_t> filtered_tetrahedron_active_subface_start_index{};
stl_vector_mp<uint32_t> filtered_active_vertices{};
filtered_tets.reserve(tetrahedrons.size());
filtered_tetrahedron_active_subface_start_index.reserve(tetrahedrons.size());
filtered_active_vertices.reserve(tetrahedrons.size());
for (size_t i = 0; i < tetrahedrons.size(); ++i) {
if (tetrahedron_active_subface_start_index[i] < tetrahedron_active_subface_start_index[i + 1]) {
filtered_tetrahedron_active_subface_start_index.emplace_back(tetrahedron_active_subface_start_index[i]);
const auto& vertices = filtered_tets.emplace_back(std::move(tetrahedrons[i])); const auto& vertices = filtered_tets.emplace_back(std::move(tetrahedrons[i]));
filtered_active_vertices.insert(filtered_active_vertices.end(), vertices.begin(), vertices.end()); filtered_active_vertices.insert(filtered_active_vertices.end(), vertices.begin(), vertices.end());
} }
} }
// always keep the last element of tetrahedron_active_subface_start_index as an ender active_subface_indices.shrink_to_fit();
filtered_tetrahedron_active_subface_start_index.emplace_back(tetrahedron_active_subface_start_index.back());
filtered_tetrahedron_active_subface_start_index.shrink_to_fit();
filtered_tets.shrink_to_fit(); filtered_tets.shrink_to_fit();
std::swap(filtered_tetrahedron_active_subface_start_index, tetrahedron_active_subface_start_index); filtered_active_vertices.shrink_to_fit();
std::swap(filtered_tets, tetrahedrons); std::swap(filtered_tets, tetrahedrons);
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t> filtered_vert_infos{};
std::sort(filtered_active_vertices.begin(), filtered_active_vertices.end()); std::sort(filtered_active_vertices.begin(), filtered_active_vertices.end());
auto end_iter = std::unique(filtered_active_vertices.begin(), filtered_active_vertices.end()); auto end_iter = std::unique(filtered_active_vertices.begin(), filtered_active_vertices.end());
auto vertex_count = std::distance(filtered_active_vertices.begin(), end_iter);
Eigen::MatrixXd filtered_vert_infos(vertex_count, vertex_infos.cols());
auto filtered_vert_infos_iter = filtered_vert_infos.rowwise().begin();
for (auto iter = filtered_active_vertices.begin(); iter != end_iter; ++iter) { for (auto iter = filtered_active_vertices.begin(); iter != end_iter; ++iter) {
const auto vertex_index = *iter; const auto vertex_index = *iter;
filtered_vert_infos.emplace(vertex_index, vertex_infos.at(vertex_index)); *filtered_vert_infos_iter = vertex_infos.row(vertex_index);
vertex_indices_mapping[vertex_index] = std::distance(filtered_active_vertices.begin(), iter);
filtered_vert_infos_iter++;
} }
std::swap(filtered_vert_infos, vertex_infos); vertex_infos = filtered_vert_infos;
} }

10
network_process/src/process.cpp

@ -24,16 +24,18 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
stl_vector_mp<polygon_face_t> iso_faces{}; stl_vector_mp<polygon_face_t> iso_faces{};
// primitive generation // primitive generation
{ {
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t> vertex_infos{}; 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{}; flat_hash_map_mp<uint32_t, stl_vector_mp<uint32_t>> vertex_to_tet_mapping{};
{ {
stl_vector_mp<grid_region> vertex_exist_regions{}; stl_vector_mp<grid_region> vertex_exist_regions{};
extract_vertex_infos(settings, tree, scene_bg_mesh_info, vertex_infos, vertex_exist_regions); extract_vertex_infos(settings, tree, scene_bg_mesh_info, vertex_infos);
pair_tetrahedron(scene_bg_mesh_info, vertex_exist_regions, tetrahedrons, vertex_to_tet_mapping); pair_tetrahedron(scene_bg_mesh_info, tetrahedrons, vertex_to_tet_mapping);
} }
filter_tet_by_subface(vertex_to_tet_mapping, filter_tet_by_subface(vertex_to_tet_mapping,
vertex_infos, vertex_infos,
vertex_indices_mapping,
tetrahedrons, tetrahedrons,
tetrahedron_active_subface_start_index, tetrahedron_active_subface_start_index,
active_subface_indices, active_subface_indices,
@ -41,6 +43,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
} }
auto tet_active_subface_counts = compute_implicit_arrangements(vertex_infos, auto tet_active_subface_counts = compute_implicit_arrangements(vertex_infos,
vertex_indices_mapping,
tetrahedrons, tetrahedrons,
tetrahedron_active_subface_start_index, tetrahedron_active_subface_start_index,
active_subface_indices, active_subface_indices,
@ -52,6 +55,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings&
tetrahedron_active_subface_start_index, tetrahedron_active_subface_start_index,
active_subface_indices, active_subface_indices,
vertex_infos, vertex_infos,
vertex_indices_mapping,
iso_pts, iso_pts,
iso_verts, iso_verts,
iso_faces); iso_faces);

Loading…
Cancel
Save