Skip to content

Commit

Permalink
STYLE: Replace T var; var.Fill(x) with auto var = MakeFilled<T>(x)
Browse files Browse the repository at this point in the history
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*)[ ]+(\w+);[\r\n]+\1\3\.Fill\(
    Replace with: $1auto $3 = MakeFilled<$2>\(
    Filters: itk*.h;itk*.hxx;itk*.cxx
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Excluded "itkVectorMeanImageFunction.hxx", because it may try to fill a
`VariableLengthVector` (which is not supported by `MakeFilled`).

Follow-up to pull request InsightSoftwareConsortium#4891
commit d6c9eed
"STYLE: Replace Fill calls with `auto var = itk::MakeFilled<T>` in tests"
  • Loading branch information
N-Dekker authored and dzenanz committed Nov 4, 2024
1 parent d516e70 commit 6cb6bf9
Show file tree
Hide file tree
Showing 47 changed files with 83 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ ShapedFloodFilledFunctionConditionalConstIterator<TImage, TFunction>::Initialize
m_ImageRegion = this->m_Image->GetBufferedRegion();

// Build and setup the neighborhood iterator
typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType tmp_iter(radius, this->m_Image, m_ImageRegion);
m_NeighborhoodIterator = tmp_iter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ ContourSpatialObject<TDimension>::Update()
// "`ContourSpatialObject<TDimension>::Update()` LINEAR_INTERPOLATION case may need some adjustment"
// https://github.com/InsightSoftwareConsortium/ITK/issues/3222

PointType newPoint;
newPoint.Fill(NumericTraits<double>::max());
auto newPoint = MakeFilled<PointType>(NumericTraits<double>::max());
for (unsigned int i = 0; i < m_InterpolationFactor; ++i)
{
for (unsigned int d = 0; d < TDimension; ++d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ TubeSpatialObjectPoint<TPointDimension>::GetRadiusInWorldSpace() const
itkExceptionMacro("The SpatialObject must be set prior to calling.");
}

CovariantVectorType cVect;
cVect.Fill(m_RadiusInObjectSpace);
auto cVect = MakeFilled<CovariantVectorType>(m_RadiusInObjectSpace);
cVect = Superclass::m_SpatialObject->GetObjectToWorldTransform()->TransformCovariantVector(cVect);
double worldR = 0;
for (unsigned int d = 0; d < TPointDimension; ++d)
Expand All @@ -72,8 +71,7 @@ TubeSpatialObjectPoint<TPointDimension>::SetRadiusInWorldSpace(double newR)
itkExceptionMacro("The SpatialObject must be set prior to calling.");
}

CovariantVectorType cVect;
cVect.Fill(newR);
auto cVect = MakeFilled<CovariantVectorType>(newR);
cVect =
Superclass::m_SpatialObject->GetObjectToWorldTransform()->GetInverseTransform()->TransformCovariantVector(cVect);
m_RadiusInObjectSpace = 0;
Expand Down
5 changes: 2 additions & 3 deletions Modules/Core/Transform/include/itkBSplineTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ BSplineTransform<TParametersValueType, VDimension, VSplineOrder>::BSplineTransfo
// dir[0][2],dir[1][2],dir[2][2]]


OriginType meshOrigin{};
PhysicalDimensionsType meshPhysical;
meshPhysical.Fill(1.0);
OriginType meshOrigin{};
auto meshPhysical = MakeFilled<PhysicalDimensionsType>(1.0);

DirectionType meshDirection;
meshDirection.SetIdentity();
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Transform/include/itkScaleTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ void
ScaleTransform<TParametersValueType, VDimension>::SetIdentity()
{
Superclass::SetIdentity();
ScaleType i;
i.Fill(1.0);
auto i = MakeFilled<ScaleType>(1.0);
this->SetScale(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ class ITK_TEMPLATE_EXPORT N4BiasFieldCorrectionImageFilter : public ImageToImage
void
SetNumberOfFittingLevels(unsigned int n)
{
ArrayType nlevels;

nlevels.Fill(n);
auto nlevels = MakeFilled<ArrayType>(n);
this->SetNumberOfFittingLevels(nlevels);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ N4BiasFieldCorrectionImageFilter<TInputImage, TMaskImage, TOutputImage>::Generat
reconstructer->SetSplineOrder(this->m_SplineOrder);
reconstructer->Update();

typename BSplineReconstructerType::ArrayType numberOfLevels;
numberOfLevels.Fill(1);
auto numberOfLevels = MakeFilled<typename BSplineReconstructerType::ArrayType>(1);
for (unsigned int d = 0; d < ImageDimension; ++d)
{
if (this->m_NumberOfFittingLevels[d] + 1 >= this->m_CurrentLevel &&
Expand Down Expand Up @@ -546,8 +545,7 @@ N4BiasFieldCorrectionImageFilter<TInputImage, TMaskImage, TOutputImage>::UpdateB
auto bspliner = BSplineFilterType::New();

typename BSplineFilterType::ArrayType numberOfControlPoints;
typename BSplineFilterType::ArrayType numberOfFittingLevels;
numberOfFittingLevels.Fill(1);
auto numberOfFittingLevels = MakeFilled<typename BSplineFilterType::ArrayType>(1);
for (unsigned int d = 0; d < ImageDimension; ++d)
{
if (!this->m_LogBiasFieldControlPointLattice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ BinaryPruningImageFilter<TInputImage, TOutputImage>::ComputePruneImage()

typename OutputImageType::RegionType region = pruneImage->GetRequestedRegion();

typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
NeighborhoodIteratorType ot(radius, pruneImage, region);

typename NeighborhoodIteratorType::OffsetType offset1 = { { -1, -1 } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ BinaryThinningImageFilter<TInputImage, TOutputImage>::ComputeThinImage()

typename OutputImageType::RegionType region = thinImage->GetRequestedRegion();

typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
NeighborhoodIteratorType ot(radius, thinImage, region);

// Create a set of offsets from the center.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ ObjectMorphologyImageFilter<TInputImage, TOutputImage, TKernel>::DynamicThreaded
// Setup the kernel that spans the immediate neighbors of the current
// input pixel - used to determine if that pixel abuts a non-object
// pixel, i.e., is a boundary pixel
RadiusType bKernelSize;
bKernelSize.Fill(1);
auto bKernelSize = MakeFilled<RadiusType>(1);

TotalProgressReporter progress(this, this->GetOutput()->GetRequestedRegion().GetNumberOfPixels());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ ConvolutionImageFilter<TInputImage, TKernelImage, TOutputImage>::ComputeConvolut

// Flip the kernel
using FlipperType = FlipImageFilter<TImage>;
auto flipper = FlipperType::New();
typename FlipperType::FlipAxesArrayType axesArray;
axesArray.Fill(true);
auto flipper = FlipperType::New();
auto axesArray = MakeFilled<typename FlipperType::FlipAxesArrayType>(true);
flipper->SetFlipAxes(axesArray);
flipper->SetInput(kernelImage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ MaskedFFTNormalizedCorrelationImageFilter<TInputImage, TOutputImage, TMaskImage>

// Flip the moving images along all dimensions so that the correlation can be more easily handled.
using FlipperType = itk::FlipImageFilter<LocalInputImageType>;
typename FlipperType::FlipAxesArrayType flipAxes;
flipAxes.Fill(true);
auto flipAxes = MakeFilled<typename FlipperType::FlipAxesArrayType>(true);
auto rotater = FlipperType::New();
rotater->SetFlipAxes(flipAxes);
rotater->SetInput(inputImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ PatchBasedDenoisingBaseImageFilter<TInputImage, TOutputImage>::GetPatchRadiusInV
maxSpacing = spacing[dim];
}
}
PatchRadiusType radius;
radius.Fill(m_PatchRadius);
auto radius = MakeFilled<PatchRadiusType>(m_PatchRadius);
for (unsigned int dim = 0; dim < ImageDimension; ++dim)
{
radius[dim] = itk::Math::ceil(maxSpacing * radius[dim] / spacing[dim]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ PatchBasedDenoisingImageFilter<TInputImage, TOutputImage>::Initialize()
typename InputImageType::IndexType requiredIndex{};
const typename InputImageType::RegionType largestRegion = this->GetInput()->GetLargestPossibleRegion();
const PatchRadiusType radius = this->GetPatchRadiusInVoxels();
PatchRadiusType two;
two.Fill(2);
auto two = MakeFilled<PatchRadiusType>(2);
requiredIndex += two * radius;

if (!(largestRegion.IsInside(requiredIndex)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ class ITK_TEMPLATE_EXPORT DisplacementFieldToBSplineImageFilter : public ImageTo
void
SetNumberOfFittingLevels(unsigned int n)
{
ArrayType nlevels;

nlevels.Fill(n);
auto nlevels = MakeFilled<ArrayType>(n);
this->SetNumberOfFittingLevels(nlevels);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ DisplacementFieldToBSplineImageFilter<TInputImage, TInputPointSet, TOutputImage>

itkDebugMacro("Calculating the B-spline displacement field. ");

ArrayType close;
close.Fill(false);
auto close = MakeFilled<ArrayType>(false);

auto bspliner = BSplineFilterType::New();
bspliner->SetOrigin(this->m_BSplineDomainOrigin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ FastMarchingImageFilter<TLevelSet, TSpeedImage>::Initialize(LevelSetImageType *
m_BufferedRegion = output->GetBufferedRegion();
m_StartIndex = m_BufferedRegion.GetIndex();
m_LastIndex = m_StartIndex + m_BufferedRegion.GetSize();
typename LevelSetImageType::OffsetType offset;
offset.Fill(1);
auto offset = MakeFilled<typename LevelSetImageType::OffsetType>(1);
m_LastIndex -= offset;

// allocate memory for the PointTypeImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ FastMarchingImageFilterBase<TInput, TOutput>::CheckTopology(OutputImageType * oI
if (strictTopologyViolation)
{
// Check for handles
typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
NeighborhoodIteratorType ItL(radius, this->m_LabelImage, this->m_LabelImage->GetBufferedRegion());
ItL.SetLocation(iNode);

Expand Down Expand Up @@ -437,8 +436,7 @@ FastMarchingImageFilterBase<TInput, TOutput>::InitializeOutput(OutputImageType *
m_OutputOrigin = oImage->GetOrigin();
m_OutputDirection = oImage->GetDirection();

typename OutputImageType::OffsetType offset;
offset.Fill(1);
auto offset = MakeFilled<typename OutputImageType::OffsetType>(1);
m_LastIndex -= offset;

// Checking for handles only requires an image to keep track of
Expand Down Expand Up @@ -610,8 +608,7 @@ template <typename TInput, typename TOutput>
bool
FastMarchingImageFilterBase<TInput, TOutput>::DoesVoxelChangeViolateStrictTopology(const NodeType & idx) const
{
typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType It(radius, this->m_LabelImage, this->m_LabelImage->GetBufferedRegion());
It.SetLocation(idx);
Expand Down Expand Up @@ -647,8 +644,7 @@ template <typename TInput, typename TOutput>
bool
FastMarchingImageFilterBase<TInput, TOutput>::IsChangeWellComposed2D(const NodeType & idx) const
{
NeighborhoodRadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<NeighborhoodRadiusType>(1);

NeighborhoodIteratorType It(radius, this->m_LabelImage, this->m_LabelImage->GetBufferedRegion());
It.SetLocation(idx);
Expand Down Expand Up @@ -808,8 +804,7 @@ FastMarchingImageFilterBase<TInput, TOutput>::IsChangeWellComposed3D(const NodeT
{
std::bitset<8> neighborhoodPixels;

NeighborhoodRadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<NeighborhoodRadiusType>(1);

NeighborhoodIteratorType It(radius, this->m_LabelImage, this->m_LabelImage->GetRequestedRegion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ CannyEdgeDetectionImageFilter<TInputImage, TOutputImage>::CannyEdgeDetectionImag
m_UpdateBuffer1 = OutputImageType::New();

// Set up neighborhood slices for all the dimensions.
typename Neighborhood<OutputImagePixelType, ImageDimension>::RadiusType r;
r.Fill(1);
auto r = MakeFilled<typename Neighborhood<OutputImagePixelType, ImageDimension>::RadiusType>(1);

// Dummy neighborhood used to set up the slices
Neighborhood<OutputImagePixelType, ImageDimension> it;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,21 @@ class ITK_TEMPLATE_EXPORT DiscreteGaussianDerivativeImageFilter : public ImageTo
void
SetOrder(const typename OrderArrayType::ValueType v)
{
OrderArrayType a;

a.Fill(v);
auto a = MakeFilled<OrderArrayType>(v);
this->SetOrder(a);
}

void
SetVariance(const typename ArrayType::ValueType v)
{
ArrayType a;

a.Fill(v);
auto a = MakeFilled<ArrayType>(v);
this->SetVariance(a);
}

void
SetMaximumError(const typename ArrayType::ValueType v)
{
ArrayType a;

a.Fill(v);
auto a = MakeFilled<ArrayType>(v);
this->SetMaximumError(a);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class ITK_TEMPLATE_EXPORT UnsharpMaskImageFilter : public ImageToImageFilter<TIn
void
SetSigma(const typename SigmaArrayType::ValueType sigma)
{
SigmaArrayType sigmas;
sigmas.Fill(sigma);
auto sigmas = MakeFilled<SigmaArrayType>(sigma);
this->SetSigmas(sigmas); // checks whether it is actually modified
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ template <typename TInputImage, typename TOutputImage>
void
BoxImageFilter<TInputImage, TOutputImage>::SetRadius(const RadiusValueType & radius)
{
RadiusType rad;

rad.Fill(radius);
auto rad = MakeFilled<RadiusType>(radius);
this->SetRadius(rad);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ MovingHistogramImageFilter<TInputImage, TOutputImage, TKernel, THistogram>::Dyna
}

// now move the histogram
FixedArray<short, ImageDimension> direction;
direction.Fill(1);
auto direction = MakeFilled<FixedArray<short, ImageDimension>>(1);
int axis = ImageDimension - 1;
OffsetType offset{};
RegionType stRegion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ VectorGradientMagnitudeImageFilter<TInputImage, TRealType, TOutputImage>::Genera
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();

RadiusType r1;
r1.Fill(1);
auto r1 = MakeFilled<RadiusType>(1);
// pad the input requested region by the operator radius
inputRequestedRegion.PadByRadius(r1);

Expand Down Expand Up @@ -197,8 +196,7 @@ VectorGradientMagnitudeImageFilter<TInputImage, TRealType, TOutputImage>::Dynami

// Find the data-set boundary "faces"
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<RealVectorImageType> bC;
RadiusType r1;
r1.Fill(1);
auto r1 = MakeFilled<RadiusType>(1);
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<RealVectorImageType>::FaceListType faceList =
bC(m_RealValuedInputImage.GetPointer(), outputRegionForThread, r1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ BSplineControlPointImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenera
}
}
FixedArray<RealType, ImageDimension> U;
FixedArray<RealType, ImageDimension> currentU;
currentU.Fill(-1);
auto currentU = MakeFilled<FixedArray<RealType, ImageDimension>>(-1);

typename OutputImageType::IndexType startIndex = outputPtr->GetRequestedRegion().GetIndex();
typename PointDataImageType::IndexType startPhiIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,7 @@ BSplineScatteredDataPointSetToImageFilter<TInputPointSet, TOutputImage>::Threade
}

FixedArray<RealType, ImageDimension> U;
FixedArray<RealType, ImageDimension> currentU;
currentU.Fill(-1);
auto currentU = MakeFilled<FixedArray<RealType, ImageDimension>>(-1);

typename ImageType::IndexType startIndex = this->GetOutput()->GetRequestedRegion().GetIndex();
typename PointDataImageType::IndexType startPhiIndex = this->m_PhiLattice->GetLargestPossibleRegion().GetIndex();
Expand Down Expand Up @@ -921,8 +920,7 @@ BSplineScatteredDataPointSetToImageFilter<TInputPointSet, TOutputImage>::Threade
}

FixedArray<RealType, ImageDimension> U;
FixedArray<RealType, ImageDimension> currentU;
currentU.Fill(-1);
auto currentU = MakeFilled<FixedArray<RealType, ImageDimension>>(-1);

typename PointDataImageType::IndexType startPhiIndex = this->m_PhiLattice->GetLargestPossibleRegion().GetIndex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ PermuteAxesImageFilter<TImage>::SetOrder(const PermuteOrderArrayType & order)

// check that input is a rearrangement of the
// numbers from 0 to ImageDimension - 1
FixedArray<bool, ImageDimension> used;
used.Fill(false);
auto used = MakeFilled<FixedArray<bool, ImageDimension>>(false);

for (j = 0; j < ImageDimension; ++j)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class ITK_TEMPLATE_EXPORT BinaryCrossStructuringElement : public Neighborhood<TP
BinaryCrossStructuringElement()
{
// Default structuring element is defined to be 3x3x3...
RadiusType radius;
radius.Fill(1);
auto radius = MakeFilled<RadiusType>(1);
Self::SetRadius(radius);
Self::CreateStructuringElement();
}
Expand Down
Loading

0 comments on commit 6cb6bf9

Please sign in to comment.