Skip to content

Commit

Permalink
STYLE: Add constexpr to variables initialized by MakeFilled
Browse files Browse the repository at this point in the history
Suggests evaluating its value at compile-time, rather than at runtime.

Found by regular expressions:

    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(-?\d+\);)
    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(\d.0\);)
    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(false\);)
    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(true\);)

Inspired by a comment by Hans Johnson at
InsightSoftwareConsortium#4924 (comment)
  • Loading branch information
N-Dekker committed Nov 4, 2024
1 parent dae9bef commit 12251ef
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ShapedFloodFilledFunctionConditionalConstIterator<TImage, TFunction>::Initialize
m_ImageRegion = this->m_Image->GetBufferedRegion();

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

NeighborhoodIteratorType tmp_iter(radius, this->m_Image, m_ImageRegion);
m_NeighborhoodIterator = tmp_iter;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Transform/include/itkScaleTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void
ScaleTransform<TParametersValueType, VDimension>::SetIdentity()
{
Superclass::SetIdentity();
auto i = MakeFilled<ScaleType>(1.0);
constexpr auto i = MakeFilled<ScaleType>(1.0);
this->SetScale(i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +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
auto bKernelSize = MakeFilled<RadiusType>(1);
constexpr 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,8 +95,8 @@ ConvolutionImageFilter<TInputImage, TKernelImage, TOutputImage>::ComputeConvolut

// Flip the kernel
using FlipperType = FlipImageFilter<TImage>;
auto flipper = FlipperType::New();
auto axesArray = MakeFilled<typename FlipperType::FlipAxesArrayType>(true);
auto flipper = FlipperType::New();
constexpr 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,8 @@ 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>;
auto flipAxes = MakeFilled<typename FlipperType::FlipAxesArrayType>(true);
auto rotater = FlipperType::New();
constexpr auto flipAxes = MakeFilled<typename FlipperType::FlipAxesArrayType>(true);
auto rotater = FlipperType::New();
rotater->SetFlipAxes(flipAxes);
rotater->SetInput(inputImage);
rotater->Update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ DisplacementFieldToBSplineImageFilter<TInputImage, TInputPointSet, TOutputImage>

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

auto close = MakeFilled<ArrayType>(false);
constexpr 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,7 +127,7 @@ FastMarchingImageFilter<TLevelSet, TSpeedImage>::Initialize(LevelSetImageType *
m_BufferedRegion = output->GetBufferedRegion();
m_StartIndex = m_BufferedRegion.GetIndex();
m_LastIndex = m_StartIndex + m_BufferedRegion.GetSize();
auto offset = MakeFilled<typename LevelSetImageType::OffsetType>(1);
constexpr 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 @@ -436,7 +436,7 @@ FastMarchingImageFilterBase<TInput, TOutput>::InitializeOutput(OutputImageType *
m_OutputOrigin = oImage->GetOrigin();
m_OutputDirection = oImage->GetDirection();

auto offset = MakeFilled<typename OutputImageType::OffsetType>(1);
constexpr 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 @@ -608,7 +608,7 @@ template <typename TInput, typename TOutput>
bool
FastMarchingImageFilterBase<TInput, TOutput>::DoesVoxelChangeViolateStrictTopology(const NodeType & idx) const
{
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

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

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

auto radius = MakeFilled<NeighborhoodRadiusType>(1);
constexpr 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,7 +42,7 @@ CannyEdgeDetectionImageFilter<TInputImage, TOutputImage>::CannyEdgeDetectionImag
m_UpdateBuffer1 = OutputImageType::New();

// Set up neighborhood slices for all the dimensions.
auto r = MakeFilled<typename Neighborhood<OutputImagePixelType, ImageDimension>::RadiusType>(1);
constexpr 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 @@ -102,7 +102,7 @@ VectorGradientMagnitudeImageFilter<TInputImage, TRealType, TOutputImage>::Genera
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();

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

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

m_DifferenceFunctions.resize(m_FunctionCount, nullptr);

auto radius = MakeFilled<RadiusType>(1);
constexpr auto radius = MakeFilled<RadiusType>(1);

for (unsigned int i = 0; i < this->m_FunctionCount; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ template <typename TImage>
void
ScalarImageToCooccurrenceListSampleFilter<TImage>::GenerateData()
{
auto radius = MakeFilled<typename ShapedNeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename ShapedNeighborhoodIteratorType::RadiusType>(1);

using FaceCalculatorType = itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<ImageType>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ ImageRegistrationMethodv4<TFixedImage, TMovingImage, TTransform, TVirtualImage,

for (SizeValueType level = 0; level < this->m_NumberOfLevels; ++level)
{
auto shrinkFactors = MakeFilled<ShrinkFactorsPerDimensionContainerType>(1);
constexpr auto shrinkFactors = MakeFilled<ShrinkFactorsPerDimensionContainerType>(1);
this->SetShrinkFactorsPerDimension(level, shrinkFactors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class ITK_TEMPLATE_EXPORT SegmentationLevelSetImageFilter
{
m_SegmentationFunction = s;

auto r = MakeFilled<typename SegmentationFunctionType::RadiusType>(1);
constexpr auto r = MakeFilled<typename SegmentationFunctionType::RadiusType>(1);

m_SegmentationFunction->Initialize(r);
this->SetDifferenceFunction(m_SegmentationFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ BinaryImageToLevelSetImageAdaptor<TInput, WhitakerSparseLevelSetImage<TOutput, T
LevelSetLayerType & layerPlus2 = this->m_LevelSet->GetLayer(outputLayer);
const auto plus2 = static_cast<LevelSetOutputType>(outputLayer);

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

ZeroFluxNeumannBoundaryCondition<InternalImageType> im_nbc;

Expand Down Expand Up @@ -197,7 +197,7 @@ BinaryImageToLevelSetImageAdaptor<TInput,

LevelSetLayerType & layer0 = this->m_LevelSet->GetLayer(LevelSetType::ZeroLayer());

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

ZeroFluxNeumannBoundaryCondition<InternalImageType> im_nbc;

Expand Down Expand Up @@ -260,7 +260,7 @@ BinaryImageToLevelSetImageAdaptor<TInput, WhitakerSparseLevelSetImage<TOutput, T
LevelSetLayerType & layerMinus1 = this->m_LevelSet->GetLayer(LevelSetType::MinusOneLayer());
LevelSetLayerType & layerPlus1 = this->m_LevelSet->GetLayer(LevelSetType::PlusOneLayer());

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

ZeroFluxNeumannBoundaryCondition<InternalImageType> im_nbc;

Expand Down Expand Up @@ -399,7 +399,7 @@ BinaryImageToLevelSetImageAdaptor<TInput, ShiSparseLevelSetImage<TInput::ImageDi
LevelSetLayerType & layerMinus1 = this->m_LevelSet->GetLayer(LevelSetType::MinusOneLayer());
LevelSetLayerType & layerPlus1 = this->m_LevelSet->GetLayer(LevelSetType::PlusOneLayer());

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

ZeroFluxNeumannBoundaryCondition<InternalImageType> im_nbc;

Expand Down Expand Up @@ -541,7 +541,7 @@ BinaryImageToLevelSetImageAdaptor<TInput, MalcolmSparseLevelSetImage<TInput::Ima

LevelSetLayerType & layer = this->m_LevelSet->GetLayer(LevelSetType::ZeroLayer());

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

ZeroFluxNeumannBoundaryCondition<InternalImageType> im_nbc;

Expand Down Expand Up @@ -603,7 +603,7 @@ BinaryImageToLevelSetImageAdaptor<TInput, MalcolmSparseLevelSetImage<TInput::Ima

ZeroFluxNeumannBoundaryCondition<InternalImageType> sp_nbc;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ UpdateMalcolmSparseLevelSet<VDimension, TEquationContainer>::EvolveWithUnPhasedP
// neighborhood iterator
ZeroFluxNeumannBoundaryCondition<LabelImageType> sp_nbc;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -258,7 +258,7 @@ UpdateMalcolmSparseLevelSet<VDimension, TEquationContainer>::EvolveWithPhasedPro

ZeroFluxNeumannBoundaryCondition<LabelImageType> sp_nbc;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -352,7 +352,7 @@ UpdateMalcolmSparseLevelSet<VDimension, TEquationContainer>::CompactLayersToSing

ZeroFluxNeumannBoundaryCondition<LabelImageType> sp_nbc;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ UpdateShiSparseLevelSet<VDimension, TEquationContainer>::Update()
// neighborhood iterator
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -184,7 +184,7 @@ UpdateShiSparseLevelSet<VDimension, TEquationContainer>::UpdateLayerPlusOne()

ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -283,7 +283,7 @@ UpdateShiSparseLevelSet<VDimension, TEquationContainer>::UpdateLayerMinusOne()

ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -379,7 +379,7 @@ UpdateShiSparseLevelSet<VDimension, TEquationContainer>::Con(const LevelSetInput

ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>
/** todo: put neighborhood creation in protected method */
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -194,7 +194,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>

ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -355,7 +355,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>

ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -460,7 +460,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>
{
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -565,7 +565,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>
{
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -669,7 +669,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>
{
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -796,7 +796,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>
{
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down Expand Up @@ -853,7 +853,7 @@ UpdateWhitakerSparseLevelSet<VDimension, TLevelSetValueType, TEquationContainer>
{
ZeroFluxNeumannBoundaryCondition<LabelImageType> spNBC;

auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);

NeighborhoodIteratorType neighIt(radius, this->m_InternalImage, this->m_InternalImage->GetLargestPossibleRegion());

Expand Down

0 comments on commit 12251ef

Please sign in to comment.