Skip to content

Commit a398507

Browse files
committed
SPM12 r6685
1 parent 61d19bb commit a398507

File tree

1,097 files changed

+47946
-18206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,097 files changed

+47946
-18206
lines changed

@file_array/private/file2mat.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: file2mat.c 5446 2013-04-24 16:56:51Z guillaume $
2+
* $Id: file2mat.c 6618 2015-12-01 16:25:38Z spm $
33
* John Ashburner
44
*/
55

@@ -625,7 +625,20 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
625625
if (map.dtype->channels == 1)
626626
{
627627
plhs[0] = mxCreateNumericArray(ndim,odim,map.dtype->clss,mxREAL);
628-
map.dtype->func(ndim-1, idim, iptr, idat, odim, mxGetData(plhs[0]));
628+
#ifdef SPM_WIN32
629+
/* https://msdn.microsoft.com/en-us/library/windows/desktop/aa366801.aspx */
630+
__try
631+
{
632+
#endif
633+
map.dtype->func(ndim-1, idim, iptr, idat, odim, mxGetData(plhs[0]));
634+
#ifdef SPM_WIN32
635+
}
636+
__except(GetExceptionCode()==EXCEPTION_IN_PAGE_ERROR ?
637+
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
638+
{
639+
mexErrMsgTxt("An exception occured while accessing the data.");
640+
}
641+
#endif
629642
if (map.swap)
630643
map.dtype->swap(ocumprod[ndim],mxGetData(plhs[0]));
631644
}

@file_array/private/file2mat.mexw64

512 Bytes
Binary file not shown.

@file_array/private/init.mexw32

0 Bytes
Binary file not shown.

@file_array/private/init.mexw64

0 Bytes
Binary file not shown.

@file_array/subsasgn.m

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
% Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging
55

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

99

1010
if isempty(subs), return; end
@@ -145,7 +145,13 @@
145145

146146
%-Convert data into output datatype
147147
%--------------------------------------------------------------------------
148-
if dt(ind).isint, dat = round(dat); end
148+
if dt(ind).isint
149+
% Avoid "Warning: Out of range value converted to intmin() or intmax()."
150+
dat = max(dat,dt(ind).min);
151+
dat = min(dat,dt(ind).max);
152+
153+
dat = round(dat);
154+
end
149155

150156
%ws = warning('off'); % Avoid warning messages in R14 SP3
151157
dat = feval(dt(ind).conv,dat);

@gifti/fieldnames.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
88

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

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

14-
pfn = {'vertices' 'faces' 'normals' 'cdata' 'mat' 'labels' 'indices'};
14+
pfn = {'vertices','faces','normals','cdata','mat','labels','indices'};
1515

16-
names = pfn(isintent(this,pfn));
16+
names = unique(pfn(isintent(this,pfn)));

@gifti/gifti.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
99

1010
% Guillaume Flandin
11-
% $Id: gifti.m 6347 2015-02-24 17:59:16Z guillaume $
11+
% $Id: gifti.m 6601 2015-11-19 13:55:32Z guillaume $
1212

1313
switch nargin
1414

@@ -67,6 +67,9 @@
6767
elseif strcmpi(e,'.asc') || strcmpi(e,'.srf')
6868
this = read_freesurfer_file(varargin{1});
6969
this = gifti(this);
70+
elseif strcmpi(e,'.vtk')
71+
this = mvtk_read(varargin{1});
72+
this = gifti(this);
7073
else
7174
this = read_gifti_file(varargin{1},giftistruct);
7275
this = class(this,'gifti');

@gifti/isfield.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
99

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

13-
tf = ismember(field, fieldnames(this));
13+
tf = ismember(field, fieldnames(this));

@gifti/private/mvtk_read.m

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
function M = mvtk_read(filename)
2+
% Read VTK formatted data from disk
3+
% FORMAT M = mvtk_read(filename)
4+
%
5+
% filename - VTK-formatted file name
6+
% M - data structure
7+
%__________________________________________________________________________
8+
%
9+
% VTK File Formats Specifications:
10+
% http://www.vtk.org/VTK/img/file-formats.pdf
11+
%
12+
% Requirements: zstream, base64decode
13+
%__________________________________________________________________________
14+
% Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging
15+
16+
% Guillaume Flandin
17+
% $Id: mvtk_read.m 6601 2015-11-19 13:55:32Z guillaume $
18+
19+
20+
[pth,name,ext] = fileparts(filename);
21+
switch ext
22+
case '.vtk'
23+
M = mvtk_read_legacy(filename);
24+
case {'.vti','.vtp','.vtr','.vts','.vtu'}
25+
% Serial vtkImageData (structured)
26+
% Serial vtkPolyData (unstructured)
27+
% Serial vtkRectilinearGrid (structured)
28+
% Serial vtkStructuredGrid (structured)
29+
% Serial vtkUnstructuredGrid (unstructured)
30+
M = mvtk_read_xml(filename);
31+
otherwise
32+
error('Unknown file format.');
33+
end
34+
35+
%==========================================================================
36+
% function M = mvtk_read_legacy(filename)
37+
%==========================================================================
38+
function M = mvtk_read_legacy(filename)
39+
40+
fid = fopen(filename,'rt');
41+
if fid == -1
42+
error('Cannot open %s.',filename);
43+
end
44+
45+
%- Part 1: file version and identifier
46+
% # vtk DataFile Version 2.0
47+
l = fgetl(fid);
48+
if ~ischar(l), error('VTK file incomplete.'); end
49+
if ~strncmpi(l,'# vtk DataFile Version',22)
50+
error('This is not a VTK formatted file.');
51+
end
52+
53+
%- Part 2: header
54+
l = fgetl(fid);
55+
if ~ischar(l), error('VTK file incomplete.'); end
56+
57+
%- Part 3: file format
58+
format = fgetl(fid);
59+
if ~ismember(format,{'ASCII','BINARY'})
60+
error('Unknown file format.');
61+
end
62+
63+
%- Part 4: dataset structure
64+
data_attributes = false;
65+
l = fgetl(fid);
66+
if ~ischar(l), error('VTK file incomplete.'); end
67+
[D,l] = strtok(l);
68+
if ~strcmp(D,'DATASET'), error('Invalid VTK file.'); end
69+
F = strtok(l(2:end));
70+
switch F
71+
case 'STRUCTURED_POINTS'
72+
warning('Unsupported dataset format.');
73+
l = fgetl(fid);
74+
DIM = sscanf(l,'DIMENSIONS %d %d %d');
75+
l = fgetl(fid);
76+
ORIGIN = sscanf(l,'ORIGIN %f %f %f');
77+
l = fgetl(fid);
78+
SPACING = sscanf(l,'SPACING %f %f %f');
79+
case 'STRUCTURED_GRID'
80+
warning('Unsupported dataset format.');
81+
l = fgetl(fid);
82+
DIM = sscanf(l,'DIMENSIONS %d %d %d');
83+
l = fgetl(fid);
84+
% assume float and n = prod(DIM)
85+
PTS = textscan(fid,'%f %f %f\n',prod(DIM),'CollectOutput',true);
86+
PTS = PTS{1};
87+
case 'RECTILINEAR_GRID'
88+
warning('Unsupported dataset format.');
89+
l = fgetl(fid);
90+
DIM = sscanf(l,'DIMENSIONS %d %d %d');
91+
l = fgetl(fid);
92+
XCOORDS = textscan(fid,'%f',DIM(1),'CollectOutput',true);
93+
XCOORDS = XCOORDS{1};
94+
l = fgetl(fid);
95+
YCOORDS = textscan(fid,'%f',DIM(2),'CollectOutput',true);
96+
YCOORDS = YCOORDS{1};
97+
l = fgetl(fid);
98+
ZCOORDS = textscan(fid,'%f',DIM(3),'CollectOutput',true);
99+
ZCOORDS = ZCOORDS{1};
100+
case 'POLYDATA'
101+
while true
102+
l = fgetl(fid);
103+
if ~ischar(l), break; end
104+
[D,l] = strtok(l);
105+
switch D
106+
case 'POINTS'
107+
[N,l] = strtok(l(2:end)); % l still contains dataType
108+
N = str2double(N);
109+
M.vertices = textscan(fid,'%f %f %f\n',N,'CollectOutput',true);
110+
M.vertices = M.vertices{1};
111+
case 'POLYGONS'
112+
[N,l] = strtok(l(2:end));
113+
N = str2double(N);
114+
S = strtok(l);
115+
S = str2double(S);
116+
if 4*N ~= S, error('Unsupported dataset format.'); end
117+
M.faces = textscan(fid,'3 %d %d %d\n',N,'CollectOutput',true);
118+
M.faces = M.faces{1} + 1;
119+
case {'VERTICES','LINES','TRIANGLE_STRIPS'}
120+
error('Unsupported data type.');
121+
case {'POINT_DATA','CELL_DATA'}
122+
data_attributes = true;
123+
[N,l] = strtok(l(2:end));
124+
N = str2double(N);
125+
break;
126+
otherwise
127+
error('Invalid VTK file.');
128+
end
129+
end
130+
case {'UNSTRUCTURED_GRID','FIELD'}
131+
error('Unsupported data type.');
132+
otherwise
133+
error('Invalid VTK file.');
134+
end
135+
136+
%- Part 5: dataset attributes (POINT_DATA and CELL_DATA)
137+
if data_attributes
138+
%l = fgetl(fid); % {POINT_DATA,CELL_DATA} N
139+
l = fgetl(fid); % SCALARS dataName dataType numComp
140+
[P,l] = strtok(l);
141+
[S,l] = strtok(l(2:end));
142+
[S,l] = strtok(l(2:end));
143+
S = strtok(l(2:end)); S = str2double(S);
144+
l = fgetl(fid); % LOOKUP_TABLE default
145+
fmt = repmat('%f ',1,S);
146+
fmt = [fmt(1:end-1) '\n'];
147+
M.cdata = textscan(fid,fmt,N,'CollectOutput',true);
148+
M.cdata = M.cdata{1};
149+
end
150+
151+
fclose(fid);
152+
153+
%==========================================================================
154+
% function M = mvtk_read_xml(filename)
155+
%==========================================================================
156+
function M = mvtk_read_xml(filename)
157+
158+
try
159+
X = xmltree(filename);
160+
catch
161+
error('Cannot parse file %s.',filename);
162+
end
163+
164+
warning('Unsupported file format.');
165+
M = struct([]);

0 commit comments

Comments
 (0)