Home > vbmeg > external > iso2mesh > savestl.m

savestl

PURPOSE ^

SYNOPSIS ^

function savestl(node,elem,fname,solidname)

DESCRIPTION ^

 savestl(node,elem,fname,solidname)

 save a tetrahedral mesh to an STL (Standard Tessellation Language) file

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2012/02/14

 input:
      node: input, surface node list, dimension Nx3
      elem: input, tetrahedral element list; if size(elem,2)==3, it is a surface
      fname: output file name
      solidname: an optional string for the name of the object

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function savestl(node,elem,fname,solidname)
0002 %
0003 % savestl(node,elem,fname,solidname)
0004 %
0005 % save a tetrahedral mesh to an STL (Standard Tessellation Language) file
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2012/02/14
0009 %
0010 % input:
0011 %      node: input, surface node list, dimension Nx3
0012 %      elem: input, tetrahedral element list; if size(elem,2)==3, it is a surface
0013 %      fname: output file name
0014 %      solidname: an optional string for the name of the object
0015 %
0016 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0017 %
0018 
0019 fid=fopen(fname,'wt');
0020 if(fid==-1)
0021     error('You do not have permission to save mesh files.');
0022 end
0023 
0024 if(nargin<4) 
0025     solidname='';
0026 end
0027 fprintf(fid,'solid %s\n', solidname);
0028 
0029 if(nargin<3)
0030     error('incomplete input');
0031 end
0032 if(isempty(node) || size(node,2)<3)
0033     error('invalid node input');
0034 end
0035 if(~isempty(elem))
0036   if(size(elem,2)>=5)
0037     elem(:,5:end)=[];
0038   end
0039   if(size(elem,2)==4)
0040     elem=meshreorient(node,elem);
0041     elem=volface(elem);
0042   end
0043   ev=surfplane(node,elem);
0044   ev=ev(:,1:3)./repmat(sqrt(sum(ev(:,1:3).*ev(:,1:3),2)),1,3);
0045   len=size(elem,1);
0046   for i=1:len
0047       fprintf(fid,['facet normal %e %e %e\n' ...
0048                    ' outer loop\n' ...
0049                    '  vertex %e %e %e\n' ...
0050                    '  vertex %e %e %e\n' ...
0051                    '  vertex %e %e %e\n' ...
0052                    ' endloop\n' ...
0053                    'endfacet\n'], [ev(i,:)',node(elem(i,:),1:3)']);
0054   end
0055 end
0056 
0057 fprintf(fid,'endsolid %s\n', solidname);
0058 
0059 fclose(fid);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005