资源简介
matlab开发-stlread。将stl文件读取到matlab补丁兼容的矩阵中。
代码片段和文件信息
function [x y z varargout] = stlread(filename)
% This function reads an STL file in binary format into matrixes X Y and
% Z and C. C is optional and contains color rgb data in 5 bits.
%
% USAGE: [x y z c] = stlread(filename);
%
% To plot use patch(xyzc) or patch(xyz)
%
% Written by Doron Harlev
if nargout>4
error(‘Too many output arguments‘)
end
use_color=(nargout==4);
fid=fopen(filename ‘r‘); %Open the file assumes STL Binary format.
if fid == -1
error(‘File could not be opened check name or path.‘)
end
ftitle=fread(fid80‘uchar=>schar‘); % Read file title
num_facet=fread(fid1‘int32‘); % Read number of Facets
fprintf(‘\ntitle: %s\n‘ char(ftitle‘));
fprintf(‘Num Facets: %d\n‘ num_facet);
% Preallocate memory to save running time
x=zeros(3num_facet); y=zeros(3num_facet); z=zeros(3num_facet);
if use_color
c=uint8(zeros(3num_facet));
end
h = waitbar(0‘Please wait...‘);
for i=1:num_facet
norm=fread(fid3‘float32‘); % normal coordinates ignored for now
ver1=fread(fid3‘float32‘); % vertex 1
ver2=fread(fid3‘float32‘); % vertex 2
ver3=fread(fid3‘float32‘); % vertex 3
col=fread(fid1‘uint16‘); % color bytes
if (bitget(col16)==1 & use_color)
r=bitshift(bitand(2^16-1 col)-10);
g=bitshift(bitand(2^11-1 col)-5);
b=bitand(2^6-1 col);
c(:i)=[r; g; b];
end
x(:i)=[ver1(1); ver2(1); ver3(1)]; % convert to matlab “patch“ compatible format
y(:i)=[ver1(2); ver2(2); ver3(2)];
z(:i)=[ver1(3); ver2(3); ver3(3)];
if mod(ifloor(num_facet/10))==0
waitbar(i/num_faceth);
end
end
if use_color
varargout(1)={c};
end
fclose(fid);
close(h);
% For more information http://rpdrc.ic.polyu.edu.hk/old_files/stl_binary_format.htm
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1840 2018-07-11 20:18 stlread.m
- 上一篇:matlab开发-彩色图像对比度增强
- 下一篇:matlab开发-单相动态电压调节器
相关资源
- matlab开发-三维图像堆栈查看器
- matlab开发-动态电压恢复器故障dvr
- matlab开发-数据处理的分组方法GMDH
- matlab开发-DVR
- matlab开发-ParetoSet
- matlab开发-ShamirsSecretSharing
- matlab开发-othellom
- matlab开发-EMGONOFF
- matlab开发-级联H桥多电平转换三相
- matlab开发-带图形用户界面的步进电机
- matlab开发-MFTireGUI
- matlab开发-自适应霍夫曼编码技术字符
- matlab开发-ConnectFour
- matlab开发-floodfillscanline
- matlab开发-Paretosurfacenavigator
- matlab开发-分步序达尔文粒子群优化
- matlab开发-改进的解决方案经济调度方
- matlab开发-为Resnet50网络设计工具箱模
- matlab开发-sigmoid
- matlab开发-同步发电机的详细模型,包
- matlab开发-多层反向传播神经网络
- matlab开发-Parrotminirones的模拟支持包
- matlab开发-nnsysid
- matlab开发-使用gnewton-raphson方法查找任
- matlab开发-UR5控制Matlab
-
matlab开发-mssamultiob
jectivesalpswarmalg - matlab开发-Vasicek
- matlab开发-直流到全桥逆变器
- matlab开发-使用xFoiland ParseCGeometric参数
- matlab开发-如何模拟6到10个输入状态空
评论
共有 条评论