Skip to content

Commit

Permalink
STYLE: Remove p->Initialize() calls directly after p = T::New()
Browse files Browse the repository at this point in the history
For any ITK type `T`, `T::New()` does already initialize the object it returns.

Using Notepad++, Replace in Files, doing:

    Find what:  (\w+)([ ]+= .+::New\(\);\r\n)[\r\n]* [ ]+\1->Initialize\(\);
    Replace with:  $1$2
    Filters: itk*.* !+\test
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually removed an obsolete comment saying `Clear elements`.
  • Loading branch information
N-Dekker committed Nov 21, 2024
1 parent ac021d0 commit 51c7a49
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ BSplineTransformInitializer<TTransform, TImage>::InitializeTransform() const
using CoordRepType = typename ImagePointType::CoordRepType;

using PointSetType = PointSet<CoordRepType, SpaceDimension>;
auto cornerPoints = PointSetType::New();
cornerPoints->Initialize();
auto cornerPoints

using PointType = typename PointSetType::PointType;
using PointType = typename PointSetType::PointType;
using PointIdentifier = typename PointSetType::PointIdentifier;
using RealType = typename PointType::RealType;
using VectorType = typename PointType::VectorType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,12 @@ N4BiasFieldCorrectionImageFilter<TInputImage, TMaskImage, TOutputImage>::UpdateB

const typename ImporterType::OutputImageType * parametricFieldEstimate = importer->GetOutput();

PointSetPointer fieldPoints = PointSetType::New();
fieldPoints->Initialize();
auto & pointSTLContainer = fieldPoints->GetPoints()->CastToSTLContainer();
PointSetPointer fieldPoints auto & pointSTLContainer = fieldPoints->GetPoints()->CastToSTLContainer();
pointSTLContainer.reserve(numberOfIncludedPixels);
auto & pointDataSTLContainer = fieldPoints->GetPointData()->CastToSTLContainer();
pointDataSTLContainer.reserve(numberOfIncludedPixels);

auto weights = BSplineFilterType::WeightsContainerType::New();
weights->Initialize();
auto & weightSTLContainer = weights->CastToSTLContainer();
auto weights auto & weightSTLContainer = weights->CastToSTLContainer();
weightSTLContainer.reserve(numberOfIncludedPixels);

const auto maskImageBufferRange = MakeImageBufferRange(this->GetMaskImage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ DisplacementFieldToBSplineImageFilter<TInputImage, TInputPointSet, TOutputImage>
itkExceptionMacro("The number of input points does not match the number of weight elements.");
}

auto fieldPoints = InputPointSetType::New();
fieldPoints->Initialize();
auto fieldPoints

auto weights = WeightsContainerType::New();
auto weights = WeightsContainerType::New();

IdentifierType numberOfPoints{};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ FastMarchingImageToNodePairContainerAdaptor<TInput, TOutput, TImage>::SetPointsF
{
if (iLabel == Traits::Alive || iLabel == Traits::InitialTrial || iLabel == Traits::Forbidden)
{
NodePairContainerPointer nodes = NodePairContainerType::New();
nodes->Initialize();
NodePairContainerPointer nodes

using IteratorType = ImageRegionConstIteratorWithIndex<ImageType>;
using IteratorType = ImageRegionConstIteratorWithIndex<ImageType>;
IteratorType it(image, image->GetBufferedRegion());

if (iLabel == Traits::Alive || iLabel == Traits::InitialTrial ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ WindowConvergenceMonitoringFunction<TScalar>::GetConvergenceValue() const -> Rea
bspliner->SetNumberOfControlPoints(ncps);
bspliner->SetNumberOfWorkUnits(1);

auto energyProfileWindow = EnergyProfileType::New();
energyProfileWindow->Initialize();
auto energyProfileWindow

for (unsigned int n = 0; n < this->m_WindowSize; ++n)
for (unsigned int n = 0; n < this->m_WindowSize; ++n)
{
ProfilePointType windowPoint;
windowPoint[0] = static_cast<typename ProfilePointType::CoordRepType>(n) /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ LandmarkBasedTransformInitializer<TTransform, TFixedImage, TMovingImage>::Intern
}

// Set a pointSet from the input landmarks.
auto pointSet = PointSetType::New();
pointSet->Initialize();
auto pointSet

PointsContainerConstIterator fixedIt = this->m_FixedLandmarks.begin();
PointsContainerConstIterator movingIt = this->m_MovingLandmarks.begin();
PointsContainerConstIterator fixedIt = this->m_FixedLandmarks.begin();
PointsContainerConstIterator movingIt = this->m_MovingLandmarks.begin();
for (size_t i = 0; fixedIt != this->m_FixedLandmarks.end(); ++i, ++fixedIt, ++movingIt)
{
pointSet->SetPoint(static_cast<typename PointSetType::PointIdentifier>(i), (*fixedIt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ typename LabeledPointSetToPointSetMetricv4<TFixedPointSet, TMovingPointSet, TInt
LabeledPointSetToPointSetMetricv4<TFixedPointSet, TMovingPointSet, TInternalComputationValueType>::
GetLabeledFixedPointSet(const LabelType label) const
{
auto fixedPointSet = FixedPointSetType::New();
fixedPointSet->Initialize();
auto fixedPointSet

typename FixedPointSetType::PointIdentifier count{};
typename FixedPointSetType::PointIdentifier count{};

typename FixedPointSetType::PointsContainerConstIterator It = this->m_FixedPointSet->GetPoints()->Begin();
typename FixedPointSetType::PointDataContainerIterator ItD = this->m_FixedPointSet->GetPointData()->Begin();
Expand All @@ -155,10 +154,9 @@ typename LabeledPointSetToPointSetMetricv4<TFixedPointSet, TMovingPointSet, TInt
LabeledPointSetToPointSetMetricv4<TFixedPointSet, TMovingPointSet, TInternalComputationValueType>::
GetLabeledMovingPointSet(const LabelType label) const
{
auto movingPointSet = MovingPointSetType::New();
movingPointSet->Initialize();
auto movingPointSet

typename MovingPointSetType::PointIdentifier count{};
typename MovingPointSetType::PointIdentifier count{};

typename MovingPointSetType::PointsContainerConstIterator It = this->m_MovingPointSet->GetPoints()->Begin();
typename MovingPointSetType::PointDataContainerIterator ItD = this->m_MovingPointSet->GetPointData()->Begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ typename BSplineSyNImageRegistrationMethod<TFixedImage, TMovingImage, TOutputTra
}
}

auto gradientPointSet = BSplinePointSetType::New();
gradientPointSet->Initialize();
auto gradientPointSet

if (fixedPointSets[0]->GetNumberOfPoints() > 0)
if (fixedPointSets[0]->GetNumberOfPoints() > 0)
{
typename PointSetType::Pointer transformedPointSet =
dynamic_cast<PointSetMetricType *>(this->m_Metric.GetPointer())->GetModifiableFixedTransformedPointSet();
Expand All @@ -307,10 +306,7 @@ typename BSplineSyNImageRegistrationMethod<TFixedImage, TMovingImage, TOutputTra
weightedMask,
gradientPointSet);
}
else
{
updateField = metricGradientField;
}
else { updateField = metricGradientField; }
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,9 @@ ImageRegistrationMethodv4<TFixedImage, TMovingImage, TTransform, TVirtualImage,

for (SizeValueType n = 0; n < numberOfLocalMetrics; ++n)
{
auto samplePointSet = MetricSamplePointSetType::New();
samplePointSet->Initialize();
auto samplePointSet

using SamplePointType = typename MetricSamplePointSetType::PointType;
using SamplePointType = typename MetricSamplePointSetType::PointType;

using RandomizerType = Statistics::MersenneTwisterRandomVariateGenerator;
auto randomizer = RandomizerType::New();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,14 @@ TimeVaryingBSplineVelocityFieldImageRegistrationMethod<TFixedImage,
this->m_OutputTransform->IntegrateVelocityField();

// Keep track of velocityFieldPointSet from the previous iteration
VelocityFieldPointSetPointer velocityFieldPointSetFromPreviousIteration = VelocityFieldPointSetType::New();
velocityFieldPointSetFromPreviousIteration->Initialize();
VelocityFieldPointSetPointer velocityFieldPointSetFromPreviousIteration

VelocityFieldPointSetPointer velocityFieldPointSet = VelocityFieldPointSetType::New();
velocityFieldPointSet->Initialize();
VelocityFieldPointSetPointer velocityFieldPointSet

auto velocityFieldWeights = WeightsContainerType::New();
velocityFieldWeights->Initialize();
auto velocityFieldWeights

// Monitor the convergence
using ConvergenceMonitoringType = itk::Function::WindowConvergenceMonitoringFunction<RealType>;
// Monitor the convergence
using ConvergenceMonitoringType = itk::Function::WindowConvergenceMonitoringFunction<RealType>;
auto convergenceMonitoring = ConvergenceMonitoringType::New();
convergenceMonitoring->SetWindowSize(this->m_ConvergenceWindowSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ BayesianClassifierInitializationImageFilter<TInputImage, TProbabilityPrecisionTy
meanEstimatorsContainer->Reserve(m_NumberOfClasses);
covarianceEstimatorsContainer->Reserve(m_NumberOfClasses);

m_MembershipFunctionContainer = MembershipFunctionContainerType::New();
m_MembershipFunctionContainer->Initialize(); // Clear elements
for (unsigned int i = 0; i < m_NumberOfClasses; ++i)
m_MembershipFunctionContainer // Clear elements
for (unsigned int i = 0; i < m_NumberOfClasses; ++i)
{
meanEstimatorsContainer->InsertElement(i, new typename GaussianMembershipFunctionType::MeanVectorType(1));
covarianceEstimatorsContainer->InsertElement(i,
Expand Down

0 comments on commit 51c7a49

Please sign in to comment.