1 /*
2 * Medical Image Registration ToolKit (MIRTK)
3 *
4 * Copyright 2013-2015 Imperial College London
5 * Copyright 2013-2015 Andreas Schuh
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #include "gtest/gtest.h"
21
22 #include "mirtk/GenericImage.h"
23 #include "mirtk/UnaryVoxelFunction.h"
24
25 using namespace mirtk;
26 using namespace mirtk::ForEachVoxelDomain;
27
28 // ===========================================================================
29 // Tests
30 // ===========================================================================
31
32 // ---------------------------------------------------------------------------
TEST(UnaryVoxelFunction,GetMin)33 TEST(UnaryVoxelFunction, GetMin)
34 {
35 GreyImage image;
36 // Empty image
37 {
38 UnaryVoxelFunction::GetMin min;
39 ForEachVoxel(image, min);
40 EXPECT_TRUE(IsNaN(min.GetMinAsDouble()));
41 }
42 // 2D image
43 image.Initialize(11, 7);
44 image.Put(2, 6, 7);
45 image.Put(5, 3, -42);
46 image.Put(2, 3, -41);
47 {
48 UnaryVoxelFunction::GetMin min;
49 ForEachVoxel(image, min);
50 EXPECT_EQ(-42.0, min.GetMinAsDouble());
51 }
52 {
53 UnaryVoxelFunction::GetMin min;
54 ParallelForEachVoxel(image, min);
55 EXPECT_EQ(-42.0, min.GetMinAsDouble());
56 }
57 {
58 UnaryVoxelFunction::GetMin min;
59 ForEachVoxelIf<Foreground>(image, min);
60 EXPECT_EQ(-42.0, min.GetMinAsDouble());
61 }
62 {
63 UnaryVoxelFunction::GetMin min;
64 ParallelForEachVoxelIf<Foreground>(image, min);
65 EXPECT_EQ(-42.0, min.GetMinAsDouble());
66 }
67 image.PutBackgroundValueAsDouble(.0);
68 {
69 UnaryVoxelFunction::GetMin min;
70 ForEachVoxelIf<Foreground>(image, min);
71 EXPECT_EQ(-42.0, min.GetMinAsDouble());
72 min.Reset();
73 ForEachVoxelIf<AboveBackgroundLevel>(image, min);
74 EXPECT_EQ(7.0, min.GetMinAsDouble());
75 }
76 {
77 UnaryVoxelFunction::GetMin min;
78 ParallelForEachVoxelIf<Foreground>(image, min);
79 EXPECT_EQ(-42.0, min.GetMinAsDouble());
80 min.Reset();
81 ParallelForEachVoxelIf<AboveBackgroundLevel>(image, min);
82 EXPECT_EQ(7.0, min.GetMinAsDouble());
83 }
84 image.ClearBackgroundValue();
85 // 3D image
86 /*
87 image.Initialize(11, 7, 5);
88 image.Put(2, 3, 0, 7);
89 image.Put(5, 3, 3, -42);
90 image.Put(2, 3, 2, -41);
91 // 4D image
92 image.Initialize(11, 7, 5, 3);
93 */
94 }
95
96 // ===========================================================================
97 // Main
98 // ===========================================================================
99
100 // ---------------------------------------------------------------------------
main(int argc,char * argv[])101 int main(int argc, char *argv[])
102 {
103 ::testing::InitGoogleTest(&argc, argv);
104 return RUN_ALL_TESTS();
105 }
106