0001 function savestl(node,elem,fname,solidname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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);