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

SCM Repository

[diderot] View of /branches/fem/test/lzc2d.diderot
ViewVC logotype

View of /branches/fem/test/lzc2d.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3210 - (download) (annotate)
Mon Jul 13 14:39:06 2015 UTC (4 years, 1 month ago) by cchiw
File size: 1580 byte(s)
creating a copy of branch of vis12
/* lzc2d

Demo of laplacian zero-crossing edges via Newton-Raphson method.
Initializes positions on a grid, and each update applies one
step of Newton-Raphson.

Process output with:

unu dice -i posgm.nrrd -a 0 -o ./
unu jhisto -i {0,1}.nrrd -min 0 0 -max 1 1 -b 600 600 -t float -o count.nrrd
unu jhisto -i {0,1}.nrrd -w 2.nrrd -min 0 0 -max 1 1 -b 600 600 -t float \
 | unu 2op / - count.nrrd \
 | unu 2op exists - 0 \
 | unu gamma -g 1.4 \
 | unu quantize -b 8 -o lzc2d.png
rm -f {0,1,2}.nrrd count.nrrd

*/


int gridSize = 500;
field#3(2)[] F = bspln5 ⊛ image("../data/ddro-128.nrrd");
int stepsMax = 30;
real epsilon = 0.00001;

strand sample (int ui, int vi) {
    output vec3 posgm = [0.0, 0.0, 0.0];
    vec2 pos = [lerp(0.0, 1.0, -0.5, real(ui), real(gridSize)-0.5),
                lerp(0.0, 1.0, -0.5, real(vi), real(gridSize)-0.5)];
    int steps = 0;
    update {
        // We bail if we're no longer inside or taken too many steps.
        if (!inside(pos, F) || steps > stepsMax) {
	    die;
        }
        vec2 grad = identity[2]:∇⊗∇⊗∇F(pos); // the gradient of the laplacian
        if (|grad| == 0.0) {
	    die;
        }
        vec2 norm = normalize(grad);
        vec2 delta = -(trace(∇⊗∇F(pos))/|grad|)*norm;  // Newton-Raphson step
        if (|delta| < epsilon) {    // we've converged if step is small enough
	    stabilize;
        }
        pos += delta;
        steps += 1;
    }
    stabilize {
       posgm = [pos[0], pos[1], |∇F(pos)|];
    }
}

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