Skip to content

Commit

Permalink
Add support for VersorRigid3D Transform
Browse files Browse the repository at this point in the history
  • Loading branch information
PranjalSahu committed Dec 17, 2022
1 parent 7649b0d commit acccf2c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 89 deletions.
3 changes: 2 additions & 1 deletion include/itkLandmarkRegistrationEstimator.h
Expand Up @@ -27,7 +27,8 @@
namespace itk
{

template <unsigned int Dimension>

template <unsigned int Dimension, typename TTransform>
class LandmarkRegistrationEstimator : public itk::ParametersEstimator<Point<double, Dimension>, double>
{
public:
Expand Down
86 changes: 40 additions & 46 deletions include/itkLandmarkRegistrationEstimator.hxx
Expand Up @@ -21,7 +21,6 @@

#include "itkLandmarkRegistrationEstimator.h"
#include "itkLandmarkBasedTransformInitializer.h"
#include "itkSimilarity3DTransform.h"
#include "itkIntTypes.h"
#include "nanoflann.hpp"
#include "itkMesh.h"
Expand All @@ -30,31 +29,31 @@
namespace itk
{

template <unsigned int Dimension>
LandmarkRegistrationEstimator<Dimension>::LandmarkRegistrationEstimator()

template <unsigned int Dimension, typename TTransform>
LandmarkRegistrationEstimator<Dimension, TTransform>::LandmarkRegistrationEstimator()
{
this->delta = NumericTraits<double>::min();
this->minForEstimate = Dimension;
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
void
LandmarkRegistrationEstimator<Dimension>::SetDelta(double inputDelta)
LandmarkRegistrationEstimator<Dimension, TTransform>::SetDelta(double inputDelta)
{
this->delta = inputDelta*inputDelta;
}


template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
double
LandmarkRegistrationEstimator<Dimension>::GetDelta()
LandmarkRegistrationEstimator<Dimension, TTransform>::GetDelta()
{
return this->delta;
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
void
LandmarkRegistrationEstimator<Dimension>::Estimate(std::vector<Point<double, Dimension> *> & data,
LandmarkRegistrationEstimator<Dimension, TTransform>::Estimate(std::vector<Point<double, Dimension> *> & data,
std::vector<double> & parameters)
{
parameters.clear();
Expand All @@ -63,18 +62,15 @@ LandmarkRegistrationEstimator<Dimension>::Estimate(std::vector<Point<double, Dim
using PixelType = float;
using FixedImageType = itk::Image<PixelType, DimensionPoint>;
using MovingImageType = itk::Image<PixelType, DimensionPoint>;

using TransformType = itk::Similarity3DTransform<double>;

using TransformInitializerType =
itk::LandmarkBasedTransformInitializer<TransformType, FixedImageType, MovingImageType>;
itk::LandmarkBasedTransformInitializer<TTransform, FixedImageType, MovingImageType>;
auto initializer = TransformInitializerType::New();
auto transform = TTransform::New();

typename TransformInitializerType::LandmarkPointContainer fixedLandmarks;
typename TransformInitializerType::LandmarkPointContainer movingLandmarks;

// Obtain the parameters of the Similarity3DTransform
auto transform = TransformType::New();

fixedLandmarks.reserve(data.size());
movingLandmarks.reserve(data.size());

Expand Down Expand Up @@ -102,22 +98,22 @@ LandmarkRegistrationEstimator<Dimension>::Estimate(std::vector<Point<double, Dim

// Copy the transform parameters in the input variable
auto transformParameters = transform->GetParameters();
for (unsigned int i = 0; i < 7; ++i)
for (unsigned int i = 0; i < transformParameters.GetSize(); ++i)
{
parameters.push_back(transformParameters.GetElement(i));
}

auto fixedParameters = transform->GetFixedParameters();
for (unsigned int i = 0; i < 3; ++i)
for (unsigned int i = 0; i < fixedParameters.GetSize(); ++i)
{
parameters.push_back(fixedParameters.GetElement(i));
}
return;
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
void
LandmarkRegistrationEstimator<Dimension>::Estimate(std::vector<Point<double, Dimension>> & data,
LandmarkRegistrationEstimator<Dimension, TTransform>::Estimate(std::vector<Point<double, Dimension>> & data,
std::vector<double> & parameters)
{
std::vector<Point<double, Dimension> *> usedData;
Expand All @@ -129,9 +125,9 @@ LandmarkRegistrationEstimator<Dimension>::Estimate(std::vector<Point<double, Dim
Estimate(usedData, parameters);
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
void
LandmarkRegistrationEstimator<Dimension>::LeastSquaresEstimate(std::vector<Point<double, Dimension> *> & data,
LandmarkRegistrationEstimator<Dimension, TTransform>::LeastSquaresEstimate(std::vector<Point<double, Dimension> *> & data,
std::vector<double> & parameters)
{
parameters.clear();
Expand All @@ -141,14 +137,12 @@ LandmarkRegistrationEstimator<Dimension>::LeastSquaresEstimate(std::vector<Point
using FixedImageType = itk::Image<PixelType, DimensionPoint>;
using MovingImageType = itk::Image<PixelType, DimensionPoint>;

using Similarity3DTransformType = Similarity3DTransform<double>;
using TransformInitializerType =
itk::LandmarkBasedTransformInitializer<Similarity3DTransformType, FixedImageType, MovingImageType>;
// Obtain the parameters of the Similarity3DTransform

auto transform = Similarity3DTransformType::New();
itk::LandmarkBasedTransformInitializer<TTransform, FixedImageType, MovingImageType>;

auto initializer = TransformInitializerType::New();

auto transform = TTransform::New();

itk::Point<double, 3> point;
typename TransformInitializerType::LandmarkPointContainer fixedLandmarks;
typename TransformInitializerType::LandmarkPointContainer movingLandmarks;
Expand Down Expand Up @@ -176,22 +170,22 @@ LandmarkRegistrationEstimator<Dimension>::LeastSquaresEstimate(std::vector<Point

// Copy the transform parameters in the input variable
auto transformParameters = transform->GetParameters();
for (unsigned int i = 0; i < 7; ++i)
for (unsigned int i = 0; i < transformParameters.GetSize(); ++i)
{
parameters.push_back(transformParameters.GetElement(i));
}

auto fixedParameters = transform->GetFixedParameters();
for (unsigned int i = 0; i < 3; ++i)
for (unsigned int i = 0; i < fixedParameters.GetSize(); ++i)
{
parameters.push_back(fixedParameters.GetElement(i));
}
return;
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
void
LandmarkRegistrationEstimator<Dimension>::LeastSquaresEstimate(std::vector<Point<double, Dimension>> & data,
LandmarkRegistrationEstimator<Dimension, TTransform>::LeastSquaresEstimate(std::vector<Point<double, Dimension>> & data,
std::vector<double> & parameters)
{
std::vector<Point<double, Dimension> *> usedData;
Expand All @@ -204,26 +198,26 @@ LandmarkRegistrationEstimator<Dimension>::LeastSquaresEstimate(std::vector<Point
LeastSquaresEstimate(usedData, parameters);
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
bool
LandmarkRegistrationEstimator<Dimension>::Agree(std::vector<double> & parameters, Point<double, Dimension> & data)
LandmarkRegistrationEstimator<Dimension, TTransform>::Agree(std::vector<double> & parameters, Point<double, Dimension> & data)
{
using Similarity3DTransformType = Similarity3DTransform<double>;
auto transform = Similarity3DTransformType::New();
auto transform = TTransform::New();

auto optParameters = transform->GetParameters();
auto fixedParameters = transform->GetFixedParameters();

int counter = 0;
for (unsigned int i = 7; i < 10; ++i)
unsigned int totalParameters = optParameters.GetSize() + fixedParameters.GetSize();
for (unsigned int i = optParameters.GetSize(); i < totalParameters; ++i)
{
fixedParameters.SetElement(counter, parameters[i]);
counter = counter + 1;
}
transform->SetFixedParameters(fixedParameters);

counter = 0;
for (unsigned int i = 0; i < 7; ++i)
for (unsigned int i = 0; i < optParameters.GetSize(); ++i)
{
optParameters.SetElement(counter, parameters[i]);
counter = counter + 1;
Expand All @@ -247,9 +241,9 @@ LandmarkRegistrationEstimator<Dimension>::Agree(std::vector<double> & parameters
}


template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
void
LandmarkRegistrationEstimator<Dimension>::SetAgreeData(std::vector<Point<double, Dimension>> & data)
LandmarkRegistrationEstimator<Dimension, TTransform>::SetAgreeData(std::vector<Point<double, Dimension>> & data)
{
this->agreePoints = PointsContainer::New();
this->agreePoints->reserve(data.size());
Expand Down Expand Up @@ -278,27 +272,27 @@ LandmarkRegistrationEstimator<Dimension>::SetAgreeData(std::vector<Point<double,
this->mat_adaptor->index->buildIndex();
}

template <unsigned int Dimension>
template <unsigned int Dimension, typename TTransform>
std::vector<bool>
LandmarkRegistrationEstimator<Dimension>::AgreeMultiple(std::vector<double> & parameters,
LandmarkRegistrationEstimator<Dimension, TTransform>::AgreeMultiple(std::vector<double> & parameters,
std::vector<Point<double, Dimension>> & data, unsigned int currentBest)
{
using Similarity3DTransformType = Similarity3DTransform<double>;
auto transform = Similarity3DTransformType::New();
auto transform = TTransform::New();

auto optParameters = transform->GetParameters();
auto fixedParameters = transform->GetFixedParameters();

int counter = 0;
for (unsigned int i = 7; i < 10; ++i)
unsigned int totalParameters = optParameters.GetSize() + fixedParameters.GetSize();
for (unsigned int i = optParameters.GetSize(); i < totalParameters; ++i)
{
fixedParameters.SetElement(counter, parameters[i]);
counter = counter + 1;
}
transform->SetFixedParameters(fixedParameters);

counter = 0;
for (unsigned int i = 0; i < 7; ++i)
for (unsigned int i = 0; i < optParameters.GetSize(); ++i)
{
optParameters.SetElement(counter, parameters[i]);
counter = counter + 1;
Expand Down
3 changes: 2 additions & 1 deletion include/itkParametersEstimator.h
Expand Up @@ -21,7 +21,8 @@

#include <vector>
#include "itkObject.h"

#include "itkSimilarity3DTransform.h"
#include "itkVersorRigid3DTransform.h"

namespace itk
{
Expand Down
2 changes: 1 addition & 1 deletion include/itkRANSAC.h
Expand Up @@ -73,7 +73,7 @@ namespace itk
* \ingroup Ransac
*/

template <typename T, typename SType>
template <typename T, typename SType, typename TTransform>
class ITK_TEMPLATE_EXPORT RANSAC : public Object
{
public:
Expand Down

0 comments on commit acccf2c

Please sign in to comment.