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