| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -7,86 +7,6 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include <fstream> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include "post_topo/chain_post_processing.hpp" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					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 = is_forward ? 0.8f : 0.2f; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        float b = 1.0f - r; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        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(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					// Export OBJ without patch information
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void export_obj_no_patch( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    const stl_vector_mp<Eigen::Vector3d>& iso_pts, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    const stl_vector_mp<polygon_face_t>& iso_faces, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    const std::string& filename) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // Write OBJ file
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::string obj_filename = filename + ".obj"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::ofstream ofs(obj_filename); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (!ofs) return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // Write all vertices
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (const auto& v : iso_pts) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ofs << "v " << v.x() << " " << v.y() << " " << v.z() << "\n"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // Write all faces
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (const auto& face : iso_faces) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ofs << "f"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        for (auto vi : face.vertex_indices) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            ofs << " " << (vi + 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, | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -154,7 +74,6 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                         iso_verts, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                         iso_faces); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    export_obj_no_patch(iso_pts, iso_faces, "halfpatch_bbefore_connect"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // connect components by topology
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    stl_vector_mp<uint32_t>                             patch_of_face(iso_faces.size()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    stl_vector_mp<uint32_t>                             shell_of_half_patch{}; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -278,6 +197,5 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                remap_parametric_plane_vertices(output_parametric_planes); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        export_halfpatch_obj(iso_pts, iso_faces, patches, "halfpatch_final"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} |