⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voi_applytrf.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function hfile = voi_ApplyTrf(hfile, trf, exact, invflag)
% VOI::ApplyTrf  - apply transformations to VOI coordinates
%
% FORMAT:       [voi = ] voi.ApplyTrf(trf [,exact, invflag])
%
% Input fields:
%
%       trf         single TRF or (cell array) list of TRF (or TAL)
%       exact       flag to not round coordinates (default false)
%       invflag     either single boolean or list of boolean
%
% Output fields:
%
%       voi         VOI with transformed coordinates

% Version:  v0.7b
% Build:    7090215
% Date:     Sep-02 2007, 3:11 PM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'voi') || ...
   (~isBVQXfile(trf, 'trf') && ...
    ~isBVQXfile(trf, 'tal') && ...
    (~iscell(trf) || ...
      isempty(trf) || ...
     (~isBVQXfile(trf{1}, 'trf') && ...
      ~isBVQXfile(trf{1}, 'tal'))))
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end
bc = bvqxfile_getcont(hfile.L);
if ~iscell(trf)
    trf = {trf};
else
    trf = trf(:)';
end
for tc = 2:numel(trf)
    if numel(trf{tc}) ~= 1 || ...
       (~isBVQXfile(trf{tc}, 'trf') && ...
        ~isBVQXfile(trf{tc}, 'tal'))
        error( ...
            'BVQXfile:BadArgument', ...
            'Invalid TRF argument in cell %d.', ...
            tc ...
        );
    end
end
if nargin < 3 || ...
   ~islogical(exact) || ...
    isempty(exact)
    exact = false;
else
    exact = exact(1);
end
if nargin < 4 || ...
   ~islogical(invflag) || ...
   (numel(invflag) ~= 1 && ...
    numel(invflag) ~= numel(trf))
    invflag = false(1, numel(trf));
elseif numel(invflag) == 1
    invflag = repmat(invflag, [1, numel(trf)]);
else
    invflag = invflag(:)';
end

% get VOI array and all coordinates
voi = bc.VOI;
nvoi = numel(voi);
nvox = zeros(1, nvoi);
for vc = 1:nvoi
    nvox = size(voi(vc).Voxels, 1);
end
vox = zeros(nvox, 3);
tvc = 0;
for vc = 1:nvoi
    vox((tvc + 1):(tvc + nvox(vc)), :) = voi(vc).Voxels;
    tvc = tvc + nvox(vc);
end

% transform?
if strcmpi(bc.CoordsType, 'tal')
    cintal = true;
    vox = 128 - vox;
else
    cintal = false;
end

% perform transformations
for tc = 1:numel(trf)
    
    % TRF
    if isBVQXfile(trf{tc}, 'trf')
        
        % check trf
        tbc = bvqxfile_getcont(trf{tc}.L);
        if tbc.TransformationType ~= 2 || ...
           ~strcmpi(tbc.DataFormat, 'matrix') || ...
            numel(tbc.TFMatrix) ~= 16
            error( ...
                'BVQXfile:BadArgument', ...
                'Invalid TRF object given in cell %d.', ...
                tc ...
            );
        end
        
        % apply
        vox = applybvtrf(vox, tbc.TFMatrix, ~invflag(tc));
        
    % TAL
    else
        vox = acpc2tal(vox, trf{tc}, invflag(tc));
    end
end

% transform back
if cintal
    vox = 128 - vox;
end

% round
if ~exact
    vox = round(vox);
end

% spread into VOI array
tvc = 0;
for vc = 1:nvoi
    if exact
        voi(vc).Voxels = vox((tvc + 1):(tvc + nvox(vc)), :);
    else
        voi(vc).Voxels = unique(vox((tvc + 1):(tvc + nvox(vc)), :), 'rows');
    end
    tvc = tvc + nvox(vc);
end

% set back
bc.VOI = voi;
bvqxfile_setcont(hfile.L, bc);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -