Hardware accelerated ray-triangle intersection

版本 1.2.0.0 (35.6 KB) 作者: Thomas Seers
GPU portable implementation of the ray-triangle intersection method of Moller and Trumbore (1997)
841.0 次下载
更新时间 2015/2/13

查看许可证

% Ray-triangle intersection algorithm of Muller and Trumbore (1997)
% formatted for arrayfun to allow hardware acceleration
% Call with gpuarray and arrayfun to execute on the GPU: thjs
% may give two orders of magnitude speed up over vectorized
% cpu based implementation
% INPUT:
% P0x, P0y, P0z / P1x, P1y, P1z / P2x, P2y, P2z: xyz components of the
% triangle objects
% orx, ory, orz: xyz componants of the ray origin
% Dx, Dy, Dz: xyz components of the ray directional (unit) vectors
% OUTPUT:
% distOut: distance from from the ray-tri intersection to the origin or nan
% if no intersection is located
% flag: logical where true indicates intersection and false indicates
% no intersection
% Usage example:
% Step 1: convert mx3 direction vectors, D = [Dx Dy Dz] to gpuarray object
% >> gD = gpuArray(D);
% Step 2: call rayTriGPU using arrayfun with scalar input formatting
% where P0, P1, P2 are the nx3 vertex lists of the triangle corner points
% and where or is the xyz coordinates of the origin
% >> [dist, flag] = arrayfun(@rayTriGPU, P0(:,1)', P0(:,2)', P0(:,3)', ...
% P1(:,1)', P1(:,2)', P1(:,3)', ...
% P2(:,1)', P2(:,2)', P2(:,3)', ...
% or(:,1), or(:,2), or(:,3), ...
% gD(:,1),gD(:,2),gD(:,3));
% Step 3: recover data
% distances = gather(dist);
% Output is an mxn array containing a the distance from the ray-tri
% intersection to the origin or nan if no intersection is located
% Implentation based upon that of Paul Peeling (originally from Jesus P.
% Mena-Chalco of FEX), MathWorks (which returns a flag but not the
% intersection distance).

% Per ray flags can be obtained from the output dist using the following
% method:
% >> flagT = true(size(D,1),1);
% >> flagT(sum(isnan(dist),2) == size(P0,1)) = false;
% This may save transfer time off the GPU

% Dependencies: requires Parallel Computing Toolbox
% Test data (testDataTri.mat) is provided with the package

% references
% Fast, Minimum Storage Ray/Triangle Intersection, Möller & Trumbore.
% Journal of Graphics Tools, 1997.

引用格式

Thomas Seers (2024). Hardware accelerated ray-triangle intersection (https://www.mathworks.com/matlabcentral/fileexchange/49670-hardware-accelerated-ray-triangle-intersection), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2013a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.2.0.0

Changed description to match new function output (distOut)

1.1.0.0

Changed output to avoid potential conflict with the built-in function: dist

1.0.0.0