source: an2_editstack.m @ 41

Last change on this file since 41 was 39, checked in by tjniskan, 11 years ago
  • Added "Recent Files" quick access menu in File-menu
  • Fixed a bug in plugins/copy_data_to_workspace.m that made writing a

new name for a variable difficult

  • Fixed a bug in the file prefix editbox in an2_export_gui.m
  • Changed references to Analyze 2.0 in all license notices to Aedes.

The name change should now be complete...

M an2_export_gui.m
M an2_cellsprintf.m
M an2_calc_wait.m
M an2_check_file_exist.m
M an2_iseven.m
M an2_cellwrite.m
M an2_wbar.m
M an2_rot3d.m
M an2_readfdf.m
M an2_revision.m
M an2_viewprocpar.m
M an2_checkcthdr.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
M an2_resviewer.m
M an2_maptool.m
M aedes.m
M an2_res2table.m
M an2_copy_roi.m
M plugins/save_roi_as_mask.m
M plugins/write_difference_images.m
M plugins/plot_profile.m
M plugins/calculate_t2_map.m
M plugins/calculate_t1r_map.m
M plugins/view_kspace.m
M plugins/copy_data_to_workspace.m
M plugins/take_snapshot.m
M an2_inputdlg.m
M an2_roi_copy_gui.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
M an2_killfigs.m
M an2_roi_stats.m
M an2_saveres.m
M an2_rotateflip.m
M an2_juigetfiles.m
M an2_gui_defaults.m
M an2_editstack.m
M an2_update.m
M an2_write_nifti.m

File size: 13.3 KB
Line 
1function [filelist,rem_ind,add_ind,sort_ind] = an2_editstack(DATA)
2% AN2_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, (or 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=an2_gui_defaults;
88%GD.col.mainfig = FigColor;
89fig_h = 305;
90fig_w = 550;
91scrsz = get(0,'screensize');
92fig_pos = [scrsz(3)/2-fig_w/2 scrsz(4)/2-fig_h/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[fn, fp, fi] = an2_juigetfiles( ...
405  {['fid;FID;*.hdr;*.HDR;*.nii;*.NII;*.sur;*.SUR;',...
406    '*.mri;*.MRI;*.mrd;*.MRD;*.ima;*.IMA;*.dcm;*.DCM;',...
407    '*.xxm;*.XXM;*.mat;*.MAT;*.t1r;*.T1R;*.s1r;*.S1R;*.fdf;*.FDF;',...
408    '*.t2r;*.T2R;*.s2r;*.S2R;*.t1;*.T1;*.t2;*.T2;*.s1;*.S1;*.s2;*.S2;*.df;*.DF',...
409    '*.sf;*.SF'],'All Supported Files';...
410   'fid;FID','Varian FID-files (fid)'; ...
411   '*.hdr;*.HDR;*.nii;*.NII',...
412   'NIfTI and Analyze 7.5 Files (*.nii,*.hdr)'; ...
413   '*.sur;*.SUR','S.M.I.S. Image files (*.sur)'; ...
414   '*.mri;*.MRI','MRI-Files (*.mri)'; ...
415   '*.mrd;*.MRD','MRD-Files (*.mrd)'; ...
416   '*.ima;*.IMA','Siemens Vision Image Files (*.ima)'; ...
417   '*.dcm;*.DCM','DICOM image files (*.dcm)';...
418   '*.mat;*.MAT','Matlab MAT-Files (*.mat)';...
419   '*.fdf;*.FDF','Varian FDF-Files (*.fdf)';...
420   '*.t1r;*.T1R','T1R-Files (*.t1r)';...
421   '*.s1r;*.S1R','S1R-Files (*.s1r)';...
422   '*.t2r;*.T2R','T2R-Files (*.t2r)';...
423   '*.s2r;*.S2R','S2R-Files (*.s2r)';...
424   '*.t1;*.T1','T1-Files (*.t1)';...
425   '*.t2;*.T2','T2-Files (*.t2)';...
426   '*.s1;*.S1','S1-Files (*.s1)';...
427   '*.s2;*.S2','S2-Files (*.s2)';...
428   '*.df;*.DF','DF-Files (*.df)';...
429   '*.sf;*.SF','SF-Files (*.sf)';...
430   '*.*', 'All Files (*.*)'},...
431  'Select Data File(s)',filepath);
432if isequal(fn,0) || isequal(fp,0)
433  return
434end
435
436CurrentFiles = get(H.FILELBOX,'string');
437
438% Construct full file cell
439AddedFiles = cell(length(fn),1);
440for ii=1:length(fn)
441  AddedFiles{ii} = [fp{ii},fn{ii}];
442end
443
444% Check if some of the added files already exist in the list
445tmp={CurrentFiles{ismember(CurrentFiles,AddedFiles)}};
446rm_ind=find(ismember(AddedFiles,tmp));
447rem_files = {AddedFiles{rm_ind}};
448AddedFiles(rm_ind) = [];
449
450% Add unique files to the list
451if ~isempty(AddedFiles)
452  NewFiles = {AddedFiles{:}, CurrentFiles{:}}';
453  set(H.FILELBOX,'string',NewFiles,...
454                 'value',1:length(AddedFiles),...
455                 'listboxtop',1)
456 
457  % Check if buttons need to be disabled
458  l_CheckSelection([],[])
459 
460  % Warn about dublicates that weren't added
461  if ~isempty(rem_files)
462    h=warndlg({['The following files were not added' ...
463               ' because they were dublicates:'],'',...
464              rem_files{:}},'Warning',...
465              'modal');
466  end
467else
468  h=warndlg({['All files were skipped' ...
469              ' because they were dublicates!'],...
470             'No files added.'},'Warning',...
471            'modal');
472end
473
474
475
476end % function l_ResetFileList(h,
477
478%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479%
480% OK button is pressed
481%
482%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483function l_OKCallBack(h,evd)
484
485cancel = false;
486liststr = get(H.FILELBOX,'string');
487Dat.liststr = liststr';
488delete(H.FH);
489
490end % function l_OKCallBack(h,
491
492end
Note: See TracBrowser for help on using the repository browser.

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