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 1883 - (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 1883 image(2)[] diderot = load("data/ddro-80.nrrd"); 12 : jhr 1880 field#1(2)[] F = ctmr ⊛ diderot; 13 : int stepsMax = 10; 14 : real epsilon = 0.0001; 15 : 16 : strand sample (int ui, int vi) { 17 : output vec2 pos = [lerp(0.0, 1.0, -0.5, real(ui), real(gridSize)-0.5), 18 : lerp(0.0, 1.0, -0.5, real(vi), real(gridSize)-0.5)]; 19 : // set the isvalue to 50, 30, or 10, depending on whichever we're closest to 20 : real isoval = 50.0 if F(pos) >= 40.0 21 : else 30.0 if F(pos) >= 20.0 22 : else 10.0; 23 : int steps = 0; 24 : update { 25 : // We bail if we're no longer inside or taken too many steps. 26 : if (!inside(pos, F) || steps > stepsMax) { 27 : die; 28 : } 29 : // GLKs recent changes (revision 1329) were made to make the code 30 : // a more obvious implementation of Newton-Raphson, and also to create 31 : // some obvious and not-so-obvious opportunties for optimization 32 : vec2 grad = ∇F(pos); 33 : if (|grad| == 0.0) { // can't compute step if |∇F|, so have to bail 34 : die; 35 : } 36 : vec2 norm = normalize(grad); 37 : vec2 delta = -((F(pos) - isoval)/|grad|)*norm; // Newton-Raphson step 38 : if (|delta| < epsilon) { // we've converged if step is small enough 39 : stabilize; 40 : } 41 : pos += delta; 42 : steps += 1; 43 : } 44 : } 45 : 46 : 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