Closed seanm closed 2 weeks ago
I remember there was some discussion about this not long ago. @N-Dekker @hjmjohnson
This is the PR where that somewhat related discussion happened: #4485.
@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
And it may not be correct following the discussion around:
https://github.com/InsightSoftwareConsortium/ITK/pull/4485#issuecomment-1975185951
And it may not be correct
So shall I just close/discard this?
Ideally, Hans and/or Niels will review this 😄
Ideally, Hans and/or Niels will review this
OK, thanks @dzenanz I'll have a look! (I'm back 😃!)
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: https://github.com/InsightSoftwareConsortium/ITK/blob/07f8459bdf913647dab52108d8ff284d05eb4fe4/Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx#L492-L497
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.
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)
@N-Dekker Added test that you suggested.
Would be good is someone could reword my commit message to explain what this change actually is. :)
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.
\azp ITK.Linux
/azp ITK.Linux
@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.
@N-Dekker Thanks. I have implemented your additional suggestions.
/azp ITK.macOS
/azp ITK.macOS.Python
@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 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...