diff --git a/Modules/Core/Common/test/itkPointSetGTest.cxx b/Modules/Core/Common/test/itkPointSetGTest.cxx index 6c1cb8f2ea5..8461daae77a 100644 --- a/Modules/Core/Common/test/itkPointSetGTest.cxx +++ b/Modules/Core/Common/test/itkPointSetGTest.cxx @@ -18,6 +18,7 @@ // First include the header file to be tested: #include "itkPointSet.h" +#include "itkDeref.h" #include "../../QuadEdgeMesh/include/itkQuadEdgeMeshTraits.h" #include #include // For equal. @@ -80,3 +81,36 @@ TEST(PointSet, SetPointsByCoordinates) TestSetPointsByCoordinates(*itk::PointSet::New()); TestSetPointsByCoordinates(*itk::PointSet>::New()); } + + +// Tests that PointSet::Graft copies the pointers to the points and the data. +TEST(PointSet, GraftDoesShallowCopyOfPointsAndData) +{ + const auto check = [](const auto & pointSet) { + const auto clone = pointSet.Clone(); + + // Check that Clone() did not return null, by using itk::Deref(ptr). + const auto & constClone = itk::Deref(clone.get()); + + clone->Graft(&pointSet); + + // Expect that Graft does "shallow copying", only copying the *pointers* to the points and the data. + EXPECT_EQ(constClone.GetPoints(), pointSet.GetPoints()); + EXPECT_EQ(constClone.GetPointData(), pointSet.GetPointData()); + }; + + // First check an empty point set: + check(*itk::PointSet::New()); + + // Then check a non-empty point set with `double` data: + using PixelType = double; + static constexpr unsigned int Dimension = 2; + using PointSetType = itk::PointSet; + using PointType = PointSetType::PointType; + + const auto pointSet = PointSetType::New(); + pointSet->SetPoints(itk::MakeVectorContainer({ PointType(), itk::MakeFilled(1.0f) })); + pointSet->SetPointData(itk::MakeVectorContainer({ 0.0, 1.0, 2.0 })); + + check(*pointSet); +}