ng_read_mesh

PURPOSE ^

[srf,vtx,fc,bc,simp,edg,mat_ind] = ng_read_mesh(filename)

SYNOPSIS ^

function[srf,vtx,fc,bc,simp,edg,mat_ind] = ng_read_mesh(filename)

DESCRIPTION ^

[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
 B.Grychtol = 2024 mods to run quicker

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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 % B.Grychtol = 2024 mods to run quicker
0012 %
0013 % EIDORS's srf array is a subset of NetGen's surface element data
0014 % (columns 6:8). The first column of the surface element data also
0015 % ascribes a face number to each surface which is saved as the fc
0016 % array. Each line of the srf array contains 3 indices to define
0017 % a triangle mapped on to the three dimensional vtx array.
0018 % EIDORS's vtx array is a direct equivalent to NetGen's pointer data.
0019 %
0020 %
0021 % srf      = The surfaces indices into vtx
0022 % simp     = The volume indices into vtx
0023 % vtx      = The vertices matrix
0024 % fc       = A one column matrix containing the face numbers
0025 % edg      = Edge segment information
0026 % filename = Name of file containing NetGen .vol information
0027 % mat_ind  = Material index
0028 
0029 % $Id: ng_read_mesh.m 6849 2024-05-05 06:23:23Z bgrychtol $
0030 % (C) 2002-2024 (C) Licenced under the GPL
0031 
0032 % Filenames cause problems under windows. Change \ to /
0033 if ~isunix
0034    filename(filename=='\') = '/';
0035 end
0036 
0037 eidors_msg(['ng_read_mesh ' filename],3);
0038 
0039 orig = filename;
0040 if strcmp(filename(end-2:end),'.gz')
0041    if ~isunix
0042        error(['can''t ungzip ' filename ' unless system is unix']);
0043    end
0044    filename = filename(1:end-3);
0045    system(['gunzip -c ' orig ' > ' filename]);
0046 end
0047 fid = fopen(filename,'r');
0048 assert(fid ~= -1, ['failed to open file: ' filename ]);
0049 content = textscan(fid,'%s','Delimiter','\n');
0050 content = content{:};
0051 fclose(fid);
0052 
0053 idx = find(any(startsWith(content,{'s','v','e','p'}),2));
0054 se = []; ve = []; es = []; vtx = [];
0055 for i = 1:numel(idx)
0056     tline = content{idx(i)};
0057     if strcmp(tline, 'endmesh'), break; end
0058     nlines = str2double(content{idx(i)+1});
0059     if nlines == 0, continue, end
0060     block = content(idx(i)+2 : idx(i)+1+nlines);
0061     if     strcmp(tline,'surfaceelementsgi') % GEOM_STL
0062        se= get_lines_with_numbers( block, 11);
0063     elseif strcmp(tline,'surfaceelements') % default
0064        se= get_lines_with_numbers( block, 8);
0065     elseif strcmp(tline,'surfaceelementsuv') % GEOM_OCC, GEOM_ACIS
0066        se= get_lines_with_numbers( block, 14);
0067     elseif strcmp(tline,'volumeelements')
0068        ve= get_lines_with_numbers( block, 6);
0069     elseif strcmp(tline,'edgesegmentsgi2')
0070        es= get_lines_with_numbers( block, 12);
0071     elseif strcmp(tline,'points')
0072        vtx= get_lines_with_numbers( block, 3);
0073     end
0074 end
0075 
0076 if strcmp(orig(end-2:end),'.gz')
0077    system(['rm -f ' filename]);
0078 end
0079 
0080 srf = se(:,6:8);
0081 fc = se(:,1);
0082 if ~isempty(ve)
0083    simp = ve(:,3:6);
0084    mat_ind=ve(:,1);
0085 else
0086    % *.in2d case
0087    simp = srf;
0088    mat_ind = fc; % not sure..
0089 end
0090 edg = es;
0091 bc = se(:,2);
0092 
0093 function mat= get_lines_with_numbers( lines, n_cols)
0094 % mat= sscanf(sprintf('%s ',lines{:}),'%f',[n_cols,numel(lines)])';
0095 % dramatically faster (not ridiculously slow) in octave, same in Matlab
0096 mat = textscan(sprintf('%s ',lines{:}),'%f');
0097 mat = reshape(mat{1}, [n_cols, numel(lines)])';
0098 
0099

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005