-
-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STYLE: Make PrintSelf
implementation style consistent
#3872
STYLE: Make PrintSelf
implementation style consistent
#3872
Conversation
8ba8047
to
a53a4cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! There are still a few compile errors.
I know. Still WIP/draft. I have other changes locally, but unsure whether I should split it across at least 2 PRs, as it is becoming difficult to deal with. Also it is not intended to be comprehensive, as unfortunately, this is not an automated change. I also grant that some changes belong to |
Having it as a single commit is fine. I know that splitting into themed commits requires extra effort. |
Amazing work getting this more consistent!
One other issue that some time occurs with the print self methods is when "pixel types" are char. When they are a char then they are printed as an ASCII char and not a numeric value as expected. This is a case where the NumbericTraits::PrintType must be used. This is clearly separate work. |
Thanks Brad.
Will rework the commit message as time permits and as I revise all the changes contained.
Yes, had that in mind, but did not take the chance to make the changes. Will try to do that for the ivars that I'll be streaming, but will not be checking the existing ones as a general rule. Note that this process is not automated, and I do not intend it to be comprehensive across the entire code base, but just a first step: I have mainly looked at some given patterns (like containing equal signs, etc.). Also, it will take me some time until I can get a working version. For now, it is still WIP. |
db723f1
to
19557f6
Compare
96bc1cd
to
1edc5e3
Compare
1a7fbfd
to
d257b97
Compare
361f692
to
4aee9a9
Compare
Make `PrintSelf`implementation style consistent following the ITK SWG coding style guideline and the available ITK macros: - Always print the superclass first. - Print only the class instance variables. - Use the `os << indent << "{ivarName}: " << m_ivarName << std::endl` recipe: do not print the leading `m_` of the ivar; use a colon after printing its name; leave a whitespace between the colon and the printed value of the ivar. - For boolean ivars print `On`/`Off` according to their values using the ternary operator. - Use `itkPrintSelfObjectMacro` to print objects inheriting from `itk::LightObject` that can be null. - For pointers that do not inherit from `itk::LightObject` check whether they are non-null before attempting to print them and print the `(empty)` string otherwise. - Rely on the self printing ability of the ITK classes to avoid boilerplate code when printing the corresponding ivars in other classes' `PrintSelf` methods. - Take advantage of the output stream `<<` insertion operator overload for `std::vector` types in the `itk::print_helper` namespace defined in `itkPrintHelper.h` to print such types consistently. - Cast custom types to their numerical values using `itk::NumericTraits::PrinType` so that they are printed as expected. - Remove statements printing the hard-coded class name and its own pointer, e.g. ``` os << indent << "ArrowSpatialObject(" << this << ")" << std::endl; ``` `PrintSelf` does this without requiring the removed line. - Save typing `this->` to point to the instance of the current class. Apply the same principles to the `<<` operator overloads. Overload the ostream operator for the `FixedImageSamplePoint` class used by the `itk::ImageToImageMetric` class. Overload the ostream operator for the `ImageVoxel` class used by the `itk::DeformableSimplexMesh3DGradientConstraintForceFilter` class.
4aee9a9
to
173752f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on a glance.
Modules/Core/ImageFunction/include/itkBSplineInterpolateImageFunction.hxx
Show resolved
Hide resolved
Modules/Nonunit/Review/include/itkMultiphaseSparseFiniteDifferenceImageFilter.hxx
Show resolved
Hide resolved
itkPrintSelfObject(Material);
itkPrintSelfObjectMacro(Element); Does |
Again, thanks for the heads-up @issakomi. You're right, it should be |
Thanks @jhlegarreta. |
Oh, my bad. I did not have the |
PR #3918. |
Make
PrintSelf
implementation style consistent following the ITK SWGcoding style guideline and the available ITK macros:
os << indent << "{ivarName}: " << m_ivarName << std::endl
recipe: do not print the leading
m_
of the ivar; use a colon afterprinting its name; leave a whitespace between the colon and the
printed value of the ivar.
On
/Off
according to their values using theternary operator.
itkPrintSelfObjectMacro
to print objects inheriting fromitk::LightObject
that can be null.itk::LightObject
check whetherthey are non-null before attempting to print them and print the
(empty)
string otherwise.boilerplate code when printing the corresponding ivars in other
classes'
PrintSelf
methods.<<
insertion operator overloadfor
std::vector
types in theitk::print_helper
namespace definedin
itkPrintHelper.h
to print such types consistently.itk::NumericTraits::PrinType
so that they are printed as expected.pointer, e.g.
PrintSelf
does this without requiring the removed line.this->
to point to the instance of the current class.Apply the same principles to the
<<
operator overloads.Overload the ostream operator for the
FixedImageSamplePoint
class usedby the
itk::ImageToImageMetric
class.Overload the ostream operator for the
ImageVoxel
class used by theitk::DeformableSimplexMesh3DGradientConstraintForceFilter
class.Overload the ostream operator for the
ImageVoxel
class used by theitk::DeformableSimplexMesh3DGradientConstraintForceFilter
class.PR Checklist