| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -6,18 +6,16 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#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) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					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::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); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        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; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -27,32 +25,28 @@ void export_halfpatch_obj( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    mtl.close(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::string obj_filename = filename + ".obj"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::string   obj_filename = filename + ".obj"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::ofstream ofs(obj_filename); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (!ofs) return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ofs << "mtllib "<< mtl_filename << "\n"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ofs << "mtllib " << mtl_filename << "\n"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // 输出所有顶点
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (const auto& v : iso_pts) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ofs << "v " << v.x() << " " << v.y() << " " << v.z() << "\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); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        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); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                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); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                for (auto it = face.vertex_indices.rbegin(); it != face.vertex_indices.rend(); ++it) ofs << " " << (*it + 1); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            ofs << "\n"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -60,6 +54,33 @@ void export_halfpatch_obj( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ofs.close(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void export_obj(const stl_vector_mp<Eigen::Vector3d>&                       vertices, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stl_vector_mp<uint32_t>&                                    faces, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stl_vector_mp<uint32_t>& output_vertex_counts_of_face, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                const std::string& filename) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::string   obj_filename = filename + ".obj"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    std::ofstream ofs(obj_filename); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (!ofs) return; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // 输出所有顶点
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (const auto& v : vertices) { ofs << "v " << v.x() << " " << v.y() << " " << v.z() << "\n"; } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // 输出所有面
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // 输出所有面
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    size_t idx = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    for (auto count : output_vertex_counts_of_face) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ofs << "f"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        for (size_t i = 0; i < count; ++i) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            ofs << " " << (faces[idx++] + 1); // OBJ 索引从1开始
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ofs << "\n"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ofs.close(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ofs.close(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					ISNP_API void build_implicit_network_by_blobtree(const s_settings&               settings, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                                 const baked_blobtree_t&         tree, | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -164,7 +185,7 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            arrangement_cells.reserve(shells.size()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            for (uint32_t i = 0; i < shells.size(); ++i) { arrangement_cells.emplace_back(stl_vector_mp<uint32_t>{i}); } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stl_vector_mp<std::pair<uint32_t, uint32_t>> shell_links{}; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -208,6 +229,10 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    transform_subface_to_primitive_labels(tree, cell_subface_signs, cell_primitive_signs); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                active_cell_label = filter_cells_by_boolean(tree, cell_primitive_signs); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                for (uint32_t i = 0; i < arrangement_cells.size(); ++i) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    std::cout << "Cell " << i << " active: " << active_cell_label[i] << std::endl; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            filter_polygon_faces(iso_faces, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                 patches, | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -218,10 +243,8 @@ ISNP_API void build_implicit_network_by_blobtree(const s_settings& | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                 active_cell_label, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                 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"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            filter_active_vertices(iso_pts, output_vertices, output_polygon_faces); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            export_obj(output_vertices, output_polygon_faces,output_vertex_counts_of_face,"final"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |