Home > vbmeg > functions > tool_box > dmri_processor > functions > util > dmri_parcel_view.m

dmri_parcel_view

PURPOSE ^

Launch parcellation viewer.

SYNOPSIS ^

function dmri_parcel_view(freesurfer_dir, parcel_dir, hemi)

DESCRIPTION ^

 Launch parcellation viewer.

 [Usage]
    dmri_parcel_view(freesurfer_dir, parcel_dir, hemi);

 [Input]
    freesurfer_dir : freesurfer directory.
        parcel_dir : parcel directory.
              hemi : 'l' or 'r'
                    = 'l' : left hemisphere. [default]
                    = 'r' : right hemisphere.

 [Output]
    none

 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 dmri_parcel_view(freesurfer_dir, parcel_dir, hemi)
0002 % Launch parcellation viewer.
0003 %
0004 % [Usage]
0005 %    dmri_parcel_view(freesurfer_dir, parcel_dir, hemi);
0006 %
0007 % [Input]
0008 %    freesurfer_dir : freesurfer directory.
0009 %        parcel_dir : parcel directory.
0010 %              hemi : 'l' or 'r'
0011 %                    = 'l' : left hemisphere. [default]
0012 %                    = 'r' : right hemisphere.
0013 %
0014 % [Output]
0015 %    none
0016 %
0017 % Copyright (C) 2011, ATR All Rights Reserved.
0018 % License : New BSD License(see VBMEG_LICENSE.txt)
0019 
0020 %
0021 % --- Previous check
0022 %
0023 if nargin < 2
0024     error('Please check input arguments.');
0025 end
0026 if exist(freesurfer_dir, 'dir') ~= 7
0027     error('Specified freesurfer_dir not found.');
0028 end
0029 if exist(parcel_dir, 'dir') ~= 7
0030     error('Specified parcel_dir not found.');
0031 end
0032 
0033 if ~exist('hemi', 'var')
0034     hemi = 'l';
0035 end
0036 
0037 %
0038 % --- Main Procedure
0039 %
0040 disp('Reading Left/Right parcellation area...');
0041 % Create color table file of parcels for left/right hemisphere.
0042 [lh_clut_file, rh_clut_file, Nlabel_l, Nlabel_r] = ...
0043     dmri_color_table_create_for_parcels(parcel_dir, parcel_dir);
0044 
0045 % Create annot file
0046 [FS_SUBJECTS_ROOT, SUBJ] = fileparts(vb_rm_trailing_slash(freesurfer_dir));
0047 
0048 switch(hemi)
0049     case 'l'
0050         clut_file = lh_clut_file;
0051         hemi      = 'lh';
0052         angle     = [-90 0];
0053         script_file = fullfile(parcel_dir, filesep, 'view_left_parcel.sh');
0054     case 'r'
0055         clut_file = rh_clut_file;
0056         hemi      = 'rh';
0057         angle     = [90, 0];
0058         script_file = fullfile(parcel_dir, filesep, 'view_right_parcel.sh');
0059     otherwise
0060         error('Unknown hemisphere type was specified. Please specify ''l'' or ''r''.');
0061 end
0062 
0063 label_dir      = fullfile(parcel_dir, filesep, 'parcels_label');
0064 tmp_label_dir  = tempname(label_dir);
0065 
0066 % Create symbolic link
0067 if exist('/usr/bin/rename.ul', 'file')
0068     rename = 'rename.ul'; % Ubuntu Debian
0069 else
0070     rename = 'rename';    % other distribution
0071 end
0072 
0073 
0074 cmd0_1 = ['ln -s ', label_dir, '/*.label', ...
0075         ' ', tmp_label_dir];
0076 cmd0_2 = [rename ' parcel lh.parcel parcel{1..' num2str(Nlabel_l), '}.label'];
0077 cmd0_3 = [rename ' parcel rh.parcel parcel{' num2str(Nlabel_l+1), '..', num2str(Nlabel_l+Nlabel_r) '}.label'];
0078 
0079 cmd1 = ['mris_label2annot', ...
0080        ' --ctab ', clut_file, ...
0081        ' --ldir ', tmp_label_dir, ...
0082        ' --s ', SUBJ, ...
0083        ' --a parcel2000', ...
0084        ' --h ', hemi, ...
0085        ' --no-unknown'];
0086 
0087 dmri_script_file_create(script_file);
0088 fid = fopen(script_file, 'a');
0089 if fid == -1
0090     error('Cannot create view_parcel script file.');
0091 end
0092 fprintf(fid, '\n%s\n', ['SUBJECTS_DIR=' FS_SUBJECTS_ROOT]);
0093 fprintf(fid, '\n## PREPROCESS\n');
0094 fprintf(fid, '# Create symbolic link to label files\n');
0095 fprintf(fid, '%s\n', ['mkdir ', tmp_label_dir]);
0096 fprintf(fid, '%s\n', cmd0_1);
0097 fprintf(fid, '\n## Add prefix lh/rh to parcelN.label\n');
0098 fprintf(fid, '%s\n', ['cd ', tmp_label_dir]);
0099 fprintf(fid, '%s\n', cmd0_2);
0100 fprintf(fid, '%s\n', cmd0_3);
0101 
0102 fprintf(fid, '\n## Create annotation file\n');
0103 fprintf(fid, 'rm -rf %s\n', fullfile(freesurfer_dir, filesep, 'label/lh.parcel2000.annot'));
0104 fprintf(fid, 'rm -rf %s\n', fullfile(freesurfer_dir, filesep, 'label/rh.parcel2000.annot'));
0105 fprintf(fid, '%s\n', cmd1);
0106 fprintf(fid, '%s\n', ['rm -rf ', tmp_label_dir]);
0107 fclose(fid);
0108 
0109 
0110 %
0111 % --- Create annotation file and confirm display
0112 %
0113 [status, msg] = system(script_file);
0114 if status ~= 0
0115     error(msg);
0116 end
0117 
0118 % Load inflate data
0119 h = figure;
0120 inflated_file = fullfile(freesurfer_dir, 'surf',  [hemi, '.inflated']);
0121 aparc_file    = fullfile(freesurfer_dir, 'label', [hemi, '.parcel2000.annot']);
0122 
0123 [V, F]     = read_surf(inflated_file);
0124 [tmp, col] = read_annotation(aparc_file);
0125 
0126 msh.vertices = V;
0127 msh.faces    = F + 1; % MATLAB patch requires 1 start
0128 msh.FaceVertexCdata = fscolor2rgb(col);
0129 
0130 p = patch(msh);
0131 set(p,'FaceColor','flat','EdgeColor','none');
0132 set(h, 'Color', 'k');
0133 set(gca, 'Color', 'k');
0134 
0135 view(angle);
0136 axis tight;
0137 axis equal;
0138 rotate3d;

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