0001 function [node,elem]=meshcheckrepair(node,elem,opt,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
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
0089 end