码迷,mamicode.com
首页 > 其他好文 > 详细

高效的计算Laplacian 矩阵

时间:2014-12-21 22:04:15      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:

直接上代码,可以直接调用:

function L1 = CP_Laplacian( M )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
% number of vertices (size of matrix)
nverts = size(M.vertices,1);

% assume manifold and faces oriented uniformly
edges = [M.faces(:,[1,2]); M.faces(:,[2,3]); M.faces(:,[3,1])];

% extract vertices from matrix
v1Idxs = edges(:,1);
v2Idxs = edges(:,2);
v1s = M.vertices(v1Idxs,:);
v2s = M.vertices(v2Idxs,:);

% compute edge lengths and weights
eps = 1e-8;
edgel = sqrt( sum( (v1s-v2s).^2, 2 ) );
edgew = 1 ./ (eps + edgel );

% construct sparse matrix
nnzeros = size(edges,1) / 2;
L1 = sparse( v1Idxs, v2Idxs, edgew, nverts, nverts );

% compute diagonal by summing column-major (faster)
D = -full( sum( L1,1 ) );

% insert D in 0-diagonal of L1
L1 = spdiags(D,0,L1);

end

高效的计算Laplacian 矩阵

标签:

原文地址:http://www.cnblogs.com/zhanglianbo/p/4177058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!