Skip to content

Commit

Permalink
ENH: Add GetPreviousTransformConfiguration to ElastixBase
Browse files Browse the repository at this point in the history
Used to slightly simplify `TransformBase<TElastix>::ReadFromFile()`.
  • Loading branch information
N-Dekker committed Mar 23, 2023
1 parent 38b6152 commit b261946
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Core/ComponentBaseClasses/elxTransformBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,14 @@ TransformBase<TElastix>::ReadFromFile()
/** Call the function ReadInitialTransformFromFile. */
if (fileName == "NoInitialTransform")
{
const auto numberOfConfigurations = elastixBase.GetNumberOfTransformConfigurations();

if ((numberOfConfigurations > 1) && (&configuration != elastixBase.GetTransformConfiguration(0)))
if (elastixBase.GetNumberOfTransformConfigurations() > 1)
{
for (size_t index{ 1 }; index < numberOfConfigurations; ++index)
const Configuration::ConstPointer previousTransformConfiguration =
elastixBase.GetPreviousTransformConfiguration(configuration);

if (previousTransformConfiguration)
{
if (elastixBase.GetTransformConfiguration(index) == &configuration)
{
// Use the previous configuration (at position index - 1) for the initial transform.
this->ReadInitialTransformFromConfiguration(elastixBase.GetTransformConfiguration(index - 1));
break;
}
this->ReadInitialTransformFromConfiguration(previousTransformConfiguration);
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions Core/Kernel/elxElastixBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,21 @@ ElastixBase::GetTransformConfiguration(const size_t index) const
}


/**
* ************** GetPreviousTransformConfiguration *********************
*/

Configuration::ConstPointer
ElastixBase::GetPreviousTransformConfiguration(const Configuration & configuration) const
{
const auto begin = m_TransformConfigurations.cbegin();
const auto end = m_TransformConfigurations.cend();
const auto found = std::find(begin, end, &configuration);

return (found == begin || found == end) ? nullptr : *(found - 1);
}


/**
* ************** GetNumberOfTransformConfigurations *********************
*/
Expand Down
5 changes: 5 additions & 0 deletions Core/Kernel/elxElastixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ class ElastixBase
Configuration::ConstPointer
GetTransformConfiguration(const size_t index) const;

/** Returns the transformation configuration just before the specified one, or null. Returns null if the specified
* configuration does not have a previous one in the vector of transformation configurations. */
Configuration::ConstPointer
GetPreviousTransformConfiguration(const Configuration & configuration) const;

/** Returns the number of configurations in the vector of transformation configurations. */
size_t
GetNumberOfTransformConfigurations() const;
Expand Down

0 comments on commit b261946

Please sign in to comment.