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

SCM Repository

[diderot] Annotation of /tests/bc2d/vimg-bc.diderot
ViewVC logotype

Annotation of /tests/bc2d/vimg-bc.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4640 - (view) (download)

1 : glk 4640 input image(2)[] img ("2D image dataset to view") = image("test.nrrd");
2 :     input image(1)[3] cmimg ("colormap to use") = image("cmap.nrrd");
3 :     input vec2 cent ("center of viewing window") = [290,414];
4 :     input real fov ("height of viewing window") = 20000;
5 :     input int ss ("# of samples") = 500;
6 :     input real angle ("orientation (in counter-clockwise degrees) of viewing window") = 0;
7 :     input vec3 bkgd ("RGB color to show outside image domain") = [0.2,0.1,0.1];
8 :     input vec3 fcol ("RGB color to show inside features") = [0.0,1.0,0.0];
9 :     input real iso ("value at which to show approximate isocontour") = 0;
10 :     input real th ("apparent thickness of feature (meaning varies depending on which)") = 0.1;
11 :     input real cmin ("value to use at min end of colormap") = -1;
12 :     input real cmax ("value to use at max end of colormap") = 1;
13 :    
14 :     /*
15 :     The field to sample and view; needs to be more or less differentiable
16 :     depending on what we want to do with it.
17 :     C1 kernels include: c1tent, ctmr, bspln3, c4hexic
18 :     C2 kernels include: c2ctmr, bspln3, c4hexic
19 :     */
20 :     field#2(2)[] F = c4hexic ⊛ mirror(img);
21 :    
22 :     /*
23 :     The colormap can always use tent; it is not differentiated. Note the
24 :     clamp() here: it means that before evaluating cmap(x), x will be clamped to
25 :     inside the domain of cmap, as defined by the location of the samples in the
26 :     cmimg, and the support of the reconstruction filter tent. From a
27 :     functional sense, it might make more sense for the notation to use
28 :     composition: "tent⊛cming◦clamp": clamp first, then lookup into cmimg and
29 :     reconstruct with tent, but this looks a bit weird.
30 :     */
31 :     field#0(1)[3] cmap = tent ⊛ clamp(cmimg);
32 :    
33 :     // compute the image-to-world transform based on specification
34 :     // of the viewing window
35 :     real wdth = fov;
36 :     real phi = angle*π/180;
37 :     tensor[2,2] rot = [[cos(phi),sin(phi)],[-sin(phi),cos(phi)]];
38 :     vec2 spc = [wdth/(ss-1), fov/(ss-1)];
39 :     vec2 dir0 = rot•[spc[0], 0];
40 :     vec2 dir1 = rot•[0, spc[1]];
41 :     vec2 orig = cent - (dir0*(ss-1) + dir1*(ss-1))/2;
42 :    
43 :     // A function that is 1 at 0, and goes down linearly to 0 according to
44 :     // thickness parameter th. Note that if a function is a simple expression like
45 :     // this it can be defined with a single `=`, with no need for a `return`
46 :     // inside a sequence of statements. You might want to call this function
47 :     // "tent" but that name is already taken by a kernel.
48 :     function real bump(real z) = max(0, 1 - |z|/th);
49 :    
50 :     strand sample(int ui, int vi) {
51 :     // The output type for a Diderot program is fixed at compile-time,
52 :     // regardless of input variable values or execution outcomes. So
53 :     // this program sometimes saves what is really just grayscale
54 :     // information in an RGB color image.
55 :     output vec3 rgb = bkgd;
56 :     real ll = 0;
57 :     update {
58 :     vec2 x = orig + ui*dir0 + vi*dir1;
59 :     ll = bump(F(x) - iso);
60 :     rgb = cmap(lerp(0,1,cmin,F(x),cmax));
61 :     rgb = lerp(rgb, fcol, ll);
62 :     stabilize;
63 :     }
64 :     }
65 :    
66 :     initially [ sample(ui, vi) | vi in 0..(ss-1),
67 :     ui in 0..(ss-1) ];

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