|
18 | 18 |
|
19 | 19 | // First include the header file to be tested: |
20 | 20 | #include "itkPointSet.h" |
| 21 | +#include "itkDeref.h" |
21 | 22 | #include "../../QuadEdgeMesh/include/itkQuadEdgeMeshTraits.h" |
22 | 23 | #include <gtest/gtest.h> |
23 | 24 | #include <algorithm> // For equal. |
@@ -80,3 +81,35 @@ TEST(PointSet, SetPointsByCoordinates) |
80 | 81 | TestSetPointsByCoordinates(*itk::PointSet<int>::New()); |
81 | 82 | TestSetPointsByCoordinates(*itk::PointSet<double, 2, itk::QuadEdgeMeshTraits<double, 2, bool, bool>>::New()); |
82 | 83 | } |
| 84 | + |
| 85 | + |
| 86 | +// Tests that `PointSet::Graft` just copies the *pointers* to the points and the data. It does not do a "deep copy". |
| 87 | +TEST(PointSet, GraftDoesShallowCopy) |
| 88 | +{ |
| 89 | + const auto check = [](const auto & pointSet) { |
| 90 | + const auto clone = pointSet.Clone(); |
| 91 | + |
| 92 | + // Check that Clone() did not return null, by using itk::Deref(ptr). |
| 93 | + const auto & constClone = itk::Deref(clone.get()); |
| 94 | + |
| 95 | + clone->Graft(&pointSet); |
| 96 | + |
| 97 | + // Expect that the pointers to the points and the data of the clone are equal to those of the original. |
| 98 | + EXPECT_EQ(constClone.GetPoints(), pointSet.GetPoints()); |
| 99 | + EXPECT_EQ(constClone.GetPointData(), pointSet.GetPointData()); |
| 100 | + }; |
| 101 | + |
| 102 | + // First check an empty point set: |
| 103 | + check(*itk::PointSet<int>::New()); |
| 104 | + |
| 105 | + // Then check a non-empty 2-D point set with `double` data: |
| 106 | + using PixelType = double; |
| 107 | + using PointSetType = itk::PointSet<PixelType, 2>; |
| 108 | + using PointType = PointSetType::PointType; |
| 109 | + |
| 110 | + const auto pointSet = PointSetType::New(); |
| 111 | + pointSet->SetPoints(itk::MakeVectorContainer<PointType>({ PointType(), itk::MakeFilled<PointType>(1.0f) })); |
| 112 | + pointSet->SetPointData(itk::MakeVectorContainer<PixelType>({ 0.0, 1.0, 2.0 })); |
| 113 | + |
| 114 | + check(*pointSet); |
| 115 | +} |
0 commit comments