【发布时间】:2019-11-02 14:40:53
【问题描述】:
我通过点来进行三角测量并吐出单元格数据。但是返回的值是错误的,因为单元格数据违反了三角测量原则。
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, 0.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)。
// ----- 结果 ---- 但是有些方法是错误的(0,1,2,3)和(0,1,3,4)。如果我减少 z 的 3 和 4 下降到 300 和 -300 它吐出 3 个细胞。 ( 0, 1, 2, 3), (4, 0, 2, 3) 和 (1, 4, 2, 3)。
//-----更新1.----
所以我改变了提取顶点的方式。我直接从 itCell->vertext->point() 转换,我得到了我认为正确的顶点。但它仍然给了我很多细胞 与其他单元格相交。我认为该集合应该是唯一的,并且不与其他单元格相交。
【问题讨论】: