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

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005