/MatlabCode/branches/Greg's Branch/Online/isosamp/iso2mesh/plottetra.m

http://horwitzlab.googlecode.com/ · MATLAB · 66 lines · 35 code · 6 blank · 25 comment · 1 complexity · aaf5255dc035ecf57c0132f73eb76dd9 MD5 · raw file

  1. function hm=plottetra(node,elem,varargin)
  2. %
  3. % hm=plottetra(node,elem,opt)
  4. %
  5. % plot 3D surface meshes
  6. %
  7. % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
  8. %
  9. % input:
  10. % node: a node coordinate list, 3 columns for x/y/z; if node has a
  11. % 4th column, it will be used to set the color at each node.
  12. % elem: a tetrahedral element list; if elem has a 5th column,
  13. % it will be used to separate the mesh into
  14. % sub-domains and display them in different colors.
  15. % opt: additional options for a patch object, see plotmesh
  16. %
  17. % output:
  18. % hm: handle or handles (vector) to the plotted surfaces
  19. %
  20. % example:
  21. %
  22. % h=plottetra(node,elem);
  23. % h=plottetra(node,elem,'facealpha',0.5);
  24. %
  25. % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
  26. %
  27. rngstate = rand ('state');
  28. randseed=hex2dec('623F9A9E'); % "U+623F U+9A9E"
  29. if(isoctavemesh) randseed=randseed+3; end
  30. if(~isempty(getvarfrom('base','ISO2MESH_RANDSEED')))
  31. randseed=getvarfrom('base','ISO2MESH_RANDSEED');
  32. end
  33. rand('state',randseed);
  34. if(~iscell(elem))
  35. if(size(elem,2)>4)
  36. tag=elem(:,5);
  37. types=unique(tag);
  38. hold on;
  39. h=[];
  40. for i=1:length(types)
  41. idx=find(tag==types(i));
  42. face=volface(elem(idx,1:4));
  43. if(size(node,2)==3)
  44. h=[h plotsurf(node,face,'facecolor',rand(3,1),varargin{:})];
  45. else
  46. h=[h plotsurf(node,face,varargin{:})];
  47. end
  48. end
  49. else
  50. face=volface(elem(:,1:4));
  51. h=plotsurf(node,face,varargin{:});
  52. end
  53. end
  54. if(~isempty(h))
  55. axis equal;
  56. end
  57. if(~isempty(h) & nargout>=1)
  58. hm=h;
  59. end
  60. rand ('state',rngstate);