gpt4 book ai didi

c++ - Cgal 表面网格 - 连通性

转载 作者:行者123 更新时间:2023-11-30 03:29:32 29 4
gpt4 key购买 nike

我有点困惑连接是如何工作的。我正在尝试从网格中移除面,并调整连接性,移除未使用的边和顶点。当我使用 mesh.is_valid() 它显示连接问题

Integrity of previous halfedge of h1 corrupted. Halfedge of v0 is not an incoming halfedge. vertices: iterated: 1 vs number_of_vertices(): 5 halfedges: iterated: 2 vs number_of_halfedges(): 14 faces: iterated: 3 vs number_of_faces(): 3

代码:

#include <string>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <boost/foreach.hpp>
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

typedef CGAL::Surface_mesh<K::Point_3> Mesh;
typedef Mesh::Vertex_index vertex_descriptor;
typedef Mesh::Face_index face_descriptor;
typedef Mesh::Halfedge_index halfedge_descriptor;
typedef Mesh::Edge_index edge_descriptor;

int main()
{
Mesh mesh;
vertex_descriptor v0 = mesh.add_vertex(K::Point_3(0,2,0));
vertex_descriptor v1 = mesh.add_vertex(K::Point_3(2,2,0));
vertex_descriptor v2 = mesh.add_vertex(K::Point_3(0,0,0));
vertex_descriptor v3 = mesh.add_vertex(K::Point_3(2,0,0));
vertex_descriptor v4 = mesh.add_vertex(K::Point_3(1,1,0));
mesh.add_face(v3, v1, v4);
mesh.add_face(v0, v4, v1);
mesh.add_face(v0, v2, v4);
mesh.add_face(v2, v3, v4);

int counter = 0;
std::vector <edge_descriptor> edg;
BOOST_FOREACH(face_descriptor fd, mesh.faces()){
if(counter == 0){
halfedge_descriptor hed = mesh.halfedge(fd);
halfedge_descriptor prev = mesh.prev(hed);
halfedge_descriptor next = mesh.next(hed);

mesh.set_vertex_halfedge_to_border_halfedge (next);
mesh.set_vertex_halfedge_to_border_halfedge (prev);
mesh.set_vertex_halfedge_to_border_halfedge (hed);

if(mesh.is_border(mesh.opposite(next))){
mesh.remove_edge(mesh.edge(next));
std::cout << "Remove next halfedge " << next << std::endl;
}else{
mesh.set_face(next, mesh.null_face());
std::cout << "sets next halfedge " << next << std::endl;
}

if(mesh.is_border(mesh.opposite(prev))){
mesh.remove_edge(mesh.edge(prev));
std::cout << "Remove prev halfedge " << prev << std::endl;
}else{
mesh.set_face(prev, mesh.null_face());
std::cout << "sets prev halfedge " << prev << std::endl;
}
if(mesh.is_border(mesh.opposite(hed))){
mesh.remove_edge(mesh.edge(hed));
std::cout << "Remove Face halfedge " << hed << std::endl;
}else{
mesh.set_face(hed, mesh.null_face());
std::cout << "sets Face halfedge " << hed << std::endl;
}
mesh.remove_face(fd);
counter++;

}
}
mesh.collect_garbage();
mesh.is_valid();
return 0;
}

最佳答案

使用 remove_face Euler operations 的功能.它将在幕后为您“保持有效性”。欧拉运算适用于任何类型 Graph 的值,它是 MutableFaceGraph 的“模型” .幸运的是,你的SurfaceMesh就是这样一个模型。

如果你用下面的代码替换你的循环(这是不必要的,因为你只想要一张脸),你会看到它是如何工作的:

int counter = 0;
BOOST_FOREACH(face_descriptor fd, mesh.faces()){
counter++;
}
std::cout << counter << " faces" << std::endl;

CGAL::Euler::remove_face(mesh.halfedge(*mesh.faces().begin()), mesh );
mesh.collect_garbage();
mesh.is_valid();

counter = 0;
BOOST_FOREACH(face_descriptor fd, mesh.faces()){
counter++;
}
std::cout << counter << " faces" << std::endl;

这不会产生验证错误,并确认操作后网格中少了一个面。

关于c++ - Cgal 表面网格 - 连通性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45652756/

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