Home > functions > common > loadfunc > vb_load_cortex.m

vb_load_cortex

PURPOSE ^

load cortex vertex coordinate from brain file

SYNOPSIS ^

function [Vout,F,xx,inf_C,xxA]= vb_load_cortex(brainfile, coord_type, analyzefile)

DESCRIPTION ^

 load cortex vertex coordinate from brain file

 -- Syntax
 [Vout,F,xx,inf_C,xxA] = vb_load_cortex(brainfile,coord_type,analyzefile)

 -- Input
   brainfile : <required>Brain file name
             :
  coord_type : <optional> <<string>> ID of coordinate. 
             : [not be specified]
             : (default) return V of brainfile as 'Vout'
             : 'SPM_Right_m' [m]
             : 'Analyze_Right_voxel'  [voxel]
             : 'Inflate'              
             : 'Talairach': Talairach coordinate [mm]
             : 'MNI'      : MNI-space coordinate [mm]
             : If coord_type does not match with the all of above IDs,
               it is interpreted as a user-specified ID and searching
               struct variable 'Vall', if any. 
             :
 analyzefile : <conditional required> corresponding to brainfile
             : If the data is old format, or 'Analyze_Right_voxel' or 
             : 'SPM_Right_m' is requested, analyzefile is needed.
               
 --- Output
 Vout  : cortex vertex coordinate [Nvertex, 3]
 F     : Triangle patch index structure
 xx    : Normal vector to cortical surface [Nvertex, 3]
 inf_C : Color corresponding to Gyrus in inflate data [Nvertex, 1]
 xxA   : patch area assigned to each vertex [Nvertex, 1]

 written by M. Sato  2005-8-1
 Modified by Taku Yoshioka 2005-08-22
 2007-03-12 (Sako) added two coord_types ('Talairach' and 'MNI')
 2007-8-6 Masa-aki Sato bug fix for old format
 2008-1-16 Masa-aki Sato 'V' is returned if there is no inflate data 
 2010-11-18 Taku Yoshioka
  User-specified coordinate type supported. 
  Message display changed (vb_disp). 

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Vout,F,xx,inf_C,xxA]= vb_load_cortex(brainfile, coord_type, analyzefile)
0002 % load cortex vertex coordinate from brain file
0003 %
0004 % -- Syntax
0005 % [Vout,F,xx,inf_C,xxA] = vb_load_cortex(brainfile,coord_type,analyzefile)
0006 %
0007 % -- Input
0008 %   brainfile : <required>Brain file name
0009 %             :
0010 %  coord_type : <optional> <<string>> ID of coordinate.
0011 %             : [not be specified]
0012 %             : (default) return V of brainfile as 'Vout'
0013 %             : 'SPM_Right_m' [m]
0014 %             : 'Analyze_Right_voxel'  [voxel]
0015 %             : 'Inflate'
0016 %             : 'Talairach': Talairach coordinate [mm]
0017 %             : 'MNI'      : MNI-space coordinate [mm]
0018 %             : If coord_type does not match with the all of above IDs,
0019 %               it is interpreted as a user-specified ID and searching
0020 %               struct variable 'Vall', if any.
0021 %             :
0022 % analyzefile : <conditional required> corresponding to brainfile
0023 %             : If the data is old format, or 'Analyze_Right_voxel' or
0024 %             : 'SPM_Right_m' is requested, analyzefile is needed.
0025 %
0026 % --- Output
0027 % Vout  : cortex vertex coordinate [Nvertex, 3]
0028 % F     : Triangle patch index structure
0029 % xx    : Normal vector to cortical surface [Nvertex, 3]
0030 % inf_C : Color corresponding to Gyrus in inflate data [Nvertex, 1]
0031 % xxA   : patch area assigned to each vertex [Nvertex, 1]
0032 %
0033 % written by M. Sato  2005-8-1
0034 % Modified by Taku Yoshioka 2005-08-22
0035 % 2007-03-12 (Sako) added two coord_types ('Talairach' and 'MNI')
0036 % 2007-8-6 Masa-aki Sato bug fix for old format
0037 % 2008-1-16 Masa-aki Sato 'V' is returned if there is no inflate data
0038 % 2010-11-18 Taku Yoshioka
0039 %  User-specified coordinate type supported.
0040 %  Message display changed (vb_disp).
0041 %
0042 % Copyright (C) 2011, ATR All Rights Reserved.
0043 % License : New BSD License(see VBMEG_LICENSE.txt)
0044 
0045 inf_C = [];
0046 
0047 % --- check brain file --- %
0048 if ~exist('brainfile', 'var'), brainfile = []; end;
0049 [brain_id] = inner_check_brainfile(brainfile);
0050 
0051 % --- MAIN PROCEDURE --------------------------------------------------------- %
0052 %
0053 
0054 % --- DEFAULT
0055 %
0056 if ~exist('coord_type','var'),
0057   load(brainfile,'V','F','xx','xxA');
0058   Vout = V;
0059   return;
0060 end;
0061 
0062 load(brainfile,'V*','F','xx','xxA');
0063 
0064 switch coord_type
0065   % --- Inflate
0066   %
0067  case  'Inflate'
0068   if exist('Vinflate','var')
0069     Vout = Vinflate;
0070     load(brainfile,'inf_C'); 
0071   else
0072     inflated_brainfile = [brain_id '.inflate.mat'];
0073     if exist(inflated_brainfile, 'file')
0074       load(inflated_brainfile, 'V','inf_C')
0075       Vout = V;
0076     else
0077       Vout = V;
0078       inf_C = ones(size(V,1),1);
0079       vb_disp(['There is no inflate brain data:' brainfile ]);
0080     end;
0081   end;
0082 
0083   % --- SPM_Right_m
0084   %
0085  case  'SPM_Right_m'
0086   if exist('Vinfo','var')
0087     Vout = V;
0088   else
0089     vb_disp('Old SBI brain file ');
0090     [Vdim, Vsize] = analyze_hdr_read(analyzefile);
0091     Vout = vb_vox_to_spm_right(Vox,Vdim,Vsize)*0.001;% mm -> m
0092   end;
0093     
0094   % --- Analyze_Right_voxel
0095   %
0096  case  'Analyze_Right_voxel'
0097   if exist('Vinfo','var')
0098     if exist('Vox','var')
0099       Vout = Vox;
0100     else
0101       [Vdim, Vsize] = analyze_hdr_read(analyzefile);
0102       Vout = vb_spm_right_to_analyze_right(V,Vdim,Vsize);
0103     end;
0104   else
0105     vb_disp('Old SBI brain file ');
0106     [Vdim, Vsize] = analyze_hdr_read(analyzefile);
0107     Vout = vb_vox_to_analyze_right(Vox,Vdim,Vsize);
0108   end;
0109     
0110   % --- Talairach
0111   %
0112  case  'Talairach'
0113   if exist('Vtal', 'var')
0114     Vout = Vtal;
0115   else
0116     xyzfile = [brain_id  '.xyz.mat'];
0117     if exist(xyzfile, 'file')
0118       load(xyzfile, 'XYZtal');
0119       Vout = XYZtal;
0120     else
0121       Vout = [];
0122     end;
0123   end;
0124     
0125   % --- MNI
0126   %
0127  case  'MNI'
0128   if exist('Vmni', 'var')
0129     Vout = Vmni;
0130   else
0131     xyzfile = [brain_id  '.xyz.mat'];
0132     if exist(xyzfile, 'file')
0133       load(xyzfile, 'XYZmm');
0134       Vout = XYZmm;
0135     else
0136       Vout = [];
0137     end;
0138   end;
0139     
0140  otherwise
0141   if ~exist('Vall'), 
0142     error('Unknown coord_type : %s', coord_type);
0143   end;
0144   
0145   Vout = [];
0146   for i=1:length(Vall.key)
0147     if strcmp(Vall.key{i},coord_type), 
0148       Vout = Vall.V{i};
0149       break;
0150     end;
0151   end;
0152   
0153   if isempty(Vout), 
0154     error('Unknown coord_type : %s', coord_type);
0155   end;
0156 end;
0157 
0158 return;
0159 
0160 %
0161 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0162 
0163 % --- INNER FUNCTIONS -------------------------------------------------------- %
0164 %
0165 % --- inner_check_brainfile()
0166 %
0167 function [brain_id] = inner_check_brainfile(brainfile)
0168 
0169 if isempty(brainfile), error('brainfile is a required parameter'); end;
0170 
0171 if ~isempty( findstr(brainfile, '.brain.mat') )
0172     brain_id = brainfile(1:findstr(brainfile, '.brain.mat')-1);
0173 else
0174     error(['Brain file name is not correct:' brainfile]);
0175 end
0176 
0177 if exist(brainfile, 'file') ~= 2
0178   error('cannot read brainfile : %s', brainfile);
0179 end
0180 %
0181 % --- end of inner_check_brainfile()
0182 
0183 %%% END OF FILE %%%

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005