Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdvancedCombinationTransform::GetNumberOfTransforms() returns zero when initial transform is not a combination! #927

Open
N-Dekker opened this issue Jun 29, 2023 · 1 comment
Assignees

Comments

@N-Dekker
Copy link
Member

It appears that AdvancedCombinationTransform::GetNumberOfTransforms() returns zero when the initial transform is not a combination transform. Looking at the original commit (2fc2c49, November 14, 2013):

template <typename TScalarType, unsigned int NDimensions>
SizeValueType
AdvancedCombinationTransform<TScalarType, NDimensions>
::GetNumberOfTransforms( void ) const
{
SizeValueType num = 0;
CurrentTransformConstPointer currentTransform = GetCurrentTransform();
if( currentTransform.IsNotNull() )
{
InitialTransformConstPointer initialTransform = GetInitialTransform();
if( initialTransform.IsNotNull() )
{
const Self *initialTransformCasted =
dynamic_cast< const Self * >( initialTransform.GetPointer() );
if ( initialTransformCasted )
{
num += initialTransformCasted->GetNumberOfTransforms() + 1;
}
}
else
{
num++;
}
}
return num;
} // end GetNumberOfTransforms()

Simplified as follows (by the first commit of pull request #925):

 if (GetCurrentTransform()) 
 { 
   if (const InitialTransformConstPointer initialTransform = GetInitialTransform()) 
   { 
     if (const auto initialTransformCasted = dynamic_cast<const Self *>(initialTransform.GetPointer())) 
     { 
       return initialTransformCasted->GetNumberOfTransforms() + 1; 
     } 
   } 
   else 
   { 
     return 1; 
   } 
 } 
  
 return 0; 

You see, if the dynamic_cast<const Self *> fails, the function falls back to just return 0. Is that OK? Because it seems to me that it should return 2 instead.

Example unit test:

  const auto Dimension = 2U;

  using TranslationTransformElastixType = elx::TranslationTransformElastix<ElastixType<Dimension>>;
  using AdvancedCombinationTransformType = TranslationTransformElastixType::Superclass1;
  using AdvancedTransformType = AdvancedCombinationTransformType::Superclass;
  const auto TranslationTransformElastix = TranslationTransformElastixType::New();
  const auto initialTranslationTransformElastix = TranslationTransformElastixType::New();

  // The following expectation passes as well, no problem.
  EXPECT_EQ(TranslationTransformElastix->GetNumberOfTransforms(), 1);
  TranslationTransformElastix->AdvancedCombinationTransformType::SetInitialTransform(
    initialTranslationTransformElastix);
  // The following expectation passes, no problem.
  EXPECT_EQ(TranslationTransformElastix->GetNumberOfTransforms(), 2);

  const auto advancedTranslationTransform = itk::AdvancedTranslationTransform<double, Dimension>::New();
  TranslationTransformElastix->AdvancedCombinationTransformType::SetInitialTransform(advancedTranslationTransform);
  // The following expectation fails, because GetNumberOfTransforms() returns zero!!!
  EXPECT_EQ(TranslationTransformElastix->GetNumberOfTransforms(), 2);

@N-Dekker
Copy link
Member Author

@mstaring @stefanklein Could it be that in practice the initial transform is always also a combination transform? (Meaning that the dynamic_cast<const Self *>(initialTransform.GetPointer()) always returns a non-null pointer anyway?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants