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

📄 srf_recalcnormals.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function hfile = srf_RecalcNormals(hfile)
% SRF::RecalcNormals  - recalculate normals by using the right-hand rule
%
% FORMAT:       [srf] = srf.RecalcNormals;
%
% No input fields
%
% Output fields:
%
%       srf         altered object

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

% check arguments
if nargin ~= 1 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'srf')
    error( ...
        'BVQXfile:BadArguments', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end
bc = bvqxfile_getcont(hfile.L);

% get coordinates and neighbors
crd = bc.VertexCoordinate;
nei = bc.Neighbors(:, 2);
ncd = size(crd, 1);
if ncd ~= numel(nei)
    error( ...
        'BVQXfile:BadObject', ...
        'Invalid object.' ...
    );
end

% generate some intermediate arrays for cross
csa = zeros(ncd, 12, 3);
csb = zeros(ncd, 12, 3);

% iterate over coordinates
for cc = 1:ncd
    
    % get neighbors and their number
    tne = nei{cc};
    tnn = numel(tne);
    
    % get coordinates of neighbors
    crn = crd(tne, :);
    
    % build vectors of triangles
    csa(cc, 1:tnn, :) = crn - crd(cc * ones(1, tnn), :);
    csb(cc, 1:tnn, :) = crn([2:tnn,1], :) - crn;
end

% compute cross products (normals)
crs = squeeze(mean(cross(csa, csb, 3), 2));

% resize to length and store
bc.VertexNormal = crs ./ (sqrt(sum(crs .* crs, 2)) * ones(1, 3));
bvqxfile_setcont(hfile.L, bc);

⌨️ 快捷键说明

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