1 // This is mul/vil3d/tests/test_tricub_interp.cxx
2 #include <iostream>
3 #include "testlib/testlib_test.h"
4 #ifdef _MSC_VER
5 # include "vcl_msvc_warnings.h"
6 #endif
7 #include <vil3d/vil3d_image_view.h>
8 #include <vil3d/vil3d_tricub_interp.h>
9 #include "vxl_config.h"
10
11
test_tricub_interp_float()12 static void test_tricub_interp_float()
13 {
14 std::cout << "*************************************\n"
15 << " Testing vil3d_tricub_interp <float>\n"
16 << "*************************************\n";
17
18 unsigned ni = 7;
19 unsigned nj = 7;
20 unsigned nk = 7;
21 vil3d_image_view<float> image0;
22 image0.set_size(ni,nj,nk);
23
24 for (unsigned y=0;y<image0.nj();++y)
25 for (unsigned x=0;x<image0.ni();++x)
26 for (unsigned z=0;z<image0.nk();++z)
27 image0(x,y,z) = x*0.1f+y+z*10;
28
29 std::ptrdiff_t istep = image0.istep();
30 std::ptrdiff_t jstep = image0.jstep();
31 std::ptrdiff_t kstep = image0.kstep();
32
33 {
34 double v1 = vil3d_tricub_interp_raw(3,3,3,image0.origin_ptr(),istep,jstep,kstep);
35 TEST_NEAR("vil3d_tricub_interp_raw at grid point",v1,33.3f,1e-5);
36
37 double v2 = vil3d_tricub_interp_raw(3.4,3,3,image0.origin_ptr(),istep,jstep,kstep);
38 TEST_NEAR("vil3d_tricub_interp_raw at off-grid point",v2,33.34f,1e-5);
39 double v3 = vil3d_tricub_interp_raw(3.4,3.5,3,image0.origin_ptr(),istep,jstep,kstep);
40 TEST_NEAR("vil3d_tricub_interp_raw at off-grid point",v3,33.84f,1e-5);
41 double v4 = vil3d_tricub_interp_raw(3.4,3.5,3.5,image0.origin_ptr(),istep,jstep,kstep);
42 TEST_NEAR("vil3d_tricub_interp_raw at off-grid point",v4,38.84f,1e-5);
43 }
44
45 {
46 double v1 = vil3d_tricub_interp_safe(3,3,3,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
47 TEST_NEAR("vil3d_tricub_interp_safe at grid point",v1,33.3f,1e-5);
48
49 double v2 = vil3d_tricub_interp_safe(3.4,3,3,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
50 TEST_NEAR("vil3d_tricub_interp_safe at off-grid point",v2,33.34f,1e-5);
51 double v3 = vil3d_tricub_interp_safe(3.4,3.5,3,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
52 TEST_NEAR("vil3d_tricub_interp_safe at off-grid point",v3,33.84f,1e-5);
53 double v4 = vil3d_tricub_interp_safe(3.4,3.5,3.5,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
54 TEST_NEAR("vil3d_tricub_interp_safe at off-grid point",v4,38.84f,1e-5);
55
56 double v_outside = vil3d_tricub_interp_safe(-1,-1,-1,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
57 TEST_NEAR("vil3d_tricub_interp_safe outside image",v_outside,0,1e-9);
58 double v_unsafe = vil3d_tricub_interp_safe(5,5,5,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
59 TEST_NEAR("vil3d_tricub_interp_safe at unsafe point",v_unsafe,0,1e-9);
60 }
61 }
62
63
test_tricub_interp_int()64 static void test_tricub_interp_int()
65 {
66 std::cout << "*******************************************\n"
67 << " Testing vil3d_tricub_interp <vxl_uint_32>\n"
68 << "*******************************************\n";
69
70 unsigned ni = 7;
71 unsigned nj = 7;
72 unsigned nk = 7;
73 vil3d_image_view<vxl_uint_32> image0;
74 image0.set_size(ni,nj,nk);
75
76 for (unsigned y=0;y<image0.nj();++y)
77 for (unsigned x=0;x<image0.ni();++x)
78 for (unsigned z=0;z<image0.nk();++z)
79 image0(x,y,z) = x + y*10 + z*100;
80
81 std::ptrdiff_t istep = image0.istep();
82 std::ptrdiff_t jstep = image0.jstep();
83 std::ptrdiff_t kstep = image0.kstep();
84
85 {
86 double v1 = vil3d_tricub_interp_raw(3,3,3,image0.origin_ptr(),istep,jstep,kstep);
87 TEST_NEAR("vil3d_tricub_interp_raw at grid point",v1,333.0f,1e-5);
88
89 double v2 = vil3d_tricub_interp_raw(3.4,3,3,image0.origin_ptr(),istep,jstep,kstep);
90 TEST_NEAR("vil3d_tricub_interp_raw at off-grid point",v2,333.4f,1e-5);
91
92 double v3 = vil3d_tricub_interp_raw(3.4,3.5,3,image0.origin_ptr(),istep,jstep,kstep);
93 TEST_NEAR("vil3d_tricub_interp_raw at off-grid point",v3,338.4f,1e-5);
94
95 double v4 = vil3d_tricub_interp_raw(3.4,3.5,3.5,image0.origin_ptr(),istep,jstep,kstep);
96 TEST_NEAR("vil3d_tricub_interp_raw at off-grid point",v4,388.4f,1e-5);
97 }
98
99 {
100 double v1 = vil3d_tricub_interp_safe(3,3,3,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
101 TEST_NEAR("vil3d_tricub_interp_safe at grid point",v1,333.0f,1e-5);
102
103 double v2 = vil3d_tricub_interp_safe(3.4,3,3,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
104 TEST_NEAR("vil3d_tricub_interp_safe at off-grid point",v2,333.4f,1e-5);
105
106 double v3 = vil3d_tricub_interp_safe(3.4,3.5,3,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
107 TEST_NEAR("vil3d_tricub_interp_safe at off-grid point",v3,338.4f,1e-5);
108
109 double v4 = vil3d_tricub_interp_safe(3.4,3.5,3.5,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
110 TEST_NEAR("vil3d_tricub_interp_safe at off-grid point",v4,388.4f,1e-5);
111
112 double v_outside = vil3d_tricub_interp_safe(-1,-1,-1,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
113 TEST_NEAR("vil3d_tricub_interp_safe outside image",v_outside,0,1e-9);
114
115 double v_unsafe = vil3d_tricub_interp_safe(5,5,5,image0.origin_ptr(),ni,nj,nk,istep,jstep,kstep);
116 TEST_NEAR("vil3d_tricub_interp_safe at unsafe point",v_unsafe,0,1e-9);
117 }
118 }
119
120
test_tricub_interp()121 static void test_tricub_interp()
122 {
123 test_tricub_interp_float();
124 test_tricub_interp_int();
125 }
126
127 TESTMAIN(test_tricub_interp);
128