-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_parent.m
executable file
·33 lines (26 loc) · 1.07 KB
/
find_parent.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
function [ levelParent, tileParent, indexParent ] = find_parent( index, nRegions, NUM_PARTITIONS_J )
%% FIND_PARENT finds descriptors of parent
% This function finds the level, tile number and continuous index of the
% parent of the region for the given index
%
% Input: index, nRegions, NUM_PARTITIONS_J
%
% Output: levelParent, tileParent, indexParent
%%
switch index
case 1
% Special case for zeroth region
tileParent = NaN;
levelParent = NaN;
indexParent = NaN;
otherwise
cummulativeRegions = cumsum(nRegions); % vector of the cummulative number of regions up until each level
indexSmaller = find(cummulativeRegions < index, 1, 'last'); % cummulativeRegions will have
level = indexSmaller + 1; % Present level
tile = index - cummulativeRegions(indexSmaller);
% Figure out ID of parent
tileParent = ceil(tile/NUM_PARTITIONS_J);
levelParent = level-1;
indexParent = sum(nRegions(1 : level-2)) + tileParent;
end
end