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

SCM Repository

[diderot] View of /branches/ein16/ertest/visprog/mode-iso-vr.diderot
ViewVC logotype

View of /branches/ein16/ertest/visprog/mode-iso-vr.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4537 - (download) (annotate)
Thu Sep 8 15:39:49 2016 UTC (3 years ago) by cchiw
File size: 3023 byte(s)
:central location of vis programs
input real isoval = 0.9;
input real thresh = 0;
input real thick = 0.8;

/*
lo-res version for testing compilation:
ln -sf dpl2001-smten9.nrrd ten9.nrrd

hi-res, no oversampling
ln -sf /Users/gk/d/dpl/dpl2001-ten9.nrrd ten9.nrrd

hi-res, with oversampling
ln -sf /Users/gk/d/dpl/dpl2008-ten9.nrrd ten9.nrrd

reall hi-res, with oversampling
ln -sf /Users/gk/d/dpl/dpl3346-ten9.nrrd ten9.nrrd
*/

field#2(3)[3,3] V = c4hexic ⊛ image("../data/ten9.nrrd");
//field#2(3)[3,3] V = bspln3 ⊛ image("../data/ten9.nrrd");
field#2(3)[3,3] E = V - trace(V)*identity[3]/3;
field#2(3)[] F = 3*sqrt(6)*det(E/|E|);

field#0(1)[3] cmap = tent ⊛ image("../data/diverg-cmap.nrrd");
function vec3 color(vec3 x) = cmap(clamp(-1,1,F(x)/2));

input real refStep = 1;

input vec3 camEye = [-71, 85, 72];
input vec3 camAt = [0, 0, -7];
input vec3 camUp = [0, 0, 1];
input real camNearAtRel = -20;
input real camFarAtRel = 20;
input real camFOV = 13;
input int iresU = 640;
input int iresV = 400;
input real phongKa = 0.3;
input real phongKd = 0.7;
input real rayStep = 0.4;
input vec3 lightVsp = [-2.0, -3.5, -4.0];

// (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 from eye
vec3 camU = normalize(camN × camUp);    // right
vec3 camV = camN × camU;                // down
real camVmax = tan(camFOV*π/360)*camDist;
real camUmax = camVmax*iresU/iresV;
vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);

function real isoalpha(real v, real g) = max(clamp(0, 1, 1.3*(1 - |v+isoval|/(g*thick))),
                                             clamp(0, 1, 1.3*(1 - |v-isoval|/(g*thick))));
function real rigalpha(real v, real g) = clamp(0, 1, 1.3*(1 - |v/g|/thick));

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 = (camDist*camN + rayU*camU + rayV*camV)/camDist;
  real transp = 1;
  vec3 rgb = [0, 0, 0];
  output vec4 rgba = [0, 0, 0, 0];

  update {
    vec3 x = camEye + rayN*rayVec;
    if (inside(x,V)) {
      vec3 grad = [0,0,0];
      real a = 0;

      real val = F(x);        // (iso) NOTRIG
      grad = -∇F(x);          // (iso) NOTRIG
      a = isoalpha(val, |grad|); // (iso) NOTRIG


      if (a > 0) {
        a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
        real depth = lerp(1.1, 0.8, camNear, rayN, camFar);
        real shade = |normalize(grad)•light|;
        rgb += transp*a*depth*(phongKa + phongKd*shade)*color(x);
        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