【发布时间】:2017-07-12 10:24:12
【问题描述】:
我正在使用这个工具箱中的code 来计算一组面孔的邻接矩阵。我的faces 是一个m*3 数组,例如:
23 13 12
12 22 23
13 4 12
23 14 13
22 35 23
据我了解,邻接矩阵应该是nxn 矩阵,其中n 是顶点数。对于我的一些网格 .ply 文件,我得到的邻接矩阵的维度小于顶点数。例如,n=5047,但我的邻接矩阵的维度为 nxn= 4719x4719。
这种行为的原因可能是什么?我不仅在所有网格文件上都收到此错误,而是在某些网格文件上收到此错误。
代码:
function A = triangulation2adjacency(face,vertex)
% triangulation2adjacency - compute the adjacency matrix
% of a given triangulation.
%
% A = triangulation2adjacency(face);
% or for getting a weighted graph
% A = triangulation2adjacency(face,vertex);
%
% Copyright (c) 2005 Gabriel Peyr
[tmp,face] = check_face_vertex([],face);
f = double(face)';
A = sparse([f(:,1); f(:,1); f(:,2); f(:,2); f(:,3); f(:,3)], ...
[f(:,2); f(:,3); f(:,1); f(:,3); f(:,1); f(:,2)], ...
1.0);
% avoid double links
A = double(A>0);
return;
nvert = max(max(face));
nface = size(face,1);
A = spalloc(nvert,nvert,3*nface);
for i=1:nface
for k=1:3
kk = mod(k,3)+1;
if nargin<2
A(face(i,k),face(i,kk)) = 1;
else
v = vertex(:,face(i,k))-vertex(:,face(i,kk));
A(face(i,k),face(i,kk)) = sqrt( sum(v.^2) ); % euclidean distance
end
end
end
% make sure that all edges are symmetric
A = max(A,A');
【问题讨论】:
标签: matlab graph-theory mesh adjacency-matrix