1 // This is mul/vimt3d/tests/test_resample.cxx
2 #include <iostream>
3 #include "testlib/testlib_test.h"
4 #ifdef _MSC_VER
5 # include "vcl_msvc_warnings.h"
6 #endif
7 #include <vimt3d/vimt3d_resample_trilinear.h>
8 #include <vimt3d/vimt3d_transform_3d.h>
9
10
11 //========================================================================
test_resample_trilinear_scale_2()12 static void test_resample_trilinear_scale_2()
13 {
14 std::cout << "*******************************************\n"
15 << " Testing vimt3d_resample_trilinear_scale_2\n"
16 << "*******************************************\n";
17
18 unsigned sni=3;
19 unsigned snj=3;
20 unsigned snk=3;
21 vimt3d_image_3d_of<int> src(sni, snj, snk);
22 for (unsigned i=0; i<sni; ++i)
23 for (unsigned j=0; j<snj; ++j)
24 for (unsigned k=0; k<snk; ++k)
25 src.image()(i,j,k) = 10000 + 10*k + 100*j + 1000*i;
26
27 vimt3d_image_3d_of<int> dst;
28 vimt3d_resample_trilinear_scale_2(src, dst);
29 unsigned dni = dst.image().ni();
30 unsigned dnj = dst.image().nj();
31 unsigned dnk = dst.image().nk();
32
33
34 // Testing
35 // src.print_all(std::cout);
36 // dst.print_all(std::cout);
37 ///
38
39 bool all_voxs_correct = true;
40 for (unsigned i=0; i<dni; ++i)
41 for (unsigned j=0; j<dnj; ++j)
42 for (unsigned k=0; k<dnk; ++k)
43 all_voxs_correct = all_voxs_correct &&
44 dst.image()(i,j,k)==int(10000 + 5*k + 50*j + 500*i);
45
46 TEST("Voxel values correct", all_voxs_correct, true);
47
48 const vimt3d_transform_3d& src_w2i = src.world2im();
49 const vimt3d_transform_3d& dst_w2i = dst.world2im();
50
51 vimt3d_transform_3d scaling;
52 scaling.set_zoom_only(2.0, 2.0, 2.0, 0.0, 0.0, 0.0);
53 TEST("Transforms correct", dst_w2i==(scaling*src_w2i), true);
54 }
55
56
57
58 //========================================================================
test_resample_trilin_smoothing_edge_extend()59 static void test_resample_trilin_smoothing_edge_extend()
60 {
61 std::cout << "******************************************************\n"
62 << " Testing vimt3d_resample_trilin_smoothing_edge_extend\n"
63 << "******************************************************\n";
64
65 unsigned sni=5;
66 unsigned snj=5;
67 unsigned snk=5;
68 vimt3d_image_3d_of<int> src(sni, snj, snk);
69 for (unsigned i=0; i<sni; ++i)
70 for (unsigned j=0; j<snj; ++j)
71 for (unsigned k=0; k<snk; ++k)
72 src.image()(i,j,k) = 10000 + 10*k + 100*j + 1000*i;
73
74 vimt3d_transform_3d w2i;
75 w2i.set_zoom_only(0.5, 0, 0, 1);
76 vimt3d_image_3d_of<int> dst(3, 3, 4, 1, w2i);
77 vimt3d_resample_trilin_smoothing_edge_extend(src, dst);
78 unsigned dni = dst.image().ni();
79 unsigned dnj = dst.image().nj();
80 unsigned dnk = dst.image().nk();
81
82
83 // Testing
84 // src.print_all(std::cout);
85 // dst.print_all(std::cout);
86 ///
87
88 bool all_voxs_correct = true;
89 for (unsigned i=0; i<dni; ++i)
90 for (unsigned j=0; j<dnj; ++j)
91 for (unsigned k=0; k<dnk; ++k)
92 all_voxs_correct = all_voxs_correct && (
93 (k==0 && dst.image()(i,j,k)==int(10000 + 0 + 200*j + 2000*i)) ||
94 (k>0 && dst.image()(i,j,k)==int(10000 + 20*(k-1) + 200*j + 2000*i)) );
95
96 TEST("Voxel values correct", all_voxs_correct, true);
97
98 TEST("Transforms correct", dst.world2im(), w2i);
99 }
100
101
102 //========================================================================
103 //========================================================================
test_resample()104 static void test_resample()
105 {
106 test_resample_trilinear_scale_2();
107 test_resample_trilin_smoothing_edge_extend();
108 }
109
110
111 //========================================================================
112 //========================================================================
113 TESTMAIN(test_resample);
114