@@ -63,26 +63,30 @@ itkBSplineKernelFunctionTest(int, char *[])
63
63
64
64
65
65
// Testing the output of BSplineKernelFunction
66
- #define TEST_BSPLINE_KERNEL (ORDERNUM ) \
67
- { \
68
- using FunctionType = itk::BSplineKernelFunction<ORDERNUM>; \
69
- auto function = FunctionType::New (); \
70
- \
71
- function->Print (std::cout); \
72
- for (unsigned int j = 0 ; j < npoints; ++j) \
73
- { \
74
- double results = function->Evaluate (x[j]); \
75
- /* compare with external results */ \
76
- if (itk::Math::abs (results - b##ORDERNUM[j]) > 1e-6 ) \
77
- { \
78
- std::cout << " Error with " << ORDERNUM << " order BSplineKernelFunction" << std::endl; \
79
- std::cout << " Expected: " << b##ORDERNUM[j] << " but got " << results; \
80
- std::cout << " at x = " << x[j] << std::endl; \
81
- std::cout << " Test failed" << std::endl; \
82
- return EXIT_FAILURE; \
83
- } \
84
- } \
85
- } \
66
+ #define TEST_BSPLINE_KERNEL (ORDERNUM ) \
67
+ { \
68
+ using FunctionType = itk::BSplineKernelFunction<ORDERNUM>; \
69
+ auto function = FunctionType::New (); \
70
+ \
71
+ function->Print (std::cout); \
72
+ const double epsilon = 1e-6 ; \
73
+ for (unsigned int j = 0 ; j < npoints; ++j) \
74
+ { \
75
+ double results = function->Evaluate (x[j]); \
76
+ /* compare with external results */ \
77
+ if (itk::Math::abs (results - b##ORDERNUM[j]) > epsilon) \
78
+ { \
79
+ std::cerr.precision (static_cast <int >(itk::Math::abs (std::log10 (epsilon)))); \
80
+ std::cerr << " Test failed!" << std::endl; \
81
+ std::cerr << " Error with " << ORDERNUM << " order BSplineKernelFunction " ; \
82
+ std::cerr << " at index [" << j << " ] " << std::endl; \
83
+ std::cerr << " Expected value " << b##ORDERNUM[j] << std::endl; \
84
+ std::cerr << " differs from " << results; \
85
+ std::cerr << " by more than " << epsilon << std::endl; \
86
+ return EXIT_FAILURE; \
87
+ } \
88
+ } \
89
+ } \
86
90
ITK_MACROEND_NOOP_STATEMENT
87
91
88
92
TEST_BSPLINE_KERNEL (0 );
@@ -101,12 +105,15 @@ itkBSplineKernelFunctionTest(int, char *[])
101
105
double expectedValue = 0.0 ;
102
106
double results = derivFunction->Evaluate (xx);
103
107
104
- if (itk::Math::abs (results - expectedValue) > 1e-6 )
108
+ const double epsilon = 1e-6 ;
109
+ if (itk::Math::abs (results - expectedValue) > epsilon)
105
110
{
106
- std::cout << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction" << std::endl;
107
- std::cout << " Expected: " << expectedValue << " but got " << results;
108
- std::cout << " at x = " << xx << std::endl;
109
- std::cout << " Test failed" << std::endl;
111
+ std::cerr.precision (static_cast <int >(itk::Math::abs (std::log10 (epsilon))));
112
+ std::cerr << " Test failed!" << std::endl;
113
+ std::cerr << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction at " << xx << std::endl;
114
+ std::cerr << " Expected value " << expectedValue << std::endl;
115
+ std::cerr << " differs from " << results;
116
+ std::cerr << " by more than " << epsilon << std::endl;
110
117
return EXIT_FAILURE;
111
118
}
112
119
}
@@ -125,12 +132,15 @@ itkBSplineKernelFunctionTest(int, char *[])
125
132
double expectedValue = function->Evaluate (xx + 0.5 ) - function->Evaluate (xx - 0.5 );
126
133
double results = derivFunction->Evaluate (xx);
127
134
128
- if (itk::Math::abs (results - expectedValue) > 1e-6 )
135
+ const double epsilon = 1e-6 ;
136
+ if (itk::Math::abs (results - expectedValue) > epsilon)
129
137
{
130
- std::cout << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction" << std::endl;
131
- std::cout << " Expected: " << expectedValue << " but got " << results;
132
- std::cout << " at x = " << xx << std::endl;
133
- std::cout << " Test failed" << std::endl;
138
+ std::cerr.precision (static_cast <int >(itk::Math::abs (std::log10 (epsilon))));
139
+ std::cerr << " Test failed!" << std::endl;
140
+ std::cerr << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction at " << xx << std::endl;
141
+ std::cerr << " Expected value " << expectedValue << std::endl;
142
+ std::cerr << " differs from " << results;
143
+ std::cerr << " by more than " << epsilon << std::endl;
134
144
return EXIT_FAILURE;
135
145
}
136
146
}
@@ -151,12 +161,15 @@ itkBSplineKernelFunctionTest(int, char *[])
151
161
double expectedValue = function->Evaluate (xx + 0.5 ) - function->Evaluate (xx - 0.5 );
152
162
double results = derivFunction->Evaluate (xx);
153
163
154
- if (itk::Math::abs (results - expectedValue) > 1e-6 )
164
+ const double epsilon = 1e-6 ;
165
+ if (itk::Math::abs (results - expectedValue) > epsilon)
155
166
{
156
- std::cout << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction" << std::endl;
157
- std::cout << " Expected: " << expectedValue << " but got " << results;
158
- std::cout << " at x = " << xx << std::endl;
159
- std::cout << " Test failed" << std::endl;
167
+ std::cerr.precision (static_cast <int >(itk::Math::abs (std::log10 (epsilon))));
168
+ std::cerr << " Test failed!" << std::endl;
169
+ std::cerr << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction at " << xx << std::endl;
170
+ std::cerr << " Expected value " << expectedValue << std::endl;
171
+ std::cerr << " differs from " << results;
172
+ std::cerr << " by more than " << epsilon << std::endl;
160
173
return EXIT_FAILURE;
161
174
}
162
175
}
@@ -177,12 +190,15 @@ itkBSplineKernelFunctionTest(int, char *[])
177
190
double expectedValue = function->Evaluate (xx + 0.5 ) - function->Evaluate (xx - 0.5 );
178
191
double results = derivFunction->Evaluate (xx);
179
192
180
- if (itk::Math::abs (results - expectedValue) > 1e-6 )
193
+ const double epsilon = 1e-6 ;
194
+ if (itk::Math::abs (results - expectedValue) > epsilon)
181
195
{
182
- std::cout << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction" << std::endl;
183
- std::cout << " Expected: " << expectedValue << " but got " << results;
184
- std::cout << " at x = " << xx << std::endl;
185
- std::cout << " Test failed" << std::endl;
196
+ std::cerr.precision (static_cast <int >(itk::Math::abs (std::log10 (epsilon))));
197
+ std::cerr << " Test failed!" << std::endl;
198
+ std::cerr << " Error with " << SplineOrder << " order BSplineDerivativeKernelFunction at " << xx << std::endl;
199
+ std::cerr << " Expected value " << expectedValue << std::endl;
200
+ std::cerr << " differs from " << results;
201
+ std::cerr << " by more than " << epsilon << std::endl;
186
202
return EXIT_FAILURE;
187
203
}
188
204
}
0 commit comments