From 09be69e835dcca277b4cff5830966bd8496876a9 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 22 Jun 2021 18:10:50 +0200 Subject: [PATCH] STYLE: Use the new ITK 5.2 `OptimizerParameters` constructors Simplified the code by using these two `explicit` constructors, which are added with ITK 5.2: OptimizerParameters(SizeValueType dimension, const ValueType & value); OptimizerParameters(const ValueType * inputData, SizeValueType dimension); Follow-up to pull request https://github.com/SuperElastix/elastix/pull/475 commit 6803b26a73aea270cf7b75e0febc4d53ea21053e "COMP: Upgrade ITK from v5.1.1 to v5.2.0" --- Common/GTesting/elxConversionGTest.cxx | 4 +--- Common/GTesting/elxTransformIOGTest.cxx | 6 +++--- Common/Transforms/itkStackTransform.hxx | 7 +------ ...ComputePreconditionerUsingDisplacementDistribution.hxx | 8 +++----- .../itkCMAEvolutionStrategyOptimizer.cxx | 3 +-- Core/Install/elxConversion.cxx | 2 +- Testing/elxInvertTransform.cxx | 6 +----- 7 files changed, 11 insertions(+), 25 deletions(-) diff --git a/Common/GTesting/elxConversionGTest.cxx b/Common/GTesting/elxConversionGTest.cxx index 5e6bf5050..d7f4fe56d 100644 --- a/Common/GTesting/elxConversionGTest.cxx +++ b/Common/GTesting/elxConversionGTest.cxx @@ -265,9 +265,7 @@ GTEST_TEST(Conversion, ToOptimizerParameters) for (const double value : { -1.0, 0.0, 1.0, DBL_MIN, DBL_MAX }) { - OptimizerParametersType expectedOptimizerParameters(1U); - expectedOptimizerParameters[0] = value; - EXPECT_EQ(Conversion::ToOptimizerParameters(StdVectorType{ value }), expectedOptimizerParameters); + EXPECT_EQ(Conversion::ToOptimizerParameters(StdVectorType{ value }), OptimizerParametersType(1U, value)); } StdVectorType stdVector(10U); diff --git a/Common/GTesting/elxTransformIOGTest.cxx b/Common/GTesting/elxTransformIOGTest.cxx index 9124d5d92..51902355e 100644 --- a/Common/GTesting/elxTransformIOGTest.cxx +++ b/Common/GTesting/elxTransformIOGTest.cxx @@ -275,9 +275,9 @@ struct WithDimension elxTransform->SetElastix(elastixObject); elxTransform->BeforeAll(); - ParameterMapType parameterMap; - const itk::OptimizerParameters optimizerParameters(itk::Array(vnl_vector(2U, testValue))); - elxTransform->CreateTransformParametersMap(optimizerParameters, parameterMap); + ParameterMapType parameterMap; + + elxTransform->CreateTransformParametersMap(itk::OptimizerParameters(2U, testValue), parameterMap); for (const auto key : { "TransformParameters", "Origin", "Spacing" }) { diff --git a/Common/Transforms/itkStackTransform.hxx b/Common/Transforms/itkStackTransform.hxx index af3e47e65..3bcb88798 100644 --- a/Common/Transforms/itkStackTransform.hxx +++ b/Common/Transforms/itkStackTransform.hxx @@ -56,13 +56,8 @@ StackTransform::SetParameters( const NumberOfParametersType numSubTransformParameters = this->m_SubTransformContainer[0]->GetNumberOfParameters(); for (unsigned int t = 0; t < this->m_NumberOfSubTransforms; ++t) { - // MS, \todo: the new itk::TransformParameters only have constructors taking 1 argument - // ParametersType subparams ( ParametersArrayType( &( param.data_block()[ t * numSubTransformParameters ] ), - // numSubTransformParameters, false ) ); ParametersType subparams ( &( param.data_block()[ t * - // numSubTransformParameters ] ), numSubTransformParameters, false ); // NTA, split the parameter by number of subparameters - const Array subarray(&(param.data_block()[t * numSubTransformParameters]), numSubTransformParameters); - ParametersType subparams(subarray); + const ParametersType subparams(&(param.data_block()[t * numSubTransformParameters]), numSubTransformParameters); this->m_SubTransformContainer[t]->SetParametersByValue(subparams); } diff --git a/Common/itkComputePreconditionerUsingDisplacementDistribution.hxx b/Common/itkComputePreconditionerUsingDisplacementDistribution.hxx index 25c5ca9d5..c7ff17dc4 100644 --- a/Common/itkComputePreconditionerUsingDisplacementDistribution.hxx +++ b/Common/itkComputePreconditionerUsingDisplacementDistribution.hxx @@ -199,9 +199,8 @@ ComputePreconditionerUsingDisplacementDistribution::Com #endif /** Loop over all voxels in the sample container. */ - ParametersType binCount(P); - binCount.Fill(0.0); - unsigned int samplenr = 0; // needed for global value only + ParametersType binCount(P, 0.0); + unsigned int samplenr = 0; // needed for global value only for (iter = begin; iter != end; ++iter) { @@ -631,8 +630,7 @@ ComputePreconditionerUsingDisplacementDistribution::Com JacobianType jacjjacj(outdim, outdim); const double sqrt2 = std::sqrt(static_cast(2.0)); NonZeroJacobianIndicesType jacind(sizejacind); - ParametersType binCount(P); - binCount.Fill(0.0); + ParametersType binCount(P, 0.0); /** Loop over all voxels in the sample container. */ for (iter = begin; iter != end; ++iter) diff --git a/Components/Optimizers/CMAEvolutionStrategy/itkCMAEvolutionStrategyOptimizer.cxx b/Components/Optimizers/CMAEvolutionStrategy/itkCMAEvolutionStrategyOptimizer.cxx index f59f9f86c..0214a85ce 100644 --- a/Components/Optimizers/CMAEvolutionStrategy/itkCMAEvolutionStrategyOptimizer.cxx +++ b/Components/Optimizers/CMAEvolutionStrategy/itkCMAEvolutionStrategyOptimizer.cxx @@ -404,8 +404,7 @@ CMAEvolutionStrategyOptimizer::InitializeProgressVariables(void) this->m_Heaviside = 0.0; /** m_SearchDirs */ - ParametersType zeroParam(N); - zeroParam.Fill(0.0); + const ParametersType zeroParam(N, 0.0); this->m_SearchDirs.clear(); this->m_SearchDirs.resize(lambda, zeroParam); diff --git a/Core/Install/elxConversion.cxx b/Core/Install/elxConversion.cxx index 020aee52a..a8e54c0e5 100644 --- a/Core/Install/elxConversion.cxx +++ b/Core/Install/elxConversion.cxx @@ -91,7 +91,7 @@ Conversion::SecondsToDHMS(const double totalSeconds, const unsigned int precisio itk::OptimizerParameters Conversion::ToOptimizerParameters(const std::vector & stdVector) { - return itk::OptimizerParameters(itk::Array(stdVector.data(), stdVector.size())); + return itk::OptimizerParameters(stdVector.data(), stdVector.size()); }; diff --git a/Testing/elxInvertTransform.cxx b/Testing/elxInvertTransform.cxx index ded5497b8..4f0e8f39a 100644 --- a/Testing/elxInvertTransform.cxx +++ b/Testing/elxInvertTransform.cxx @@ -167,11 +167,7 @@ main(int argc, char * argv[]) config->ReadParameter(vecPar, "TransformParameters", 0, numberOfParameters - 1, true, dummyErrorMessage); /** Convert to ParametersType. */ - ParametersType transformParameters(numberOfParameters); - for (unsigned int i = 0; i < numberOfParameters; ++i) - { - transformParameters[i] = vecPar[i]; - } + const ParametersType transformParameters(vecPar.data(), numberOfParameters); /** Get center of rotation. */ CenterType centerOfRotation;