|
|
@ -4,6 +4,63 @@ |
|
|
|
#include <connect_by_topo.hpp> |
|
|
|
#include <post_topo.hpp> |
|
|
|
|
|
|
|
#include <fstream> |
|
|
|
|
|
|
|
|
|
|
|
void export_halfpatch_obj( |
|
|
|
const stl_vector_mp<Eigen::Vector3d>& iso_pts, |
|
|
|
const stl_vector_mp<polygon_face_t>& iso_faces, |
|
|
|
const stl_vector_mp<stl_vector_mp<uint32_t>>& patches, |
|
|
|
const std::string& filename) |
|
|
|
{ |
|
|
|
std::string mtl_filename = filename + ".mtl"; |
|
|
|
std::ofstream mtl(mtl_filename); |
|
|
|
for (size_t half_patch = 0; half_patch < patches.size() * 2; ++half_patch) { |
|
|
|
size_t patch_idx = half_patch / 2; |
|
|
|
bool is_forward = (half_patch % 2 == 0); |
|
|
|
mtl << "newmtl patch_" << patch_idx << (is_forward ? "_in" : "_out") << "\n"; |
|
|
|
// 随机或规律分配颜色
|
|
|
|
float r = float(patch_idx % 7) / 7.0f; |
|
|
|
float g = float(patch_idx % 3) / 3.0f; |
|
|
|
float b = float(patch_idx % 5) / 5.0f; |
|
|
|
mtl << "Kd " << r << " " << g << " " << b << "\n"; |
|
|
|
} |
|
|
|
mtl.close(); |
|
|
|
|
|
|
|
std::string obj_filename = filename + ".obj"; |
|
|
|
std::ofstream ofs(obj_filename); |
|
|
|
if (!ofs) return; |
|
|
|
|
|
|
|
ofs << "mtllib "<< mtl_filename << "\n"; |
|
|
|
|
|
|
|
// 输出所有顶点
|
|
|
|
for (const auto& v : iso_pts) { |
|
|
|
ofs << "v " << v.x() << " " << v.y() << " " << v.z() << "\n"; |
|
|
|
} |
|
|
|
|
|
|
|
// 遍历所有 half-patch
|
|
|
|
for (size_t half_patch = 0; half_patch < patches.size() * 2; ++half_patch) { |
|
|
|
size_t patch_idx = half_patch / 2; |
|
|
|
bool is_forward = (half_patch % 2 == 0); |
|
|
|
ofs << "g halfpatch_" << half_patch << "\n"; |
|
|
|
ofs << "usemtl patch_" << patch_idx << (is_forward ? "_in" : "_out") << "\n"; |
|
|
|
for (auto face_idx : patches[patch_idx]) { |
|
|
|
const auto& face = iso_faces[face_idx]; |
|
|
|
ofs << "f"; |
|
|
|
if (is_forward) { |
|
|
|
for (auto vi : face.vertex_indices) |
|
|
|
ofs << " " << (vi + 1); |
|
|
|
} else { |
|
|
|
for (auto it = face.vertex_indices.rbegin(); it != face.vertex_indices.rend(); ++it) |
|
|
|
ofs << " " << (*it + 1); |
|
|
|
} |
|
|
|
ofs << "\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
ofs.close(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ISNP_API void build_implicit_network_by_blobtree(const s_settings& settings, |
|
|
|
const baked_blobtree_t& tree, |
|
|
|
stl_vector_mp<Eigen::Vector3d>& output_vertices, |
|
|
@ -87,6 +144,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& |
|
|
|
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); |
|
|
|
export_halfpatch_obj(iso_pts, iso_faces, patches, "halfpatch_before_connect"); |
|
|
|
} |
|
|
|
stl_vector_mp<stl_vector_mp<uint32_t>> half_patch_adj_list(2 * patches.size()); |
|
|
|
for (size_t i = 0; i < chains.size(); ++i) |
|
|
@ -161,6 +219,9 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& |
|
|
|
output_polygon_faces, |
|
|
|
output_vertex_counts_of_face); |
|
|
|
filter_active_vertices(output_vertices, output_polygon_faces); |
|
|
|
export_halfpatch_obj(iso_pts, iso_faces, patches, "halfpatch_final"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|