Skip to content

Commit

Permalink
restrucuting - replaced cfg.vol and vol by cfg.headmodel and headmode…
Browse files Browse the repository at this point in the history
…l in most (if not all) parts of the code, according to http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=1547

git-svn-id: svn+ssh://svn.fcdonders.nl/home/svnroot/fieldtrip/trunk@10541 0cf7c7f0-3615-4144-b4e6-68da3bce3cd0
  • Loading branch information
robertoostenveld committed Jul 15, 2015
1 parent a727a6a commit 88b82ea
Show file tree
Hide file tree
Showing 54 changed files with 1,042 additions and 1,041 deletions.
12 changes: 6 additions & 6 deletions fileio/ft_read_headshape.m
Original file line number Diff line number Diff line change
Expand Up @@ -912,15 +912,15 @@
% try reading it as volume conductor
% and treat the skin surface as headshape
try
vol = ft_read_vol(filename);
if ~ft_voltype(vol, 'bem')
headmodel = ft_read_vol(filename);
if ~ft_voltype(headmodel, 'bem')
error('skin surface can only be extracted from boundary element model');
else
if ~isfield(vol, 'skin')
vol.skin = find_outermost_boundary(vol.bnd);
if ~isfield(headmodel, 'skin')
headmodel.skin = find_outermost_boundary(headmodel.bnd);
end
shape.pnt = vol.bnd(vol.skin).pnt;
shape.tri = vol.bnd(vol.skin).tri; % also return the triangulation
shape.pnt = headmodel.bnd(headmodel.skin).pnt;
shape.tri = headmodel.bnd(headmodel.skin).tri; % also return the triangulation
success = 1;
end
catch
Expand Down
21 changes: 9 additions & 12 deletions fileio/ft_read_vol.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function [vol] = ft_read_vol(filename, varargin)
function [headmodel] = ft_read_vol(filename, varargin)

% FT_READ_VOL reads a volume conduction model from various manufacturer
% specific files. Currently supported are ASA, CTF, Neuromag, MBFYS
% and Matlab.
%
% Use as
% vol = ft_read_vol(filename, ...)
% headmodel = ft_read_vol(filename, ...)
%
% Additional options should be specified in key-value pairs and can be
% 'fileformat' string
Expand Down Expand Up @@ -48,27 +48,24 @@

switch fileformat
case 'matlab'
matfile = filename; % this solves a problem with the MATLAB compiler v3
ws = warning('off', 'MATLAB:load:variableNotFound');
tmp = load(matfile, 'vol');
warning(ws);
vol = getfield(tmp, 'vol');
% FIXME in the future the file should contain the variable 'headmodel' instead of vol
headmodel = loadvar(filename, 'vol');

case 'ctf_hdm'
vol = read_ctf_hdm(filename);
headmodel = read_ctf_hdm(filename);

case 'asa_vol'
vol = read_asa_vol(filename);
vol.type = 'asa';
headmodel = read_asa_vol(filename);
headmodel.type = 'asa';

case 'mbfys_ama'
ama = loadama(filename);
vol = ama2vol(ama);
headmodel = ama2vol(ama);

otherwise
error('unknown fileformat for volume conductor model');
end

% this will ensure that the structure is up to date, e.g. that the type is correct and that it has units
vol = ft_datatype_headmodel(vol);
headmodel = ft_datatype_headmodel(headmodel);

43 changes: 43 additions & 0 deletions fileio/private/loadvar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function value = loadvar(filename, varname)

% LOADVAR is a helper function for cfg.inputfile

% Copyright (C) 2010, Robert Oostenveld
%
% $Id$

assert(ischar(filename), 'file name should be a string');

if nargin<2
fprintf('reading variable from file ''%s''\n', filename);
else
assert(ischar(varname), 'variable name should be a string');
fprintf('reading ''%s'' from file ''%s''\n', varname, filename);
end

% note that this sometimes fails, returning an empty var
% this is probably due to MATLAB filename and MATLAB version issues
var = whos('-file', filename);

if length(var)==0 && nargin==1
filecontent = load(filename); % read everything from the file, regardless of how the variables are called
varname = fieldnames(filecontent);
if length(varname)==1
% the one variable in the file will be returned
value = filecontent.(varname{i});
clear filecontent
else
error('cannot read an unspecified variable in case of a file containing multiple variables');
end

elseif length(var)==1
filecontent = load(filename); % read the one variable in the file, regardless of how it is called
value = filecontent.(var.name);
clear filecontent

else
filecontent = load(filename, varname);
value = filecontent.(varname); % read the variable named according to the input specification
clear filecontent
end

Loading

0 comments on commit 88b82ea

Please sign in to comment.