%%%%Demo Fig.4
% Use flag to choose different methods
% Author: Kaihua Zhang
% Email: cskhzhang@comp.polyu.edu.hk
% Date:  15/7/2010

clc;close all;clear all;
%--------------------------
%--------------------------
fprintf('You can choose different methods\n')
fprintf('1: RD, 2:re-initialization method 3: without re-initialization \n\n\n')
%--------------------------
flag= input('Please choose your method and then press Enter: 1: RD, 2:re-initialization method 3: without re-initialization \n'); 
%--------------------------

i = 1:100;
j = 1:100;
[x,y]=meshgrid(i,j);
R = 30;
b = 50;
a = 50;
phi = sqrt((x-a).^2+(y-b).^2) - R;

figure(1);hold on;plot(phi(50,:));grid on;
delt = 0.1;delt2 = 0.1;F = 1;
for n = 1:100
    phi = NeumannBoundCond(phi);
    [Kappa,absR] = Curvature_central(phi);
    switch flag
        case 1
            phi = phi + delt*F*absR;
            phi = phi + delt2*4*del2(phi);
            Tit = 'RD';
        case 2
            phi = phi + delt*F*absR;
            phi = reinit_SD(phi, 1, 1, 0.5,10);
            Tit = 're-initialization';
        case 3
            phi = phi + delt*F*absR;
            Tit = 'without re-initialization';
    end
   
    if mod(n,10)==0
        figure(1);hold on;plot(phi(50,:));pause(0.01);
        title(Tit);
    end
end
figure;mesh(phi);
Tit = strcat('Final LSF of',Tit);
title(Tit);
   
    