Browse Source

fix tet build error

V2-integral
Zhicheng Wang 2 days ago
parent
commit
3c6843b269
  1. 92
      network_process/interface/fwd_types.hpp
  2. 9
      network_process/src/connect_by_topo/topology_ray_shooting.cpp
  3. 3
      network_process/src/network_process.cpp
  4. 45
      network_process/src/prim_gen/build_tetrahedron_and_adjacency.cpp
  5. 20
      network_process/src/prim_gen/extract_mesh.cpp
  6. 8
      network_process/src/prim_gen/extract_vertex_infos.cpp

92
network_process/interface/fwd_types.hpp

@ -16,61 +16,55 @@ using pod_key_t = std::array<uint32_t, N>;
// ==============================================================================
struct scene_bg_mesh_info_t {
Eigen::Vector3d grid_offset{};
Eigen::Vector3d grid_size{};
Eigen::Vector3d grid_size_inv{};
Eigen::Vector<uint64_t, 3> vert_resolution{};
};
// x as the most significant bit, y as the second most significant bit, z as the least significant bit
static inline uint32_t hash_vert_pos(size_t x, size_t y, size_t z, const scene_bg_mesh_info_t& info)
{
return static_cast<uint32_t>(z + info.vert_resolution.z() * (y + info.vert_resolution.y() * x));
}
static inline uint32_t pos_hash_max(const scene_bg_mesh_info_t& info)
{
return hash_vert_pos(info.vert_resolution.x() - 1, info.vert_resolution.y() - 1, info.vert_resolution.z() - 1, info);
}
static inline uint32_t hash_increment_x(uint32_t hashed_value, const scene_bg_mesh_info_t& info)
{
return hashed_value + static_cast<uint32_t>(info.vert_resolution.y() * info.vert_resolution.z());
}
static inline uint32_t hash_increment_y(uint32_t hashed_value, const scene_bg_mesh_info_t& info)
{
return hashed_value + static_cast<uint32_t>(info.vert_resolution.z());
}
struct scene_bg_mesh_info_t {
void init(const aabb_t& aabb, uint32_t resolution)
{
this->grid_offset = aabb.min();
this->grid_size = aabb.sizes() / resolution;
this->vert_resolution = resolution + 1;
this->grid_resolution = resolution;
if (this->vert_resolution % 2 == 1) {
this->invert_hash_grid = [this](uint32_t hashed_value) {
auto y = (hashed_value / this->grid_resolution) % this->grid_resolution;
auto x = hashed_value / (this->grid_resolution * this->grid_resolution);
auto s = (x + y) & 1;
auto z = (hashed_value % this->grid_resolution) ^ s;
return std::array{x, y, z};
};
} else {
this->invert_hash_grid = [this](uint32_t hashed_value) {
auto z = hashed_value % this->grid_resolution;
auto y = (hashed_value / this->grid_resolution) % this->grid_resolution;
auto x = hashed_value / (this->grid_resolution * this->grid_resolution);
return std::array{x, y, z};
};
}
}
static inline uint32_t hash_increment_z(uint32_t hashed_value, const scene_bg_mesh_info_t& info) { return hashed_value + 1; }
inline uint32_t hash_grid_pos(uint32_t x, uint32_t y, uint32_t z) const noexcept
{
return z + this->vert_resolution * (y + this->vert_resolution * x);
}
static inline Eigen::Vector3d get_grid_pos(size_t x, size_t y, size_t z, const scene_bg_mesh_info_t& info)
{
return info.grid_offset + Eigen::Vector3d(x, y, z).cwiseProduct(info.grid_size);
}
inline Eigen::Vector3d get_vert_pos(uint32_t hashed_value) const
{
auto z = hashed_value % this->vert_resolution;
auto y = (hashed_value / this->vert_resolution) % this->vert_resolution;
auto x = hashed_value / (this->vert_resolution * this->vert_resolution);
return this->grid_offset + Eigen::Vector3d(x, y, z).cwiseProduct(this->grid_size);
}
static inline Eigen::Vector3d get_grid_pos(const Eigen::Vector3d& pos, const scene_bg_mesh_info_t& info)
{
return (pos - info.grid_offset).cwiseProduct(info.grid_size_inv);
}
uint32_t grid_count() const noexcept { return grid_resolution * grid_resolution * grid_resolution; }
static inline Eigen::Vector3d get_vert_pos(uint32_t hashed_value, const scene_bg_mesh_info_t& info)
{
size_t z = static_cast<size_t>(hashed_value % (info.vert_resolution.z()));
size_t y = static_cast<size_t>((hashed_value / info.vert_resolution.z()) % info.vert_resolution.y());
size_t x = static_cast<size_t>(hashed_value / (info.vert_resolution.z() * info.vert_resolution.y()));
return get_grid_pos(x, y, z, info);
}
std::function<std::array<uint32_t, 3>(uint32_t)> invert_hash_grid{};
static inline std::array<size_t, 3> get_grid_pos(uint32_t hashed_value, const scene_bg_mesh_info_t& info)
{
size_t z = static_cast<size_t>(hashed_value % (info.vert_resolution.z()));
size_t y = static_cast<size_t>((hashed_value / info.vert_resolution.z()) % info.vert_resolution.y());
size_t x = static_cast<size_t>(hashed_value / (info.vert_resolution.z() * info.vert_resolution.y()));
return {x, y, z};
}
Eigen::Vector3d grid_offset{};
Eigen::Vector3d grid_size{};
uint32_t vert_resolution{};
uint32_t grid_resolution{};
};
// ==============================================================================

9
network_process/src/connect_by_topo/topology_ray_shooting.cpp

@ -72,8 +72,7 @@ struct equal_to<face_with_orient_t> {
// ============================================================================================
void topo_ray_shooting(const scene_bg_mesh_info_t &scene_bg_mesh_info,
const std::vector<std::array<uint32_t, 4>> &tetrahedrons,
void topo_ray_shooting(const std::vector<std::array<uint32_t, 4>> &tetrahedrons,
const flat_hash_map<uint32_t, uint32_t> &vertex_lexigraphical_adjacency,
const std::vector<arrangement_t> &tetrahedron_arrangements,
const std::vector<iso_vertex_t> &iso_verts,
@ -95,8 +94,7 @@ void topo_ray_shooting(const scene_bg_mesh_info_t &scene_bg_mesh
flat_hash_map<face_header_t, uint32_t> iso_face_id_of_tet_face{};
// map: (tet_id, tet_vert_id) --> (iso_vert_id, component_id)
flat_hash_map<simplified_vertex_header_t, component_header_t> iso_vId_compId_of_tet_vert{};
find_extremal_edges(scene_bg_mesh_info,
iso_verts,
find_extremal_edges(iso_verts,
iso_faces,
patches,
components,
@ -215,8 +213,7 @@ void topo_ray_shooting(const scene_bg_mesh_info_t &scene_bg_mesh
}
}
void find_extremal_edges(const scene_bg_mesh_info_t &scene_bg_mesh_info,
const std::vector<iso_vertex_t> &iso_verts,
void find_extremal_edges(const std::vector<iso_vertex_t> &iso_verts,
const std::vector<polygon_face_t> &iso_faces,
const std::vector<std::vector<uint32_t>> &patches,
const std::vector<std::vector<uint32_t>> &components,

3
network_process/src/network_process.cpp

@ -253,8 +253,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& s
} else {
{
std::vector<std::pair<uint32_t, uint32_t>> shell_links{};
topo_ray_shooting(scene_bg_mesh_info,
tetrahedrons,
topo_ray_shooting(tetrahedrons,
vertex_lexigraphical_adjacency,
tetrahedron_arrangements,
iso_verts,

45
network_process/src/prim_gen/build_tetrahedron_and_adjacency.cpp

@ -21,9 +21,8 @@ void build_tetrahedron_and_adjacency(const scene_bg_mesh_info_t&
flat_hash_map<uint32_t, std::vector<uint32_t>>& reverse_vertex_adjacency,
btree_map<uint32_t, std::vector<uint32_t>>& vertex_to_tet_mapping)
{
scene_bg_mesh_info_t culled_scene_bg_mesh_info = scene_bg_mesh_info;
culled_scene_bg_mesh_info.vert_resolution -= Eigen::Vector<uint64_t, 3>::Ones();
tetrahedrons.reserve((culled_scene_bg_mesh_info.vert_resolution.array() - 1).prod() * 5);
auto res = scene_bg_mesh_info.grid_resolution - 1;
tetrahedrons.reserve(res * res * res * 5);
auto insert_or_compare_vertex_adjacency = [&](uint32_t src, uint32_t dst) {
reverse_vertex_adjacency[dst].reserve(reverse_vertex_adjacency[dst].size() + 3);
@ -32,16 +31,16 @@ void build_tetrahedron_and_adjacency(const scene_bg_mesh_info_t&
reverse_vertex_adjacency[dst].emplace_back(src);
};
for (size_t i = 0; i < pos_hash_max(culled_scene_bg_mesh_info); i += 2) {
auto [x, y, z] = get_grid_pos(i, culled_scene_bg_mesh_info);
auto v0 = hash_vert_pos(x, y, z, scene_bg_mesh_info);
auto v1 = hash_increment_x(v0, scene_bg_mesh_info); // +yz
auto v2 = hash_increment_y(v1, scene_bg_mesh_info); // +yz+z
auto v3 = hash_increment_y(v0, scene_bg_mesh_info); // +z
auto v4 = hash_increment_z(v0, scene_bg_mesh_info); // +1
auto v5 = hash_increment_x(v4, scene_bg_mesh_info); // +yz+1
auto v6 = hash_increment_y(v5, scene_bg_mesh_info); // +yz+z+1
auto v7 = hash_increment_y(v4, scene_bg_mesh_info); // +z+1
for (size_t i = 0; i < scene_bg_mesh_info.grid_count(); i += 2) {
auto [x, y, z] = scene_bg_mesh_info.invert_hash_grid(i);
auto v0 = scene_bg_mesh_info.hash_grid_pos(x, y, z);
auto v1 = scene_bg_mesh_info.hash_grid_pos(x + 1, y, z);
auto v2 = scene_bg_mesh_info.hash_grid_pos(x + 1, y + 1, z);
auto v3 = scene_bg_mesh_info.hash_grid_pos(x, y + 1, z);
auto v4 = scene_bg_mesh_info.hash_grid_pos(x, y, z + 1);
auto v5 = scene_bg_mesh_info.hash_grid_pos(x + 1, y, z + 1);
auto v6 = scene_bg_mesh_info.hash_grid_pos(x + 1, y + 1, z + 1);
auto v7 = scene_bg_mesh_info.hash_grid_pos(x, y + 1, z + 1);
// vertex lexigraphical ordering: v0, v4, v3, v1, v7, v5, v2, v6
tetrahedrons.emplace_back(std::array{v4, v3, v1, v6});
@ -59,16 +58,16 @@ void build_tetrahedron_and_adjacency(const scene_bg_mesh_info_t&
insert_or_compare_vertex_adjacency(v7, v4);
}
for (size_t i = 1; i < pos_hash_max(culled_scene_bg_mesh_info); i += 2) {
auto [x, y, z] = get_grid_pos(i, culled_scene_bg_mesh_info);
auto v0 = hash_vert_pos(x, y, z, scene_bg_mesh_info);
auto v1 = hash_increment_x(v0, scene_bg_mesh_info);
auto v2 = hash_increment_y(v1, scene_bg_mesh_info);
auto v3 = hash_increment_y(v0, scene_bg_mesh_info);
auto v4 = hash_increment_z(v0, scene_bg_mesh_info);
auto v5 = hash_increment_x(v4, scene_bg_mesh_info);
auto v6 = hash_increment_y(v5, scene_bg_mesh_info);
auto v7 = hash_increment_y(v4, scene_bg_mesh_info);
for (size_t i = 1; i < scene_bg_mesh_info.grid_count(); i += 2) {
auto [x, y, z] = scene_bg_mesh_info.invert_hash_grid(i);
auto v0 = scene_bg_mesh_info.hash_grid_pos(x, y, z);
auto v1 = scene_bg_mesh_info.hash_grid_pos(x + 1, y, z);
auto v2 = scene_bg_mesh_info.hash_grid_pos(x + 1, y + 1, z);
auto v3 = scene_bg_mesh_info.hash_grid_pos(x, y + 1, z);
auto v4 = scene_bg_mesh_info.hash_grid_pos(x, y, z + 1);
auto v5 = scene_bg_mesh_info.hash_grid_pos(x + 1, y, z + 1);
auto v6 = scene_bg_mesh_info.hash_grid_pos(x + 1, y + 1, z + 1);
auto v7 = scene_bg_mesh_info.hash_grid_pos(x, y + 1, z + 1);
// vertex lexigraphical ordering: v0, v4, v3, v1, v7, v5, v2, v6
tetrahedrons.emplace_back(std::array{v0, v7, v5, v2});

20
network_process/src/prim_gen/extract_mesh.cpp

@ -174,10 +174,10 @@ void extract_iso_mesh(const std::array<uint32_t, 3>& tet_active_sub
impl2[mapped_not_boundary_vIds[2]],
impl2[mapped_not_boundary_vIds[3]]};
const auto coord = compute_barycentric_coords(f1, f2, f3);
iso_pts.emplace_back(coord[0] * get_vert_pos(not_boundary_vIds[0], scene_bg_mesh_info)
+ coord[1] * get_vert_pos(not_boundary_vIds[1], scene_bg_mesh_info)
+ coord[2] * get_vert_pos(not_boundary_vIds[2], scene_bg_mesh_info)
+ coord[3] * get_vert_pos(not_boundary_vIds[3], scene_bg_mesh_info));
iso_pts.emplace_back(coord[0] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[0])
+ coord[1] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[1])
+ coord[2] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[2])
+ coord[3] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[3]));
} else if (num_boundary_planes == 1) { // on tet face
generate_new_iso_vert(vert_on_tetFace, [&] {
const auto & impl0 = vertex_infos.col(implicit_pIds[0]), &impl1 = vertex_infos.col(implicit_pIds[1]);
@ -188,21 +188,21 @@ void extract_iso_mesh(const std::array<uint32_t, 3>& tet_active_sub
impl1[mapped_not_boundary_vIds[1]],
impl1[mapped_not_boundary_vIds[2]]};
const auto coord = compute_barycentric_coords(f1, f2);
iso_pts.emplace_back(coord[0] * get_vert_pos(not_boundary_vIds[0], scene_bg_mesh_info)
+ coord[1] * get_vert_pos(not_boundary_vIds[1], scene_bg_mesh_info)
+ coord[2] * get_vert_pos(not_boundary_vIds[2], scene_bg_mesh_info));
iso_pts.emplace_back(coord[0] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[0])
+ coord[1] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[1])
+ coord[2] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[2]));
});
} else if (num_boundary_planes == 2) { // on tet edge
generate_new_iso_vert(vert_on_tetEdge, [&] {
const auto f1 = vertex_infos(vertex_indices_mapping.at(not_boundary_vIds[0]), implicit_pIds[0]);
const auto f2 = vertex_infos(vertex_indices_mapping.at(not_boundary_vIds[1]), implicit_pIds[0]);
const auto coord = compute_barycentric_coords(f1, f2);
iso_pts.emplace_back(coord[0] * get_vert_pos(not_boundary_vIds[0], scene_bg_mesh_info)
+ coord[1] * get_vert_pos(not_boundary_vIds[1], scene_bg_mesh_info));
iso_pts.emplace_back(coord[0] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[0])
+ coord[1] * scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[1]));
});
} else { // on tet vertex
generate_new_iso_vert(vert_on_tetVert,
[&] { iso_pts.emplace_back(get_vert_pos(not_boundary_vIds[0], scene_bg_mesh_info)); });
[&] { iso_pts.emplace_back(scene_bg_mesh_info.get_vert_pos(not_boundary_vIds[0])); });
}
}
// create iso-faces

8
network_process/src/prim_gen/extract_vertex_infos.cpp

@ -26,11 +26,7 @@ void extract_vertex_infos(const s_settings& settings,
subface_active_vertices.resize(tree.subfaces.size());
auto scene_aabb = mark_primitive_boundings(settings.scene_aabb_margin, tree, primitive_boundings);
scene_bg_mesh_info.grid_offset = scene_aabb.min();
scene_bg_mesh_info.grid_size = scene_aabb.sizes() / settings.resolution;
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.init(scene_aabb, settings.resolution);
// compute the SDF values for each vertex
for (uint32_t i = 0; i < tree.subfaces.size(); ++i) {
@ -39,7 +35,7 @@ void extract_vertex_infos(const s_settings& settings,
const auto subface_type = tree.subface_types[i];
auto sdf_evaluator = std::bind(internal::get_eval_sdf_ptr(subface_type), subface_ptr, std::placeholders::_1);
for (uint32_t j = 0; j < subface_vert_info.size(); ++j) {
auto pos = get_vert_pos(j, scene_bg_mesh_info);
auto pos = scene_bg_mesh_info.get_vert_pos(j);
subface_vert_info[j] = sdf_evaluator(pos);
}
}

Loading…
Cancel
Save