Home > phiwave > @slover > fill_defaults.m

fill_defaults

PURPOSE ^

check and fill fields in object

SYNOPSIS ^

function obj = fill_defaults(obj)

DESCRIPTION ^

 check and fill fields in object
 FORMAT obj = fill_defaults(obj)
 
 Input
 obj    - object to fill
 
 Output
 obj    - object filled

 $Id: fill_defaults.m,v 1.2 2005/05/06 22:59:56 matthewbrett Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function obj = fill_defaults(obj)
0002 % check and fill fields in object
0003 % FORMAT obj = fill_defaults(obj)
0004 %
0005 % Input
0006 % obj    - object to fill
0007 %
0008 % Output
0009 % obj    - object filled
0010 %
0011 % $Id: fill_defaults.m,v 1.2 2005/05/06 22:59:56 matthewbrett Exp $
0012 
0013 % Some default structures
0014 def_labs = struct('colour',[1 1 1],'size',0.075,'format', '%+3.0f');
0015 def_fig  = struct('position', [0 0 1 0.92], 'units', 'normalized', ...
0016              'valign', 'top');
0017 def_area = struct('position', [0 0 1 1], ...
0018           'units', '', ...
0019           'halign', 'center',...
0020           'valign', 'middle');
0021 
0022 % Figure.  We allow the figure to be dead, if we are going to resurrect
0023 % it later.
0024 dead_f = 0;
0025 if ~isempty(obj.figure)
0026   % Is it dead?
0027   if ~ishandle(obj.figure)
0028     % Do we want to revive it?
0029     if ~obj.resurrectf
0030       error('Figure handle is not a valid figure')
0031     end
0032     dead_f = 1;
0033     obj.refreshf = 1;
0034   elseif ~strcmp(get(obj.figure,'Type'),'figure')
0035     error('Figure handle is not a figure')
0036   end
0037 else
0038   % no figure handle. Try spm figure, then gcf
0039   obj.figure = spm_figure('FindWin', 'Graphics'); 
0040   if isempty(obj.figure)
0041     obj.figure = gcf;
0042   end
0043 end
0044 % set defaults for SPM figure
0045 if ~dead_f
0046   if strcmp(get(obj.figure, 'Tag'),'Graphics')
0047     % position figure nicely for SPM
0048     obj.area = mars_struct('fillafromb', obj.area, def_fig);
0049   end
0050 end
0051 
0052 % orientation; string or 4x4 matrix
0053 orientn = [];
0054 if ischar(obj.transform)
0055   orientn = find(strcmpi(obj.transform, {'axial', ... 
0056             'coronal', ...
0057             'sagittal', ...
0058             'saggital'}));
0059   if isempty(orientn)
0060     error(sprintf('Unexpected orientation %s', obj.transform));
0061   end
0062   if orientn == 4
0063     warning('Goofy spelling of sagittal, but we''ll let you off');
0064   end
0065   ts = [0 0 0 0 0 0 1 1 1;...
0066       0 0 0 pi/2 0 0 1 -1 1;...
0067       0 0 0 pi/2 0 -pi/2 -1 1 1];
0068   obj.transform = spm_matrix(ts(orientn,:));
0069 end
0070 
0071 % default slice size, slice matrix depends on orientation
0072 if (isempty(obj.slicedef) | isempty(obj.slices)) ...
0073       & ~isempty(obj.img)
0074   % take image sizes from first image
0075   V = obj.img(1).vol;
0076   D = V.dim(1:3);
0077   T = obj.transform * V.mat;
0078   vcorners = [1 1 1; D(1) 1 1; 1 D(2) 1; D(1:2) 1; ...
0079           1 1 D(3); D(1) 1 D(3); 1 D(2:3) ; D(1:3)]';
0080   corners = T * [vcorners; ones(1,8)];
0081   SC = sort(corners');
0082   vxsz = sqrt(sum(T(1:3,1:3).^2));
0083   
0084   if isempty(obj.slicedef)
0085     obj.slicedef = [SC(1,1) vxsz(1) SC(8,1);SC(1,2) vxsz(2) SC(8,2)];
0086   end
0087   if isempty(obj.slices)
0088     obj.slices = [SC(1,3):vxsz(3):SC(8,3)];
0089   end
0090 end
0091 
0092 % labels
0093 if ischar(obj.labels)
0094   if ~strcmp(lower(obj.labels), 'none')
0095     error('If labels is string, should be ''none''');
0096   end
0097 else
0098   obj.labels = mars_struct('fillafromb', obj.labels, def_labs);
0099 end
0100 
0101 % figure area stuff
0102 obj.area = mars_struct('fillafromb', obj.area, def_area);
0103 if isempty(obj.area.units)
0104   if (all(obj.area.position>=0 & obj.area.position<=1))
0105     obj.area.units = 'normalized';
0106   else
0107     obj.area.units = 'pixels';
0108   end
0109 end
0110 
0111 % fill various img arguments
0112 
0113 % set colour intensities as we go
0114 remcol = 1;
0115 for i = 1:length(obj.img)
0116   img = obj.img(i);
0117   if ~mars_struct('isthere', img, 'type')
0118     % default is true colour, unless prop is Inf
0119     img.type = 'truecolour';
0120     if mars_struct('isthere', img, 'prop')
0121       if img.prop == Inf
0122     img.type = 'split';
0123     img.prop = 1;
0124       end
0125     end
0126   end
0127   if ~mars_struct('isthere', img, 'hold')
0128     if ~mars_struct('isthere', img.vol, 'imgdata')
0129       % normal file vol struct
0130       img.hold = 1;
0131     else
0132       % 3d matrix vol struct
0133       img.hold = 0;
0134     end
0135   end
0136   if ~mars_struct('isthere', img, 'background')
0137     img.background = NaN;
0138   end
0139   if ~mars_struct('isthere', img, 'prop')
0140     % default is true colour
0141     if strcmpi(img.type, 'truecolour')
0142       img.prop = remcol/(length(obj.img)-i+1);
0143       remcol = remcol - img.prop;
0144     else
0145       img.prop = 1;
0146     end
0147   end
0148   if ~mars_struct('isthere', img, 'range')
0149     [mx mn] = pr_volmaxmin(img.vol);
0150     img.range = [mn mx];
0151   end
0152   if ~mars_struct('isthere', img, 'cmap')
0153     if strcmpi(img.type, 'split')
0154       if obj.range(1)<obj.range(2)
0155     img.cmap = pr_getcmap('hot');
0156       else
0157     img.cmap = pr_getcmap('winter');
0158       end
0159     else                  % true colour
0160       img.cmap = gray;
0161     end
0162   else % check cmap is OK
0163     if ischar(img.cmap)
0164       img.cmap = pr_getcmap(img.cmap);
0165     end
0166   end  
0167   if ~mars_struct('isthere', img, 'outofrange')
0168     % this can be complex, and depends on split/true colour
0169     if strcmpi(img.type, 'split')
0170       if xor(img.range(1) < img.range(2), ...
0171          img.range(2) < 0)
0172     img.outofrange = {[0],size(img.cmap,1)};
0173       else
0174     obj.img(imgno).outofrange={[1], [0]};
0175       end
0176     else            % true colour
0177       img.outofrange = {1,size(img.cmap,1)};
0178     end
0179   end
0180   for j=1:2
0181     if isempty(img.outofrange{j})
0182       img.outofrange(j) = {0};
0183     end
0184   end
0185   if ~mars_struct('isthere', img, 'nancol')
0186     img.nancol = 0;
0187   end
0188   imgs(i) = img;
0189 end
0190 obj.img = imgs;
0191 return
0192

Generated on Wed 06-Jul-2005 18:07:21 by m2html © 2003