diff --git a/Modules/Core/Common/include/itkPointSet.h b/Modules/Core/Common/include/itkPointSet.h index 51829cbd6c7b..c4741e547bff 100644 --- a/Modules/Core/Common/include/itkPointSet.h +++ b/Modules/Core/Common/include/itkPointSet.h @@ -162,6 +162,18 @@ class ITK_TEMPLATE_EXPORT PointSet : public PointSetBaseCastToSTLContainer() = m_PointDataContainer->CastToSTLConstContainer(); + m_PointDataContainer = pointData; + } + } }; // End Class: PointSet } // end namespace itk diff --git a/Modules/Core/Common/include/itkPointSetBase.h b/Modules/Core/Common/include/itkPointSetBase.h index d8c86ee99009..ca2aa1378aa3 100644 --- a/Modules/Core/Common/include/itkPointSetBase.h +++ b/Modules/Core/Common/include/itkPointSetBase.h @@ -67,6 +67,8 @@ class ITK_TEMPLATE_EXPORT PointSetBase : public DataObject /** \see LightObject::GetNameOfClass() */ itkOverrideGetNameOfClassMacro(PointSetBase); + itkCloneMacro(Self); + /** Convenient type alias obtained from TPointsContainer template parameter. */ using PointType = typename TPointsContainer::Element; using CoordRepType = typename PointType::CoordRepType; @@ -190,6 +192,25 @@ class ITK_TEMPLATE_EXPORT PointSetBase : public DataObject itkGetConstMacro(BufferedRegion, RegionType); + + /** Returns a "deep copy" of this point set, having copied its points and point data. */ + Pointer + MakeDeepCopy() const + { + const auto clone = this->Clone(); + clone->Graft(this); + + if (m_PointsContainer) + { + // Make a new copy of the points, detached from the original one. + const auto points = TPointsContainer::New(); + points->CastToSTLContainer() = m_PointsContainer->CastToSTLConstContainer(); + clone->m_PointsContainer = points; + } + clone->DetachPointData(); + return clone; + } + protected: /** Default-constructor, to be used by derived classes. */ PointSetBase() = default; @@ -215,6 +236,10 @@ class ITK_TEMPLATE_EXPORT PointSetBase : public DataObject RegionType m_RequestedNumberOfRegions{}; RegionType m_BufferedRegion{ -1 }; RegionType m_RequestedRegion{ -1 }; + +private: + virtual void + DetachPointData() = 0; }; } // end namespace itk