SCM Repository
View of /branches/charisee_dev/examples/dti/dti-vr-byhand.diderot
Parent Directory
|
Revision Log
Revision 3276 -
(download)
(annotate)
Tue Oct 13 02:42:05 2015 UTC (6 years, 7 months ago) by cchiw
File size: 3732 byte(s)
Tue Oct 13 02:42:05 2015 UTC (6 years, 7 months ago) by cchiw
File size: 3732 byte(s)
added byhand examples
input real isoval = 0.5; input real thick = 0.8; field#2(3)[3,3] V = bspln3 ⊛ image("/Users/chariseechiw/diderot/charisee_dev/ertest/data/tball.nrrd"); //field#2(3)[3,3] E = V - trace(V)*identity[3]/3; //field#2(3)[] F = sqrt(3.0/2.0)*|E|/|V| - isoval; //tensor equivalent probes field //field#2(3)[] e1= |E|; //field#1(3)[3] dele1= ∇e1; //field#2(3)[] e2 = |V|; //field#2(3)[] dele2= ∇e2; //field#1(3)[3] G = ∇(e1/e2); //field#1(3)[3] G = (((∇e1)*e2)-((∇e2)*e1))/(e2*e2);//quotient rule field#2(3)[3] hackRGB = bspln3 ⊛ image("/Users/chariseechiw/diderot/charisee_dev/data/const-curl3d.nrrd"); function vec3 color(vec3 x) = hackRGB(x); vec3 cutVec = [-1,-0.03,0.02]; real cutPos = -1.5; real refStep = 1; // set camera, image, and rendering parameters input vec3 camEye = [440.499, 66.673, 175.265]; input vec3 camAt = [69.6939, 103.067, 41.4651]; input vec3 camUp = [-0.0808311, 0.0976636, 0.991932]; input real camNearAtRel = -90; input real camFarAtRel = 90; input real camFOV = 17; input int iresU = 520; input int iresV = 370; input real phongKa = 0.3; input real phongKd = 0.7; input real rayStep = 0.4; input vec3 lightVsp = [-2.0, -2.5, -8.0]; // (boilerplate) computation of camera and light info real camDist = |camAt - camEye|; real camNear = camNearAtRel + camDist; real camFar = camFarAtRel + camDist; vec3 camN = normalize(camAt - camEye); // away from eye vec3 camU = normalize(camN × camUp); // right vec3 camV = camN × camU; // down real camVmax = tan(camFOV*π/360)*camDist; real camUmax = camVmax*iresU/iresV; vec3 light = transpose([camU,camV,camN])•normalize(lightVsp); function real alpha(real v, real g) = 1.0 if (v > 0) else clamp(0, 1, 1.3*(1 - |v|/(g*thick))); strand raycast(int ui, int vi) { real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5); real rayV = lerp(-camVmax, camVmax, -0.5, vi, iresV-0.5); real rayN = camNear; vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; real transp = 1; vec3 rgb = [0, 0, 0]; output vec4 rgba = [0, 0, 0, 0]; update { vec3 x = camEye + rayN*rayVec; if (inside(x,V) && (x - camAt)•normalize(cutVec) > cutPos) { real val = 0; vec3 grad = [0,0,0]; //e1=|E| tensor[3,3] e1inner=V(x)-trace(V(x))*identity[3]/3; real e1=sqrt(e1inner:e1inner); //∇|E|; vec3 XXXX=(∇(trace(V)))(x);//<<< need to remove trace tensor [3,3,3] t4=∇⊗V(x)- (XXXX⊗identity[3]/3); //can't do tensor outproduct op vec3 t3 =2*(t4:(e1inner));//product rule vec3 dele1=(1/2)*t3/sqrt(e1inner:e1inner); //val = F(x); val =sqrt(3.0/2.0)*e1/|V(x)|; real e2=|V(x)|; vec3 t0= (V(x):∇⊗V(x))+(V(x):∇⊗V(x)) ;//product rule vec3 dele2= (1/2)* t0/sqrt(V(x):V(x)) ; //chain rule //grad=∇F(x) vec3 G= ((dele1*e2)-(dele2*e1))/(e2*e2);//quotient rule grad = -(sqrt(3.0/2.0)*G); real a = alpha(val, |grad|); if (a > 0) { a = 1 - pow(1-a, rayStep); real depth = lerp(1.1, 0.8, camNear, rayN, camFar); real shade = max(0, normalize(grad)•light); vec3 thisrgb = (phongKa + phongKd*shade)*color(x); if ((x - camAt)•normalize(cutVec) < cutPos + 1.1*rayStep) { thisrgb = phongKd*color(x); } rgb += transp*a*depth*thisrgb; transp *= 1 - a; } } if (transp < 0.01) { // early ray termination transp = 0; stabilize; } if (rayN > camFar) { stabilize; } rayN = rayN + rayStep; } stabilize { real a = 1-transp; if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a]; } } 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 |