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 866 - (view) (download)

1 : glk 866 // vr-curv
2 :     //
3 :     // curvature-based volume rendering
4 :    
5 :     string dataFile = "../data/quad-patches-pad.nrrd";
6 :     vec3 camEye = [183.021, -411.857, 686.458];
7 :     vec3 camAt = [55.4037, 40.2407, 4.32732];
8 :     vec3 camUp = [0.0, 0.0, 1.0];
9 :     real camNear = -42.0;
10 :     real camFar = 42.0;
11 :     real camFOV = 7.15;
12 :     //int imgResU = 640;
13 :     //int imgResV = 480;
14 :     int imgResU = 480;
15 :     int imgResV = 345;
16 :     //int imgResU = 320;
17 :     //int imgResV = 240;
18 :     real rayStep = 2.0;
19 :     real valOpacMin = -0.1;
20 :     real valOpacMax = 0.1;
21 :     image(2)[] imgR = load("../data/hue-0.nrrd"); field#0(2)[] RR = imgR ⊛ tent;
22 :     image(2)[] imgG = load("../data/hue-1.nrrd"); field#0(2)[] GG = imgG ⊛ tent;
23 :     image(2)[] imgB = load("../data/hue-2.nrrd"); field#0(2)[] BB = imgB ⊛ tent;
24 :     //image(2)[3] imgRGB = load("../data/hue.nhdr"); field#0(2)[3] RGB = imgRGB ⊛ tent;
25 :    
26 :     real camDist = |camAt - camEye|;
27 :     real camVspNear = camNear + camDist;
28 :     real camVspFar = camFar + camDist;
29 :     vec3 camN = normalize(camAt - camEye);
30 :     vec3 camU = normalize(camN × camUp);
31 :     vec3 camV = camN × camU;
32 :     real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
33 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
34 :    
35 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
36 :     vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
37 :    
38 :     real phongKa = 0.05;
39 :     real phongKd = 0.80;
40 :     real phongKs = 0.20;
41 :     real phongSp = 30.0;
42 :    
43 :     image(3)[] img = load (dataFile);
44 :     field#2(3)[] F = img ⊛ bspln3;
45 :    
46 :     strand RayCast (int ui, int vi)
47 :     {
48 :     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);
50 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
51 :    
52 :     real rayN = camVspNear;
53 :     real transp = 1.0;
54 :     real gray = 0.0;
55 :     real or = 0.0;
56 :     real og = 0.0;
57 :     real ob = 0.0;
58 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
59 :    
60 :     update
61 :     {
62 :     vec3 pos = camEye + rayN*rayVec;
63 :     if (inside (pos,F)) {
64 :     // ########## BEGIN per-sample code
65 :     real val = F@pos;
66 :     vec3 grad = -∇F@pos;
67 :     vec3 norm = normalize(grad);
68 :     if (val > valOpacMin) { // we have some opacity
69 :     tensor[3,3] H = ∇(∇F)@pos;
70 :     tensor[3,3] P = identity[3] - norm⊗norm;
71 :     tensor[3,3] G = (P•H•P)/|grad|;
72 :     real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
73 :     real k1 = max(-0.19, min(0.19, (trace(G) + disc)/2.0));
74 :     real k2 = max(-0.19, min(0.19, (trace(G) - disc)/2.0));
75 :     vec2 kk = [k1,k2];
76 :     vec3 rgb = RGB@kk if inside(kk,RGB)
77 :     else [0.0,0.0,0.0];
78 :     real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
79 :     real ld = lightDir • norm;
80 :     real mat = ( phongKa
81 :     + phongKd*(ld if ld > 0.0 else 0.0)
82 :     + phongKs*(ld^phongSp if ld > 0.0 else 0.0));
83 :     gray = gray + transp*opac*mat;
84 :     or = or + transp*opac*mat*rgb[0];
85 :     og = og + transp*opac*mat*rgb[1];
86 :     ob = ob + transp*opac*mat*rgb[2];
87 :     transp = transp*(1.0 - opac);
88 :     }
89 :     }
90 :     if (transp < 0.001) { // early ray termination
91 :     // rgba = [gray, gray, gray, 1.0];
92 :     rgba = [or, og, ob, 1.0];
93 :     stabilize;
94 :     }
95 :     if (rayN > camVspFar) {
96 :     rgba = [gray, gray, gray, 1.0-transp];
97 :     stabilize;
98 :     }
99 :     rayN = rayN + rayStep;
100 :     }
101 :    
102 :     /* render: output maxval */
103 :     }
104 :    
105 :     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