我尝试了下面的代码,但我的索引不正确。我正在尝试使用 CGAL 和 3D Delaunay 渲染线条,但我得到了正确的索引。很难获得3D Delaunay的索引。我不知道哪个部分是错误的,我尝试使用 4 个顶点,它看起来是正确的,但是超过 5 个索引时我得到错误的三角形......
std::vector<int> triangles;
std::map<Delaunay3::Vertex_handle, int> index_of_vertex;
int j = 0;
for (Delaunay3::Finite_vertices_iterator it = dt.finite_vertices_begin();
it != dt.finite_vertices_end(); ++it, ++j) {
index_of_vertex[it.base()] = j;
}
for (Delaunay3::Finite_facets_iterator itFacet = dt.finite_facets_begin();
itFacet != dt.finite_facets_end(); itFacet++) {
triangles.push_back(index_of_vertex[itFacet->first->vertex(0)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(1)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(0)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(3)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(1)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(3)]);
}
std::vector<WORD> lineIndex;
lineIndex.resize(triangles.size() * sizeof(int) * 4);
int l, t;
for (l = 0, t = 0; t < triangles.size(); t += 4) {
// Each triangle has 3 lines, so D3D_PRIMITIVE_TOPOLOGY_LINELIST needs 6 vertices
// Each vertex has to be listed twice
lineIndex[l] = triangles[t];
l++;
lineIndex[l] = triangles[t + 1];
l++;
lineIndex[l] = triangles[t + 1];
l++;
lineIndex[l] = triangles[t + 2];
l++;
lineIndex[l] = triangles[t + 2];
l++;
lineIndex[l] = triangles[t];
l++;
}
// Fill in a buffer description for drawing only the triangle outlines
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = numTriangleVertices * 3 * sizeof(int); // <---- from the function
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
ZeroMemory(&InitData, sizeof(InitData));
InitData.pSysMem = static_cast<void*>(lineIndex.data());
pd3dDevice->CreateBuffer(&bd, &InitData, &g_pTriOutlineIndexBuffer);
让我用只有 4 个非共面顶点的三角测量来解释它。
然后你有 4 个有限面。它们中的每一个都表示为一个std::pair<Delaunay3::Cell_handle, int> pair;
,其中pair. first
是入射到小平面的像元,pair.second
是顶点的索引,与小平面中的小平面相对。
如果pair.second == 0
,则1,2,3
面顶点的索引;如果pair.second == 1
,则2,3,0
面顶点的索引;等。
也就是说,一般来说,pair.second == i
,小平面顶点的索引是(i+1)%4, (i+2)%4, (i+3)%4
还有一个帮助类,它是三角测量的基类https://doc.cgal.org/latest/TDS_3/classCGAL_1_1Triangulation__utils__3.html
它允许您编写Delaunay_3::vertex_triple_index(i,j)
。
我同意这根本没有很好的记录,我们将改进这一点。