read .off file in matlab
来源:互联网 发布:卧龙01坐骑进阶数据 编辑:程序博客网 时间:2024/06/05 18:02
OFF 文件格式如下:
OFF441 800 00 0 00.05 0 00.1 0 00.15 0 0...0.9 1 00.95 1 01 1 03 0 1 223 0 22 21...3 397 398 4193 397 419 4183 418 419 4403 418 440 439
matlab文件如下:
function [V,F,UV,C,N] = readOFF( filename ) % READOFF reads an OFF file with vertex/face information % % [V,F,UV,C,N] = readOFF( filename ) % % Input: % filename path to .obj file % Outputs: % V #V by 3 list of vertices % F #F by 3 list of triangle indices % UV #V by 2 list of texture coordinates % C #V by 3 list of colors % N #V by 3 list of normals % % See also: load_mesh, readOBJfast, readOBJ% (C) 2007 Denis Kovacs, NYU%------------------------------------------------------------------------- V = []; F = []; UV = []; C = []; N = []; fp = fopen( filename, 'r' ); OFFheader = upper(fscanf( fp, '%s\n', 1 )); if (OFFheader(end-2:end) ~= 'OFF') warning('no OFF file!'); return; end OFFdim = 3; OFF_N = 0; OFF_C=0; OFF_ST=0; if find(OFFheader=='N') OFFdim = OFFdim+3; OFF_N=1; end if find(OFFheader=='C') OFFdim = OFFdim+3; OFF_C=1; end if find(OFFheader=='S') OFFdim = OFFdim+2; OFF_ST=1; end d = fscanf( fp, '%d', 3); nV = d(1); nF = d(2); nE = d(3); disp(sprintf(' - Reading %d vertices', nV)); switch OFFdim case 3; OFFV = textscan( fp, '%f %f %f', nV); case 5; OFFV = textscan( fp, '%f %f %f %f %f', nV); case 6; OFFV = textscan( fp, '%f %f %f %f %f %f', nV); case 7; OFFV = textscan( fp, '%f %f %f %f %f %f %f', nV); case 8; OFFV = textscan( fp, '%f %f %f %f %f %f %f %f', nV); case 9; OFFV = textscan( fp, '%f %f %f %f %f %f %f %f %f', nV); case 10; OFFV = textscan( fp, '%f %f %f %f %f %f %f %f %f %f', nV); case 11; OFFV = textscan( fp, '%f %f %f %f %f %f %f %f %f %f %f', nV); otherwise; error('Unsupported number of vertex entries'); end try OFFV = cell2mat(OFFV); end OFFdim = 1; V = OFFV(:,OFFdim:(OFFdim+2)); OFFdim = OFFdim + 3; if (OFF_N) N = OFFV(:,OFFdim:(OFFdim+2)); OFFdim = OFFdim + 3; end if (OFF_C) C = OFFV(:,OFFdim:(OFFdim+2)); OFFdim = OFFdim + 3; end if (OFF_ST) UV = OFFV(:,OFFdim:(OFFdim+1)); OFFdim = OFFdim + 2; end if (nF ~= 0) disp(sprintf(' - Reading %d faces', nF)); F = cell2mat( textscan( fp, '%d %d %d %d %d %d', nF ) ); F = double(F(:, 2:(F(1,1)+1) ) + 1 ); else F = []; end disp(' - done.');end
执行命令:
[V,F,UV,C,N] = readOFF( 'square_21.off' )我们得到
- Reading 441 vertices
- Reading 800 faces
- done.
0 0
- read .off file in matlab
- read obj in matlab
- Read File in Python
- Parallel mex file in Matlab
- read file in kernel (flip_open and flip_close)
- read UTF-8 text file in C++
- Read properties file in a jar
- Read the Last line in a file
- How to read Json file or text file in Spark
- LibSVM scale-svm file in matlab
- Save .mat file in older version matlab
- how to change file names in matlab
- File Read
- read file
- .off文件格式(Object file format(.off))简介
- How to read file in Java – BufferedInputStream Example
- A simple way to read an XML file in Java
- could not read symbols: File in wrong format
- 用开关控制LED(五)
- 类加载机制
- CentOS与linux端口的开放与关闭
- HDU 2029 Palindromes _easy version(字符串)
- ACM第三次练习—1002
- read .off file in matlab
- 狸猫的面试——项目描述——视频通信
- WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptRes
- Java中的String字符串为什么不可变
- Reverse a binary tree in O(1)
- Android:通过build gradle中的buildTypes设置自动log开关(二)
- Centos7上使用官方YUM源安装Mysql
- 高数小知识点(2)
- 剑指offer之编程(六)