source: an2_roi_copy_gui.m @ 36

Last change on this file since 36 was 36, checked in by tjniskan, 11 years ago
  • Added option to an2_readfid, an2_data_read and an2_readfidprefs

which allows controlling the output precision. Default is 'double'
(which is more precise), but if you have a very long data changing
this to 'single' will half the memory requirements.

  • Rewrote an2_inputdlg so that it does not depend on Matlab license.
  • Deleted many depricated files.
  • Moved addicon.m under misclib.
  • Added Analyze2 under GNU General Public License (version 2).
  • Added GPL license in license.txt file and added license

notifications in m-files.

M an2_export_gui.m
M analyze2.m
M an2_cellsprintf.m
M an2_getfilefilter.m
M an2_calc_wait.m
D an2_getnicedialoglocation.m
D misclib/uiclear.m
M misclib/spectrsum.m
M misclib/shiftind.m
M misclib/dcm_info.m
D misclib/b1_map.m
A misclib/addicon.m
M misclib/makelcmraw.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
D an2_questerrordlg.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
A license.txt
M an2_resviewer.m
M an2_maptool.m
M an2_res2table.m
M an2_helpabout.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
D an2_setdefaultbutton.m
M an2_readfid.m
M an2_readfidprefs.m
D addicon.m
M an2_readtab.m
D an2_imaread.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_errordump.m
M an2_update.m
M an2_write_nifti.m

File size: 11.4 KB
Line 
1function [slice_ind,dir_ind,roilabel,copytype] = an2_roi_copy_gui(ROI,roi_ind)
2% AN2_ROI_COPY_GUI -
3%   
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
14% This function is a part of Analyze 2.0 - 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,
21% P.O. Box 1627,
22% FIN-70211, Kuopio
23% FINLAND
24%
25% This program may be used under the terms of the GNU General Public
26% License version 2.0 as published by the Free Software Foundation
27% and appearing in the file LICENSE.TXT included in the packaging of
28% this program.
29%
30% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32
33
34% Initialize public variables
35H = [];
36slice_ind=[];
37roilabel = [];
38copytype=[];
39dir_ind = [];
40cancel=0;
41
42%% Determine if ROI is for normal or mixed type data
43if length(ROI(1).voxels)>1
44  isMixedType = true;
45else
46  isMixedType = false;
47end
48
49H = l_DrawGUI(ROI,roi_ind);
50fig_h = H.FH;
51
52%% Wait for exit
53waitfor(fig_h)
54if cancel
55  slice_ind=[];
56  roilabel=[];
57  dir_ind=[];
58end
59clear H
60return
61
62%%%%%%%%%%%%%%%%%%%%%%%%%
63% Draw GUI
64%%%%%%%%%%%%%%%%%%%%%%%%%
65function H=l_DrawGUI(ROI,roi_ind)
66
67%% Parse ROI structure
68roi_labels = {ROI(:).label};
69
70
71%% Load default font and colors
72FigColor=get(0,'DefaultUicontrolBackgroundcolor');
73GD=an2_gui_defaults;
74GD.col.mainfig = FigColor;%[236 233 216]./255;
75fig_h = 395;
76fig_w = 250;
77scrsz = get(0,'screensize');
78fig_pos = [scrsz(3)/2-fig_w/2 scrsz(4)/2-fig_h/2 fig_w fig_h];
79
80
81%% The main figure
82H.FH = figure('position',fig_pos,...
83              'Units','Pixel', ...
84              'Name','Copy ROI', ...
85              'Numbertitle','off', ...
86              'Tag','roi_copy_fig', ...
87              'Color',FigColor,...%[236 233 216]./255, ...
88              'Toolbar','none', ...
89              'Menubar','none', ...
90              'DoubleBuffer','on', ...
91              'DockControls','off',...
92              'renderer','painters',...
93              'KeyPressFcn','',...
94              'resize','off',...
95              'windowstyle','modal');
96fh = H.FH;
97
98%% Select ROI text
99h1 = uicontrol('parent',fh,...
100               'units','pixels',...
101               'position',[10 fig_h-10-15 170 15],...
102               'style','text',...
103               'horizontalalign','left',...
104               'backgroundcolor',FigColor,...[236 233 216]./255,...
105               'string','Select ROI(s) to be copied');
106
107%% ROI label popupmenu
108tmp=get(h1,'extent');
109H.ROILBOX = uicontrol('parent',fh,...
110                      'units','pixels',...
111                      'position',[10 fig_h-25-65 230 65],...
112                      'style','listbox',...
113                      'string',roi_labels,...
114                      'value',roi_ind,...
115                      'min',0,'max',2,...
116                      'backgroundcolor','w');
117
118
119tmp=get(H.ROILBOX,'position');
120%% Source select popup
121% $$$ H.SOURCEPOPUP = uicontrol('parent',fh,...
122% $$$                           'units','pixels',...
123% $$$                           'position',[tmp(1) tmp(2)-tmp(4)-5 tmp(3) tmp(4)],...
124% $$$                           'style','popup',...
125% $$$                           'string',,...
126% $$$                           'value',1,...
127% $$$                           'backgroundcolor','w');
128
129%% Direction uipanel
130% $$$ h1 = uipanel('parent',fh,...
131% $$$              'units','pixels',...
132% $$$              'position',[5 tmp(2)-90-15 240 90],...
133% $$$              'title','Direction',...
134% $$$              'backgroundcolor',GD.col.mainfig);
135% $$$ tmp=get(h1,'position');
136
137%% Button group for direction radiobuttons
138H.DIRBTNGRP = uibuttongroup('parent',fh,...
139                      'units','pixels',...
140                      'position',[5 tmp(2)-85-15 240 85],...
141                      'title','Copy Direction',...
142                      'backgroundcolor',GD.col.mainfig);
143H.XRADIO = uicontrol('parent',H.DIRBTNGRP,...
144                     'units','pixel',...
145                     'position',[15 50 150 15],...
146                     'style','radio',...
147                     'string','X direction',...'value',1,...
148                     'backgroundcolor',GD.col.mainfig);
149tmp=get(H.XRADIO,'position');
150H.YRADIO = uicontrol('parent',H.DIRBTNGRP,...
151                     'units','pixel',...
152                     'position',[15 tmp(2)-20 150 15],...
153                     'style','radio',...
154                     'string','Y direction',...'value',0,...
155                     'backgroundcolor',GD.col.mainfig);
156tmp=get(H.YRADIO,'position');
157H.ZRADIO = uicontrol('parent',H.DIRBTNGRP,...
158                     'units','pixel',...
159                     'position',[15 tmp(2)-20 150 15],...
160                     'style','radio',...
161                     'string','Z direction',...'value',0,...
162                     'backgroundcolor',GD.col.mainfig);
163set(H.DIRBTNGRP,'SelectedObject',H.XRADIO)
164tmp=get(H.DIRBTNGRP,'position');
165
166
167%% Copy type btngroup
168H.CPTYPEGRP = uibuttongroup('parent',fh,...
169                            'units','pixels',...
170                            'position',[5 tmp(2)-70-10 240 70],...
171                            'title','Copy type',...
172                            'backgroundcolor',GD.col.mainfig);
173H.APPENDRADIO = uicontrol('parent',H.CPTYPEGRP,...
174                          'units','pixel',...
175                          'position',[15 35 150 15],...
176                          'style','radio',...
177                          'string','Append',...
178                          'backgroundcolor',GD.col.mainfig);
179tmp=get(H.APPENDRADIO,'position');
180H.OVERWRITERADIO = uicontrol('parent',H.CPTYPEGRP,...
181                             'units','pixel',...
182                             'position',[15 tmp(2)-25 80 15],...
183                             'style','radio',...
184                             'string','Overwrite',...
185                             'backgroundcolor',GD.col.mainfig);
186set(H.CPTYPEGRP,'SelectedObject',H.APPENDRADIO)
187if ~isMixedType
188  set([H.APPENDRADIO,H.OVERWRITERADIO],'enable','off')
189end
190%% Slice selection btngroup
191tmp=get(H.CPTYPEGRP,'position');
192H.SLBTNGRP = uibuttongroup('parent',fh,...
193                     'units','pixels',...
194                     'position',[5 tmp(2)-70-10 240 70],...
195                     'title','Copy ROI to...',...
196                     'backgroundcolor',GD.col.mainfig);
197
198H.ALLRADIO = uicontrol('parent',H.SLBTNGRP,...
199                       'units','pixel',...
200                       'position',[15 35 150 15],...
201                       'style','radio',...
202                       'string','All slices',...
203                       'backgroundcolor',GD.col.mainfig);
204tmp=get(H.ALLRADIO,'position');
205
206H.CUSTOMRADIO = uicontrol('parent',H.SLBTNGRP,...
207                          'units','pixel',...
208                          'position',[15 tmp(2)-25 80 15],...
209                          'style','radio',...
210                          'string','Custom',...
211                          'backgroundcolor',GD.col.mainfig);
212tmp=get(H.CUSTOMRADIO,'position');
213H.CUSTOMEDIT = uicontrol('parent',H.SLBTNGRP,...
214                         'units','pixel',...
215                         'position',[85 tmp(2) 145 18],...
216                         'style','edit',...
217                         'backgroundcolor','w',...
218                         'horizontalalign','left',...
219                         'string','1:end',...
220                         'enable','off');
221set(H.SLBTNGRP,'SelectedObject',H.ALLRADIO,...
222               'SelectionChangeFcn',@l_SelectCustom)
223
224tmp=get(H.SLBTNGRP,'position');
225H.CANCELBTN = uicontrol('parent',fh,...
226                        'units','pixel',...
227                        'position',[175 tmp(2)-10-25 70 25],...
228                        'string','Cancel',...
229                        'callback',@l_Cancel);
230H.OKBTN = uicontrol('parent',fh,...
231                    'units','pixel',...
232                    'position',[100 tmp(2)-10-25 70 25],...
233                    'string','OK',...
234                    'callback',@l_CheckValues);
235
236%% If the ROI is for mixed type data, disable Y and Z buttons
237if isMixedType
238  set([H.YRADIO,H.ZRADIO],'enable','off','value',0)
239  set(H.XRADIO,'value',1)
240end
241
242end % function H=l_DrawGUI()
243
244
245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246% Select ALL/CUSTOM slices
247%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248  function l_SelectCustom(h,evd)
249 
250  if evd.NewValue==H.CUSTOMRADIO
251    set(H.CUSTOMEDIT,'enable','on')
252  else
253    set(H.CUSTOMEDIT,'enable','off')
254  end
255 
256  end % function l_SelectCustom(h,
257
258
259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260% Check values when OK is pressed
261%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262  function l_CheckValues(h,evd)
263 
264  %% Get handle to the selected radio button
265  h=get(H.DIRBTNGRP,'SelectedObject');
266 
267  %% Get ROI label
268  roi_vals=get(H.ROILBOX,'value');
269  if isempty(roi_vals)
270    warndlg('No ROI(s) selected! Please, select at least one ROI.',...
271            'Error','modal');
272    return
273  end
274  str=get(H.ROILBOX,'string');
275  roilabel = {str{roi_vals}};
276 
277  %% ROI index
278  %roi_ind=find(strcmp({ROI(:).label},str));
279  roi_ind=1;
280 
281  %% Copy Type
282  hCpType=get(H.CPTYPEGRP,'SelectedObject');
283  if hCpType==H.APPENDRADIO
284    copytype='append';
285  else
286    copytype='overwrite';
287  end
288 
289  %% Determine ROI size in the selected direction
290  if isMixedType
291    sz=length(ROI(roi_ind).voxels);
292  else 
293    if h==H.XRADIO
294      sz=size(ROI(roi_ind).voxels{1},3);
295      dir_ind=1;
296    elseif h==H.YRADIO
297      sz=size(ROI(roi_ind).voxels{1},2);
298      dir_ind=2;
299    else
300      sz=size(ROI(roi_ind).voxels{1},1);
301      dir_ind=3;
302    end
303  end
304 
305  %% Check if all slices or custom radio button is selected
306  h2=get(H.SLBTNGRP,'SelectedObject');
307 
308  if h2==H.ALLRADIO
309    slice_ind = 1:sz;
310  else %% Parse the custom string
311   
312    %% Get custom string
313    custom_str = get(H.CUSTOMEDIT,'string');
314   
315    %% Check that the string contains only valid characters
316    tmp_ind=ismember(custom_str,'0123456789end:,*+-/');
317    if ~all(tmp_ind)
318      h=warndlg(['The custom text "' custom_str '" contains invalid characters'],...
319                'Invalid expression','modal');
320      uiwait(h)
321      return
322    end
323   
324    % replace 'end' statement with ROI size
325    custom_str=strrep(custom_str,'end','sz');
326   
327    % Try to evaluate the index string
328    try
329      eval(['slice_ind=[' custom_str '];']);
330    catch
331      h=warndlg({['Could not evaluate expression "' custom_str '".'],...
332                 ['Custom string has to be a valid Matlab vector expression.']},...
333                'Could not evaluate expression','modal');
334      uiwait(h)
335      return
336    end
337   
338    % Sort indices and make sure that all indices are unique
339    slice_ind=unique(slice_ind);
340   
341    % Make sure that min>=1 and max<=sz
342    if max(slice_ind)>sz
343      h=warndlg({['Could not evaluate expression "' custom_str '".'],...
344                 'Maximum slice index exceeds the number of slices.'},...
345                'Could not evaluate expression','modal');
346      uiwait(h)
347      return
348    end
349    if min(slice_ind)<1
350      h=warndlg({['Could not evaluate expression "' custom_str '".'],...
351                 ['Slice indices have to be larger than zero.']},...
352                'Could not evaluate expression','modal');
353      uiwait(h)
354      return
355    end
356   
357  end
358 
359  % If this point is reached, all is well and we can exit normally
360  delete(H.FH)
361 
362  end % function l_CheckValues(h,
363
364
365%%%%%%%%%%%%%%%%%%%%%%
366% Cancel is pressed
367%%%%%%%%%%%%%%%%%%%%%%
368  function l_Cancel(h,evd)
369 
370  %% Set the cancel flag and resume with exit
371  cancel=1;
372 
373  delete(H.FH)
374 
375  end % function l_Cancel(h,
376end
Note: See TracBrowser for help on using the repository browser.

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