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

BUG: added 2 missing lines #4698

Merged
merged 3 commits into from
Jun 18, 2024
Merged

BUG: added 2 missing lines #4698

merged 3 commits into from
Jun 18, 2024

Conversation

seanm
Copy link
Contributor

@seanm seanm commented May 30, 2024

No description provided.

@github-actions github-actions bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:Core Issues affecting the Core module labels May 30, 2024
@seanm
Copy link
Contributor Author

seanm commented May 30, 2024

@thewtex here are the 2 missing lines you requested in #3037. I have no idea what this does or fixes though, so could you propose a proper commit message and I'll amend the commit...

@dzenanz
Copy link
Member

dzenanz commented May 30, 2024

I remember there was some discussion about this not long ago. @N-Dekker @hjmjohnson

@dzenanz
Copy link
Member

dzenanz commented May 30, 2024

This is the PR where that somewhat related discussion happened: #4485.

@thewtex
Copy link
Member

thewtex commented Jun 3, 2024

@seanm per #3037 , those lines are meant to go at the start of

template <typename TScalar, unsigned int NInputDimensions,
          unsigned int NOutputDimensions>
MatrixOffsetTransformBase<TScalar, NInputDimensions, NOutputDimensions>
::MatrixOffsetTransformBase(const MatrixType & matrix, const OutputVectorType & offset)
{
// here

@thewtex
Copy link
Member

thewtex commented Jun 3, 2024

And it may not be correct following the discussion around:

#4485 (comment)

@seanm
Copy link
Contributor Author

seanm commented Jun 3, 2024

And it may not be correct

So shall I just close/discard this?

@dzenanz dzenanz requested review from hjmjohnson and N-Dekker June 3, 2024 17:00
@dzenanz
Copy link
Member

dzenanz commented Jun 3, 2024

Ideally, Hans and/or Niels will review this 😄

@N-Dekker
Copy link
Contributor

N-Dekker commented Jun 3, 2024

Ideally, Hans and/or Niels will review this

OK, thanks @dzenanz I'll have a look! (I'm back 😃!)

@N-Dekker
Copy link
Contributor

N-Dekker commented Jun 3, 2024

I'm still looking for an actual relevant use case for the MatrixOffsetTransformBase(const MatrixType &, const OutputVectorType &) constructor. It's protected, and it isn't being used by MatrixOffsetTransformBase::New(), obviously. Is it being tested, directly or indirectly?


Update: It appears that this specific constructor has no code coverage at all:
Coverage started on Tuesday, June 04 2024
Coverage for ./Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx
Which makes me wonder if this constructor is very useful at all 🤷

Anyway, I guess your pull request would fix a (hypothetical?) crash, when a transform would be constructed by this specific constructor, and then transform->GetFixedParameters() would be called. Because GetFixedParameters() assumes that m_FixedParameters has at least VInputDimension elements:

MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::GetFixedParameters() const
{
for (unsigned int i = 0; i < VInputDimension; ++i)
{
this->m_FixedParameters[i] = this->m_Center[i];
}

So the proposed fix looks OK to me, although it should still have a unit test. And I still wonder if it's very useful to keep maintaining this constructor, if it is unused.

@N-Dekker
Copy link
Contributor

N-Dekker commented Jun 4, 2024

I think the unit test with this PR might be as follows:

TEST(MatrixOffsetTransformBase, CreateWithMatrixAndOffset)
{
  class DerivedTransform : public itk::MatrixOffsetTransformBase<>
  {
  public:
    ITK_DISALLOW_COPY_AND_MOVE(DerivedTransform);

    static auto
    Create()
    {
      // Indirectly call the `MatrixOffsetTransformBase(const MatrixType &, const OutputVectorType &)` constructor.
      const itk::SmartPointer<DerivedTransform> ptr = new DerivedTransform(MatrixType(), OutputVectorType());
      ptr->UnRegister();
      return ptr;
    }

  private:
    // Inherit the constructors of MatrixOffsetTransformBase:
    using itk::MatrixOffsetTransformBase<>::MatrixOffsetTransformBase;
  };

  const auto                                  transform = DerivedTransform::Create();
  const DerivedTransform::FixedParametersType expectedFixedParameters(DerivedTransform::InputSpaceDimension, 0);

  EXPECT_EQ(transform->GetFixedParameters(), expectedFixedParameters);
}

The last line is the essential one here: EXPECT_EQ(transform->GetFixedParameters(), expectedFixedParameters) checks that m_FixedParameters has the expected number of zero-values. But moreover, it checks that GetFixedParameters() does not crash! Would that be helpful to you? (The test could be added to Core/Transform/test/itkMatrixOffsetTransformBaseGTest.cxx)

@hjmjohnson hjmjohnson requested a review from N-Dekker June 12, 2024 17:33
@hjmjohnson hjmjohnson force-pushed the matrix-offset-2-lines branch from 1e626aa to b510209 Compare June 12, 2024 17:34
@github-actions github-actions bot added the type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct label Jun 12, 2024
@hjmjohnson
Copy link
Member

@N-Dekker Added test that you suggested.

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

🙌 💯

@seanm @N-Dekker @hjmjohnson awesome teamwork!

@seanm
Copy link
Contributor Author

seanm commented Jun 13, 2024

Would be good is someone could reword my commit message to explain what this change actually is. :)

@N-Dekker
Copy link
Contributor

Honestly, if this specific MatrixOffsetTransformBase(const MatrixType &, const OutputVectorType &) constructor isn't really useful, I would rather see it being removed. Would be willing to sacrifice the beautiful 😸 unit test that I proposed, with this PR.

@hjmjohnson
Copy link
Member

\azp ITK.Linux

@hjmjohnson
Copy link
Member

/azp ITK.Linux

@hjmjohnson hjmjohnson force-pushed the matrix-offset-2-lines branch from 4e8ed79 to acb499d Compare June 14, 2024 19:05
@N-Dekker
Copy link
Contributor

@hjmjohnson There are a few similar unused constructors in derived classes (11!) that should also be deprecated, when MatrixOffsetTransformBase(const MatrixType &, const OutputVectorType &) is deprecated:

AffineTransform(const MatrixType & matrix, const OutputVectorType & offset);
ComposeScaleSkewVersor3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
FixedCenterOfRotationAffineTransform(const MatrixType & matrix, const OutputVectorType & offset);
QuaternionRigidTransform(const MatrixType & matrix, const OutputVectorType & offset);
Rigid3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
ScalableAffineTransform(const MatrixType & matrix, const OutputVectorType & offset);
ScaleSkewVersor3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
ScaleVersor3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
Similarity3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
VersorRigid3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
VersorTransform(const MatrixType & matrix, const OutputVectorType & offset);

These 11 constructors all directly or indirectly call MatrixOffsetTransformBase(const MatrixType &, const OutputVectorType &). But none of them are tested, it appears that they aren't even compiled!!! At least not at the CI. And they are all protected, so they just won't be used anywhere, I guess.

@hjmjohnson hjmjohnson force-pushed the matrix-offset-2-lines branch from acb499d to 98260ba Compare June 16, 2024 15:22
@hjmjohnson
Copy link
Member

@N-Dekker Thanks. I have implemented your additional suggestions.

@hjmjohnson hjmjohnson force-pushed the matrix-offset-2-lines branch from 98260ba to 15260ca Compare June 17, 2024 14:54
@github-actions github-actions bot removed the type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct label Jun 17, 2024
@hjmjohnson
Copy link
Member

/azp ITK.macOS

@hjmjohnson
Copy link
Member

/azp ITK.macOS.Python

These constructor signatures are not used, and are
not necessary to implement the behavior.

The derived unused constructors in derived classes (11) are
also be deprecated, when MatrixOffsetTransformBase(const MatrixType &,
const OutputVectorType &) is deprecated:

AffineTransform(const MatrixType & matrix, const OutputVectorType & offset);
ComposeScaleSkewVersor3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
FixedCenterOfRotationAffineTransform(const MatrixType & matrix, const OutputVectorType & offset);
QuaternionRigidTransform(const MatrixType & matrix, const OutputVectorType & offset);
Rigid3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
ScalableAffineTransform(const MatrixType & matrix, const OutputVectorType & offset);
ScaleSkewVersor3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
ScaleVersor3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
Similarity3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
VersorRigid3DTransform(const MatrixType & matrix, const OutputVectorType & offset);
VersorTransform(const MatrixType & matrix, const OutputVectorType & offset);

These 11 constructors all directly or indirectly call
MatrixOffsetTransformBase(const MatrixType &, const OutputVectorType &).
But none of them are tested, it appears that they aren't even
compiled!!! At least not at the CI. And they are all protected, so they
can not be used in the public API.

Disabled GTest that used now deprecated interface.
@hjmjohnson hjmjohnson force-pushed the matrix-offset-2-lines branch from 15260ca to 3b82edc Compare June 17, 2024 19:17
@hjmjohnson hjmjohnson merged commit 328606b into master Jun 18, 2024
14 checks passed
@N-Dekker
Copy link
Contributor

@hjmjohnson I see you fixed the warnings by removing the MatrixOffsetTransformBase.CreateWithMatrixAndOffset GTest that I suggested before, which is fine by me, no problem 👍

@thewtex thewtex deleted the matrix-offset-2-lines branch August 30, 2024 18:59
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 type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants