20 #include <vtkIdList.h> 21 #include <vtkKdTree.h> 22 #include <vtkKdTreePointLocator.h> 23 #include <vtkPoints.h> 24 #include <vtkPolyData.h> 33 typedef std::pair<unsigned int, double> Correspondence;
35 bool operator()(
const Correspondence &a,
const Correspondence &b) {
return (a.second < b.second); }
39 : m_MaxIterations(1000),
40 m_Threshold(0.000001),
41 m_FRENormalizationFactor(1.0),
43 m_MaxIterationsInWeightedPointTransform(1000),
46 m_NumberOfIterations(0),
47 m_MovingSurface(nullptr),
48 m_FixedSurface(nullptr),
59 vtkKdTreePointLocator *Y,
66 typedef itk::Matrix<double, 3, 3> WeightMatrix;
68 #pragma omp parallel for 69 for (
int i = 0; i < X->GetNumberOfPoints(); ++i)
71 vtkIdType bestIdx = 0;
75 vtkIdList *ids = vtkIdList::New();
86 while (ids->GetNumberOfIds() <= 0)
88 Y->FindPointsWithinRadius(r, p, ids);
94 for (vtkIdType j = 0; j < ids->GetNumberOfIds(); ++j)
97 const vtkIdType
id = ids->GetId(j);
101 Y->GetDataSet()->GetPoint(
id, p);
110 const double dist = res[0] * res[0] + res[1] * res[1] + res[2] * res[2];
120 Y->GetDataSet()->GetPoint(bestIdx, p);
122 sigma_Z[i] = sigma_Y[bestIdx];
124 Correspondence _pair(i, bestDist);
125 correspondences[i] = _pair;
134 unsigned int numberOfTrimmedPoints = 0;
138 vtkPoints *X = vtkPoints::New();
140 vtkPoints *Z = vtkPoints::New();
153 vtkPoints *X_sorted = vtkPoints::New();
154 vtkPoints *Z_sorted = vtkPoints::New();
159 vtkKdTreePointLocator *Y = vtkKdTreePointLocator::New();
167 Z->SetNumberOfPoints(X->GetNumberOfPoints());
169 Sigma_Z.resize(X->GetNumberOfPoints());
170 distanceList.resize(X->GetNumberOfPoints());
171 RotationNew.SetIdentity();
172 TranslationNew.Fill(0.0);
183 numberOfTrimmedPoints = X->GetNumberOfPoints() *
m_TrimmFactor;
188 Sigma_Z_sorted.resize(numberOfTrimmedPoints);
189 Sigma_X_sorted.resize(numberOfTrimmedPoints);
190 X_sorted->SetNumberOfPoints(numberOfTrimmedPoints);
191 Z_sorted->SetNumberOfPoints(numberOfTrimmedPoints);
202 unsigned int radiusDoubled = 0;
223 std::sort(distanceList.begin(), distanceList.end(),
AICPComp);
225 for (
unsigned int i = 0; i < numberOfTrimmedPoints; ++i)
227 const int idx = distanceList[i].first;
228 Sigma_Z_sorted[i] = Sigma_Z[idx];
229 Sigma_X_sorted[i] = Sigma_X[idx];
230 Z_sorted->SetPoint(i, Z->GetPoint(idx));
231 X_sorted->SetPoint(i, X->GetPoint(idx));
236 Sigma_X_k = &Sigma_X_sorted;
237 Sigma_Z_k = &Sigma_Z_sorted;
258 currSearchRadius *= 2.0;
261 if (radiusDoubled >= 20)
263 mitkThrow() <<
"Radius doubled 20 times, preventing endless loop, check input and search radius";
267 diff =
m_FRE - FRE_new;
269 }
while (diff < -1.0e-3);
287 stepSize = (k % 2 == 0) ? stepSize / 2 : stepSize;
288 stepSize = (stepSize == 0) ? 1 : stepSize;
CovarianceMatrixList m_CovarianceMatricesFixedSurface
AnisotropicIterativeClosestPointRegistration()
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
itk::SmartPointer< Surface > m_MovingSurface
double m_FRENormalizationFactor
CovarianceMatrix Rotation
void ComputeCorrespondences(vtkPoints *X, vtkPoints *Z, vtkKdTreePointLocator *Y, const CovarianceMatrixList &sigma_X, const CovarianceMatrixList &sigma_Y, CovarianceMatrixList &sigma_Z, CorrespondenceList &correspondences, const double radius)
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< CovarianceMatrix > CovarianceMatrixList
unsigned int m_MaxIterations
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
struct AICPComperator AICPComp
CovarianceMatrixList m_CovarianceMatricesMovingSurface
itk::SmartPointer< Surface > m_FixedSurface
itk::SmartPointer< WeightedPointTransform > m_WeightedPointTransform
static void PropagateMatrices(const MatrixList &src, MatrixList &dst, const Rotation &rotation)
Propagate a list of matrices with a rotation matrix.
~AnisotropicIterativeClosestPointRegistration() override
std::vector< Correspondence > CorrespondenceList
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
static void TransformPoints(vtkPoints *src, vtkPoints *dst, const Rotation &rotation, const Translation &translation)
Transforms a point cloud with a Rotation and Translation.
unsigned int m_NumberOfIterations
static WeightMatrix CalculateWeightMatrix(const CovarianceMatrix &sigma_X, const CovarianceMatrix &sigma_Y)
Method that computes a WeightMatrix with two CovarianceMatrices.
Translation m_Translation
double m_MaxIterationsInWeightedPointTransform