Skip to content

Commit dc9dbc9

Browse files
ENH: Adopt PrintNumericTrait helper toolkit-wide
Replace 513 PrintSelf NumericTraits-cast call sites across 221 files in Modules/ with calls to itk::print_helper::PrintNumericTrait. The conversion targets only the canonical standalone-statement form of the boilerplate os << indent << "NAME: " << static_cast<typename NumericTraits<TYPE>::PrintType>(EXPR) << std::endl; in 1- and 2-line variants, with or without the typename keyword and with or without the itk:: namespace qualifier. Method-call expressions (this->GetX()) are handled. Chained streaming statements that emit multiple members from a single os<<... expression are intentionally not rewritten — those would not be a drop-in replacement and are easier to leave under reviewer discretion. The cast-through-NumericTraits is preserved for char-family integer types (rendered numerically) and elided for every other type by the helper's constexpr branch. No observable behavior change at runtime. Co-Authored-By: Jon Haitz Legarreta Gorroño <jhlegarreta@users.noreply.github.com>
1 parent 79841ed commit dc9dbc9

221 files changed

Lines changed: 748 additions & 1123 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Modules/Core/Common/include/itkAnnulusOperator.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "itkNeighborhoodOperator.h"
2222
#include "itkVector.h"
23+
#include "itkPrintHelper.h"
2324

2425
namespace itk
2526
{
@@ -225,13 +226,10 @@ class ITK_TEMPLATE_EXPORT AnnulusOperator : public NeighborhoodOperator<TPixel,
225226
os << indent << "Thickness: " << m_Thickness << std::endl;
226227
os << indent << "Normalize: " << m_Normalize << std::endl;
227228
os << indent << "BrightCenter: " << m_BrightCenter << std::endl;
228-
os << indent << "InteriorValue: " << static_cast<typename NumericTraits<PixelType>::PrintType>(m_InteriorValue)
229-
<< std::endl;
230-
os << indent << "AnnulusValue: " << static_cast<typename NumericTraits<PixelType>::PrintType>(m_AnnulusValue)
231-
<< std::endl;
232-
os << indent << "ExteriorValue: " << static_cast<typename NumericTraits<PixelType>::PrintType>(m_ExteriorValue)
233-
<< std::endl;
234-
os << indent << "Spacing: " << static_cast<typename NumericTraits<SpacingType>::PrintType>(m_Spacing) << std::endl;
229+
itk::print_helper::PrintNumericTrait(os, indent, "InteriorValue", m_InteriorValue);
230+
itk::print_helper::PrintNumericTrait(os, indent, "AnnulusValue", m_AnnulusValue);
231+
itk::print_helper::PrintNumericTrait(os, indent, "ExteriorValue", m_ExteriorValue);
232+
itk::print_helper::PrintNumericTrait(os, indent, "Spacing", m_Spacing);
235233
}
236234

237235
protected:

Modules/Core/Common/include/itkBinaryThresholdSpatialFunction.hxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define itkBinaryThresholdSpatialFunction_hxx
2020

2121

22+
#include "itkPrintHelper.h"
2223
namespace itk
2324
{
2425

@@ -28,12 +29,8 @@ BinaryThresholdSpatialFunction<TFunction>::PrintSelf(std::ostream & os, Indent i
2829
{
2930
Superclass::PrintSelf(os, indent);
3031

31-
os << indent
32-
<< "LowerThreshold: " << static_cast<typename NumericTraits<FunctionOutputType>::PrintType>(m_LowerThreshold)
33-
<< std::endl;
34-
os << indent
35-
<< "UpperThreshold: " << static_cast<typename NumericTraits<FunctionOutputType>::PrintType>(m_UpperThreshold)
36-
<< std::endl;
32+
itk::print_helper::PrintNumericTrait(os, indent, "LowerThreshold", m_LowerThreshold);
33+
itk::print_helper::PrintNumericTrait(os, indent, "UpperThreshold", m_UpperThreshold);
3734

3835
itkPrintSelfObjectMacro(Function);
3936
}

Modules/Core/Common/include/itkImageDuplicator.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define itkImageDuplicator_hxx
2020

2121
#include "itkImageAlgorithm.h"
22+
#include "itkPrintHelper.h"
2223

2324
namespace itk
2425
{
@@ -64,8 +65,7 @@ ImageDuplicator<TInputImage>::PrintSelf(std::ostream & os, Indent indent) const
6465
itkPrintSelfObjectMacro(InputImage);
6566
itkPrintSelfObjectMacro(DuplicateImage);
6667

67-
os << indent << "InternalImageTime: " << static_cast<NumericTraits<ModifiedTimeType>::PrintType>(m_InternalImageTime)
68-
<< std::endl;
68+
itk::print_helper::PrintNumericTrait(os, indent, "InternalImageTime", m_InternalImageTime);
6969
}
7070
} // end namespace itk
7171

Modules/Core/Common/include/itkMinimumMaximumImageCalculator.hxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define itkMinimumMaximumImageCalculator_hxx
2020

2121
#include "itkImageRegionConstIteratorWithIndex.h"
22+
#include "itkPrintHelper.h"
2223

2324
namespace itk
2425
{
@@ -113,8 +114,8 @@ MinimumMaximumImageCalculator<TInputImage>::PrintSelf(std::ostream & os, Indent
113114
{
114115
Superclass::PrintSelf(os, indent);
115116

116-
os << indent << "Minimum: " << static_cast<typename NumericTraits<PixelType>::PrintType>(m_Minimum) << std::endl;
117-
os << indent << "Maximum: " << static_cast<typename NumericTraits<PixelType>::PrintType>(m_Maximum) << std::endl;
117+
itk::print_helper::PrintNumericTrait(os, indent, "Minimum", m_Minimum);
118+
itk::print_helper::PrintNumericTrait(os, indent, "Maximum", m_Maximum);
118119
os << indent << "Index of Minimum: " << m_IndexOfMinimum << std::endl;
119120
os << indent << "Index of Maximum: " << m_IndexOfMaximum << std::endl;
120121
itkPrintSelfObjectMacro(Image);

Modules/Core/Common/include/itkNeighborhood.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ void
117117
Neighborhood<TPixel, VDimension, TContainer>::PrintSelf(std::ostream & os, Indent indent) const
118118
{
119119
using namespace itk::print_helper;
120-
os << indent << "Size: " << static_cast<typename NumericTraits<SizeType>::PrintType>(m_Size) << std::endl;
121-
os << indent << "Radius: " << static_cast<typename NumericTraits<SizeType>::PrintType>(m_Radius) << std::endl;
120+
itk::print_helper::PrintNumericTrait(os, indent, "Size", m_Size);
121+
itk::print_helper::PrintNumericTrait(os, indent, "Radius", m_Radius);
122122
os << indent << "StrideTable: " << m_StrideTable << std::endl;
123123
os << indent << "OffsetTable: " << m_OffsetTable << std::endl;
124124
}

Modules/Core/Common/include/itkObjectStore.hxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ ObjectStore<TObjectType>::PrintSelf(std::ostream & os, Indent indent) const
134134
Superclass::PrintSelf(os, indent);
135135

136136
os << indent << "GrowthStrategy: " << m_GrowthStrategy << std::endl;
137-
os << indent << "Size: " << static_cast<NumericTraits<SizeValueType>::PrintType>(m_Size) << std::endl;
138-
os << indent << "LinearGrowthSize: " << static_cast<NumericTraits<SizeValueType>::PrintType>(m_LinearGrowthSize)
139-
<< std::endl;
137+
itk::print_helper::PrintNumericTrait(os, indent, "Size", m_Size);
138+
itk::print_helper::PrintNumericTrait(os, indent, "LinearGrowthSize", m_LinearGrowthSize);
140139
os << indent << "FreeList: " << m_FreeList << std::endl;
141140
}
142141
} // end namespace itk

Modules/Core/Common/include/itkPointSetToImageFilter.hxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "itkBoundingBox.h"
2323
#include "itkNumericTraits.h"
2424
#include "itkMath.h"
25+
#include "itkPrintHelper.h"
2526

2627
namespace itk
2728
{
@@ -227,10 +228,8 @@ PointSetToImageFilter<TInputPointSet, TOutputImage>::PrintSelf(std::ostream & os
227228
os << indent << "Origin: " << m_Origin << std::endl;
228229
os << indent << "Spacing: " << m_Spacing << std::endl;
229230
os << indent << "Direction: " << m_Direction << std::endl;
230-
os << indent << "Inside Value : " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_InsideValue)
231-
<< std::endl;
232-
os << indent << "Outside Value : " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_OutsideValue)
233-
<< std::endl;
231+
itk::print_helper::PrintNumericTrait(os, indent, "Inside Value ", m_InsideValue);
232+
itk::print_helper::PrintNumericTrait(os, indent, "Outside Value ", m_OutsideValue);
234233
}
235234
} // end namespace itk
236235

Modules/Core/Common/include/itkResourceProbe.hxx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,16 @@ ResourceProbe<ValueType, MeanType>::Print(std::ostream & os, Indent indent) cons
5858
{
5959
using namespace print_helper;
6060

61-
os << indent << "StartValue: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_StartValue)
62-
<< std::endl;
63-
os << indent << "TotalValue: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_TotalValue)
64-
<< std::endl;
65-
os << indent << "MinimumValue: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_MinimumValue)
66-
<< std::endl;
67-
os << indent << "MaximumValue: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_MaximumValue)
68-
<< std::endl;
69-
os << indent
70-
<< "StandardDeviation: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_StandardDeviation)
71-
<< std::endl;
72-
os << indent << "StandardError: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_StandardError)
73-
<< std::endl;
74-
75-
os << indent << "NumberOfStarts: " << static_cast<NumericTraits<CountType>::PrintType>(m_NumberOfStarts) << std::endl;
76-
os << indent << "NumberOfStops: " << static_cast<NumericTraits<CountType>::PrintType>(m_NumberOfStops) << std::endl;
77-
os << indent << "NumberOfIteration: " << static_cast<NumericTraits<CountType>::PrintType>(m_NumberOfIteration)
78-
<< std::endl;
61+
itk::print_helper::PrintNumericTrait(os, indent, "StartValue", m_StartValue);
62+
itk::print_helper::PrintNumericTrait(os, indent, "TotalValue", m_TotalValue);
63+
itk::print_helper::PrintNumericTrait(os, indent, "MinimumValue", m_MinimumValue);
64+
itk::print_helper::PrintNumericTrait(os, indent, "MaximumValue", m_MaximumValue);
65+
itk::print_helper::PrintNumericTrait(os, indent, "StandardDeviation", m_StandardDeviation);
66+
itk::print_helper::PrintNumericTrait(os, indent, "StandardError", m_StandardError);
67+
68+
itk::print_helper::PrintNumericTrait(os, indent, "NumberOfStarts", m_NumberOfStarts);
69+
itk::print_helper::PrintNumericTrait(os, indent, "NumberOfStops", m_NumberOfStops);
70+
itk::print_helper::PrintNumericTrait(os, indent, "NumberOfIteration", m_NumberOfIteration);
7971

8072
os << indent << "ProbeValueList: " << m_ProbeValueList << std::endl;
8173

Modules/Core/GPUCommon/include/itkGPUReduction.hxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define itkGPUReduction_hxx
2020

2121
#include "itkMacro.h"
22+
#include "itkPrintHelper.h"
2223

2324
// #define CPU_VERIFY
2425

@@ -59,8 +60,8 @@ GPUReduction<TElement>::PrintSelf(std::ostream & os, Indent indent) const
5960
os << indent << "Size: " << m_Size << std::endl;
6061
itkPrintSelfBooleanMacro(SmallBlock);
6162

62-
os << indent << "GPUResult: " << static_cast<typename NumericTraits<TElement>::PrintType>(m_GPUResult) << std::endl;
63-
os << indent << "CPUResult: " << static_cast<typename NumericTraits<TElement>::PrintType>(m_CPUResult) << std::endl;
63+
itk::print_helper::PrintNumericTrait(os, indent, "GPUResult", m_GPUResult);
64+
itk::print_helper::PrintNumericTrait(os, indent, "CPUResult", m_CPUResult);
6465
}
6566

6667
template <typename TElement>

Modules/Core/ImageFunction/include/itkBSplineInterpolateImageFunction.hxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ BSplineInterpolateImageFunction<TImageType, TCoordinate, TCoefficientType>::Prin
5959
Superclass::PrintSelf(os, indent);
6060

6161
os << indent << "Scratch: " << m_Scratch << std::endl;
62-
os << indent
63-
<< "DataLength: " << static_cast<typename NumericTraits<typename TImageType::SizeType>::PrintType>(m_DataLength)
64-
<< std::endl;
62+
itk::print_helper::PrintNumericTrait(os, indent, "DataLength", m_DataLength);
6563
os << indent << "SplineOrder: " << m_SplineOrder << std::endl;
6664

6765
itkPrintSelfObjectMacro(Coefficients);
@@ -73,8 +71,7 @@ BSplineInterpolateImageFunction<TImageType, TCoordinate, TCoefficientType>::Prin
7371

7472
itkPrintSelfBooleanMacro(UseImageDirection);
7573

76-
os << indent << "NumberOfWorkUnits: " << static_cast<NumericTraits<ThreadIdType>::PrintType>(m_NumberOfWorkUnits)
77-
<< std::endl;
74+
itk::print_helper::PrintNumericTrait(os, indent, "NumberOfWorkUnits", m_NumberOfWorkUnits);
7875

7976
os << indent << "ThreadedEvaluateIndex: ";
8077
if (m_ThreadedEvaluateIndex != nullptr)

0 commit comments

Comments
 (0)