spm_mesh_adjacency.m 916 B

12345678910111213141516171819202122232425
  1. function A = spm_mesh_adjacency(F)
  2. % Compute the adjacency matrix of a triangle mesh
  3. % FORMAT A = spm_mesh_adjacency(F)
  4. % F - a [fx3] faces array or a patch structure
  5. %
  6. % A - adjacency matrix as a sparse [vxv] array
  7. %__________________________________________________________________________
  8. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  9. % Guillaume Flandin
  10. % $Id: spm_mesh_adjacency.m 4035 2010-08-05 18:54:32Z guillaume $
  11. if ~isnumeric(F) && isfield(F,'vertices')
  12. N = size(F.vertices,1);
  13. F = double(F.faces);
  14. A = sparse([F(:,1); F(:,1); F(:,2); F(:,2); F(:,3); F(:,3)], ...
  15. [F(:,2); F(:,3); F(:,1); F(:,3); F(:,1); F(:,2)], 1, N, N);
  16. else
  17. if isstruct(F), F = F.faces; end
  18. F = double(F);
  19. A = sparse([F(:,1); F(:,1); F(:,2); F(:,2); F(:,3); F(:,3)], ...
  20. [F(:,2); F(:,3); F(:,1); F(:,3); F(:,1); F(:,2)], 1);
  21. end
  22. A = double(A > 0);