Skip to content

Commit 20249ec

Browse files
N-Dekkerdzenanz
authored andcommitted
ENH: Make Parameters empty, do not warn in Transform default-constructor
Defaulted (`= default`) the `Transform` default-constructor, ensuring that it will make both its `Parameters` and its `FixedParameters` empty. Allowed calling this default-constructor from a derived transform class without getting a `itkWarningMacro`.
1 parent ddcaa84 commit 20249ec

File tree

4 files changed

+91
-11
lines changed

4 files changed

+91
-11
lines changed

Modules/Core/Transform/include/itkTransform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersVa
571571
typename LightObject::Pointer
572572
InternalClone() const override;
573573

574-
Transform();
574+
/** Default-constructor. Creates a transform, having empty `Parameters` and `FixedParameters`. */
575+
Transform() = default;
576+
575577
Transform(NumberOfParametersType numberOfParameters);
576578
#if defined(__GNUC__)
577579
// A bug in some versions of the GCC and Clang compilers

Modules/Core/Transform/include/itkTransform.hxx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525
namespace itk
2626
{
2727

28-
template <typename TParametersValueType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
29-
Transform<TParametersValueType, NInputDimensions, NOutputDimensions>::Transform()
30-
: m_Parameters(1)
31-
, m_FixedParameters()
32-
{
33-
itkWarningMacro(
34-
<< "Using default transform constructor. Should specify NOutputDims and NParameters as args to constructor.");
35-
}
36-
37-
3828
template <typename TParametersValueType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
3929
Transform<TParametersValueType, NInputDimensions, NOutputDimensions>::Transform(
4030
NumberOfParametersType numberOfParameters)

Modules/Core/Transform/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ set(ITKTransformGTests
190190
itkEuler3DTransformGTest.cxx
191191
itkMatrixOffsetTransformBaseGTest.cxx
192192
itkSimilarityTransformGTest.cxx
193+
itkTransformGTest.cxx
193194
itkTranslationTransformGTest.cxx
194195
)
195196
CreateGoogleTestDriver(ITKTransform "${ITKTransform-Test_LIBRARIES}" "${ITKTransformGTests}")
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
19+
// First include the header file to be tested:
20+
#include "itkTransform.h"
21+
22+
#include <gtest/gtest.h>
23+
24+
namespace
25+
{
26+
template <typename TParametersValueType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
27+
class DerivedTransform : public itk::Transform<TParametersValueType, NInputDimensions, NOutputDimensions>
28+
{
29+
public:
30+
ITK_DISALLOW_COPY_AND_MOVE(DerivedTransform);
31+
32+
using Self = DerivedTransform;
33+
using Superclass = itk::Transform<TParametersValueType, NInputDimensions, NOutputDimensions>;
34+
using Pointer = itk::SmartPointer<Self>;
35+
36+
itkNewMacro(Self);
37+
38+
private:
39+
DerivedTransform() = default;
40+
41+
using typename Superclass::FixedParametersType;
42+
using typename Superclass::InputPointType;
43+
using typename Superclass::JacobianType;
44+
using typename Superclass::OutputPointType;
45+
using typename Superclass::ParametersType;
46+
47+
static constexpr const char * exceptionMessage =
48+
"This member function is not meant to be called during unit testing!";
49+
50+
void
51+
SetParameters(const ParametersType &) override
52+
{
53+
itkExceptionMacro(<< exceptionMessage);
54+
}
55+
56+
void
57+
SetFixedParameters(const FixedParametersType &) override
58+
{
59+
itkExceptionMacro(<< exceptionMessage);
60+
}
61+
62+
OutputPointType
63+
TransformPoint(const InputPointType &) const override
64+
{
65+
itkExceptionMacro(<< exceptionMessage);
66+
}
67+
68+
void
69+
ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const override
70+
{
71+
itkExceptionMacro(<< exceptionMessage);
72+
}
73+
};
74+
} // namespace
75+
76+
77+
// Tests that a transform derived from itk::Transform has empty Parameters and FixedParameters by default.
78+
TEST(Transform, HasEmptyParametersAndFixedParametersByDefault)
79+
{
80+
const auto expectEmpty = [](const auto & transform) {
81+
EXPECT_TRUE(transform.GetParameters().empty());
82+
EXPECT_TRUE(transform.GetFixedParameters().empty());
83+
};
84+
85+
expectEmpty(*(DerivedTransform<float, 2, 2>::New()));
86+
expectEmpty(*(DerivedTransform<double, 3, 4>::New()));
87+
}

0 commit comments

Comments
 (0)