-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcplane_test.m
74 lines (63 loc) · 2.25 KB
/
cplane_test.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
xvec = linspace(-2,2,50);
yvec = linspace(-2,2,50);
sliz = linspace(-3,3,100);
% consider an ellipse: f(x,y) = 1 for x^2/1^2 + y^2/1^2 + z^2/2^2 <= 1
% and f(x,y) = 0 outside the ellipse.
P = 12;
sig = 0.2;
% set up radial sampling lines on each C-plane
R = linspace(0,2,40);
THETA = (0:2*P-1)*pi/P;
[Rm, Tm] = meshgrid(R, THETA);
Rm = Rm(:); Tm = Tm(:);
%------------------- estimate ocvlambda --------------------------------
zslice=0; % consider the largest circular crosssection of the ellipsoid
xd = zeros(size(Rm)); yd = xd; fd = xd;
flag=0;
for ii = 1:numel(Rm)
xc = Rm(ii)*cos(Tm(ii));
yc = Rm(ii)*sin(Tm(ii));
if xc^2/1 + yc^2/1 + zslice^2/2^2 <=1
fc=1;
else
fc=0;
end
if ( xc<max(xvec) && xc>min(xvec) && yc<max(yvec) && yc>min(yvec) )
flag=flag+1;
xd(flag)=xc;
yd(flag)=yc;
fd(flag)=fc;
end
end
xd = xd(1:flag); yd = yd(1:flag); fd = fd(1:flag);
fdno = fd + sig*randn(size(fd));
[fgrid, xgrid, ygrid, ocvlambda, lambdaVec, valVec] = cplane_crossval( xd, yd, fdno, xvec, yvec );
%------------------------ reconstruct all cplanes with ocvlambda smoothing parameter -----------------
cplaneStack = zeros( size(fgrid,1), size(fgrid,2), numel(sliz) ); % holds the 3D stack of C-planes
for zslice = 1:numel(sliz)
xd = zeros(size(Rm)); yd = xd; fd = xd;
flag=0;
for ii = 1:numel(Rm)
xc = Rm(ii)*cos(Tm(ii));
yc = Rm(ii)*sin(Tm(ii));
if xc^2/1 + yc^2/1 + sliz(zslice)^2/2^2 <=1
fc=1;
else
fc=0;
end
if ( xc<max(xvec) && xc>min(xvec) && yc<max(yvec) && yc>min(yvec) )
flag=flag+1;
xd(flag)=xc;
yd(flag)=yc;
fd(flag)=fc;
end
end
xd = xd(1:flag); yd = yd(1:flag); fd = fd(1:flag);
fdn = fd + sig*randn(size(fd));
[finterp, xgrid, ygrid,mse] = cplane( xvec, yvec, xd, yd, fdn, 'laplacian', 'backslash', ocvlambda );
cplaneStack(:,:,zslice) = finterp;
end
figure(1); stem3( xd, yd, fdno ); title('noisy data points on a c-plane');
figure(2); surf(fgrid, 'edgecolor', 'none'); title('surface fit to the c-plane of figure1');
% Uncomment the next line if you have slidingviewer.m from Matlab FileExchange:
% figure(3); slidingviewer(cplaneStack); colormap hot