hm=plotedges(node,edges,opt) or hm=plotedges(node,loops,opt) plot a 3D polyline or close loop (1d manifold) author: Qianqian Fang <fangq at nmr.mgh.harvard.edu> input: node: node coordinates, dimension (nn,3); if node has a 4th column, it will be used to set the color at each node. edges:edge list: a 2-column index array, with each row being an edge connecting the two indexed node loops:loops is an NaN separated integer array, with each segment denoting a 3D polyline or loop represented by a list of node indices opt: additional options for the plotting, see plotmesh output: hm: handle or handles (vector) to the plotted surfaces example: h=plotedges(node,[1 2 3 4 5 nan 6 7 8 9]); h=plotedges(node,edges,'marker','o','linewidth',2,'color','r'); -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function hh=plotedges(node,edges,varargin) 0002 % 0003 % hm=plotedges(node,edges,opt) 0004 % or 0005 % hm=plotedges(node,loops,opt) 0006 % 0007 % plot a 3D polyline or close loop (1d manifold) 0008 % 0009 % author: Qianqian Fang <fangq at nmr.mgh.harvard.edu> 0010 % 0011 % input: 0012 % node: node coordinates, dimension (nn,3); if node has a 0013 % 4th column, it will be used to set the color at each node. 0014 % edges:edge list: a 2-column index array, with each row being 0015 % an edge connecting the two indexed node 0016 % loops:loops is an NaN separated integer array, with each segment 0017 % denoting a 3D polyline or loop represented by a list of node 0018 % indices 0019 % opt: additional options for the plotting, see plotmesh 0020 % 0021 % output: 0022 % hm: handle or handles (vector) to the plotted surfaces 0023 % 0024 % example: 0025 % 0026 % h=plotedges(node,[1 2 3 4 5 nan 6 7 8 9]); 0027 % h=plotedges(node,edges,'marker','o','linewidth',2,'color','r'); 0028 % 0029 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0030 % 0031 0032 edlen=size(edges,1); 0033 hh=[]; 0034 if(isempty(edges)) 0035 return; 0036 end 0037 0038 rngstate = rand ('state'); 0039 0040 if(size(edges,1)==1 || size(edges,2)==1) % a loop: single column/row edges 0041 randseed=hex2dec('623F9A9E'); % "U+623F U+9A9E" 0042 if(isoctavemesh) randseed=randseed+3; end 0043 if(~isempty(getvarfrom({'caller','base'},'ISO2MESH_RANDSEED'))) 0044 randseed=getvarfrom({'caller','base'},'ISO2MESH_RANDSEED'); 0045 end 0046 rand('state',randseed); 0047 0048 loops=edges(:)'; 0049 if(~isnan(loops(end))) 0050 loops(end+1)=nan; 0051 end 0052 seg=find(isnan(loops)); 0053 seglen=length(seg); 0054 seghead=1; 0055 for i=1:seglen 0056 h=plotmesh(node(loops(seghead:seg(i)-1),:), 'color',rand(3,1), varargin{:}); 0057 hh=[hh h]; 0058 seghead=seg(i)+1; 0059 end 0060 else % an edge list 0061 if(size(node,2)==2) % 2D polyline 0062 for i=1:edlen 0063 h = line([node(edges(i,1),1) node(edges(i,2),1)],[node(edges(i,1),2) node(edges(i,2),2)], varargin{:}); 0064 hh=[hh,h]; 0065 end 0066 else % 3D polyline 0067 for i=1:edlen 0068 h = line([node(edges(i,1),1) node(edges(i,2),1)],[node(edges(i,1),2) ... 0069 node(edges(i,2),2)],[node(edges(i,1),3) node(edges(i,2),3)], varargin{:}); 0070 hh=[hh,h]; 0071 end 0072 end 0073 end 0074 0075 rand ('state',rngstate);