function [ node_xyz, face_node, face_normal, ierror ] = stla_read ( ...
input_file_name, node_num, face_num )
%% STLA_READ reads graphics information from an ASCII StereoLithography file.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 25 September 2005
%
% Author:
%
% John Burkardt
%
% Reference:
%
% 3D Systems, Inc,
% Stereolithography Interface Specification,
% October 1989.
%
% Parameters:
%
% Input, string INPUT_FILE_NAME, the name of the input file.
%
% Input, integer NODE_NUM, the number of vertices defined.
%
% Input, integer FACE_NUM, the number of faces defined.
%
% Output, real NODE_XYZ(3,NODE_NUM), the coordinates of points.
%
% Output, integer FACE_NODE(3,FACE_NUM), the nodes that make up each face.
%
% Output, real FACE_NORMAL(3,FACE_NUM), the normal vector
% at each face.
%
ierror = 0;
state = 0;
text_num = 0;
face = 0;
node = 0;
node_xyz = zeros ( 3, node_num );
face_node = zeros ( 3, face_num );
face_normal = zeros ( 3, face_num );
%
% Open the file.
%
iunit = fopen ( input_file_name, 'r' );
if ( iunit < 0 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' Could not open the file "%s".\n', input_file_name );
ierror = 1;
return
end
%
% Read the next line of text.
%
while ( 1 )
text = fgetl ( iunit );
if ( text == -1 )
if ( state ~= 0 & state ~= 1 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' End-of-file, but model not finished.\n' );
ierror = 1;
return
end
break;
end
text_num = text_num + 1;
done = 1;
%
% Read the first word in the line.
%
[ word1, done ] = word_next_read ( text, done );
%
% "Doctor" the text, changing a beginning occurrence of:
%
% END FACET to ENDFACET
% END LOOP to ENDLOOP
% END SOLID to ENDSOLID
% FACET NORMAL to FACETNORMAL
% OUTER LOOP to OUTERLOOP
%
if ( s_eqi ( word1, 'END' ) )
[ word2, done ] = word_next_read ( text, done );
if ( ~s_eqi ( word2, 'FACET' ) & ...
~s_eqi ( word2, 'LOOP' ) & ...
~s_eqi ( word2, 'SOLID' ) )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' The tag END was followed by an illegal\n' );
fprintf ( 1, ' word: "%s", when expecting\n', word );
fprintf ( 1, ' "FACET", "LOOP", or "SOLID".\n' );
ierror = 1;
return
end
word1 = s_cat ( word1, word2 );
elseif ( s_eqi ( word1, 'FACET' ) )
[ word2, done ] = word_next_read ( text, done );
if ( ~s_eqi ( word2, 'NORMAL' ) )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' The tag FACET was followed by an illegal\n' );
fprintf ( 1, ' word: "%s", when expecting\n', word2 );
fprintf ( 1, ' "NORMAL".\n' );
ierror = 1;
return
end
word1 = s_cat ( word1, word2 );
elseif ( s_eqi ( word1, 'OUTER' ) )
[ word2, done ] = word_next_read ( text, done );
if ( ~s_eqi ( word2, 'LOOP' ) )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' The tag OUTER was followed by an illegal\n' );
fprintf ( 1, ' word: "%s", when expecting\n', word2 );
fprintf ( 1, ' "LOOP".\n' );
ierror = 1;
return
end
word1 = s_cat ( word1, word2 );
end
%
% This first word tells us what to do.
%
% SOLID - begin a new solid.
% Valid in state 0, moves to state 1.
% ENDSOLID - end current solid.
% Valid in state 1, moves to state 0.
%
% FACETNORMAL - begin a new facet.
% Valid in state 0 or 1, moves to state 2.
% ENDFACET - end current facet.
% Valid in state 2, moves to state 1.
%
% OUTERLOOP - begin a list of vertices.
% Valid in state 2, moves to state 3, sets vertex count to 0.
% ENDLOOP - end vertex list.
% Valid in state 3, moves to state 2.
%
% VERTEX - give coordinates of next vertex.
% Valid in state 3.
%
% End of file -
% Valid in state 0 or 1.
%
if ( s_eqi ( word1, 'SOLID' ) )
if ( state ~= 0 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' A new SOLID statement was encountered, but we\n' );
fprintf ( 1, ' have not finished processing the current solid.\n' );
ierror = 1
return
end
state = 1;
elseif ( s_eqi ( word1, 'ENDSOLID' ) )
if ( state ~= 1 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' An END SOLID statement was encountered, but\n' );
fprintf ( 1, ' either we have not begun a solid at all, or we\n' );
fprintf ( 1, ' are not at an appropriate point to finish the\n' );
fprintf ( 1, ' current solid.\n' );
ierror = 1;
return
end
state = 0;
elseif ( s_eqi ( word1, 'FACETNORMAL' ) )
if ( state ~= 0 & state ~= 1 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' Model not in right state for FACET.\n' );
ierror = 1;
return
end
state = 2;
face = face + 1;
if ( face_num < face )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Warning!\n' );
fprintf ( 1, ' More faces being read than expected.\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
ierror = 1;
return
end
for i = 1 : 3
face_normal(i,face) = 0.0;
[ word2, done ] = word_next_read ( text, done );
if ( done )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' End of information while reading a component\n' );
fprintf ( 1, ' of the normal vector.\n' );
ierror = 1;
return
end
[ dval, lchar, ierror ] = s_to_r8 ( word2 );
if ( ierror ~= 0 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' Reading a component of the normal vector.\n' );
ierror = 1;
return
end
face_normal(i,face) = dval;
end
elseif ( s_eqi ( word1, 'ENDFACET' ) )
if ( state ~= 2 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' Model not in right state for ENDFACET.\n' );
ierror = 1;
return
end
state = 1;
elseif ( s_eqi ( word1, 'OUTERLOOP' ) )
if ( state ~= 2 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' Model not in right state for OUTERLOOP.\n' );
ierror = 1;
return
end
state = 3;
vertex = 0;
elseif ( s_eqi ( word1, 'ENDLOOP' ) )
if ( state ~= 3 )
fprintf ( 1, '\n' );
fprintf ( 1, 'STLA_READ - Fatal error!\n' );
fprintf ( 1, ' File line number = %d\n', text_num );
fprintf ( 1, ' Model not in right state for ENDLOOP.\n' );
ierror = 1;
return
没有合适的资源?快使用搜索试试~ 我知道了~
SSTL_DISPLAY_T.rar_STL拓扑_matlab stl_matlab stl点_stl matlab_stl显示
共24个文件
m:15个
stla:4个
png:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 191 浏览量
2022-09-24
04:36:11
上传
评论
收藏 101KB RAR 举报
温馨提示
STL文件读取程序(Matlab):可以将ASCII格式的的STL文件中的数据点信息及网格拓扑信息读出,并显示在屏幕上
资源推荐
资源详情
资源评论
收起资源包目录
SSTL_DISPLAY_T.rar (24个子文件)
SSTL_DISPLAY_T
STL_DISPLAY_Display
block100.png 11KB
bottle.png 24KB
s_eqi.m 957B
stla_read.m 10KB
stla_display.m 2KB
humanoid_tri.png 12KB
stla_size.m 5KB
s_len_trim.m 530B
block100.stla 3KB
s_cat.m 978B
s_to_r8.m 5KB
word_next_read.m 3KB
ch_cap.m 442B
s_escape_tex.m 1KB
stla_size_print.m 1KB
bottle.stla 288KB
humanoid_tri.stla 19KB
ch_eqi.m 601B
timestamp.m 337B
cube.png 6KB
ch_is_digit.m 517B
STLA_DISPLAY - Display an ASCII STL 3D Graphics File.mht 9KB
cube.stla 2KB
ch_to_digit.m 727B
共 24 条
- 1
资源评论
四散
- 粉丝: 49
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功