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_fsd1.diderot
ViewVC logotype

View of /branches/ein16/synth/d2/symb/symb_fsd1.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: 2951 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 real off ("translation offset from origin-centered grid") = 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, currently from 0 to 5") = 10;
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[1,1] rot = [[cos(theta)],[sin(theta))]];
// sample spacing on faster and (unsheared) slower axis
real spc = width/(sz0-1);

// changed hereto do 1 dimension
real edge0 =spc;// rot•spc;

// location of first sample
real orig = -(edge0*(sz0-1))/2 + off;

//-- field defined by coefficients --
//-- single--
input vec3 base = [2, 9, 7];    // _, x, x*x

input real scale = 1;

function real func(real x) {


    real a = base[0];
    real b = base[1];
    real c = base[2];

    real ret = 0;
    if (0 == which) {
        ret = a+b*x+c*x*x;
    }
    else if (1 == which) {
        ret = a+(b*x)+(c*x*x)+(5*x*x*x);
    }
    else {
        print("Sorry, no function defined for which = ", which, "\n");
    }
    return ret;

}

strand sample(int idx0) {
    output real out = 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) {
        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: 1\n");
        print("sizes: ", sz0, "\n");
        print("kinds: space \n");
        print("centers: cell\n");
        // NOTE: this assumes machine endianness
        print("endian: little\n");
        print("encoding: raw\n");
        print("space dimension: 1\n");
        // Diderot prints vectors like it parses them, e.g "[0.1,0.3]"
        // but this is not how orientation vectors are stored in the NRRD
        // header, hence the need to print individual components
        print("space directions: (", edge0, ")\n");
        print("space origin: (", orig, ")\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);
    stabilize;
    }
}

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

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