Home > marsbar > @mars_space > mars_space.m

mars_space

PURPOSE ^

mars_space - class constructor for space defining object

SYNOPSIS ^

function [o, others] = mars_space(params, params2)

DESCRIPTION ^

 mars_space - class constructor for space defining object
 FORMAT [o, others] = mars_space(params, params2)
 Inputs [defaults]
 params  - either 
           a structure, containing fields to construct the object
           an spm vol struct (see spm_vol)
           a string, giving and image name (see spm_vol)
           a matrix (for which, only the dimensions are used)
           a 3x1 or 1x3 dimension vector
 params2   in the latter 2 cases, might contain a 4x4 transformation matrix
           [eye(4)]

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [o, others] = mars_space(params, params2)
0002 % mars_space - class constructor for space defining object
0003 % FORMAT [o, others] = mars_space(params, params2)
0004 % Inputs [defaults]
0005 % params  - either
0006 %           a structure, containing fields to construct the object
0007 %           an spm vol struct (see spm_vol)
0008 %           a string, giving and image name (see spm_vol)
0009 %           a matrix (for which, only the dimensions are used)
0010 %           a 3x1 or 1x3 dimension vector
0011 % params2   in the latter 2 cases, might contain a 4x4 transformation matrix
0012 %           [eye(4)]
0013 %
0014 % $Id$
0015   
0016 myclass = 'mars_space';
0017 defstruct = struct('dim', [1 1 1],...
0018            'mat', eye(4));
0019 
0020 if nargin < 1
0021   params = [];
0022 end
0023 if nargin < 2
0024   params2 = [];
0025 end
0026 if isa(params, myclass)
0027   o = params;
0028   return
0029 end
0030 
0031 % check inputs
0032 if ~isstruct(params)
0033   % Matlab 7 does not like assigment of struct to non empty var
0034   inp1 = params;
0035   clear params;
0036   if ischar(inp1) % maybe it is an image filename
0037     params = spm_vol(inp1);
0038     params.dim = params.dim(1:3);
0039   elseif prod(size(inp1)) == 3 
0040     % could be the dimensions of a space
0041     params.dim = inp1(:)';
0042     if ~isempty(params2), params.mat = params2; end
0043   else                               
0044     % lets hope it's a useful matrix, but with a mat parameter, quoi
0045     if isempty(params2)
0046       error(['Need to pass a ''mat'' definition with a'...
0047          ' matrix'])
0048     end
0049     params.mat = params2;
0050     m = inp1;
0051     sz = size(m);
0052     params.dim = [1 1 1];
0053     params.dim(1:length(sz)) = sz;
0054   end
0055 end
0056 
0057 % fill with defaults, parse into fields for this object, children
0058 [pparams, others] = mars_struct('ffillsplit', defstruct, params);
0059 
0060 o  = class(pparams, myclass);
0061 return

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