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

SCM Repository

[diderot] Annotation of /branches/vis12/test/lzc2d-lifted.diderot
ViewVC logotype

Annotation of /branches/vis12/test/lzc2d-lifted.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1965 - (view) (download)

1 : glk 1965 /* lzc2d-lifted
2 :    
3 :     If we could lift tensor operations to fields ...
4 :    
5 :     */
6 :    
7 :    
8 :     int gridSize = 500;
9 :     field#4(2)[] img = bspln5 ⊛ image("../data/ddro-128.nrrd");
10 :    
11 :     /*
12 :     BUG? get:
13 :     uncaught exception Fail [Fail: bogus field binding]
14 :     raised at common/phase-timer.sml:76.50-76.52
15 :     raised at common/phase-timer.sml:76.50-76.52
16 :     raised at high-to-mid/high-to-mid.sml:141.19-141.45
17 :     */
18 :     field#1(2)[] F = 2.0*img;
19 :    
20 :    
21 :     /*
22 :     BUG? get:
23 :     [lzc2d-lifted.diderot:31.1-32.0] Error: unable to resolve overloaded operator "-"
24 :     argument type is: (field#4(2)[] * real)
25 :    
26 :     uncaught exception Fail [Fail: Error in compiling lzc2d-lifted.diderot]
27 :     raised at common/phase-timer.sml:76.50-76.52
28 :     raised at common/phase-timer.sml:76.50-76.52
29 :     raised at driver/main.sml:27.39-27.76
30 :     */
31 :     //field#1(2)[] F = img - 30.0;
32 :    
33 :     /* dreaming being able to define a field with more non-trivial
34 :     operations on another */
35 :     //field#1(2)[] F = identity[2]:∇⊗∇img; // same as trace(∇⊗∇img)
36 :    
37 :    
38 :     int stepsMax = 30;
39 :     real epsilon = 0.00001;
40 :    
41 :     strand sample (int ui, int vi) {
42 :     output vec2 pos = [lerp(0.0, 1.0, -0.5, real(ui), real(gridSize)-0.5),
43 :     lerp(0.0, 1.0, -0.5, real(vi), real(gridSize)-0.5)];
44 :     int steps = 0;
45 :     update {
46 :     // We bail if we're no longer inside or taken too many steps.
47 :     if (!inside(pos, F) || steps > stepsMax) {
48 :     die;
49 :     }
50 :     vec2 grad = ∇F(pos);
51 :     if (|grad| == 0.0) {
52 :     die;
53 :     }
54 :     vec2 norm = normalize(grad);
55 :     vec2 delta = -(F(pos)/|grad|)*norm; // Newton-Raphson step
56 :     if (|delta| < epsilon) { // we've converged if step is small enough
57 :     stabilize;
58 :     }
59 :     pos += delta;
60 :     steps += 1;
61 :     }
62 :     }
63 :    
64 :     initially { sample(ui, vi) | vi in 0..(gridSize-1), ui in 0..(gridSize-1) };

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