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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1967 - (view) (download)

1 : glk 1967
2 :     /*
3 :    
4 :     ../bin/diderotc --exec isosurf.diderot \
5 :     && ./isosurf \
6 :     && overrgb -i rayRGBA.nrrd -b 0.1 0.15 0.2 -o isosurf.png
7 :    
8 :     */
9 :    
10 :     field#3(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 = 2;
22 :     int stepsMax = 20;
23 :     real epsilon = 0.001;
24 :     real isoVal = 30.0; // use 80 to see lots of code red failures
25 :     vec3 lightVspDir = [0.9, -2.5, -2.2];
26 :     real phongKa = 0.05;
27 :     real phongKd = 0.6;
28 :     real phongKs = 0.4;
29 :     real phongSp = 60.0;
30 :    
31 :     // boilerplate computation of camera and light info
32 :     real camDist = |camAt - camEye|;
33 :     real camVspNear = camNear + camDist;
34 :     real camVspFar = camFar + camDist;
35 :     vec3 camN = normalize(camAt - camEye);
36 :     vec3 camU = normalize(camN × camUp);
37 :     vec3 camV = camN × camU;
38 :     real camVmax = tan(camFOV*π/360.0)*camDist;
39 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
40 :     vec3 lightDir = normalize(lightVspDir[0]*camU +
41 :     lightVspDir[1]*camV +
42 :     lightVspDir[2]*camN);
43 :    
44 :     // RayCast(ui,vi) computes rendered color for pixel (ui,vi)
45 :     strand RayCast (int ui, int vi) {
46 :     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 :     vec3 rayDir = normalize(rayVec);
50 :     bool skipping = true;
51 :     real rayN = camVspNear;
52 :     output vec4 rayRGBA = [0.0, 0.0, 0.0, 0.0];
53 :     int steps = 0;
54 :    
55 :     vec3 pos0 = [0.0,0.0,0.0]; // HEY unwanted initialization
56 :     vec3 pos1 = [0.0,0.0,0.0]; // HEY unwanted initialization
57 :     vec3 pos = [0.0,0.0,0.0]; // HEY unwanted initialization
58 :    
59 :     update {
60 :     if (skipping) {
61 :     // skipping along ray, looking for sign change in FF - isoVal
62 :     if (rayN > camVspFar) {
63 :     stabilize;
64 :     }
65 :     pos0 = camEye + rayN*rayVec;
66 :     pos1 = camEye + (rayN + rayStep)*rayVec;
67 :     if (inside(pos0, FF) && inside(pos1, FF)) {
68 :     if ((FF(pos0) - isoVal)*(FF(pos1) - isoVal) < 0.0) {
69 :     // segment between pos0 and pos1 intersects isosurface;
70 :     // we're done skipping, initialize root finding
71 :     skipping = false;
72 :     pos = (pos0 + pos1)/2.0;
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 = ∇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 = -(FF(pos) - isoVal)/(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