-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaedes_editstack.m
More file actions
467 lines (388 loc) · 12.2 KB
/
Copy pathaedes_editstack.m
File metadata and controls
467 lines (388 loc) · 12.2 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
function [filelist,rem_ind,add_ind,sort_ind] = aedes_editstack(DATA)
% AEDES_EDITSTACK - GUI for editing image stack
%
%
% Synopsis:
%
% Description:
%
% Examples:
%
% See also:
%
% This function is a part of Aedes - A graphical tool for analyzing
% medical images
%
% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
%
% Department of Physics, Department of Neurobiology
% University of Kuopio, FINLAND
%
% This program may be used under the terms of the GNU General Public
% License version 2.0 as published by the Free Software Foundation
% and appearing in the file LICENSE.TXT included in the packaging of
% this program.
%
% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
% Public variables
H = [];
Out = [];
Dat = [];
cancel = true;
% Get file names and paths
for ii=1:length(DATA)
Dat.fnames{ii} = DATA{ii}.HDR.fname;
Dat.fpaths{ii} = DATA{ii}.HDR.fpath;
Dat.fullfiles{ii} = [DATA{ii}.HDR.fpath,...
DATA{ii}.HDR.fname];
end
H = l_DrawGUI;
% Initial selection check
l_CheckSelection([],[])
% Wait for quit
waitfor(H.FH)
if cancel
clear H Dat cancel DATA
filelist = {};
rem_ind = [];
add_ind = [];
sort_ind = [];
return
end
filelist = Dat.liststr;
if ispc
rem_ind = ~ismember(lower(Dat.fullfiles),lower(filelist));
[tmp,sort_ind] = ismember(lower(filelist),lower(Dat.fullfiles));
add_ind = ~ismember(lower(filelist),lower(Dat.fullfiles));
else
rem_ind = ~ismember(Dat.fullfiles,filelist);
[tmp,sort_ind] = ismember(filelist,Dat.fullfiles);
add_ind = ~ismember(filelist,Dat.fullfiles);
end
clear H Dat cancel DATA
return
%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Draw Main GUI
%
%%%%%%%%%%%%%%%%%%%%%%%%%
function H=l_DrawGUI()
%% Load default font and colors
%FigColor=get(0,'DefaultUicontrolBackgroundcolor');
GD=aedes_gui_defaults;
%GD.col.mainfig = FigColor;
fig_h = 305;
fig_w = 550;
fig_location = aedes_dialoglocation([fig_w,fig_h]);
fig_pos = [fig_location(1) fig_location(2) fig_w fig_h];
%% The main figure
H.FH = figure('position',fig_pos,...
'Units','Pixel', ...
'Name','Edit Image Stack', ...
'Numbertitle','off', ...
'Tag','im_rotate_gui', ...
'Color',GD.col.mainfig, ...
'Toolbar','none', ...
'Menubar','none', ...
'DoubleBuffer','on', ...
'DockControls','off',...
'renderer','painters',...
'KeyPressFcn','',...
'resize','off',...
'windowstyle','modal');
% Options uipanel
H.OPTUIPANEL = uipanel('parent',H.FH,...
'units','pixel',...
'position',[5 40 fig_w-10 fig_h-45],...
'backgroundcolor',GD.col.frame);
% Buttons uipanel
H.BTNPANEL = uipanel('parent',H.OPTUIPANEL,...
'units','pixel',...
'position',[10 10 150 105+85+15+30],...
'title','Options',...
'backgroundcolor',GD.col.frame);
% File listbox
tmp = get(H.BTNPANEL,'position');
H.FILELBOX = uicontrol('parent',H.OPTUIPANEL,...
'units','pixel',...
'style','listbox',...
'position',[tmp(1)+tmp(3)+10 tmp(2) fig_w-tmp(1)-tmp(3)-35 ...
tmp(4)-8],...
'backgroundcolor','w',...
'string',Dat.fullfiles,...
'Min',0,'Max',2,...
'value',1,...
'CallBack',@l_CheckSelection);
tmp = get(H.FILELBOX,'position');
files_tx = uicontrol('parent',H.OPTUIPANEL,...
'units','pixel',...
'style','text',...
'position',[tmp(1) tmp(2)+tmp(4) 150 12],...
'string','Files (slices)',...
'horizontalalign','left',...
'fontweig','bold',...
'backgroundcolor',GD.col.frame);
% Options buttons
tmp=get(H.BTNPANEL,'position');
H.ADDFILESBTN = uicontrol('parent',H.BTNPANEL,...
'position',[5 tmp(4)-45 tmp(3)-10 25],...
'string','Add Files',...
'Callback',@l_AddFiles,...
'Enable','on');
tmp=get(H.ADDFILESBTN,'position');
H.REMFILESBTN = uicontrol('parent',H.BTNPANEL,...
'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
'string','Remove Files',...
'Callback',@l_RemoveSelected,...
'Enable','on');
tmp=get(H.REMFILESBTN,'position');
H.MOVETOPBTN = uicontrol('parent',H.BTNPANEL,...
'position',[tmp(1) tmp(2)-tmp(4)-45 tmp(3) tmp(4)],...
'string','Move to Top',...
'Callback',{@l_MoveFcn,'top'},...
'Enable','off');
tmp=get(H.MOVETOPBTN,'position');
H.MOVEUPBTN = uicontrol('parent',H.BTNPANEL,...
'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
'string','Move Up',...
'Callback',{@l_MoveFcn,'up'},...
'Enable','off');
tmp=get(H.MOVEUPBTN,'position');
H.MOVEDOWNBTN = uicontrol('parent',H.BTNPANEL,...
'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
'string','Move Down',...
'Callback',{@l_MoveFcn,'down'},...
'Enable','off');
tmp=get(H.MOVEDOWNBTN,'position');
H.MOVEBOTTOMBTN = uicontrol('parent',H.BTNPANEL,...
'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
'string','Move Bottom',...
'Callback',{@l_MoveFcn,'bottom'},...
'Enable','off');
% Cancel button
tmp = get(H.OPTUIPANEL,'position');
H.CANCELBTN = uicontrol('parent',H.FH,...
'units','pixel',...
'position',[tmp(1)+tmp(3)-70 5 70 30],...
'string','Cancel',...
'callback','delete(gcbf)');
% OK Button
tmp = get(H.CANCELBTN,'position');
H.OKBTN = uicontrol('parent',H.FH,...
'units','pixel',...
'position',[tmp(1)-tmp(3)-5 tmp(2) tmp(3) tmp(4)],...
'string','OK',...
'callback',@l_OKCallBack);
tmp = get(H.OKBTN,'position');
H.RESETBTN = uicontrol('parent',H.FH,...
'units','pixel',...
'position',[5 tmp(2) tmp(3) tmp(4)],...
'string','Reset list',...
'callback',@l_ResetList);
end % function H=l_DrawGUI()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Reset List
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_ResetList(h,evd)
% Ask for confirmatio
if ~isempty(h)
resp = questdlg('This will reset file list to default. Are you sure?',...
'Reset File List?','Yes','No','No');
if strcmpi(resp,'No')
return
end
end
% Update file list
set(H.FILELBOX,'string',Dat.fullfiles,...
'value',[],...
'listboxtop',1)
% Check if buttons need to be disabled
l_CheckSelection([],[])
end % function l_ResetList(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Check listbox selection
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_CheckSelection(h,evd)
% Button handles
btn_h = [H.ADDFILESBTN,...
H.REMFILESBTN,...
H.MOVETOPBTN,...
H.MOVEUPBTN,...
H.MOVEDOWNBTN,...
H.MOVEBOTTOMBTN];
% Get selected files
val = get(H.FILELBOX,'value');
str = get(H.FILELBOX,'string');
val_max = length(str);
if isempty(val)
set(btn_h(2:end),'enable','off')
return
end
if any(val==1) && any(val==val_max)
set(btn_h(3:end),'enable','off')
elseif any(val==1)
set(btn_h(3:4),'enable','off')
set(setdiff(btn_h,btn_h(3:4)),'enable','on')
elseif any(val==val_max)
set(btn_h(5:6),'enable','off')
set(setdiff(btn_h,btn_h(5:6)),'enable','on')
else
set(btn_h,'enable','on')
end
% Enable Remove button
set(btn_h(2),'enable','on')
end % function l_CheckSelectio(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Move files in the list
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_MoveFcn(h,evd,opt)
% Get listbox string and value
liststr=get(H.FILELBOX,'string');
listval = get(H.FILELBOX,'value');
if isempty(listval)
return
end
% Get selected listbox items
sel_items = {liststr{listval}};
unsel_items = {liststr{setdiff(1:length(liststr),listval)}};
switch lower(opt)
case 'top'
% Determine move length
if min(listval)>1
move_length=diff([1 min(listval)]);
end
case 'up'
if min(listval)>1
move_length=1;
end
case 'down'
if max(listval)<length(liststr)
move_length=-1;
end
case 'bottom'
if max(listval)<length(liststr)
move_length=diff([length(liststr) max(listval)]);
end
otherwise
error('%s\n%s\n%s','Congratulations! You should not be able to produce this error!',...
'In addition, I''m not all that sorry and there is no one to send an error message.',...
'Please, stop bothering me and go away...')
end
% Compute new values
newsel_values = listval-move_length;
newunsel_values = setdiff(1:length(liststr),newsel_values);
% Rebuild list
newlist = cell(1,length(liststr));
newlist(newsel_values) = sel_items;
newlist(newunsel_values) = unsel_items;
% Refresh listbox
if any(strcmpi(opt,{'top','up'}))
lboxtop = newsel_values(1);
else
lboxtop = max(1,newsel_values(end)-10);
end
set(H.FILELBOX,'string',newlist,...
'value',newsel_values,...
'listboxtop',lboxtop)
% Check if buttons need to be disabled
l_CheckSelection([],[])
end % function l_MoveFcn(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Remove selected files
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_RemoveSelected(h,evd)
% Get listbox string and value
liststr=get(H.FILELBOX,'string');
listval = get(H.FILELBOX,'value');
if isempty(listval)
return
end
% Throw an error message if the user tries to remove all files
if length(listval)==length(liststr)
h=errordlg({'The file list cannot be empty!',...
'At least one file has to remain on the list.'},...
'List cannot be empty!','modal');
return
end
% Remove selected files
liststr(listval)=[];
% Refresh listbox
set(H.FILELBOX,'string',liststr,...
'value',[],...
'listboxtop',1)
% Check if buttons need to be disabled
l_CheckSelection([],[])
end % function l_RemoveSelected(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Add Files to list
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_AddFiles(h,evd)
% Default filepath
try
filepath=getpref('Aedes','GetDataFileDir');
catch
filepath='';
end
% Ask for a file
[filefilt,dataformats] = aedes_getfilefilter;
[fn, fp, fi] = aedes_juigetfiles(filefilt,...
'Select Data File(s)',filepath);
if isequal(fn,0) || isequal(fp,0)
return
end
CurrentFiles = get(H.FILELBOX,'string');
% Construct full file cell
AddedFiles = cell(length(fn),1);
for ii=1:length(fn)
AddedFiles{ii} = [fp{ii},fn{ii}];
end
% Check if some of the added files already exist in the list
tmp={CurrentFiles{ismember(CurrentFiles,AddedFiles)}};
rm_ind=find(ismember(AddedFiles,tmp));
rem_files = {AddedFiles{rm_ind}};
AddedFiles(rm_ind) = [];
% Add unique files to the list
if ~isempty(AddedFiles)
NewFiles = {AddedFiles{:}, CurrentFiles{:}}';
set(H.FILELBOX,'string',NewFiles,...
'value',1:length(AddedFiles),...
'listboxtop',1)
% Check if buttons need to be disabled
l_CheckSelection([],[])
% Warn about dublicates that weren't added
if ~isempty(rem_files)
h=warndlg({['The following files were not added' ...
' because they were dublicates:'],'',...
rem_files{:}},'Warning',...
'modal');
end
else
h=warndlg({['All files were skipped' ...
' because they were dublicates!'],...
'No files added.'},'Warning',...
'modal');
end
end % function l_ResetFileList(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% OK button is pressed
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_OKCallBack(h,evd)
cancel = false;
liststr = get(H.FILELBOX,'string');
Dat.liststr = liststr';
delete(H.FH);
end % function l_OKCallBack(h,
end