我必須用Matlab分析一些STL文件,並且我用STL閱讀器成功導入它們,但此函數僅返回頂點和麪(三角形)。從三角測量的邊緣/頂點矩陣
這是the STL reader我正在使用和this is an example STL file,由gmsh
工具生成gmsh -2 -format stl -bin t4.geo
。在這種情況下,STL功能的代碼在最後。
mesh = stlread("t4.stl");
是否有一個函數可以用來從這樣的三角測量中獲得頂點/邊緣鄰接矩陣?
function [F,V,N] = stlbinary(M)
F = [];
V = [];
N = [];
if length(M) < 84
error('MATLAB:stlread:incorrectFormat', ...
'Incomplete header information in binary STL file.');
end
% Bytes 81-84 are an unsigned 32-bit integer specifying the number of faces
% that follow.
numFaces = typecast(M(81:84),'uint32');
%numFaces = double(numFaces);
if numFaces == 0
warning('MATLAB:stlread:nodata','No data in STL file.');
return
end
T = M(85:end);
F = NaN(numFaces,3);
V = NaN(3*numFaces,3);
N = NaN(numFaces,3);
numRead = 0;
while numRead < numFaces
% Each facet is 50 bytes
% - Three single precision values specifying the face normal vector
% - Three single precision values specifying the first vertex (XYZ)
% - Three single precision values specifying the second vertex (XYZ)
% - Three single precision values specifying the third vertex (XYZ)
% - Two unused bytes
i1 = 50 * numRead + 1;
i2 = i1 + 50 - 1;
facet = T(i1:i2)';
n = typecast(facet(1:12),'single');
v1 = typecast(facet(13:24),'single');
v2 = typecast(facet(25:36),'single');
v3 = typecast(facet(37:48),'single');
n = double(n);
v = double([v1; v2; v3]);
% Figure out where to fit these new vertices, and the face, in the
% larger F and V collections.
fInd = numRead + 1;
vInd1 = 3 * (fInd - 1) + 1;
vInd2 = vInd1 + 3 - 1;
V(vInd1:vInd2,:) = v;
F(fInd,:) = vInd1:vInd2;
N(fInd,:) = n;
numRead = numRead + 1;
end
end
如果你的臉,你的人幾乎都有邊......這是本質上的一行代碼,我相信你能做到這一點,如果你嘗試。 – Ratbert
應該很容易,但我看起來矩陣每三角形索引一次,所以我很困惑。事實是,臉部矩陣只是數字'1:nvertices'重新成形的列表。 – senseiwa
我不明白這個代碼是如何與問題相關的。 – Ratbert