Skip to content

Commit

Permalink
STYLE: Add local configuration variables to elx stack transforms
Browse files Browse the repository at this point in the history
- Follow-up to pull request #986 commit e205d1d "ENH: Add local `const Configuration &` variables to ImageSamplers"
  • Loading branch information
N-Dekker committed Jun 14, 2024
1 parent bc62b72 commit 9dd972e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "elxAffineLogStackTransform.h"

#include "itkImageRegionExclusionConstIteratorWithIndex.h"
#include <itkDeref.h>
#include <vnl/vnl_math.h>

namespace elastix
Expand Down Expand Up @@ -100,11 +101,12 @@ AffineLogStackTransform<TElastix>::ReadFromFile()
{
if (!this->HasITKTransformParameters())
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Read stack-spacing, stack-origin and number of sub-transforms. */
this->GetConfiguration()->ReadParameter(
m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
this->GetConfiguration()->ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
this->GetConfiguration()->ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);

ReducedDimensionInputPointType RDcenterOfRotationPoint{};

Expand Down Expand Up @@ -184,17 +186,19 @@ AffineLogStackTransform<TElastix>::InitializeTransform()
SizeType fixedImageSize =
this->m_Registration->GetAsITKBaseType()->GetFixedImage()->GetLargestPossibleRegion().GetSize();

const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

for (unsigned int i = 0; i < ReducedSpaceDimension; ++i)
{
/** Check COR index: Returns zero when parameter was in the parameter file. */
bool foundI = this->m_Configuration->ReadParameter(centerOfRotationIndex[i], "CenterOfRotation", i, false);
bool foundI = configuration.ReadParameter(centerOfRotationIndex[i], "CenterOfRotation", i, false);
if (!foundI)
{
centerGivenAsIndex = false;
}

/** Check COR point: Returns zero when parameter was in the parameter file. */
bool foundP = this->m_Configuration->ReadParameter(RDcenterOfRotationPoint[i], "CenterOfRotationPoint", i, false);
bool foundP = configuration.ReadParameter(RDcenterOfRotationPoint[i], "CenterOfRotationPoint", i, false);
if (!foundP)
{
centerGivenAsPoint = false;
Expand All @@ -207,7 +211,7 @@ AffineLogStackTransform<TElastix>::InitializeTransform()
*/
bool automaticTransformInitialization = false;
bool tmpBool = false;
this->m_Configuration->ReadParameter(tmpBool, "AutomaticTransformInitialization", 0);
configuration.ReadParameter(tmpBool, "AutomaticTransformInitialization", 0);
if (tmpBool && this->Superclass1::GetInitialTransform() == nullptr)
{
automaticTransformInitialization = true;
Expand Down Expand Up @@ -270,17 +274,19 @@ template <class TElastix>
void
AffineLogStackTransform<TElastix>::SetScales()
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Create the new scales. */
const NumberOfParametersType numberOfParameters = this->GetNumberOfParameters();
ScalesType newscales(numberOfParameters);

/** Check if automatic scales estimation is desired. */
bool automaticScalesEstimation = false;
this->m_Configuration->ReadParameter(automaticScalesEstimation, "AutomaticScalesEstimation", 0);
configuration.ReadParameter(automaticScalesEstimation, "AutomaticScalesEstimation", 0);

/** Check also AutomaticScalesEstimationStackTransform for backwards compatability. */
bool automaticScalesEstimationStackTransform = false;
this->m_Configuration->ReadParameter(
configuration.ReadParameter(
automaticScalesEstimationStackTransform, "AutomaticScalesEstimationStackTransform", 0, false);

if (automaticScalesEstimationStackTransform)
Expand Down Expand Up @@ -327,7 +333,7 @@ AffineLogStackTransform<TElastix>::SetScales()
const unsigned int rotationPart = (ReducedSpaceDimension) * (ReducedSpaceDimension);
const unsigned int totalPart = (SpaceDimension) * (ReducedSpaceDimension);

/** this->m_Configuration->ReadParameter() returns 0 if there is a value given
/** configuration.ReadParameter() returns 0 if there is a value given
* in the parameter-file, and returns 1 if there is no value given in the
* parameter-file.
* Check which option is used:
Expand All @@ -343,7 +349,7 @@ AffineLogStackTransform<TElastix>::SetScales()
int sizeLastDimension =
this->GetElastix()->GetFixedImage()->GetLargestPossibleRegion().GetSize()[SpaceDimension - 1];

std::size_t count = this->m_Configuration->CountNumberOfParameterEntries("Scales");
std::size_t count = configuration.CountNumberOfParameterEntries("Scales");

/** Check which of the above options is used. */
if (count == 0)
Expand All @@ -363,7 +369,7 @@ AffineLogStackTransform<TElastix>::SetScales()
{
/** In this case the second option is used. */
double scale = defaultScalingvalue;
this->m_Configuration->ReadParameter(scale, "Scales", 0);
configuration.ReadParameter(scale, "Scales", 0);
newscales.Fill(scale);

/** The non-rotation scales are set to 1.0 */
Expand All @@ -379,7 +385,7 @@ AffineLogStackTransform<TElastix>::SetScales()
/** In this case the third option is used. */
for (unsigned int i = 0; i < numberOfParameters; ++i)
{
this->m_Configuration->ReadParameter(newscales[i], "Scales", i);
configuration.ReadParameter(newscales[i], "Scales", i);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "elxBSplineStackTransform.h"

#include "itkImageRegionExclusionConstIteratorWithIndex.h"
#include <itkDeref.h>
#include <vnl/vnl_math.h>

namespace elastix
Expand Down Expand Up @@ -224,16 +225,18 @@ BSplineStackTransform<TElastix>::PreComputeGridInformation()
* Which is the default schedule, if no GridSpacingSchedule is supplied.
*/

const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Determine which method is used. */
bool method1 = false;
std::size_t count1 = this->m_Configuration->CountNumberOfParameterEntries("FinalGridSpacingInVoxels");
std::size_t count1 = configuration.CountNumberOfParameterEntries("FinalGridSpacingInVoxels");
if (count1 > 0)
{
method1 = true;
}

bool method2 = false;
std::size_t count2 = this->m_Configuration->CountNumberOfParameterEntries("FinalGridSpacingInPhysicalUnits");
std::size_t count2 = configuration.CountNumberOfParameterEntries("FinalGridSpacingInPhysicalUnits");
if (count2 > 0)
{
method2 = true;
Expand All @@ -257,7 +260,7 @@ BSplineStackTransform<TElastix>::PreComputeGridInformation()
{
for (unsigned int dim = 0; dim < ReducedSpaceDimension; ++dim)
{
this->m_Configuration->ReadParameter(
configuration.ReadParameter(
finalGridSpacingInVoxels[dim], "FinalGridSpacingInVoxels", this->GetComponentLabel(), dim, 0);
}

Expand All @@ -274,7 +277,7 @@ BSplineStackTransform<TElastix>::PreComputeGridInformation()
{
for (unsigned int dim = 0; dim < ReducedSpaceDimension; ++dim)
{
this->m_Configuration->ReadParameter(
configuration.ReadParameter(
finalGridSpacingInPhysicalUnits[dim], "FinalGridSpacingInPhysicalUnits", this->GetComponentLabel(), dim, 0);
}
}
Expand All @@ -285,7 +288,7 @@ BSplineStackTransform<TElastix>::PreComputeGridInformation()
m_GridScheduleComputer->GetSchedule(gridSchedule);

/** Read what the user has specified. This overrules everything. */
count2 = this->m_Configuration->CountNumberOfParameterEntries("GridSpacingSchedule");
count2 = configuration.CountNumberOfParameterEntries("GridSpacingSchedule");
unsigned int entry_nr = 0;
if (count2 == 0)
{
Expand All @@ -297,7 +300,7 @@ BSplineStackTransform<TElastix>::PreComputeGridInformation()
{
for (unsigned int dim = 0; dim < ReducedSpaceDimension; ++dim)
{
this->m_Configuration->ReadParameter(gridSchedule[res][dim], "GridSpacingSchedule", entry_nr, false);
configuration.ReadParameter(gridSchedule[res][dim], "GridSpacingSchedule", entry_nr, false);
}
++entry_nr;
}
Expand All @@ -308,7 +311,7 @@ BSplineStackTransform<TElastix>::PreComputeGridInformation()
{
for (unsigned int dim = 0; dim < ReducedSpaceDimension; ++dim)
{
this->m_Configuration->ReadParameter(gridSchedule[res][dim], "GridSpacingSchedule", entry_nr, false);
configuration.ReadParameter(gridSchedule[res][dim], "GridSpacingSchedule", entry_nr, false);
++entry_nr;
}
}
Expand Down Expand Up @@ -444,16 +447,17 @@ BSplineStackTransform<TElastix>::ReadFromFile()
{
if (!this->HasITKTransformParameters())
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Read spline order settings and initialize BSplineTransform. */
m_SplineOrder = 3;
this->GetConfiguration()->ReadParameter(
m_SplineOrder, "BSplineTransformSplineOrder", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_SplineOrder, "BSplineTransformSplineOrder", this->GetComponentLabel(), 0, 0);

/** Read stack-spacing, stack-origin and number of sub-transforms. */
bool dummy = this->GetConfiguration()->ReadParameter(
m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
dummy |= this->GetConfiguration()->ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
dummy |= this->GetConfiguration()->ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);
bool dummy =
configuration.ReadParameter(m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
dummy |= configuration.ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
dummy |= configuration.ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);

/** Initialize the right B-spline transform. */
this->InitializeBSplineTransform();
Expand All @@ -475,13 +479,13 @@ BSplineStackTransform<TElastix>::ReadFromFile()
/** Get GridSize, GridIndex, GridSpacing and GridOrigin. */
for (unsigned int i = 0; i < ReducedSpaceDimension; ++i)
{
dummy |= this->m_Configuration->ReadParameter(gridsize[i], "GridSize", i);
dummy |= this->m_Configuration->ReadParameter(gridindex[i], "GridIndex", i);
dummy |= this->m_Configuration->ReadParameter(gridspacing[i], "GridSpacing", i);
dummy |= this->m_Configuration->ReadParameter(gridorigin[i], "GridOrigin", i);
dummy |= configuration.ReadParameter(gridsize[i], "GridSize", i);
dummy |= configuration.ReadParameter(gridindex[i], "GridIndex", i);
dummy |= configuration.ReadParameter(gridspacing[i], "GridSpacing", i);
dummy |= configuration.ReadParameter(gridorigin[i], "GridOrigin", i);
for (unsigned int j = 0; j < ReducedSpaceDimension; ++j)
{
this->m_Configuration->ReadParameter(griddirection(j, i), "GridDirection", i * ReducedSpaceDimension + j);
configuration.ReadParameter(griddirection(j, i), "GridDirection", i * ReducedSpaceDimension + j);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define elxEulerStackTransform_hxx

#include "elxEulerStackTransform.h"
#include <itkDeref.h>

namespace elastix
{
Expand Down Expand Up @@ -96,11 +97,12 @@ EulerStackTransform<TElastix>::ReadFromFile()
{
if (!this->HasITKTransformParameters())
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Read stack-spacing, stack-origin and number of sub-transforms. */
this->GetConfiguration()->ReadParameter(
m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
this->GetConfiguration()->ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
this->GetConfiguration()->ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);

ReducedDimensionInputPointType RDcenterOfRotationPoint{};

Expand Down Expand Up @@ -163,6 +165,7 @@ template <class TElastix>
void
EulerStackTransform<TElastix>::InitializeTransform()
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Set all parameters to zero (no rotations, no translation). */
m_DummySubTransform->SetIdentity();
Expand All @@ -185,15 +188,14 @@ EulerStackTransform<TElastix>::InitializeTransform()
for (unsigned int i = 0; i < ReducedSpaceDimension; ++i)
{
/** Check COR index: Returns zero when parameter was in the parameter file. */
const bool foundI = this->m_Configuration->ReadParameter(centerOfRotationIndex[i], "CenterOfRotation", i, false);
const bool foundI = configuration.ReadParameter(centerOfRotationIndex[i], "CenterOfRotation", i, false);
if (!foundI)
{
centerGivenAsIndex = false;
}

/** Check COR point: Returns zero when parameter was in the parameter file. */
const bool foundP =
this->m_Configuration->ReadParameter(redDimCenterOfRotationPoint[i], "CenterOfRotationPoint", i, false);
const bool foundP = configuration.ReadParameter(redDimCenterOfRotationPoint[i], "CenterOfRotationPoint", i, false);
if (!foundP)
{
centerGivenAsPoint = false;
Expand Down Expand Up @@ -221,7 +223,7 @@ EulerStackTransform<TElastix>::InitializeTransform()

/** FIX: why may the cop not work when using direction cosines? */
bool UseDirectionCosines = true;
this->m_Configuration->ReadParameter(UseDirectionCosines, "UseDirectionCosines", 0);
configuration.ReadParameter(UseDirectionCosines, "UseDirectionCosines", 0);
if (!UseDirectionCosines)
{
log::info(std::ostringstream{}
Expand Down Expand Up @@ -325,18 +327,19 @@ template <class TElastix>
void
EulerStackTransform<TElastix>::SetScales()
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Create the new scales. */
const NumberOfParametersType numberOfParameters = this->GetNumberOfParameters();
ScalesType newscales(numberOfParameters);

/** Check if automatic scales estimation is desired. */
bool automaticScalesEstimation = false;
this->m_Configuration->ReadParameter(automaticScalesEstimation, "AutomaticScalesEstimation", 0);
configuration.ReadParameter(automaticScalesEstimation, "AutomaticScalesEstimation", 0);

/** Check also AutomaticScalesEstimationStackTransform for backwards compatability. */
bool automaticScalesEstimationStackTransform = false;
this->m_Configuration->ReadParameter(
configuration.ReadParameter(
automaticScalesEstimationStackTransform, "AutomaticScalesEstimationStackTransform", 0, false);

if (automaticScalesEstimationStackTransform)
Expand Down Expand Up @@ -382,7 +385,7 @@ EulerStackTransform<TElastix>::SetScales()
const unsigned int numRotationParsPerDimension = ReducedSpaceDimension == 2 ? 1 : 3;
const unsigned int numTotalParsPerDimension = ReducedSpaceDimension == 2 ? 3 : 6;

/** this->m_Configuration->ReadParameter() returns 0 if there is a value given
/** configuration.ReadParameter() returns 0 if there is a value given
* in the parameter-file, and returns 1 if there is no value given in the
* parameter-file.
*
Expand All @@ -399,7 +402,7 @@ EulerStackTransform<TElastix>::SetScales()
const int sizeLastDimension =
this->GetElastix()->GetFixedImage()->GetLargestPossibleRegion().GetSize()[SpaceDimension - 1];

std::size_t count = this->m_Configuration->CountNumberOfParameterEntries("Scales");
std::size_t count = configuration.CountNumberOfParameterEntries("Scales");

/** Check which of the above options is used. */
if (count == 0)
Expand All @@ -421,7 +424,7 @@ EulerStackTransform<TElastix>::SetScales()
{
/** In this case the second option is used. */
double scale = defaultScalingvalue;
this->m_Configuration->ReadParameter(scale, "Scales", 0);
configuration.ReadParameter(scale, "Scales", 0);
newscales.Fill(scale);

/** The non-rotation scales are set to 1.0 for all dimensions */
Expand All @@ -440,7 +443,7 @@ EulerStackTransform<TElastix>::SetScales()
/** In this case the third option is used. */
for (unsigned int i = 0; i < numberOfParameters; ++i)
{
this->m_Configuration->ReadParameter(newscales[i], "Scales", i);
configuration.ReadParameter(newscales[i], "Scales", i);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "elxTranslationStackTransform.h"

#include "itkImageRegionExclusionConstIteratorWithIndex.h"
#include <itkDeref.h>
#include <vnl/vnl_math.h>

namespace elastix
Expand Down Expand Up @@ -125,11 +126,12 @@ TranslationStackTransform<TElastix>::ReadFromFile()

if (!this->HasITKTransformParameters())
{
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Read stack-spacing, stack-origin and number of sub-transforms. */
this->GetConfiguration()->ReadParameter(
m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
this->GetConfiguration()->ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
this->GetConfiguration()->ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_NumberOfSubTransforms, "NumberOfSubTransforms", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_StackOrigin, "StackOrigin", this->GetComponentLabel(), 0, 0);
configuration.ReadParameter(m_StackSpacing, "StackSpacing", this->GetComponentLabel(), 0, 0);

/** Initialize translation transform. */
InitializeTranslationTransform();
Expand Down

0 comments on commit 9dd972e

Please sign in to comment.