matlab – 如何从3D Delaunay三角剖分中获取三角形

我有一个3D点云的三角测量dt(或者可能是四面体化),我想找到一种从中提取三角形的好方法.注意,我知道如何获得四面体,它的简单dt.ConnectivityList,是否有一种从四面体中获取三角形的有效方法?每个三角形应仅在列表中出现一次.

目前我正在做以下事情 – 但是它很慢:

dt = delaunayTriangulation([X Y Z]);
tetrahedra = dt.ConnectivityList;

tris = cell(1, size(tetrahedra, 1)); % contains indices of tris in a tetra
for tt=1:size(tetrahedra, 1)
    vertIds = tetrahedra(tt, :); % vertex indices

    vmask = logical([0 1 1 1]);
    tris{tt} = [vertIds(circshift(vmask, [0 0 0 0]));
                vertIds(circshift(vmask, [1 1 1 1]));
                vertIds(circshift(vmask, [2 2 2 2]));
                vertIds(circshift(vmask, [3 3 3 3]))];
end

tris = unique(sort(cell2mat(tris'), 2), 'rows');

最佳答案 这是一个矢量化版本:

% take all four subsets of three points from the tets and concatenate
tris2 = [tetrahedra(:,[1 2 3]); tetrahedra(:,[1 2 4]); tetrahedra(:,[1 3 4]); tetrahedra(:, [2 3 4])];
% sort each row
tris2 = sort(tris2, 2);
% eliminate duplicates
tris2 = unique(tris2, 'rows');

我得到100,000个测试点(随机数)

Cellmethod: time=9.870982, numelements = 1344960
Vectmethod: time=1.014797, numelements = 1344960
点赞