gpt4 book ai didi

c++ - 表面网格-去除边缘,循环进入无限循环CGAL

转载 作者:行者123 更新时间:2023-11-28 05:03:23 26 4
gpt4 key购买 nike

我正在制作 slice 函数,该函数删除 y 长度处的部分网格。当我尝试删除网格的已移除面边缘时,问题开始出现,它进入无限循环。

哪里出了问题!

//removes edge - puts in infinite loop
BOOST_FOREACH(halfEdge_descriptor hed, halfedges_around_face(mesh.halfedge(fd), mesh)){
edge_descriptor ed = mesh.edge(hed);
mesh.remove_edge(ed);
}

当我遍历 halfedges 时,它会按预期进行迭代,但是当我尝试通过转换为

remove_edge(Edge_index ed)

进入无限循环。

任何人都可以解释为什么会这样,我该如何解决?

完整代码!

void Mesh::slice(SurfaceMesh &mesh,  double lengthToCut){
typedef SurfaceMesh::Vertex_index vertex_descriptor;
typedef SurfaceMesh::Face_index face_descriptor;
typedef SurfaceMesh::Halfedge_index halfEdge_descriptor;
typedef SurfaceMesh::Edge_index edge_descriptor;
double y = findMaxY(mesh) - lengthToCut; // length of a mesh
//;oops over faces
BOOST_FOREACH(face_descriptor fd, mesh.faces()){
int verticesLargerThan = 0;
//loops over vertices of face
BOOST_FOREACH(vertex_descriptor vd,vertices_around_face(mesh.halfedge(fd), mesh)){
if(CGAL::compare ( mesh.point(vd)[1], y) == CGAL::LARGER){
verticesLargerThan++;
// if all vertices y coordinates are larger than double y, then removes face
if(verticesLargerThan == 3){
mesh.remove_face(fd);
//mesh.remove_face(fd);
int removedFaceCounter = 0;
BOOST_FOREACH(face_descriptor rfd,faces_around_face(mesh.halfedge(fd), mesh)){
if(mesh.is_removed(rfd)){
removedFaceCounter++;
}
//remove all edges and vertices of face if face is not linked to any other face
if(removedFaceCounter == 3){
//removes edge - puts in infinite loop
BOOST_FOREACH(halfEdge_descriptor hed, halfedges_around_face(mesh.halfedge(fd), mesh)){
edge_descriptor ed = mesh.edge(hed);
mesh.remove_edge(ed);
}
//removes vertice
BOOST_FOREACH(vertex_descriptor rvd,vertices_around_face(mesh.halfedge(fd), mesh)){
//removes vertice if its not linked to any face
bool allFacesRemoved = true;
BOOST_FOREACH(face_descriptor rfvd, faces_around_target(mesh.halfedge(fd), mesh)){

if(!mesh.is_removed(rfvd)){
allFacesRemoved = false;
break;
}
}
if(allFacesRemoved){
mesh.remove_vertex(rvd);
}
}
}
}
}
}
}
}

最佳答案

这是一个典型的错误:删除您正在迭代的元素。在这种特殊情况下,您将在迭代面部边缘的同时移除边缘。您不太可能会找到停止迭代的初始边,因此会出现无限循环。

关于c++ - 表面网格-去除边缘,循环进入无限循环CGAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45394410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com