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

SCM Repository

[diderot] Annotation of /tests/glk-tests/new/fsamp.diderot
ViewVC logotype

Annotation of /tests/glk-tests/new/fsamp.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4640 - (view) (download)

1 : glk 4640 #version 2
2 :    
3 :     input int sz0 = 30;
4 :     input int sz1 = 30;
5 :     input int sz2 = 30;
6 :     input real width = 4;
7 :     input int which = 1;
8 :     vec3 spc = [width/(sz0-1), width/(sz1-1), width/(sz2-1)];
9 :    
10 :     input vec3 pp = [0.2,0.2,0.2];
11 :     vec4 qq = normalize([pp[0],pp[1],pp[2],1.0]);
12 :     tensor[3,3] rot = [[qq[0]*qq[0] + qq[1]*qq[1] - qq[2]*qq[2] - qq[3]*qq[3],
13 :     2*(qq[1]*qq[2] - qq[0]*qq[3]),
14 :     2*(qq[1]*qq[3] + qq[0]*qq[2])],
15 :     [2*(qq[1]*qq[2] + qq[0]*qq[3]),
16 :     qq[0]*qq[0] - qq[1]*qq[1] + qq[2]*qq[2] - qq[3]*qq[3],
17 :     2*(qq[2]*qq[3] - qq[0]*qq[1])],
18 :     [2*(qq[1]*qq[3] - qq[0]*qq[2]),
19 :     2*(qq[2]*qq[3] + qq[0]*qq[1]),
20 :     qq[0]*qq[0] - qq[1]*qq[1] - qq[2]*qq[2] + qq[3]*qq[3]]];
21 :     vec3 xdir = rot•[spc[0], 0.0, 0.0];
22 :     vec3 ydir = rot•[0.0, spc[1], 0.0];
23 :     vec3 zdir = rot•[0.0, 0.0, spc[2]];
24 :     vec3 orig = -(xdir*(sz0-1) + ydir*(sz1-1) + zdir*(sz2-1))/2;
25 :    
26 :     function real func(vec3 pos) {
27 :     if (1 == which) {
28 :     return pos•pos/2;
29 :     } else if (2 == which) {
30 :     // a C1 union of a downward parabala (constant hessian)
31 :     // and a gaussian (hessian goes to zer0)
32 :     real sig = 0.7;
33 :     real aa = 0.1209853623/(sig^3);
34 :     real bb = 3*0.1209853623/sig;
35 :     real rr = |pos|;
36 :     real cap = -aa*rr*rr + bb;
37 :     real gss = exp(-rr*rr/(2*sig*sig))/(sqrt(2*π)*sig);
38 :     // the rr < sig conditional won't work, so use lerp instead
39 :     real ww = clamp(0, 1, lerp(0, 1, -1, 100*(rr-sig), 1));
40 :     real ret = (1-ww)*cap + ww*gss;
41 :     return ret;
42 :     } else if (3 == which) {
43 :     real x = pos[0];
44 :     real y = pos[1];
45 :     return atan2(y,x);
46 :     } else {
47 :     return 2*pos[0] + erf(10*(0.8-|pos|));
48 :     }
49 :     }
50 :    
51 :     strand sample(int xi, int yi, int zi) {
52 :     output real vv = 0;
53 :     update {
54 :     vec3 xyz = orig + xi*xdir + yi*ydir + zi*zdir;
55 :     vv = func(xyz);
56 :     stabilize;
57 :     }
58 :     }
59 :     start {
60 :     print("NRRD0004\n");
61 :     print("# Complete NRRD file format specification at:\n");
62 :     print("# http://teem.sourceforge.net/nrrd/format.html\n");
63 :     print("type: float\n");
64 :     print("dimension: 3\n");
65 :     print("sizes: ", sz0, " ", sz1, " ", sz2, "\n");
66 :     print("kinds: space space space\n");
67 :     print("endian: little\n");
68 :     print("encoding: raw\n");
69 :     print("space dimension: 3\n");
70 :     print("space directions: (", xdir[0], ",", xdir[1], ",", xdir[2],
71 :     ") (", ydir[0], ",", ydir[1], ",", ydir[2],
72 :     ") (", zdir[0], ",", zdir[1], ",", zdir[2], ")\n");
73 :     print("space origin: (", orig[0], ",", orig[1], ",", orig[2], ")\n");
74 :     print("data file: vv.nrrd\n");
75 :     print("byte skip: -1\n");
76 :     }
77 :     create_array { sample(xi, yi, zi) | zi in 0..(sz2-1), yi in 0..(sz1-1), xi in 0..(sz0-1) }

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