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

 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 %
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 5523 2017-06-07 12:24:14Z aadler $
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 while 1
0049     tline = fgetl(fid);
0050     if ~ischar(tline); fclose(fid); break; end
0051 
0052     if     strcmp(tline,'surfaceelementsgi') % netgen-4.x
0053        se= get_lines_with_numbers( fid, 11);
0054     elseif strcmp(tline,'surfaceelements'); % netgen-5.x
0055        se= get_lines_with_numbers( fid, 8);
0056     elseif strcmp(tline,'surfaceelementsuv'); % netgen-6.x
0057        se= get_lines_with_numbers( fid, 14);
0058     elseif strcmp(tline,'volumeelements')
0059        ve= get_lines_with_numbers( fid, 6);
0060     elseif strcmp(tline,'edgesegmentsgi2')
0061        es= get_lines_with_numbers( fid, 12);
0062     elseif strcmp(tline,'points')
0063        vtx= get_lines_with_numbers( fid, 3);
0064     end
0065 end
0066 
0067 if strcmp(orig(end-2:end),'.gz')
0068    system(['rm -f ' filename]);
0069 end
0070 
0071 srf = se(:,6:8);
0072 fc = se(:,1);
0073 if ~isempty(ve)
0074    simp = ve(:,3:6);
0075    mat_ind=ve(:,1);
0076 else
0077    % *.in2d case
0078    simp = srf;
0079    mat_ind = fc; % not sure..
0080 end
0081 edg = es;
0082 bc = se(:,2);
0083 
0084 function mat= get_lines_with_numbers( fid, n_cols);
0085    tline = fgetl(fid);
0086    n_rows = sscanf(tline,'%d');
0087    mat= fscanf(fid,'%f',[n_cols,n_rows])';
0088 
0089

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005