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.diderot
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1009 - (view) (download)

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