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

SCM Repository

[diderot] View of /branches/lamont/test/lzc2d-lifted.diderot
ViewVC logotype

View of /branches/lamont/test/lzc2d-lifted.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2081 - (download) (annotate)
Mon Nov 5 23:26:06 2012 UTC (6 years, 10 months ago) by lamonts
File size: 1766 byte(s)
Creating new developmented branch based on vis12
/* lzc2d-lifted

If we could lift tensor operations to fields ...

*/


int gridSize = 500;
field#4(2)[] img = bspln5 ⊛ image("../data/ddro-128.nrrd");

/*
BUG? get:
uncaught exception Fail [Fail: bogus field binding]
  raised at common/phase-timer.sml:76.50-76.52
  raised at common/phase-timer.sml:76.50-76.52
  raised at high-to-mid/high-to-mid.sml:141.19-141.45
*/
field#1(2)[] F = 2.0*img;


/*
BUG? get:
[lzc2d-lifted.diderot:31.1-32.0] Error: unable to resolve overloaded operator "-"
  argument type is: (field#4(2)[] * real)

uncaught exception Fail [Fail: Error in compiling lzc2d-lifted.diderot]
  raised at common/phase-timer.sml:76.50-76.52
  raised at common/phase-timer.sml:76.50-76.52
  raised at driver/main.sml:27.39-27.76
*/
//field#1(2)[] F = img - 30.0;

/* dreaming being able to define a field with more non-trivial
   operations on another */
//field#1(2)[] F = identity[2]:∇⊗∇img; // same as trace(∇⊗∇img)


int stepsMax = 30;
real epsilon = 0.00001;

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)];
    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 = ∇F(pos);
        if (|grad| == 0.0) {
	    die;
        }
        vec2 norm = normalize(grad);
        vec2 delta = -(F(pos)/|grad|)*norm;  // Newton-Raphson step
        if (|delta| < epsilon) {    // we've converged if step is small enough
	    stabilize;
        }
        pos += delta;
        steps += 1;
    }
}

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