Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

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

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

Fri Feb 27 17:31:40 2015 UTC (6 years, 2 months ago) by glk
File size: 1106 byte(s)
`isosurfaces of vector magnitude`
```/*

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

*/

real isoval = 0.2;
field#2(2)[2] V = bspln3 ⊛ load("vec3.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(-1.5, 1.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) };
```