[newnode,newelem]=mergemesh(node,elem,varargin) concatenate two or more tetrahedral meshes or triangular surfaces author: Qianqian Fang <fangq at nmr.mgh.harvard.edu> input: node: node coordinates, dimension (nn,3) elem: tetrahedral element or triangle surface (nn,3) to (nn,5) output: newnode: the node coordinates after merging, dimension (nn,3) newelem: tetrahedral element or surfaces after merging (nn,4) or (nhn,5) note: you can call meshcheckrepair for the output newnode and newelem to remove the duplicated nodes or elements. mergemesh does detect self-intersecting elements when merging; to remove self-intersecting elements, you need to use mergesurf(). example: [node1,face1,elem1]=meshabox([0 0 0],[10 10 10],1,1); [node2,face2,elem2]=meshasphere([5 5 13.1],3,0.3,3); [newnode,newelem]=mergemesh(node1,elem1,node2,elem2); plotmesh(newnode,newelem); figure; [newnode,newface]=mergemesh(node1,face1,node2,face2); plotmesh(newnode,newface,'x>5'); -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function [newnode,newelem]=mergemesh(node,elem,varargin) 0002 % 0003 % [newnode,newelem]=mergemesh(node,elem,varargin) 0004 % 0005 % concatenate two or more tetrahedral meshes or triangular surfaces 0006 % 0007 % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu> 0008 % 0009 % input: 0010 % node: node coordinates, dimension (nn,3) 0011 % elem: tetrahedral element or triangle surface (nn,3) to (nn,5) 0012 % 0013 % output: 0014 % newnode: the node coordinates after merging, dimension (nn,3) 0015 % newelem: tetrahedral element or surfaces after merging (nn,4) or (nhn,5) 0016 % 0017 % note: you can call meshcheckrepair for the output newnode and 0018 % newelem to remove the duplicated nodes or elements. mergemesh does 0019 % detect self-intersecting elements when merging; to remove self-intersecting 0020 % elements, you need to use mergesurf(). 0021 % 0022 % example: 0023 % 0024 % [node1,face1,elem1]=meshabox([0 0 0],[10 10 10],1,1); 0025 % [node2,face2,elem2]=meshasphere([5 5 13.1],3,0.3,3); 0026 % [newnode,newelem]=mergemesh(node1,elem1,node2,elem2); 0027 % plotmesh(newnode,newelem); 0028 % figure; 0029 % [newnode,newface]=mergemesh(node1,face1,node2,face2); 0030 % plotmesh(newnode,newface,'x>5'); 0031 % 0032 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0033 % 0034 0035 len=length(varargin); 0036 newnode=node; 0037 newelem=elem; 0038 if(len>0 & mod(len,2)~=0) 0039 error('you must give node and element in pairs'); 0040 end 0041 0042 X=mesheuler(newelem); 0043 0044 if(size(newelem,2)==4) 0045 if(X>=0) 0046 newelem(:,end+1)=1; 0047 end 0048 end 0049 if(size(newelem,2)==3) 0050 newelem(:,end+1)=1; 0051 end 0052 for i=1:2:len 0053 no=varargin{i}; 0054 el=varargin{i+1}; 0055 baseno=size(newnode,1); 0056 if(size(no,2)~=size(newnode,2)) 0057 error('input node arrays have inconsistent columns'); 0058 end 0059 if(size(el,2)==5 | size(el,2)==4) 0060 el(:,1:4)=el(:,1:4)+baseno; 0061 if(size(el,2)==4 & X>=0) 0062 el(:,5)=1+(i+1)/2; 0063 end 0064 newnode=[newnode;no]; 0065 newelem=[newelem;el]; 0066 elseif(size(el,2)==3 & size(newelem,2)==4) 0067 el(:,1:3)=el(:,1:3)+baseno; 0068 if(size(el,2)==3) 0069 el(:,4)=1+(i+1)/2; 0070 end 0071 newnode=[newnode;no]; 0072 newelem=[newelem;el]; 0073 else 0074 error('input element arrays have inconsistent columns'); 0075 end 0076 end