-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_ancestry.m
executable file
·28 lines (27 loc) · 1.08 KB
/
find_ancestry.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
function [ indexAncestry ] = find_ancestry( index, nRegions, NUM_PARTITIONS_J )
%% FIND_PARENT Finds descriptors of parent
% This function finds the level, tile number and continuous index of the
% ancestry of the region with given index
%
% Input: index, nRegions, NUM_PARTITIONS_J
%
% Output: indexAncestry, indexes for parental hierarchy (ancestry)
%%
switch index
case 1
% Special case for zeroth region
indexAncestry = [];
otherwise
cummulativeRegions = cumsum(nRegions);
indexSmaller = find(cummulativeRegions < index, 1, 'last');
% pre-allocate vector
indexAncestry = zeros(indexSmaller, 1, 'int64'); % number of ancestry members is one smaller than level
% Fill ancestry by looping through parent's parents
for k = 1 : indexSmaller
[ ~,~,i_parent ] = find_parent( index, nRegions,NUM_PARTITIONS_J );
indexAncestry(k,1) = i_parent;
index = i_parent;
end
indexAncestry = flip(indexAncestry); % Order from coarsest to finest
end
end