0
我正在製作切片功能,刪除長度爲y的部分網格。當我嘗試刪除網格的已刪除的面部邊緣時,問題就開始了,它會進入無限循環。表面網格 - 刪除邊緣,循環進入無限循環CGAL
問題出現在哪裏!
//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)
它進入無限循環。
任何人都可以解釋它爲什麼這樣做,我該如何解決它?
Full Code!
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);
}
}
}
}
}
}
}
}
已經發現了,愚蠢的我大聲笑 – duufous