Skip to content

Commit

Permalink
SPM8 r4010
Browse files Browse the repository at this point in the history
  • Loading branch information
SPMcentral committed Jul 21, 2010
1 parent 9d20829 commit d0afb4b
Show file tree
Hide file tree
Showing 2,401 changed files with 152,066 additions and 140,640 deletions.
3 changes: 2 additions & 1 deletion @file_array/size.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

%
% $Id: size.m 1143 2008-02-07 19:33:33Z spm $
% $Id: size.m 3730 2010-02-17 13:24:26Z john $


sa = struct(a);
nd = 0;
for i=1:numel(sa),
nd = max(nd,numel(sa(i).dim));
nd = max(nd,max(find(sa(i).pos==1)));
end
nd = nd+1;

Expand Down
8 changes: 6 additions & 2 deletions @file_array/subsref.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

%
% $Id: subsref.m 3418 2009-09-25 11:06:39Z guillaume $
% $Id: subsref.m 3958 2010-06-30 16:24:46Z guillaume $


if isempty(subs), return; end
Expand Down Expand Up @@ -156,7 +156,11 @@
dt = datatypes;
dt = dt([dt.code]==sobj.dtype);
sz = dt.size;
mem = 400*1024*1024; % in bytes, has to be a multiple of 16 (max([dt.size]))
try
mem = spm('Memory'); % in bytes, has to be a multiple of 16 (max([dt.size]))
catch
mem = 200 * 1024 * 1024;
end
s = ceil(prod(sobj.dim) * sz / mem);

% Assign indices to partitions
Expand Down
10 changes: 9 additions & 1 deletion @gifti/gifti.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: gifti.m 2587 2009-01-05 12:11:39Z vladimir $
% $Id: gifti.m 3999 2010-07-19 10:54:18Z guillaume $

switch nargin

Expand Down Expand Up @@ -38,6 +38,14 @@
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,...
Expand Down
8 changes: 4 additions & 4 deletions @gifti/private/isintent.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: isintent.m 3556 2009-11-11 18:20:34Z guillaume $
% $Id: isintent.m 3999 2010-07-19 10:54:18Z guillaume $

a = [];
b = [];
Expand Down Expand Up @@ -51,11 +51,11 @@
fprintf('Intent %s is ignored.\n',this.data{i}.attributes.Intent);
end
end
[d,i] = unique(a);
[d,i] = unique(a,'first');
if length(d) < length(a)
warning('Several fields match intent type. Using first.');
%warning('Several fields match intent type. Using first.');
a = a(i);
b = b(i);
%b = b(i);
end

function c = cdata
Expand Down
6 changes: 3 additions & 3 deletions @gifti/private/read_gifti_file.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: read_gifti_file.m 2076 2008-09-10 12:34:08Z guillaume $
% $Id: read_gifti_file.m 3999 2010-07-19 10:54:18Z guillaume $

% Import XML-based GIfTI file
%--------------------------------------------------------------------------
Expand All @@ -23,8 +23,8 @@
error('[GIFTI] %s is not a GIFTI 1.0 file.', filename);
end
attr = cell2mat(attributes(t,'get',root(t)));
attr = cell2struct({attr.val},{attr.key},2);
if ~isempty(setxor(fieldnames(attr),{'Version','NumberOfDataArrays'}))
attr = cell2struct({attr.val},strrep({attr.key},':','_'),2);
if ~all(ismember({'Version','NumberOfDataArrays'},fieldnames(attr)))
error('[GIFTI] Missing mandatory attributes for GIFTI root element.');
end
if str2double(attr.Version) ~= 1
Expand Down
160 changes: 155 additions & 5 deletions @gifti/save.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function save(this,filename,encoding)
% filename - name of GIfTI file that will be created
% encoding - optional argument to specify encoding format, among
% ASCII, Base64Binary, GZipBase64Binary, ExternalFileBinary,
% Collada (.dae)
% Collada (.dae), IDTF (.idtf).
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: save.m 3556 2009-11-11 18:20:34Z guillaume $
% $Id: save.m 3999 2010-07-19 10:54:18Z guillaume $

error(nargchk(1,3,nargin));

Expand All @@ -23,6 +23,9 @@ function save(this,filename,encoding)
if nargin == 3 && strcmpi(encoding,'collada')
ext = '.dae';
end
if nargin == 3 && strcmpi(encoding,'idtf')
ext = '.idtf';
end
[p,f,e] = fileparts(filename);
if ~ismember(lower(e),{ext})
e = ext;
Expand All @@ -45,6 +48,8 @@ function save(this,filename,encoding)
fid = save_gii(fid,this,encoding);
case '.dae'
fid = save_dae(fid,this);
case '.idtf'
fid = save_idtf(fid,this);
otherwise
error('Unknown file format.');
end
Expand Down Expand Up @@ -105,12 +110,12 @@ function save(this,filename,encoding)
case {'ASCII', 'Base64Binary','GZipBase64Binary' }
case 'ExternalFileBinary'
extfilename = this.data{i}.attributes.ExternalFileName;
[p,f] = fileparts(filename);
if isempty(extfilename)
[p,f] = fileparts(fopen(fid));
extfilename = [f '.dat'];
end
[p,f,e] = fileparts(extfilename);
this.data{i}.attributes.ExternalFileName = fullfile(fileparts(filename),[f e]);
this.data{i}.attributes.ExternalFileName = fullfile(fileparts(fopen(fid)),[f e]);
this.data{i}.attributes.ExternalFileOffset = num2str(def.offset);
otherwise
error('[GIFTI] Unknown data encoding: %s.',this.data{i}.attributes.Encoding);
Expand All @@ -123,7 +128,7 @@ function save(this,filename,encoding)
fprintf(fid,'<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">\n');
fprintf(fid,'<GIFTI Version="1.0" NumberOfDataArrays="%d">\n',numel(this.data));

o = inline('blanks(x*3)');
o = @(x) blanks(x*3);

% MetaData
%--------------------------------------------------------------------------
Expand Down Expand Up @@ -379,3 +384,148 @@ function save(this,filename,encoding)
% End of XML
%--------------------------------------------------------------------------
fprintf(fid,'</COLLADA>\n');

%==========================================================================
% function fid = save_idtf(fid,this)
%==========================================================================
function fid = save_idtf(fid,this)

o = inline('blanks(x*3)');

s = struct(this);

% Compute normals
%--------------------------------------------------------------------------
if ~isfield(s,'normals')
try
s.normals = spm_mesh_normals(...
struct('vertices',s.vertices,'faces',s.faces),true);
catch
s.normals = [];
end
end

% Split the mesh into connected components
%--------------------------------------------------------------------------
try
C = spm_mesh_label(s.faces);
d = [];
try
if size(s.cdata,2) == 1 && (any(s.cdata>1) || any(s.cdata<0))
mi = min(s.cdata); ma = max(s.cdata);
s.cdata = (s.cdata-mi)/ (ma-mi);
else
end
end
for i=1:numel(unique(C))
d(i).faces = s.faces(C==i,:);
u = unique(d(i).faces);
d(i).vertices = s.vertices(u,:);
d(i).normals = s.normals(u,:);
a = 1:max(d(i).faces(:));
a(u) = 1:size(d(i).vertices,1);
%a = sparse(1,double(u),1:1:size(d(i).vertices,1));
d(i).faces = a(d(i).faces);
d(i).mat = s.mat;
try
d(i).cdata = s.cdata(u,:);
if size(d(i).cdata,2) == 1
d(i).cdata = repmat(d(i).cdata,1,3);
end
end
end
s = d;
end

% FILE_HEADER
%--------------------------------------------------------------------------
fprintf(fid,'FILE_FORMAT "IDTF"\n');
fprintf(fid,'FORMAT_VERSION 100\n\n');

% NODES
%--------------------------------------------------------------------------
for i=1:numel(s)
fprintf(fid,'NODE "MODEL" {\n');
fprintf(fid,'%sNODE_NAME "%s"\n',o(1),sprintf('Mesh%04d',i));
fprintf(fid,'%sPARENT_LIST {\n',o(1));
fprintf(fid,'%sPARENT_COUNT %d\n',o(2),1);
fprintf(fid,'%sPARENT %d {\n',o(2),0);
fprintf(fid,'%sPARENT_NAME "%s"\n',o(3),'<NULL>');
fprintf(fid,'%sPARENT_TM {\n',o(3));
I = s(i).mat; % eye(4);
for j=1:size(I,2)
fprintf(fid,'%s',o(4)); fprintf(fid,'%f ',I(:,j)'); fprintf(fid,'\n');
end
fprintf(fid,'%s}\n',o(3));
fprintf(fid,'%s}\n',o(2));
fprintf(fid,'%s}\n',o(1));
fprintf(fid,'%sRESOURCE_NAME "%s"\n',o(1),sprintf('Mesh%04d',i));
%fprintf(fid,'%sMODEL_VISIBILITY "BOTH"\n',o(1));
fprintf(fid,'}\n\n');
end

% NODE_RESOURCES
%--------------------------------------------------------------------------
for i=1:numel(s)
fprintf(fid,'RESOURCE_LIST "MODEL" {\n');
fprintf(fid,'%sRESOURCE_COUNT %d\n',o(1),1);
fprintf(fid,'%sRESOURCE %d {\n',o(1),0);
fprintf(fid,'%sRESOURCE_NAME "%s"\n',o(2),sprintf('Mesh%04d',i));
fprintf(fid,'%sMODEL_TYPE "MESH"\n',o(2));
fprintf(fid,'%sMESH {\n',o(2));
fprintf(fid,'%sFACE_COUNT %d\n',o(3),size(s(i).faces,1));
fprintf(fid,'%sMODEL_POSITION_COUNT %d\n',o(3),size(s(i).vertices,1));
fprintf(fid,'%sMODEL_NORMAL_COUNT %d\n',o(3),size(s(i).normals,1));
if ~isfield(s(i),'cdata') || isempty(s(i).cdata)
c = 0;
else
c = size(s(i).cdata,1);
end
fprintf(fid,'%sMODEL_DIFFUSE_COLOR_COUNT %d\n',o(3),c);
fprintf(fid,'%sMODEL_SPECULAR_COLOR_COUNT %d\n',o(3),0);
fprintf(fid,'%sMODEL_TEXTURE_COORD_COUNT %d\n',o(3),0);
fprintf(fid,'%sMODEL_BONE_COUNT %d\n',o(3),0);
fprintf(fid,'%sMODEL_SHADING_COUNT %d\n',o(3),1);
fprintf(fid,'%sMODEL_SHADING_DESCRIPTION_LIST {\n',o(3));
fprintf(fid,'%sSHADING_DESCRIPTION %d {\n',o(4),0);
fprintf(fid,'%sTEXTURE_LAYER_COUNT %d\n',o(5),0);
fprintf(fid,'%sSHADER_ID %d\n',o(5),0);
fprintf(fid,'%s}\n',o(4));
fprintf(fid,'%s}\n',o(3));

fprintf(fid,'%sMESH_FACE_POSITION_LIST {\n',o(3));
fprintf(fid,'%d %d %d\n',s(i).faces'-1);
fprintf(fid,'%s}\n',o(3));

fprintf(fid,'%sMESH_FACE_NORMAL_LIST {\n',o(3));
fprintf(fid,'%d %d %d\n',s(i).faces'-1);
fprintf(fid,'%s}\n',o(3));

fprintf(fid,'%sMESH_FACE_SHADING_LIST {\n',o(3));
fprintf(fid,'%d\n',zeros(size(s(i).faces,1),1));
fprintf(fid,'%s}\n',o(3));

if c
fprintf(fid,'%sMESH_FACE_DIFFUSE_COLOR_LIST {\n',o(3));
fprintf(fid,'%d %d %d\n',s(i).faces'-1);
fprintf(fid,'%s}\n',o(3));
end

fprintf(fid,'%sMODEL_POSITION_LIST {\n',o(3));
fprintf(fid,'%f %f %f\n',s(i).vertices');
fprintf(fid,'%s}\n',o(3));

fprintf(fid,'%sMODEL_NORMAL_LIST {\n',o(3));
fprintf(fid,'%f %f %f\n',s(i).normals');
fprintf(fid,'%s}\n',o(3));

if c
fprintf(fid,'%sMODEL_DIFFUSE_COLOR_LIST {\n',o(3));
fprintf(fid,'%f %f %f\n',s(i).cdata');
fprintf(fid,'%s}\n',o(3));
end

fprintf(fid,'%s}\n',o(2));
fprintf(fid,'%s}\n',o(1));
fprintf(fid,'}\n');
end
8 changes: 5 additions & 3 deletions @gifti/subsasgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: subsasgn.m 3556 2009-11-11 18:20:34Z guillaume $
% $Id: subsasgn.m 3999 2010-07-19 10:54:18Z guillaume $

switch subs(1).type
case '.'
if ~ismember(subs(1).subs, {'vertices' 'faces' 'normals' 'cdata','mat'})
if ~ismember(subs(1).subs, {'vertices' 'faces' 'normals' 'cdata','mat','private'})
error('Reference to non-existent field ''%s''.',subs(1).subs);
else
% TODO % handle cases when length(subs) > 1
[i,n] = isintent(this,subs(1).subs);
if isempty(i)
if isempty(i) && ~strcmp(subs(1).subs,'private')
n = length(this.data) + 1;
% TODO % Initialise data field appropriately
this.data{n}.metadata = struct([]);
Expand Down Expand Up @@ -54,6 +54,8 @@
this.data{n}.space(1).MatrixData = A;
end
end
elseif strcmp(subs(1).subs,'private')
this = builtin('subsasgn',this,subs(2:end),A);
else
if strcmp(subs(1).subs,'faces')
if length(subs) > 1
Expand Down
13 changes: 11 additions & 2 deletions @gifti/subsref.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: subsref.m 2076 2008-09-10 12:34:08Z guillaume $
% $Id: subsref.m 3999 2010-07-19 10:54:18Z guillaume $

if length(this) > 1
warning('Not implemented.');
Expand All @@ -26,7 +26,16 @@
if strcmp(subs(1).subs,'mat')
varargout{1} = this.data{j}.space.MatrixData;
else
varargout{1} = this.data{j}.data;
if length(j) == 1
varargout{1} = this.data{j}.data;
else
a = [this.data{j}];
try
varargout{1} = [a.data];
catch
error('Data arrays are of different sizes.');
end
end
end
end
if strcmp(subs(1).subs,'faces')
Expand Down
Loading

0 comments on commit d0afb4b

Please sign in to comment.