0001 function hm=plotsurf(node,face,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
0028
0029
0030
0031
0032
0033 rngstate = rand ('state');
0034
0035 if(nargin>=2)
0036 randseed=hex2dec('623F9A9E');
0037 if(isoctavemesh) randseed=randseed+3; end
0038 if(~isempty(getvarfrom({'caller','base'},'ISO2MESH_RANDSEED')))
0039 randseed=getvarfrom({'caller','base'},'ISO2MESH_RANDSEED');
0040 end
0041 rand('state',randseed);
0042
0043 if(iscell(face))
0044 sc=sparse(10,3);
0045 sc(1:10,:)=rand(3,10)';
0046 len=length(face);
0047 newsurf=cell(1);
0048
0049 for i=1:len
0050 fc=face{i};
0051 if(iscell(fc) && length(fc)>=2)
0052 if(fc{2}+1>10)
0053 sc(fc{2}+1,:)=rand(1,3);
0054 end
0055 if(fc{2}+1>length(newsurf))
0056 newsurf{fc{2}+1}={};
0057 end
0058 newsurf{fc{2}+1}{end+1}=fc{1};
0059 else
0060 if(iscell(fc))
0061 newsurf{1}{end+1}=cell2mat(fc);
0062 else
0063 newsurf{1}{end+1}=fc;
0064 end
0065 end
0066 end
0067 hold on;
0068 h=[];
0069 newlen=length(newsurf);
0070
0071 for i=1:newlen
0072 if(isempty(newsurf{i})); continue; end
0073 try
0074 subface=cell2mat(newsurf{i}')';
0075 if(size(subface,1)>1 && ismatrix(subface))
0076 subface=subface';
0077 end
0078 h=[h patch('Vertices',node,'Faces',subface,'facecolor',sc(i,:),varargin{:})];
0079 catch
0080 for j=1:length(newsurf{i})
0081 h=[h patch('Vertices',node,'Faces',newsurf{i}{j},'facecolor',sc(i,:),varargin{:})];
0082 end
0083 end
0084 end
0085 else
0086 if(size(face,2)==4)
0087 tag=face(:,4);
0088 types=unique(tag);
0089 hold on;
0090 h=[];
0091 for i=1:length(types)
0092 if(size(node,2)==3)
0093 h=[h plotasurf(node,face(tag==types(i),1:3),'facecolor',rand(3,1),varargin{:})];
0094 else
0095 h=[h plotasurf(node,face(tag==types(i),1:3),varargin{:})];
0096 end
0097 end
0098 else
0099 h=plotasurf(node,face,varargin{:});
0100 end
0101 end
0102 end
0103 if(~isempty(h))
0104 axis equal;
0105 if(all(get(gca,'view')==[0 90]))
0106 view(3);
0107 end
0108 end
0109 if(~isempty(h) && nargout>=1)
0110 hm=h;
0111 end
0112
0113 rand ('state',rngstate);
0114
0115
0116 function hh=plotasurf(node,face,varargin)
0117 isoct=isoctavemesh;
0118 if(size(face,2)<=2)
0119 h=plotedges(node,face,varargin{:});
0120 else
0121 if(size(node,2)==4)
0122 if(isoct && ~exist('trisurf','file'))
0123 h=trimesh(face(:,1:3),node(:,1),node(:,2),node(:,3),node(:,4),'edgecolor','k',varargin{:});
0124 else
0125 h=trisurf(face(:,1:3),node(:,1),node(:,2),node(:,3),node(:,4),varargin{:});
0126 end
0127 else
0128 if(isoct && ~exist('trisurf','file'))
0129 h=trimesh(face(:,1:3),node(:,1),node(:,2),node(:,3),'edgecolor','k',varargin{:});
0130 else
0131 h=trisurf(face(:,1:3),node(:,1),node(:,2),node(:,3),varargin{:});
0132 end
0133 end
0134 end
0135 if(exist('h','var')) hh=h; end