/
GLDIslandfinder.m
72 lines (69 loc) · 2.24 KB
/
GLDIslandfinder.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function [NodeList,groupings,groups] = GLDIslandfinder(file)
%GLDIslandfinder Finds the nodes of islands in a GLM file.
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fid = fopen(file);
i=0;
disp('Reading GLM...')
while ~feof(fid)
newline = fgets(fid);
if containsRelaxed(newline,'name "')~=0
i = i+1;
string = cellstr(newline);
string = regexprep(string,{'name',';',' ','"'},{'','','',''});
Objects{1}(i,1) = string;
found = 0;
while found == 0
newline = fgets(fid);
if containsRelaxed(newline,'from "')~=0
string = cellstr(newline);
string = regexprep(string,{'from',';',' ','"'},{'','','',''});
Objects{2}(i,1) = string;
found = 1;
end
end
found = 0;
while found == 0
newline = fgets(fid);
if containsRelaxed(newline,'to "')~=0
string = cellstr(newline);
string = regexprep(string,{'to',';',' ','"'},{'','','',''});
Objects{3}(i,1) = string;
found = 1;
end
end
end
end
fclose(fid);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Building Node List...')
[Objects{3},I] = sort(Objects{3});
Objects{1} = Objects{1}(I,:);
Objects{2} = Objects{2}(I,:);
[Objectss{2},IA2] = sort(Objects{2});
Objectss{3} = Objects{3};
len = length(Objects{1});
grouping = zeros(len,1);%group #
group = 1;
disp('Building Tree and Finding Islands...')
for i = 1:len
if ~grouping(i)
[grouping,group] = traverseIsland(Objectss,Objects,IA2,grouping,group,i);
end
end
groups = unique(grouping);
groups(:,2) = 0;
groupsize = size(groups);
for i = 1:groupsize(1)
for j = 1:length(grouping)
if grouping(j) == groups(i,1)
groups(i,2) = groups(i,2)+1;
end
end
end
groupings = [grouping;grouping];
[NodeList,IA,~] = unique([Objects{2};Objects{3}]);
groupings = groupings(IA,1);
if length(groups)>1
disp(['Important: ',num2str(length(groups)-1),' islands were found, and ',num2str(sum(groupings==0)),' individual disconnected components.']);
end
end