Home > marsbar > mars_display_roi.m

mars_display_roi

PURPOSE ^

utility routines for display of ROIs in graphic window

SYNOPSIS ^

function varargout=mars_display_roi(action_str, varargin)

DESCRIPTION ^

 utility routines for display of ROIs in graphic window
 FORMAT varargout=mars_display_roi(action_str, varargin)

 Usual call displays one or more ROIs on structural image:
 FORMAT mars_display_roi('display', roi_obj, structv, cmap)
 
 roi_obj   - single ROI object, or cell array of objects, or strings
 structv   - structural image or spm_vol struct for image
             [marsbar default structural if not passed]
 cmap      - colormap to use for display

 V0.2 - use of jet/specified colormap for display of many ROIs
 V0.3 - string input allowed, actionstrs as first arg, service callback

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout=mars_display_roi(action_str, varargin)
0002 % utility routines for display of ROIs in graphic window
0003 % FORMAT varargout=mars_display_roi(action_str, varargin)
0004 %
0005 % Usual call displays one or more ROIs on structural image:
0006 % FORMAT mars_display_roi('display', roi_obj, structv, cmap)
0007 %
0008 % roi_obj   - single ROI object, or cell array of objects, or strings
0009 % structv   - structural image or spm_vol struct for image
0010 %             [marsbar default structural if not passed]
0011 % cmap      - colormap to use for display
0012 %
0013 % V0.2 - use of jet/specified colormap for display of many ROIs
0014 % V0.3 - string input allowed, actionstrs as first arg, service callback
0015 %
0016 % $Id$
0017   
0018 global st; % global variable from spm_orthviews
0019 
0020 if nargin < 1
0021   action_str = '';
0022 end
0023 if isempty(action_str), action_str = 'display'; end
0024 
0025 switch lower(action_str), case 'display'             %-Display ROIs
0026 if nargin < 2
0027   roi_obj = spm_get([0 Inf],'*roi.mat','Select ROI(s) to view');
0028 else 
0029   roi_obj = varargin{1};
0030 end
0031 if isempty(roi_obj), return, end
0032 
0033 if nargin < 3
0034   mb = spm('getglobal', 'MARS');
0035   if ~isempty(mb)
0036     structv = mb.OPTIONS.structural.fname;
0037   else
0038     structv = fullfile(spm('dir'), 'canonical', ...
0039                ['avg152T1' mars_veropts('template_ext')]);
0040   end
0041 else
0042   structv = varargin{2};
0043 end
0044 if ischar(structv)
0045   structv = spm_vol(structv);
0046 end
0047 if nargin < 4
0048   cmap = jet;
0049 else
0050   cmap = varargin{3};
0051 end
0052 
0053 % Process filenames to roi objects
0054 roi_obj = maroi('load_cell', roi_obj);
0055 
0056 olen = prod(size(roi_obj));
0057 if olen > 1
0058   col_inds = round((0:(olen-1))*(size(cmap, 1)-1)/(olen-1))+1;
0059 else
0060   col_inds = 1;
0061 end
0062 
0063 % display with spm orthoviews
0064 spm_image('init', structv.fname);
0065 
0066 % space for object for which this is not defined
0067 sp = mars_space(structv);
0068 
0069 mo = [];
0070 roi_ctr = 1;
0071 for i = 1:olen
0072   roi = roi_obj{i};
0073   
0074   % check ROI contains something
0075   if isempty(roi) 
0076     warning(sprintf('ROI %d is missing', i));
0077   elseif is_empty_roi(roi)
0078     warning(sprintf('ROI %d:%s is empty', i, label(roi)));
0079   else
0080     % Define space for ROI
0081     nsp = native_space(roi);
0082     if isempty(nsp)
0083       nsp = sp;
0084     end
0085     
0086     % convert ROI to matrix
0087     mo = maroi_matrix(roi, nsp);
0088     dat = matrixdata(mo);
0089     if isempty(dat) | ~any(dat(:))
0090       warning(sprintf('ROI %d: %s  - contains no points to show',...
0091               i, label(roi)));
0092     else
0093       dat(dat == 0) = NaN;
0094       % add to image to display
0095       mars_orthviews('AddColouredMatrix', 1, dat, nsp.mat, cmap(col_inds(i),:));
0096   
0097       % Information for display
0098       XYZ = realpts(roi,nsp);
0099       mx = max(XYZ, [], 2); mn = min(XYZ, [], 2);
0100       lbl = label(roi);
0101       if isempty(lbl), lbl = '[No label]'; end
0102       roi_info(roi_ctr) = struct(...
0103       'label', lbl,...
0104       'num', i,...
0105       'c_o_m', c_o_m(mo, nsp, 'real'),...
0106       'volume', volume(mo),...
0107       'maxx', [mn(1) mx(1)],...
0108       'maxy', [mn(2) mx(2)],...
0109       'maxz', [mn(3) mx(3)] ...
0110       );
0111       roi_ctr = roi_ctr + 1;
0112     end
0113   end
0114 end
0115 if roi_ctr == 1
0116   return
0117 end
0118 
0119 % ROI information panel
0120 %-----------------------------------------------------------------------
0121 WS = spm('WinScale');
0122 fg = spm_figure('GetWin','Graphics');
0123 % Frame for ROI info
0124 uicontrol(fg,'Style','Frame','Position',[305 360 280 240].*WS);
0125 
0126 % ROI selection menu
0127 rl = length(roi_info); 
0128 labs = [num2str([1:rl]') repmat(': ', rl, 1) strvcat(roi_info(:).label)];
0129 uicontrol(fg,'Style','popupmenu' ,'Position',[320 570 250 20].*WS,...
0130       'String', cellstr(labs),...
0131       'Callback','mars_display_roi(''roi_menu'')', ...
0132       'ToolTipString','ROIs', 'Userdata', roi_info);
0133 
0134 uicontrol(fg,'Style','Text', 'Position',[310 520 50 020].*WS,...
0135       'String','Label:','HorizontalAlignment','left');
0136 uicontrol(fg,'Style','Text', 'Position',[310 490 110 020].*WS,...
0137       'String','Centre of mass:','HorizontalAlignment','left');
0138 uicontrol(fg,'Style','Text', 'Position',[310 460 110 020].*WS,...
0139       'String','Volume (mm):','HorizontalAlignment','left');
0140 uicontrol(fg,'Style','Text', 'Position',[310 430 110 020].*WS,...
0141       'String','Max/min X(mm):','HorizontalAlignment','left');
0142 uicontrol(fg,'Style','Text', 'Position',[310 400 110 020].*WS,...
0143       'String','Max/min Y(mm):','HorizontalAlignment','left');
0144 uicontrol(fg,'Style','Text', 'Position',[310 370 110 020].*WS,...
0145       'String','Max/min Z(mm):','HorizontalAlignment','left');
0146 
0147 % Text information
0148 st.mars.txt.label = uicontrol(fg,'Style','Text', ...
0149                   'Position',[360 520 220 020].*WS,...
0150                   'String','',...
0151                   'HorizontalAlignment','left',...
0152                   'FontWeight','bold');
0153 st.mars.txt.c_o_m = uicontrol(fg,'Style','Text', ...
0154                   'Position',[425 490 155 020].*WS,...
0155                   'String','',...
0156                   'HorizontalAlignment','left',...
0157                   'FontWeight','bold');
0158 st.mars.txt.volume = uicontrol(fg,'Style','Text', ...
0159                    'Position',[425 460 155 020].*WS,...
0160                    'String','',...
0161                    'HorizontalAlignment','left',...
0162                    'FontWeight','bold');
0163 st.mars.txt.maxx = uicontrol(fg,'Style','Text', ...
0164                  'Position',[425 430 155 020].*WS,...
0165                  'String','',...
0166                  'HorizontalAlignment','left',...
0167                  'FontWeight','bold');
0168 st.mars.txt.maxy = uicontrol(fg,'Style','Text', ...
0169                  'Position',[425 400 155 020].*WS,...
0170                  'String','',...
0171                  'HorizontalAlignment','left',...
0172                  'FontWeight','bold');
0173 st.mars.txt.maxz = uicontrol(fg,'Style','Text', ...
0174                  'Position',[425 370 155 020].*WS,...
0175                  'String','',...
0176                  'HorizontalAlignment','left',...
0177                  'FontWeight','bold');
0178 
0179 % store ROI information is orthviews global structure
0180 st.mars.roi_info = roi_info;
0181 
0182 % set our own callback for crosshair move
0183 st.callback = 'mars_display_roi(''orthcb'');';
0184 
0185 % Move to centre of mass of last ROI in list
0186 mars_orthviews('Reposition', roi_info(end).c_o_m);
0187 mars_display_roi('show_info', length(roi_info));
0188 
0189 case 'roi_menu'         % callback service from ROI menu
0190 if isfield(st, 'mars')
0191   v = get(gco, 'Value');
0192   mars_orthviews('Reposition', st.mars.roi_info(v).c_o_m);
0193   mars_display_roi('show_info', v);
0194 end
0195  
0196 case 'show_info'    % show info for ROI, from ROI info structure
0197 v = varargin{1};  
0198 if isfield(st, 'mars')
0199   if ~isempty(v)
0200     set(st.mars.txt.label, 'String', ...
0201               st.mars.roi_info(v).label);
0202     set(st.mars.txt.c_o_m, 'String', ...
0203               sprintf('%.3g  %.3g %.3g', ...
0204                   st.mars.roi_info(v).c_o_m));
0205     set(st.mars.txt.volume, 'String', ...
0206               sprintf('%8.2f', st.mars.roi_info(v).volume));
0207     set(st.mars.txt.maxx, 'String', ...
0208               sprintf('%.3g %.3g', st.mars.roi_info(v).maxx));
0209     set(st.mars.txt.maxy, 'String', ...
0210               sprintf('%.3g %.3g', st.mars.roi_info(v).maxy));
0211     set(st.mars.txt.maxz, 'String', ...
0212               sprintf('%.3g %.3g', st.mars.roi_info(v).maxz));
0213   else
0214     set(st.mars.txt.label, 'String','');
0215     set(st.mars.txt.c_o_m, 'String','');
0216     set(st.mars.txt.volume, 'String','');
0217     set(st.mars.txt.maxx, 'String','');
0218     set(st.mars.txt.maxy, 'String','');
0219     set(st.mars.txt.maxz, 'String','');
0220   end 
0221 end
0222 
0223 case 'orthcb'           % callback service from mars_orthviews
0224   
0225 % This copied from mars_orthviews 'shopos' function
0226 
0227 % The position of the crosshairs has been moved.
0228 %-----------------------------------------------------------------------
0229 if isfield(st,'mp'),
0230   fg = spm_figure('Findwin','Graphics');
0231   if any(findobj(fg) == st.mp),
0232     set(st.mp,'String',sprintf('%.1f %.1f %.1f',mars_orthviews('pos')));
0233     pos = mars_orthviews('pos',1);
0234     set(st.vp,'String',sprintf('%.1f %.1f %.1f',pos));
0235     
0236     % Set intensity to ROI list
0237     in_str = '';
0238     roi_p = [];
0239     V1 = st.vols{1};
0240     for r = 1:length(V1.blobs)
0241       p2 = V1.blobs{r}.mat \ V1.mat * [pos; 1];
0242       rval = spm_sample_vol(V1.blobs{r}.vol,...
0243             p2(1),p2(2),p2(3), ...
0244             0);
0245       if ~isnan(rval) & rval ~= 0
0246     roi_p = [roi_p r];
0247     in_str = [in_str num2str(r) ' '];
0248       end
0249     end
0250     set(st.in,'String',in_str);
0251     
0252     % find, and show info for ROI
0253     if ~isempty(roi_p)
0254       v = find(roi_p(end) == [st.mars.roi_info(:).num]);
0255       mars_display_roi('show_info', v);
0256     else
0257       mars_display_roi('show_info', []);
0258     end      
0259     
0260   else,
0261     st.Callback = ';';
0262     rmfield(st,{'mp','vp','in'});
0263   end;
0264 else,
0265   st.Callback = ';';
0266 end;
0267 
0268 otherwise
0269   error(['Unknown action strig: ' action_str]);
0270 end

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019