Skip to content

Commit

Permalink
ENH: Add local const Configuration & variables to ImageSamplers
Browse files Browse the repository at this point in the history
Follow-up to pull request #830 commit bfc2ee8 "ENH: Add local `const Configuration &` variables to Optimizers"
  • Loading branch information
N-Dekker committed Nov 14, 2023
1 parent 2c44c33 commit e205d1d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
5 changes: 4 additions & 1 deletion Components/ImageSamplers/Grid/elxGridSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define elxGridSampler_hxx

#include "elxGridSampler.h"
#include "elxDeref.h"

namespace elastix
{
Expand All @@ -32,6 +33,8 @@ template <class TElastix>
void
GridSampler<TElastix>::BeforeEachResolution()
{
const Configuration & configuration = Deref(Superclass2::GetConfiguration());

const unsigned int level = this->m_Registration->GetAsITKBaseType()->GetCurrentLevel();

GridSpacingType gridspacing;
Expand All @@ -41,7 +44,7 @@ GridSampler<TElastix>::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<SampleGridSpacingValueType>(spacing_dim);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define elxMultiInputRandomCoordinateSampler_hxx

#include "elxMultiInputRandomCoordinateSampler.h"
#include "elxDeref.h"

namespace elastix
{
Expand All @@ -32,26 +33,25 @@ template <class TElastix>
void
MultiInputRandomCoordinateSampler<TElastix>::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. */
Expand All @@ -78,7 +78,7 @@ MultiInputRandomCoordinateSampler<TElastix>::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);
Expand Down
6 changes: 4 additions & 2 deletions Components/ImageSamplers/Random/elxRandomSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define elxRandomSampler_hxx

#include "elxRandomSampler.h"
#include "elxDeref.h"

namespace elastix
{
Expand All @@ -31,12 +32,13 @@ template <class TElastix>
void
RandomSampler<TElastix>::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);

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

#include "elxRandomCoordinateSampler.h"
#include "elxDeref.h"
#include "itkLinearInterpolateImageFunction.h"

namespace elastix
Expand All @@ -32,18 +33,18 @@ template <class TElastix>
void
RandomCoordinateSampler<TElastix>::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<InputImageType, CoordRepType>;
Expand All @@ -59,8 +60,7 @@ RandomCoordinateSampler<TElastix>::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. */
Expand All @@ -87,7 +87,7 @@ RandomCoordinateSampler<TElastix>::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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define elxRandomSamplerSparseMask_hxx

#include "elxRandomSamplerSparseMask.h"
#include "elxDeref.h"

namespace elastix
{
Expand All @@ -32,12 +33,13 @@ template <class TElastix>
void
RandomSamplerSparseMask<TElastix>::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);

Expand Down

0 comments on commit e205d1d

Please sign in to comment.