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 b3a5638
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BSplineTransformInitializer<TTransform, TImage>::InitializeTransform() const

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


using PointType = typename PointSetType::PointType;
using PointIdentifier = typename PointSetType::PointIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ N4BiasFieldCorrectionImageFilter<TInputImage, TMaskImage, TOutputImage>::UpdateB
const typename ImporterType::OutputImageType * parametricFieldEstimate = importer->GetOutput();

PointSetPointer fieldPoints = PointSetType::New();
fieldPoints->Initialize();

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();
weightSTLContainer.reserve(numberOfIncludedPixels);

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

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


auto weights = WeightsContainerType::New();

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


using IteratorType = ImageRegionConstIteratorWithIndex<ImageType>;
IteratorType it(image, image->GetBufferedRegion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ WindowConvergenceMonitoringFunction<TScalar>::GetConvergenceValue() const -> Rea
bspliner->SetNumberOfWorkUnits(1);

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


for (unsigned int n = 0; n < this->m_WindowSize; ++n)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ LandmarkBasedTransformInitializer<TTransform, TFixedImage, TMovingImage>::Intern

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


PointsContainerConstIterator fixedIt = this->m_FixedLandmarks.begin();
PointsContainerConstIterator movingIt = this->m_MovingLandmarks.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ typename LabeledPointSetToPointSetMetricv4<TFixedPointSet, TMovingPointSet, TInt
GetLabeledFixedPointSet(const LabelType label) const
{
auto fixedPointSet = FixedPointSetType::New();
fixedPointSet->Initialize();


typename FixedPointSetType::PointIdentifier count{};

Expand All @@ -156,7 +156,7 @@ typename LabeledPointSetToPointSetMetricv4<TFixedPointSet, TMovingPointSet, TInt
GetLabeledMovingPointSet(const LabelType label) const
{
auto movingPointSet = MovingPointSetType::New();
movingPointSet->Initialize();


typename MovingPointSetType::PointIdentifier count{};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ typename BSplineSyNImageRegistrationMethod<TFixedImage, TMovingImage, TOutputTra
}

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


if (fixedPointSets[0]->GetNumberOfPoints() > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ ImageRegistrationMethodv4<TFixedImage, TMovingImage, TTransform, TVirtualImage,
for (SizeValueType n = 0; n < numberOfLocalMetrics; ++n)
{
auto samplePointSet = MetricSamplePointSetType::New();
samplePointSet->Initialize();


using SamplePointType = typename MetricSamplePointSetType::PointType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ TimeVaryingBSplineVelocityFieldImageRegistrationMethod<TFixedImage,

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


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


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


// Monitor the convergence
using ConvergenceMonitoringType = itk::Function::WindowConvergenceMonitoringFunction<RealType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ BayesianClassifierInitializationImageFilter<TInputImage, TProbabilityPrecisionTy
covarianceEstimatorsContainer->Reserve(m_NumberOfClasses);

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

0 comments on commit b3a5638

Please sign in to comment.