source: aedes_editstack.m

Last change on this file was 155, checked in by tjniskan, 7 years ago
  • Added support for multiple monitor systems

M aedes_inputdlg.m
M aedes_roi_copy_gui.m
A aedes_dialoglocation.m
M aedes_readfidprefs.m
M aedes_rotateflip.m
M aedes_resviewer.m
M aedes.m
M aedes_helpabout.m
M plugins/fat_analysis.m
M plugins/copy_data_to_workspace.m
M aedes_export_gui.m
M aedes_headerbrowser.m
M aedes_revision.m
M aedes_juigetfiles.m
M aedes_editstack.m

File size: 12.2 KB
Line 
1function [filelist,rem_ind,add_ind,sort_ind] = aedes_editstack(DATA)
2% AEDES_EDITSTACK - GUI for editing image stack
3%   
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
14% This function is a part of Aedes - A graphical tool for analyzing
15% medical images
16%
17% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
18%
19% Department of Physics, Department of Neurobiology
20% University of Kuopio, FINLAND
21%
22% This program may be used under the terms of the GNU General Public
23% License version 2.0 as published by the Free Software Foundation
24% and appearing in the file LICENSE.TXT included in the packaging of
25% this program.
26%
27% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
30
31
32% Public variables
33H = [];
34Out = [];
35Dat = [];
36cancel = true;
37
38
39% Get file names and paths
40for ii=1:length(DATA)
41  Dat.fnames{ii} = DATA{ii}.HDR.fname;
42  Dat.fpaths{ii} = DATA{ii}.HDR.fpath;
43  Dat.fullfiles{ii} = [DATA{ii}.HDR.fpath,...
44                      DATA{ii}.HDR.fname];
45end
46H = l_DrawGUI;
47
48% Initial selection check
49l_CheckSelection([],[])
50
51% Wait for quit
52waitfor(H.FH)
53if cancel
54  clear H Dat cancel DATA
55  filelist = {};
56  rem_ind = [];
57  add_ind = [];
58  sort_ind = [];
59  return
60end
61
62filelist = Dat.liststr;
63
64if ispc
65  rem_ind = ~ismember(lower(Dat.fullfiles),lower(filelist));
66  [tmp,sort_ind] = ismember(lower(filelist),lower(Dat.fullfiles));
67  add_ind = ~ismember(lower(filelist),lower(Dat.fullfiles));
68else
69  rem_ind = ~ismember(Dat.fullfiles,filelist);
70  [tmp,sort_ind] = ismember(filelist,Dat.fullfiles);
71  add_ind = ~ismember(filelist,Dat.fullfiles);
72end
73clear H Dat cancel DATA
74
75return
76
77%%%%%%%%%%%%%%%%%%%%%%%%%
78%
79% Draw Main GUI
80%
81%%%%%%%%%%%%%%%%%%%%%%%%%
82function H=l_DrawGUI()
83 
84
85%% Load default font and colors
86%FigColor=get(0,'DefaultUicontrolBackgroundcolor');
87GD=aedes_gui_defaults;
88%GD.col.mainfig = FigColor;
89fig_h = 305;
90fig_w = 550;
91fig_location = aedes_dialoglocation([fig_w,fig_h]);
92fig_pos = [fig_location(1) fig_location(2) fig_w fig_h];
93
94%% The main figure
95H.FH = figure('position',fig_pos,...
96              'Units','Pixel', ...
97              'Name','Edit Image Stack', ...
98              'Numbertitle','off', ...
99              'Tag','im_rotate_gui', ...
100              'Color',GD.col.mainfig, ...
101              'Toolbar','none', ...
102              'Menubar','none', ...
103              'DoubleBuffer','on', ...
104              'DockControls','off',...
105              'renderer','painters',...
106              'KeyPressFcn','',...
107              'resize','off',...
108              'windowstyle','modal');
109
110% Options uipanel
111H.OPTUIPANEL = uipanel('parent',H.FH,...
112                       'units','pixel',...
113                       'position',[5 40 fig_w-10 fig_h-45],...
114                                           'backgroundcolor',GD.col.frame);
115
116
117% Buttons uipanel
118H.BTNPANEL = uipanel('parent',H.OPTUIPANEL,...
119                     'units','pixel',...
120                     'position',[10 10 150 105+85+15+30],...
121                     'title','Options',...
122                                         'backgroundcolor',GD.col.frame);
123
124
125
126% File listbox
127tmp = get(H.BTNPANEL,'position');
128H.FILELBOX = uicontrol('parent',H.OPTUIPANEL,...
129                       'units','pixel',...
130                       'style','listbox',...
131                       'position',[tmp(1)+tmp(3)+10 tmp(2) fig_w-tmp(1)-tmp(3)-35 ...
132                   tmp(4)-8],...
133                       'backgroundcolor','w',...
134                       'string',Dat.fullfiles,...
135                       'Min',0,'Max',2,...
136                       'value',1,...
137                       'CallBack',@l_CheckSelection);
138tmp = get(H.FILELBOX,'position');
139files_tx = uicontrol('parent',H.OPTUIPANEL,...
140                     'units','pixel',...
141                     'style','text',...
142                     'position',[tmp(1) tmp(2)+tmp(4) 150 12],...
143                     'string','Files (slices)',...
144                     'horizontalalign','left',...
145                     'fontweig','bold',...
146                                         'backgroundcolor',GD.col.frame);
147
148% Options buttons
149tmp=get(H.BTNPANEL,'position');
150H.ADDFILESBTN = uicontrol('parent',H.BTNPANEL,...
151                          'position',[5 tmp(4)-45 tmp(3)-10 25],...
152                          'string','Add Files',...
153                          'Callback',@l_AddFiles,...
154                          'Enable','on');
155tmp=get(H.ADDFILESBTN,'position');
156H.REMFILESBTN = uicontrol('parent',H.BTNPANEL,...
157                          'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
158                          'string','Remove Files',...
159                          'Callback',@l_RemoveSelected,...
160                          'Enable','on');
161tmp=get(H.REMFILESBTN,'position');
162H.MOVETOPBTN = uicontrol('parent',H.BTNPANEL,...
163                         'position',[tmp(1) tmp(2)-tmp(4)-45 tmp(3) tmp(4)],...
164                         'string','Move to Top',...
165                         'Callback',{@l_MoveFcn,'top'},...
166                         'Enable','off');
167tmp=get(H.MOVETOPBTN,'position');
168H.MOVEUPBTN = uicontrol('parent',H.BTNPANEL,...
169                        'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
170                        'string','Move Up',...
171                        'Callback',{@l_MoveFcn,'up'},...
172                        'Enable','off');
173tmp=get(H.MOVEUPBTN,'position');
174H.MOVEDOWNBTN = uicontrol('parent',H.BTNPANEL,...
175                          'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
176                          'string','Move Down',...
177                          'Callback',{@l_MoveFcn,'down'},...
178                          'Enable','off');
179tmp=get(H.MOVEDOWNBTN,'position');
180H.MOVEBOTTOMBTN = uicontrol('parent',H.BTNPANEL,...
181                            'position',[tmp(1) tmp(2)-tmp(4)-3 tmp(3) tmp(4)],...
182                            'string','Move Bottom',...
183                            'Callback',{@l_MoveFcn,'bottom'},...
184                            'Enable','off');
185
186% Cancel button
187tmp = get(H.OPTUIPANEL,'position');
188H.CANCELBTN = uicontrol('parent',H.FH,...
189                       'units','pixel',...
190                       'position',[tmp(1)+tmp(3)-70 5 70 30],...
191                       'string','Cancel',...
192                       'callback','delete(gcbf)');
193
194% OK Button
195tmp = get(H.CANCELBTN,'position');
196H.OKBTN = uicontrol('parent',H.FH,...
197                    'units','pixel',...
198                    'position',[tmp(1)-tmp(3)-5 tmp(2) tmp(3) tmp(4)],...
199                    'string','OK',...
200                    'callback',@l_OKCallBack);
201tmp = get(H.OKBTN,'position');
202H.RESETBTN = uicontrol('parent',H.FH,...
203                       'units','pixel',...
204                       'position',[5 tmp(2) tmp(3) tmp(4)],...
205                       'string','Reset list',...
206                       'callback',@l_ResetList);
207
208
209end % function H=l_DrawGUI()
210
211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212%
213% Reset List
214%
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216function l_ResetList(h,evd)
217
218% Ask for confirmatio
219if ~isempty(h)
220  resp = questdlg('This will reset file list to default. Are you sure?',...
221                  'Reset File List?','Yes','No','No');
222  if strcmpi(resp,'No')
223    return
224  end
225end
226
227% Update file list
228set(H.FILELBOX,'string',Dat.fullfiles,...
229               'value',[],...
230               'listboxtop',1)
231
232% Check if buttons need to be disabled
233l_CheckSelection([],[])
234
235end % function l_ResetList(h,
236
237%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238%
239% Check listbox selection
240%
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242function l_CheckSelection(h,evd)
243
244% Button handles
245btn_h = [H.ADDFILESBTN,...
246        H.REMFILESBTN,...
247        H.MOVETOPBTN,...
248        H.MOVEUPBTN,...
249        H.MOVEDOWNBTN,...
250        H.MOVEBOTTOMBTN];
251
252% Get selected files
253val = get(H.FILELBOX,'value');
254str = get(H.FILELBOX,'string');
255val_max = length(str);
256
257if isempty(val)
258  set(btn_h(2:end),'enable','off')
259  return
260end
261if any(val==1) && any(val==val_max)
262  set(btn_h(3:end),'enable','off')
263elseif any(val==1)
264  set(btn_h(3:4),'enable','off')
265  set(setdiff(btn_h,btn_h(3:4)),'enable','on')
266elseif any(val==val_max)
267  set(btn_h(5:6),'enable','off')
268  set(setdiff(btn_h,btn_h(5:6)),'enable','on')
269else
270  set(btn_h,'enable','on')
271end
272
273% Enable Remove button
274set(btn_h(2),'enable','on')
275
276end % function l_CheckSelectio(h, 
277
278
279%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280%
281% Move files in the list
282%
283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284function l_MoveFcn(h,evd,opt)
285
286% Get listbox string and value
287liststr=get(H.FILELBOX,'string');
288listval = get(H.FILELBOX,'value');
289if isempty(listval)
290  return
291end
292
293% Get selected listbox items
294sel_items = {liststr{listval}};
295unsel_items = {liststr{setdiff(1:length(liststr),listval)}};
296
297switch lower(opt)
298 case 'top'
299 
300  % Determine move length
301  if min(listval)>1
302    move_length=diff([1 min(listval)]);
303  end
304 
305 case 'up'
306  if min(listval)>1
307    move_length=1;
308  end
309 
310 case 'down'
311  if max(listval)<length(liststr)
312    move_length=-1;
313  end
314 
315 case 'bottom'
316  if max(listval)<length(liststr)
317    move_length=diff([length(liststr) max(listval)]);
318  end
319 
320 otherwise
321  error('%s\n%s\n%s','Congratulations! You should not be able to produce this error!',...
322         'In addition, I''m not all that sorry and there is no one to send an error message.',...
323         'Please, stop bothering me and go away...')
324 
325end
326
327% Compute new values
328newsel_values = listval-move_length;
329newunsel_values = setdiff(1:length(liststr),newsel_values);
330
331% Rebuild list
332newlist = cell(1,length(liststr));
333newlist(newsel_values) = sel_items;
334newlist(newunsel_values) = unsel_items;
335
336% Refresh listbox
337if any(strcmpi(opt,{'top','up'}))
338  lboxtop = newsel_values(1);
339else
340  lboxtop = max(1,newsel_values(end)-10);
341end
342
343set(H.FILELBOX,'string',newlist,...
344               'value',newsel_values,...
345               'listboxtop',lboxtop)
346
347% Check if buttons need to be disabled
348l_CheckSelection([],[])
349
350end % function l_MoveFcn(h,
351
352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353%
354% Remove selected files
355%
356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357function l_RemoveSelected(h,evd)
358
359% Get listbox string and value
360liststr=get(H.FILELBOX,'string');
361listval = get(H.FILELBOX,'value');
362if isempty(listval)
363  return
364end
365
366% Throw an error message if the user tries to remove all files
367if length(listval)==length(liststr)
368  h=errordlg({'The file list cannot be empty!',...
369             'At least one file has to remain on the list.'},...
370             'List cannot be empty!','modal');
371  return
372end
373
374% Remove selected files
375liststr(listval)=[];
376
377% Refresh listbox
378set(H.FILELBOX,'string',liststr,...
379               'value',[],...
380               'listboxtop',1)
381
382% Check if buttons need to be disabled
383l_CheckSelection([],[])
384
385
386end % function l_RemoveSelected(h,
387
388
389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390%
391% Add Files to list
392%
393%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394function l_AddFiles(h,evd)
395 
396% Default filepath
397try
398  filepath=getpref('Aedes','GetDataFileDir');
399catch
400  filepath='';
401end
402
403% Ask for a file
404[filefilt,dataformats] = aedes_getfilefilter;
405[fn, fp, fi] = aedes_juigetfiles(filefilt,...
406  'Select Data File(s)',filepath);
407if isequal(fn,0) || isequal(fp,0)
408  return
409end
410
411CurrentFiles = get(H.FILELBOX,'string');
412
413% Construct full file cell
414AddedFiles = cell(length(fn),1);
415for ii=1:length(fn)
416  AddedFiles{ii} = [fp{ii},fn{ii}];
417end
418
419% Check if some of the added files already exist in the list
420tmp={CurrentFiles{ismember(CurrentFiles,AddedFiles)}};
421rm_ind=find(ismember(AddedFiles,tmp));
422rem_files = {AddedFiles{rm_ind}};
423AddedFiles(rm_ind) = [];
424
425% Add unique files to the list
426if ~isempty(AddedFiles)
427  NewFiles = {AddedFiles{:}, CurrentFiles{:}}';
428  set(H.FILELBOX,'string',NewFiles,...
429                 'value',1:length(AddedFiles),...
430                 'listboxtop',1)
431 
432  % Check if buttons need to be disabled
433  l_CheckSelection([],[])
434 
435  % Warn about dublicates that weren't added
436  if ~isempty(rem_files)
437    h=warndlg({['The following files were not added' ...
438               ' because they were dublicates:'],'',...
439              rem_files{:}},'Warning',...
440              'modal');
441  end
442else
443  h=warndlg({['All files were skipped' ...
444              ' because they were dublicates!'],...
445             'No files added.'},'Warning',...
446            'modal');
447end
448
449
450
451end % function l_ResetFileList(h,
452
453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454%
455% OK button is pressed
456%
457%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458function l_OKCallBack(h,evd)
459
460cancel = false;
461liststr = get(H.FILELBOX,'string');
462Dat.liststr = liststr';
463delete(H.FH);
464
465end % function l_OKCallBack(h,
466
467end
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008