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

SCM Repository

[diderot] Annotation of /branches/ein16/synth/d2/symb_fv2d2.diderot
ViewVC logotype

Annotation of /branches/ein16/synth/d2/symb_fv2d2.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3874 - (view) (download)

1 : cchiw 3865 input int sz0 ("# samples on faster axis") = 101;
2 :     input int sz1 ("# samples on slower axis") = 100;
3 :     input real width ("approx width of world-space region sampled") = 1;
4 :     input vec2 off ("translation offset from origin-centered grid") = [0,0];
5 :     input real shear ("amount of shear in sampling grid") = 0;
6 :     input real angle ("orientation (in degrees) of faster axis") = 0;
7 :     input int which ("which function to sample") = 9;
8 :     input vec4 parm ("parameters that functions may use") = [0,0,0,0];
9 :    
10 :     real theta = angle*π/180;
11 :     // rotation by theta of [1,0] towards [0,1]
12 :     tensor[2,2] rot = [[cos(theta),-sin(theta)],[sin(theta),cos(theta)]];
13 :     // sample spacing on faster and (unsheared) slower axis
14 :     vec2 spc = [width/(sz0-1), width/(sz1-1)];
15 :     // inter-sample vector on faster axis
16 :     vec2 edge0 = rot•[spc[0], 0];
17 :     // inter-sample vector on slower axis
18 :     vec2 edge1 = rot•[0, spc[1]] + shear*edge0;
19 :     // location of first sample
20 :     vec2 orig = -(edge0*(sz0-1) + edge1*(sz1-1))/2 + off;
21 :    
22 :     //-- field defined by coefficients --
23 :     //-- single--
24 :     input vec2 base = [0, 0]; // b*x, c*y
25 :     //--squared--
26 :     input vec2 xsq = [0, 0]; // d*x^2, g*y*x^2
27 :     input vec2 ysq = [0, 0]; // f*y^2, h*x*y^2
28 :     //--diagonal--
29 :     input vec3 diag = [0, 0, 0]; // a, e*x*y, i*y^2*x^2
30 :    
31 :     input real scale = 1;
32 :    
33 :    
34 :     function real definef(vec2 pos) {
35 :     real x = pos[0];
36 :     real y = pos[1];
37 :     real z = pos[2];
38 :     real b = base[0];
39 :     real c = base[1];
40 :     real d = xsq[0];
41 :     real g = xsq[1];
42 :     real f = ysq[0];
43 :     real h = ysq[1];
44 :     real a = diag[0];
45 :     real e = diag[1];
46 :     real i = diag[2];
47 :    
48 :     real ret = 0;
49 :     // as intended to be represented
50 :     //-- single--
51 :     real t0 = b*x + c*y;
52 :     //--squared--
53 :     real t1 = d*x^2 + g*y*x^2;
54 :     real t2 = f*y^2 + h*x*y^2;
55 :     real t3 = a + e*x*y + i*(y^2)*(x^2);
56 :     ret = scale*(t0+t1+t2+t3);
57 :     return ret;
58 :     }
59 :    
60 :     function vec2 func(vec2 pos) {
61 :     real x = pos[0];
62 :     real y = pos[1];
63 :     real z = pos[2];
64 :     real b = base[0];
65 :     real c = base[1];
66 :     real d = xsq[0];
67 :     real g = xsq[1];
68 :     real f = ysq[0];
69 :     real h = ysq[1];
70 :     real a = diag[0];
71 :     real e = diag[1];
72 :     real i = diag[2];
73 :     vec2 ret = [0, 0];
74 :     if (0 == which) { // 0: [x,y] ramp
75 :     ret = [x,y];
76 :     } else if (1 == which) { // 1:
77 :     ret = [x*x,y*y];
78 :     } else if (2 == which) { // 2:
79 :     ret = [x,y*y];
80 :     } else if (3 == which) {
81 :     // takes gradient of f
82 :     //-- x-axis--
83 :     real x0 = b;
84 :     real x1 = d*2*x + g*y*2*x;
85 :     real x2 = h*y^2;
86 :     real x3 = e*y + i*(y^2)*(2*x);
87 :     real xaxis = (x0+x1+x2+x3);
88 :     //-- y-axis--
89 :     real y0 = c;
90 :     real y1 = g*x^2;
91 :     real y2 = f*2*y + h*x*2*y;
92 :     real y3 = e*x + i*(2*y)*(x^2);
93 :     real yaxis = (y0+y1+y2+y3);
94 :     ret = [xaxis, yaxis];
95 :     } else if (4 == which){
96 :     real val = definef(pos);
97 : cchiw 3874 ret =[val,2*val];
98 : cchiw 3865 }
99 :     else {
100 :     print("Sorry, -no function defined for which = ", which, "\n");
101 :     }
102 :     return ret;
103 :     }
104 :    
105 :     strand sample(int idx0, int idx1) {
106 :     output vec2 out = [0.0,0.0];
107 :     update {
108 :     /* Diderot doesn't (currently) allow print statements from
109 :     global initialization, so to print something once per
110 :     program, you need to test for a condition that will be true
111 :     for one strand. By the immediate stabilize, this will only
112 :     run for one iteration. */
113 :     if (0 == idx0 && 0 == idx1) {
114 :     print("NRRD0004\n");
115 :     print("# Complete NRRD file format specification at:\n");
116 :     print("# http://teem.sourceforge.net/nrrd/format.html\n");
117 :     // NOTE: this assumes we haven't been compiled with --double
118 :     print("type: float\n");
119 :     print("dimension: 3\n");
120 :     print("sizes: 2 ", sz0, " ", sz1, "\n");
121 :     print("kinds: 2-vector space space\n");
122 :    
123 :     // print("centers: cell cell\n");
124 :    
125 :     print("endian: little\n"); // NOTE: this assumes machine endianness
126 :     print("encoding: raw\n");
127 :     print("space dimension: 2\n");
128 :     print("space directions: none (", edge0[0], ",", edge0[1],
129 :     ") (", edge1[0], ",", edge1[1], ")\n");
130 :     print("space origin: (", orig[0], ",", orig[1], ")\n");
131 :     // NOTE: this assumes output filename is not explicitly set
132 :     print("data file: out.nrrd\n");
133 :     print("byte skip: -1\n");
134 :     }
135 :     out = func(orig + idx0*edge0 + idx1*edge1);
136 :     stabilize;
137 :     }
138 :     }
139 :    
140 :     /*
141 :     ** Create one strand per sample point. The "initially [ ]" creates a grid
142 :     ** of strands (as opposed to a collection).
143 :     */
144 :     initially [ sample(idx0, idx1)
145 :     | idx1 in 0..(sz1-1), // SLOWER axis
146 :     idx0 in 0..(sz0-1) ]; // FASTER axis

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