{"title":"void Collapse(Vertex *u,Vertex *v){\n\t// Collapse the edge uv by moving vertex u onto v\n\t// Actually remove tris on uv, then update tris that\n\t// have u to have v, and then remove u.\n\tif(!v) {\n\t\t// u is a vertex all by itself so just delete it\n\t\tdelete u;\n\t\treturn;\n\t}\n\tstd::vector<Vertex *>tmp;\n\t// make tmp a Array of all the neighbors of u\n\tfor (unsigned int i = 0; ineighbor.size(); i++) {\n\t\tmp.push_back(u->neighbor[i]);\n\t}\n\t// delete triangles on edge uv:\n\t{\n\t\tauto i = u->face.size();\n\t\twhile (i--) {\n\t\t\tif (u->face[i]->HasVertex(v)) {\n\t\t\t\tdelete(u->face[i]);\n\t\t\t}\n\t\t}\n\t}\n\t// update remaining triangles to have v instead of u\n\t{\n\t\tauto i = u->face.size();\n\t\twhile (i--) {\n\t\t\tu->face[i]->ReplaceVertex(u, v);\n\t\t}\n\t}\n\tdelete u; \n\t// recompute the edge collapse costs for neighboring vertices\n\tfor (unsigned int i = 0; i<tmp.size(); i++) {\n\t\tComputeEdgeCostAtVertex(tmp[i]);\n\t}\n}\n解析代码内容:该函数用于将边uv合并,即将顶点u移动到顶点v上。具体操作如下:\n\n1. 判断顶点v是否存在,如果不存在,则顶点u是一个单独的顶点,直接删除顶点u,并返回。\n2. 创建一个临时数组tmp,用于存储顶点u的所有邻居顶点。\n3. 删除边uv上的三角形:\n - 遍历顶点u的所有三角形,如果该三角形包含顶点v,则删除该三角形。\n4. 更新剩余三角形的顶点,将顶点u替换为顶点v:\n - 遍历顶点u的所有三角形,将其中的顶点u替换为顶点v。\n5. 删除顶点u。\n6. 重新计算邻居顶点的边合并成本:\n - 遍历临时数组tmp中的所有顶点,重新计算其边合并成本。\n7. 函数结束。\n\n注:该函数依赖于其他函数ComputeEdgeCostAtVertex和ReplaceVertex的实现。

C++ Collapse Edge Function Implementation: Optimizing Mesh Geometry

原文地址: https://www.cveoy.top/t/topic/pzyL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录