Home > marsbar > @marsy > xyz.m

xyz

PURPOSE ^

gets XYZ coordinates for region

SYNOPSIS ^

function [XYZ, M]= xyz(o, r_no, xyz_type)

DESCRIPTION ^

 gets XYZ coordinates for region 
 FORMAT [XYZ M]= xyz(o, r_no, xyz_type)
 
 Inputs
 o         - marsy object
 r_no      - region number
 xyz_type  - string, one of 'mm','real','vox' 
             where 'real' is a synonym for 'mm'
             and 'mm' is the default (if not passed)
             'mm' results in coordinates in mm
             'vox' gives coordinates in voxels
 
 Outputs
 XYZ       - coordinates in specified reference
 M         - 4x4 transformation mapping voxels to mm
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [XYZ, M]= xyz(o, r_no, xyz_type)
0002 % gets XYZ coordinates for region
0003 % FORMAT [XYZ M]= xyz(o, r_no, xyz_type)
0004 %
0005 % Inputs
0006 % o         - marsy object
0007 % r_no      - region number
0008 % xyz_type  - string, one of 'mm','real','vox'
0009 %             where 'real' is a synonym for 'mm'
0010 %             and 'mm' is the default (if not passed)
0011 %             'mm' results in coordinates in mm
0012 %             'vox' gives coordinates in voxels
0013 %
0014 % Outputs
0015 % XYZ       - coordinates in specified reference
0016 % M         - 4x4 transformation mapping voxels to mm
0017 %
0018 % $Id$
0019 
0020 r = n_regions(o);
0021 if nargin < 2
0022   error('Need region number to get XYZ coordinates')
0023 end
0024 if r_no > r
0025   error('Region number too large');
0026 end
0027 if nargin < 3
0028   xyz_type = 'mm';
0029 end
0030 
0031 XYZ = [];
0032 M = eye(4);
0033 st = y_struct(o);
0034 if ~isfield(st, 'regions')
0035   return
0036 end
0037 r_st = st.regions{r_no};
0038 if ~isfield(r_st, 'vXYZ') |  ~isfield(r_st, 'mat')
0039   return
0040 end
0041 XYZ = r_st.vXYZ;
0042 if isempty(XYZ), return, end
0043 switch xyz_type
0044  case 'vox'
0045  case {'mm', 'real'}
0046   [m n] = size(XYZ);
0047   if m == 3, XYZ = [XYZ; ones(1, n)]; end
0048   M = r_st.mat;
0049   XYZ = M * XYZ;
0050  otherwise
0051   error(['Unknown coordinate type: ' xyz_type]);
0052 end
0053 XYZ = XYZ(1:3,:);

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