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

SCM Repository

[diderot] Annotation of /branches/vis12/test/isosurf-lapl.diderot
ViewVC logotype

Annotation of /branches/vis12/test/isosurf-lapl.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1969 - (view) (download)

1 : glk 1968
2 :     /*
3 :    
4 :     ../bin/diderotc --exec isosurf-lapl.diderot \
5 :     && ./isosurf-lapl \
6 :     && overrgb -i rayRGBA.nrrd -b 0.1 0.15 0.2 -o isosurf-lapl.png
7 :    
8 :     */
9 :    
10 :     field#4(3)[] FF = bspln5 ⊛ image("../data/mobius.nrrd");
11 :    
12 :     // set camera, image, and rendering parameters
13 :     vec3 camEye = [-104.957, -249.445, 297.334];
14 :     vec3 camAt = [39.5087, 37.2972, 40.6096];
15 :     vec3 camUp = [0.16498, 0.610459, 0.774675];
16 :     real camNear = -46.0;
17 :     real camFar = 46.0;
18 :     real camFOV = 6.56;
19 :     int imgResU = 480;
20 :     int imgResV = 345;
21 :     real rayStep = 1;
22 :     int stepsMax = 20;
23 : glk 1969 real epsilon = 0.003;
24 : glk 1968 vec3 lightVspDir = [0.9, -2.5, -2.2];
25 :     real phongKa = 0.05;
26 :     real phongKd = 0.6;
27 :     real phongKs = 0.4;
28 :     real phongSp = 60.0;
29 :    
30 :     // boilerplate computation of camera and light info
31 :     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*π/360.0)*camDist;
38 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
39 :     vec3 lightDir = normalize(lightVspDir[0]*camU +
40 :     lightVspDir[1]*camV +
41 :     lightVspDir[2]*camN);
42 :    
43 :     // RayCast(ui,vi) computes rendered color for pixel (ui,vi)
44 :     strand RayCast (int ui, int vi) {
45 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
46 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
47 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
48 :     vec3 rayDir = normalize(rayVec);
49 :     bool skipping = true;
50 :     real rayN = camVspNear;
51 :     output vec4 rayRGBA = [0.0, 0.0, 0.0, 0.0];
52 :     int steps = 0;
53 :    
54 :     vec3 pos0 = [0.0,0.0,0.0]; // HEY unwanted initialization
55 :     vec3 pos1 = [0.0,0.0,0.0]; // HEY unwanted initialization
56 :     vec3 pos = [0.0,0.0,0.0]; // HEY unwanted initialization
57 :    
58 :     update {
59 :     if (skipping) {
60 : glk 1969 // skipping along ray, looking for sign change
61 : glk 1968 if (rayN > camVspFar) {
62 :     stabilize;
63 :     }
64 :     pos0 = camEye + rayN*rayVec;
65 :     pos1 = camEye + (rayN + rayStep)*rayVec;
66 :     pos = (pos0 + pos1)/2.0;
67 :     if (inside(pos0, FF) && inside(pos1, FF)) {
68 :     if (trace(∇⊗∇FF(pos0))*trace(∇⊗∇FF(pos1)) < 0.0
69 :     && |∇FF(pos)| > 10.0) {
70 :     // segment between pos0 and pos1 intersects isosurface;
71 :     // we're done skipping, initialize root finding
72 :     skipping = false;
73 :     }
74 :     }
75 :     if (skipping) {
76 :     rayN = rayN + rayStep;
77 :     }
78 :     } else {
79 :     // root finding starting at pos
80 :     if (steps > stepsMax) {
81 :     // failure, code green
82 :     rayRGBA = [0.0, 1.0, 0.0, 1.0];
83 :     stabilize;
84 :     }
85 :     if (!inside(pos, FF)) {
86 :     // failure, code red
87 :     rayRGBA = [1.0, 0.0, 0.0, 1.0];
88 :     stabilize;
89 :     }
90 :     vec3 grad = identity[3]:∇⊗∇⊗∇FF(pos);
91 :     if (|grad| == 0.0) {
92 :     // failure, code blue
93 :     rayRGBA = [0.0, 0.0, 1.0, 1.0];
94 :     stabilize;
95 :     }
96 :     real delta = -trace(∇⊗∇FF(pos))/(grad•rayDir);
97 :     if (|delta| < epsilon) { // we've converged; color the point
98 :     vec3 norm = normalize(grad);
99 :     real ld = max(0.0, norm • lightDir);
100 :     real hd = max(0.0, norm • normalize(lightDir - rayDir));
101 :     real gray = phongKa + phongKd*ld + phongKs*hd^phongSp;
102 :     rayRGBA = [gray, gray, gray, 1.0];
103 :     stabilize;
104 :     }
105 :     pos += delta*rayDir;
106 :     steps += 1;
107 :     }
108 :     }
109 :     }
110 :    
111 :     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