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

SCM Repository

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

View of /branches/lamont/test/lzc2d-brute-BUG1.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: 3054 byte(s)
Creating new developmented branch based on vis12
// lzc2d-brute
//
// Demo of laplacian zero-crossing edges via brute-force search
// and then Illinois false position
//
// 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 lzc2d.png

int gridSize = 300;
field#2(2)[] F = c4hexic ⊛ image("../data/ddro-64.nrrd");
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)];
    vec2 posA=pos;
    vec2 posB=pos;
    int stepsNum = 0;
    int side = 0;
    real step = 0.004;
    real fA=0.0;
    real fB=0.0;
    real A=0.0;
    real B=1.0;
    bool searching = true;
    update {
        // We bail if we're no longer inside or taken too many steps.
        if (!inside(pos, F) || stepsNum > stepsMax) {
	    die;
        }
        if (searching) {
          posA = pos;
          real ll = trace(∇⊗∇F(pos));
          vec2 dir = normalize(∇F(pos));
          real sgn = 1.0 if ll > 0.0 else -1.0;
          posB = pos + sgn*step*dir;
          searching = trace(∇⊗∇F(posB))*ll > 0.0;
          if (!searching) {
             /* set up next phase */
             fA = trace(∇⊗∇F(posA));
             fB = trace(∇⊗∇F(posB));
          }
        } else {
          pos = lerp(posA, posB, fA, 0.0, fB);
          real fs = trace(∇⊗∇F(pos));
          if (0.0 == fs) {
            stabilize;
          }
          if (fs*fB > 0.0) { /* not between s and b */
            posB = pos;
            fB = fs;
            if (1 == side) {
              fA /= 2.0;
            }
            side = 1;
          } else { /* not between a and s */
            posA = pos;
            fA = fs;
            if (-1 == side) {
              fB /= 2.0;
            }
            side = -1;
          }
          if (|posA - posB| < epsilon ) {
            /* BUG: is this the long-standing well-known control-flow graph bug?        
            compiling generates:

            error in cvtMethod(Update, ...)
            uncaught exception Fail [Fail: unimplemented]
              raised at common/phase-timer.sml:76.50-76.52
              raised at translate/translate.sml:384.110-384.112
              raised at translate/translate.sml:324.29-324.31
              raised at translate/translate.sml:324.29-324.31
              raised at translate/translate.sml:324.29-324.31
              raised at translate/translate.sml:297.29-297.49
             
            but this is a place where the choice between stabilize and die
            (and one of the two will certainly be called) depends on a test.
            Can be re-written without an else branch but seems cleaner this way.
            */
            if (|∇F(pos)| > 0.0001) {
              stabilize;
            } else {
              die;
            }
          }
        }
        stepsNum += 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