Home > marsbar > @maroi_pointlist > maroi_pointlist.m

maroi_pointlist

PURPOSE ^

maroi_pointlist - class constructor

SYNOPSIS ^

function [o, others] = maroi_pointlist(params, type)

DESCRIPTION ^

 maroi_pointlist - class constructor
 FORMAT [o, others] = maroi_pointlist(params, type)
 Inputs [defaults]
  params  - one of
            structure containing fields XYZ, mat

  type    - one of 'vox', 'real' or 'mm' ['real']
            ('mm' is the same as 'real')
            specifies if XYZ matrix is in real (mm) or voxel space

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [o, others] = maroi_pointlist(params, type)
0002 % maroi_pointlist - class constructor
0003 % FORMAT [o, others] = maroi_pointlist(params, type)
0004 % Inputs [defaults]
0005 %  params  - one of
0006 %            structure containing fields XYZ, mat
0007 %
0008 %  type    - one of 'vox', 'real' or 'mm' ['real']
0009 %            ('mm' is the same as 'real')
0010 %            specifies if XYZ matrix is in real (mm) or voxel space
0011 %
0012 % $Id$
0013   
0014 myclass = 'maroi_pointlist';
0015 defstruct = struct('XYZ', [],...
0016            'mat', eye(4),...
0017          'vals',[],...
0018          'voxblock',[]);
0019 
0020 if nargin < 1
0021   params = [];
0022 end
0023 if nargin < 2
0024   type = 'real';  
0025 end
0026 if isa(params, myclass)
0027   o = params;
0028   return
0029 end
0030 
0031 % fill with defaults
0032 pparams = mars_struct('ffillmerge', defstruct, params);
0033 
0034 % umbrella object, parse out fields for (this object and children)
0035 [uo, pparams] = maroi(pparams);
0036 
0037 % reparse parameters into those for this object, children
0038 [pparams, others] = mars_struct('split', pparams, defstruct);
0039 
0040 % return if no points passed
0041 if isempty(pparams.XYZ)
0042   o = class(pparams, myclass, uo);
0043   return
0044 end
0045 
0046 % reset points vector if wrong size
0047 if size(pparams.XYZ, 1) == 1
0048   pparams.XYZ = pparams.XYZ';
0049 end
0050 
0051 if strcmp(type, 'real') | strcmp(type, 'mm') 
0052   % point list is in real space -> convert
0053   pparams.XYZ = inv(pparams.mat) * ...
0054       [pparams.XYZ; ones(1, size(pparams.XYZ,2))];
0055   pparams.XYZ = pparams.XYZ(1:3,:);
0056 end
0057 
0058 % check that the points are in a sensible voxel space
0059 tiny = 0.001; % tolerance for non-integer voxel values
0060 if any(any((abs(pparams.XYZ - round(pparams.XYZ))) > tiny))
0061   error(['Non integer points in voxel space - ' ...
0062      'are points really of type ''' type '''?']);
0063 end
0064 pparams.XYZ = round(pparams.XYZ);
0065 
0066 % make temporary voxel block for further resampling etc
0067 pparams.voxblock = my_voxblock(pparams.XYZ, pparams.mat, pparams.vals);
0068 
0069 % apply implied thresholding
0070 if ~isempty(pparams.vals)
0071   tmp = find(~isnan(pparams.vals) & ...
0072          abs(pparams.vals) >= roithresh(uo));
0073   pparams.XYZ = pparams.XYZ(:, tmp);
0074   if binarize(uo)
0075     pparams.vals = [];
0076   else
0077     pparams.vals = pparams.vals(tmp);
0078   end
0079 end
0080 
0081 % make object
0082 o = class(pparams, myclass, uo);
0083 return

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