diff --git a/Core/Main/itkElastixRegistrationMethod.hxx b/Core/Main/itkElastixRegistrationMethod.hxx index e2a0c84aa..8c96f8482 100644 --- a/Core/Main/itkElastixRegistrationMethod.hxx +++ b/Core/Main/itkElastixRegistrationMethod.hxx @@ -177,6 +177,25 @@ ElastixRegistrationMethod::GenerateData() m_EnableOutput && m_LogToConsole, static_cast(m_LogLevel)); + if (m_InitialTransformParameterObject && !m_OutputDirectory.empty()) + { + // Write InitialTransformParameters.0.txt, InitialTransformParameters.1.txt, InitialTransformParameters.2.txt, etc. + std::string initialTransformParameterFileName = "NoInitialTransform"; + unsigned i{}; + + for (auto transformParameterMap : m_InitialTransformParameterObject->GetParameterMaps()) + { + transformParameterMap["InitialTransformParameterFileName"] = { initialTransformParameterFileName }; + + const auto transformParameterFileName = "InitialTransformParameters." + std::to_string(i) + ".txt"; + elx::ParameterObject::WriteParameterFile(transformParameterMap, m_OutputDirectory + transformParameterFileName); + initialTransformParameterFileName = transformParameterFileName; + ++i; + } + + argumentMap["-tp"] = initialTransformParameterFileName; + } + const auto fixedImageDimensionString = std::to_string(FixedImageDimension); const auto fixedImagePixelTypeString = elx::PixelTypeToString(); const auto movingImageDimensionString = std::to_string(MovingImageDimension);