-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeAdmin_UpdateGUI.m
213 lines (200 loc) · 9.55 KB
/
TreeAdmin_UpdateGUI.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
function TreeAdmin_UpdateGUI(handles)
% {'animal','dpi','HFS','lateral_side','pyramidal_blade','arc','complete
% ness','xyz_scale','one_micron_sampling'}
if ~isfield(handles.admin,'all_trees')
return
end
if numel(handles.admin.all_trees) > size(handles.admin.treecolors,1)
handles.admin.treecolors = repmat(handles.admin.treecolors,[ceil(numel(handles.admin.all_trees)/size(handles.admin.treecolors,1)),1]);
end
if max(cellfun(@(x) max(x.R),handles.admin.all_trees)) > size(handles.admin.treecolors,1)
handles.admin.treecolors = repmat(handles.admin.treecolors,[ceil(max(cellfun(@(x) max(x.R),handles.admin.all_trees))/size(handles.admin.treecolors,1)),1]);
end
if handles.filter.changed && ~handles.admin.locktreelist_ok
handles.filter.changed = false;
handles.filter.selected_trees = 1;
set(handles.Trees,'Value',1)
handles.admin.filter = false(numel(handles.admin.all_trees),1);
for t = 1: numel(handles.admin.all_trees)
if handles.admin.deleted_trees(t)
handles.admin.filter(t) = false;
else
handles.admin.filter(t) = TreeAdmin_checktreewithfilter(handles.admin.all_trees{t},handles.filter);
end
end
end
% %% dpi check
% % dpi = cellfun(@(x) x.dpi,handles.admin.all_trees);%,'UniformOutput',0))
% dpi = zeros(numel(handles.admin.all_trees),1,'uint16');
% dpi(~cellfun(@(x) isempty(x.dpi),handles.admin.all_trees)) = 1;
% dpi(dpi>0) = cat(1,handles.admin.all_trees{dpi>0}.dpi);
% handles.admin.select = cat(2,handles.admin.select,dpi >= handles.admin.dpi_min & dpi <= handles.admin.dpi_max);
%
% %% HFS check
% % HFS = cellfun(@(x) x.HFS,handles.admin.all_trees);%,'UniformOutput',0))
% HFS = zeros(numel(handles.admin.all_trees),1,'uint16');
% HFS(~cellfun(@(x) isempty(x.HFS),handles.admin.all_trees)) = 1;
% HFS(HFS>0) = cat(1,handles.admin.all_trees{HFS>0});
% switch sum([handles.admin.HFS_pos,handles.admin.HFS_neg])
% case 0
%
% case 1
% if handles.admin.arc_pos
% handles.admin.select = cat(2,handles.admin.select,HFS == 1);
% else
% handles.admin.select = cat(2,handles.admin.select,HFS == 0);
% end
% case 2
% handles.admin.select = cat(2,handles.admin.select,~isempty(HFS));
% end
%
% %% Lateral Side Check
% lateral_side = cellfun(@(x) x.lateral_side,handles.admin.all_trees,'UniformOutput',0);
% switch sum([handles.admin.ipsi,handles.admin.contra])
% case 0
%
% case 1
% if handles.admin.ipsi
% handles.admin.select = cat(2,handles.admin.select,strcmp({'ipsi'},lateral_side));%,'Ipsi','Ipsilateral','ipsilateral'},lateral_side));
% else
% handles.admin.select = cat(2,handles.admin.select,strcmp({'contra'},lateral_side));%,'Contra','Contralateral','contralateral'},lateral_side));
% end
% case 2
% handles.admin.select = cat(2,handles.admin.select,~strcmp('',lateral_side));
% end
%
% %% pyramidal blade check
% pyramidal_blade = cellfun(@(x) x.pyramidal_blade,handles.admin.all_trees,'UniformOutput',0);
% switch sum([handles.admin.ipsi,handles.admin.contra])
% case 0
%
% case 1
% if handles.admin.supra
% handles.admin.select = cat(2,handles.admin.select,strcmp({'supra'},pyramidal_blade));%,'Supra','Suprapyramidal','suprapyramidal'},pyramidal_blade));
% else
% handles.admin.select = cat(2,handles.admin.select,strcmp({'infra'},pyramidal_blade));%,'Infra','Infrapyramidal','infrapyramidal'},pyramidal_blade));
% end
% case 2
% handles.admin.select = cat(2,handles.admin.select,~strcmp('',pyramidal_blade));
% end
%
%
%
% %% Arc check
%
% arc = cellfun(@(x) x.arc,handles.admin.all_trees);%,'UniformOutput',0))
% arc = zeros(numel(handles.admin.all_trees),1,'uint16');
% arc(~cellfun(@(x) isempty(x.arc),handles.admin.all_trees)) = 1;
% arc(arc>0) = cat(1,handles.admin.all_trees{arc>0});
% switch sum([handles.admin.arc_pos,handles.admin.arc_neg])
% case 0
%
% case 1
% if handles.admin.arc_pos
% handles.admin.select = cat(2,handles.admin.select,arc == 1);
% else
% handles.admin.select = cat(2,handles.admin.select,arc == 0);
% end
% case 2
% handles.admin.select = cat(2,handles.admin.select,~isempty(arc));
% end
%
% %% completeness check
% completeness = cellfun(@(x) x.completeness,handles.admin.all_trees);%,'UniformOutput',0))
% handles.admin.select = cat(2,handles.admin.select,completeness >= handles.admin.compl_min & completeness <= handles.admin.compl_max);
%
%
% end
%%
if sum(handles.admin.filter) == 0
set(handles.Animal,'Value',1)
set(handles.Animal,'String',{})
handles.admin.selected_animals = [];
set(handles.Trees,'String',{})
handles.admin.filtered_trees = handles.admin.filter;
set(handles.Details,'Data',{})
set(handles.Details,'Enable','off')
set(handles.n_sel_trees,'String','')
elseif ~handles.admin.locktreelist_ok
if isfield(handles.filter,'filtered_animals')
selanim = handles.filter.filtered_animals(handles.filter.selected_animals);
else
selanim = {};
end
handles.filter.filtered_animals = unique(cellfun(@(x) num2str(x.animal),handles.admin.all_trees(handles.admin.filter),'UniformOutput',0));
liststring = handles.filter.filtered_animals;
if any(cellfun(@isempty,liststring))
liststring{cellfun(@isempty,liststring)} = 'Unknown';
end
set(handles.Animal,'String',liststring)
selanimind = [];
for a = 1:numel(selanim)
ind = cellfun(@(x) strcmp(x,selanim{a}),handles.filter.filtered_animals);
if sum(ind)==1
selanimind = cat(1,selanimind,find(ind));
end
end
if ~isempty(selanimind)
handles.filter.selected_animals = selanimind;
set(handles.Animal,'Value',selanimind)
elseif isempty(handles.filter.selected_animals) || ~all(get(handles.Animal,'Value')' == handles.filter.selected_animals) || any(handles.filter.selected_animals > numel(handles.filter.filtered_animals))
set(handles.Animal,'Value',1)
handles.filter.selected_animals = 1;
end
handles.filter.filtered_trees = handles.admin.filter & cellfun(@(x) any(strcmp(x.animal,handles.filter.filtered_animals(handles.filter.selected_animals))),handles.admin.all_trees)';%,'UniformOutput',0);
handles.filter.filtered_tree_names = cell(sum(handles.filter.filtered_trees),2);
filtered_trees = find(handles.filter.filtered_trees);
for t = 1:numel(filtered_trees)
t2 = filtered_trees(t);
handles.filter.filtered_tree_names{t,1} = handles.admin.all_trees{t2}.name;
handles.filter.filtered_tree_names{t,2} = t2;
end
set(handles.Trees,'String',handles.filter.filtered_tree_names(:,1))
end
if ~handles.admin.locktreelist_ok && (~exist('liststring','var') || numel(get(handles.Animal,'String')) ~= numel(liststring) || ~all(strcmp(get(handles.Animal,'String'),liststring')) || any(size(handles.filter.filtered_tree_names,1) < handles.filter.selected_trees))
handles.filter.selected_trees = 1;
set(handles.Trees,'Value',1)
set(handles.n_sel_trees,'String','1 tree(s) selected')
end
if sum(handles.admin.filter) ~= 0
selected_tree_names = handles.filter.filtered_tree_names(handles.filter.selected_trees,1);
if numel(get(handles.Details,'RowName')) ~= numel(selected_tree_names) || ~all(strcmp(selected_tree_names,get(handles.Details,'RowName')))
handles.admin.selected_detail = [];
end
set(handles.Details,'Enable','on')
cont = {'','...'};
selected_tree_names = cellfun(@(x) strcat(x(1:min(size(x,2),35)),cont{(min(size(x,2),35)==35)+1}),selected_tree_names,'UniformOutput',0);
set(handles.Details,'RowName',selected_tree_names)
% selected_trees = cat(1,handles.admin.all_trees{cat(1,handles.filter.filtered_tree_names{handles.filter.selected_trees,2})}); %struct
selected_trees = handles.admin.all_trees(cat(1,handles.filter.filtered_tree_names{handles.filter.selected_trees,2}));
details_cell = cell(numel(selected_trees),numel(handles.admin.tags(1,:)));
for c = 1:size(details_cell,2)
% details_cell(1:numel(selected_trees),c)={selected_trees.(handles.admin.tags{1,c})}'; %struct
details_cell(1:numel(selected_trees),c)=cellfun(@(x) x.(handles.admin.tags{1,c}),selected_trees,'UniformOutput',0)';
end
set(handles.Details,'Data',details_cell)%,'ColumnFormat',{'char','short','logical',{'ipsi','contra','unknown'},{'supra','infra','unknown'},'logical','short','short','short'})
end
%% Tree Preview
set(handles.TreeAdmin,'CurrentAxes',handles.Preview)
cla(handles.Preview)
if handles.admin.preview_ok && exist('selected_trees','var')
if handles.admin.rotate_ok
for t = 1:numel(selected_trees)
selected_trees{t} = rot_tree(selected_trees{t},[],'-m3dY');
end
end
[~,spreaded_trees] = spread_tree(selected_trees);
for t = 1:numel(spreaded_trees)
spreaded_trees{t}.D(spreaded_trees{t}.D<3) = 3;
if numel(spreaded_trees{t}.R) == numel(spreaded_trees{t}.X)
plot_tree(spreaded_trees{t},handles.admin.treecolors(spreaded_trees{t}.R,:));
else
plot_tree(spreaded_trees{t});
end
end
end
%% Finish
if get(handles.Legend_ok,'Value')
legend(handles.Preview,handles.filter.filtered_tree_names(handles.filter.selected_trees,1))
end
guidata(handles.TreeAdmin,handles)