[srf,vtx,fc,bc,simp,edg,mat_ind] = ng_read_mesh(filename) Function to read in a mesh model from NetGen and saves it in five arrays; surface (srf), veritices (vtx), face no. (fc) volume (simp) and edges (edg) Version 4.0 B.D.Grieve - 27/01/2002 + modifications by lmazurk A.Adler - 2006 mods to run quicker B.Grychtol - 2012 partial support for *.in2d EIDORS's srf array is a subset of NetGen's surface element data (columns 6:8). The first column of the surface element data also ascribes a face number to each surface which is saved as the fc array. Each line of the srf array contains 3 indices to define a triangle mapped on to the three dimensional vtx array. EIDORS's vtx array is a direct equivalent to NetGen's pointer data. srf = The surfaces indices into vtx simp = The volume indices into vtx vtx = The vertices matrix fc = A one column matrix containing the face numbers edg = Edge segment information filename = Name of file containing NetGen .vol information mat_ind = Material index
0001 function[srf,vtx,fc,bc,simp,edg,mat_ind] = ng_read_mesh(filename) 0002 %[srf,vtx,fc,bc,simp,edg,mat_ind] = ng_read_mesh(filename) 0003 % Function to read in a mesh model from NetGen and saves it in 0004 % five arrays; surface (srf), veritices (vtx), face no. (fc) 0005 % volume (simp) and edges (edg) 0006 % 0007 % Version 4.0 0008 % B.D.Grieve - 27/01/2002 + modifications by lmazurk 0009 % A.Adler - 2006 mods to run quicker 0010 % B.Grychtol - 2012 partial support for *.in2d 0011 % 0012 % EIDORS's srf array is a subset of NetGen's surface element data 0013 % (columns 6:8). The first column of the surface element data also 0014 % ascribes a face number to each surface which is saved as the fc 0015 % array. Each line of the srf array contains 3 indices to define 0016 % a triangle mapped on to the three dimensional vtx array. 0017 % EIDORS's vtx array is a direct equivalent to NetGen's pointer data. 0018 % 0019 % 0020 % srf = The surfaces indices into vtx 0021 % simp = The volume indices into vtx 0022 % vtx = The vertices matrix 0023 % fc = A one column matrix containing the face numbers 0024 % edg = Edge segment information 0025 % filename = Name of file containing NetGen .vol information 0026 % mat_ind = Material index 0027 0028 % $Id: ng_read_mesh.m 5718 2018-03-27 21:55:14Z alistair_boyle $ 0029 % (C) 2002-2012 (C) Licenced under the GPL 0030 0031 % Filenames cause problems under windows. Change \ to / 0032 if ~isunix 0033 filename(filename=='\') = '/'; 0034 end 0035 0036 eidors_msg(['ng_read_mesh ' filename],3); 0037 0038 orig = filename; 0039 if strcmp(filename(end-2:end),'.gz') 0040 if ~isunix 0041 error(['can''t ungzip ' filename ' unless system is unix']); 0042 end 0043 filename = filename(1:end-3); 0044 system(['gunzip -c ' orig ' > ' filename]); 0045 end 0046 0047 fid = fopen(filename,'r'); 0048 assert(fid ~= -1, ['failed to open file: ' filename ]); 0049 while 1 0050 tline = fgetl(fid); 0051 if ~ischar(tline); fclose(fid); break; end 0052 0053 if strcmp(tline,'surfaceelementsgi') % netgen-4.x 0054 se= get_lines_with_numbers( fid, 11); 0055 elseif strcmp(tline,'surfaceelements'); % netgen-5.x 0056 se= get_lines_with_numbers( fid, 8); 0057 elseif strcmp(tline,'surfaceelementsuv'); % netgen-6.x 0058 se= get_lines_with_numbers( fid, 14); 0059 elseif strcmp(tline,'volumeelements') 0060 ve= get_lines_with_numbers( fid, 6); 0061 elseif strcmp(tline,'edgesegmentsgi2') 0062 es= get_lines_with_numbers( fid, 12); 0063 elseif strcmp(tline,'points') 0064 vtx= get_lines_with_numbers( fid, 3); 0065 end 0066 end 0067 0068 if strcmp(orig(end-2:end),'.gz') 0069 system(['rm -f ' filename]); 0070 end 0071 0072 srf = se(:,6:8); 0073 fc = se(:,1); 0074 if ~isempty(ve) 0075 simp = ve(:,3:6); 0076 mat_ind=ve(:,1); 0077 else 0078 % *.in2d case 0079 simp = srf; 0080 mat_ind = fc; % not sure.. 0081 end 0082 edg = es; 0083 bc = se(:,2); 0084 0085 function mat= get_lines_with_numbers( fid, n_cols); 0086 tline = fgetl(fid); 0087 n_rows = sscanf(tline,'%d'); 0088 mat= fscanf(fid,'%f',[n_cols,n_rows])'; 0089 0090