Skip to content

Commit

Permalink
BUG: Ignore "InitialTransformParametersFileName" when configurations > 1
Browse files Browse the repository at this point in the history
When there are two or more "TransformConfigurations", the sequence of transforms is entirely specified by those configurations, and not by transform parameter files. The "InitialTransformParametersFileName" parameter should then be ignored.

Aims to fix a test failure that occurred when running itkElastixRegistrationMethodTest from
https://github.com/InsightSoftwareConsortium/ITKElastix/blob/v0.16.0/test/itkElastixRegistrationMethodTest.cxx at the current revision of the elastix main branch.

The bug appears introduced with pull request #837 commit 1d75664 "ENH: Find previous configuration without interpreting filename as index" (merged on March 17, 2023).
  • Loading branch information
N-Dekker committed May 7, 2023
1 parent ec8034d commit 73a0d3a
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions Core/ComponentBaseClasses/elxTransformBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -348,43 +348,42 @@ TransformBase<TElastix>::ReadFromFile()
} // end if this->m_ReadWriteTransformParameters

/** Task 2 - Get the InitialTransform. */

/** Get the InitialTransformName. */
std::string fileName = "NoInitialTransform";
configuration.ReadParameter(fileName, "InitialTransformParametersFileName", 0);

const ElastixBase & elastixBase = Deref(Superclass::GetElastix());

/** Call the function ReadInitialTransformFromFile. */
if (fileName == "NoInitialTransform")
if (elastixBase.GetNumberOfTransformConfigurations() > 1)
{
if (elastixBase.GetNumberOfTransformConfigurations() > 1)
{
const Configuration::ConstPointer previousTransformConfiguration =
elastixBase.GetPreviousTransformConfiguration(configuration);
const Configuration::ConstPointer previousTransformConfiguration =
elastixBase.GetPreviousTransformConfiguration(configuration);

if (previousTransformConfiguration)
{
this->ReadInitialTransformFromConfiguration(previousTransformConfiguration);
}
if (previousTransformConfiguration)
{
this->ReadInitialTransformFromConfiguration(previousTransformConfiguration);
}
}
else
{
/** Check if the initial transform of this transform parameter file
* is not the same as this transform parameter file. Otherwise,
* we will have an infinite loop.
*/
std::string fullFileName1 = itksys::SystemTools::CollapseFullPath(fileName);
std::string fullFileName2 = itksys::SystemTools::CollapseFullPath(configuration.GetParameterFileName());
if (fullFileName1 == fullFileName2)
/** Get the InitialTransformName. */
std::string fileName = "NoInitialTransform";
configuration.ReadParameter(fileName, "InitialTransformParametersFileName", 0);

/** Call the function ReadInitialTransformFromFile. */
if (fileName != "NoInitialTransform")
{
itkExceptionMacro(<< "ERROR: The InitialTransformParametersFileName is identical to the current "
"TransformParameters filename! An infinite loop is not allowed.");
}
/** Check if the initial transform of this transform parameter file
* is not the same as this transform parameter file. Otherwise,
* we will have an infinite loop.
*/
std::string fullFileName1 = itksys::SystemTools::CollapseFullPath(fileName);
std::string fullFileName2 = itksys::SystemTools::CollapseFullPath(configuration.GetParameterFileName());
if (fullFileName1 == fullFileName2)
{
itkExceptionMacro(<< "ERROR: The InitialTransformParametersFileName is identical to the current "
"TransformParameters filename! An infinite loop is not allowed.");
}

/** We can safely read the initial transform. */
this->ReadInitialTransformFromFile(fileName.c_str());
/** We can safely read the initial transform. */
this->ReadInitialTransformFromFile(fileName.c_str());
}
}

/** Task 3 - Read from the configuration file how to combine the
Expand Down

0 comments on commit 73a0d3a

Please sign in to comment.