function mars_display_roi(roi_obj, structv)
% displays one or more ROIs on structural image
% FORMAT mars_display_roi(roi_obj, structv)
% 
% roi_obj   - single ROI object, or cell array of objects
% structv   - structural image or spm_vol struct for image
%             [marsbar default structural if not passed]

if nargin < 1
  error('Need ROI to display');
end
if ~iscell(roi_obj), roi_obj = {roi_obj};end
if nargin < 2
  mb = spm('getglobal', 'MARSBAR');
  if ~isempty(mb)
    structv = mb.structural.fname;
  else
    structv = fullfile(spm('dir'), 'canonical', 'avg152t1.img');
  end
end
if ischar(structv)
  structv = spm_vol(structv);
end

colours = [1 0 0;1 1 0;0 1 0;0 1 1;0 0 1;1 0 1];
clen = size(colours, 1);
olen = length(roi_obj);
if olen > clen
  error(['Can only display ' num2str(clen) ' ROIs at a time']);
end

% display with spm orthoviews
spm_image('init', structv.fname);

% space for object for which this is not defined
sp = mars_space(structv);

mo = [];
for i = 1:olen
  roi = roi_obj{i};
  % check ROI contains something
  if isempty(roi) | is_empty_roi(roi)
    warning(sprintf('ROI %d: %s  - is empty', i, label(roi)));
  else
    % convert ROI to matrix
    nsp = native_space(roi);
    if isempty(nsp)
      nsp = sp;
    end
    mo = maroi_matrix(roi, nsp);
    dat = matrixdata(mo);
    if isempty(dat) | ~any(dat(:))
      warning(sprintf('ROI %d: %s  - contains no points to show',...
		      i, label(roi)));
      mo = [];
    else
      dat(dat == 0) = NaN;
      % add to image to display
      spm_orthviews('AddColouredMatrix', 1, dat, nsp.mat, colours(i,:));
    end
  end
end
if ~isempty(mo)
  spm_orthviews('Reposition', c_o_m(mo, sp, 'real'));
end

% st.callback = 'mars_display_roi(''orthcb'');';

