Home > vbmeg > external > iso2mesh > savevrml.m

savevrml

PURPOSE ^

SYNOPSIS ^

function savevrml(node,face,elem,fname)

DESCRIPTION ^

 savevrml(node,face,elem,fname)

 save a surface mesh to VRML 1.0 format

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2010/04/25

 input:
      node: input, surface node list, dimension (nn,3)
      face: input, surface face element list, dimension (be,3)
      elem: input, tetrahedral element list, dimension (ne,4)
      fname: output file name

 -- 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 savevrml(node,face,elem,fname)
0002 %
0003 % savevrml(node,face,elem,fname)
0004 %
0005 % save a surface mesh to VRML 1.0 format
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2010/04/25
0009 %
0010 % input:
0011 %      node: input, surface node list, dimension (nn,3)
0012 %      face: input, surface face element list, dimension (be,3)
0013 %      elem: input, tetrahedral element list, dimension (ne,4)
0014 %      fname: output file name
0015 %
0016 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0017 %
0018 
0019 if(nargin==2)
0020    fname=face;
0021    face=[];
0022    elem=[];
0023 end
0024 
0025 if(nargin==3)
0026    fname=elem;
0027    elem=[];
0028 end
0029 
0030 fid=fopen(fname,'wt');
0031 if(fid==-1)
0032     error('You do not have permission to save mesh files.');
0033 end
0034 
0035 fprintf(fid,'#VRML V1.0 ascii\n#Generated by iso2mesh (http://iso2mesh.sf.net)\n');
0036 fprintf(fid,'Separator {\nSwitch {\n\tDEF %s\n\tSeparator {\n',fname);
0037 
0038 if(~isempty(node))
0039   node=node(:,1:3);
0040   fprintf(fid,'\t\tCoordinate3 {\n\t\t\tpoint [\n');
0041   fprintf(fid,'%.16f %.16f %.16f,\n',node');
0042   fprintf(fid,'\t\t\t]\n\t\t}\n');
0043 end
0044 
0045 if(~isempty(face))
0046   face=face(:,1:3);
0047   fprintf(fid,'\t\tIndexedFaceSet {\n\t\t\tcoordIndex [\n');
0048   fprintf(fid,'%d %d %d -1\n',(face-1)');
0049   fprintf(fid,'\t\t\t]\n\t\t}\n');
0050 end
0051 
0052 fprintf(fid,'\t} # Separator\n}\n}\n');
0053 
0054 fclose(fid);

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