Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Use the new ITK 5.2 OptimizerParameters constructors #484

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Common/GTesting/elxConversionGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Common/GTesting/elxTransformIOGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ struct WithDimension
elxTransform->SetElastix(elastixObject);
elxTransform->BeforeAll();

ParameterMapType parameterMap;
const itk::OptimizerParameters<double> optimizerParameters(itk::Array<double>(vnl_vector<double>(2U, testValue)));
elxTransform->CreateTransformParametersMap(optimizerParameters, parameterMap);
ParameterMapType parameterMap;

elxTransform->CreateTransformParametersMap(itk::OptimizerParameters<double>(2U, testValue), parameterMap);

for (const auto key : { "TransformParameters", "Origin", "Spacing" })
{
Expand Down
7 changes: 1 addition & 6 deletions Common/Transforms/itkStackTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ StackTransform<TScalarType, NInputDimensions, NOutputDimensions>::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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mstaring This pull request finally fixes the \todo that you wrote many years ago 😃 The new (ITK 5.2) itk::OptmizerParameters does have a few more convenient constructors than before, including one that accepts a data pointer and a size as arguments! No need to use a temporary subarray anymore!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work and lgtm!

// 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<double> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ ComputePreconditionerUsingDisplacementDistribution<TFixedImage, TTransform>::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)
{
Expand Down Expand Up @@ -631,8 +630,7 @@ ComputePreconditionerUsingDisplacementDistribution<TFixedImage, TTransform>::Com
JacobianType jacjjacj(outdim, outdim);
const double sqrt2 = std::sqrt(static_cast<double>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Core/Install/elxConversion.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Conversion::SecondsToDHMS(const double totalSeconds, const unsigned int precisio
itk::OptimizerParameters<double>
Conversion::ToOptimizerParameters(const std::vector<double> & stdVector)
{
return itk::OptimizerParameters<double>(itk::Array<double>(stdVector.data(), stdVector.size()));
return itk::OptimizerParameters<double>(stdVector.data(), stdVector.size());
};


Expand Down
6 changes: 1 addition & 5 deletions Testing/elxInvertTransform.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down