0001 function hm=plotmesh(node,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
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 selector=[];
0059 opt=[];
0060 face=[];
0061 elem=[];
0062
0063 if(nargin>1)
0064 hasopt=0;
0065 for i=1:length(varargin)
0066 if(ischar(varargin{i}))
0067 if(~isempty(regexp(varargin{i},'[x-zX-Z]')) && ~isempty(regexp(varargin{i},'[><=&|]')))
0068 selector=varargin{i};
0069 if(nargin>=i+1) opt=varargin(i+1:end); end
0070 else
0071 opt=varargin(i:end);
0072 end
0073 if(i==1)
0074 face=[];elem=[];
0075 elseif(i==2)
0076 if(iscell(varargin{1}) | size(varargin{1},2)<4)
0077 face=varargin{1}; elem=[];
0078 elseif(size(varargin{1},2)==4)
0079 faceid=unique(varargin{1}(:,4));
0080 if(length(faceid)==1)
0081 face=varargin{1}; elem=[];
0082 elseif(any(hist(varargin{1}(:,4),unique(varargin{1}(:,4)))>50))
0083 face=varargin{1}; elem=[];
0084 else
0085 elem=varargin{1}; face=[];
0086 end
0087 else
0088 elem=varargin{1}; face=[];
0089 end
0090 elseif(i==3)
0091 face=varargin{1};
0092 elem=varargin{2};
0093 end
0094 hasopt=1;
0095 break;
0096 end
0097 end
0098 if(hasopt==0)
0099 if(length(varargin)>=2)
0100 face=varargin{1};
0101 elem=varargin{2};
0102 if(length(varargin)>2) opt=varargin(3:end); end
0103 elseif(iscell(varargin{1}) | size(varargin{1},2)<4)
0104 face=varargin{1}; elem=[];
0105 elseif(size(varargin{1},2)==4)
0106 faceid=unique(varargin{1}(:,4));
0107 if(length(faceid)==1)
0108 face=varargin{1}; elem=[];
0109 elseif(any(hist(varargin{1}(:,4),unique(varargin{1}(:,4)))>50))
0110 face=varargin{1}; elem=[];
0111 else
0112 elem=varargin{1}; face=[];
0113 end
0114 else
0115 elem=varargin{1}; face=[];
0116 end
0117 end
0118 end
0119
0120 holdstate=ishold;
0121 if(~holdstate)
0122 cla;
0123 end
0124 if(size(node,2)==4 && size(elem,2)==5)
0125 warning(['You have specified the node colors by both the 4th ' ...
0126 'and 5th columns of node and face inputs, respectively. ' ...
0127 'The node input takes priority']);
0128 end
0129 if(isempty(face) && isempty(elem))
0130 if(isempty(selector))
0131 if(isempty(opt))
0132 h=plot3(node(:,1),node(:,2),node(:,3),'o');
0133 else
0134 h=plot3(node(:,1),node(:,2),node(:,3),opt{:});
0135 end
0136 else
0137 x=node(:,1);
0138 y=node(:,2);
0139 z=node(:,3);
0140 idx=eval(['find(' selector ')']);
0141 if(~isempty(idx))
0142 if(isempty(opt))
0143 h=plot3(node(idx,1),node(idx,2),node(idx,3),'o');
0144 else
0145 h=plot3(node(idx,1),node(idx,2),node(idx,3),opt{:});
0146 end
0147 else
0148 warning('nothing to plot');
0149 end
0150 end
0151 end
0152
0153 if(~isempty(face))
0154 hold on;
0155 if(isempty(selector))
0156 if(isempty(opt))
0157 h=plotsurf(node,face);
0158 else
0159 h=plotsurf(node,face,opt{:});
0160 end
0161 else
0162 if(iscell(face))
0163 cent=meshcentroid(node,face);
0164 else
0165 cent=meshcentroid(node,face(:,1:3));
0166 end
0167 x=cent(:,1);
0168 y=cent(:,2);
0169 z=cent(:,3);
0170 idx=eval(['find(' selector ')']);
0171 if(~isempty(idx))
0172 if(iscell(face))
0173 h=plotsurf(node,face(idx),opt{:});
0174 else
0175 h=plotsurf(node,face(idx,:),opt{:});
0176 end
0177 else
0178 warning('no surface to plot');
0179 end
0180 end
0181 end
0182
0183 if(~isempty(elem))
0184 hold on;
0185 if(isempty(selector))
0186 if(isempty(opt))
0187 h=plottetra(node,elem);
0188 else
0189 h=plottetra(node,elem,opt{:});
0190 end
0191 else
0192 cent=meshcentroid(node,elem(:,1:4));
0193 x=cent(:,1);
0194 y=cent(:,2);
0195 z=cent(:,3);
0196 if(regexp(selector,'='))
0197 if(size(node,2)==4)
0198 [cutpos,cutvalue,facedata]=qmeshcut(elem,node(:,1:3),node(:,4),selector);
0199 elseif(size(node,2)==3)
0200 [cutpos,cutvalue,facedata]=qmeshcut(elem,node,node(:,3),selector);
0201 else
0202 error('plotmesh can only plot 3D tetrahedral meshes');
0203 end
0204 if(~isreal(cutvalue))
0205 cutvalue=abs(cutvalue);
0206 end
0207 h=patch('Vertices',cutpos,'Faces',facedata,'FaceVertexCData',cutvalue,'facecolor','interp',opt{:});
0208 else
0209 idx=eval(['find(' selector ')']);
0210 if(~isempty(idx))
0211 if(isempty(opt))
0212 h=plottetra(node,elem(idx,:));
0213 else
0214 h=plottetra(node,elem(idx,:),opt{:});
0215 end
0216 else
0217 warning('no tetrahedral element to plot');
0218 end
0219 end
0220 end
0221 end
0222
0223 if(exist('h','var') & ~holdstate)
0224 hold off;
0225 end
0226 if(exist('h','var'))
0227 if(any(get(gca,'dataaspectratio')>1e8))
0228 view(3);
0229 end
0230 axis equal;
0231 end
0232 if(exist('h','var') & nargout>=1)
0233 hm=h;
0234 end