diff --git a/Components/ImageSamplers/Grid/elxGridSampler.hxx b/Components/ImageSamplers/Grid/elxGridSampler.hxx index 0ebf84d75..7fbccda50 100644 --- a/Components/ImageSamplers/Grid/elxGridSampler.hxx +++ b/Components/ImageSamplers/Grid/elxGridSampler.hxx @@ -20,6 +20,7 @@ #define elxGridSampler_hxx #include "elxGridSampler.h" +#include "elxDeref.h" namespace elastix { @@ -32,6 +33,8 @@ template void GridSampler::BeforeEachResolution() { + const Configuration & configuration = Deref(Superclass2::GetConfiguration()); + const unsigned int level = this->m_Registration->GetAsITKBaseType()->GetCurrentLevel(); GridSpacingType gridspacing; @@ -41,7 +44,7 @@ GridSampler::BeforeEachResolution() for (unsigned int dim = 0; dim < InputImageDimension; ++dim) { spacing_dim = 2; - this->GetConfiguration()->ReadParameter( + configuration.ReadParameter( spacing_dim, "SampleGridSpacing", this->GetComponentLabel(), level * InputImageDimension + dim, -1); gridspacing[dim] = static_cast(spacing_dim); } diff --git a/Components/ImageSamplers/MultInputRandomCoordinate/elxMultiInputRandomCoordinateSampler.hxx b/Components/ImageSamplers/MultInputRandomCoordinate/elxMultiInputRandomCoordinateSampler.hxx index 7188669e6..4bc6115ae 100644 --- a/Components/ImageSamplers/MultInputRandomCoordinate/elxMultiInputRandomCoordinateSampler.hxx +++ b/Components/ImageSamplers/MultInputRandomCoordinate/elxMultiInputRandomCoordinateSampler.hxx @@ -20,6 +20,7 @@ #define elxMultiInputRandomCoordinateSampler_hxx #include "elxMultiInputRandomCoordinateSampler.h" +#include "elxDeref.h" namespace elastix { @@ -32,26 +33,25 @@ template void MultiInputRandomCoordinateSampler::BeforeEachResolution() { + const Configuration & configuration = Deref(Superclass2::GetConfiguration()); + const unsigned int level = (this->m_Registration->GetAsITKBaseType())->GetCurrentLevel(); /** Set the NumberOfSpatialSamples. */ unsigned long numberOfSpatialSamples = 5000; - this->GetConfiguration()->ReadParameter( - numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); this->SetNumberOfSamples(numberOfSpatialSamples); /** Set up the fixed image interpolator and set the SplineOrder, default value = 1. */ auto fixedImageInterpolator = DefaultInterpolatorType::New(); unsigned int splineOrder = 1; - this->GetConfiguration()->ReadParameter( - splineOrder, "FixedImageBSplineInterpolationOrder", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(splineOrder, "FixedImageBSplineInterpolationOrder", this->GetComponentLabel(), level, 0); fixedImageInterpolator->SetSplineOrder(splineOrder); this->SetInterpolator(fixedImageInterpolator); /** Set the UseRandomSampleRegion bool. */ bool useRandomSampleRegion = false; - this->GetConfiguration()->ReadParameter( - useRandomSampleRegion, "UseRandomSampleRegion", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(useRandomSampleRegion, "UseRandomSampleRegion", this->GetComponentLabel(), level, 0); this->SetUseRandomSampleRegion(useRandomSampleRegion); /** Set the SampleRegionSize. */ @@ -78,7 +78,7 @@ MultiInputRandomCoordinateSampler::BeforeEachResolution() /** Read user's choice. */ for (unsigned int i = 0; i < InputImageDimension; ++i) { - this->GetConfiguration()->ReadParameter( + configuration.ReadParameter( sampleRegionSize[i], "SampleRegionSize", this->GetComponentLabel(), level * InputImageDimension + i, 0); } this->SetSampleRegionSize(sampleRegionSize); diff --git a/Components/ImageSamplers/Random/elxRandomSampler.hxx b/Components/ImageSamplers/Random/elxRandomSampler.hxx index db40e90e3..834694f07 100644 --- a/Components/ImageSamplers/Random/elxRandomSampler.hxx +++ b/Components/ImageSamplers/Random/elxRandomSampler.hxx @@ -19,6 +19,7 @@ #define elxRandomSampler_hxx #include "elxRandomSampler.h" +#include "elxDeref.h" namespace elastix { @@ -31,12 +32,13 @@ template void RandomSampler::BeforeEachResolution() { + const Configuration & configuration = Deref(Superclass2::GetConfiguration()); + const unsigned int level = (this->m_Registration->GetAsITKBaseType())->GetCurrentLevel(); /** Set the NumberOfSpatialSamples. */ unsigned long numberOfSpatialSamples = 5000; - this->GetConfiguration()->ReadParameter( - numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); this->SetNumberOfSamples(numberOfSpatialSamples); diff --git a/Components/ImageSamplers/RandomCoordinate/elxRandomCoordinateSampler.hxx b/Components/ImageSamplers/RandomCoordinate/elxRandomCoordinateSampler.hxx index 94fdc1b59..db28b7f83 100644 --- a/Components/ImageSamplers/RandomCoordinate/elxRandomCoordinateSampler.hxx +++ b/Components/ImageSamplers/RandomCoordinate/elxRandomCoordinateSampler.hxx @@ -19,6 +19,7 @@ #define elxRandomCoordinateSampler_hxx #include "elxRandomCoordinateSampler.h" +#include "elxDeref.h" #include "itkLinearInterpolateImageFunction.h" namespace elastix @@ -32,18 +33,18 @@ template void RandomCoordinateSampler::BeforeEachResolution() { + const Configuration & configuration = Deref(Superclass2::GetConfiguration()); + const unsigned int level = this->m_Registration->GetAsITKBaseType()->GetCurrentLevel(); /** Set the NumberOfSpatialSamples. */ unsigned long numberOfSpatialSamples = 5000; - this->GetConfiguration()->ReadParameter( - numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); this->SetNumberOfSamples(numberOfSpatialSamples); /** Set up the fixed image interpolator and set the SplineOrder, default value = 1. */ unsigned int splineOrder = 1; - this->GetConfiguration()->ReadParameter( - splineOrder, "FixedImageBSplineInterpolationOrder", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(splineOrder, "FixedImageBSplineInterpolationOrder", this->GetComponentLabel(), level, 0); if (splineOrder == 1) { using LinearInterpolatorType = itk::LinearInterpolateImageFunction; @@ -59,8 +60,7 @@ RandomCoordinateSampler::BeforeEachResolution() /** Set the UseRandomSampleRegion bool. */ bool useRandomSampleRegion = false; - this->GetConfiguration()->ReadParameter( - useRandomSampleRegion, "UseRandomSampleRegion", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(useRandomSampleRegion, "UseRandomSampleRegion", this->GetComponentLabel(), level, 0); this->SetUseRandomSampleRegion(useRandomSampleRegion); /** Set the SampleRegionSize. */ @@ -87,7 +87,7 @@ RandomCoordinateSampler::BeforeEachResolution() /** Read and check user's choice. */ for (unsigned int i = 0; i < InputImageDimension; ++i) { - this->GetConfiguration()->ReadParameter( + configuration.ReadParameter( sampleRegionSize[i], "SampleRegionSize", this->GetComponentLabel(), level * InputImageDimension + i, 0); } this->SetSampleRegionSize(sampleRegionSize); diff --git a/Components/ImageSamplers/RandomSparseMask/elxRandomSamplerSparseMask.hxx b/Components/ImageSamplers/RandomSparseMask/elxRandomSamplerSparseMask.hxx index f26bf44dd..538eec6ed 100644 --- a/Components/ImageSamplers/RandomSparseMask/elxRandomSamplerSparseMask.hxx +++ b/Components/ImageSamplers/RandomSparseMask/elxRandomSamplerSparseMask.hxx @@ -20,6 +20,7 @@ #define elxRandomSamplerSparseMask_hxx #include "elxRandomSamplerSparseMask.h" +#include "elxDeref.h" namespace elastix { @@ -32,12 +33,13 @@ template void RandomSamplerSparseMask::BeforeEachResolution() { + const Configuration & configuration = Deref(Superclass2::GetConfiguration()); + const unsigned int level = (this->m_Registration->GetAsITKBaseType())->GetCurrentLevel(); /** Set the NumberOfSpatialSamples. */ unsigned long numberOfSpatialSamples = 5000; - this->GetConfiguration()->ReadParameter( - numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); + configuration.ReadParameter(numberOfSpatialSamples, "NumberOfSpatialSamples", this->GetComponentLabel(), level, 0); this->SetNumberOfSamples(numberOfSpatialSamples);