From bb0ba2ffaee16637841147e4839298732a3bbb4c Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 25 Nov 2024 16:09:17 -0600 Subject: [PATCH] STYLE: One declaration per line for readability Multiple declarations in a single statement reduces readability. Detect local variable declaration statements and update to have only one statement per declaration. Initialize values rather than independant assignments of each element --- .../Common/BoundingBoxOfAPointSet/Code.cxx | 16 ++++------ src/Core/Common/CreateAPointSet/Code.cxx | 14 ++------- src/Core/Mesh/AddPointsAndEdges/Code.cxx | 19 +++--------- src/Core/Mesh/WriteMeshToVTP/Code.cxx | 20 +++---------- .../ImageGrid/FitSplineIntoPointSet/Code.cxx | 29 +++++++------------ 5 files changed, 27 insertions(+), 71 deletions(-) diff --git a/src/Core/Common/BoundingBoxOfAPointSet/Code.cxx b/src/Core/Common/BoundingBoxOfAPointSet/Code.cxx index 269e37854..1e777ead1 100644 --- a/src/Core/Common/BoundingBoxOfAPointSet/Code.cxx +++ b/src/Core/Common/BoundingBoxOfAPointSet/Code.cxx @@ -36,17 +36,11 @@ main() PointsContainerPointer points = pointSet->GetPoints(); // Create points - PointType p0, p1, p2; - - p0[0] = 0.0; - p0[1] = 0.0; - p0[2] = 0.0; - p1[0] = 0.1; - p1[1] = 0.0; - p1[2] = 0.0; - p2[0] = 0.0; - p2[1] = 0.1; - p2[2] = 0.0; + // Create points + using PointType = PointSetType::PointType; + const PointType p0({ 0.0, 0.0, 0.0 }); + const PointType p1({ 0.1, 0.0, 0.0 }); + const PointType p2({ 0.0, 0.1, 0.0 }); points->InsertElement(0, p0); points->InsertElement(1, p1); diff --git a/src/Core/Common/CreateAPointSet/Code.cxx b/src/Core/Common/CreateAPointSet/Code.cxx index b6fc0173c..d2c291360 100644 --- a/src/Core/Common/CreateAPointSet/Code.cxx +++ b/src/Core/Common/CreateAPointSet/Code.cxx @@ -33,17 +33,9 @@ main() // Create points using PointType = PointSetType::PointType; - PointType p0, p1, p2; - - p0[0] = 0.0; - p0[1] = 0.0; - p0[2] = 0.0; - p1[0] = 0.1; - p1[1] = 0.0; - p1[2] = 0.0; - p2[0] = 0.0; - p2[1] = 0.1; - p2[2] = 0.0; + const PointType p0({ 0.0, 0.0, 0.0 }); + const PointType p1({ 0.1, 0.0, 0.0 }); + const PointType p2({ 0.0, 0.1, 0.0 }); points->InsertElement(0, p0); points->InsertElement(1, p1); diff --git a/src/Core/Mesh/AddPointsAndEdges/Code.cxx b/src/Core/Mesh/AddPointsAndEdges/Code.cxx index 388d8e77a..d7bc84b5f 100644 --- a/src/Core/Mesh/AddPointsAndEdges/Code.cxx +++ b/src/Core/Mesh/AddPointsAndEdges/Code.cxx @@ -42,20 +42,10 @@ CreatePointOnlyMesh() auto mesh = MeshType::New(); // Create points - MeshType::PointType p0, p1, p2, p3; - - p0[0] = -1.0; - p0[1] = -1.0; - p0[2] = 0.0; // first point ( -1, -1, 0 ) - p1[0] = 1.0; - p1[1] = -1.0; - p1[2] = 0.0; // second point ( 1, -1, 0 ) - p2[0] = 1.0; - p2[1] = 1.0; - p2[2] = 0.0; // third point ( 1, 1, 0 ) - p3[0] = 1.0; - p3[1] = 1.0; - p3[2] = 1.0; // third point ( 1, 1, 1 ) + const MeshType::PointType p0({ -1.0, -1.0, 0 }); // first point ( -1, -1, 0 ) + const MeshType::PointType p1({ 1.0, -1.0, 0.0 }); // second point ( 1, -1, 0 ) + const MeshType::PointType p2({ 1.0, 1.0, 0.0 }); // third point ( 1, 1, 0 ) + const MeshType::PointType p3({ 1.0, 1.0, 1.0 }); // forth point ( 1, 1, 1 ) mesh->SetPoint(0, p0); mesh->SetPoint(1, p1); @@ -68,7 +58,6 @@ CreatePointOnlyMesh() using PointsIterator = MeshType::PointsContainer::Iterator; PointsIterator pointIterator = mesh->GetPoints()->Begin(); - PointsIterator end = mesh->GetPoints()->End(); while (pointIterator != end) { diff --git a/src/Core/Mesh/WriteMeshToVTP/Code.cxx b/src/Core/Mesh/WriteMeshToVTP/Code.cxx index aacc9ef41..30a35e9e9 100644 --- a/src/Core/Mesh/WriteMeshToVTP/Code.cxx +++ b/src/Core/Mesh/WriteMeshToVTP/Code.cxx @@ -48,20 +48,10 @@ CreateMeshWithEdges() auto mesh = MeshType::New(); // Create points - MeshType::PointType p0, p1, p2, p3; - - p0[0] = -1.0; - p0[1] = -1.0; - p0[2] = 0.0; // first point ( -1, -1, 0 ) - p1[0] = 1.0; - p1[1] = -1.0; - p1[2] = 0.0; // second point ( 1, -1, 0 ) - p2[0] = 1.0; - p2[1] = 1.0; - p2[2] = 0.0; // third point ( 1, 1, 0 ) - p3[0] = 1.0; - p3[1] = 1.0; - p3[2] = 1.0; // third point ( 1, 1, 1 ) + const MeshType::PointType p0({ -1.0, -1.0, 0 }); // first point ( -1, -1, 0 ) + const MeshType::PointType p1({ 1.0, -1.0, 0.0 }); // second point ( 1, -1, 0 ) + const MeshType::PointType p2({ 1.0, 1.0, 0.0 }); // third point ( 1, 1, 0 ) + const MeshType::PointType p3({ 1.0, 1.0, 1.0 }); // forth point ( 1, 1, 1 ) mesh->SetPoint(0, p0); mesh->SetPoint(1, p1); @@ -74,7 +64,6 @@ CreateMeshWithEdges() using PointsIterator = MeshType::PointsContainer::Iterator; PointsIterator pointIterator = mesh->GetPoints()->Begin(); - PointsIterator end = mesh->GetPoints()->End(); while (pointIterator != end) { @@ -86,7 +75,6 @@ CreateMeshWithEdges() using CellAutoPointer = MeshType::CellType::CellAutoPointer; using LineType = itk::LineCell; - CellAutoPointer line0; line0.TakeOwnership(new LineType); line0->SetPointId(0, 0); // line between points 0 and 1 diff --git a/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx b/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx index 1966d5eba..ca6f531b6 100644 --- a/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx +++ b/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx @@ -28,32 +28,26 @@ main() constexpr unsigned int DataDimension = 2; using DataType = itk::Vector; - using PointSetType = itk::PointSet; auto pointSet = PointSetType::New(); - PointSetType::PointType param0, param1, param2; + const PointSetType::PointType param0{ 0.0 }; - param0[0] = 0.0; - DataType p0; - p0[0] = 10.0; - p0[1] = 10.0; + const DataType p0({ 10.0, 10.0 }); pointSet->SetPoint(0, param0); pointSet->SetPointData(0, p0); - param1[0] = 1.0; - DataType p1; - p1[0] = 80.0; - p1[1] = 50.0; + const PointSetType::PointType param1{ 1.0 }; + const DataType p1({ 80.0, 50.0 }); pointSet->SetPoint(1, param1); pointSet->SetPointData(1, p1); - param2[0] = 2.0; - DataType p2; - p2[0] = 180.0; - p2[1] = 180.0; + + PointSetType::PointType param2{ 2.0 }; + DataType p2({ 100.0, 100.0 }); + pointSet->SetPoint(2, param2); pointSet->SetPointData(2, p2); @@ -68,11 +62,10 @@ main() SplineFilterType::ArrayType closedim; closedim[0] = 0; - ImageType::PointType parametricDomainOrigin; - parametricDomainOrigin[0] = 0.0; + const ImageType::PointType parametricDomainOrigin{ 0.0 }; - ImageType::SpacingType parametricDomainSpacing; - parametricDomainSpacing[0] = 0.0001; // this determines the sampling of the continuous B-spline object. + // this determines the sampling of the continuous B-spline object. + const ImageType::SpacingType parametricDomainSpacing{ 0.0001 }; ImageType::SizeType parametricDomainSize; parametricDomainSize[0] = 2.0 / parametricDomainSpacing[0] + 1;