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

SCM Repository

[diderot] Annotation of /branches/fem/test/vr-curv-quad.diderot
ViewVC logotype

Annotation of /branches/fem/test/vr-curv-quad.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3210 - (view) (download)

1 : glk 1163 // vr-curv-quad
2 : jhr 1115 //
3 :     // Demonstration of curvature-based transfer functions in volume rendering
4 :     //
5 :     // process output with:
6 : glk 2677 // overrgb -i outRGBA.nrrd -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 : jhr 1115
8 : glk 1163 // volume dataset
9 : glk 2677 field#2(3)[] F = bspln3 ⊛ image("../data/quad-patches-pad.nrrd");
10 : glk 1163
11 :     // RGB colormap of (kappa1,kapp2)
12 : jhr 1927 field#0(2)[3] RGB = tent ⊛ image("../data/txf/2d-bow.nrrd");
13 : jhr 1115
14 :     // set camera, image, and rendering parameters
15 :     vec3 camEye = [183.021, -411.857, 686.458];
16 : glk 2677 input bool camOrtho = false;
17 :     vec3 camAt = [55.4037, 40.2407, 0];
18 : jhr 1115 vec3 camUp = [0.0, 0.0, 1.0];
19 :     real camNear = -42.0;
20 :     real camFar = 42.0;
21 :     real camFOV = 7.15;
22 :     int imgResU = 480;
23 :     int imgResV = 345;
24 :     real rayStep = 0.2;
25 :     real valOpacMin = -0.25;
26 :     real valOpacMax = -0.10;
27 :     vec3 lightVspDir = [0.9, -2.5, -2.5];
28 :     vec3 lightRGB = [1.0, 1.0, 1.0];
29 :     real phongKa = 0.1;
30 :     real phongKd = 0.7;
31 :     real phongKs = 0.3;
32 :     real phongSp = 45.0;
33 :    
34 : glk 1163 // boilerplate computation of camera and light info
35 : jhr 1115 real camDist = |camAt - camEye|;
36 :     real camVspNear = camNear + camDist;
37 :     real camVspFar = camFar + camDist;
38 :     vec3 camN = normalize(camAt - camEye);
39 :     vec3 camU = normalize(camN × camUp);
40 :     vec3 camV = camN × camU;
41 :     real camVmax = tan(camFOV*π/360.0)*camDist;
42 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
43 : glk 2677 vec3 lightDir = normalize(lightVspDir[0]*camU +
44 :     lightVspDir[1]*camV +
45 : jhr 1115 lightVspDir[2]*camN);
46 :    
47 : glk 1163 // RayCast(ui,vi) computes rendered color for pixel (ui,vi)
48 : jhr 1115 strand RayCast (int ui, int vi) {
49 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
50 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
51 : glk 2677 vec3 rayVec = camN if camOrtho else (camDist*camN + rayU*camU + rayV*camV)/camDist;
52 :     vec3 rayEye = (rayU*camU + rayV*camV if camOrtho else [0,0,0]) + camEye;
53 : glk 1124 vec3 vv = normalize(-rayVec);
54 : jhr 1115
55 :     real rayN = camVspNear;
56 :     real rayTransp = 1.0;
57 :     vec3 rayRGB = [0.0, 0.0, 0.0];
58 :     output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];
59 :    
60 :     update {
61 : glk 2677 vec3 pos = rayEye + rayN*rayVec;
62 : jhr 1115 if (inside (pos,F)) {
63 :     real val = F(pos);
64 : glk 2677 if (val > valOpacMin) { // we have some opacity
65 : jhr 1115 vec3 grad = -∇F(pos);
66 :     vec3 norm = normalize(grad);
67 :     // begin curvature computation
68 : jhr 1640 tensor[3,3] H = ∇⊗∇F(pos);
69 : jhr 1115 tensor[3,3] P = identity[3] - norm⊗norm;
70 :     tensor[3,3] G = -(P•H•P)/|grad|;
71 :     real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
72 :     real k1 = (trace(G) + disc)/2.0;
73 :     real k2 = (trace(G) - disc)/2.0;
74 : glk 1163 // find material RGBA
75 : glk 1330 vec3 matRGB = RGB([clamp(-1.0, 1.0, 6.0*k1),
76 :     clamp(-1.0, 1.0, 6.0*k2)]);
77 : jhr 1115 real alpha = min(1.0, lerp(0.0, 1.0,
78 :     valOpacMin, val, valOpacMax));
79 :     real ld = max(0.0, norm • lightDir);
80 : glk 1124 real hd = max(0.0, norm • normalize(lightDir + vv));
81 : jhr 1115 // Phong shading
82 :     vec3 pntRGB = (phongKa*matRGB
83 : jhr 1383 + phongKd*ld*modulate(matRGB, lightRGB)
84 :     + phongKs*hd^phongSp*lightRGB);
85 : jhr 1115 // composite with existing ray color and transparency
86 : glk 1330 rayRGB += rayTransp*alpha*pntRGB;
87 :     rayTransp *= 1.0 - alpha;
88 : jhr 1115 }
89 :     }
90 :     if (rayTransp < 0.01) { // early ray termination
91 :     rayTransp = 0.0;
92 :     stabilize;
93 :     }
94 :     if (rayN > camVspFar) {
95 :     stabilize;
96 :     }
97 :     rayN = rayN + rayStep;
98 :     }
99 :    
100 : jhr 1640 stabilize {
101 :     outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];
102 :     }
103 : glk 1163
104 : jhr 1640 /* render: output maxval */
105 : jhr 1115 }
106 :    
107 :     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