Repository: InsightSoftwareConsortium/ITK (language: python)

Issue:
STYLE: Remove `p->Initialize()` calls directly after `p = T::New()`
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`.


Discussion / hints:

Fix patch:
diff --git a/Examples/DataRepresentation/Path/PolyLineParametricPath1.cxx b/Examples/DataRepresentation/Path/PolyLineParametricPath1.cxx
index da6332dde76..47cda0ae542 100644
--- a/Examples/DataRepresentation/Path/PolyLineParametricPath1.cxx
+++ b/Examples/DataRepresentation/Path/PolyLineParametricPath1.cxx
@@ -86,7 +86,6 @@ main(int argc, char * argv[])
   // Software Guide : BeginCodeSnippet
   ImageType::ConstPointer image = reader->GetOutput();
   auto                    path = PathType::New();
-  path->Initialize();
 
   using ContinuousIndexType = PathType::ContinuousIndexType;
   ContinuousIndexType cindex;


Test patch:
diff --git a/Modules/Filtering/DisplacementField/test/itkDisplacementFieldToBSplineImageFilterTest.cxx b/Modules/Filtering/DisplacementField/test/itkDisplacementFieldToBSplineImageFilterTest.cxx
index 63a59418393..683065414a2 100644
--- a/Modules/Filtering/DisplacementField/test/itkDisplacementFieldToBSplineImageFilterTest.cxx
+++ b/Modules/Filtering/DisplacementField/test/itkDisplacementFieldToBSplineImageFilterTest.cxx
@@ -59,7 +59,6 @@ itkDisplacementFieldToBSplineImageFilterTest(int, char *[])
   confidenceImage->FillBuffer(1.0);
 
   auto pointSet = PointSetType::New();
-  pointSet->Initialize();
 
   auto ones_points = itk::MakeFilled<VectorType>(1.0);
 
diff --git a/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest2.cxx b/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest2.cxx
index 36a5645ca19..f401bc813b0 100644
--- a/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest2.cxx
+++ b/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest2.cxx
@@ -98,8 +98,6 @@ itkBSplineScatteredDataPointSetToImageFilterTest2(int argc, char * argv[])
 
   FilterType::WeightsContainerType::Pointer pointWeights = FilterType::WeightsContainerType::New();
 
-  pointWeights->Initialize();
-
   unsigned int abritrarySize = filter->GetInput()->GetNumberOfPoints() - 1;
   pointWeights->resize(abritrarySize);
   for (unsigned int i = 0; i < pointWeights->Size(); ++i)
diff --git a/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest4.cxx b/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest4.cxx
index ebc7b84e8c3..2bc98116936 100644
--- a/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest4.cxx
+++ b/Modules/Filtering/ImageGrid/test/itkBSplineScatteredDataPointSetToImageFilterTest4.cxx
@@ -56,11 +56,9 @@ itkBSplineScatteredDataPointSetToImageFilterTest4(int, char *[])
   // Instantiate example corresponding points with relative weighting
 
   auto pointSet = PointSetType::New();
-  pointSet->Initialize();
 
   using WeightsContainerType = FilterType::WeightsContainerType;
   auto weights = WeightsContainerType::New();
-  weights->Initialize();
 
   // Create first landmark pair and weights
   PointType landmarkInFirstImage1;
diff --git a/Modules/Numerics/Optimizersv4/test/itkRegistrationParameterScalesFromPhysicalShiftPointSetTest.cxx b/Modules/Numerics/Optimizersv4/test/itkRegistrationParameterScalesFromPhysicalShiftPointSetTest.cxx
index e46fc891096..3576d4d60a6 100644
--- a/Modules/Numerics/Optimizersv4/test/itkRegistrationParameterScalesFromPhysicalShiftPointSetTest.cxx
+++ b/Modules/Numerics/Optimizersv4/test/itkRegistrationParameterScalesFromPhysicalShiftPointSetTest.cxx
@@ -87,9 +87,7 @@ itkRegistrationParameterScalesFromPhysicalShiftPointSetTest(int, char *[])
   using PointType = PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   itk::Size<Dimension> virtualDomainSize;
   virtualDomainSize[0] = static_cast<itk::SizeValueType>(10);
diff --git a/Modules/Registration/Common/test/itkPointsLocatorTest.cxx b/Modules/Registration/Common/test/itkPointsLocatorTest.cxx
index 746c5626560..57fd33fc2ac 100644
--- a/Modules/Registration/Common/test/itkPointsLocatorTest.cxx
+++ b/Modules/Registration/Common/test/itkPointsLocatorTest.cxx
@@ -33,7 +33,6 @@ testPointsLocatorTest()
 
   using PointsContainerType = TPointsContainer;
   auto points = PointsContainerType::New();
-  points->Initialize();
 
   using PointsLocatorType = itk::PointsLocator<PointsContainerType>;
   auto pointsLocator = PointsLocatorType::New();
diff --git a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricRegistrationTest.cxx b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricRegistrationTest.cxx
index cd7667fa7b2..1598d267c4c 100644
--- a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricRegistrationTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricRegistrationTest.cxx
@@ -78,10 +78,8 @@ itkEuclideanDistancePointSetMetricRegistrationTestRun(unsigned int
   using CoordRepType = typename PointType::CoordRepType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Create a few points and apply a small rotation to make the moving point set
 
diff --git a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest.cxx b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest.cxx
index df9cc2e8a20..de6207c049c 100644
--- a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest.cxx
@@ -31,10 +31,8 @@ itkEuclideanDistancePointSetMetricTestRun()
   using PointType = typename PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Produce two simple point sets of 1) a circle and 2) the same circle with an offset;
   PointType offset;
diff --git a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest2.cxx b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest2.cxx
index df038b36ee8..ad177098832 100644
--- a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest2.cxx
+++ b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest2.cxx
@@ -37,10 +37,8 @@ itkEuclideanDistancePointSetMetricTest2Run()
   using PointType = typename PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Create a few points and apply a small offset to make the moving points
   auto      pointMax = static_cast<float>(100.0);
@@ -200,7 +198,6 @@ itkEuclideanDistancePointSetMetricTest2Run()
 
   // Test with no valid points.
   auto fixedPoints2 = PointSetType::New();
-  fixedPoints2->Initialize();
   fixedPoint[0] = -pointMax;
   fixedPoint[1] = 0.0;
   fixedPoints2->SetPoint(0, fixedPoint);
diff --git a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest3.cxx b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest3.cxx
index 3dcbe106d8a..d9fb2d5c195 100644
--- a/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest3.cxx
+++ b/Modules/Registration/Metricsv4/test/itkEuclideanDistancePointSetMetricTest3.cxx
@@ -38,10 +38,8 @@ itkEuclideanDistancePointSetMetricTest3Run(double distanceThreshold)
   auto pointsLocator = PointsLocatorType::New();
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Create a few points and apply a small offset to make the moving points
   auto      pointMax = static_cast<float>(1.0);
diff --git a/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricRegistrationTest.cxx b/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricRegistrationTest.cxx
index 98eb57ab14d..4322da2f2bb 100644
--- a/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricRegistrationTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricRegistrationTest.cxx
@@ -75,10 +75,8 @@ itkExpectationBasedPointSetMetricRegistrationTest(int argc, char * argv[])
   using PointType = PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
 
   // two ellipses, one rotated slightly
diff --git a/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricTest.cxx b/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricTest.cxx
index ba4e3d8f106..36c28170c57 100644
--- a/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkExpectationBasedPointSetMetricTest.cxx
@@ -32,10 +32,8 @@ itkExpectationBasedPointSetMetricTestRun()
   using PointType = typename PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Produce two simple point sets of 1) a circle and 2) the same circle with an offset;
   PointType offset;
diff --git a/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricRegistrationTest.cxx b/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricRegistrationTest.cxx
index 3ed45880a83..55cc0468abd 100644
--- a/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricRegistrationTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricRegistrationTest.cxx
@@ -79,10 +79,8 @@ itkJensenHavrdaCharvatTsallisPointSetMetricRegistrationTest(int argc, char * arg
   using PointType = PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
 
   // two ellipses, one rotated slightly
diff --git a/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricTest.cxx b/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricTest.cxx
index b710a7e3c69..5bbe3bd4f23 100644
--- a/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkJensenHavrdaCharvatTsallisPointSetMetricTest.cxx
@@ -32,10 +32,8 @@ itkJensenHavrdaCharvatTsallisPointSetMetricTestRun()
   using VectorType = typename PointType::VectorType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Produce two simple point sets of 1) a circle and 2) the same circle with an offset
   PointType  offset;
diff --git a/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricRegistrationTest.cxx b/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricRegistrationTest.cxx
index 036e29ff1b3..68c36db422f 100644
--- a/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricRegistrationTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricRegistrationTest.cxx
@@ -70,10 +70,8 @@ itkLabeledPointSetMetricRegistrationTestPerMetric(unsigned int numberOfIteration
   using PointType = typename PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // two circles with a small offset
   PointType offset;
diff --git a/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricTest.cxx b/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricTest.cxx
index 7c43ce23506..e65216a5393 100644
--- a/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricTest.cxx
+++ b/Modules/Registration/Metricsv4/test/itkLabeledPointSetMetricTest.cxx
@@ -35,10 +35,8 @@ itkLabeledPointSetMetricTestRun()
   using PointType = typename PointSetType::PointType;
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // Produce two simple point sets of 1) a circle and 2) the same circle with an offset;
   PointType offset;
diff --git a/Modules/Registration/RegistrationMethodsv4/test/itkBSplineSyNPointSetRegistrationTest.cxx b/Modules/Registration/RegistrationMethodsv4/test/itkBSplineSyNPointSetRegistrationTest.cxx
index 12d8f636324..c216b6646c4 100644
--- a/Modules/Registration/RegistrationMethodsv4/test/itkBSplineSyNPointSetRegistrationTest.cxx
+++ b/Modules/Registration/RegistrationMethodsv4/test/itkBSplineSyNPointSetRegistrationTest.cxx
@@ -40,10 +40,8 @@ itkBSplineSyNPointSetRegistrationTest(int itkNotUsed(argc), char * itkNotUsed(ar
 
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // two circles with a small offset
   PointType offset;
diff --git a/Modules/Registration/RegistrationMethodsv4/test/itkSimplePointSetRegistrationTest.cxx b/Modules/Registration/RegistrationMethodsv4/test/itkSimplePointSetRegistrationTest.cxx
index 6041dbb8373..eba382356d4 100644
--- a/Modules/Registration/RegistrationMethodsv4/test/itkSimplePointSetRegistrationTest.cxx
+++ b/Modules/Registration/RegistrationMethodsv4/test/itkSimplePointSetRegistrationTest.cxx
@@ -121,10 +121,8 @@ itkSimplePointSetRegistrationTest(int itkNotUsed(argc), char * itkNotUsed(argv)[
 
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // two circles with a small offset
   PointType offset;
diff --git a/Modules/Registration/RegistrationMethodsv4/test/itkSyNPointSetRegistrationTest.cxx b/Modules/Registration/RegistrationMethodsv4/test/itkSyNPointSetRegistrationTest.cxx
index eb33a40d263..715f2f65f74 100644
--- a/Modules/Registration/RegistrationMethodsv4/test/itkSyNPointSetRegistrationTest.cxx
+++ b/Modules/Registration/RegistrationMethodsv4/test/itkSyNPointSetRegistrationTest.cxx
@@ -41,10 +41,8 @@ itkSyNPointSetRegistrationTest(int itkNotUsed(argc), char * itkNotUsed(argv)[])
 
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // two circles with a small offset
   PointType offset;
diff --git a/Modules/Registration/RegistrationMethodsv4/test/itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest.cxx b/Modules/Registration/RegistrationMethodsv4/test/itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest.cxx
index e8f30331204..87e51d1beb0 100644
--- a/Modules/Registration/RegistrationMethodsv4/test/itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest.cxx
+++ b/Modules/Registration/RegistrationMethodsv4/test/itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest.cxx
@@ -42,10 +42,8 @@ itkTimeVaryingBSplineVelocityFieldPointSetRegistrationTest(int itkNotUsed(argc),
 
 
   auto fixedPoints = PointSetType::New();
-  fixedPoints->Initialize();
 
   auto movingPoints = PointSetType::New();
-  movingPoints->Initialize();
 
   // two circles with a small offset
   PointType offset;
diff --git a/Modules/Segmentation/LevelSets/test/itkShapePriorMAPCostFunctionTest.cxx b/Modules/Segmentation/LevelSets/test/itkShapePriorMAPCostFunctionTest.cxx
index bcde9f00841..99ab1e89843 100644
--- a/Modules/Segmentation/LevelSets/test/itkShapePriorMAPCostFunctionTest.cxx
+++ b/Modules/Segmentation/LevelSets/test/itkShapePriorMAPCostFunctionTest.cxx
@@ -49,7 +49,6 @@ itkShapePriorMAPCostFunctionTest(int, char *[])
    */
   using ShapeFunctionType = itk::SphereSignedDistanceFunction<double, Dimension>;
   auto shape = ShapeFunctionType::New();
-  shape->Initialize();
 
   /**
    * Set up a statistical model of the shape parameters.
diff --git a/Modules/Segmentation/LevelSets/test/itkShapePriorSegmentationLevelSetFunctionTest.cxx b/Modules/Segmentation/LevelSets/test/itkShapePriorSegmentationLevelSetFunctionTest.cxx
index a36ad06b62d..a0935f3c2b2 100644
--- a/Modules/Segmentation/LevelSets/test/itkShapePriorSegmentationLevelSetFunctionTest.cxx
+++ b/Modules/Segmentation/LevelSets/test/itkShapePriorSegmentationLevelSetFunctionTest.cxx
@@ -130,7 +130,6 @@ itkShapePriorSegmentationLevelSetFunctionTest(int, char *[])
 
   using ShapeFunctionType = itk::SphereSignedDistanceFunction<double, Dimension>;
   auto shape = ShapeFunctionType::New();
-  shape->Initialize();
 
   ShapeFunctionType::ParametersType parameters(shape->GetNumberOfParameters());
   parameters[0] = 10.0;