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

SCM Repository

[diderot] View of /branches/vis12/bugs/open/bug051.diderot
ViewVC logotype

View of /branches/vis12/bugs/open/bug051.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3379 - (download) (annotate)
Fri Nov 6 16:06:47 2015 UTC (3 years, 10 months ago) by jhr
File size: 5598 byte(s)
  update NOTES for new bugs
/*

** A workaround is to use the --disable-mid-check command-line argument

Regardless of whether this is technically a bug, this is a problem that
effectively halted further experimentation with this program, just like
a bug does.

Changing the kernel from c2tent or bspln3 to c4hexic causes the
compile time to increase by more than a factor of ten. Compiling
with: /usr/bin/time ../../bin/diderotc --exec --log bug051.diderot
has the following times:

with c4hexic
       47.32 real        37.30 user        10.00 sys
with bspln3
        2.50 real         2.28 user         0.21 sys
with c2tent
        1.02 real         0.90 user         0.12 sys

Also, charisee's compiler crashes on this program; this should
be used to monitor the success of merging.
error converting:
 EINAPP grad0CE4-EIN-0:IMG(3)< >, 1:KRN 2:TEN <>,  <[|v0_{}★h(1)dx_0}|[ S2]]> _{(0 DIM:3)}
img0611 , _t0633 , x06F9
uncaught exception Fail [Fail: Expected Image and kernel arguments]
  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:289.118-289.120
  raised at high-to-mid/ProbeEin.sml:73.23-73.65
*/

// set camera, image, and rendering parameters
input vec3 camEye = [3582.12, 2068.56, -6651.47];
input vec3 camAt = [4081.46, 3089.44, 1508.09];
input vec3 camUp = [-0.71549, -0.686483, 0.129674];
input real camNearAtRel = -973.999;
input real camFarAtRel = 956.383;
input real camFOV = 13;
input int iresU = 600;
input int iresV = 480;
input real refStep = 1;
input real rayStep = 2;
input vec3 lightVsp = [-2, -3, -4];
input real phongKa = 0.3;
input real phongKd = 0.7;
input real thickness = 1;

input real isoval = 5300;
input int which = 0;

input image(3)[] img = image("../data/dotf.nrrd");
field#2(3)[] F = c4hexic ⊛ img; // crazy long compile time
//field#2(3)[] F = bspln3 ⊛ img;  // normal compile time
//field#2(3)[] F = c2tent ⊛ img;  // normal compile time

function real alpha(real v, real g) = max(0, 1 - |v|/(g*thickness));

function tensor[3,3] inverse(tensor[3,3] A) {
  real dd = (  A[0,0]*A[1,1]*A[2,2]
             + A[1,0]*A[2,1]*A[0,2]
             + A[2,0]*A[0,1]*A[1,2]
             - A[2,0]*A[1,1]*A[0,2]
             - A[1,0]*A[0,1]*A[2,2]
             - A[0,0]*A[2,1]*A[1,2]);
  tensor[3,3] ret = [[ (A[1,1]*A[2,2] - A[1,2]*A[2,1]),
                      -(A[0,1]*A[2,2] - A[0,2]*A[2,1]),
                       (A[0,1]*A[1,2] - A[0,2]*A[1,1])],
                     [-(A[1,0]*A[2,2] - A[1,2]*A[2,0]),
                       (A[0,0]*A[2,2] - A[0,2]*A[2,0]),
                      -(A[0,0]*A[1,2] - A[0,2]*A[1,0])],
                     [ (A[1,0]*A[2,1] - A[1,1]*A[2,0]),
                      -(A[0,0]*A[2,1] - A[0,1]*A[2,0]),
                       (A[0,0]*A[1,1] - A[0,1]*A[1,0])]];
  ret /= dd;
  return ret;
}

function bool pten(tensor[3,3] M) {
  print("  [", M[0,0], " ", M[0,1], " ", M[0,2], "]\n       [", M[1,0], " ", M[1,1], " ", M[1,2], "]\n       [", M[2,0], " ", M[2,1], " ", M[2,2], "]\n");
  return true;
}

// (boilerplate) computation of camera and light info
real camDist = |camAt - camEye|;
real camNear = camNearAtRel + camDist;
real camFar = camFarAtRel + camDist;
vec3 camN = normalize(camAt - camEye);  // away
vec3 camU = normalize(camN × camUp);    // right
vec3 camV = camU × camN;                // up
real camVmax = tan(camFOV*π/360)*camDist;
real camUmax = camVmax*iresU/iresV;
vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);

strand raycast(int ui, int vi) {
  real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5);
  real rayV = lerp(camVmax, -camVmax, -0.5, vi, iresV-0.5);
  real rayN = camNear;
  vec3 rayVec = camN + (rayU*camU + rayV*camV)/camDist;
  real transp = 1;
  vec3 rgb = [0,0,0];
  output vec4 rgba = [0,0,0,0];
  int stepi = 0;
  bool noop = false;

  update {
    stepi += 1;
    vec3 x = camEye + rayN*rayVec;
    if (inside(x,F)) {
      vec3 grad = ∇F(x);
      real a = 0;
      if (0 == which) {  // isosurface
        real val = F(x) - isoval;
        if (61 == ui && 48 == vi) {
          print("stepi ", stepi, ": x=", x, " F(x)=", F(x), "\n");
        }
        a = alpha(val, |grad|);
      } else if (1 == which) { // peaks
        tensor[3,3] hess = ∇⊗∇F(x);
        tensor[3,3] hinv = inverse(hess);
        tensor[3,3] hprd = hinv•hess;
        vec3 off = hinv•grad;
        a = alpha(|off|, 1);
        if (61 == ui && 48 == vi && F(x) > isoval) { // && (446 < stepi && stepi < 450)) {
          print("stepi ", stepi, ": x=", x, " F(x)=", F(x), "\n");
          print("     hess = "); noop = pten(hess);
          print("     hinv = "); noop = pten(hinv);
          print("     hprd = "); noop = pten(hprd);
          print("   off = ", off, "\n");
          print("   |off| = ", |off|, "\n");
          print("   F(x+off) = ", F(x+off), "\n");
          print("   |del(F+off)| = ", |∇F(x+off)|, "\n");
        }
        grad = off;
      }
      if (a > 0) {  // we have some opacity
        a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
        real depth = lerp(1.3, 0.6, camNear, rayN, camFar);
        real shade = max(0, -normalize(grad)•light);
        rgb += transp*depth*a*(phongKa + phongKd*shade)*[1,1,1];
        transp *= 1 - a;
      }
    }
    if (transp < 0.01) {  // early ray termination
      transp = 0;
      stabilize;
    }
    if (rayN > camFar) {
      stabilize;
    }
    rayN = rayN + rayStep;
  }
  stabilize {
    real a = 1-transp;
    if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a];
  }
}
initially [ raycast(ui, vi) | vi in 0..iresV-1, ui in 0..iresU-1 ];

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0