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

SCM Repository

[diderot] View of /tests/vis15-bugs/dvrbug.diderot
ViewVC logotype

View of /tests/vis15-bugs/dvrbug.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4796 - (download) (annotate)
Mon Oct 24 11:39:31 2016 UTC (2 years, 9 months ago) by glk
File size: 5821 byte(s)
note on apparently problematic line
input bool GfpMip = true;
input bool boundGfpByRfpIso = true;
input bool includeGfpByTindic = false;
input bool includeGfpByTdist = false;
input bool renderTdist = true;
input bool fbfaHack = true;
input real Tindic = 0;
input bool verbose = true;
input vec3 RfpCol = [1,0,0];
input vec3 GfpCol = [0,1,0];
input vec3 TrkCol = [0,0,1];
input vec3 camEye;
input vec3 camAt;
input vec3 camUp;
input real camNearAtRel;
input real camFarAtRel;
input real camFOV = 20;
input int iresU;
input int iresV;
input real refStep;
input real rayStep;
input real thickness;
input vec3 lightVsp = [1, 1, -1];
input real phongKa = 0.2;
input real phongKd = 0.8;
input real maxalpha = 1.0;
input vec3 trackedIdx = [0,0,0];
vec3 tracked = [[0.37052959203720093,-3.9941885471343994,0],
[3.9941885471343994,0.37052959203720093,0],
[0,0,-4.2697978019714355]]•trackedIdx + [2959.3408203125,1106.0570068359375,1147.5330810546875];

input real Risoval = 1800;

/*
//input real Gisoval = 2000;
field#1(3)[2] V = ctmr ⊛ image("vol.nrrd");
field#1(3)[] Gfp = V[0] - Gisoval;
field#1(3)[] Rfp = V[1] - Risoval;
*/

input image(3)[] Gimg = image("dvrbug-vol.nrrd");
input image(3)[] Rimg = image("dvrbug-vol.nrrd");
input image(3)[] Timg = image("dvrbug-vol.nrrd");

field#2(3)[] Gfp = bspln3 ⊛ Gimg;
field#2(3)[] Rfp = bspln3 ⊛ Rimg - Risoval;
field#1(3)[] Tdist = c1tent ⊛ Timg - 13;

function real alpha(real v, real g) = clamp(0, 1, (1 - |v|/(g*thickness)));
function real inalpha(real v, real g) = (1.0 if v > 0 else max(0.0, 1.0 - |v|/(g*thickness)));
function real alphx(real x) = (1 if x < 0 else clamp(0, 1, 1.4 - |x|/thickness));

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

// (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; // - rayStep;
  vec3 rayVec = camN + (rayU*camU + rayV*camV)/camDist;
  vec3 rayDir = normalize(rayVec);
  real transp = 1;
  vec3 RGB = [0,0,0];
  real Gmax = 0;
  output real TT = ∞;
  output vec4 RGBa = [0,0,0,0];
  update {
    if (verbose && ui == 0 && rayN == camNear) {
       print("", vi, "/", iresV, "\n");
    }
    rayN = rayN + rayStep;
    if (rayN > camFar) {
      stabilize;
    }
    real trkN = (tracked - camEye)•camN;
    vec3 x = camEye + rayN*rayVec;
    TT = min(TT, |x-tracked|);

    if (!inside(x,Gfp)) { continue; }

    real depth = 1; // lerp(1, 1, camNear, rayN, camFar);

    vec3 tot = tracked - x;
    if (Tindic > 0) {
        real val = |tot|;
        vec3 grad = -tot;
        real aa = clamp(0,1,3*maxalpha*(1 - |val - Tindic|/(0.7*thickness)));
        aa = 1 - pow(1-aa, rayStep*|rayVec|/refStep);
        vec3 gdir = normalize(grad);
        aa *= 1 if (gdir•rayDir)^2 < 0.15 else 0;
        real shade = lerp(0,1, -1,|gdir•light|,1)^3;
        RGB += [1,1,1]*transp*depth*aa*(phongKa + phongKd*shade);
        transp *= 1 - aa;
    }

    // -------- Rfp isosurface
    real val = Rfp(x);
    vec3 grad = -∇Rfp(x);
    real aa = maxalpha*alpha(val, |grad|);
    vec3 gdir = normalize(grad);
    if (fbfaHack) { aa *= lerp(0.25,1,(1-(gdir•rayDir)^2)^2); }
    aa = 1 - pow(1-aa, rayStep*|rayVec|/refStep);
    real shade = lerp(0,1, -1,gdir•light,1)^3;
    RGB += RfpCol*transp*depth*aa*(phongKa + phongKd*shade);
    transp *= 1 - aa;

    real inA = 0; // inalpha(val, |grad|) if boundGfpByRfpIso else 0;
    if (Tindic > 0) {
      if (includeGfpByTindic && |tot| < 1.5*Tindic) {
         inA = max(inA, 1 if |tot| < Tindic else
                        lerp(1,0,Tindic,|tot|,1.5*Tindic) if |tot| < 1.5*Tindic else 0);
      }
      if (includeGfpByTdist && |trkN - rayN| < 1.5*Tindic) {
      print("HEY HEY\n");
         inA = max(inA, 1 if |trkN - rayN| < Tindic else
                        lerp(1,0,Tindic,|trkN - rayN|,1.5*Tindic) if |trkN - rayN| < 1.5*Tindic else 0);
      }
    }
    inA = 0;  // BUG: adding this line crashes compiler

    if (inA > 0) {
       if (GfpMip) {
           Gmax = max(Gmax, inA*Gfp(x));
       } else {
          tensor[3,3] hh = ∇⊗∇Gfp(x);
          vec3 delta = inv(hh)•∇Gfp(x);
          aa = inA*alphx(|delta| - 19);
          if (aa > 0) {
             real{3} eval = evals(hh);
             aa *= clamp(0,1,lerp(0,1,0.04,-eval{0},0.11));
          }
          aa = 1 - pow(1-aa, rayStep*|rayVec|/refStep);
          shade = lerp(0,1, -1,normalize(delta)•light,1)^3;
          RGB += GfpCol*transp*aa*(phongKa + phongKd*shade);
          transp *= 1 - aa;
       }
    }
    if (renderTdist) {
       // -------- Tdist isosurface
       val = Tdist(x);
       grad = ∇Tdist(x);
       aa = maxalpha*alpha(val, |grad|);
       aa = 1 - pow(1-aa, rayStep*|rayVec|/refStep);
       gdir = normalize(grad);
       shade = lerp(0,1, -1,gdir•light,1)^3;
       RGB += TrkCol*transp*depth*aa*(phongKa + phongKd*shade);
       transp *= 1 - aa;
    }
  }
   stabilize {
      real aa = 1-transp;
      real RR = RGB[0];
      real GG = RGB[1];
      real BB = RGB[2];
      if (GfpMip) {
         if (aa > 0) { RR = RR/aa; BB = BB/aa; }
         GG = Gmax;
      } else {
         if (aa > 0) { RR = RR/aa; GG = GG/aa; BB = BB/aa; }
      }
      RGBa = [RR, GG, BB, aa];
   }
}
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