ng_stl2tet

PURPOSE ^

NG_STL2TET creates a tetrahedral mesh from an stl file

SYNOPSIS ^

function mdl = ng_stl2tet(stlfile, varargin)

DESCRIPTION ^

NG_STL2TET creates a tetrahedral mesh from an stl file
 Netgen treats STL files as approximate and re-meshes the boundary.
 The operation of Netgen is influenced by parameters specified in the
 ng.opt file (see NG_WRITE_OPT). The following parameters were found to be
 useful (Netgen's default values):

 opt.options.curvaturesafety = 2.0;
 opt.stloptions.yangle = 30;
 opt.stloptions.contyangle = 20;
 opt.stloptions.edgecornerangle = 60;
 opt.stloptions.chartangle = 15;
 opt.stloptions.outerchartangle = 70;

 USAGE:
 mdl = ng_stl2tet(stlfile, ...) where:
        mdl - EIDORS fwd_model struct
    stlfile - either:
                 - a path to an stl file (!! must be ASCII !!)
               OR
                 - an EIDORS fwd_model with .nodes and .boundary or .elems
               OR
                 - a struct with .vertices and .faces
        ... - parameters to ng_write_opt

 If stlfile is a struct, stl_write will be called first and an STL file
 written in a temporary location. 

 CASHING: Calls are cashed iff stlfile is a struct.

 NOTE: Only one surface per file is allowed.

 See also CALL_NETGEN, STL_WRITE, NG_WRITE_OPT, GMSH_STL2TET

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mdl = ng_stl2tet(stlfile, varargin)
0002 %NG_STL2TET creates a tetrahedral mesh from an stl file
0003 % Netgen treats STL files as approximate and re-meshes the boundary.
0004 % The operation of Netgen is influenced by parameters specified in the
0005 % ng.opt file (see NG_WRITE_OPT). The following parameters were found to be
0006 % useful (Netgen's default values):
0007 %
0008 % opt.options.curvaturesafety = 2.0;
0009 % opt.stloptions.yangle = 30;
0010 % opt.stloptions.contyangle = 20;
0011 % opt.stloptions.edgecornerangle = 60;
0012 % opt.stloptions.chartangle = 15;
0013 % opt.stloptions.outerchartangle = 70;
0014 %
0015 % USAGE:
0016 % mdl = ng_stl2tet(stlfile, ...) where:
0017 %        mdl - EIDORS fwd_model struct
0018 %    stlfile - either:
0019 %                 - a path to an stl file (!! must be ASCII !!)
0020 %               OR
0021 %                 - an EIDORS fwd_model with .nodes and .boundary or .elems
0022 %               OR
0023 %                 - a struct with .vertices and .faces
0024 %        ... - parameters to ng_write_opt
0025 %
0026 % If stlfile is a struct, stl_write will be called first and an STL file
0027 % written in a temporary location.
0028 %
0029 % CASHING: Calls are cashed iff stlfile is a struct.
0030 %
0031 % NOTE: Only one surface per file is allowed.
0032 %
0033 % See also CALL_NETGEN, STL_WRITE, NG_WRITE_OPT, GMSH_STL2TET
0034 
0035 % (C) Bartlomiej Grychtol, 2012-2021.
0036 % $Id: ng_stl2tet.m 7124 2024-12-29 15:18:32Z aadler $
0037 
0038 if isstruct(stlfile)
0039     try
0040        name = stlfile.name;
0041     catch
0042        name = 'ng_stl2tet';
0043     end
0044     try
0045        opt.cache_obj{1} = stlfile.nodes;
0046        if isfield(stlfile, 'boundary')
0047           opt.cache_obj{2} = stlfile.boundary;
0048        else 
0049           opt.cache_obj{2} = stlfile.elems;
0050        end
0051     catch
0052        opt.cache_obj = {stlfile.vertices, stlfile.faces};
0053     end
0054     if nargin > 1
0055        opt.cache_obj = horzcat(opt.cache_obj, varargin);
0056     end
0057     mdl = eidors_cache(@do_ng_stl2tet,[{stlfile}, varargin(:)'], opt);
0058 else
0059     [~, name, ext] = fileparts(stlfile); name = [name ext];
0060     mdl = do_ng_stl2tet(stlfile, varargin{:});
0061 end
0062 
0063 mdl = eidors_obj('fwd_model', mdl, 'name', name);
0064 
0065 
0066 function mdl = do_ng_stl2tet(stlfile, varargin)
0067 if isstruct(stlfile)
0068     stem = tempname;
0069     stlname = [stem '.stl'];
0070     stl_write(stlfile, stlname, 'txt');
0071 else
0072     stem = strrep(stlfile,'.stl','');
0073     stlname = stlfile;
0074 end
0075 volfile = [stem, '.vol'];
0076 if nargin > 1
0077    ng_write_opt(varargin{:});
0078 end
0079 call_netgen(stlname,volfile);
0080 if nargin > 1
0081    delete('ng.opt'); % clean up
0082 end
0083 mdl=ng_mk_fwd_model(volfile,[],[],[],[]);
0084 mdl = fix_boundary(mdl);
0085

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