Skip to content

Commit

Permalink
STYLE: Use ConvertNumberToString instead of local NumberToString objects
Browse files Browse the repository at this point in the history
Simplified code by removing local `convert` function objects, and just
calling the new `ConvertNumberToString` convenience function instead.
  • Loading branch information
N-Dekker authored and dzenanz committed Mar 23, 2022
1 parent d3daa71 commit c00f18a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 55 deletions.
28 changes: 12 additions & 16 deletions Modules/Core/Common/src/itkArrayOutputSpecialization.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ namespace itk
template <>
std::ostream & operator<<<double>(std::ostream & os, const Array<double> & arr)
{
NumberToString<double> convert;
os << "[";
const size_t length = arr.size();
if (length >= 1)
{
const size_t last = length - 1;
for (size_t i = 0; i < last; ++i)
{
os << convert(arr[i]) << ", ";
os << ConvertNumberToString(arr[i]) << ", ";
}
os << convert(arr[last]);
os << ConvertNumberToString(arr[last]);
}
os << "]";
return os;
Expand All @@ -43,17 +42,16 @@ std::ostream & operator<<<double>(std::ostream & os, const Array<double> & arr)
template <>
std::ostream & operator<<<float>(std::ostream & os, const Array<float> & arr)
{
NumberToString<float> convert;
os << "[";
const size_t length = arr.size();
if (length >= 1)
{
const size_t last = length - 1;
for (size_t i = 0; i < last; ++i)
{
os << convert(static_cast<float>(arr[i])) << ", ";
os << ConvertNumberToString(arr[i]) << ", ";
}
os << convert(static_cast<float>(arr[last]));
os << ConvertNumberToString(arr[last]);
}
os << "]";
return os;
Expand All @@ -62,9 +60,8 @@ std::ostream & operator<<<float>(std::ostream & os, const Array<float> & arr)
template <>
std::ostream & operator<<<double>(std::ostream & os, const Array2D<double> & arr)
{
NumberToString<double> convert;
const unsigned int numberOfRows = arr.rows();
const unsigned int numberOfColumns = arr.cols();
const unsigned int numberOfRows = arr.rows();
const unsigned int numberOfColumns = arr.cols();

for (unsigned int r = 0; r < numberOfRows; ++r)
{
Expand All @@ -74,9 +71,9 @@ std::ostream & operator<<<double>(std::ostream & os, const Array2D<double> & arr
const unsigned int lastColumn = numberOfColumns - 1;
for (unsigned int c = 0; c < lastColumn; ++c)
{
os << convert(arr(r, c)) << ", ";
os << ConvertNumberToString(arr(r, c)) << ", ";
}
os << convert(arr(r, lastColumn));
os << ConvertNumberToString(arr(r, lastColumn));
}
os << "]" << std::endl;
}
Expand All @@ -87,9 +84,8 @@ std::ostream & operator<<<double>(std::ostream & os, const Array2D<double> & arr
template <>
std::ostream & operator<<<float>(std::ostream & os, const Array2D<float> & arr)
{
NumberToString<float> convert;
const unsigned int numberOfRows = arr.rows();
const unsigned int numberOfColumns = arr.cols();
const unsigned int numberOfRows = arr.rows();
const unsigned int numberOfColumns = arr.cols();

for (unsigned int r = 0; r < numberOfRows; ++r)
{
Expand All @@ -99,9 +95,9 @@ std::ostream & operator<<<float>(std::ostream & os, const Array2D<float> & arr)
const unsigned int lastColumn = numberOfColumns - 1;
for (unsigned int c = 0; c < lastColumn; ++c)
{
os << convert(arr(r, c)) << ", ";
os << ConvertNumberToString(arr(r, c)) << ", ";
}
os << convert(arr(r, lastColumn));
os << ConvertNumberToString(arr(r, lastColumn));
}
os << "]" << std::endl;
}
Expand Down
7 changes: 3 additions & 4 deletions Modules/IO/MeshBYU/include/itkBYUMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@ class ITKIOMeshBYU_EXPORT BYUMeshIO : public MeshIOBase
void
WritePoints(T * buffer, std::ofstream & outputFile)
{
NumberToString<T> convert;
Indent indent(1);
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
Indent indent(1);
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();

for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
{
outputFile << indent;
for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
{
outputFile << convert(buffer[index++]) << " ";
outputFile << ConvertNumberToString(buffer[index++]) << " ";
}
outputFile << '\n';
}
Expand Down
3 changes: 1 addition & 2 deletions Modules/IO/MeshBase/include/itkMeshIOBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,11 @@ class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject
SizeValueType numberOfLines,
SizeValueType numberOfComponents)
{
NumberToString<T> convert;
for (SizeValueType ii = 0; ii < numberOfLines; ++ii)
{
for (SizeValueType jj = 0; jj < numberOfComponents; ++jj)
{
outputFile << convert(buffer[ii * numberOfComponents + jj]) << " ";
outputFile << ConvertNumberToString(buffer[ii * numberOfComponents + jj]) << " ";
}
outputFile << '\n';
}
Expand Down
10 changes: 4 additions & 6 deletions Modules/IO/MeshOBJ/include/itkOBJMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ class ITKIOMeshOBJ_EXPORT OBJMeshIO : public MeshIOBase
void
WritePoints(T * buffer, std::ofstream & outputFile)
{
NumberToString<T> convert;
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();

for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
{
outputFile << "v ";
for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
{
outputFile << convert(buffer[index++]) << " ";
outputFile << ConvertNumberToString(buffer[index++]) << " ";
}
outputFile << '\n';
}
Expand Down Expand Up @@ -155,15 +154,14 @@ class ITKIOMeshOBJ_EXPORT OBJMeshIO : public MeshIOBase
void
WritePointData(T * buffer, std::ofstream & outputFile)
{
NumberToString<T> convert;
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();
SizeValueType index = itk::NumericTraits<SizeValueType>::ZeroValue();

for (SizeValueType ii = 0; ii < this->m_NumberOfPointPixels; ++ii)
{
outputFile << "vn ";
for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
{
outputFile << convert(buffer[index++]) << " ";
outputFile << ConvertNumberToString(buffer[index++]) << " ";
}

outputFile << '\n';
Expand Down
46 changes: 22 additions & 24 deletions Modules/IO/MeshVTK/include/itkVTKPolyDataMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
void
WritePointsBufferAsASCII(std::ofstream & outputFile, T * buffer, const StringType & pointComponentType)
{
NumberToString<T> convert;
/** 1. Write number of points */
outputFile << "POINTS " << this->m_NumberOfPoints;

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

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

return;
Expand Down Expand Up @@ -725,7 +724,6 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
void
WritePointDataBufferAsASCII(std::ofstream & outputFile, T * buffer, const StringType & pointPixelComponentName)
{
NumberToString<T> convert;
MetaDataDictionary & metaDic = this->GetMetaDataDictionary();
StringType dataName;

Expand Down Expand Up @@ -795,16 +793,17 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
while (i < num)
{
// row 1
outputFile << convert(*ptr++) << indent;
outputFile << ConvertNumberToString(*ptr++) << indent;
e12 = *ptr++;
outputFile << convert(e12) << indent;
outputFile << convert(zero) << '\n';
outputFile << ConvertNumberToString(e12) << indent;
outputFile << ConvertNumberToString(zero) << '\n';
// row 2
outputFile << convert(e12) << indent;
outputFile << convert(*ptr++) << indent;
outputFile << convert(zero) << '\n';
outputFile << ConvertNumberToString(e12) << indent;
outputFile << ConvertNumberToString(*ptr++) << indent;
outputFile << ConvertNumberToString(zero) << '\n';
// row 3
outputFile << convert(zero) << indent << convert(zero) << indent << convert(zero) << "\n\n";
outputFile << ConvertNumberToString(zero) << indent << ConvertNumberToString(zero) << indent
<< ConvertNumberToString(zero) << "\n\n";
i += 3;
}
}
Expand All @@ -816,20 +815,20 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
while (i < num)
{
// row 1
outputFile << convert(*ptr++) << indent;
outputFile << ConvertNumberToString(*ptr++) << indent;
e12 = *ptr++;
outputFile << convert(e12) << indent;
outputFile << ConvertNumberToString(e12) << indent;
e13 = *ptr++;
outputFile << convert(e13) << '\n';
outputFile << ConvertNumberToString(e13) << '\n';
// row 2
outputFile << convert(e12) << indent;
outputFile << convert(*ptr++) << indent;
outputFile << ConvertNumberToString(e12) << indent;
outputFile << ConvertNumberToString(*ptr++) << indent;
e23 = *ptr++;
outputFile << convert(e23) << '\n';
outputFile << ConvertNumberToString(e23) << '\n';
// row 3
outputFile << convert(e13) << indent;
outputFile << convert(e23) << indent;
outputFile << convert(*ptr++) << "\n\n";
outputFile << ConvertNumberToString(e13) << indent;
outputFile << ConvertNumberToString(e23) << indent;
outputFile << ConvertNumberToString(*ptr++) << "\n\n";
i += 6;
}
}
Expand All @@ -847,9 +846,9 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
{
for (jj = 0; jj < this->m_NumberOfPointPixelComponents - 1; ++jj)
{
outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]) << indent;
outputFile << ConvertNumberToString(buffer[ii * this->m_NumberOfPointPixelComponents + jj]) << indent;
}
outputFile << convert(buffer[ii * this->m_NumberOfPointPixelComponents + jj]);
outputFile << ConvertNumberToString(buffer[ii * this->m_NumberOfPointPixelComponents + jj]);
outputFile << '\n';
}
}
Expand Down Expand Up @@ -1124,14 +1123,13 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
unsigned int numberOfPixelComponents,
SizeValueType numberOfPixels)
{
NumberToString<float> convert;
outputFile << numberOfPixelComponents << "\n";
Indent indent(2);
for (SizeValueType ii = 0; ii < numberOfPixels; ++ii)
{
for (unsigned int jj = 0; jj < numberOfPixelComponents; ++jj)
{
outputFile << convert(static_cast<float>(buffer[ii * numberOfPixelComponents + jj])) << indent;
outputFile << ConvertNumberToString(static_cast<float>(buffer[ii * numberOfPixelComponents + jj])) << indent;
}

outputFile << "\n";
Expand Down
5 changes: 2 additions & 3 deletions Modules/IO/TransformInsightLegacy/src/itkTxtTransformIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,13 @@ template <typename TParametersValueType>
inline void
print_vector(std::ofstream & s, vnl_vector<TParametersValueType> const & v)
{
NumberToString<TParametersValueType> convert;
for (unsigned int i = 0; i + 1 < v.size(); ++i)
{
s << convert(v[i]) << ' ';
s << ConvertNumberToString(v[i]) << ' ';
}
if (!v.empty())
{
s << convert(v.back());
s << ConvertNumberToString(v.back());
}
}
} // namespace itk_impl_details
Expand Down

0 comments on commit c00f18a

Please sign in to comment.