如何用MATLAB读stl并显示点云文件
function [VertexData,FVCD,isBinary]=stl2matlab(stlfile)
% STL2MATLAB reads STL-file, ASCII or binary format, into Matlab
%
% Usage:
%
% [VertexData, FVCD]=stl2matlab(stlfile)
%
% Input:
%
% stlfile - STL-file
%
% Output:
%
% VertexData - Cellarray containing matrices with vertices
% FVCD - FaceVertexColorData
% isBinary - Flag with STL-file information
%
% To plot the STL-object use plotSTL(VertexData) or plotSTL(VertexData,FVCD)
%
% m-file can be downloaded at
% http://www.mathworks.com/matlabcentral/fileexchange/13253-iges-toolbox
%
% written by Per Bergstrm --
% if nargin ==
warning('No STL-file is specified');
end VertexData=cell(,); try % Try to read an STL ASCII file
[VertexData{}, VertexData{}, VertexData{}, FVCD] = stlAread(stlfile);
isBinary=false; catch try % Try to read an STL binary file
[VertexData{}, VertexData{}, VertexData{}, FVCD] = stlBread(stlfile);
isBinary=true; catch error('File could not be read!') end end function [X, Y, Z, FVCD] = stlAread(stlfile)
% Reads an STL ASCII file fid=fopen(stlfile,'r'); fileTitle=sscanf(fgetl(fid),'%*s %s'); vnum=;
fclr=;
testASCII=true;
lineCount=; while feof(fid) ==
stlLine=fgetl(fid);
keyWord=sscanf(stlLine,'%s');
if strncmpi(keyWord,'c',) == ;
fclr=sscanf(stlLine,'%*s %f %f %f');
elseif strncmpi(keyWord,'v',) == ;
vnum=vnum+;
vertex(:,vnum)=sscanf(stlLine,'%*s %f %f %f');
clr(:,vnum)=fclr;
elseif testASCII
lineCount=lineCount+;
if lineCount>
if vnum>
testASCII=false;
else
error('File is not an STL ASCII file!')
end
end
end
end X=[vertex(,::end);vertex(,::end);vertex(,::end)];
Y=[vertex(,::end);vertex(,::end);vertex(,::end)];
Z=[vertex(,::end);vertex(,::end);vertex(,::end)]; FVCD=reshape(clr,,vnum/); fclose(fid); function [X, Y, Z, FVCD] = stlBread(stlfile)
% Reads an STL binary file fid=fopen(stlfile,'r'); fileTitle=fread(fid,,'uchar=>schar');
fnum=fread(fid,,'int32'); X=zeros(,fnum);
Y=zeros(,fnum);
Z=zeros(,fnum); FVCD=uint8(zeros(,fnum)); for i=:fnum,
normal=fread(fid,,'float32');
vertex1=fread(fid,,'float32');
vertex2=fread(fid,,'float32');
vertex3=fread(fid,,'float32');
clr=fread(fid,,'uint16');
if bitget(clr,)==
rd=bitshift(bitand(,clr),-);
grn=bitshift(bitand(,clr),-);
bl=bitand(,clr);
FVCD(:,i)=[rd;grn;bl];
end
X(:,i)=[vertex1(); vertex2(); vertex3()];
Y(:,i)=[vertex1(); vertex2(); vertex3()];
Z(:,i)=[vertex1(); vertex2(); vertex3()];
end fclose(fid);
把这个函数放到Matlab中去,然后
b = figure();
model = stl2matlab('rawmodel-983.stl');
patch(model{},model{},model{},'b');
axis equal;
view(,);
mesh(x, y,z);
title('topographie map')
具体什么原理不太懂,反正这样真的可以
就是图丑了一点2333333333333333333
如何用MATLAB读stl并显示点云文件的更多相关文章
- Java使用FileReader(file)、readLine()读取文件,以行为单位,一次读一行,一直读到null时结束,每读一行都显示行号。
//Java使用FileReader(file).readLine()读取文件,以行为单位,一次读一行,一直读到null时结束,每读一行都显示行号. public static void readFi ...
- 如何解决 Matlab 画图时中文显示乱码的问题?
使用的是win10系统,从前几个月某一天,我的matlab的figure里的中文都变成了口口.很是郁闷,还以为是动到了什么配置引起的. 前几天更新了matlab 2018b,发现还有这个问题.就觉得不 ...
- matlab中的输出显示函数
matlab中的输出显示函数 在matlab中使用的显示函数有disp.sprintf.fprintf比较常用.下面来介绍一下他们的用法. 1.disp()函数: disp(x)主要是用来输出变量x的 ...
- Matlab 用fread、fwrite实现大文件读写
最近在分析一个35G的大数据文件,猛一看,是不是很吓人啊,不过还好,师兄写文件的格式非常规范,读取数据来也就很方便了,主要是使用了读写文件的两个函数fread和fwrite,下面用matlab简单尝试 ...
- Matlab中调用VS编译的exe文件并传递变量 的方法
经历::在网上找了很多方法,都没有实现在matlab中调用vs的exe文件并且能够传递变量参数,一些小细节花费了自己很多时间,比喻忽略了一些空格! 网上很多的方法都是纯粹复制别人的方法,自己都没有去 ...
- Visual Studio 打开解决方案后 弹出框显示 "正在打开文件..." 迟迟没反应 的解决方法
Visual Studio 打开解决方案后 弹出框显示 "正在打开文件...",任务管理器的devenv进程又很正常,不会显示"未响应". 而IDE的左下角有个 ...
- vim——打开多个文件、同时显示多个文件、在文件之间切换
打开多个文件: 1.vim还没有启动的时候: 在终端里输入 vim file1 file2 ... filen便可以打开所有想要打开的文件 2.vim已经启动 输入 :open file 可以再打开 ...
- PCL Show Point Cloud 显示点云
在使用PCL库的时候,经常需要显示点云,可以用下面这段代码: #include <pcl/visualization/cloud_viewer.h> pcl::PointCloud< ...
- 在xcode运行编译时,编译成功,但项目中显示缺少该文件,这是只要关闭重启xcode即可。
在xcode运行编译时,编译成功,但项目中显示缺少该文件,这是只要关闭重启xcode即可.
随机推荐
- SQL Server获取星期几
上一周在解决一个Bug的时候,需要在SQL Server获取星期几的需求,在网上搜索了下,发现一篇好的文章,特转载下! 今天是星期几,例子 1: 1 SET LANGUAGE N'English' - ...
- 申请Let's Encrypt永久免费SSL证书
Let's Encrypt简介 Let's Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla.Cisco.Akamai.IdenTrust.EFF等组织人员发起 ...
- 通过excel创建表
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- UITableView自定义Cell中,纯代码编程动态获取高度
在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:( ...
- Office2010安装出现“错误1907”的解决方法(未验证)
http://bbs.pcbeta.com/viewthread-1627988-1-5.html 这个问题我遇到过.解决方法:1.安装时提示错误选择忽略,安装完成后.2.如果能正常使用OFFICE软 ...
- sql 查询结果自定义排序
sqlserver 使用case when then 语句来实现 select name from fruit order by case name end oracle 使用decode实现 ,,, ...
- windows下面配合thinkphp5.1.7的nginx.conf内容
参考了https://blog.csdn.net/yangjiale521/article/details/77623514 感谢该作者 #user nobody;worker_processes 1 ...
- MySQL data type
MySQL数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 数值类型 MySQL支持所有标准SQ ...
- 决策树(decision tree)
决策树是一种常见的机器学习模型.形象地说,决策树对应着我们直观上做决策的过程:经由一系列判断,得到最终决策.由此,我们引出决策树模型. 一.决策树的基本流程 决策树的跟节点包含全部样例,叶节点则对应决 ...
- 使用Microsoft自带的小工具将可执行文件(.exe)注册为系统服务
首先,我们从Microsoft下载Windows Resource Kits,Download 下载完成后,运行rktools.exe进行安装. 安装完成后,我们打开安装目录,将其中的"in ...