1 : |
glk |
959 |
// derivs3
|
2 : |
|
|
//
|
3 : |
|
|
// for debugging transforms of derivatives from index to world, in 3D.
|
4 : |
|
|
//
|
5 : |
|
|
// Can output image of errors in reconstructed values, or reconstructed
|
6 : |
glk |
961 |
// gradients, according to which of (1), (2), (3) is uncommented below.
|
7 : |
glk |
959 |
// In other case, output is processed with:
|
8 : |
|
|
//
|
9 : |
|
|
// unu reshape -i mip.txt -s 3 300 300 | unu quantize -b 8 -min 0 -max 1 -o derivs2.png
|
10 : |
|
|
//
|
11 : |
|
|
// This should produce an *ALL BLACK IMAGE* (modulo a few near-black
|
12 : |
|
|
// pixels due to numerical precision issues)
|
13 : |
|
|
|
14 : |
|
|
// F: full isotropic resolution
|
15 : |
|
|
image(3)[] Fimg = load ("../data/parab/parab3-150.nrrd");
|
16 : |
glk |
961 |
field#1(3)[] F0 = Fimg ⊛ ctmr;
|
17 : |
|
|
field#2(3)[] F = Fimg ⊛ bspln3;
|
18 : |
glk |
959 |
|
19 : |
|
|
// FX: one fifth as many samples along X
|
20 : |
|
|
image(3)[] FXimg = load ("../data/parab/parab3-x30.nrrd");
|
21 : |
glk |
961 |
field#1(3)[] F0X = FXimg ⊛ ctmr;
|
22 : |
|
|
field#2(3)[] FX = FXimg ⊛ bspln3;
|
23 : |
glk |
959 |
|
24 : |
|
|
// FY: one fifth as many samples along Y
|
25 : |
|
|
image(3)[] FYimg = load ("../data/parab/parab3-y30.nrrd");
|
26 : |
glk |
961 |
field#1(3)[] F0Y = FYimg ⊛ ctmr;
|
27 : |
|
|
field#2(3)[] FY = FYimg ⊛ bspln3;
|
28 : |
glk |
959 |
|
29 : |
|
|
// FZ: one fifth as many samples along Z
|
30 : |
|
|
image(3)[] FZimg = load ("../data/parab/parab3-z30.nrrd");
|
31 : |
glk |
961 |
field#1(3)[] F0Z = FZimg ⊛ ctmr;
|
32 : |
|
|
field#2(3)[] FZ = FZimg ⊛ bspln3;
|
33 : |
glk |
959 |
|
34 : |
|
|
int imgSize = 300;
|
35 : |
|
|
|
36 : |
|
|
strand sample (int xi, int yi) {
|
37 : |
|
|
real xx = lerp(-50.0, 50.0, 0.0, real(xi), real(imgSize-1));
|
38 : |
|
|
real yy = lerp(-50.0, 50.0, 0.0, real(yi), real(imgSize-1));
|
39 : |
|
|
real zz = 25.0;
|
40 : |
|
|
vec3 p = [xx,yy,zz];
|
41 : |
glk |
961 |
real f = xx^2 + yy^2 + zz^2; // analytic parabola function
|
42 : |
|
|
vec3 g = [2.0*xx,2.0*yy,2.0*zz]; // analytic gradient
|
43 : |
|
|
tensor[3,3] h = [[2.0,0.0,0.0], // analytic hessian
|
44 : |
|
|
[0.0,2.0,0.0],
|
45 : |
|
|
[0.0,0.0,2.0]];
|
46 : |
glk |
959 |
output vec3 val = [0.0,0.0,0.0];
|
47 : |
glk |
961 |
tensor[3,3] mh = zeros[3,3];
|
48 : |
glk |
959 |
update {
|
49 : |
|
|
|
50 : |
|
|
// Uncomment one of the following:
|
51 : |
|
|
|
52 : |
|
|
// (1) These are the errors in the values
|
53 : |
glk |
961 |
// This works fine; here as a sanity check
|
54 : |
|
|
// val = [|F0X(p)-f|, |F0Y(p)-f|, |F0Z(p)-f|];
|
55 : |
glk |
959 |
|
56 : |
|
|
// (2) These are magnitudes of the errors in the gradients
|
57 : |
glk |
976 |
//val = [|∇FX(p)-g|, |∇FY(p)-g|, |∇FZ(p)-g|];
|
58 : |
glk |
959 |
|
59 : |
glk |
961 |
// (3) Magnitudes of errors in Hessians
|
60 : |
glk |
976 |
val = [|∇(∇FX)(p)-h|, |∇(∇FY)(p)-h|, |∇(∇FZ)(p)-h|]/50.0;
|
61 : |
glk |
961 |
|
62 : |
glk |
959 |
stabilize;
|
63 : |
|
|
}
|
64 : |
|
|
}
|
65 : |
|
|
|
66 : |
|
|
initially [ sample(xi, yi) | yi in 0..(imgSize-1), xi in 0..(imgSize-1) ];
|