把STL文件ACSII格式读入matlab
来源:互联网 发布:西门子s7 300编程软件 编辑:程序博客网 时间:2024/05/22 04:33
function [fout, vout, cout] = ReadSTLACSII(filename)
fid=fopen(filename, 'r');
if fid == -1
error('文件打开错误!.')
end
%读取文件头,STL文件第一行是文件名
File_name = sscanf(fgetl(fid), '%*s %s'); %CAD object name, if needed.
%定义变量
vnum=0; %Vertex number counter.
report_num=0; %Report the status as we go.
STLvcolor = 0;
STLxyz=0;
%开始读整个文件,直到结束符为止
while feof(fid) == 0 % test for end of file, if not then do stuff
tline = fgetl(fid); % reads a line of data from file.
fword = sscanf(tline, '%s'); % make the line a character string
%检查颜色
if strncmpi(fword, 'facet normal',12) == 1; % Checking if a "C"olor line, as "C" is 1st char.
STLvcolor = sscanf(tline, '%*s %f %f %f'); % & if a C, get the RGB color data of the face. % we "*s" skip the name "color" and get the data.
end % Keep this color, until the next color is used.
%检查坐标
if strncmpi(fword, 'vertex',6) == 1; % Checking if a "V"ertex line, as "V" is 1st char.
STLxyz= sscanf(tline, '%*s %lf %lf %lf'); % & if a V, get the XYZ data of it.
vnum = vnum + 1;
end
%检查坐标是否增加
if vnum~=report_num
report_num=vnum;
v(:,vnum)=STLxyz;
c(:,vnum) = STLvcolor; % A color for each vertex, which will color the
if mod(report_num,249)==0;
disp(sprintf('Reading vertix num: %d.',vnum));
end
end
end
%关闭文件
fclose(fid);
% Build face list; The vertices are in order, so just number them.
fnum = vnum/3; %Number of faces, vnum is number of vertices. STL is triangles.
flist = 1:vnum; %Face list of vertices, all in order.
F = reshape(flist, 3,fnum); %Make a "3 by fnum" matrix of face list data.
%
% Return the faces and vertexs.
%
fout = F'; %Orients the array for direct use in patch.
vout = v'; % "
cout = c';
end
fid=fopen(filename, 'r');
if fid == -1
error('文件打开错误!.')
end
%读取文件头,STL文件第一行是文件名
File_name = sscanf(fgetl(fid), '%*s %s'); %CAD object name, if needed.
%定义变量
vnum=0; %Vertex number counter.
report_num=0; %Report the status as we go.
STLvcolor = 0;
STLxyz=0;
%开始读整个文件,直到结束符为止
while feof(fid) == 0 % test for end of file, if not then do stuff
tline = fgetl(fid); % reads a line of data from file.
fword = sscanf(tline, '%s'); % make the line a character string
%检查颜色
if strncmpi(fword, 'facet normal',12) == 1; % Checking if a "C"olor line, as "C" is 1st char.
STLvcolor = sscanf(tline, '%*s %f %f %f'); % & if a C, get the RGB color data of the face. % we "*s" skip the name "color" and get the data.
end % Keep this color, until the next color is used.
%检查坐标
if strncmpi(fword, 'vertex',6) == 1; % Checking if a "V"ertex line, as "V" is 1st char.
STLxyz= sscanf(tline, '%*s %lf %lf %lf'); % & if a V, get the XYZ data of it.
vnum = vnum + 1;
end
%检查坐标是否增加
if vnum~=report_num
report_num=vnum;
v(:,vnum)=STLxyz;
c(:,vnum) = STLvcolor; % A color for each vertex, which will color the
if mod(report_num,249)==0;
disp(sprintf('Reading vertix num: %d.',vnum));
end
end
end
%关闭文件
fclose(fid);
% Build face list; The vertices are in order, so just number them.
fnum = vnum/3; %Number of faces, vnum is number of vertices. STL is triangles.
flist = 1:vnum; %Face list of vertices, all in order.
F = reshape(flist, 3,fnum); %Make a "3 by fnum" matrix of face list data.
%
% Return the faces and vertexs.
%
fout = F'; %Orients the array for direct use in patch.
vout = v'; % "
cout = c';
end
- 把STL文件ACSII格式读入matlab
- C#读取ACSII格式的STL格式
- matlab批读入文件dir
- matlab 逐行从文件读入
- Matlab如何批量读入文件
- 趣谈MATLAB的图像读入格式问题
- OpenCV读入Matlab标定结果的格式
- 基于matlab读入指定文件夹下的指定格式的文件
- 把STL转为ACT格式
- 【stl】copy读入文件|插入迭代器
- Demo:把文件内容读入一个String
- C\C++把TXT文件读入内存
- 如何把文件中的数据读入程序
- 深入C语言把文件读入字符串
- Matlab写序列txt文件,VS读入
- matlab---调用.exe文件,批量写入读入
- matlab读取stl文件
- C++读入obj格式模型文件
- java读书笔记----关于java中的static
- 寻找数组中最大值和最小值
- 美化DataGridView控件
- Just a Hook
- App Store上架注意事项
- 把STL文件ACSII格式读入matlab
- SSH框架单元测试工具类
- 【整理】SIMD、MMX、SSE、AVX、3D Now!、neon
- 实例解说Linux中fdisk分区使用方法
- Android学习15--使用(Drawable)资源
- 项目管理/研发管理过程中的一些感悟
- [CTSC99]拯救大兵瑞恩
- 学习总结之ETH OAM:Y.1731与CFM
- 史上最经典的Linux内核学习方法论