diff --git a/Modules/Core/Transform/include/itkKernelTransform.h b/Modules/Core/Transform/include/itkKernelTransform.h index 22bacc413dc..24351ef78f2 100644 --- a/Modules/Core/Transform/include/itkKernelTransform.h +++ b/Modules/Core/Transform/include/itkKernelTransform.h @@ -225,6 +225,25 @@ class ITK_TEMPLATE_EXPORT KernelTransform : public TransformGetInverse(inv); + return inv; + } + /** Stiffness of the spline. A stiffness of zero results in the * standard interpolating spline. A non-zero stiffness allows the * spline to approximate rather than interpolate the landmarks. diff --git a/Modules/Core/Transform/include/itkKernelTransform.hxx b/Modules/Core/Transform/include/itkKernelTransform.hxx index bdd7057db44..f3662ef7bad 100644 --- a/Modules/Core/Transform/include/itkKernelTransform.hxx +++ b/Modules/Core/Transform/include/itkKernelTransform.hxx @@ -508,6 +508,43 @@ KernelTransform::GetFixedParameters() const -> } +template +bool +KernelTransform::GetInverse(Self * inverseTransform) const +{ + if (!inverseTransform) + { + return false; + } + + auto deepCopyLandmarks = [](const typename PointSetType::ConstPointer source, + typename PointSetType::Pointer destination) { + typename PointSetType::PointsContainer::ConstIterator sourceIt = source->GetPoints()->Begin(); + + typename PointSetType::PointIdentifier i{ 0 }; + while (sourceIt != source->GetPoints()->End()) + { + destination->SetPoint(i, sourceIt->Value()); + ++i; + ++sourceIt; + } + }; + + // make a deep copy of the source and target landmarks + typename PointSetType::Pointer sourceLandmarks = PointSetType::New(); + typename PointSetType::Pointer targetLandmarks = PointSetType::New(); + deepCopyLandmarks(this->GetSourceLandmarks(), sourceLandmarks); + deepCopyLandmarks(this->GetTargetLandmarks(), targetLandmarks); + + // inversion comes from reversing the landmarks + inverseTransform->SetSourceLandmarks(targetLandmarks); + inverseTransform->SetTargetLandmarks(sourceLandmarks); + inverseTransform->SetStiffness(this->GetStiffness()); + inverseTransform->ComputeWMatrix(); + + return true; +} + template void KernelTransform::PrintSelf(std::ostream & os, Indent indent) const