Z-Buffer消隐算法的Matlab实现


用Matlab实现的Z-Buffer算法,其中读取了一个wrl文件和obj文件
资源截图
代码片段和文件信息
function [vertexfacesnormallocationpicture] = read_obj(filenamepicturename)
 
% read_obj - load a .obj file.
%
%   [vertexfacenormal] = read_obj(filename);
%
%   faces    : list of facesangle elements
%   vertex  : node vertexinatates
%   normal : normal vector list
%
%   Copyright (c) 2008 Gabriel Peyre
 
fid = fopen(filename);
if fid<0
    error([‘Cannot open ‘ filename ‘.‘]);
end
 
frewind(fid);
a = fscanf(fid‘%c‘1);
if strcmp(a ‘P‘)
    % This is the montreal neurological institute (MNI) specific ASCII facesangular mesh data structure.
    % For FreeSurfer software a slightly different data input coding is
    % needed. It will be provided upon request.
    fscanf(fid‘%f‘5);
    n_points=fscanf(fid‘%i‘1);
    vertex=fscanf(fid‘%f‘[3n_points]);
    normal=fscanf(fid‘%f‘[3n_points]);
    n_faces=fscanf(fid‘%i‘1);
    fscanf(fid‘%i‘5+n_faces);
    faces=fscanf(fid‘%i‘[3n_faces])‘+1;
    fclose(fid);
    return;
end
 
frewind(fid);
vertex = [];
faces = [];
location = [];
normal = [];
while 1
    s = fgetl(fid);
    if ~ischar(s) 
        break;
    end
    if ~isempty(s) && strcmp(s(1) ‘f‘)
        % face
        af =  sscanf(s(3:end)‘%d/%d/%d %d/%d/%d %d/%d/%d‘);
        faces(:end+1) =af(1:3:end1);
%        faces(:end+1) = sscanf(s(3:end) ‘%d %d %d‘);
    end
    if ~isempty(s) && strcmp(s(1) ‘v‘)
        if strcmp(s(2) ‘ ‘)
            % vertex
            vertex(:end+1) = sscanf(s(3:end) ‘%f %f %f‘);
        elseif strcmp(s(2) ‘t‘)
            location(:end+1) = sscanf(s(4:end) ‘%f %f‘);
        elseif strcmp(s(2) ‘n‘)
            normal(:end+1) = sscanf(s(4:end) ‘%f %f %f‘);
        end
    end
end
fclose(fid);

picture = imread(picturename);
[highwidth~] = size(picture);
location(1:) = location(1:) * width;
location(2:) = high-1-location(2:) * high;
 


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     103625  2016-07-26 21:34  testAngry00.jpg

     文件    6607102  2016-07-25 15:17  testAngry00.wrl

     文件     687801  2013-07-27 20:36  testu4d_test000.jpg

     文件        211  2013-07-27 20:39  testu4d_test000.mtl

     文件    8566714  2013-07-27 20:26  testu4d_test000.obj

     文件       1840  2018-05-17 19:38  test
ead_obj.m

     文件       1628  2018-05-16 22:01  test
ead_wrl.m

     文件      56864  2018-05-17 20:24  test
esult.png

     文件        671  2018-05-17 20:24  test est_obj.m

     文件        653  2018-05-17 20:23  test est_wrl.m

     文件       2921  2018-05-17 20:14  testBuffer.m

    ..AD...         0  2018-05-17 20:26  testAngry

     目录          0  2018-05-17 20:22  testu4d_test

     目录          0  2018-05-17 20:24  test

----------- ---------  ---------- -----  ----

             16030030                    14


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)