|
16 | 16 | * |
17 | 17 | *=========================================================================*/ |
18 | 18 |
|
| 19 | +#include <cmath> |
19 | 20 | #include <iostream> |
20 | 21 |
|
21 | 22 | #include "itkScaleLogarithmicTransform.h" |
@@ -266,6 +267,53 @@ itkScaleLogarithmicTransformTest(int, char *[]) |
266 | 267 | } |
267 | 268 |
|
268 | 269 |
|
| 270 | + // Exercise the Jacobian about a non-zero center |
| 271 | + { |
| 272 | + auto centeredTransform = TransformType::New(); |
| 273 | + |
| 274 | + TransformType::InputPointType center; |
| 275 | + center[0] = 5; |
| 276 | + center[1] = 6; |
| 277 | + center[2] = 7; |
| 278 | + centeredTransform->SetCenter(center); |
| 279 | + |
| 280 | + TransformType::ParametersType parameters = centeredTransform->GetParameters(); |
| 281 | + parameters[0] = std::log(2.0); |
| 282 | + parameters[1] = std::log(3.0); |
| 283 | + parameters[2] = std::log(4.0); |
| 284 | + centeredTransform->SetParameters(parameters); |
| 285 | + |
| 286 | + constexpr TransformType::InputPointType::ValueType pInit[3]{ 10, 10, 10 }; |
| 287 | + const TransformType::InputPointType p = pInit; |
| 288 | + |
| 289 | + TransformType::JacobianType jacobian; |
| 290 | + centeredTransform->ComputeJacobianWithRespectToParameters(p, jacobian); |
| 291 | + |
| 292 | + const TransformType::ScaleType & scales = centeredTransform->GetScale(); |
| 293 | + |
| 294 | + testStatus = true; |
| 295 | + for (unsigned int i = 0; i < N; ++i) |
| 296 | + { |
| 297 | + // d/dLog(scale[i]) of scale[i] * (p[i] - center[i]) + center[i] |
| 298 | + const double expected = scales[i] * (p[i] - center[i]); |
| 299 | + if (itk::Math::Absolute(jacobian(i, i) - expected) > epsilon) |
| 300 | + { |
| 301 | + testStatus = false; |
| 302 | + break; |
| 303 | + } |
| 304 | + } |
| 305 | + if (!testStatus) |
| 306 | + { |
| 307 | + std::cerr << "Error in ComputeJacobianWithRespectToParameters()." << std::endl; |
| 308 | + std::cerr << "The center of the transformation was ignored." << std::endl; |
| 309 | + std::cerr << "Jacobian: " << jacobian << std::endl; |
| 310 | + return EXIT_FAILURE; |
| 311 | + } |
| 312 | + |
| 313 | + std::cout << "Successful ComputeJacobianWithRespectToParameters() " << std::endl; |
| 314 | + } |
| 315 | + |
| 316 | + |
269 | 317 | std::cout << "Test finished" << std::endl; |
270 | 318 | return EXIT_SUCCESS; |
271 | 319 | } |
0 commit comments