-
Notifications
You must be signed in to change notification settings - Fork 0
/
createAdjMatrixVol.m
46 lines (37 loc) · 1.46 KB
/
createAdjMatrixVol.m
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
function AdjMat = createAdjMatrixVol(V, sizeV)
w = sizeV(1);
h = sizeV(3);
d = sizeV(2);
% h = size(V,1); w = size(V,2); d = size(V,3);
numVox = w*h*d;
AdjMat = zeros(numVox, numVox);
% TODO: ensure the correct indexing using Matlab's convention!!!
for z = 1:h
for y = 1:d
for x = 1:w
id = ((z-1)*d+(y-1))*w+x-1 + 1;
% check neighborhood
for nz = -1:1
for ny = -1:1
for nx = -1:1
distToCtr = norm([nx,ny,nz],2);
if distToCtr > 1 || distToCtr == 0% skip if L2-norm is greater than 1 or equal to 0
continue;
end
zz = z + nz;
yy = y + ny;
xx = x + nx;
if zz < 1 || yy < 1 || xx < 1 ||...
zz > h || yy > d || xx > w
continue; % out of bound
end
idn = ((zz-1)*d+(yy-1))*w+xx-1 + 1;
% set connection
AdjMat(id,idn) = 1;
end
end
end
end
end
end
end