Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /branches/charisee/ertest/vispaper/gmiso2d/gmiso2d.diderot
 [diderot] / branches / charisee / ertest / vispaper / gmiso2d / gmiso2d.diderot

# View of /branches/charisee/ertest/vispaper/gmiso2d/gmiso2d.diderot

Sat Mar 14 16:34:25 2015 UTC (4 years, 6 months ago) by cchiw
File size: 1295 byte(s)
`load->image, det(), S*T`
```/*

../../../bin/diderotc gmiso2d.diderot \
&& ./gmiso2d \
&& unu jhisto -i gmiso2d.txt -b 600 600 -min -2 -1 -max 0 1 | \
unu 2op neq - 0 | \
unu quantize -b 8 -o gmiso2d.png \
&& open gmiso2d.png

*/

//note my branch doesn't know Inputs, "InputWithDefault"
//input real isoval = 0.5;

real isoval = 1.0;
field#2(2)[] V = bspln3 ⊛ image("parab3.nrrd");
field#1(2)[] F = |∇V| - isoval;

int grid = 150;
int stepsMax = 10;
real epsilon = 0.000001;

strand RootFind(real xi,real yi) {
output vec2 x = [xi,yi];
int steps = 0;

update {
// Stop if we're no longer inside or taken too many steps.
if (!inside(x, V) || steps > stepsMax)
die;

// subsequent expressions are undefined if |∇F| is zero
if (|∇F(x)| == 0.0)
die;

// the Newton-Raphson step
vec2 delta = normalize(∇F(x)) * F(x)/|∇F(x)|;

// we've converged if the change is small enough
if (|delta| < epsilon)
stabilize;
x -= delta;
steps += 1;
}
}

initially { RootFind(lerp(-2.5, 0.5, -0.5, ui, grid-0.5),
lerp(-1.5, 1.5, -0.5, vi, grid-0.5))
| vi in 0..(grid-1), ui in 0..(grid-1) };

/*
different in 3D:
vec2 -> vec3
field#1(2)[] F -> field#1(3)[] F
initially over 3D grid
*/
```