-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfindneighbors.m
More file actions
56 lines (39 loc) · 1.61 KB
/
findneighbors.m
File metadata and controls
56 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function neighbors = findneighbors(nface, coordlist, deltri)
% Find neighbors of face 'nface' (index to 'coordlist')
% patch implicitly defined by 'coordlist'
%
% Idea: Delaunay-triang. is dual to voronoi-diagram.
% The neighbors are thus the Voronoi cells that share a facet with the ones
% in nface.
% P. Steffens, 05/2008 - 08/2014
% Note: Problem: cells may partially share a facet, i.e. touch, but not have the
% vertices in common. This is because tht too big cells are artificially
% cut off.
% ** This is now treated in Makevoronoi.
if nargin<3 %Compute Delaunay triangulation, if not provided
deltri = delaunay(coordlist(:,1), coordlist(:,2));
end
% if nargin>2, s2=size(faces,2); else s2=10; end
% adjacentlist = zeros(size(coordlist,1), s2);
% index = ones(size(coordlist,1), 1);
% neighbors = [];
% for nf = 1:numel(nface)
% % s = sum(deltri==nface(nf), 2) > 0; % lines of deltri that contain nf (logical index)
% s = any(deltri==nface(nf), 2);
% allv = deltri(s,:); % content of these lines
% neighbors = [neighbors; setdiff( unique(allv(:)), nface(nf) ) ]; % -"-, unique and without nf
% end
%
% N = false(size(deltri,1),1);
% for nf = 1:numel(nface)
% N = N | any(deltri==nface(nf), 2);
% end
N = any(ismember(deltri,nface),2); % lines of deltri that contain a member of nface (logical index)
allv = deltri(N,:); % content of these lines
if numel(nface)~=1
neighbors = setdiff( unique(allv(:)), nface );
else % do same without setdiff (faster)
allv = unique(allv(:));
neighbors = allv(allv~=nface);
end
% neighbors = unique(neighbors);