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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1065 - (view) (download)

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