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

SCM Repository

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

Diff of /branches/pure-cfg/test/vr-curv-quad.diderot

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1297, Thu Jun 9 12:44:43 2011 UTC revision 1529, Fri Oct 14 18:02:04 2011 UTC
# Line 1  Line 1 
1  // vr-curv  // vr-curv-quad
2  //  //
3  // Demonstration of curvature-based transfer functions in volume rendering  // Demonstration of curvature-based transfer functions in volume rendering
4  //  //
5  // process output with:  // process output with:
6  // unu reshape -i mip.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255  -o vr-curv-quad.png  // unu reshape -i vr-curv-quad.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255  -o vr-curv-quad.png
7    
8    // volume dataset
9  field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd");  field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd");
10    
11    // RGB colormap of (kappa1,kapp2)
12  field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd");  field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd");
13    
14  // set camera, image, and rendering parameters  // set camera, image, and rendering parameters
# Line 27  Line 30 
30  real phongKs = 0.3;  real phongKs = 0.3;
31  real phongSp = 45.0;  real phongSp = 45.0;
32    
33  // (boilerplate) computation of camera and light info  // boilerplate computation of camera and light info
34  real camDist = |camAt - camEye|;  real camDist = |camAt - camEye|;
35  real camVspNear = camNear + camDist;  real camVspNear = camNear + camDist;
36  real camVspFar = camFar + camDist;  real camVspFar = camFar + camDist;
# Line 40  Line 43 
43                            lightVspDir[1]*camV +                            lightVspDir[1]*camV +
44                            lightVspDir[2]*camN);                            lightVspDir[2]*camN);
45    
46    // RayCast(ui,vi) computes rendered color for pixel (ui,vi)
47  strand RayCast (int ui, int vi) {  strand RayCast (int ui, int vi) {
48      real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);      real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
49      real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);      real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
# Line 59  Line 63 
63                vec3 grad = -∇F(pos);                vec3 grad = -∇F(pos);
64                vec3 norm = normalize(grad);                vec3 norm = normalize(grad);
65                // begin curvature computation                // begin curvature computation
66                tensor[3,3] H = ∇(∇F)(pos);                tensor[3,3] H = ∇⊗∇F(pos);
67                tensor[3,3] P = identity[3] - norm⊗norm;                tensor[3,3] P = identity[3] - norm⊗norm;
68                tensor[3,3] G = -(P•H•P)/|grad|;                tensor[3,3] G = -(P•H•P)/|grad|;
69                real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));                real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
70                real k1 = (trace(G) + disc)/2.0;                real k1 = (trace(G) + disc)/2.0;
71                real k2 = (trace(G) - disc)/2.0;                real k2 = (trace(G) - disc)/2.0;
72                // finished curvature computation; begin finding sample RGBA                // find material RGBA
73                k1 = clamp(-1.0, 1.0, 6.0*k1);                vec3 matRGB = RGB([clamp(-1.0, 1.0, 6.0*k1),
74                k2 = clamp(-1.0, 1.0, 6.0*k2);                                   clamp(-1.0, 1.0, 6.0*k2)]);
               vec3 matRGB = RGB([k1,k2]);  
75                real alpha = min(1.0, lerp(0.0, 1.0,                real alpha = min(1.0, lerp(0.0, 1.0,
76                                           valOpacMin, val, valOpacMax));                                           valOpacMin, val, valOpacMax));
77                real ld = max(0.0, norm • lightDir);                real ld = max(0.0, norm • lightDir);
# Line 78  Line 81 
81                               + phongKd*ld*modulate(matRGB, lightRGB)                               + phongKd*ld*modulate(matRGB, lightRGB)
82                               + phongKs*hd^phongSp*lightRGB);                               + phongKs*hd^phongSp*lightRGB);
83                // composite with existing ray color and transparency                // composite with existing ray color and transparency
84                rayRGB = rayRGB + rayTransp*alpha*pntRGB;                rayRGB += rayTransp*alpha*pntRGB;
85                rayTransp = rayTransp*(1.0 - alpha);                rayTransp *= 1.0 - alpha;
86            }            }
87         }         }
88         if (rayTransp < 0.01) {  // early ray termination         if (rayTransp < 0.01) {  // early ray termination
89            rayTransp = 0.0;            rayTransp = 0.0;
           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];  
90            stabilize;            stabilize;
91         }         }
92         if (rayN > camVspFar) {         if (rayN > camVspFar) {
           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];  
93            stabilize;            stabilize;
94         }         }
95         rayN = rayN + rayStep;         rayN = rayN + rayStep;
96      }      }
97    
98        stabilize {
99           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];
100        }
101    
102      /* render: output maxval */      /* render: output maxval */
103  }  }
104    

Legend:
Removed from v.1297  
changed lines
  Added in v.1529

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