From ac55440c8fc8ce260a5bc55fb349422cd3403b6a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 9 Jun 2023 17:31:35 +0200 Subject: [PATCH] ENH: ElastixRegistrationMethod writes initial transform parameter files Let ElastixRegistrationMethod write the transform maps from its InitialTransformParameterObject to the output directory. --- Core/Main/itkElastixRegistrationMethod.hxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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);