Skip to content

Commit

Permalink
STYLE: Replace T var; var = x with T var = x for arithmetic types
Browse files Browse the repository at this point in the history
Following C++ Core Guidelines, Oct 3, 2024, "Always initialize an object",
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always

Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([a-z][a-z ]*[a-z])([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Excluded `delete` statements, even if they would match the regular expression
(as in `delete var; var = x`).
  • Loading branch information
N-Dekker committed Nov 5, 2024
1 parent d37e7b4 commit 5d0df7a
Show file tree
Hide file tree
Showing 44 changed files with 105 additions and 182 deletions.
3 changes: 1 addition & 2 deletions Modules/Core/Common/include/itkColorTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ ColorTable<TComponent>::GetClosestColorTableId(TComponent r, TComponent g, TComp

for (unsigned int i = 0; i < m_NumberOfColors; ++i)
{
double match;
match = (r - static_cast<double>(m_Color[i].GetRed())) * (r - static_cast<double>(m_Color[i].GetRed()));
double match = (r - static_cast<double>(m_Color[i].GetRed())) * (r - static_cast<double>(m_Color[i].GetRed()));
match += (g - static_cast<double>(m_Color[i].GetGreen())) * (g - static_cast<double>(m_Color[i].GetGreen()));
match += (b - static_cast<double>(m_Color[i].GetGreen())) * (b - static_cast<double>(m_Color[i].GetBlue()));
if (i == 0 || match < bestMatch)
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/src/itkPlatformMultiThreaderPosix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ PlatformMultiThreader::SpawnDispatchSingleMethodThread(PlatformMultiThreader::Wo
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
#endif

int threadError;
threadError = pthread_create(
int threadError = pthread_create(
&threadHandle, &attr, reinterpret_cast<c_void_cast>(this->SingleMethodProxy), reinterpret_cast<void *>(threadInfo));
if (threadError != 0)
{
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkIteratorTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ itkIteratorTests(int, char *[])
start = clock();
itk::ImageRegionIterator<ScalarImage> it(o3, region);

unsigned short scalar;
scalar = 5;
unsigned short scalar = 5;

i = 0;
for (; !it.IsAtEnd(); ++it)
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/ImageAdaptors/test/itkVectorImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ itkVectorImageTest(int, char * argv[])
std::cerr << "[FAILED]" << std::endl;
failed = true;
}
bool adaptorTestResult;
adaptorTestResult = testVectorImageAdaptor<PixelType, Dimension, VectorImageToImageAdaptorType, VectorLength>(
vectorImageToImageAdaptor, vectorImage, region, componentToExtract);
bool adaptorTestResult =
testVectorImageAdaptor<PixelType, Dimension, VectorImageToImageAdaptorType, VectorLength>(
vectorImageToImageAdaptor, vectorImage, region, componentToExtract);
if (adaptorTestResult)
{
failed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ BSplineInterpolateImageFunction<TImageType, TCoordRep, TCoefficientType>::Evalua
tempValue = 1.0;
for (unsigned int n1 = 0; n1 < ImageDimension; ++n1)
{
unsigned int indx;
indx = m_PointsToIndex[p][n1];
unsigned int indx = m_PointsToIndex[p][n1];
coefficientIndex[n1] = (evaluateIndex)[n1][indx];

if (n1 == n)
Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,7 @@ template <typename TInputImage, typename TOutputMesh>
void
BinaryMask3DMeshSource<TInputImage, TOutputMesh>::inverse(unsigned char * x)
{
unsigned char tmp;

tmp = x[2];
unsigned char tmp = x[2];
x[2] = x[1];
x[1] = tmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ SimplexMeshAdaptTopologyFilter<TInputMesh, TOutputMesh>::ComputeCellParameters()
CovariantVectorType lineTwoFirstNormal = outputMesh->ComputeNormal(lineTwoFirstIdx);
CovariantVectorType secondNewNormal = outputMesh->ComputeNormal(secondNewIndex);

double prod;

prod = dot_product(firstNewNormal.GetVnlVector(), lineOneFirstNormal.GetVnlVector());
double prod = dot_product(firstNewNormal.GetVnlVector(), lineOneFirstNormal.GetVnlVector());

if (prod < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,7 @@ itkBSplineDeformableTransformTest3()
int
itkBSplineDeformableTransformTest(int, char *[])
{
bool failed;

failed = itkBSplineDeformableTransformTest1();
bool failed = itkBSplineDeformableTransformTest1();
if (failed)
{
return EXIT_FAILURE;
Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/Transform/test/itkBSplineTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,7 @@ itkBSplineTransformTest3()
int
itkBSplineTransformTest(int, char *[])
{
bool failed;

failed = itkBSplineTransformTest1();
bool failed = itkBSplineTransformTest1();
if (failed)
{
return EXIT_FAILURE;
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Transform/test/itkTestTransformGetInverse.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ TransformTest()
int
itkTestTransformGetInverse(int, char *[])
{
unsigned int errorCount;
errorCount = TransformTest<itk::AffineTransform<double, 3>>();
unsigned int errorCount = TransformTest<itk::AffineTransform<double, 3>>();
errorCount += TransformTest<itk::AzimuthElevationToCartesianTransform<double, 3>>();
errorCount += TransformTest<itk::BSplineTransform<double, 3>>();
errorCount += TransformTest<itk::CenteredAffineTransform<double, 3>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ constexpr int V_DEPTH = 64;
float
sphere(float x, float y, float z)
{
float dis;
dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
float dis = (x - static_cast<float>(V_WIDTH) / 2.0) * (x - static_cast<float>(V_WIDTH) / 2.0) /
((0.2f * V_WIDTH) * (0.2f * V_WIDTH)) +
(y - static_cast<float>(V_HEIGHT) / 2.0) * (y - static_cast<float>(V_HEIGHT) / 2.0) /
((0.2f * V_HEIGHT) * (0.2f * V_HEIGHT)) +
(z - static_cast<float>(V_DEPTH) / 2.0) * (z - static_cast<float>(V_DEPTH) / 2.0) /
((0.2f * V_DEPTH) * (0.2f * V_DEPTH));
return (1.0f - dis);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ BilateralImageFilter<TInputImage, TOutputImage>::BeforeThreadedGenerateData()
double rangeVariance = m_RangeSigma * m_RangeSigma;

// denominator (normalization factor) for Gaussian used for range
double rangeGaussianDenom;
rangeGaussianDenom = m_RangeSigma * std::sqrt(2.0 * itk::Math::pi);
double rangeGaussianDenom = m_RangeSigma * std::sqrt(2.0 * itk::Math::pi);

// Maximum delta for the dynamic range
double tableDelta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ int
MirrorPadImageFilter<TInputImage, TOutputImage>::FindRegionsInArea(long start, long end, long size, long offset)
{
int result = 1;
long regionsize;

regionsize = end - start;
long regionsize = end - start;
if (regionsize > 0) // Find out home many regions we have,
{
result = regionsize / size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ test3DInterpolateImagePointsFilter()
using OutputIterator = itk::ImageRegionIterator<CoordImageType3D>;
InputIterator inIter(image, region);
OutputIterator outIter(outputImage, region);
double rmse;
rmse = 0.0;
double rmse = 0.0;
while (!outIter.IsAtEnd())
{
double temp = inIter.Get() - outIter.Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ itkLabelImageToLabelMapFilterTest(int, char *[])
IndexType index;
index[0] = ctrI;
index[1] = ctrJ;
unsigned long val;
val = map->GetPixel(index);
unsigned long val = map->GetPixel(index);
std::cout << "Pixel[" << ctrI << ',' << ctrJ << "]: " << val << std::endl;
if (((ctrI == 5) || (ctrJ == 5)) && (ctrI != 7) && (ctrJ != 7))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ itkLabelMapToLabelImageFilterTest(int argc, char * argv[])
IndexType index;
index[0] = ctrI;
index[1] = ctrJ;
unsigned char val;
val = image->GetPixel(index);
unsigned char val = image->GetPixel(index);
if ((ctrI == 5) || (ctrJ == 5))
{
itkAssertOrThrowMacro((val == 1), "Error in Label Image.");
Expand Down
3 changes: 1 addition & 2 deletions Modules/Filtering/LabelMap/test/itkShiftLabelObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ itkShiftLabelObjectTest(int argc, char * argv[])
IndexType index;
index[0] = ctrI;
index[1] = ctrJ;
unsigned long val;
val = map->GetPixel(index);
unsigned long val = map->GetPixel(index);
std::cout << "Pixel[" << ctrI << ',' << ctrJ << "]: " << val << std::endl;
if ((ctrI == 5) || (ctrJ == 5))
{
Expand Down
8 changes: 2 additions & 6 deletions Modules/Filtering/Path/include/itkFourierSeriesPath.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ FourierSeriesPath<VDimension>::Evaluate(const InputType & input) const -> Output
{
InputType theta;
OutputType output;
int numHarmonics;

numHarmonics = m_CosCoefficients->Size();
int numHarmonics = m_CosCoefficients->Size();
output.Fill(0);

const double PI = 4.0 * std::atan(1.0);
Expand All @@ -57,9 +55,7 @@ FourierSeriesPath<VDimension>::EvaluateDerivative(const InputType & input) const
{
InputType theta;
VectorType output;
int numHarmonics;

numHarmonics = m_CosCoefficients->Size();
int numHarmonics = m_CosCoefficients->Size();
output.Fill(0);

const double PI = 4.0 * std::atan(1.0);
Expand Down
3 changes: 1 addition & 2 deletions Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ itkNiftiImageIOTest(int argc, char * argv[])
}
else // This is the mechanism for doing internal testing of all data types.
{
int cur_return;
cur_return = MakeNiftiImage<char>(testFileName);
int cur_return = MakeNiftiImage<char>(testFileName);
if (cur_return != 0)
{
std::cerr << "Error writing Nifti file type char" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ itkMaximumDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 0.1;
double membershipScore1 = 0.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// the maximum score is the third component. The decision rule should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@ itkMaximumRatioDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 0.1;
double membershipScore1 = 0.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// add discriminantscore with a value of zero
double membershipScore4;
membershipScore4 = 0.0;
double membershipScore4 = 0.0;
membershipScoreVector.push_back(membershipScore4);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ itkMinimumDecisionRuleTest(int, char *[])

MembershipVectorType membershipScoreVector;

double membershipScore1;
membershipScore1 = 1.1;
double membershipScore1 = 1.1;
membershipScoreVector.push_back(membershipScore1);

double membershipScore2;
membershipScore2 = 0.5;
double membershipScore2 = 0.5;
membershipScoreVector.push_back(membershipScore2);

double membershipScore3;
membershipScore3 = 1.9;
double membershipScore3 = 1.9;
membershipScoreVector.push_back(membershipScore3);

// the minimum score is the third component. The decision rule should
Expand Down
3 changes: 1 addition & 2 deletions Modules/Numerics/Optimizers/src/itkFRPROptimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ FRPROptimizer::StartOptimization()
{
this->SetCurrentIteration(currentIteration);

double fret;
fret = fp;
double fret = fp;
this->LineOptimize(&p, xi, &fret, tempCoord);

if (2.0 * itk::Math::abs(fret - fp) <=
Expand Down
11 changes: 3 additions & 8 deletions Modules/Numerics/Optimizers/src/itkPowellOptimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ PowellOptimizer::SetCurrentLinePoint(double x, double fx)
void
PowellOptimizer::Swap(double * a, double * b) const
{
double tf;

tf = *a;
double tf = *a;
*a = *b;
*b = tf;
}
Expand Down Expand Up @@ -294,8 +292,7 @@ PowellOptimizer::BracketedLineOptimize(double ax,
/* Decide if the interpolation can be tried */
if (itk::Math::abs(x - w) >= tolerance1) /* If x and w are distinct */
{
double t;
t = (x - w) * (functionValueOfX - functionValueOfV);
double t = (x - w) * (functionValueOfX - functionValueOfV);

double q; /* ted as p/q; division operation*/
q = (x - v) * (functionValueOfX - functionValueOfW);
Expand Down Expand Up @@ -343,9 +340,7 @@ PowellOptimizer::BracketedLineOptimize(double ax,
/* and reduce the enveloping range */
double t = x + new_step; /* Tentative point for the min */

double functionValueOft;

functionValueOft = this->GetLineValue(t, tempCoord);
double functionValueOft = this->GetLineValue(t, tempCoord);

if (functionValueOft <= functionValueOfX)
{
Expand Down
11 changes: 3 additions & 8 deletions Modules/Numerics/Optimizersv4/include/itkPowellOptimizerv4.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ template <typename TInternalComputationValueType>
void
PowellOptimizerv4<TInternalComputationValueType>::Swap(double * a, double * b) const
{
double tf;

tf = *a;
double tf = *a;
*a = *b;
*b = tf;
}
Expand Down Expand Up @@ -289,8 +287,7 @@ PowellOptimizerv4<TInternalComputationValueType>::BracketedLineOptimize(double
/* Decide if the interpolation can be tried */
if (itk::Math::abs(x - w) >= tolerance1) /* If x and w are distinct */
{
double t;
t = (x - w) * (functionValueOfX - functionValueOfV);
double t = (x - w) * (functionValueOfX - functionValueOfV);

double q; /* ted as p/q; division operation*/
q = (x - v) * (functionValueOfX - functionValueOfW);
Expand Down Expand Up @@ -338,9 +335,7 @@ PowellOptimizerv4<TInternalComputationValueType>::BracketedLineOptimize(double
/* and reduce the enveloping range */
double t = x + new_step; /* Tentative point for the min */

double functionValueOft;

functionValueOft = this->GetLineValue(t, tempCoord);
double functionValueOft = this->GetLineValue(t, tempCoord);

if (functionValueOft <= functionValueOfX)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ ImageClassifierFilter<TSample, TInputImage, TOutputImage>::GenerateData()
discriminantScores[i] = membershipFunctionsWeightsArray[i] * membershipFunctions[i]->Evaluate(measurements);
}

unsigned int classIndex;
classIndex = static_cast<unsigned int>(m_DecisionRule->Evaluate(discriminantScores));
unsigned int classIndex = static_cast<unsigned int>(m_DecisionRule->Evaluate(discriminantScores));

auto value = static_cast<OutputPixelType>(classLabels[classIndex]);
outItr.Set(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ MahalanobisDistanceMetric<TVector>::Evaluate(const MeasurementVectorType & measu
tempMat = tempVec * m_InverseCovariance;

// Compute |y - mean | * inverse(cov) * |y - mean|^T
double temp;
temp = std::sqrt(dot_product(tempMat.as_ref(), tempVec.as_ref()));
double temp = std::sqrt(dot_product(tempMat.as_ref(), tempVec.as_ref()));

return temp;
}
Expand Down Expand Up @@ -193,8 +192,7 @@ MahalanobisDistanceMetric<TVector>::Evaluate(const MeasurementVectorType & x1, c
tempMat = tempVec * m_InverseCovariance;

// Compute |x1 - x2 | * inverse(cov) * |x1 - x2|^T
double temp;
temp = std::sqrt(dot_product(tempMat.as_ref(), tempVec.as_ref()));
double temp = std::sqrt(dot_product(tempMat.as_ref(), tempVec.as_ref()));

return temp;
}
Expand Down
Loading

0 comments on commit 5d0df7a

Please sign in to comment.