我传入该点以进行三角剖分并输出单元格数据。但是返回的值是错误的,因为单元数据违反了三角剖分的原则。
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_3<K> Delaunay;
std::vector<K::Point_3> points;
std::map<Delaunay::Vertex_handle, int> index_of_vertex;
points.push_back(K::Point_3(-400.0, 0.0, 0.0));
points.push_back(K::Point_3(200, 400.0, 0.0));
points.push_back(K::Point_3(200, -400.0, 0.0));
points.push_back(K::Point_3(0.0, 0.0, 600.0));
points.push_back(K::Point_3(0.0, 0.0, -600.0));
//And here I push the vector to Delaunay
Delaunay dt(points.begin(), points.end());
// Keep track of vertex used
for (Delaunay::Finite_vertices_iterator it = t.finite_vertices_begin(); it != dt.finite_vertices_end(); ++it, ++j)
{
index_of_vertex[it.base()] = j;
}
// Iterate though and extract vertex and index in cell.
for (Delaunay::Finite_cells_iterator itCell = it.finite_cells_begin(), itend = dt.finite_cells_end(); itCell != itend; itCell++)
{
vector<double> verts;
vector<int> indx;
int ind0 = index_of_vertex[itCell->vertex(0)];
int ind1 = index_of_vertex[itCell->vertex(1)];
int ind2 = index_of_vertex[itCell->vertex(2)];
int ind3 = index_of_vertex[itCell->vertex(3)];
K::Point_3 v0 = points[ind0];
K::Point_3 v1 = points[ind1];
K::Point_3 v2 = points[ind2];
K::Point_3 v3 = points[ind3];
// Store the vertex
verts.push_back(CGAL::to_double(v0.x()));
...
verts.push_back(CGAL::to_double(v3.z()));
// extract the index
int ind00 = Delaunay::vertex_triple_index(0, 0);
...
int ind32 = Delaunay::vertex_triple_index(3, 2);
// Store the index
indx.push_back(ind00);
...
indx.push_back(ind32);
}
// -期望-正如您在上面看到的。我有5个点(-400.0,400.0,0.0),(200,400.0,0.0),(200,-400.0,0.0),(0.0,0.0,600.0),(0.0,0.0,600.0)。因此,如果输出正确,我很可能是两个顶点分别为(0,1,2,3)和(0,1,2,4)的单元格。
// - Result -但它是如何拆分错误的( 0,1,2,3)和(0,1,3,4)的。如果我把z从3和4减少到300和-300,它就会吐出3 cell。( 0,1,2,3),(4,0,2,3)和(1,4,2,3)。
//-更新1.
所以我改变了提取顶点的方式。我直接从itCell->vertext->point()转换,并正确地得到了我想要的顶点。但它仍然给了我很多与其他细胞相交的细胞。我认为集合应该是唯一的,并且不会与其他细胞相交。
发布于 2019-06-20 12:09:46
正如here文档所述,此函数不能保证按照PointInputIterator顺序插入点。如果你想设置与你的输入相匹配的索引,你最好使用this example。This one也可以工作。
对应函数的文档为here。
https://stackoverflow.com/questions/56674754
复制相似问题