Skip to content

Commit c96f026

Browse files
committed
BUG: Fix ElastixRegistrationMethod GetNumberOfTransforms GetNthTransform
ElastixRegistrationMethod member functions `GetNumberOfTransforms`, `GetNthTransform`, and `GetCombinationTransform` did always just return zero or null, erroneously, when the pixel type of the input images (specified by `TFixedImage` and `TMovingImage`) would be different from the internal pixel type (specified by "FixedInternalImagePixelType" and "MovingInternalImagePixelType", `float` by default). The code incorrectly assumed that the objects stored in the ElastixBase `TransformContainer` are always of type `elx::TransformBase<ElastixTemplate<TFixedImage, TMovingImage>>`. This commit just assumes that the objects stored in `TransformContainer` are of type `AdvancedCombinationTransform<double, FixedImageDimension>`. The commit aims to fix issue #965 "ElastixRegistrationMethod GetNumberOfTransforms, GetCombinationTransform, etc. does not work with non-float ImageType", reported by Matt McCormick. Extended the GoogleTest `itkElastixRegistrationMethod.CheckMinimumMovingImageUsingAnyInternalPixelType` unit test to check this issue.
1 parent 03bf078 commit c96f026

3 files changed

Lines changed: 32 additions & 36 deletions

File tree

Core/Main/GTesting/itkElastixRegistrationMethodGTest.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,9 @@ GTEST_TEST(itkElastixRegistrationMethod, CheckMinimumMovingImageUsingAnyInternal
23062306
registration.Update();
23072307

23082308
EXPECT_EQ(DerefRawPointer(registration.GetOutput()), DerefSmartPointer(movingImage));
2309+
EXPECT_EQ(registration.GetNumberOfTransforms(), 1);
2310+
EXPECT_NE(registration.GetNthTransform(0), nullptr);
2311+
EXPECT_NE(registration.GetCombinationTransform(), nullptr);
23092312
});
23102313
};
23112314

Core/Main/itkElastixRegistrationMethod.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
#define itkElastixRegistrationMethod_h
3737

3838
#include "itkImageSource.h"
39+
#include "itkAdvancedCombinationTransform.h"
3940
#include "itkElastixLogLevel.h"
4041

4142
#include "elxElastixMain.h"
4243
#include "elxElastixTemplate.h"
44+
#include "elxElastixBase.h"
4345
#include "elxTransformBase.h"
4446
#include "elxParameterObject.h"
4547

@@ -373,7 +375,11 @@ class ITK_TEMPLATE_EXPORT ElastixRegistrationMethod : public itk::ImageSource<TF
373375
/** Private using-declaration, just to avoid GCC compilation warnings: '...' was hidden [-Woverloaded-virtual] */
374376
using Superclass::SetInput;
375377

376-
using ElastixTransformBaseType = elx::TransformBase<elx::ElastixTemplate<TFixedImage, TMovingImage>>;
378+
using AdvancedCombinationTransformType =
379+
AdvancedCombinationTransform<elx::ElastixBase::CoordRepType, FixedImageDimension>;
380+
381+
AdvancedCombinationTransformType *
382+
GetAdvancedCombinationTransform() const;
377383

378384
SmartPointer<const elx::ElastixMain> m_ElastixMain{};
379385

Core/Main/itkElastixRegistrationMethod.hxx

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -979,60 +979,47 @@ template <typename TFixedImage, typename TMovingImage>
979979
unsigned int
980980
ElastixRegistrationMethod<TFixedImage, TMovingImage>::GetNumberOfTransforms() const
981981
{
982-
const auto * const transformContainer = m_ElastixMain->GetElastixBase().GetTransformContainer();
983-
984-
if ((transformContainer == nullptr) || transformContainer->empty())
985-
{
986-
return 0;
987-
}
988-
989-
const auto * const elxTransformBase =
990-
dynamic_cast<ElastixTransformBaseType *>(transformContainer->front().GetPointer());
991-
992-
return (elxTransformBase == nullptr) ? 0 : elxTransformBase->GetAsITKBaseType()->GetNumberOfTransforms();
982+
const auto advancedCombinationTransform = GetAdvancedCombinationTransform();
983+
return advancedCombinationTransform ? advancedCombinationTransform->GetNumberOfTransforms() : 0;
993984
}
994985

995986

996987
template <typename TFixedImage, typename TMovingImage>
997988
auto
998989
ElastixRegistrationMethod<TFixedImage, TMovingImage>::GetNthTransform(const unsigned int n) const -> TransformType *
999990
{
1000-
const auto * const transformContainer = m_ElastixMain->GetElastixBase().GetTransformContainer();
1001-
1002-
if ((transformContainer == nullptr) || transformContainer->empty())
1003-
{
1004-
return nullptr;
1005-
}
991+
const auto advancedCombinationTransform = GetAdvancedCombinationTransform();
992+
return advancedCombinationTransform ? advancedCombinationTransform->GetNthTransform(n) : nullptr;
993+
}
1006994

1007-
const auto * const elxTransformBase =
1008-
dynamic_cast<ElastixTransformBaseType *>(transformContainer->front().GetPointer());
1009995

1010-
if (elxTransformBase == nullptr)
996+
template <typename TFixedImage, typename TMovingImage>
997+
auto
998+
ElastixRegistrationMethod<TFixedImage, TMovingImage>::GetAdvancedCombinationTransform() const
999+
-> AdvancedCombinationTransformType *
1000+
{
10111001
{
1002+
if (m_ElastixMain)
1003+
{
1004+
if (const auto transformContainer = m_ElastixMain->GetElastixBase().GetTransformContainer();
1005+
(transformContainer != nullptr) && !transformContainer->empty())
1006+
{
1007+
if (const auto firstTransform = transformContainer->front().GetPointer())
1008+
{
1009+
return static_cast<AdvancedCombinationTransformType *>(firstTransform);
1010+
}
1011+
}
1012+
}
10121013
return nullptr;
10131014
}
1014-
return elxTransformBase->GetAsITKBaseType()->GetNthTransform(n);
10151015
}
10161016

10171017

10181018
template <typename TFixedImage, typename TMovingImage>
10191019
auto
10201020
ElastixRegistrationMethod<TFixedImage, TMovingImage>::GetCombinationTransform() const -> TransformType *
10211021
{
1022-
const auto * const transformContainer = m_ElastixMain->GetElastixBase().GetTransformContainer();
1023-
1024-
if ((transformContainer == nullptr) || transformContainer->empty())
1025-
{
1026-
return nullptr;
1027-
}
1028-
1029-
auto * const elxTransformBase = dynamic_cast<ElastixTransformBaseType *>(transformContainer->front().GetPointer());
1030-
1031-
if (elxTransformBase == nullptr)
1032-
{
1033-
return nullptr;
1034-
}
1035-
return elxTransformBase->GetAsITKBaseType();
1022+
return GetAdvancedCombinationTransform();
10361023
}
10371024

10381025

0 commit comments

Comments
 (0)