2014-02-18 200 views
4

我已經有了一個3D三角剖分dt(或者可能是四面體化)的3D點雲,我希望找到一個很好的方法從中提取三角形。請注意,我知道如何獲得四面體,其簡單的dt.ConnectivityList,是否有一種從四面體中獲得三角形的有效方法?每個三角形只能在列表中出現一次。如何從3D Delaunay三角剖分中獲得三角形

目前我'做以下 - 這不過是痛苦的緩慢:

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'); 
+0

不,我看看你在那裏使用的任何函數,但是你是否嘗試將'tris'聲明爲一個數組而不是ac數組?我對大循環中的細胞有過「有趣」的體驗。 – McMa

+0

@McMa是的,這是一個可能的優化,但是,我仍然需要對每一行進行排序,然後刪除模糊。 – brtk

回答

2

這裏有一個向量化版本:

% 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'); 

擁有10個測試點(隨機數)我得到

Cellmethod: time=9.870982, numelements = 1344960 
Vectmethod: time=1.014797, numelements = 1344960 
+0

我知道你的應用程序可能太晚了,但我喜歡這個難題... – xenoclast