hm=plottetra(node,elem,opt) plot 3D surface meshes author: Qianqian Fang <fangq at nmr.mgh.harvard.edu> input: node: a node coordinate list, 3 columns for x/y/z; if node has a 4th column, it will be used to set the color at each node. elem: a tetrahedral element list; if elem has a 5th column, and the 5th column are all integers, it will be treated as labels of sub-domains and display them in different colors. if the 5th column contains non-integer values, it will be used to map to the color of triangles. opt: additional options for a patch object, see plotmesh output: hm: handle or handles (vector) to the plotted surfaces example: h=plottetra(node,elem); h=plottetra(node,elem,'facealpha',0.5); -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function hm=plottetra(node,elem,varargin) 0002 % 0003 % hm=plottetra(node,elem,opt) 0004 % 0005 % plot 3D surface meshes 0006 % 0007 % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu> 0008 % 0009 % input: 0010 % node: a node coordinate list, 3 columns for x/y/z; if node has a 0011 % 4th column, it will be used to set the color at each node. 0012 % elem: a tetrahedral element list; if elem has a 5th column, 0013 % and the 5th column are all integers, it will be treated 0014 % as labels of sub-domains and display them in different colors. 0015 % if the 5th column contains non-integer values, it will be 0016 % used to map to the color of triangles. 0017 % opt: additional options for a patch object, see plotmesh 0018 % 0019 % output: 0020 % hm: handle or handles (vector) to the plotted surfaces 0021 % 0022 % example: 0023 % 0024 % h=plottetra(node,elem); 0025 % h=plottetra(node,elem,'facealpha',0.5); 0026 % 0027 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0028 % 0029 0030 rngstate = rand ('state'); 0031 0032 randseed=hex2dec('623F9A9E'); % "U+623F U+9A9E" 0033 if(isoctavemesh) randseed=randseed+3; end 0034 0035 if(~isempty(getvarfrom({'caller','base'},'ISO2MESH_RANDSEED'))) 0036 randseed=getvarfrom({'caller','base'},'ISO2MESH_RANDSEED'); 0037 end 0038 rand('state',randseed); 0039 0040 if(~iscell(elem)) 0041 if(size(elem,2)>4) 0042 tag=elem(:,5); 0043 types=unique(tag); 0044 hold on; 0045 h=[]; 0046 if(all(isinteger(tag))) 0047 for i=1:length(types) 0048 idx=find(tag==types(i)); 0049 face=volface(elem(idx,1:4)); 0050 if(size(node,2)==3) 0051 h=[h plotsurf(node,face,'facecolor',rand(3,1),varargin{:})]; 0052 else 0053 h=[h plotsurf(node,face,varargin{:})]; 0054 end 0055 end 0056 else 0057 [face,eid]=volface(elem(:,1:4)); 0058 if(size(elem,2)>=5) 0059 h=[h plotsurf(node,face,'FaceVertexCData',tag(eid), varargin{:})]; 0060 else 0061 h=[h plotsurf(node,face,varargin{:})]; 0062 end 0063 end 0064 else 0065 face=volface(elem(:,1:4)); 0066 h=plotsurf(node,face,varargin{:}); 0067 end 0068 end 0069 0070 if(~isempty(h)) 0071 axis equal; 0072 end 0073 if(~isempty(h) & nargout>=1) 0074 hm=h; 0075 end 0076 0077 rand ('state',rngstate);