Skip to content

Commit

Permalink
ENH: Add GraftDoesShallowCopyOfPointsAndData to PointSet GTest unit test
Browse files Browse the repository at this point in the history
Tests that PointSet::Graft copies the pointers to the points and the data.
  • Loading branch information
N-Dekker committed Oct 29, 2024
1 parent f8b31d8 commit 7fc3b10
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Modules/Core/Common/test/itkPointSetGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// First include the header file to be tested:
#include "itkPointSet.h"
#include "itkDeref.h"
#include "../../QuadEdgeMesh/include/itkQuadEdgeMeshTraits.h"
#include <gtest/gtest.h>
#include <algorithm> // For equal.
Expand Down Expand Up @@ -80,3 +81,36 @@ TEST(PointSet, SetPointsByCoordinates)
TestSetPointsByCoordinates(*itk::PointSet<int>::New());
TestSetPointsByCoordinates(*itk::PointSet<double, 2, itk::QuadEdgeMeshTraits<double, 2, bool, bool>>::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<int>::New());

// Then check a non-empty point set with `double` data:
using PixelType = double;
static constexpr unsigned int Dimension = 2;
using PointSetType = itk::PointSet<PixelType, Dimension>;
using PointType = PointSetType::PointType;

const auto pointSet = PointSetType::New();
pointSet->SetPoints(itk::MakeVectorContainer<PointType>({ PointType(), itk::MakeFilled<PointType>(1.0f) }));
pointSet->SetPointData(itk::MakeVectorContainer<PixelType>({ 0.0, 1.0, 2.0 }));

check(*pointSet);
}

0 comments on commit 7fc3b10

Please sign in to comment.