-
%Copyright 2018 John Moosemiller
%Permission is
hereby granted, free of charge, to any person
obtaining a
copy
of
this
software
and
associated
documentation
files
(the
to deal in the Software
without restriction, including without limitation
the rights to use, copy, modify, merge,
publish, distribute, sublicense,
and/or
sell
copies
of
the
Software,
and
to
permit
persons
to
whom
the
Software
is furnished to do
so, subject to the following
conditions:
%The above copyright notice and this
permission notice shall be included
in
all copies or substantial portions of the
Software.
%THE SOFTWARE IS PROVIDED
OR
IMPLIED,
INCLUDING
BUT
NOT
LIMITED
TO
THE
WARRANTIES
OF
MERCHANTABILITY,
FITNESS
FOR
A
PARTICULAR
PURPOSE
AND
NONINFRINGEMENT.
IN
NO
EVENT
SHALL
THE
AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER
LIABILITY,
WHETHER
IN
AN
ACTION
OF
CONTRACT,
TORT
OR
OTHERWISE,
ARISING
FROM,
OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN
THE SOFTWARE.
function
[vertices, faces,
color] = stlread(filename)
%
This function reads an STL file in binary format
into matrixes vertices
% and
faces which can be used by patch to view the
stl.
%
% MATLAB code by Doron
Harlev
% Octave edits by
John Moosemiller && @zmughal
read_norm = 0;
% whether we want to read the face
normals
% Process arguments {{{
if
nargout > 3
error(
'Too many output
arguments'
);
end
use_color = (
nargout == 3 );
% }}}
% Open the
file, assumes STL Binary format. {{{
fid=fopen(filename,
'r'
);
if
( fid == -1)
error(
'File could not be
opened, check name or
path.'
)
end
% }}}
% Read in
header {{{
ftitle =
fread(fid, 80,
'uchar=>schar'
);
% Read file title
num_facet = fread(fid, 1,
'int32'
);
% Read
number of Facets
fprintf(
'nTitle:
%sn'
, char(ftitle'));
fprintf(
'Num Facets:
%dn'
, num_facet);
% }}}
% Preallocate memory to
save running time {{{
vertices = zeros( 3 * num_facet, 3
);
faces = zeros(
num_facet, 3 );
if
use_color
color = uint8( zeros( 3, num_facet
) );
end
-
-
-
-
-
-
-
-
-
上一篇:图的遍历实现实验报告2011021225陈曦路
下一篇:arcgis学习心得