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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 975 - (view) (download)

1 : glk 975 // iso2d-cbrt
2 :     //
3 :     // Demo of difficulty of finding isocontours via Newton-Raphson method
4 :     // with nasty input; in this case it follows the shape of cbrt(r),
5 :     // so many of the points dramatically fail to converge.
6 :     //
7 :     // Process output with:
8 :     // unu jhisto -i mip.txt -b 500 500 -min 0 0 -max 499 499 | unu 2op neq - 0 | unu quantize -b 8 -o iso2d-cbrt.png
9 :    
10 :    
11 :     int gridSize = 150;
12 :     real isoval = 0.0;
13 :     image(2)[] img = load("../data/cbrt-500-unit.nrrd");
14 :     field#2(2)[] F = img ⊛ bspln3;
15 :     int stepsMax = 40;
16 :     real epsilon = 0.001;
17 :    
18 :     strand sample (int ui, int vi) {
19 :     output vec2 pos = [lerp(1.0, 499.0, -0.5, real(ui), real(gridSize)-0.5),
20 :     lerp(1.0, 499.0, -0.5, real(vi), real(gridSize)-0.5)];
21 :     int steps = 0;
22 :     update {
23 :     // We bail if we're no longer inside or taken too many steps.
24 :     // We tag this strand result as garbage by setting it to a
25 :     // non-finite position; these will be filtered later.
26 :     // This is really what "die" is for, though (see below).
27 :     if (!inside(pos, F) || steps >= stepsMax) {
28 :     pos = [nan,nan];
29 :     // HEY (BUG) we shouldn't even have to use non-finite values;
30 :     // we should be able to just say "die;". Currently, using
31 :     // "die" leads to the program never finishing...
32 :     stabilize;
33 :     }
34 :     vec2 grad = ∇F(pos);
35 :     real gmsq = grad • grad;
36 :     // If |∇F|=0 we can't compute update; we have to bail
37 :     if (gmsq == 0.0) {
38 :     pos = [nan,nan];
39 :     stabilize;
40 :     }
41 :     // delta = Newton-Raphson step
42 :     vec2 delta = -(F(pos) - isoval)*grad/gmsq;
43 :     // We've converged if the update is small enough
44 :     if (|delta| < epsilon) {
45 :     stabilize;
46 :     }
47 :     pos = pos + delta;
48 :     steps = steps + 1;
49 :     }
50 :     }
51 :    
52 :     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