1##  Copyright (C) 2014-2015  Daniel Kraft <d@domob.eu>
2##  GNU Octave level-set package.
3##
4##  This program is free software: you can redistribute it and/or modify
5##  it under the terms of the GNU General Public License as published by
6##  the Free Software Foundation, either version 3 of the License, or
7##  (at your option) any later version.
8##
9##  This program is distributed in the hope that it will be useful,
10##  but WITHOUT ANY WARRANTY; without even the implied warranty of
11##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12##  GNU General Public License for more details.
13##
14##  You should have received a copy of the GNU General Public License
15##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17## -*- texinfo -*-
18## @deftypefn  {Function File} {} ls_animate_evolution (@var{phi}, @var{f}, @var{h}, @var{times}, @var{wait})
19##
20## Animate the evolution of a level-set geometry.  The evolution
21## is calculated with @code{ls_solve_stationary} and @code{ls_extract_solution}
22## for the given arguments,  and the result plotted in the current figure
23## for the times given in @var{times}.  Between updating to the next
24## ``movie frame'', sleep for @var{wait} seconds.
25##
26## @seealso{ls_solve_stationary, ls_extract_solution}
27## @end deftypefn
28
29function ls_animate_evolution (phi, f, h, times, wait)
30  if (nargin () != 5)
31    print_usage ();
32  endif
33
34  d = ls_solve_stationary (phi, f, h);
35
36  % The figure is cleared and the speed plotted only once,
37  % to prevent ugly "jittering".  At each step, only the
38  % last contour plot object is removed to re-draw it.
39
40  clf ();
41  hold ("on");
42  imagesc (f);
43  ls_sign_colourmap ("highlight");
44  set (gca (), "ydir", "normal");
45
46  handle = false;
47  for t = times
48    phit = ls_extract_solution (t, d, phi, f);
49    if (handle)
50      delete (handle);
51    endif
52    [~, handle] = contour (phit, [0, 0], "k", "LineWidth", 2);
53    axis ("equal");
54    drawnow ();
55    sleep (wait);
56  endfor
57  hold ("off");
58endfunction
59
60% Simple demo with a basic situation.
61%!demo
62%!  n = 100;
63%!  x = linspace (-2, 2, n);
64%!  h = x(2) - x(1);
65%!  [XX, YY] = meshgrid (x, x);
66%!
67%!  phi = ls_genbasic (XX, YY, "sphere", [0, 0], 1.7);
68%!  f = -XX.^2 - YY.^2;
69%!
70%!  times = linspace (0, 1, 60);
71%!  ls_animate_evolution (phi, f, h, times, 0.05);
72