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

SCM Repository

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

View of /branches/ein16/synth/d2/symb/symb_fv2d2.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4236 - (download) (annotate)
Wed Jul 20 03:02:00 2016 UTC (3 years, 6 months ago) by cchiw
File size: 4353 byte(s)
added generic cases for trace|det and added test cases
input int sz0 ("# samples on faster axis") = 101;
input int sz1 ("# samples on slower axis") = 100;
input real width ("approx width of world-space region sampled") = 1;
input vec2 off ("translation offset from origin-centered grid") = [0,0];
input real shear ("amount of shear in sampling grid") = 0;
input real angle ("orientation (in degrees) of faster axis") = 0;
input int which ("which function to sample") = 9;
input vec4 parm ("parameters that functions may use") = [0,0,0,0];

real theta = angle*π/180;
// rotation by theta of [1,0] towards [0,1]
tensor[2,2] rot = [[cos(theta),-sin(theta)],[sin(theta),cos(theta)]];
// sample spacing on faster and (unsheared) slower axis
vec2 spc = [width/(sz0-1), width/(sz1-1)];
// inter-sample vector on faster axis
vec2 edge0 = rot•[spc[0], 0];
// inter-sample vector on slower axis
vec2 edge1 = rot•[0, spc[1]] + shear*edge0;
// location of first sample
vec2 orig = -(edge0*(sz0-1) + edge1*(sz1-1))/2 + off;

//-- field defined by coefficients --
//-- single--
input vec2 base1 = [0, 0];    // b*x, c*y
input vec2 xsq1 = [0, 0];     // d*x^2, g*y*x^2
input vec2 ysq1 = [0, 0];     // f*y^2, h*x*y^2
input vec3 diag1 = [0, 0, 0];    // a, e*x*y,  i*y^2*x^2


//-- single--
input vec2 base2 = [0, 0];    // b*x, c*y
input vec2 xsq2 = [0, 0];     // d*x^2, g*y*x^2
input vec2 ysq2 = [0, 0];     // f*y^2, h*x*y^2
input vec3 diag2 = [0, 0, 0];    // a, e*x*y,  i*y^2*x^2


input real scale = 1;


function real definef(vec2 pos, vec2 base, vec2 xsq, vec2 ysq, vec3 diag) {
    real x = pos[0];
    real y = pos[1];
    real b = base[0];
    real c = base[1];
    real d = xsq[0];
    real g = xsq[1];
    real f = ysq[0];
    real h = ysq[1];
    real a = diag[0];
    real e = diag[1];
    real i = diag[2];
    real ret = 0;
    // as intended to be represented
    //-- single--
    real t0 = b*x + c*y;
    //--squared--
    real t1 = d*x^2 + g*y*x^2;
    real t2 = f*y^2 + h*x*y^2;
    real t3 = a + e*x*y + i*(y^2)*(x^2);
    ret = scale*(t0+t1+t2+t3);
    return ret;
    }

function vec2 func(vec2 pos) {
    real x = pos[0];
    real y = pos[1];
    real z = pos[2];
    vec2 ret = [0, 0];
    if (0 == which){
        real val1 = definef(pos, base1, xsq1, ysq1, diag1);
        real val2 = definef(pos, base2, xsq2, ysq2, diag2);
        ret =[val1, val2];
    } else if (1 == which) {        // 0: [x,y] ramp
        ret = [x,y];
    } else if (2 == which) { // 1:
        ret = [x*x,y*y];
    } else if (3 == which) { // 2:
        ret = [x,y*y];
    } else {
        print("Sorry, -no function defined for which = ", which, "\n");
    }
    return ret;
}

strand sample(int idx0, int idx1) {
    output vec2 out = [0.0,0.0];
    update {
        /* Diderot doesn't (currently) allow print statements from
        global initialization, so to print something once per
        program, you need to test for a condition that will be true
        for one strand.  By the immediate stabilize, this will only
        run for one iteration. */
        if (0 == idx0 && 0 == idx1) {
            print("NRRD0004\n");
            print("# Complete NRRD file format specification at:\n");
            print("# http://teem.sourceforge.net/nrrd/format.html\n");
            // NOTE: this assumes we haven't been compiled with --double
            print("type: float\n");
            print("dimension: 3\n");
            print("sizes: 2 ", sz0, " ", sz1, "\n");
            print("kinds: 2-vector space space\n");

            //         print("centers: cell cell\n");

            print("endian: little\n");         // NOTE: this assumes machine endianness
            print("encoding: raw\n");
            print("space dimension: 2\n");
            print("space directions: none (", edge0[0], ",", edge0[1],
            ") (", edge1[0], ",", edge1[1], ")\n");
            print("space origin: (", orig[0], ",", orig[1], ")\n");
            // NOTE: this assumes output filename is not explicitly set
            print("data file: out.nrrd\n");
            print("byte skip: -1\n");
        }
        out = func(orig + idx0*edge0 + idx1*edge1);
        stabilize;
    }
}

/*
** Create one strand per sample point. The "initially [ ]" creates a grid
** of strands (as opposed to a collection).
*/
initially [ sample(idx0, idx1)
| idx1 in 0..(sz1-1),   // SLOWER axis
idx0 in 0..(sz0-1) ]; // FASTER axis

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