Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/pure-cfg/test/iso2d.diderot
ViewVC logotype

Annotation of /branches/pure-cfg/test/iso2d.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 954 - (view) (download)

1 : glk 953 // iso2d
2 :     //
3 :     // Demo of finding isocontours via Newton-Raphson method.
4 :     // Initializes positions on a grid, and each update applies one
5 :     // step of Newton-Raphson.
6 :     //
7 :     // Process output with:
8 :     // unu jhisto -i mip.txt -b 512 512 -min 0 0 -max 63 63 | unu 2op neq - 0 | unu quantize -b 8 -o iso2d.png
9 :    
10 :     int gridSize = 100;
11 :     real isoval = 30.0;
12 :     image(2)[] img = load("../data/ddro-64-unit.nrrd");
13 :     field#1(2)[] F = img ⊛ ctmr;
14 : glk 954 int stepsMax = 10;
15 : glk 953 real epsilon = 0.001;
16 :    
17 :     strand sample (int ui, int vi) {
18 :     output vec2 pos = [lerp(1.0, 62.0, -0.5, real(ui), real(gridSize)-0.5),
19 :     lerp(1.0, 62.0, -0.5, real(vi), real(gridSize)-0.5)];
20 :     int steps = 0;
21 :     update {
22 :     // We bail if we're no longer inside or taken too many steps.
23 :     // We tag this strand result as garbage by setting it to a
24 :     // non-finite position; these will be filtered later.
25 :     // This is really what "die" is for, though (see below).
26 : glk 954 if (!inside(pos, F) || steps > stepsMax) {
27 : glk 953 // HEY (BUG) not able to use NaN as in "pos = [nan,nan]"
28 :     // generated C code "vec2f(nanf, nanf)" causes problems
29 :     pos = [∞,∞];
30 :     // HEY (BUG) we shouldn't even have to use non-finite values;
31 :     // we should be able to just say "die;". Currently, using
32 :     // "die" leads to the program never finishing...
33 :     stabilize;
34 :     }
35 :     vec2 grad = ∇F(pos);
36 :     real gmsq = grad • grad;
37 :     // If |∇F|=0 we can't compute update; we have to bail
38 :     if (gmsq == 0.0) {
39 :     pos = [∞,∞];
40 :     stabilize;
41 :     }
42 :     // delta = Newton-Raphson step
43 :     vec2 delta = -(F(pos) - isoval)*grad/gmsq;
44 :     // We've converged if the update is small enough
45 :     if (|delta| < epsilon) {
46 :     stabilize;
47 :     }
48 :     pos = pos + delta;
49 :     steps = steps + 1;
50 :     }
51 :     }
52 :    
53 :     initially [ sample(ui, vi) | vi in 0..(gridSize-1), ui in 0..(gridSize-1) ];

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0