File size: 6,000 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
function this = subsasgn(this, subs, A)
% Subscript assignment for GIfTI objects
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Guillaume Flandin
% $Id: subsasgn.m 6513 2015-08-05 17:52:13Z guillaume $
switch subs(1).type
case '.'
if ~ismember(subs(1).subs, ...
{'vertices' 'faces' 'normals' 'cdata','mat','indices','private'})
error('Reference to non-existent field ''%s''.',subs(1).subs);
end
% TODO % handle cases when length(subs) > 1
[i,n] = isintent(this,subs(1).subs);
if isempty(i) && ~strcmp(subs(1).subs,'private')
n = length(this.data) + 1;
if n==1, this.data = {}; end
% TODO % Initialise data field appropriately
this.data{n}.metadata = struct([]);
this.data{n}.space = [];
this.data{n}.attributes.Dim = size(A);
% TODO % set DataType according to intent type
this.data{n}.data = [];
switch subs(1).subs
case {'vertices','mat'}
in = 'NIFTI_INTENT_POINTSET';
dt = 'NIFTI_TYPE_FLOAT32';
this.data{n}.space.DataSpace = 'NIFTI_XFORM_UNKNOWN';
this.data{n}.space.TransformedSpace = 'NIFTI_XFORM_UNKNOWN';
this.data{n}.space.MatrixData = eye(4);
case 'faces'
in = 'NIFTI_INTENT_TRIANGLE';
dt = 'NIFTI_TYPE_INT32';
case 'indices'
in = 'NIFTI_INTENT_NODE_INDEX';
dt = 'NIFTI_TYPE_INT32';
case 'normals'
in = 'NIFTI_INTENT_VECTOR';
dt = 'NIFTI_TYPE_FLOAT32';
case 'cdata'
in = 'NIFTI_INTENT_NONE';
dt = 'NIFTI_TYPE_FLOAT32';
otherwise
error('This should not happen.');
end
this.data{n}.attributes.Intent = in;
this.data{n}.attributes.DataType = dt;
end
switch subs(1).subs
%- .private
%--------------------------------------------------------------
case 'private'
this = builtin('subsasgn',this,subs(2:end),A);
% .mat
%--------------------------------------------------------------
case 'mat'
if length(subs) > 1
this.data{n}.space(1).MatrixData = builtin('subsasgn',...
this.data{n}.space(1).MatrixData,subs(2:end),A);
else
if ~isequal(size(A),[4 4])
error('Invalid Coordinate System Transform Matrix.');
end
this.data{n}.space(1).MatrixData = A;
end
%- .faces
%--------------------------------------------------------------
case 'faces'
if length(subs) > 1
this.data{n}.data = int32(builtin('subsasgn',this.data{n}.data,subs(2:end),A-1));
else
this.data{n}.data = int32(A - 1);
this.data{n}.attributes.Dim = size(A);
end
%- .indices
%--------------------------------------------------------------
case 'indices'
if n ~= 1
this.data = this.data([n setdiff(1:numel(this.data),n)]);
n = 1;
end
if length(subs) > 1
this.data{n}.data = int32(builtin('subsasgn',this.data{n}.data,subs(2:end),A-1));
else
A = A(:);
this.data{n}.data = int32(A - 1);
this.data{n}.attributes.Dim = size(A);
end
%- .vertices, .normals, .cdata
%--------------------------------------------------------------
otherwise
if length(subs) > 1
if numel(n) == 1
this.data{n}.data = single(builtin('subsasgn',this.data{n}.data,subs(2:end),A));
this.data{n}.attributes.Dim = size(this.data{n}.data);
else
if numel(subs(2).subs) == 1
error('Linear indexing not supported: use multiple subscripts.');
end
idx = subs(2).subs{2};
if isequal(idx,':'), idx = 1:numel(this.data); end
for k=1:numel(idx)
s = subs(2);
s.subs{2} = 1;
if numel(A) == 1
this.data{idx(k)}.data = single(builtin('subsasgn',this.data{idx(k)}.data,s,A));
else
this.data{idx(k)}.data = single(builtin('subsasgn',this.data{idx(k)}.data,s,A(:,k)));
end
this.data{idx(k)}.attributes.Dim = size(this.data{idx(k)}.data);
end
end
else
if numel(n) == 1
if isa(A,'file_array')
this.data{n}.data = A;
this.data{n}.attributes.Dim = A.dim;
else
this.data{n}.data = single(A);
this.data{n}.attributes.Dim = size(A);
end
else
error('Syntax not implemented.');
end
end
end
case '()'
case '{}'
otherwise
error('This should not happen.');
end
|