Skip to content

Commit

Permalink
ENH: Print all member variables.
Browse files Browse the repository at this point in the history
Print all member variables.

Take advantage of the commit to
- Use the `itk::NumericTraits::PrintType` definition, the `print_helper`-enabled
  overload for array-like types, and the `itkPrintSelfObjectMacro` macro
  to improve how the ivars and objects that can be null pointers are printed.
- Print the member variables in the same order they were declared for the
  sake of consistency.
- Print the member variable names verbatim to conform to the ITK SW Guide.
  • Loading branch information
jhlegarreta authored and dzenanz committed Feb 24, 2021
1 parent 6ce1c4e commit 4334133
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "itkCastImageFilter.h"

#include "itkMath.h"
#include "itkPrintHelper.h"

namespace itk
{
Expand Down Expand Up @@ -233,25 +234,19 @@ void
DisplacementFieldJacobianDeterminantFilter<TInputImage, TRealType, TOutputImage>::PrintSelf(std::ostream & os,
Indent indent) const
{
unsigned int i;
using namespace print_helper;

Superclass::PrintSelf(os, indent);
os << indent << "m_UseImageSpacing = " << m_UseImageSpacing << std::endl;
os << indent << "m_RequestedNumberOfThreads = " << m_RequestedNumberOfThreads << std::endl;
os << indent << "m_DerivativeWeights = ";
for (i = 0; i < ImageDimension; i++)
{
os << m_DerivativeWeights[i] << " ";
}
os << std::endl;
os << indent << "m_HalfDerivativeWeights = ";
for (i = 0; i < ImageDimension; i++)
{
os << m_HalfDerivativeWeights[i] << " ";
}
os << std::endl;
os << indent << "m_NeighborhoodRadius = " << m_NeighborhoodRadius << std::endl;
os << indent << "m_RealValuedInputImage = " << m_RealValuedInputImage.GetPointer() << std::endl;

os << indent << "DerivativeWeights: " << m_DerivativeWeights << std::endl;
os << indent << "HalfDerivativeWeights: " << m_HalfDerivativeWeights << std::endl;
os << indent << "UseImageSpacing: " << m_UseImageSpacing << std::endl;
os << indent << "RequestedNumberOfThreads: "
<< static_cast<typename NumericTraits<ThreadIdType>::PrintType>(m_RequestedNumberOfThreads) << std::endl;
os << indent << "RealValuedInputImage: " << m_RealValuedInputImage.GetPointer() << std::endl;
os << indent
<< "NeighborhoodRadius: " << static_cast<typename NumericTraits<RadiusType>::PrintType>(m_NeighborhoodRadius)
<< std::endl;
}
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "itkProgressReporter.h"
#include "itkMacro.h"
#include "itkMath.h"
#include "itkPrintHelper.h"

namespace itk
{
Expand Down Expand Up @@ -213,11 +214,24 @@ template <typename TInputImage1, typename TInputImage2>
void
DirectedHausdorffDistanceImageFilter<TInputImage1, TInputImage2>::PrintSelf(std::ostream & os, Indent indent) const
{
using namespace print_helper;

Superclass::PrintSelf(os, indent);

os << indent << "DirectedHausdorffDistance: " << m_DirectedHausdorffDistance << std::endl;
os << indent << "AverageHausdorffDistance: " << m_AverageHausdorffDistance << std::endl;
os << indent << "Use Image Spacing : " << m_UseImageSpacing << std::endl;
os << indent << "DistanceMap: " << m_DistanceMap << std::endl;
os << indent << "MaxDistance: " << m_MaxDistance << std::endl;
os << indent << "PixelCount:" << m_PixelCount << std::endl;
os << indent << "Sum: ";
for (auto const & elem : m_Sum)
{
std::cout << elem.GetSum() << " ";
}
os << std::endl;
os << indent << "DirectedHausdorffDistance: "
<< static_cast<typename NumericTraits<RealType>::PrintType>(m_DirectedHausdorffDistance) << std::endl;
os << indent << "AverageHausdorffDistance: "
<< static_cast<typename NumericTraits<RealType>::PrintType>(m_AverageHausdorffDistance) << std::endl;
os << indent << "UseImageSpacing : " << m_UseImageSpacing << std::endl;
}
} // end namespace itk
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "itkCastImageFilter.h"

#include "itkMath.h"
#include "itkPrintHelper.h"

namespace itk
{
Expand All @@ -45,25 +46,19 @@ void
VectorGradientMagnitudeImageFilter<TInputImage, TRealType, TOutputImage>::PrintSelf(std::ostream & os,
Indent indent) const
{
unsigned i;
using namespace print_helper;

Superclass::PrintSelf(os, indent);
os << indent << "m_UseImageSpacing = " << m_UseImageSpacing << std::endl;
os << indent << "m_UsePrincipleComponents = " << m_UsePrincipleComponents << std::endl;
os << indent << "m_RequestedNumberOfThreads = " << m_RequestedNumberOfThreads << std::endl;
os << indent << "m_DerivativeWeights = ";
for (i = 0; i < ImageDimension; i++)
{
os << m_DerivativeWeights[i] << " ";
}
os << std::endl;
os << indent << "m_ComponentWeights = ";
for (i = 0; i < VectorDimension; i++)
{
os << m_ComponentWeights[i] << " ";
}
os << std::endl;
os << indent << "m_RealValuedInputImage = " << m_RealValuedInputImage.GetPointer() << std::endl;

os << indent << "DerivativeWeights: " << m_DerivativeWeights << std::endl;
os << indent << "ComponentWeights: " << m_ComponentWeights << std::endl;
os << indent << "SqrtComponentWeights: " << m_SqrtComponentWeights << std::endl;
os << indent << "UseImageSpacing: " << m_UseImageSpacing << std::endl;
os << indent << "UsePrincipleComponents: " << m_UsePrincipleComponents << std::endl;
os << indent << "RequestedNumberOfThreads: "
<< static_cast<typename NumericTraits<ThreadIdType>::PrintType>(m_RequestedNumberOfThreads) << std::endl;

itkPrintSelfObjectMacro(RealValuedInputImage);
}

template <typename TInputImage, typename TRealType, typename TOutputImage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define itkImagePCAShapeModelEstimator_hxx

#include "itkImagePCAShapeModelEstimator.h"
#include "itkPrintHelper.h"

namespace itk
{
Expand All @@ -38,41 +39,22 @@ template <typename TInputImage, typename TOutputImage>
void
ImagePCAShapeModelEstimator<TInputImage, TOutputImage>::PrintSelf(std::ostream & os, Indent indent) const
{
os << indent << " " << std::endl;
os << indent << "Shape Models " << std::endl;
os << indent << "Results printed in the superclass " << std::endl;
os << indent << " " << std::endl;
using namespace print_helper;

Superclass::PrintSelf(os, indent);

itkDebugMacro(<< " ");
itkDebugMacro(<< "Results of the shape model algorithms");
itkDebugMacro(<< "====================================");

itkDebugMacro(<< "The eigen values new method are: ");

itkDebugMacro(<< m_EigenValues);
itkDebugMacro(<< m_EigenVectorNormalizedEnergy);

itkDebugMacro(<< " ");
itkDebugMacro(<< "================== ");

itkDebugMacro(<< "The eigen vectors new method are: ");

for (unsigned int i = 0; i < m_EigenValues.size(); i++)
{
itkDebugMacro(<< m_EigenVectors.get_row(i));
}

itkDebugMacro(<< " ");
itkDebugMacro(<< "+++++++++++++++++++++++++");

// Print out ivars
os << indent << "NumberOfPrincipalComponentsRequired: ";
os << m_NumberOfPrincipalComponentsRequired << std::endl;
os << indent << "NumberOfTrainingImages: ";
os << m_NumberOfTrainingImages << std::endl;
} // end PrintSelf
os << indent << "InputImageIteratorArray size: " << m_InputImageIteratorArray.size() << std::endl;
os << indent << "Means: " << m_Means << std::endl;
os << indent << "InnerProduct: " << m_InnerProduct << std::endl;
os << indent << "EigenVectors: " << m_EigenVectors << std::endl;
os << indent << "EigenValues: " << m_EigenValues << std::endl;
os << indent << "EigenVectorNormalizedEnergy: " << m_EigenVectorNormalizedEnergy << std::endl;
os << indent << "InputImageSize: " << static_cast<typename NumericTraits<ImageSizeType>::PrintType>(m_InputImageSize)
<< std::endl;
os << indent << "NumberOfPixels: " << m_NumberOfPixels << std::endl;
os << indent << "NumberOfTrainingImages: " << m_NumberOfTrainingImages << std::endl;
os << indent << "NumberOfPrincipalComponentsRequired: " << m_NumberOfPrincipalComponentsRequired << std::endl;
}

/**
* Enlarge the output requested region to the largest possible region.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ void
AnchorOpenCloseImageFilter<TImage, TKernel, TCompare1, TCompare2>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

os << indent << "Boundary1: " << static_cast<typename NumericTraits<InputImagePixelType>::PrintType>(m_Boundary1)
<< std::endl;
os << indent << "Boundary2: " << static_cast<typename NumericTraits<InputImagePixelType>::PrintType>(m_Boundary2)
<< std::endl;
}

} // end namespace itk
Expand Down
6 changes: 5 additions & 1 deletion Modules/IO/MINC/src/itkMINCImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "vnl/vnl_vector.h"
#include "itkMetaDataObject.h"
#include "itkArray.h"
#include "itkPrintHelper.h"

#include <itk_minc2.h>

Expand Down Expand Up @@ -263,9 +264,12 @@ MINCImageIO::~MINCImageIO()
void
MINCImageIO::PrintSelf(std::ostream & os, Indent indent) const
{
using namespace print_helper;

Superclass::PrintSelf(os, indent);

os << indent << "NDims: " << this->m_MINCPImpl->m_NDims << std::endl;
os << indent << "MINCPImpl: " << m_MINCPImpl << std::endl;
os << indent << "DirectionCosines: " << m_DirectionCosines << std::endl;
}

void
Expand Down
2 changes: 2 additions & 0 deletions Modules/IO/MRC/src/itkMRCImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void
MRCImageIO::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

itkPrintSelfObjectMacro(MRCHeader);
}

bool
Expand Down
3 changes: 3 additions & 0 deletions Modules/IO/MeshBYU/src/itkBYUMeshIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ void
BYUMeshIO ::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

os << indent << "FilePosition: " << static_cast<typename NumericTraits<StreamOffsetType>::PrintType>(m_FilePosition)
<< std::endl;
os << indent << "PartId: " << m_PartId << std::endl;
os << indent << "First Cell Id: " << m_FirstCellId << std::endl;
os << indent << "Last Cell Id: " << m_LastCellId << std::endl;
Expand Down
6 changes: 6 additions & 0 deletions Modules/IO/NIFTI/src/itkNiftiImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ void
NiftiImageIO ::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

os << indent << "NiftiImageHolder: " << *(this->m_NiftiImageHolder).get() << std::endl;
os << indent << "NiftiImage: " << this->m_NiftiImage << std::endl;
os << indent << "RescaleSlope: " << this->m_RescaleSlope << std::endl;
os << indent << "RescaleIntercept: " << this->m_RescaleIntercept << std::endl;
os << indent << "OnDiskComponentType: " << this->m_OnDiskComponentType << std::endl;
os << indent << "LegacyAnalyze75Mode: " << this->m_LegacyAnalyze75Mode << std::endl;
}

Expand Down
2 changes: 2 additions & 0 deletions Modules/IO/NRRD/src/itkNrrdImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void
NrrdImageIO::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

os << indent << "NrrdCompressionEncoding: " << m_NrrdCompressionEncoding << std::endl;
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define itkMultiphaseSparseFiniteDifferenceImageFilter_hxx

#include "itkMultiphaseSparseFiniteDifferenceImageFilter.h"
#include "itkPrintHelper.h"


namespace itk
{
Expand Down Expand Up @@ -1390,10 +1392,35 @@ MultiphaseSparseFiniteDifferenceImageFilter<TInputImage, TFeatureImage, TOutputI
std::ostream & os,
Indent indent) const
{
using namespace print_helper;

Superclass::PrintSelf(os, indent);

os << indent << "m_IsoSurfaceValue: " << this->m_IsoSurfaceValue << std::endl;
os << indent << "m_BoundsCheckingActive: " << m_BoundsCheckingActive;
os << indent << "ConstantGradientValue: " << m_ConstantGradientValue << std::endl;
os << indent << "ValueOne: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_ValueOne) << std::endl;
os << indent << "ValueZero: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_ValueZero) << std::endl;
os << indent << "StatusChanging: " << static_cast<typename NumericTraits<StatusType>::PrintType>(m_StatusChanging)
<< std::endl;
os << indent << "StatusActiveChangingUp: "
<< static_cast<typename NumericTraits<StatusType>::PrintType>(m_StatusActiveChangingUp) << std::endl;
os << indent << "StatusActiveChangingDown: "
<< static_cast<typename NumericTraits<StatusType>::PrintType>(m_StatusActiveChangingDown) << std::endl;
os << indent
<< "StatusBoundaryPixel: " << static_cast<typename NumericTraits<StatusType>::PrintType>(m_StatusBoundaryPixel)
<< std::endl;
os << indent << "StatusNull: " << static_cast<typename NumericTraits<StatusType>::PrintType>(m_StatusNull)
<< std::endl;
os << indent << "SparseData: " << m_SparseData << std::endl;
os << indent << "NumberOfLayers: " << m_NumberOfLayers << std::endl;
os << indent << "IsoSurfaceValue: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_IsoSurfaceValue)
<< std::endl;
os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_BackgroundValue)
<< std::endl;
os << indent << "InterpolateSurfaceLocation: " << m_InterpolateSurfaceLocation << std::endl;
os << indent << "CurrentFunctionIndex: " << m_CurrentFunctionIndex << std::endl;
os << indent << "RMSSum: " << m_RMSSum << std::endl;
os << indent << "RMSCounter: " << m_RMSCounter << std::endl;
os << indent << "BoundsCheckingActive: " << m_BoundsCheckingActive << std::endl;

for (IdCellType i = 0; i < this->m_FunctionCount; i++)
{
Expand All @@ -1409,11 +1436,6 @@ MultiphaseSparseFiniteDifferenceImageFilter<TInputImage, TFeatureImage, TOutputI
os << indent << "m_UpdateBuffer: size=" << static_cast<InputSizeValueType>(sparsePtr->m_UpdateBuffer.size())
<< " capacity = " << static_cast<InputSizeValueType>(sparsePtr->m_UpdateBuffer.capacity()) << std::endl;
}

os << indent << "Interpolate Surface Location " << m_InterpolateSurfaceLocation << std::endl;
os << indent << "Number of Layers " << m_NumberOfLayers << std::endl;
os << indent << "Value Zero " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_ValueZero) << std::endl;
os << indent << "Value One " << static_cast<typename NumericTraits<ValueType>::PrintType>(m_ValueOne) << std::endl;
}
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,15 +888,23 @@ SyNImageRegistrationMethod<TFixedImage, TMovingImage, TOutputTransform, TVirtual
{
Superclass::PrintSelf(os, indent);

os << indent << "Number of current iterations per level: " << this->m_NumberOfIterationsPerLevel << std::endl;
os << indent << "Learning rate: " << this->m_LearningRate << std::endl;
os << indent << "Convergence threshold: " << this->m_ConvergenceThreshold << std::endl;
os << indent << "Convergence window size: " << this->m_ConvergenceWindowSize << std::endl;
os << indent
<< "Gaussian smoothing variance for the update field: " << this->m_GaussianSmoothingVarianceForTheUpdateField
os << indent << "LearningRate: " << static_cast<typename NumericTraits<RealType>::PrintType>(this->m_LearningRate)
<< std::endl;
os << indent
<< "Gaussian smoothing variance for the total field: " << this->m_GaussianSmoothingVarianceForTheTotalField
os << indent << "ConvergenceThreshold: "
<< static_cast<typename NumericTraits<RealType>::PrintType>(this->m_ConvergenceThreshold) << std::endl;
os << indent << "ConvergenceWindowSize: " << this->m_ConvergenceWindowSize << std::endl;

itkPrintSelfObjectMacro(MovingToMiddleTransform);
itkPrintSelfObjectMacro(FixedToMiddleTransform);

os << indent << "NumberOfIterationsPerLevel: " << this->m_NumberOfIterationsPerLevel << std::endl;
os << indent << "DownsampleImagesForMetricDerivatives: " << m_DownsampleImagesForMetricDerivatives << std::endl;
os << indent << "AverageMidPointGradients: " << m_AverageMidPointGradients << std::endl;
os << indent << "GaussianSmoothingVarianceForTheUpdateField: "
<< static_cast<typename NumericTraits<RealType>::PrintType>(this->m_GaussianSmoothingVarianceForTheUpdateField)
<< std::endl;
os << indent << "GaussianSmoothingVarianceForTheTotalField: "
<< static_cast<typename NumericTraits<RealType>::PrintType>(this->m_GaussianSmoothingVarianceForTheTotalField)
<< std::endl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,15 @@ void
ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::PrintSelf(std::ostream & os,
Indent indent) const
{
os << indent << " " << std::endl;
os << indent << "Gaussian Models generated from the training data." << std::endl;
os << indent << "TrainingImage: ";
os << m_TrainingImage.GetPointer() << std::endl;
os << indent << "Results printed in the superclass " << std::endl;
os << indent << " " << std::endl;

Superclass::PrintSelf(os, indent);
} // end PrintSelf

/**
* Generate data (start the model building process)
*/
os << indent << "NumberOfSamples: " << m_NumberOfSamples << std::endl;
os << indent << "Means: " << m_Means << std::endl;
os << indent << "Covariance: " << m_Covariance << std::endl;

itkPrintSelfObjectMacro(TrainingImage);
}

template <typename TInputImage, typename TMembershipFunction, typename TTrainingImage>
void
ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::GenerateData()
Expand Down
Loading

0 comments on commit 4334133

Please sign in to comment.