| | function [obj] = ft_convert_units(obj, target, varargin) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | feedback = ft_getopt(varargin, 'feedback', false); |
| |
|
| | if isstruct(obj) && numel(obj)>1 |
| | |
| | for i=1:numel(obj) |
| | if nargin>1 |
| | tmp(i) = ft_convert_units(obj(i), target, varargin{:}); |
| | else |
| | tmp(i) = ft_convert_units(obj(i)); |
| | end |
| | end |
| | obj = tmp; |
| | return |
| | end |
| |
|
| | |
| | |
| | |
| | if isfield(obj, 'unit') && ~isempty(obj.unit) |
| | |
| | unit = obj.unit; |
| | |
| | elseif isfield(obj, 'bnd') && isfield(obj.bnd, 'unit') |
| | |
| | unit = unique({obj.bnd.unit}); |
| | if ~all(strcmp(unit, unit{1})) |
| | error('inconsistent units in the individual boundaries'); |
| | else |
| | unit = unit{1}; |
| | end |
| | |
| | |
| | |
| | obj.bnd = rmfield(obj.bnd, 'unit'); |
| | |
| | else |
| | |
| | if isfield(obj, 'chanpos') && ~isempty(obj.chanpos) |
| | siz = norm(idrange(obj.chanpos)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'elecpos') && ~isempty(obj.elecpos) |
| | siz = norm(idrange(obj.elecpos)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'coilpos') && ~isempty(obj.coilpos) |
| | siz = norm(idrange(obj.coilpos)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'pnt') && ~isempty(obj.pnt) |
| | siz = norm(idrange(obj.pnt)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'pos') && ~isempty(obj.pos) |
| | siz = norm(idrange(obj.pos)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'transform') && ~isempty(obj.transform) |
| | |
| | [pos_voxel, pos_head] = cornerpoints(obj.dim, obj.transform); |
| | siz = norm(idrange(pos_head)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'fid') && isfield(obj.fid, 'pnt') && ~isempty(obj.fid.pnt) |
| | siz = norm(idrange(obj.fid.pnt)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'fid') && isfield(obj.fid, 'pos') && ~isempty(obj.fid.pos) |
| | siz = norm(idrange(obj.fid.pos)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif ft_voltype(obj, 'infinite') |
| | |
| | unit = 'm'; |
| | |
| | elseif ft_voltype(obj,'singlesphere') |
| | siz = obj.r; |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif ft_voltype(obj,'localspheres') |
| | siz = median(obj.r); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif ft_voltype(obj,'concentricspheres') |
| | siz = max(obj.r); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'bnd') && isstruct(obj.bnd) && isfield(obj.bnd(1), 'pnt') && ~isempty(obj.bnd(1).pnt) |
| | siz = norm(idrange(obj.bnd(1).pnt)); |
| | unit = ft_estimate_units(siz); |
| | |
| | elseif isfield(obj, 'bnd') && isstruct(obj.bnd) && isfield(obj.bnd(1), 'pos') && ~isempty(obj.bnd(1).pos) |
| | siz = norm(idrange(obj.bnd(1).pos)); |
| | unit = ft_estimate_units(siz); |
| |
|
| | elseif isfield(obj, 'nas') && isfield(obj, 'lpa') && isfield(obj, 'rpa') |
| | pnt = [obj.nas; obj.lpa; obj.rpa]; |
| | siz = norm(idrange(pnt)); |
| | unit = ft_estimate_units(siz); |
| | |
| | else |
| | error('cannot determine geometrical units'); |
| | |
| | end |
| | end |
| |
|
| | if nargin<2 || isempty(target) |
| | |
| | obj.unit = unit; |
| | return |
| | elseif strcmp(unit, target) |
| | |
| | obj.unit = unit; |
| | return |
| | end |
| |
|
| | |
| | |
| | |
| | scale = ft_scalingfactor(unit, target); |
| |
|
| | if istrue(feedback) |
| | |
| | fprintf('converting units from ''%s'' to ''%s''\n', unit, target) |
| | end |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | if isfield(obj, 'r'), obj.r = scale * obj.r; end |
| | if isfield(obj, 'o'), obj.o = scale * obj.o; end |
| | if isfield(obj, 'bnd') && isfield(obj.bnd, 'pnt') |
| | for i=1:length(obj.bnd) |
| | obj.bnd(i).pnt = scale * obj.bnd(i).pnt; |
| | end |
| | end |
| | if isfield(obj, 'bnd') && isfield(obj.bnd, 'pos') |
| | for i=1:length(obj.bnd) |
| | obj.bnd(i).pos = scale * obj.bnd(i).pos; |
| | end |
| | end |
| |
|
| | |
| | if isfield(obj, 'pnt1'), obj.pnt1 = scale * obj.pnt1; end |
| | if isfield(obj, 'pnt2'), obj.pnt2 = scale * obj.pnt2; end |
| | if isfield(obj, 'prj'), obj.prj = scale * obj.prj; end |
| |
|
| | |
| | if isfield(obj, 'pnt'), obj.pnt = scale * obj.pnt; end |
| | if isfield(obj, 'pos'), obj.pos = scale * obj.pos; end |
| | if isfield(obj, 'chanpos'), obj.chanpos = scale * obj.chanpos; end |
| | if isfield(obj, 'chanposorg'), obj.chanposorg = scale * obj.chanposorg; end |
| | if isfield(obj, 'coilpos'), obj.coilpos = scale * obj.coilpos; end |
| | if isfield(obj, 'elecpos'), obj.elecpos = scale * obj.elecpos; end |
| |
|
| | |
| | if isfield(obj, 'tra') && isfield(obj, 'chanunit') |
| | |
| | for i=1:length(obj.chanunit) |
| | tok = tokenize(obj.chanunit{i}, '/'); |
| | if ~isempty(regexp(obj.chanunit{i}, 'm$', 'once')) |
| | |
| | obj.tra(i,:) = obj.tra(i,:) / scale; |
| | obj.chanunit{i} = [tok{1} '/' target]; |
| | elseif ~isempty(regexp(obj.chanunit{i}, '[T|V]$', 'once')) |
| | |
| | elseif strcmp(obj.chanunit{i}, 'unknown') |
| | |
| | else |
| | error('unexpected units %s', obj.chanunit{i}); |
| | end |
| | end |
| | end |
| |
|
| | |
| | if isfield(obj, 'fid') && isfield(obj.fid, 'pnt'), obj.fid.pnt = scale * obj.fid.pnt; end |
| | if isfield(obj, 'fid') && isfield(obj.fid, 'pos'), obj.fid.pos = scale * obj.fid.pos; end |
| |
|
| | |
| | if isfield(obj, 'resolution'), obj.resolution = scale * obj.resolution; end |
| |
|
| | |
| | if isfield(obj, 'xgrid') && ~ischar(obj.xgrid), obj.xgrid = scale * obj.xgrid; end |
| | if isfield(obj, 'ygrid') && ~ischar(obj.ygrid), obj.ygrid = scale * obj.ygrid; end |
| | if isfield(obj, 'zgrid') && ~ischar(obj.zgrid), obj.zgrid = scale * obj.zgrid; end |
| |
|
| | |
| | if isfield(obj, 'transform'), |
| | H = diag([scale scale scale 1]); |
| | obj.transform = H * obj.transform; |
| | end |
| |
|
| | if isfield(obj, 'transformorig'), |
| | H = diag([scale scale scale 1]); |
| | obj.transformorig = H * obj.transformorig; |
| | end |
| |
|
| | |
| | |
| | if isfield(obj, 'orig') && (isfield(obj.orig, 'pnt') || isfield(obj.orig, 'pos')) |
| | obj.orig.pnt = scale * obj.orig.pnt; |
| | end |
| |
|
| | |
| | obj.unit = target; |
| |
|
| | |
| | |
| | |
| | function r = idrange(x) |
| | keeprow=true(size(x,1),1); |
| | for l=1:size(x,2) |
| | keeprow = keeprow & isfinite(x(:,l)); |
| | end |
| | sx = sort(x(keeprow,:), 1); |
| | ii = round(interp1([0, 1], [1, size(x(keeprow,:), 1)], [.1, .9])); |
| | r = diff(sx(ii, :)); |
| |
|