Home > vbmeg > external > iso2mesh > meshcheckrepair.m

meshcheckrepair

PURPOSE ^

SYNOPSIS ^

function [node,elem]=meshcheckrepair(node,elem,opt,varargin)

DESCRIPTION ^

 [node,elem]=meshcheckrepair(node,elem,opt)
 
 check and repair a surface mesh

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2008/10/10

 input/output:
      node: input/output, surface node list, dimension (nn,3)
      elem: input/output, surface face element list, dimension (be,3)
      opt: options, including
            'dupnode': remove duplicated nodes
            'dupelem' or 'duplicated': remove duplicated elements
            'dup': both above
            'isolated': remove isolated nodes
            'open': abort when open surface is found
            'deep': call external jmeshlib to remove non-manifold vertices
            'meshfix': repair a closed surface by the meshfix utility (new)
                       it can remove self-intersecting elements and fill holes
            'intersect': test a surface for self-intersecting elements

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [node,elem]=meshcheckrepair(node,elem,opt,varargin)
0002 %
0003 % [node,elem]=meshcheckrepair(node,elem,opt)
0004 %
0005 % check and repair a surface mesh
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2008/10/10
0009 %
0010 % input/output:
0011 %      node: input/output, surface node list, dimension (nn,3)
0012 %      elem: input/output, surface face element list, dimension (be,3)
0013 %      opt: options, including
0014 %            'dupnode': remove duplicated nodes
0015 %            'dupelem' or 'duplicated': remove duplicated elements
0016 %            'dup': both above
0017 %            'isolated': remove isolated nodes
0018 %            'open': abort when open surface is found
0019 %            'deep': call external jmeshlib to remove non-manifold vertices
0020 %            'meshfix': repair a closed surface by the meshfix utility (new)
0021 %                       it can remove self-intersecting elements and fill holes
0022 %            'intersect': test a surface for self-intersecting elements
0023 %
0024 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0025 %
0026 
0027 extra=varargin2struct(varargin{:});
0028 
0029 if(nargin<3 || strcmp(opt,'dupnode')|| strcmp(opt,'dup'))
0030     l1=size(node,1);
0031     [node,elem]=removedupnodes(node,elem,jsonopt('Tolerance',0,extra));
0032     l2=size(node,1);
0033     if(l2~=l1) fprintf(1,'%d duplicated nodes were removed\n',l1-l2); end
0034 end
0035 
0036 if(nargin<3 || strcmp(opt,'duplicated')|| strcmp(opt,'dupelem')|| strcmp(opt,'dup'))
0037     l1=size(elem,1);
0038     elem=removedupelem(elem);
0039     l2=length(elem);
0040     if(l2~=l1) fprintf(1,'%d duplicated elements were removed\n',l1-l2); end
0041 end
0042 
0043 if(nargin<3 || strcmp(opt,'isolated'))
0044     l1=length(node);
0045     [node,elem]=removeisolatednode(node,elem);
0046     l2=length(node);
0047     if(l2~=l1) fprintf(1,'%d isolated nodes were removed\n',l1-l2); end
0048 end
0049 
0050 if(nargin==3 && strcmp(opt,'open'))
0051     eg=surfedge(elem);
0052     if(~isempty(eg)) 
0053         error('open surface found, you need to enclose it by padding zeros around the volume');
0054     end
0055 end
0056 
0057 if(nargin<3 || strcmp(opt,'deep'))
0058     exesuff=getexeext;
0059     exesuff=fallbackexeext(exesuff,'jmeshlib');
0060     deletemeshfile(mwpath('post_sclean.off'));
0061     saveoff(node(:,1:3),elem(:,1:3),mwpath('pre_sclean.off'));
0062     system([' "' mcpath('jmeshlib') exesuff '" "' mwpath('pre_sclean.off') '" "' mwpath('post_sclean.off') '"']);
0063     [node,elem]=readoff(mwpath('post_sclean.off'));
0064 end
0065 
0066 exesuff=fallbackexeext(getexeext,'meshfix');
0067 moreopt=' -q -a 0.01 ';
0068 if(isstruct(extra) && isfield(extra,'MeshfixParam'))
0069     moreopt=extra.MeshfixParam;
0070 end
0071 
0072 if(nargin>=3 && strcmp(opt,'meshfix'))
0073     deletemeshfile(mwpath('pre_sclean.off'));
0074     deletemeshfile(mwpath('pre_sclean_fixed.off'));
0075     saveoff(node,elem,mwpath('pre_sclean.off'));
0076     system([' "' mcpath('meshfix') exesuff '" "' mwpath('pre_sclean.off') ...
0077         '" ' moreopt]);
0078     [node,elem]=readoff(mwpath('pre_sclean_fixed.off'));
0079 end
0080 
0081 if(nargin>=3 && strcmp(opt,'intersect'))
0082     moreopt=sprintf(' -q --no-clean --intersect -o "%s"',mwpath('pre_sclean_inter.msh'));
0083     deletemeshfile(mwpath('pre_sclean.off'));
0084     deletemeshfile(mwpath('pre_sclean_inter.msh'));
0085     saveoff(node,elem,mwpath('pre_sclean.off'));
0086     system([' "' mcpath('meshfix') exesuff '" "' mwpath('pre_sclean.off') ...
0087         '" ' moreopt]);
0088     %[node,elem]=readoff(mwpath('pre_sclean_inter.off'));
0089 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005