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

SCM Repository

[diderot] View of /branches/pure-cfg/test/vr-curv.diderot
ViewVC logotype

View of /branches/pure-cfg/test/vr-curv.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 866 - (download) (annotate)
Tue Apr 19 20:26:44 2011 UTC (8 years, 6 months ago) by glk
File size: 3566 byte(s)
for curvature demos
// vr-curv
//
// curvature-based volume rendering

string dataFile = "../data/quad-patches-pad.nrrd";
vec3 camEye = [183.021, -411.857, 686.458];
vec3 camAt = [55.4037, 40.2407, 4.32732];
vec3 camUp = [0.0, 0.0, 1.0];
real camNear = -42.0;
real camFar = 42.0;
real camFOV = 7.15;
//int imgResU = 640;
//int imgResV = 480;
int imgResU = 480;
int imgResV = 345;
//int imgResU = 320;
//int imgResV = 240;
real rayStep = 2.0;
real valOpacMin = -0.1;
real valOpacMax = 0.1;
image(2)[] imgR = load("../data/hue-0.nrrd"); field#0(2)[] RR = imgR ⊛ tent;
image(2)[] imgG = load("../data/hue-1.nrrd"); field#0(2)[] GG = imgG ⊛ tent;
image(2)[] imgB = load("../data/hue-2.nrrd"); field#0(2)[] BB = imgB ⊛ tent;
//image(2)[3] imgRGB = load("../data/hue.nhdr"); field#0(2)[3] RGB = imgRGB ⊛ tent;

real camDist = |camAt - camEye|;
real camVspNear = camNear + camDist;
real camVspFar = camFar + camDist;
vec3 camN = normalize(camAt - camEye);
vec3 camU = normalize(camN × camUp);
vec3 camV = camN × camU;
real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
real camUmax = camVmax*real(imgResU)/real(imgResV);

vec3 lightVspDir = [0.9, -1.0, -2.5];
vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);

real phongKa = 0.05;
real phongKd = 0.80;
real phongKs = 0.20;
real phongSp = 30.0;

image(3)[] img = load (dataFile);
field#2(3)[] F = img ⊛ bspln3;

strand RayCast (int ui, int vi)
{
    real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
    real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
    vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;

    real rayN = camVspNear;
    real transp = 1.0;
    real gray = 0.0;
    real or = 0.0;
    real og = 0.0;
    real ob = 0.0;
    output vec4 rgba = [0.0, 0.0, 0.0, 0.0];

    update
    {
       vec3 pos = camEye + rayN*rayVec;
       if (inside (pos,F)) {
          // ########## BEGIN per-sample code
          real val = F@pos;
          vec3 grad = -∇F@pos;
          vec3 norm = normalize(grad);
          if (val > valOpacMin) {  // we have some opacity 
              tensor[3,3] H = ∇(∇F)@pos;
              tensor[3,3] P = identity[3] - norm⊗norm;
              tensor[3,3] G = (P•H•P)/|grad|;
              real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
              real k1 = max(-0.19, min(0.19, (trace(G) + disc)/2.0));
              real k2 = max(-0.19, min(0.19, (trace(G) - disc)/2.0));
              vec2 kk = [k1,k2];
              vec3 rgb = RGB@kk if inside(kk,RGB) 
                    else [0.0,0.0,0.0];
              real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
              real ld = lightDir • norm;
              real mat = (  phongKa
                          + phongKd*(ld if ld > 0.0 else 0.0)
                          + phongKs*(ld^phongSp if ld > 0.0 else 0.0));
              gray = gray + transp*opac*mat;
              or = or + transp*opac*mat*rgb[0];
              og = og + transp*opac*mat*rgb[1];
              ob = ob + transp*opac*mat*rgb[2];
              transp = transp*(1.0 - opac);
          }
       }
       if (transp < 0.001) {  // early ray termination
//          rgba = [gray, gray, gray, 1.0];
          rgba = [or, og, ob, 1.0];
          stabilize;
       }
       if (rayN > camVspFar) {
          rgba = [gray, gray, gray, 1.0-transp];
          stabilize;
       }
       rayN = rayN + rayStep;
    }

    /* render: output maxval */
}

initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];

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