forked from fangq/iso2mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotedges.m
75 lines (70 loc) · 2.18 KB
/
plotedges.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function hh=plotedges(node,edges,varargin)
%
% 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)
%
edlen=size(edges,1);
hh=[];
if(isempty(edges))
return;
end
rngstate = rand ('state');
if(size(edges,1)==1 || size(edges,2)==1) % a loop: single column/row edges
randseed=hex2dec('623F9A9E'); % "U+623F U+9A9E"
if(isoctavemesh) randseed=randseed+3; end
if(~isempty(getvarfrom({'caller','base'},'ISO2MESH_RANDSEED')))
randseed=getvarfrom({'caller','base'},'ISO2MESH_RANDSEED');
end
rand('state',randseed);
loops=edges(:)';
if(~isnan(loops(end)))
loops(end+1)=nan;
end
seg=find(isnan(loops));
seglen=length(seg);
seghead=1;
for i=1:seglen
h=plotmesh(node(loops(seghead:seg(i)-1),:), 'color',rand(3,1), varargin{:});
hh=[hh h];
seghead=seg(i)+1;
end
else % an edge list
if(size(node,2)==2) % 2D polyline
for i=1:edlen
h = line([node(edges(i,1),1) node(edges(i,2),1)],[node(edges(i,1),2) node(edges(i,2),2)], varargin{:});
hh=[hh,h];
end
else % 3D polyline
for i=1:edlen
h = line([node(edges(i,1),1) node(edges(i,2),1)],[node(edges(i,1),2) ...
node(edges(i,2),2)],[node(edges(i,1),3) node(edges(i,2),3)], varargin{:});
hh=[hh,h];
end
end
end
rand ('state',rngstate);