Skip to content

Commit

Permalink
STYLE: Replace elastix::Deref with ITK 5.4 itk::Deref
Browse files Browse the repository at this point in the history
Following ITK pull request InsightSoftwareConsortium/ITK#4278 commit InsightSoftwareConsortium/ITK@042d423 "ENH: Add `Deref(T *)`, to ease dereferencing a pointer safely".
  • Loading branch information
N-Dekker committed Jun 10, 2024
1 parent f03cef1 commit 995f471
Show file tree
Hide file tree
Showing 40 changed files with 145 additions and 185 deletions.
8 changes: 4 additions & 4 deletions Common/ImageSamplers/itkImageFullSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "itkImageFullSampler.h"

#include "itkImageRegionConstIteratorWithIndex.h"
#include "elxDeref.h"
#include <itkDeref.h>

#include <algorithm> // For copy_n and min.
#include <cassert>
Expand Down Expand Up @@ -155,8 +155,8 @@ void
ImageFullSampler<TInputImage>::GenerateData()
{
/** Get handles to the input image, output sample container, and the mask. */
const InputImageType & inputImage = elastix::Deref(this->GetInput());
ImageSampleContainerType & sampleContainer = elastix::Deref(this->GetOutput());
const InputImageType & inputImage = Deref(this->GetInput());
ImageSampleContainerType & sampleContainer = Deref(this->GetOutput());
const MaskType * const mask = this->Superclass::GetMask();

if (mask)
Expand All @@ -173,7 +173,7 @@ ImageFullSampler<TInputImage>::GenerateData()

if (Superclass::m_UseMultiThread)
{
MultiThreadedGenerateData(elastix::Deref(this->ProcessObject::GetMultiThreader()),
MultiThreadedGenerateData(Deref(this->ProcessObject::GetMultiThreader()),
ProcessObject::GetNumberOfWorkUnits(),
inputImage,
mask,
Expand Down
8 changes: 4 additions & 4 deletions Common/ImageSamplers/itkImageGridSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "itkImageGridSampler.h"

#include "itkImageRegionConstIteratorWithIndex.h"
#include "elxDeref.h"
#include <itkDeref.h>

#include <algorithm> // For accumulate.
#include <cassert>
Expand Down Expand Up @@ -258,8 +258,8 @@ void
ImageGridSampler<TInputImage>::GenerateData()
{
/** Get handles to the input image, output sample container, and the mask. */
const InputImageType & inputImage = elastix::Deref(this->GetInput());
ImageSampleContainerType & sampleContainer = elastix::Deref(this->GetOutput());
const InputImageType & inputImage = Deref(this->GetInput());
ImageSampleContainerType & sampleContainer = Deref(this->GetOutput());
const MaskType * const mask = this->Superclass::GetMask();

if (mask)
Expand All @@ -279,7 +279,7 @@ ImageGridSampler<TInputImage>::GenerateData()

if (Superclass::m_UseMultiThread)
{
MultiThreadedGenerateData(elastix::Deref(this->ProcessObject::GetMultiThreader()),
MultiThreadedGenerateData(Deref(this->ProcessObject::GetMultiThreader()),
ProcessObject::GetNumberOfWorkUnits(),
inputImage,
mask,
Expand Down
9 changes: 4 additions & 5 deletions Common/ImageSamplers/itkImageRandomCoordinateSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define itkImageRandomCoordinateSampler_hxx

#include "itkImageRandomCoordinateSampler.h"
#include "elxDeref.h"
#include <itkDeref.h>
#include <vnl/vnl_math.h>
#include <cassert>

Expand All @@ -35,8 +35,8 @@ void
ImageRandomCoordinateSampler<TInputImage>::GenerateData()
{
/** Get handles to the input image, output sample container, and interpolator. */
const InputImageType & inputImage = elastix::Deref(this->GetInput());
auto & samples = elastix::Deref(this->GetOutput()).CastToSTLContainer();
const InputImageType & inputImage = Deref(this->GetInput());
auto & samples = Deref(this->GetOutput()).CastToSTLContainer();
typename InterpolatorType::Pointer interpolator = this->GetModifiableInterpolator();

/** Set up the interpolator. */
Expand Down Expand Up @@ -75,8 +75,7 @@ ImageRandomCoordinateSampler<TInputImage>::GenerateData()

UserData userData{ m_RandomCoordinates, inputImage, *interpolator, samples };

elastix::Deref(this->ProcessObject::GetMultiThreader())
.SetSingleMethodAndExecute(&Self::ThreaderCallback, &userData);
Deref(this->ProcessObject::GetMultiThreader()).SetSingleMethodAndExecute(&Self::ThreaderCallback, &userData);
return;
}

Expand Down
9 changes: 4 additions & 5 deletions Common/ImageSamplers/itkImageRandomSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "itkMersenneTwisterRandomVariateGenerator.h"
#include "itkImageRandomConstIteratorWithIndex.h"
#include "elxDeref.h"
#include <itkDeref.h>
#include <cassert>

namespace itk
Expand All @@ -37,8 +37,8 @@ void
ImageRandomSampler<TInputImage>::GenerateData()
{
/** Get handles to the input image, output sample container. */
const InputImageType & inputImage = elastix::Deref(this->GetInput());
auto & samples = elastix::Deref(this->GetOutput()).CastToSTLContainer();
const InputImageType & inputImage = Deref(this->GetInput());
auto & samples = Deref(this->GetOutput()).CastToSTLContainer();

/** Get a handle to the mask. If there was no mask supplied we exercise a multi-threaded version. */
const MaskType * const mask = this->Superclass::GetMask();
Expand All @@ -53,8 +53,7 @@ ImageRandomSampler<TInputImage>::GenerateData()
randomNumberList, inputImage, croppedInputImageRegion.GetIndex(), croppedInputImageRegion.GetSize(), samples
};

elastix::Deref(this->ProcessObject::GetMultiThreader())
.SetSingleMethodAndExecute(&Self::ThreaderCallback, &userData);
Deref(this->ProcessObject::GetMultiThreader()).SetSingleMethodAndExecute(&Self::ThreaderCallback, &userData);
return;
}

Expand Down
11 changes: 5 additions & 6 deletions Common/ImageSamplers/itkImageRandomSamplerSparseMask.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define itkImageRandomSamplerSparseMask_hxx

#include "itkImageRandomSamplerSparseMask.h"
#include "elxDeref.h"
#include <itkDeref.h>
#include <cassert>

namespace itk
Expand All @@ -45,8 +45,8 @@ ImageRandomSamplerSparseMask<TInputImage>::GenerateData()
}

/** Get handles to the input image and output sample container. */
const InputImageType & inputImage = elastix::Deref(this->GetInput());
ImageSampleContainerType & sampleContainer = elastix::Deref(this->GetOutput());
const InputImageType & inputImage = Deref(this->GetInput());
ImageSampleContainerType & sampleContainer = Deref(this->GetOutput());

// Take capacity from the output container, and clear it.
std::vector<ImageSampleType> sampleVector;
Expand All @@ -72,7 +72,7 @@ ImageRandomSamplerSparseMask<TInputImage>::GenerateData()
}

/** Get a handle to the full sampler output. */
const ImageSampleContainerType & allValidSamples = elastix::Deref(this->m_InternalFullSampler->GetOutput());
const ImageSampleContainerType & allValidSamples = Deref(this->m_InternalFullSampler->GetOutput());
unsigned long numberOfValidSamples = allValidSamples.Size();


Expand All @@ -92,8 +92,7 @@ ImageRandomSamplerSparseMask<TInputImage>::GenerateData()

UserData userData{ allValidSamples.CastToSTLConstContainer(), m_RandomIndices, samples };

elastix::Deref(this->ProcessObject::GetMultiThreader())
.SetSingleMethodAndExecute(&Self::ThreaderCallback, &userData);
Deref(this->ProcessObject::GetMultiThreader()).SetSingleMethodAndExecute(&Self::ThreaderCallback, &userData);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Common/ImageSamplers/itkImageSamplerBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define itkImageSamplerBase_hxx

#include "itkImageSamplerBase.h"
#include "elxDeref.h"
#include <itkDeref.h>
#include <itkMultiThreaderBase.h>
#include <cassert>
#include <numeric> // For accumulate.
Expand Down Expand Up @@ -170,7 +170,7 @@ ImageSamplerBase<TInputImage>::GenerateInputRequestedRegion()
}

/** Get a non-const reference to the input image. */
auto & inputImage = const_cast<InputImageType &>(elastix::Deref(this->GetInput()));
auto & inputImage = const_cast<InputImageType &>(Deref(this->GetInput()));

/** Get and set the region. */
if (this->GetInputImageRegion().GetNumberOfPixels() != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "itkMultiInputImageRandomCoordinateSampler.h"
#include <vnl/vnl_inverse.h>
#include "itkConfigure.h"
#include "elxDeref.h"
#include <itkDeref.h>

namespace itk
{
Expand All @@ -41,8 +41,8 @@ MultiInputImageRandomCoordinateSampler<TInputImage>::GenerateData()
}

/** Get handles to the input image, output sample container, and mask. */
const InputImageType & inputImage = elastix::Deref(this->GetInput());
auto & samples = elastix::Deref(this->GetOutput()).CastToSTLContainer();
const InputImageType & inputImage = Deref(this->GetInput());
auto & samples = Deref(this->GetOutput()).CastToSTLContainer();
const MaskType * const mask = this->Superclass::GetMask();
typename InterpolatorType::Pointer interpolator = this->GetModifiableInterpolator();

Expand Down
39 changes: 0 additions & 39 deletions Common/elxDeref.h

This file was deleted.

4 changes: 2 additions & 2 deletions Common/elxMaskHasSameImageDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <itkImageBase.h>
#include <itkImageMaskSpatialObject.h>
#include "elxDeref.h"
#include <itkDeref.h>

namespace elastix
{
Expand All @@ -40,7 +40,7 @@ bool
MaskHasSameImageDomain(const itk::ImageMaskSpatialObject<VImageDimension> & mask,
const itk::ImageBase<VImageDimension> & inputImage)
{
const auto & maskImage = Deref(mask.GetImage());
const auto & maskImage = itk::Deref(mask.GetImage());
return maskImage.GetLargestPossibleRegion() == inputImage.GetLargestPossibleRegion() &&
maskImage.GetOrigin() == inputImage.GetOrigin() && maskImage.GetSpacing() == inputImage.GetSpacing() &&
maskImage.GetDirection() == inputImage.GetDirection();
Expand Down
4 changes: 2 additions & 2 deletions Components/ImageSamplers/Grid/elxGridSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define elxGridSampler_hxx

#include "elxGridSampler.h"
#include "elxDeref.h"
#include <itkDeref.h>

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define elxMultiInputRandomCoordinateSampler_hxx

#include "elxMultiInputRandomCoordinateSampler.h"
#include "elxDeref.h"
#include <itkDeref.h>

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

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

Expand Down
4 changes: 2 additions & 2 deletions Components/ImageSamplers/Random/elxRandomSampler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define elxRandomSampler_hxx

#include "elxRandomSampler.h"
#include "elxDeref.h"
#include <itkDeref.h>

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

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

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

#include "elxRandomCoordinateSampler.h"
#include "elxDeref.h"
#include <itkDeref.h>
#include "itkLinearInterpolateImageFunction.h"

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define elxRandomSamplerSparseMask_hxx

#include "elxRandomSamplerSparseMask.h"
#include "elxDeref.h"
#include <itkDeref.h>

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ template <class TElastix>
void
AdvancedNormalizedCorrelationMetric<TElastix>::BeforeEachResolution()
{
const Configuration & configuration = Deref(Superclass2::GetConfiguration());
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

if (configuration.HasParameter("SubtractMean"))
{
Expand Down
8 changes: 4 additions & 4 deletions Components/Optimizers/AdaGrad/elxAdaGrad.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define elxAdaGrad_hxx

#include "elxAdaGrad.h"
#include "elxDeref.h"
#include <itkDeref.h>

#include <cmath> // For abs.
#include <iomanip>
Expand Down Expand Up @@ -113,7 +113,7 @@ AdaGrad<TElastix>::BeforeEachResolution()

const unsigned int P = this->GetElastix()->GetElxTransformBase()->GetAsITKBaseType()->GetNumberOfParameters();

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

/** Set the maximumNumberOfIterations. */
SizeValueType maximumNumberOfIterations = 500;
Expand Down Expand Up @@ -578,7 +578,7 @@ AdaGrad<TElastix>::AutomaticPreconditionerEstimation()
preconditionerEstimator->SetConditionNumber( this->m_ConditionNumber );
preconditionerEstimator->SetUseScales( false ); // Make sure scales are not used
#endif
const Configuration & configuration = Deref(Superclass2::GetConfiguration());
const Configuration & configuration = itk::Deref(Superclass2::GetConfiguration());

/** Construct the preconditioner and initialize. */
this->m_PreconditionVector = ParametersType(P);
Expand Down Expand Up @@ -780,7 +780,7 @@ AdaGrad<TElastix>::SampleGradients(const ParametersType & mu0, double perturbati

} // end if NewSamplesEveryIteration.

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

/** Prepare for progress printing. */
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
Expand Down
Loading

0 comments on commit 995f471

Please sign in to comment.