ImageVerifierCode 换一换
格式:DOCX , 页数:28 ,大小:168.06KB ,
资源ID:23593669      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23593669.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(MATLAB对ply文件格式的读取和显示.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

MATLAB对ply文件格式的读取和显示.docx

1、MATLAB对ply文件格式的读取和显示MATLAB对ply文件格式的读取和显示首先是这个ply_read.m文件plain view plain copy print?在CODE上查看代码片派生到我的代码片function Elements, varargout = PLY_READ ( Path, Str ) %*80 % % PLY_READ reads a PLY 3D data file. % % DATA,COMMENTS = PLY_READ(FILENAME) reads a version 1.0 PLY file % FILENAME and returns a struc

2、ture 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. % % TRI,PTS = PLY_READ(FILENAME,tri) or % TRI,PTS,DATA,COMMENTS = P

3、LY_READ(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:

4、% Tri,Pts = PLY_READ(cow.ply,tri); % Tri,Pts = PLY_READ(bunny.ply,tri); % trisurf(Tri,Pts(:,1),Pts(:,2),Pts(:,3); % colormap(gray); axis equal; % % Discussion: % % The original version of this program had a mistake that meant it % did not properly triangulate files whose faces were not already trian

5、gular. % This has been corrected (JVB, 25 February 2007). % % Glenn Ramsey pointed out and corrected a problem that occurred % with an uninitialized value of Type2, 27 August 2012. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 27 August 2012 % % Author: %

6、% Pascal Getreuer 2004 % % Parameters: % % Local Parameters: % % COMMENTS, any comments from the file. % % ELEMENTCOUNT, the number of each type of element in file. % % ELEMENTS, the element data. % % PROPERTYTYPES, the element property types. % % SIZEOF, size in bytes of each type. % % % Open the i

7、nput file in read text mode. % fid, Msg = fopen ( Path, rt ); if ( fid = -1 ) error ( Msg ); end Buf = fscanf ( fid, %s, 1 ); if ( strcmp ( Buf, ply ) ) fclose ( fid ); error(Not a PLY file.); end % % Read the header. % Position = ftell(fid); Format = ; NumComments = 0; Comments = ; NumElements = 0;

8、 NumProperties = 0; Elements = ; ElementCount = ; PropertyTypes = ; ElementNames = ; % list of element names in the order they are stored in the file PropertyNames = ; % structure of lists of property names while ( 1 ) % % Read a line from the file. % Buf = fgetl ( fid ); BufRem = Buf; Token = ; Cou

9、nt = 0; % % Split the line into tokens. % while ( isempty(BufRem) ) tmp, BufRem = strtok(BufRem); % % Count the tokens. % if ( isempty ( tmp ) ) Count = Count + 1; TokenCount = tmp; end end % % Parse the line. % if ( Count ) switch lower ( Token1 ) % % Read the data format. % case format if ( 2 = Co

10、unt ) Format = lower ( Token2 ); if ( Count = 3 & strcmp ( Token3, 1.0 ) ) fclose ( fid ); error(Only PLY format version 1.0 supported.); end end % % Read a comment. % case comment NumComments = NumComments + 1; CommentsNumComments = ; for i = 2 : Count CommentsNumComments = CommentsNumComments,Toke

11、ni, ; end % % Read an element name. % case element if ( 3 = 3 ) NumProperties = NumProperties + 1; eval(tmp=isfield(Elements.,CurElement,TokenCount);,. fclose(fid);error(Error reading property: ,Buf); if ( tmp ) error(Duplicate property name, ,CurElement,.,Token2,.); end % % Add property subfield to

12、 Elements. % eval(Elements.,CurElement,.,TokenCount,=;, . fclose(fid);error(Error reading property: ,Buf); % % Add property subfield to PropertyTypes and save type. % eval(PropertyTypes.,CurElement,.,TokenCount,=Token2:Count-1;, . fclose(fid);error(Error reading property: ,Buf); % % Record property

13、name order. % eval(PropertyNames.,CurElement,NumProperties=TokenCount;, . fclose(fid);error(Error reading property: ,Buf); else fclose ( fid ); if ( isempty(CurElement) ) error(Property definition without element definition: ,Buf); else error(Bad property definition: ,Buf); end end % % End of header

14、. % case end_header break; end end end % % Set reading for specified data format. % if ( isempty ( Format ) ) warning(Data format unspecified, assuming ASCII.); Format = ascii; end switch Format case ascii Format = 0; case binary_little_endian Format = 1; case binary_big_endian Format = 2; otherwise

15、 fclose ( fid ); error(Data format ,Format, not supported.); end % % Read the rest of the file as ASCII data. % if ( Format ) Buf = fscanf ( fid, %f ); BufOff = 1; else % % .or, close the file, and reopen in read binary mode. % fclose ( fid ); % % Reopen the binary file as LITTLE_ENDIAN or BIG_ENDIA

16、N. % if ( Format = 1 ) fid = fopen ( Path, r, ieee-le.l64 ); else fid = fopen ( Path, r, ieee-be.l64 ); end % % Find the end of the header again. % Using ftell on the old handle doesnt give the correct position. % BufSize = 8192; Buf = blanks(10), char(fread(fid,BufSize,uchar) ; i = ; tmp = -11; whi

17、le ( isempty(i) ) i = findstr(Buf,end_header,13,10); % look for end_header + CR/LF i = i,findstr(Buf,end_header,10); % look for end_header + LF if ( isempty(i) ) tmp = tmp + BufSize; Buf = Buf(BufSize+1:BufSize+10),char(fread(fid,BufSize,uchar); end end % % seek to just after the line feed % fseek (

18、 fid, i + tmp + 11 + (Buf(i + 10) = 13), -1 ); end % % Read element data. % % PLY and MATLAB data types (for fread) % PlyTypeNames = char,uchar,short,ushort,int,uint,float,double, . char8,uchar8,short16,ushort16,int32,uint32,float32,double64; MatlabTypeNames = schar,uchar,int16,uint16,int32,uint32,s

19、ingle,double; SizeOf = 1,1,2,2,4,4,4,8; for i = 1 : NumElements % % get current element property information % eval(CurPropertyNames=PropertyNames.,ElementNamesi,;); eval(CurPropertyTypes=PropertyTypes.,ElementNamesi,;); NumProperties = size(CurPropertyNames,2); % fprintf(Reading %s.n,ElementNamesi)

20、; % % Read ASCII data. % if ( Format ) for j = 1 : NumProperties Token = getfield(CurPropertyTypes,CurPropertyNamesj); if ( strcmpi(Token1,list) ) Type(j) = 1; else Type(j) = 0; end % % Glenn Ramsey 20120827 % Initialise Type2 to prevent uninitialised value error. % Type2j = ; end % % Parse the buff

21、er. % if ( any(Type) ) % no list types Data = reshape ( . Buf(BufOff:BufOff+ElementCount(i)*NumProperties-1), . NumProperties, ElementCount(i) ); BufOff = BufOff + ElementCount(i) * NumProperties; else ListData = cell(NumProperties,1); for k = 1 : NumProperties ListDatak = cell(ElementCount(i),1); e

22、nd % % list type % for j = 1 : ElementCount(i) for k = 1 : NumProperties if ( Type(k) ) Data(j,k) = Buf(BufOff); BufOff = BufOff + 1; else tmp = Buf(BufOff); ListDatakj = Buf(BufOff+(1:tmp); BufOff = BufOff + tmp + 1; end end end end % % Read binary data. % else % translate PLY data type names to MA

23、TLAB data type names ListFlag = 0; % = 1 if ere is a list type SameFlag = 1; % = 1 if all types are the same for j = 1 : NumProperties Token = getfield(CurPropertyTypes,CurPropertyNamesj); % % Non-list type. % if ( strcmp(Token1,list ) ) tmp = rem(strmatch(Token1,PlyTypeNames,exact)-1,8)+1; if ( ise

24、mpty(tmp) ) TypeSize(j) = SizeOf(tmp); Typej = MatlabTypeNamestmp; TypeSize2(j) = 0; Type2j = ; SameFlag = SameFlag & strcmp(Type1,Typej); else fclose(fid); error(Unknown property data type, ,Token1, in , . ElementNamesi,.,CurPropertyNamesj,.); end else % list type if ( length(Token) = 3 ) ListFlag

25、= 1; SameFlag = 0; tmp = rem(strmatch(Token2,PlyTypeNames,exact)-1,8)+1; tmp2 = rem(strmatch(Token3,PlyTypeNames,exact)-1,8)+1; if ( isempty(tmp) & isempty(tmp2) ) TypeSize(j) = SizeOf(tmp); Typej = MatlabTypeNamestmp; TypeSize2(j) = SizeOf(tmp2); Type2j = MatlabTypeNamestmp2; lse fclose(fid); error(Unknown property data type, list ,Token2, ,Token3, in , . ElementNamesi,.,CurPropertyNamesj,.); end else

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1