Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /branches/vis12/test/iso2d.diderot
 [diderot] / branches / vis12 / test / iso2d.diderot

# View of /branches/vis12/test/iso2d.diderot

Sat Feb 23 15:51:42 2013 UTC (6 years, 11 months ago) by jhr
File size: 1893 byte(s)
```  Add comment about something that doesn't work.
```
```// iso2d
//
// Demo of finding isocontours via Newton-Raphson method.
// Initializes positions on a grid, and each update applies one
// step of Newton-Raphson.
//
// Process output with:
// unu jhisto -i pos.nrrd -b 512 512 -min 0 0 -max 1 1 | unu 2op neq - 0 | unu quantize -b 8  -o iso2d.png

int gridSize = 300;
field#1(2)[] F = ctmr ⊛ image("../data/ddro-80.nrrd");
int stepsMax = 10;
real epsilon = 0.0001;

strand sample (int ui, int vi) {
output 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)];
// set the isvalue to 50, 30, or 10, depending on whichever we're closest to
real isoval = 50.0 if F(pos) >= 40.0
else 30.0 if F(pos) >= 20.0
else 10.0;
// the following won't work, because the compiler doesn't know how to deal with state vars that
// are fields (really just a local binding)!
//    field#1(2)[] G = F - isoval;
int steps = 0;
update {
field#1(2)[] G = F - isoval;
// We bail if we're no longer inside or taken too many steps.
if (!inside(pos, G) || steps > stepsMax) {
die;
}
// GLKs recent changes (revision 1329) were made to make the code
// a more obvious implementation of Newton-Raphson, and also to create
// some obvious and not-so-obvious opportunties for optimization
if (|grad| == 0.0) {    // can't compute step if |∇F|, so have to bail
die;
}