Skip to content

Commit 2846c26

Browse files
committed
GUI, main file(plotVisualizer) and other functions
1 parent 63f33b2 commit 2846c26

31 files changed

+3753
-33
lines changed

180_r03.mat

402 KB
Binary file not shown.

180_r04.mat

410 KB
Binary file not shown.

180_r05.mat

419 KB
Binary file not shown.

180_r_infty.mat

6.28 KB
Binary file not shown.

180_r_infty_video1.mat

4.23 KB
Binary file not shown.

360.mat

399 KB
Binary file not shown.

H2_norm.m

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function H2 = H2_norm(L, Q)
2+
3+
% Inputs: L (Laplacian matrix), Q (projection matrix
4+
% onto n-1 dimensional space perpendicular to ones(n,1))
5+
6+
Lbar = Q*L*Q';
7+
L0 = real(reduced_lyap(Lbar));
8+
H2 = sqrt(trace(L0));

alphavol.m

+256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
function [V,S] = alphavol(X,R,fig)
2+
%ALPHAVOL Alpha shape of 2D or 3D point set.
3+
% V = ALPHAVOL(X,R) gives the area or volume V of the basic alpha shape
4+
% for a 2D or 3D point set. X is a coordinate matrix of size Nx2 or Nx3.
5+
%
6+
% R is the probe radius with default value R = Inf. In the default case
7+
% the basic alpha shape (or alpha hull) is the convex hull.
8+
%
9+
% [V,S] = ALPHAVOL(X,R) outputs a structure S with fields:
10+
% S.tri - Triangulation of the alpha shape (Mx3 or Mx4)
11+
% S.vol - Area or volume of simplices in triangulation (Mx1)
12+
% S.rcc - Circumradius of simplices in triangulation (Mx1)
13+
% S.bnd - Boundary facets (Px2 or Px3)
14+
%
15+
% ALPHAVOL(X,R,1) plots the alpha shape.
16+
%
17+
% % 2D Example - C shape
18+
% t = linspace(0.6,5.7,500)';
19+
% X = 2*[cos(t),sin(t)] + rand(500,2);
20+
% subplot(221), alphavol(X,inf,1);
21+
% subplot(222), alphavol(X,1,1);
22+
% subplot(223), alphavol(X,0.5,1);
23+
% subplot(224), alphavol(X,0.2,1);
24+
%
25+
% % 3D Example - Sphere
26+
% [x,y,z] = sphere;
27+
% [V,S] = alphavol([x(:),y(:),z(:)]);
28+
% trisurf(S.bnd,x,y,z,'FaceColor','blue','FaceAlpha',1)
29+
% axis equal
30+
%
31+
% % 3D Example - Ring
32+
% [x,y,z] = sphere;
33+
% ii = abs(z) < 0.4;
34+
% X = [x(ii),y(ii),z(ii)];
35+
% X = [X; 0.8*X];
36+
% subplot(211), alphavol(X,inf,1);
37+
% subplot(212), alphavol(X,0.5,1);
38+
%
39+
% See also DELAUNAY, TRIREP, TRISURF
40+
41+
% Author: Jonas Lundgren <[email protected]> 2010
42+
43+
% 2010-09-27 First version of ALPHAVOL.
44+
% 2010-10-05 DelaunayTri replaced by DELAUNAYN. 3D plots added.
45+
% 2012-03-08 More output added. DELAUNAYN replaced by DELAUNAY.
46+
47+
if nargin < 2 || isempty(R), R = inf; end
48+
if nargin < 3, fig = 0; end
49+
50+
% Check coordinates
51+
dim = size(X,2);
52+
if dim < 2 || dim > 3
53+
error('alphavol:dimension','X must have 2 or 3 columns.')
54+
end
55+
56+
% Check probe radius
57+
if ~isscalar(R) || ~isreal(R) || isnan(R)
58+
error('alphavol:radius','R must be a real number.')
59+
end
60+
61+
% Unique points
62+
[X,imap] = unique(X,'rows');
63+
64+
% Delaunay triangulation
65+
T = delaunay(X);
66+
67+
% Remove zero volume tetrahedra since
68+
% these can be of arbitrary large circumradius
69+
if dim == 3
70+
n = size(T,1);
71+
vol = volumes(T,X);
72+
epsvol = 1e-12*sum(vol)/n;
73+
T = T(vol > epsvol,:);
74+
holes = size(T,1) < n;
75+
end
76+
77+
% Limit circumradius of simplices
78+
[~,rcc] = circumcenters(TriRep(T,X));
79+
T = T(rcc < R,:);
80+
rcc = rcc(rcc < R);
81+
82+
% Volume/Area of alpha shape
83+
vol = volumes(T,X);
84+
V = sum(vol);
85+
86+
% Return?
87+
if nargout < 2 && ~fig
88+
return
89+
end
90+
91+
% Turn off TriRep warning
92+
warning('off','MATLAB:TriRep:PtsNotInTriWarnId')
93+
94+
% Alpha shape boundary
95+
if ~isempty(T)
96+
% Facets referenced by only one simplex
97+
B = freeBoundary(TriRep(T,X));
98+
if dim == 3 && holes
99+
% The removal of zero volume tetrahedra causes false boundary
100+
% faces in the interior of the volume. Take care of these.
101+
B = trueboundary(B,X);
102+
end
103+
else
104+
B = zeros(0,dim);
105+
end
106+
107+
% Plot alpha shape
108+
if fig
109+
figure(1)
110+
if dim == 2
111+
% Plot boundary edges and point set
112+
x = X(:,1);
113+
y = X(:,2);
114+
plot(x(B)',y(B)','r','linewidth',2), hold on
115+
plot(x,y,'k.'), hold off
116+
str = 'Area';
117+
elseif ~isempty(B)
118+
% Plot boundary faces
119+
trisurf(TriRep(B,X),'FaceColor','red','FaceAlpha',1/3);
120+
str = 'Volume';
121+
else
122+
cla
123+
str = 'Volume';
124+
end
125+
axis equal
126+
str = sprintf('Radius = %g, %s = %g', R, str, V);
127+
title(str,'fontsize',12)
128+
end
129+
130+
% Turn on TriRep warning
131+
warning('on','MATLAB:TriRep:PtsNotInTriWarnId')
132+
133+
% Return structure
134+
if nargout == 2
135+
S = struct('tri',imap(T),'vol',vol,'rcc',rcc,'bnd',imap(B));
136+
end
137+
138+
139+
%--------------------------------------------------------------------------
140+
function vol = volumes(T,X)
141+
%VOLUMES Volumes/areas of tetrahedra/triangles
142+
143+
% Empty case
144+
if isempty(T)
145+
vol = zeros(0,1);
146+
return
147+
end
148+
149+
% Local coordinates
150+
A = X(T(:,1),:);
151+
B = X(T(:,2),:) - A;
152+
C = X(T(:,3),:) - A;
153+
154+
if size(X,2) == 3
155+
% 3D Volume
156+
D = X(T(:,4),:) - A;
157+
BxC = cross(B,C,2);
158+
vol = dot(BxC,D,2);
159+
vol = abs(vol)/6;
160+
else
161+
% 2D Area
162+
vol = B(:,1).*C(:,2) - B(:,2).*C(:,1);
163+
vol = abs(vol)/2;
164+
end
165+
166+
167+
%--------------------------------------------------------------------------
168+
function B = trueboundary(B,X)
169+
%TRUEBOUNDARY True boundary faces
170+
% Remove false boundary caused by the removal of zero volume
171+
% tetrahedra. The input B is the output of TriRep/freeBoundary.
172+
173+
% Surface triangulation
174+
facerep = TriRep(B,X);
175+
176+
% Find edges attached to two coplanar faces
177+
E0 = edges(facerep);
178+
E1 = featureEdges(facerep, 1e-6);
179+
E2 = setdiff(E0,E1,'rows');
180+
181+
% Nothing found
182+
if isempty(E2)
183+
return
184+
end
185+
186+
% Get face pairs attached to these edges
187+
% The edges connects faces into planar patches
188+
facelist = edgeAttachments(facerep,E2);
189+
pairs = cell2mat(facelist);
190+
191+
% Compute planar patches (connected regions of faces)
192+
n = size(B,1);
193+
C = sparse(pairs(:,1),pairs(:,2),1,n,n);
194+
C = C + C' + speye(n);
195+
[~,p,r] = dmperm(C);
196+
197+
% Count planar patches
198+
iface = diff(r);
199+
num = numel(iface);
200+
201+
% List faces and vertices in patches
202+
facelist = cell(num,1);
203+
vertlist = cell(num,1);
204+
for k = 1:num
205+
206+
% Neglect singel face patches, they are true boundary
207+
if iface(k) > 1
208+
209+
% List of faces in patch k
210+
facelist{k} = p(r(k):r(k+1)-1);
211+
212+
% List of unique vertices in patch k
213+
vk = B(facelist{k},:);
214+
vk = sort(vk(:))';
215+
ik = [true,diff(vk)>0];
216+
vertlist{k} = vk(ik);
217+
218+
end
219+
end
220+
221+
% Sort patches by number of vertices
222+
ivert = cellfun(@numel,vertlist);
223+
[ivert,isort] = sort(ivert);
224+
facelist = facelist(isort);
225+
vertlist = vertlist(isort);
226+
227+
% Group patches by number of vertices
228+
p = [0;find(diff(ivert));num] + 1;
229+
ipatch = diff(p);
230+
231+
% Initiate true boundary list
232+
ibound = true(n,1);
233+
234+
% Loop over groups
235+
for k = 1:numel(ipatch)
236+
237+
% Treat groups with at least two patches and four vertices
238+
if ipatch(k) > 1 && ivert(p(k)) > 3
239+
240+
% Find double patches (identical vertex rows)
241+
V = cell2mat(vertlist(p(k):p(k+1)-1));
242+
[V,isort] = sortrows(V);
243+
id = ~any(diff(V),2);
244+
id = [id;0] | [0;id];
245+
id(isort) = id;
246+
247+
% Deactivate faces in boundary list
248+
for j = find(id')
249+
ibound(facelist{j-1+p(k)}) = 0;
250+
end
251+
252+
end
253+
end
254+
255+
% Remove false faces
256+
B = B(ibound,:);

anglerestrict.m

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function theta = anglerestrict(phi)
2+
%ANGLERESTRICT function to restrict an angle to a value between -PI and PI
3+
% ANGLERESTRICT(PHI) takes the angle PHI and computes the equivalent angle
4+
% between -PI and PI
5+
6+
% George Young
7+
% August 2011
8+
9+
theta = phi - 2*pi*ceil((phi-pi)/(2*pi));
10+
11+
end

barwitherr.m

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
%**************************************************************************
2+
%
3+
% This is a simple extension of the bar plot to include error bars. It
4+
% is called in exactly the same way as bar but with an extra input
5+
% parameter "errors" passed first.
6+
%
7+
% Parameters:
8+
% errors - the errors to be plotted (extra dimension used if assymetric)
9+
% varargin - parameters as passed to conventional bar plot
10+
% See bar and errorbar documentation for more details.
11+
%
12+
% Symmetric Example:
13+
% y = randn(3,4); % random y values (3 groups of 4 parameters)
14+
% errY = 0.1.*y; % 10% error
15+
% barwitherr(errY, y); % Plot with errorbars
16+
%
17+
% set(gca,'XTickLabel',{'Group A','Group B','Group C'})
18+
% legend('Parameter 1','Parameter 2','Parameter 3','Parameter 4')
19+
% ylabel('Y Value')
20+
%
21+
%
22+
% Asymmetric Example:
23+
% y = randn(3,4); % random y values (3 groups of 4 parameters)
24+
% errY = zeros(3,4,2);
25+
% errY(:,:,1) = 0.1.*y; % 10% lower error
26+
% errY(:,:,2) = 0.2.*y; % 20% upper error
27+
% barwitherr(errY, y); % Plot with errorbars
28+
%
29+
% set(gca,'XTickLabel',{'Group A','Group B','Group C'})
30+
% legend('Parameter 1','Parameter 2','Parameter 3','Parameter 4')
31+
% ylabel('Y Value')
32+
%
33+
%
34+
% Notes:
35+
% Ideally used for group plots with non-overlapping bars because it
36+
% will always plot in bar centre (so can look odd for over-lapping bars)
37+
% and for stacked plots the errorbars will be at the original y value is
38+
% not the stacked value so again odd appearance as is.
39+
%
40+
% The data may not be in ascending order. Only an issue if x-values are
41+
% passed to the fn in which case their order must be determined to
42+
% correctly position the errorbars.
43+
%
44+
%
45+
% 24/02/2011 Martina F. Callaghan Created
46+
% 12/08/2011 Martina F. Callaghan Updated for random x-values
47+
% 24/10/2011 Martina F. Callaghan Updated for asymmetric errors
48+
% 15/11/2011 Martina F. Callaghan Fixed bug for assymetric errors &
49+
% vector plots
50+
%
51+
%**************************************************************************
52+
53+
function barwitherr(errors,varargin)
54+
55+
% Check how the function has been called based on requirements for "bar"
56+
if nargin < 3
57+
% This is the same as calling bar(y)
58+
values = varargin{1};
59+
xOrder = 1:size(values,1);
60+
else
61+
% This means extra parameters have been specified
62+
if isscalar(varargin{2}) || ischar(varargin{2})
63+
% It is a width / property so the y values are still varargin{1}
64+
values = varargin{1};
65+
xOrder = 1:size(values,1);
66+
else
67+
% x-values have been specified so the y values are varargin{2}
68+
% If x-values have been specified, they could be in a random order,
69+
% get their indices in ascending order for use with the bar
70+
% locations which will be in ascending order:
71+
values = varargin{2};
72+
[tmp xOrder] = sort(varargin{1});
73+
end
74+
end
75+
76+
% If an extra dimension is supplied for the errors then they are
77+
% assymetric split out into upper and lower:
78+
if ndims(errors) == ndims(values)+1
79+
lowerErrors = errors(:,:,1);
80+
upperErrors = errors(:,:,2);
81+
elseif isvector(values)~=isvector(errors)
82+
lowerErrors = errors(:,1);
83+
upperErrors = errors(:,2);
84+
else
85+
lowerErrors = errors;
86+
upperErrors = errors;
87+
end
88+
89+
% Check that the size of "errors" corresponsds to the size of the y-values.
90+
% Arbitrarily using lower errors as indicative.
91+
if any(size(values) ~= size(lowerErrors))
92+
error('The values and errors have to be the same length')
93+
end
94+
95+
[nRows nCols] = size(values);
96+
handles.bar = bar(varargin{:}); % standard implementation of bar fn
97+
hold on
98+
99+
if nRows > 1
100+
for col = 1:nCols
101+
% Extract the x location data needed for the errorbar plots:
102+
x = get(get(handles.bar(col),'children'),'xdata');
103+
% Use the mean x values to call the standard errorbar fn; the
104+
% errorbars will now be centred on each bar; these are in ascending
105+
% order so use xOrder to ensure y values and errors are too:
106+
errorbar(mean(x,1),values(xOrder,col),lowerErrors(xOrder,col), upperErrors(xOrder, col), '.k')
107+
end
108+
else
109+
x = get(get(handles.bar,'children'),'xdata');
110+
errorbar(mean(x,1),values,errors,'.k')
111+
end
112+
113+
hold off

0 commit comments

Comments
 (0)