SCM Repository
Annotation of /branches/charisee_dev/examples/dti/dti-vr-byhand.diderot
Parent Directory
|
Revision Log
Revision 3276 - (view) (download)
1 : | cchiw | 3276 | |
2 : | input real isoval = 0.5; | ||
3 : | input real thick = 0.8; | ||
4 : | |||
5 : | |||
6 : | field#2(3)[3,3] V = bspln3 ⊛ image("/Users/chariseechiw/diderot/charisee_dev/ertest/data/tball.nrrd"); | ||
7 : | |||
8 : | |||
9 : | //field#2(3)[3,3] E = V - trace(V)*identity[3]/3; | ||
10 : | //field#2(3)[] F = sqrt(3.0/2.0)*|E|/|V| - isoval; | ||
11 : | |||
12 : | //tensor equivalent probes field | ||
13 : | //field#2(3)[] e1= |E|; | ||
14 : | //field#1(3)[3] dele1= ∇e1; | ||
15 : | //field#2(3)[] e2 = |V|; | ||
16 : | //field#2(3)[] dele2= ∇e2; | ||
17 : | //field#1(3)[3] G = ∇(e1/e2); | ||
18 : | //field#1(3)[3] G = (((∇e1)*e2)-((∇e2)*e1))/(e2*e2);//quotient rule | ||
19 : | |||
20 : | field#2(3)[3] hackRGB = bspln3 ⊛ image("/Users/chariseechiw/diderot/charisee_dev/data/const-curl3d.nrrd"); | ||
21 : | function vec3 color(vec3 x) = hackRGB(x); | ||
22 : | |||
23 : | |||
24 : | |||
25 : | vec3 cutVec = [-1,-0.03,0.02]; | ||
26 : | real cutPos = -1.5; | ||
27 : | |||
28 : | real refStep = 1; | ||
29 : | |||
30 : | // set camera, image, and rendering parameters | ||
31 : | input vec3 camEye = [440.499, 66.673, 175.265]; | ||
32 : | input vec3 camAt = [69.6939, 103.067, 41.4651]; | ||
33 : | input vec3 camUp = [-0.0808311, 0.0976636, 0.991932]; | ||
34 : | input real camNearAtRel = -90; | ||
35 : | input real camFarAtRel = 90; | ||
36 : | input real camFOV = 17; | ||
37 : | input int iresU = 520; | ||
38 : | input int iresV = 370; | ||
39 : | input real phongKa = 0.3; | ||
40 : | input real phongKd = 0.7; | ||
41 : | input real rayStep = 0.4; | ||
42 : | input vec3 lightVsp = [-2.0, -2.5, -8.0]; | ||
43 : | |||
44 : | // (boilerplate) computation of camera and light info | ||
45 : | real camDist = |camAt - camEye|; | ||
46 : | real camNear = camNearAtRel + camDist; | ||
47 : | real camFar = camFarAtRel + camDist; | ||
48 : | vec3 camN = normalize(camAt - camEye); // away from eye | ||
49 : | vec3 camU = normalize(camN × camUp); // right | ||
50 : | vec3 camV = camN × camU; // down | ||
51 : | real camVmax = tan(camFOV*π/360)*camDist; | ||
52 : | real camUmax = camVmax*iresU/iresV; | ||
53 : | vec3 light = transpose([camU,camV,camN])•normalize(lightVsp); | ||
54 : | |||
55 : | function real alpha(real v, real g) = 1.0 if (v > 0) else clamp(0, 1, 1.3*(1 - |v|/(g*thick))); | ||
56 : | |||
57 : | strand raycast(int ui, int vi) { | ||
58 : | real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5); | ||
59 : | real rayV = lerp(-camVmax, camVmax, -0.5, vi, iresV-0.5); | ||
60 : | real rayN = camNear; | ||
61 : | vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; | ||
62 : | real transp = 1; | ||
63 : | vec3 rgb = [0, 0, 0]; | ||
64 : | output vec4 rgba = [0, 0, 0, 0]; | ||
65 : | |||
66 : | update { | ||
67 : | vec3 x = camEye + rayN*rayVec; | ||
68 : | if (inside(x,V) && (x - camAt)•normalize(cutVec) > cutPos) { | ||
69 : | real val = 0; | ||
70 : | vec3 grad = [0,0,0]; | ||
71 : | |||
72 : | //e1=|E| | ||
73 : | tensor[3,3] e1inner=V(x)-trace(V(x))*identity[3]/3; | ||
74 : | real e1=sqrt(e1inner:e1inner); | ||
75 : | |||
76 : | //∇|E|; | ||
77 : | vec3 XXXX=(∇(trace(V)))(x);//<<< need to remove trace | ||
78 : | tensor [3,3,3] t4=∇⊗V(x)- (XXXX⊗identity[3]/3); //can't do tensor outproduct op | ||
79 : | vec3 t3 =2*(t4:(e1inner));//product rule | ||
80 : | vec3 dele1=(1/2)*t3/sqrt(e1inner:e1inner); | ||
81 : | |||
82 : | //val = F(x); | ||
83 : | val =sqrt(3.0/2.0)*e1/|V(x)|; | ||
84 : | |||
85 : | |||
86 : | real e2=|V(x)|; | ||
87 : | vec3 t0= (V(x):∇⊗V(x))+(V(x):∇⊗V(x)) ;//product rule | ||
88 : | vec3 dele2= (1/2)* t0/sqrt(V(x):V(x)) ; //chain rule | ||
89 : | |||
90 : | |||
91 : | //grad=∇F(x) | ||
92 : | vec3 G= ((dele1*e2)-(dele2*e1))/(e2*e2);//quotient rule | ||
93 : | grad = -(sqrt(3.0/2.0)*G); | ||
94 : | |||
95 : | real a = alpha(val, |grad|); | ||
96 : | if (a > 0) { | ||
97 : | a = 1 - pow(1-a, rayStep); | ||
98 : | real depth = lerp(1.1, 0.8, camNear, rayN, camFar); | ||
99 : | real shade = max(0, normalize(grad)•light); | ||
100 : | vec3 thisrgb = (phongKa + phongKd*shade)*color(x); | ||
101 : | if ((x - camAt)•normalize(cutVec) < cutPos + 1.1*rayStep) { | ||
102 : | thisrgb = phongKd*color(x); | ||
103 : | } | ||
104 : | rgb += transp*a*depth*thisrgb; | ||
105 : | transp *= 1 - a; | ||
106 : | } | ||
107 : | } | ||
108 : | if (transp < 0.01) { // early ray termination | ||
109 : | transp = 0; | ||
110 : | stabilize; | ||
111 : | } | ||
112 : | if (rayN > camFar) { | ||
113 : | stabilize; | ||
114 : | } | ||
115 : | rayN = rayN + rayStep; | ||
116 : | } | ||
117 : | stabilize { | ||
118 : | real a = 1-transp; | ||
119 : | if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a]; | ||
120 : | } | ||
121 : | } | ||
122 : | 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 |