File size: 3,807 Bytes
0b58803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function this = gifti(varargin)
% GIfTI Geometry file format class
% Geometry format under the Neuroimaging Informatics Technology Initiative
% (NIfTI):
%                 http://www.nitrc.org/projects/gifti/
%                      http://nifti.nimh.nih.gov/
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: gifti.m 6347 2015-02-24 17:59:16Z guillaume $

switch nargin
    
    case 0
        this = giftistruct;
        this = class(this,'gifti');
        
    case 1
        if isa(varargin{1},'gifti')
            this = varargin{1};
            
        elseif isstruct(varargin{1})
            f       = {'faces', 'face', 'tri' 'vertices', 'vert', 'pnt', 'cdata', 'indices'};
            ff      = {'faces', 'faces', 'faces', 'vertices', 'vertices', 'vertices', 'cdata', 'indices'};
            [c, ia] = intersect(f,fieldnames(varargin{1}));
            if ~isempty(c)
                this = gifti;
                for i=1:length(c)
                    this = subsasgn(this,...
                        struct('type','.','subs',ff{ia(i)}),...
                        varargin{1}.(c{i}));
                end
            elseif isempty(setxor(fieldnames(varargin{1}),...
                    {'metadata','label','data'}))
                this = class(varargin{1},'gifti');
            else
                error('[GIFTI] Invalid structure.');
            end
            
        elseif ishandle(varargin{1})
            this = struct('vertices',get(varargin{1},'Vertices'), ...
                          'faces',   get(varargin{1},'Faces'));
            if ~isempty(get(varargin{1},'FaceVertexCData'));
                  this.cdata = get(varargin{1},'FaceVertexCData');
            end
            this = gifti(this);
            
        elseif isnumeric(varargin{1})
            this = gifti;
            this = subsasgn(this,...
                struct('type','.','subs','cdata'),...
                varargin{1});
            
        elseif ischar(varargin{1})
            if size(varargin{1},1)>1
                this = gifti(cellstr(varargin{1}));
                return;
            end
            [p,n,e] = fileparts(varargin{1});
            if strcmpi(e,'.mat')
                try
                    this = gifti(load(varargin{1}));
                catch
                    error('[GIFTI] Loading of file %s failed.', varargin{1});
                end
            elseif strcmpi(e,'.asc') || strcmpi(e,'.srf')
                this = read_freesurfer_file(varargin{1});
                this = gifti(this);
            else
                this = read_gifti_file_standalone(varargin{1},giftistruct);
                this = class(this,'gifti');
            end
            
        elseif iscellstr(varargin{1})
            fnames = varargin{1};
            this(numel(fnames)) = giftistruct;
            this = class(this,'gifti');
            for i=1:numel(fnames)
                this(i) = gifti(fnames{i});
            end
            
        else
            error('[GIFTI] Invalid object construction.');
        end
        
    otherwise
        error('[GIFTI] Invalid object construction.');
end

%==========================================================================
function s = giftistruct
s = struct(...
    'metadata', ...
        struct(...
            'name',       {}, ...
            'value',      {} ...
        ), ...
    'label', ...
        struct(...
            'name',       {}, ...
            'index',      {} ...
        ), ...
    'data', ...
        struct(...
            'attributes', {}, ...
            'metadata',   struct('name',{}, 'value',{}), ...
            'space',      {}, ...
            'data',       {} ...
        ) ...
    );