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

# SCM Repository

[diderot] Annotation of /examples/iso2d-demo/iso2d.diderot
 [diderot] / examples / iso2d-demo / iso2d.diderot

# Annotation of /examples/iso2d-demo/iso2d.diderot

Revision 2079 - (view) (download)

 1 : jhr 1880 // 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 iso2d.txt -b 512 512 -min 0 0 -max 1 1 | unu 2op neq - 0 | unu quantize -b 8 -o iso2d.png 9 : 10 : int gridSize = 300; 11 : jhr 2044 image(2)[] diderot = image("data/ddro-80.nrrd"); 12 : jhr 1880 field#1(2)[] F = ctmr ⊛ diderot; 13 : jhr 2079 input int stepsMax = 50; 14 : input real stepScale = 1.0; 15 : jhr 1880 real epsilon = 0.0001; 16 : 17 : strand sample (int ui, int vi) { 18 : jhr 1920 // world is 1x1 centered at (0.5, 0.5) 19 : jhr 1880 output vec2 pos = [lerp(0.0, 1.0, -0.5, real(ui), real(gridSize)-0.5), 20 : lerp(0.0, 1.0, -0.5, real(vi), real(gridSize)-0.5)]; 21 : jhr 1920 // set the isvalue to 50, 30, or 10, depending on whichever we're closest to 22 : jhr 1880 real isoval = 50.0 if F(pos) >= 40.0 23 : else 30.0 if F(pos) >= 20.0 24 : else 10.0; 25 : int steps = 0; 26 : update { 27 : jhr 1920 // We bail if we're no longer inside or taken too many steps. 28 : jhr 1880 if (!inside(pos, F) || steps > stepsMax) { 29 : die; 30 : } 31 : vec2 grad = ∇F(pos); 32 : if (|grad| == 0.0) { // can't compute step if |∇F|, so have to bail 33 : die; 34 : } 35 : vec2 norm = normalize(grad); 36 : vec2 delta = -((F(pos) - isoval)/|grad|)*norm; // Newton-Raphson step 37 : if (|delta| < epsilon) { // we've converged if step is small enough 38 : stabilize; 39 : } 40 : jhr 2079 pos += stepScale * delta; 41 : jhr 1880 steps += 1; 42 : } 43 : } 44 : 45 : 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