Skip to content
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

Remove implicit conversion from a single scalar value to itk::Vector #3255

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Mar 7, 2022

Follow-up to commit a890962 "ENH: Make Vector construction from scalar value explicit" by Brian Helba (@brianhelba), January 26, 2015

Analog to: pull request #3237 commit 8825834 "ENH: Declare converting Point(v) constructors explicit"

N-Dekker added 2 commits March 7, 2022 17:05
The addressed implicit conversions from a single value to a `Vector`
appear unintended. Support for such an implicit conversion is intended
to be removed in the future.
Until now, this constructor was only declared `explicit` for "future"
builds (when `ITK_LEGACY_FUTURE_REMOVE` would be enabled).

Follow-up to commit a890962
"ENH: Make Vector construction from scalar value explicit"
by Brian Helba, January 26, 2015

Added a _deleted_ `Vector(nullptr_t)` constructor, especially to avoid
erroneous user code like `VectorType v = 0`.

Analog to:
pull request InsightSoftwareConsortium#3237
commit 8825834
ENH: Declare converting `Point(v)` constructors `explicit`
@github-actions github-actions bot added area:Core Issues affecting the Core module area:Registration Issues affecting the Registration module type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct labels Mar 7, 2022
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Mar 7, 2022

@dzenanz Do you have any suggestion how to fix https://open.cdash.org/viewBuildError.php?buildid=7780689 ?

Wrapping/Modules/ITKLevelSets/itkVectorThresholdSegmentationLevelSetImageFilterPython.cpp:3906:44: error: no matching function for call to 'itk::VectorThresholdSegmentationLevelSetImageFilter<itk::Image<float, 2>, itk::Image<itk::Vector<float, 2>, 2>, float>::SetMean(const double&)'

   (arg1)->SetMean((double const &)*arg2);

I can't find that cpp file (itkVectorThresholdSegmentationLevelSetImageFilterPython.cpp), how is it generated?

@dzenanz
Copy link
Member

dzenanz commented Mar 7, 2022

That file is automatically generated by SWIG, from itkVectorThresholdSegmentationLevelSetImageFilter.wrap.

@dzenanz
Copy link
Member

dzenanz commented Mar 7, 2022

I guess that making the constructor explicit is preventing some SetMean call from compiling. The reported lines do not match my local file. I guess local python compilation is needed for hunting this down.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Mar 7, 2022

The error message does seem to make sense, because SetMean expects a Vector as argument, not just a single double value:

Of course, we could add an extra SetMean(double) overload, which would fill the Vector of mean values by the specified double value. But would that be desirable?

@dzenanz
Copy link
Member

dzenanz commented Mar 7, 2022

add an extra SetMean(double)

Sounds reasonable. And it does not force us to find where the offending call is being made 😄

@github-actions github-actions bot added type:Documentation Documentation improvement or change area:Segmentation Issues affecting the Segmentation module labels Mar 8, 2022
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still fails to compile. Matt suggested to revert in #3258.

@Leengit
Copy link
Contributor

Leengit commented Mar 8, 2022

I just deleted my previous comment.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Mar 8, 2022

This still fails to compile. Matt suggested to revert in #3258.

@dzenanz I just hope 8825834 doesn't get reverted (as suggested by PR #3258). But what can I do?

@dzenanz
Copy link
Member

dzenanz commented Mar 8, 2022

Finding bugs exposed by the explicit constructor are a great attempt, which might work if there aren't too many of them 😄

@Leengit
Copy link
Contributor

Leengit commented Mar 8, 2022

https://github.com/N-Dekker/ITK/blob/9ecef41cd9a44086050b5e62f5c4eb9b993cf8d7/Modules/Segmentation/LevelSets/include/itkVectorThresholdSegmentationLevelSetImageFilter.h#L128-L129
is failing because the compiler thinks that double might be an example of a MeanVectorType but then chokes on MeanVectorType::ValueType when that turns out not be the case. We might change

  void
  SetMean(const typename MeanVectorType::ValueType meanValue)

to

  template <typename TMeanValue>
  std::enable_if_t<std::is_same<TMeanValue, typename MeanVectorType::ValueType>::value, void>
  SetMean(const TMeanValue meanValue)

Appears necessary for `NumericTraits<MeasurementVectorType>::RealType`,
which is used to define `MeanVectorType`, indirectly.

Addresses Linux Python build errors saying:

> Wrapping/Modules/ITKLevelSets/itkVectorThresholdSegmentationLevelSetImageFilterPython.cpp:
> 3906:44: error: no matching function for call to
> `VectorThresholdSegmentationLevelSetImageFilter<Image<float, 2>, Image<Vector<float, 2>, 2>, float>::SetMean(const double&)`

At https://open.cdash.org/viewBuildError.php?buildid=7780689
@N-Dekker N-Dekker force-pushed the Remove-implicit-conversions-value-to-Vector branch from 9ecef41 to 563256a Compare March 8, 2022 17:12
@github-actions github-actions bot added area:Numerics Issues affecting the Numerics module and removed area:Segmentation Issues affecting the Segmentation module labels Mar 8, 2022
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Mar 8, 2022

the compiler thinks that double might be an example of a MeanVectorType

Thanks @Leengit but if I understand correctly, MeanVectorType should be an itk::Vector, not a double!

MeanVectorType is defined at

/** Type of the mean vector. RealType on a vector-type is the same
* vector-type but with a real element type. */
using MeasurementVectorRealType = typename itk::NumericTraits<MeasurementVectorType>::RealType;
using MeanVectorType = MeasurementVectorRealType;

My guess it now that the itk::NumericTraits specialization for itk::Vector was not available at those particular lines of code. (Without this specialization, NumericTraits::RealType might just be double.) That's why I'm now hoping to fix the errors by an #include "itkNumericTraitsVectorPixel.h". With commit 563256a

Fingers crossed please 🤞

@N-Dekker N-Dekker marked this pull request as ready for review March 8, 2022 19:58
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Mar 9, 2022

I think this pull request is ready now 😃 The missing #include "itkNumericTraitsVectorPixel.h", fixed with 563256a might be a serious bug, because MeanVectorType appears defined as double, instead of a itk::Vector, when the specific NumericTraits<Vector> specialization is not included. Problem solved! 😄

@hjmjohnson hjmjohnson merged commit c679de2 into InsightSoftwareConsortium:master Mar 9, 2022
@hjmjohnson
Copy link
Member

building AnisotropicDiffusionLBR now fails:

/Users/johnsonhj/Dashboard/src/AnisotropicDiffusionLBR/include/itkLinearAnisotropicDiffusionLBRImageFilter.hxx:480:27: error: reference to type 'const itk::Vector<double, 3>' could not bind to an rvalue of type 'double'
  m_NextImage->FillBuffer(0.);
                          ^~

NOTE: ITK_FUTURE_LEGACY_REMOVE:BOOL=ON. Some of the remote modules probably will need some TLC .

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Mar 9, 2022

Thanks for the notice, @hjmjohnson

m_NextImage->FillBuffer(0.);

What you would need here is a zero-initialized itk::Vector. In general, this can be achieved by the syntax VectorType(), or VectorType{}. (Assuming that there is a VectorType alias. Otherwise I guess something like ImageType::PixelType) But probably an empty pair of curly braces will do as well:

 m_NextImage->FillBuffer({});

HTH, Niels

PS FYI The specific Vector(r) constructor has already been explicit for more than seven years, with ITK_FUTURE_LEGACY_REMOVE=ON: a890962

@hjmjohnson
Copy link
Member

SimonRit pushed a commit to RTKConsortium/RTK that referenced this pull request Mar 11, 2022
SimonRit pushed a commit to RTKConsortium/RTK that referenced this pull request Mar 11, 2022
SimonRit pushed a commit to RTKConsortium/RTK that referenced this pull request Mar 11, 2022
SimonRit pushed a commit to RTKConsortium/RTK that referenced this pull request Mar 14, 2022
SimonRit pushed a commit to RTKConsortium/RTK that referenced this pull request Mar 16, 2022
The wrapping does not compile with ITK_LEGACY_REMOVE=ON since
InsightSoftwareConsortium/ITK#3255
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jul 25, 2022
Allowing ITK_LEGACY_REMOVE=0N for ITK version >= 5.3rc04, which made those constructors `explicit`:

 - ITK pull request InsightSoftwareConsortium/ITK#3237 commit InsightSoftwareConsortium/ITK@8825834 "ENH: Declare converting `Point(v)` constructors `explicit`"
 - ITK pull request InsightSoftwareConsortium/ITK#3255 commit InsightSoftwareConsortium/ITK@abb88cc "ENH: Make Vector constructor from scalar explicit, unless LEGACY enabled"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jul 25, 2022
Allowing ITK_LEGACY_REMOVE=0N for ITK version >= 5.3rc04, which made those constructors `explicit`:

 - ITK pull request InsightSoftwareConsortium/ITK#3237 commit InsightSoftwareConsortium/ITK@8825834 "ENH: Declare converting `Point(v)` constructors `explicit`"
 - ITK pull request InsightSoftwareConsortium/ITK#3255 commit InsightSoftwareConsortium/ITK@abb88cc "ENH: Make Vector constructor from scalar explicit, unless LEGACY enabled"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jul 25, 2022
Allowing ITK_LEGACY_REMOVE=0N for ITK version >= 5.3rc04, which made those constructors `explicit`:

 - ITK pull request InsightSoftwareConsortium/ITK#3237 commit InsightSoftwareConsortium/ITK@8825834 "ENH: Declare converting `Point(v)` constructors `explicit`"
 - ITK pull request InsightSoftwareConsortium/ITK#3255 commit InsightSoftwareConsortium/ITK@abb88cc "ENH: Make Vector constructor from scalar explicit, unless LEGACY enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Core Issues affecting the Core module area:Numerics Issues affecting the Numerics module area:Registration Issues affecting the Registration module type:Documentation Documentation improvement or change type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants