0001 function mdl = gmsh_stl2tet(stlfile, maxh, extra)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 if nargin < 3
0025 extra = [];
0026 end
0027 if nargin > 1 && ~isempty(maxh)
0028 extra = [' -clmax ' num2str(maxh), ' ', extra];
0029 end
0030
0031 if isstruct(stlfile)
0032 opt.cache_obj = {stlfile.vertices, stlfile.faces};
0033 mdl = eidors_cache(@do_gmsh_stl2tet,{stlfile, extra}, opt);
0034 else
0035 mdl = do_gmsh_stl2tet(stlfile, extra);
0036 end
0037
0038
0039
0040 function mdl = do_gmsh_stl2tet(stlfile, extra)
0041 if isstruct(stlfile)
0042 stem = tempname;
0043 stl_write(stlfile, [stem, '.stl'])
0044 stlname = [stem '.stl'];
0045 else
0046 stem = strrep(stlfile,'.stl','');
0047 stlname = stlfile;
0048 end
0049
0050 fid = fopen([stem '.geo'],'w');
0051 fprintf(fid,'Merge "%s";\n',stlname);
0052 fprintf(fid,'Surface Loop(1) = {1};\n');
0053 fprintf(fid,'Volume(2) = {1};\n');
0054 fprintf(fid,'Physical Volume(3) = {2};\n');
0055 fprintf(fid,'Mesh.Algorithm3D=4;\n');
0056 fprintf(fid,'Mesh.OptimizeNetgen=1;\n');
0057 fclose(fid);
0058
0059 call_gmsh([stem '.geo'], 3, extra);
0060
0061 mdl = gmsh_mk_fwd_model([stem '.msh'],[],[],[]);
0062
0063 delete([stem '.geo']);
0064 delete([stem '.msh']);
0065 if isstruct(stlfile)
0066 delete(stlname);
0067 end