• 大小: 3KB
    文件类型: .m
    金币: 2
    下载: 0 次
    发布日期: 2024-01-04
  • 语言: Matlab
  • 标签: matlab  

资源简介

基于matlab读取stl文件并去除文件中的冗余点建立拓扑结构,方便后续操作。

资源截图

代码片段和文件信息

function [nnum node_xyz face_node face_normal ] = stl_read ( ...
 filename node_num face_num)
fid=fopen(filename ‘r‘);
if fid == -1 
    error(‘文件打开错误!.‘)
end
format long
%定义变量
nnum=0;
fnum=0;
f=0;                                    % 记录重合点的个数
l=0;                                     % 标识重合点
m=0; %标识面点
p = node_num/3;
v=zeros ( 3 node_num);
face_node = zeros ( 3 face_num );
face_normal = zeros ( 3 face_num );
node= zeros ( 3 face_num);
%开始读整个文件,直到结束符为止
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
 %disp(sprintf(fword));
%保存向量
if strncmpi(fword ‘facetnormal‘11) == 1;
    %L=L+1; disp(L);disp(sprintf(tline));
       STLnormal = sscanf(tline ‘%*s %*s %12f %12f %12f‘);
    %disp(STLnormal);
      fnum = fnum + 1;
      n(:fnum) = STLnormal;
end                                         

%检查坐标
if strncmpi(fword ‘vertex‘6) == 1;    % Checking if a “V“ertex line as “V“ is 1st char.
       %disp(sprintf(tline));
       STLxyz= sscanf(tline ‘%*s %f %f %f‘); % & if a V get the XYZ data of it.
         %disp(STLxyz);
       %disp(nnum);
  if nnum == 0
         nnum = nnum + 1;
         v(:nnum)=STLxyz;
         node(1fnum) =nnum ; 

评论

共有 条评论