Browse Source

revert to dense sample

V2-origin
Zhicheng Wang 2 days ago
parent
commit
a11003f44f
  1. 89
      network_process/src/prim_gen/extract_vertex_infos.cpp
  2. 1
      network_process/src/prim_gen/filter_tet_by_subface.cpp
  3. 74
      network_process/src/prim_gen/pair_tetrahedron.cpp

89
network_process/src/prim_gen/extract_vertex_infos.cpp

@ -21,49 +21,10 @@ aabb_t mark_primitive_boundings(double aabb_margin, const baked_blobtree_t& tree
return scene_aabb; return scene_aabb;
} }
void extract_active_subfaces(const s_settings& settings, void extract_vertex_infos(const s_settings& settings,
const baked_blobtree_t& tree, const baked_blobtree_t& tree,
const scene_bg_mesh_info_t& scene_bg_mesh_info, scene_bg_mesh_info_t& scene_bg_mesh_info,
const stl_vector_mp<aabb_t>& primitive_boundings, Eigen::MatrixXd& vertex_infos)
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos,
stl_vector_mp<stl_vector_mp<uint32_t>>& subface_active_vertices,
stl_vector_mp<grid_region>& vertex_exist_regions)
{
for (size_t i = 0; i < primitive_boundings.size(); ++i) {
const auto& primitive_aabb = primitive_boundings[i];
auto& primitive = *tree.primitives[i].object_ptr;
Eigen::Vector<size_t, 3> min_pos =
get_grid_pos(primitive_aabb.min(), scene_bg_mesh_info).array().floor().cast<size_t>();
Eigen::Vector<size_t, 3> max_pos = get_grid_pos(primitive_aabb.max(), scene_bg_mesh_info).array().ceil().cast<size_t>();
min_pos.array() = min_pos.array().max(0);
max_pos.array() = max_pos.array().min(settings.resolution);
vertex_exist_regions.emplace_back(min_pos, max_pos);
// insert active faces of the primitive into the vertex_infos
// OPTIMIZE: the corner 4 vertices can be ignored
for (size_t x = min_pos.x(); x <= max_pos.x(); ++x) {
for (size_t y = min_pos.y(); y <= max_pos.y(); ++y) {
for (size_t z = min_pos.z(); z <= max_pos.z(); ++z) {
uint32_t hashed_value = hash_vert_pos(x, y, z, scene_bg_mesh_info);
auto& vertex_info = vertex_infos[hashed_value];
vertex_info.reserve(tree.primitives[i].index_mapping.size());
for (auto j : tree.primitives[i].index_mapping) {
auto& vert_face_info = vertex_info.emplace_back();
vert_face_info.subface_index = j;
subface_active_vertices[j].emplace_back(hashed_value);
}
}
}
}
}
}
void extract_vertex_infos(const s_settings& settings,
const baked_blobtree_t& tree,
scene_bg_mesh_info_t& scene_bg_mesh_info,
flat_hash_map_mp<uint32_t, bg_mesh_vert_info_t>& vertex_infos,
stl_vector_mp<grid_region>& vertex_exist_regions)
{ {
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{};
@ -76,40 +37,16 @@ void extract_vertex_infos(const s_settings& setti
scene_bg_mesh_info.grid_size_inv = scene_bg_mesh_info.grid_size.cwiseInverse(); scene_bg_mesh_info.grid_size_inv = scene_bg_mesh_info.grid_size.cwiseInverse();
scene_bg_mesh_info.vert_resolution = Eigen::Vector<uint64_t, 3>::Constant(settings.resolution + 1); scene_bg_mesh_info.vert_resolution = Eigen::Vector<uint64_t, 3>::Constant(settings.resolution + 1);
vertex_exist_regions.reserve(primitive_boundings.size());
extract_active_subfaces(settings,
tree,
scene_bg_mesh_info,
primitive_boundings,
vertex_infos,
subface_active_vertices,
vertex_exist_regions);
// remove duplicates in the active faces of each vertex
for (auto [_, vert_info] : vertex_infos) {
std::sort(vert_info.begin(), vert_info.end(), [&](const vert_face_info_t& lhs, const vert_face_info_t& rhs) {
return lhs.subface_index < rhs.subface_index;
});
auto back_iter = std::unique(vert_info.begin(), vert_info.end());
vert_info.erase(back_iter, vert_info.end());
vert_info.shrink_to_fit();
}
// compute the SDF values for each vertex // compute the SDF values for each vertex
for (size_t i = 0; i < subface_active_vertices.size(); ++i) { vertex_infos =
auto sdf_evaluator = tree.subfaces[i].object_ptr->fetch_sdf_evaluator(); Eigen::MatrixXd::Zero(hash_vert_pos(settings.resolution, settings.resolution, settings.resolution, scene_bg_mesh_info),
tree.subfaces.size());
for (auto hashed_value : subface_active_vertices[i]) { for (uint32_t i = 0; i < tree.subfaces.size(); ++i) {
auto pos = get_vert_pos(hashed_value, scene_bg_mesh_info); auto subface_vert_info = vertex_infos.col(i);
auto& vertex_info = vertex_infos[hashed_value]; auto sdf_evaluator = tree.subfaces[i].object_ptr->fetch_sdf_evaluator();
for (uint32_t j = 0; j < subface_vert_info.size(); ++j) {
auto iter = std::lower_bound( auto pos = get_vert_pos(j, scene_bg_mesh_info);
vertex_info.begin(), subface_vert_info[j] = sdf_evaluator(pos);
vertex_info.end(),
i,
[](const vert_face_info_t& info, const size_t& face_index) { return info.subface_index < face_index; });
iter->sdf_value = sdf_evaluator(pos);
iter->sdf_sign = sign_by_sdf(iter->sdf_value);
} }
} }
} }

1
network_process/src/prim_gen/filter_tet_by_subface.cpp

@ -1,7 +1,6 @@
#include <container/btree.hpp> #include <container/btree.hpp>
#include <prim_gen.hpp> #include <prim_gen.hpp>
#include <stdexcept>
struct packed_sign_counter { struct packed_sign_counter {
uint8_t positive : 4; uint8_t positive : 4;

74
network_process/src/prim_gen/pair_tetrahedron.cpp

@ -3,56 +3,46 @@
static constexpr uint64_t intertwined_01_bit_block = 0x5555555555555555; static constexpr uint64_t intertwined_01_bit_block = 0x5555555555555555;
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)
{ {
flat_hash_set_mp<std::array<uint32_t, 4>> tetrahedron_set{}; auto max_pos = scene_bg_mesh_info.vert_resolution.template cast<size_t>() - Eigen::Vector<size_t, 3>::Ones();
tetrahedron_set.reserve(vertex_exist_regions.size() * 5); tetrahedrons.reserve((max_pos.array() - 1).prod() * 5);
for (const auto& region : vertex_exist_regions) { for (size_t x = 0; x < max_pos.x(); ++x) {
const auto& min_pos = region.first; for (size_t y = 0; y < max_pos.y(); ++y) {
const auto& max_pos = region.second; for (size_t z = 0; z < max_pos.z(); ++z) {
uint32_t v0 = hash_vert_pos(x, y, z, scene_bg_mesh_info);
for (size_t x = min_pos.x(); x < max_pos.x(); ++x) { uint32_t v1 = hash_vert_pos(x + 1, y, z, scene_bg_mesh_info);
for (size_t y = min_pos.y(); y < max_pos.y(); ++y) { uint32_t v2 = hash_vert_pos(x + 1, y + 1, z, scene_bg_mesh_info);
for (size_t z = min_pos.z(); z < max_pos.z(); ++z) { uint32_t v3 = hash_vert_pos(x, y + 1, z, scene_bg_mesh_info);
uint32_t v0 = hash_vert_pos(x, y, z, scene_bg_mesh_info); uint32_t v4 = hash_vert_pos(x, y, z + 1, scene_bg_mesh_info);
uint32_t v1 = hash_vert_pos(x + 1, y, z, scene_bg_mesh_info); uint32_t v5 = hash_vert_pos(x + 1, y, z + 1, scene_bg_mesh_info);
uint32_t v2 = hash_vert_pos(x + 1, y + 1, z, scene_bg_mesh_info); uint32_t v6 = hash_vert_pos(x + 1, y + 1, z + 1, scene_bg_mesh_info);
uint32_t v3 = hash_vert_pos(x, y + 1, z, scene_bg_mesh_info); uint32_t v7 = hash_vert_pos(x, y + 1, z + 1, scene_bg_mesh_info);
uint32_t v4 = hash_vert_pos(x, y, z + 1, scene_bg_mesh_info);
uint32_t v5 = hash_vert_pos(x + 1, y, z + 1, scene_bg_mesh_info); if ((x + y + z) % 2 == 0) {
uint32_t v6 = hash_vert_pos(x + 1, y + 1, z + 1, scene_bg_mesh_info); tetrahedrons.emplace_back(std::array{v4, v6, v1, v3});
uint32_t v7 = hash_vert_pos(x, y + 1, z + 1, scene_bg_mesh_info); tetrahedrons.emplace_back(std::array{v6, v3, v4, v7});
tetrahedrons.emplace_back(std::array{v1, v3, v0, v4});
if ((x + y + z) % 2 == 0) { tetrahedrons.emplace_back(std::array{v3, v1, v2, v6});
tetrahedron_set.insert({v4, v6, v1, v3}); tetrahedrons.emplace_back(std::array{v4, v1, v6, v5});
tetrahedron_set.insert({v6, v3, v4, v7}); } else {
tetrahedron_set.insert({v1, v3, v0, v4}); tetrahedrons.emplace_back(std::array{v7, v0, v2, v5});
tetrahedron_set.insert({v3, v1, v2, v6}); tetrahedrons.emplace_back(std::array{v2, v3, v0, v7});
tetrahedron_set.insert({v4, v1, v6, v5}); tetrahedrons.emplace_back(std::array{v5, v7, v0, v4});
} else { tetrahedrons.emplace_back(std::array{v7, v2, v6, v5});
tetrahedron_set.insert({v7, v0, v2, v5}); tetrahedrons.emplace_back(std::array{v0, v1, v2, v5});
tetrahedron_set.insert({v2, v3, v0, v7});
tetrahedron_set.insert({v5, v7, v0, v4});
tetrahedron_set.insert({v7, v2, v6, v5});
tetrahedron_set.insert({v0, v1, v2, v5});
}
} }
} }
} }
} }
tetrahedrons.reserve(tetrahedron_set.size()); for (auto i = 0; i < tetrahedrons.size(); ++i) {
for (const auto& tet : tetrahedron_set) { vertex_to_tet_mapping[tetrahedrons[i][0]].emplace_back(i);
auto tet_index = static_cast<uint32_t>(tetrahedrons.size()); vertex_to_tet_mapping[tetrahedrons[i][1]].emplace_back(i);
tetrahedrons.emplace_back(tet); vertex_to_tet_mapping[tetrahedrons[i][2]].emplace_back(i);
vertex_to_tet_mapping[tetrahedrons[i][3]].emplace_back(i);
vertex_to_tet_mapping[tet[0]].emplace_back(tet_index);
vertex_to_tet_mapping[tet[1]].emplace_back(tet_index);
vertex_to_tet_mapping[tet[2]].emplace_back(tet_index);
vertex_to_tet_mapping[tet[3]].emplace_back(tet_index);
} }
} }

Loading…
Cancel
Save