资源简介
ply格式的文件,成功的用matlab加载,之后可以做你想要的修改。
代码片段和文件信息
function [Elementsvarargout] = plyread(PathStr)
%PLYREAD Read a PLY 3D data file.
% [DATACOMMENTS] = PLYREAD(FILENAME) reads a version 1.0 PLY file
% FILENAME and returns a structure DATA. The fields in this structure
% are defined by the PLY header; each element type is a field and each
% element property is a subfield. If the file contains any comments
% they are returned in a cell string array COMMENTS.
%
% [TRIPTS] = PLYREAD(FILENAME‘tri‘) or
% [TRIPTSDATACOMMENTS] = PLYREAD(FILENAME‘tri‘) converts vertex
% and face data into triangular connectivity and vertex arrays. The
% mesh can then be displayed using the TRISURF command.
%
% Note: This function is slow for large mesh files (+50K faces)
% especially when reading data with list type properties.
%
% Example:
% [TriPts] = PLYREAD(‘cow.ply‘‘tri‘);
% trisurf(TriPts(:1)Pts(:2)Pts(:3));
% colormap(gray); axis equal;
%
% See also: PLYWRITE
% Pascal Getreuer 2004
[fidMsg] = fopen(Path‘rt‘); % open file in read text mode
if fid == -1 error(Msg); end
Buf = fscanf(fid‘%s‘1);
if ~strcmp(Buf‘ply‘)
fclose(fid);
error(‘Not a PLY file.‘);
end
%%% read header %%%
Position = ftell(fid);
Format = ‘‘;
NumComments = 0;
Comments = {}; % for storing any file comments
NumElements = 0;
NumProperties = 0;
Elements = []; % structure for holding the element data
ElementCount = []; % number of each type of element in file
PropertyTypes = []; % corresponding structure recording property types
ElementNames = {}; % list of element names in the order they are stored in the file
PropertyNames = []; % structure of lists of property names
while 1
Buf = fgetl(fid); % read one line from file
BufRem = Buf;
Token = {};
Count = 0;
while ~isempty(BufRem) % split line into tokens
[tmpBufRem] = strtok(BufRem);
if ~isempty(tmp)
Count = Count + 1; % count tokens
Token{Count} = tmp;
end
end
if Count % parse line
switch lower(Token{1})
case ‘format‘ % read data format
if Count >= 2
Format = lower(Token{2});
if Count == 3 & ~strcmp(Token{3}‘1.0‘)
fclose(fid);
error(‘Only PLY format version 1.0 supported.‘);
end
end
case ‘comment‘ % read file comment
NumComments = NumComments + 1;
Comments{NumComments} = ‘‘;
for i = 2:Count
Comments{NumComments} = [Comments{NumComments}Token{i}‘ ‘];
end
case ‘element‘ % element name
if Count >= 3
if isfield(ElementsToken{2})
fclose(fid);
error([‘Duplicate element name ‘‘‘Token{2}‘‘‘.‘]);
end
NumElements = NumElements + 1;
NumProperties = 0;
Elements
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2009-03-19 04:28 plytools\
文件 75683 2008-04-15 09:37 plytools\cow.ply
文件 13212 2008-04-15 09:37 plytools\ply.htm
文件 15640 2008-04-15 09:37 plytools\plyread.m
文件 8845 2008-04-15 09:37 plytools\plywrite.m
文件 1098 2008-04-15 09:37 plytools\plywritetri.m
文件 734 2008-04-15 09:37 plytools\README.TXT
- 上一篇:基于matlab的svpwm仿真
- 下一篇:内点法Matlab
评论
共有 条评论