Home > vbmeg > functions > brain > vb_make_flat_data.m

vb_make_flat_data

PURPOSE ^

---

SYNOPSIS ^

function vb_make_flat_data(parm)

DESCRIPTION ^

 ---
 function vb_make_flat_data(parm)

 Incorporate flat map of Brain Voyager. These data are
 associated with the brain surface data (.srf) from which 
 flat map are created. This function needs .brain.mat file,
 created based on the brain surface data, to make correspondence 
 of vertices between the original brain and flat map. 
 Variables 'IndxL' and 'IndxR' in .brain.mat file are used to make
 correspondence, i.e., reduction of vertices from the brain
 surface data to VBMEG brain data (.brain.mat). 

 Input parameters: 
 parm.[dir/file].brain     : VBMEG brain model (.brain.mat)
 parm.dir.bvoy_[left/right]: BV flat map directories
 parm.file.[left/right]_inf: BV flat map files
 parm.[dir/file].inflate   : flat model file. 
 parm.flat_cut_coeff       : (Optional) Remove patche if the
                             maximum length of the side of the 
                             patch is greater than flat_cut_coeff 
                             times the median of maximum length 
                             of all patches. 
 parm.areafile             : (Optional) Area data 'Cortex_flat',
                             which consists of vertices included
                             in patches of flat map, is registered
                             to the area file specified by this
                             parameter. 

 2005-02-15 Taku Yoshioka
 ---

 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:

SOURCE CODE ^

0001 function vb_make_flat_data(parm)
0002 % ---
0003 % function vb_make_flat_data(parm)
0004 %
0005 % Incorporate flat map of Brain Voyager. These data are
0006 % associated with the brain surface data (.srf) from which
0007 % flat map are created. This function needs .brain.mat file,
0008 % created based on the brain surface data, to make correspondence
0009 % of vertices between the original brain and flat map.
0010 % Variables 'IndxL' and 'IndxR' in .brain.mat file are used to make
0011 % correspondence, i.e., reduction of vertices from the brain
0012 % surface data to VBMEG brain data (.brain.mat).
0013 %
0014 % Input parameters:
0015 % parm.[dir/file].brain     : VBMEG brain model (.brain.mat)
0016 % parm.dir.bvoy_[left/right]: BV flat map directories
0017 % parm.file.[left/right]_inf: BV flat map files
0018 % parm.[dir/file].inflate   : flat model file.
0019 % parm.flat_cut_coeff       : (Optional) Remove patche if the
0020 %                             maximum length of the side of the
0021 %                             patch is greater than flat_cut_coeff
0022 %                             times the median of maximum length
0023 %                             of all patches.
0024 % parm.areafile             : (Optional) Area data 'Cortex_flat',
0025 %                             which consists of vertices included
0026 %                             in patches of flat map, is registered
0027 %                             to the area file specified by this
0028 %                             parameter.
0029 %
0030 % 2005-02-15 Taku Yoshioka
0031 % ---
0032 %
0033 % Copyright (C) 2011, ATR All Rights Reserved.
0034 % License : New BSD License(see VBMEG_LICENSE.txt)
0035 
0036 if ~isfield(parm,'flat_cut_coeff')
0037   parm.flat_cut_coeff = 4;
0038 end
0039 
0040 dir   = parm.dir ;
0041 file  = parm.file;
0042 
0043 tic;
0044 fprintf('--- Make Flat model \n');
0045 
0046 %
0047 % --- Brain-Voyager coordinate
0048 %
0049 % V0L/R  X:front(0)->back(255), Y:Top(0)->Bottom(255) , Z:left(0)->right(255)
0050 % FOL/R  triangle patch
0051 
0052 Srf    = vb_ScriptLoadSRF([dir.bvoy_left  file.left_inf]);
0053 
0054 V0L    = [Srf.VertexX, Srf.VertexY, Srf.VertexZ]; 
0055 F0L    = Srf.Triangles+1;
0056 LColor = Srf.MeshColor;
0057 
0058 Srf    = vb_ScriptLoadSRF([dir.bvoy_right  file.right_inf]);
0059 
0060 V0R    = [Srf.VertexX, Srf.VertexY, Srf.VertexZ]; 
0061 F0R    = Srf.Triangles+1;
0062 RColor = Srf.MeshColor;
0063 
0064 %save([dir.brain 'BVinf-' file.brain], ...
0065 %    'V0L','V0R','F0L','F0R','LColor','RColor');
0066 
0067 clear Srf F0L F0R
0068 
0069 %
0070 %         x:右(-)->左(+), y:前(-)->後(+), z:下(-)->上(+)
0071 
0072 %V2L(:,1) = -V0L(:,3);
0073 V2L(:,1) =  V0L(:,1);
0074 V2L(:,2) =  V0L(:,3);
0075 V2L(:,3) = -V0L(:,2);
0076 
0077 %V2R(:,1) = -V0R(:,3);
0078 V2R(:,1) = -V0R(:,1);
0079 V2R(:,2) =  V0R(:,3);
0080 V2R(:,3) = -V0R(:,2);
0081 
0082 V2L = V2L./max(abs([V2L(:); V2R(:)]));
0083 V2R = V2R./max(abs([V2L(:); V2R(:)]));
0084 V2L(:,1) = V2L(:,1)+min(V2L(:,1));
0085 V2R(:,1) = V2R(:,1)-max(V2R(:,1));
0086 V2L(:,1) = V2L(:,1)+0.1*max(abs([V2L(:,1); V2R(:,1)]));
0087 V2R(:,1) = V2R(:,1)-0.1*max(abs([V2L(:,1); V2R(:,1)]));
0088 
0089 %
0090 % --- redeuce patchs
0091 %
0092 %load([dir.brain  file.brain], 'F','IndxL','IndxR','MRI_ID','xxA');
0093 load([dir.brain file.brain],'F','IndxL','IndxR','xxA');
0094 
0095 %if ~strncmp( file.dicom , MRI_ID , 7 ), % compare first 7 character
0096 %  fprintf('!! MRI_ID does not match\n');
0097 %  return;
0098 %end;
0099 
0100 inf_V3L = V2L(IndxL,:);
0101 inf_V3R = V2R(IndxR,:);
0102 inf_LC    = LColor(IndxL,:);
0103 inf_RC    = RColor(IndxR,:);
0104 V    = [inf_V3L ; inf_V3R];   
0105 inf_C    = [inf_LC  ; inf_RC ];
0106 
0107 % Calculate patch size
0108 V1L = V(F.F3L(:,1),:);
0109 V2L = V(F.F3L(:,2),:);
0110 V3L = V(F.F3L(:,3),:);
0111 V1R = V(F.F3R(:,1),:);
0112 V2R = V(F.F3R(:,2),:);
0113 V3R = V(F.F3R(:,3),:);
0114 sL = max([sqrt(sum((V2L-V1L).^2,2)) sqrt(sum((V3L-V2L).^2,2)) ...
0115       sqrt(sum((V1L-V3L).^2,2))],[],2);
0116 sR = max([sqrt(sum((V2R-V1R).^2,2)) sqrt(sum((V3R-V2R).^2,2)) ...
0117       sqrt(sum((V1R-V3R).^2,2))],[],2);
0118 %sL = abs(0.5*(sum((V2L-V1L).*(V3L-V1L),2)));
0119 %sR = abs(0.5*(sum((V2R-V1R).*(V3R-V1R),2)));
0120 
0121 % Remove large patch
0122 ixL = find(sL < parm.flat_cut_coeff * median([sL; sR]));
0123 ixR = find(sR < parm.flat_cut_coeff * median([sL; sR]));
0124 
0125 %ixLv = find(inf_LC<0);
0126 %ixRv = find(inf_RC<0)+length(inf_LC);
0127 %ixL = find(ismember(F.F3L(:,1),ixLv) | ismember(F.F3L(:,2),ixLv) ...
0128 %       | ismember(F.F3L(:,3),ixLv));
0129 %ixR = find(ismember(F.F3R(:,1),ixRv) | ismember(F.F3R(:,2),ixRv) ...
0130 %       | ismember(F.F3R(:,3),ixRv));
0131 %ixL = setxor(1:size(F.F3L,1),ixL);
0132 %ixR = setxor(1:size(F.F3R,1),ixR);
0133 
0134 F.F3L = F.F3L(ixL,:);
0135 F.F3R = F.F3R(ixR,:);
0136 F.F3 = [F.F3L; F.F3R];
0137 
0138 %
0139 % --- save the brain model
0140 %
0141 
0142 % 拡張子 '.mat' を取り除く
0143 if ~isempty( findstr(file.brain, '.mat') )
0144   BRAINfile = file.brain(1:findstr(file.brain, '.mat')-1);
0145 else
0146   BRAINfile = file.brain;
0147 end
0148 
0149 fprintf(['--- Save flat model (' file.inflate ')\n']);
0150 vb_fsave([dir.inflate file.inflate],'F','V','inf_C','xxA');
0151 
0152 % Register area file
0153 if isfield(parm,'areafile'), 
0154   area_new.Iextract = unique(F.F3(:));
0155   area_new.key = 'Cortex_flat';
0156   vb_add_area(parm.areafile,area_new);
0157 end
0158

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