Skip to content

Commit c00f18a

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Use ConvertNumberToString instead of local NumberToString objects
Simplified code by removing local `convert` function objects, and just calling the new `ConvertNumberToString` convenience function instead.
1 parent d3daa71 commit c00f18a

File tree

6 files changed

+44
-55
lines changed

6 files changed

+44
-55
lines changed

Modules/Core/Common/src/itkArrayOutputSpecialization.cxx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ namespace itk
2424
template <>
2525
std::ostream & operator<<<double>(std::ostream & os, const Array<double> & arr)
2626
{
27-
NumberToString<double> convert;
2827
os << "[";
2928
const size_t length = arr.size();
3029
if (length >= 1)
3130
{
3231
const size_t last = length - 1;
3332
for (size_t i = 0; i < last; ++i)
3433
{
35-
os << convert(arr[i]) << ", ";
34+
os << ConvertNumberToString(arr[i]) << ", ";
3635
}
37-
os << convert(arr[last]);
36+
os << ConvertNumberToString(arr[last]);
3837
}
3938
os << "]";
4039
return os;
@@ -43,17 +42,16 @@ std::ostream & operator<<<double>(std::ostream & os, const Array<double> & arr)
4342
template <>
4443
std::ostream & operator<<<float>(std::ostream & os, const Array<float> & arr)
4544
{
46-
NumberToString<float> convert;
4745
os << "[";
4846
const size_t length = arr.size();
4947
if (length >= 1)
5048
{
5149
const size_t last = length - 1;
5250
for (size_t i = 0; i < last; ++i)
5351
{
54-
os << convert(static_cast<float>(arr[i])) << ", ";
52+
os << ConvertNumberToString(arr[i]) << ", ";
5553
}
56-
os << convert(static_cast<float>(arr[last]));
54+
os << ConvertNumberToString(arr[last]);
5755
}
5856
os << "]";
5957
return os;
@@ -62,9 +60,8 @@ std::ostream & operator<<<float>(std::ostream & os, const Array<float> & arr)
6260
template <>
6361
std::ostream & operator<<<double>(std::ostream & os, const Array2D<double> & arr)
6462
{
65-
NumberToString<double> convert;
66-
const unsigned int numberOfRows = arr.rows();
67-
const unsigned int numberOfColumns = arr.cols();
63+
const unsigned int numberOfRows = arr.rows();
64+
const unsigned int numberOfColumns = arr.cols();
6865

6966
for (unsigned int r = 0; r < numberOfRows; ++r)
7067
{
@@ -74,9 +71,9 @@ std::ostream & operator<<<double>(std::ostream & os, const Array2D<double> & arr
7471
const unsigned int lastColumn = numberOfColumns - 1;
7572
for (unsigned int c = 0; c < lastColumn; ++c)
7673
{
77-
os << convert(arr(r, c)) << ", ";
74+
os << ConvertNumberToString(arr(r, c)) << ", ";
7875
}
79-
os << convert(arr(r, lastColumn));
76+
os << ConvertNumberToString(arr(r, lastColumn));
8077
}
8178
os << "]" << std::endl;
8279
}
@@ -87,9 +84,8 @@ std::ostream & operator<<<double>(std::ostream & os, const Array2D<double> & arr
8784
template <>
8885
std::ostream & operator<<<float>(std::ostream & os, const Array2D<float> & arr)
8986
{
90-
NumberToString<float> convert;
91-
const unsigned int numberOfRows = arr.rows();
92-
const unsigned int numberOfColumns = arr.cols();
87+
const unsigned int numberOfRows = arr.rows();
88+
const unsigned int numberOfColumns = arr.cols();
9389

9490
for (unsigned int r = 0; r < numberOfRows; ++r)
9591
{
@@ -99,9 +95,9 @@ std::ostream & operator<<<float>(std::ostream & os, const Array2D<float> & arr)
9995
const unsigned int lastColumn = numberOfColumns - 1;
10096
for (unsigned int c = 0; c < lastColumn; ++c)
10197
{
102-
os << convert(arr(r, c)) << ", ";
98+
os << ConvertNumberToString(arr(r, c)) << ", ";
10399
}
104-
os << convert(arr(r, lastColumn));
100+
os << ConvertNumberToString(arr(r, lastColumn));
105101
}
106102
os << "]" << std::endl;
107103
}

Modules/IO/MeshBYU/include/itkBYUMeshIO.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,15 @@ class ITKIOMeshBYU_EXPORT BYUMeshIO : public MeshIOBase
118118
void
119119
WritePoints(T * buffer, std::ofstream & outputFile)
120120
{
121-
NumberToString<T> convert;
122-
Indent indent(1);
123-
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
121+
Indent indent(1);
122+
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
124123

125124
for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
126125
{
127126
outputFile << indent;
128127
for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
129128
{
130-
outputFile << convert(buffer[index++]) << " ";
129+
outputFile << ConvertNumberToString(buffer[index++]) << " ";
131130
}
132131
outputFile << '\n';
133132
}

Modules/IO/MeshBase/include/itkMeshIOBase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,11 @@ class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject
652652
SizeValueType numberOfLines,
653653
SizeValueType numberOfComponents)
654654
{
655-
NumberToString<T> convert;
656655
for (SizeValueType ii = 0; ii < numberOfLines; ++ii)
657656
{
658657
for (SizeValueType jj = 0; jj < numberOfComponents; ++jj)
659658
{
660-
outputFile << convert(buffer[ii * numberOfComponents + jj]) << " ";
659+
outputFile << ConvertNumberToString(buffer[ii * numberOfComponents + jj]) << " ";
661660
}
662661
outputFile << '\n';
663662
}

Modules/IO/MeshOBJ/include/itkOBJMeshIO.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,14 @@ class ITKIOMeshOBJ_EXPORT OBJMeshIO : public MeshIOBase
116116
void
117117
WritePoints(T * buffer, std::ofstream & outputFile)
118118
{
119-
NumberToString<T> convert;
120-
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
119+
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
121120

122121
for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
123122
{
124123
outputFile << "v ";
125124
for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
126125
{
127-
outputFile << convert(buffer[index++]) << " ";
126+
outputFile << ConvertNumberToString(buffer[index++]) << " ";
128127
}
129128
outputFile << '\n';
130129
}
@@ -155,15 +154,14 @@ class ITKIOMeshOBJ_EXPORT OBJMeshIO : public MeshIOBase
155154
void
156155
WritePointData(T * buffer, std::ofstream & outputFile)
157156
{
158-
NumberToString<T> convert;
159-
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
157+
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
160158

161159
for (SizeValueType ii = 0; ii < this->m_NumberOfPointPixels; ++ii)
162160
{
163161
outputFile << "vn ";
164162
for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
165163
{
166-
outputFile << convert(buffer[index++]) << " ";
164+
outputFile << ConvertNumberToString(buffer[index++]) << " ";
167165
}
168166

169167
outputFile << '\n';

Modules/IO/MeshVTK/include/itkVTKPolyDataMeshIO.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
432432
void
433433
WritePointsBufferAsASCII(std::ofstream & outputFile, T * buffer, const StringType & pointComponentType)
434434
{
435-
NumberToString<T> convert;
436435
/** 1. Write number of points */
437436
outputFile << "POINTS " << this->m_NumberOfPoints;
438437

@@ -441,10 +440,10 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
441440
{
442441
for (unsigned int jj = 0; jj < this->m_PointDimension - 1; ++jj)
443442
{
444-
outputFile << convert(buffer[ii * this->m_PointDimension + jj]) << " ";
443+
outputFile << ConvertNumberToString(buffer[ii * this->m_PointDimension + jj]) << " ";
445444
}
446445

447-
outputFile << convert(buffer[ii * this->m_PointDimension + this->m_PointDimension - 1]) << '\n';
446+
outputFile << ConvertNumberToString(buffer[ii * this->m_PointDimension + this->m_PointDimension - 1]) << '\n';
448447
}
449448

450449
return;
@@ -725,7 +724,6 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
725724
void
726725
WritePointDataBufferAsASCII(std::ofstream & outputFile, T * buffer, const StringType & pointPixelComponentName)
727726
{
728-
NumberToString<T> convert;
729727
MetaDataDictionary & metaDic = this->GetMetaDataDictionary();
730728
StringType dataName;
731729

@@ -795,16 +793,17 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
795793
while (i < num)
796794
{
797795
// row 1
798-
outputFile << convert(*ptr++) << indent;
796+
outputFile << ConvertNumberToString(*ptr++) << indent;
799797
e12 = *ptr++;
800-
outputFile << convert(e12) << indent;
801-
outputFile << convert(zero) << '\n';
798+
outputFile << ConvertNumberToString(e12) << indent;
799+
outputFile << ConvertNumberToString(zero) << '\n';
802800
// row 2
803-
outputFile << convert(e12) << indent;
804-
outputFile << convert(*ptr++) << indent;
805-
outputFile << convert(zero) << '\n';
801+
outputFile << ConvertNumberToString(e12) << indent;
802+
outputFile << ConvertNumberToString(*ptr++) << indent;
803+
outputFile << ConvertNumberToString(zero) << '\n';
806804
// row 3
807-
outputFile << convert(zero) << indent << convert(zero) << indent << convert(zero) << "\n\n";
805+
outputFile << ConvertNumberToString(zero) << indent << ConvertNumberToString(zero) << indent
806+
<< ConvertNumberToString(zero) << "\n\n";
808807
i += 3;
809808
}
810809
}
@@ -816,20 +815,20 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
816815
while (i < num)
817816
{
818817
// row 1
819-
outputFile << convert(*ptr++) << indent;
818+
outputFile << ConvertNumberToString(*ptr++) << indent;
820819
e12 = *ptr++;
821-
outputFile << convert(e12) << indent;
820+
outputFile << ConvertNumberToString(e12) << indent;
822821
e13 = *ptr++;
823-
outputFile << convert(e13) << '\n';
822+
outputFile << ConvertNumberToString(e13) << '\n';
824823
// row 2
825-
outputFile << convert(e12) << indent;
826-
outputFile << convert(*ptr++) << indent;
824+
outputFile << ConvertNumberToString(e12) << indent;
825+
outputFile << ConvertNumberToString(*ptr++) << indent;
827826
e23 = *ptr++;
828-
outputFile << convert(e23) << '\n';
827+
outputFile << ConvertNumberToString(e23) << '\n';
829828
// row 3
830-
outputFile << convert(e13) << indent;
831-
outputFile << convert(e23) << indent;
832-
outputFile << convert(*ptr++) << "\n\n";
829+
outputFile << ConvertNumberToString(e13) << indent;
830+
outputFile << ConvertNumberToString(e23) << indent;
831+
outputFile << ConvertNumberToString(*ptr++) << "\n\n";
833832
i += 6;
834833
}
835834
}
@@ -847,9 +846,9 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
847846
{
848847
for (jj = 0; jj < this->m_NumberOfPointPixelComponents - 1; ++jj)
849848
{
850-
outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]) << indent;
849+
outputFile << ConvertNumberToString(buffer[ii * this->m_NumberOfPointPixelComponents + jj]) << indent;
851850
}
852-
outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]);
851+
outputFile << ConvertNumberToString(buffer[ii * this->m_NumberOfPointPixelComponents + jj]);
853852
outputFile << '\n';
854853
}
855854
}
@@ -1124,14 +1123,13 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
11241123
unsigned int numberOfPixelComponents,
11251124
SizeValueType numberOfPixels)
11261125
{
1127-
NumberToString<float> convert;
11281126
outputFile << numberOfPixelComponents << "\n";
11291127
Indent indent(2);
11301128
for (SizeValueType ii = 0; ii < numberOfPixels; ++ii)
11311129
{
11321130
for (unsigned int jj = 0; jj < numberOfPixelComponents; ++jj)
11331131
{
1134-
outputFile << convert(static_cast<float>(buffer[ii * numberOfPixelComponents + jj])) << indent;
1132+
outputFile << ConvertNumberToString(static_cast<float>(buffer[ii * numberOfPixelComponents + jj])) << indent;
11351133
}
11361134

11371135
outputFile << "\n";

Modules/IO/TransformInsightLegacy/src/itkTxtTransformIO.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,13 @@ template <typename TParametersValueType>
241241
inline void
242242
print_vector(std::ofstream & s, vnl_vector<TParametersValueType> const & v)
243243
{
244-
NumberToString<TParametersValueType> convert;
245244
for (unsigned int i = 0; i + 1 < v.size(); ++i)
246245
{
247-
s << convert(v[i]) << ' ';
246+
s << ConvertNumberToString(v[i]) << ' ';
248247
}
249248
if (!v.empty())
250249
{
251-
s << convert(v.back());
250+
s << ConvertNumberToString(v.back());
252251
}
253252
}
254253
} // namespace itk_impl_details

0 commit comments

Comments
 (0)