Skip to content

Commit

Permalink
SPM12 r6685
Browse files Browse the repository at this point in the history
  • Loading branch information
SPMcentral committed Jan 15, 2016
1 parent 61d19bb commit a398507
Show file tree
Hide file tree
Showing 1,097 changed files with 47,946 additions and 18,206 deletions.
17 changes: 15 additions & 2 deletions @file_array/private/file2mat.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: file2mat.c 5446 2013-04-24 16:56:51Z guillaume $
* $Id: file2mat.c 6618 2015-12-01 16:25:38Z spm $
* John Ashburner
*/

Expand Down Expand Up @@ -625,7 +625,20 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (map.dtype->channels == 1)
{
plhs[0] = mxCreateNumericArray(ndim,odim,map.dtype->clss,mxREAL);
map.dtype->func(ndim-1, idim, iptr, idat, odim, mxGetData(plhs[0]));
#ifdef SPM_WIN32
/* https://msdn.microsoft.com/en-us/library/windows/desktop/aa366801.aspx */
__try
{
#endif
map.dtype->func(ndim-1, idim, iptr, idat, odim, mxGetData(plhs[0]));
#ifdef SPM_WIN32
}
__except(GetExceptionCode()==EXCEPTION_IN_PAGE_ERROR ?
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
mexErrMsgTxt("An exception occured while accessing the data.");
}
#endif
if (map.swap)
map.dtype->swap(ocumprod[ndim],mxGetData(plhs[0]));
}
Expand Down
Binary file modified @file_array/private/file2mat.mexw64
Binary file not shown.
Binary file modified @file_array/private/init.mexw32
Binary file not shown.
Binary file modified @file_array/private/init.mexw64
Binary file not shown.
10 changes: 8 additions & 2 deletions @file_array/subsasgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
% Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging

%
% $Id: subsasgn.m 6157 2014-09-05 18:17:54Z guillaume $
% $Id: subsasgn.m 6522 2015-08-14 18:55:42Z john $


if isempty(subs), return; end
Expand Down Expand Up @@ -145,7 +145,13 @@

%-Convert data into output datatype
%--------------------------------------------------------------------------
if dt(ind).isint, dat = round(dat); end
if dt(ind).isint
% Avoid "Warning: Out of range value converted to intmin() or intmax()."
dat = max(dat,dt(ind).min);
dat = min(dat,dt(ind).max);

dat = round(dat);
end

%ws = warning('off'); % Avoid warning messages in R14 SP3
dat = feval(dt(ind).conv,dat);
Expand Down
6 changes: 3 additions & 3 deletions @gifti/fieldnames.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: fieldnames.m 6345 2015-02-20 12:25:50Z guillaume $
% $Id: fieldnames.m 6507 2015-07-24 16:48:02Z guillaume $

if numel(this) > 1, warning('Only handle scalar objects yet.'); end

pfn = {'vertices' 'faces' 'normals' 'cdata' 'mat' 'labels' 'indices'};
pfn = {'vertices','faces','normals','cdata','mat','labels','indices'};

names = pfn(isintent(this,pfn));
names = unique(pfn(isintent(this,pfn)));
5 changes: 4 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 6347 2015-02-24 17:59:16Z guillaume $
% $Id: gifti.m 6601 2015-11-19 13:55:32Z guillaume $

switch nargin

Expand Down Expand Up @@ -67,6 +67,9 @@
elseif strcmpi(e,'.asc') || strcmpi(e,'.srf')
this = read_freesurfer_file(varargin{1});
this = gifti(this);
elseif strcmpi(e,'.vtk')
this = mvtk_read(varargin{1});
this = gifti(this);
else
this = read_gifti_file(varargin{1},giftistruct);
this = class(this,'gifti');
Expand Down
4 changes: 2 additions & 2 deletions @gifti/isfield.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: isfield.m 2076 2008-09-10 12:34:08Z guillaume $
% $Id: isfield.m 6507 2015-07-24 16:48:02Z guillaume $

tf = ismember(field, fieldnames(this));
tf = ismember(field, fieldnames(this));
165 changes: 165 additions & 0 deletions @gifti/private/mvtk_read.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
function M = mvtk_read(filename)
% Read VTK formatted data from disk
% FORMAT M = mvtk_read(filename)
%
% filename - VTK-formatted file name
% M - data structure
%__________________________________________________________________________
%
% VTK File Formats Specifications:
% http://www.vtk.org/VTK/img/file-formats.pdf
%
% Requirements: zstream, base64decode
%__________________________________________________________________________
% Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging

% Guillaume Flandin
% $Id: mvtk_read.m 6601 2015-11-19 13:55:32Z guillaume $


[pth,name,ext] = fileparts(filename);
switch ext
case '.vtk'
M = mvtk_read_legacy(filename);
case {'.vti','.vtp','.vtr','.vts','.vtu'}
% Serial vtkImageData (structured)
% Serial vtkPolyData (unstructured)
% Serial vtkRectilinearGrid (structured)
% Serial vtkStructuredGrid (structured)
% Serial vtkUnstructuredGrid (unstructured)
M = mvtk_read_xml(filename);
otherwise
error('Unknown file format.');
end

%==========================================================================
% function M = mvtk_read_legacy(filename)
%==========================================================================
function M = mvtk_read_legacy(filename)

fid = fopen(filename,'rt');
if fid == -1
error('Cannot open %s.',filename);
end

%- Part 1: file version and identifier
% # vtk DataFile Version 2.0
l = fgetl(fid);
if ~ischar(l), error('VTK file incomplete.'); end
if ~strncmpi(l,'# vtk DataFile Version',22)
error('This is not a VTK formatted file.');
end

%- Part 2: header
l = fgetl(fid);
if ~ischar(l), error('VTK file incomplete.'); end

%- Part 3: file format
format = fgetl(fid);
if ~ismember(format,{'ASCII','BINARY'})
error('Unknown file format.');
end

%- Part 4: dataset structure
data_attributes = false;
l = fgetl(fid);
if ~ischar(l), error('VTK file incomplete.'); end
[D,l] = strtok(l);
if ~strcmp(D,'DATASET'), error('Invalid VTK file.'); end
F = strtok(l(2:end));
switch F
case 'STRUCTURED_POINTS'
warning('Unsupported dataset format.');
l = fgetl(fid);
DIM = sscanf(l,'DIMENSIONS %d %d %d');
l = fgetl(fid);
ORIGIN = sscanf(l,'ORIGIN %f %f %f');
l = fgetl(fid);
SPACING = sscanf(l,'SPACING %f %f %f');
case 'STRUCTURED_GRID'
warning('Unsupported dataset format.');
l = fgetl(fid);
DIM = sscanf(l,'DIMENSIONS %d %d %d');
l = fgetl(fid);
% assume float and n = prod(DIM)
PTS = textscan(fid,'%f %f %f\n',prod(DIM),'CollectOutput',true);
PTS = PTS{1};
case 'RECTILINEAR_GRID'
warning('Unsupported dataset format.');
l = fgetl(fid);
DIM = sscanf(l,'DIMENSIONS %d %d %d');
l = fgetl(fid);
XCOORDS = textscan(fid,'%f',DIM(1),'CollectOutput',true);
XCOORDS = XCOORDS{1};
l = fgetl(fid);
YCOORDS = textscan(fid,'%f',DIM(2),'CollectOutput',true);
YCOORDS = YCOORDS{1};
l = fgetl(fid);
ZCOORDS = textscan(fid,'%f',DIM(3),'CollectOutput',true);
ZCOORDS = ZCOORDS{1};
case 'POLYDATA'
while true
l = fgetl(fid);
if ~ischar(l), break; end
[D,l] = strtok(l);
switch D
case 'POINTS'
[N,l] = strtok(l(2:end)); % l still contains dataType
N = str2double(N);
M.vertices = textscan(fid,'%f %f %f\n',N,'CollectOutput',true);
M.vertices = M.vertices{1};
case 'POLYGONS'
[N,l] = strtok(l(2:end));
N = str2double(N);
S = strtok(l);
S = str2double(S);
if 4*N ~= S, error('Unsupported dataset format.'); end
M.faces = textscan(fid,'3 %d %d %d\n',N,'CollectOutput',true);
M.faces = M.faces{1} + 1;
case {'VERTICES','LINES','TRIANGLE_STRIPS'}
error('Unsupported data type.');
case {'POINT_DATA','CELL_DATA'}
data_attributes = true;
[N,l] = strtok(l(2:end));
N = str2double(N);
break;
otherwise
error('Invalid VTK file.');
end
end
case {'UNSTRUCTURED_GRID','FIELD'}
error('Unsupported data type.');
otherwise
error('Invalid VTK file.');
end

%- Part 5: dataset attributes (POINT_DATA and CELL_DATA)
if data_attributes
%l = fgetl(fid); % {POINT_DATA,CELL_DATA} N
l = fgetl(fid); % SCALARS dataName dataType numComp
[P,l] = strtok(l);
[S,l] = strtok(l(2:end));
[S,l] = strtok(l(2:end));
S = strtok(l(2:end)); S = str2double(S);
l = fgetl(fid); % LOOKUP_TABLE default
fmt = repmat('%f ',1,S);
fmt = [fmt(1:end-1) '\n'];
M.cdata = textscan(fid,fmt,N,'CollectOutput',true);
M.cdata = M.cdata{1};
end

fclose(fid);

%==========================================================================
% function M = mvtk_read_xml(filename)
%==========================================================================
function M = mvtk_read_xml(filename)

try
X = xmltree(filename);
catch
error('Cannot parse file %s.',filename);
end

warning('Unsupported file format.');
M = struct([]);
Loading

0 comments on commit a398507

Please sign in to comment.