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