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

SCM Repository

[diderot] Annotation of /branches/charisee_dev/examples/dti/dti-vr-byhand.diderot
ViewVC logotype

Annotation of /branches/charisee_dev/examples/dti/dti-vr-byhand.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3307 - (view) (download)

1 : cchiw 3276 input real isoval = 0.5;
2 :     input real thick = 0.8;
3 : cchiw 3303 field#2(3)[3,3] V = bspln3 ⊛ image("../ertest/data/tball.nrrd");
4 : cchiw 3283 field#0(3)[3,3,3] G=∇⊗V;
5 : cchiw 3303 field#2(3)[3] hackRGB = bspln3 ⊛ image("../data/const-curl3d.nrrd");
6 : cchiw 3276 function vec3 color(vec3 x) = hackRGB(x);
7 :     vec3 cutVec = [-1,-0.03,0.02];
8 :     real cutPos = -1.5;
9 :     real refStep = 1;
10 :     input vec3 camEye = [440.499, 66.673, 175.265];
11 :     input vec3 camAt = [69.6939, 103.067, 41.4651];
12 :     input vec3 camUp = [-0.0808311, 0.0976636, 0.991932];
13 :     input real camNearAtRel = -90;
14 :     input real camFarAtRel = 90;
15 :     input real camFOV = 17;
16 :     input int iresU = 520;
17 :     input int iresV = 370;
18 :     input real phongKa = 0.3;
19 :     input real phongKd = 0.7;
20 :     input real rayStep = 0.4;
21 :     input vec3 lightVsp = [-2.0, -2.5, -8.0];
22 :     real camDist = |camAt - camEye|;
23 :     real camNear = camNearAtRel + camDist;
24 :     real camFar = camFarAtRel + camDist;
25 :     vec3 camN = normalize(camAt - camEye); // away from eye
26 :     vec3 camU = normalize(camN × camUp); // right
27 :     vec3 camV = camN × camU; // down
28 :     real camVmax = tan(camFOV*π/360)*camDist;
29 :     real camUmax = camVmax*iresU/iresV;
30 :     vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);
31 :    
32 :     function real alpha(real v, real g) = 1.0 if (v > 0) else clamp(0, 1, 1.3*(1 - |v|/(g*thick)));
33 :    
34 :     strand raycast(int ui, int vi) {
35 :     real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5);
36 :     real rayV = lerp(-camVmax, camVmax, -0.5, vi, iresV-0.5);
37 :     real rayN = camNear;
38 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
39 :     real transp = 1;
40 :     vec3 rgb = [0, 0, 0];
41 :     output vec4 rgba = [0, 0, 0, 0];
42 :    
43 :     update {
44 :     vec3 x = camEye + rayN*rayVec;
45 :     if (inside(x,V) && (x - camAt)•normalize(cutVec) > cutPos) {
46 :     real val = 0;
47 :     vec3 grad = [0,0,0];
48 : cchiw 3283
49 :    
50 :     real m=|V(x)|;
51 :     tensor[3,3,3] g=G(x);
52 :     tensor[3] t1=(1/2)*(V(x):g+g:V(x))/m;
53 : cchiw 3276
54 : cchiw 3283 vec3 t2=[g[0,0,0]+g[0,1,1]+g[0,2,2],g[1,0,0]+g[1,1,1]+g[1,2,2],g[2,0,0]+g[2,1,1]+g[2,2,2]];
55 :     tensor [3,3] E = V(x) - trace(V(x))*identity[3]/3;
56 : cchiw 3307 tensor[3,3,3] t3= g-t2⊗identity[3]/3;
57 : cchiw 3283 real t4=|E|;
58 : cchiw 3307 tensor [3] t5=(1/2)*(t3:E +E:t3)/(E:E);
59 :     val=sqrt(3.0/2.0)*t4/m - isoval;
60 : cchiw 3283 real t8=sqrt(3.0/2.0);
61 :     vec3 t6 =(m*t5);
62 :     vec3 t7 = (t4*t1);
63 :     grad =t8*(t6- t7)/(m*m);
64 : cchiw 3276
65 :     real a = alpha(val, |grad|);
66 :     if (a > 0) {
67 :     a = 1 - pow(1-a, rayStep);
68 :     real depth = lerp(1.1, 0.8, camNear, rayN, camFar);
69 :     real shade = max(0, normalize(grad)•light);
70 :     vec3 thisrgb = (phongKa + phongKd*shade)*color(x);
71 :     if ((x - camAt)•normalize(cutVec) < cutPos + 1.1*rayStep) {
72 :     thisrgb = phongKd*color(x);
73 :     }
74 :     rgb += transp*a*depth*thisrgb;
75 :     transp *= 1 - a;
76 :     }
77 :     }
78 :     if (transp < 0.01) { // early ray termination
79 :     transp = 0;
80 :     stabilize;
81 :     }
82 :     if (rayN > camFar) {
83 :     stabilize;
84 :     }
85 :     rayN = rayN + rayStep;
86 :     }
87 :     stabilize {
88 :     real a = 1-transp;
89 :     if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a];
90 :     }
91 :     }
92 :     initially [ raycast(ui, vi) | vi in 0..iresV-1, ui in 0..iresU-1 ];

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0