MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkStandardICPPointRegister.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include <math.h>
15
16//vtk header
17#include <vtkPoints.h>
18#include <vtkIterativeClosestPointTransform.h>
19#include <vtkMatrix4x4.h>
20#include <vtkLandmarkTransform.h>
21#include <vtkVertexGlyphFilter.h>
22
23
25 mitk::PointSet::Pointer StaticSet,
26 double Threshold,
27 itk::Matrix<double,3,3>& TransformationR,
28 itk::Vector<double,3>& TransformationT,
29 double& FRE,
30 int& n,
31 std::string& ErrorMessage,
32 int max_iterations
33 )
34 {
35 //##################### convert input data ################################
36 //convert source points (= moving points) to vtkPolyData:
38 //convert target points (= static points) to vtkPolyData:
40
41 return StandardICPPointRegisterAlgorithm(source,target,Threshold,TransformationR,TransformationT,FRE,n,ErrorMessage,max_iterations);
42 }
43
45 vtkSmartPointer<vtkPolyData> StaticSurface,
46 double Threshold,
47 itk::Matrix<double,3,3>& TransformationR,
48 itk::Vector<double,3>& TransformationT,
49 double& FRE,
50 int& n,
51 std::string& ErrorMessage,
52 int max_iterations
53 )
54 {
55 //################# clean up return variables at first ####################
56 TransformationR = itk::Matrix<double,3,3>(); TransformationR.Fill(0);
57 TransformationR[0][0] = 1; TransformationR[1][1] = 1; TransformationR[2][2] = 1;
58 TransformationT = itk::Vector<double,3>(); TransformationT.Fill(0);
59 n = 0;
60 FRE = 0;
61 ErrorMessage = "";
62
63 //################# check for right input #################################
64 if (MovingSurface.GetPointer() == NULL || StaticSurface.GetPointer() == NULL)
65 {
66 ErrorMessage = "Error, at least one input value is missing";
67 return false;
68 }
69
70 vtkSmartPointer<vtkPolyData> source = MovingSurface;
71 vtkSmartPointer<vtkPolyData> target = StaticSurface;
72
73 //##################### setup ICP transform ###############################
75 icp->SetMaximumMeanDistance(Threshold);
76 icp->SetSource(source);
77 icp->SetTarget(target);
78 icp->GetLandmarkTransform()->SetModeToRigidBody();
79 icp->SetMaximumNumberOfIterations(max_iterations);
80 icp->Modified();
81 icp->Update();
82
83 //##################### get results #######################################
84 vtkSmartPointer<vtkMatrix4x4> m = icp->GetMatrix();
85 TransformationR[0][0] = m->GetElement(0,0);
86 TransformationR[0][1] = m->GetElement(0,1);
87 TransformationR[0][2] = m->GetElement(0,2);
88 TransformationR[1][0] = m->GetElement(1,0);
89 TransformationR[1][1] = m->GetElement(1,1);
90 TransformationR[1][2] = m->GetElement(1,2);
91 TransformationR[2][0] = m->GetElement(2,0);
92 TransformationR[2][1] = m->GetElement(2,1);
93 TransformationR[2][2] = m->GetElement(2,2);
94 TransformationT[0] = m->GetElement(0,3);
95 TransformationT[1] = m->GetElement(1,3);
96 TransformationT[2] = m->GetElement(2,3);
97 n = icp->GetNumberOfIterations();
98 //vtkIterativeClosestPointTransform does not compute FRE, needs to be computed separately
99 ErrorMessage = "Registration succeeded";
100 return true;
101 }
102
103
105 {
108 for(int i=0; i<PointSet->GetSize(); i++)
109 {
110 double point[3] = {PointSet->GetPoint(i)[0],PointSet->GetPoint(i)[1],PointSet->GetPoint(i)[2]};
111 points->InsertNextPoint(point);
112 }
114 temp->SetPoints(points);
115
117 vertexFilter->SetInputData(temp);
118 vertexFilter->Update();
119
120 returnValue->ShallowCopy(vertexFilter->GetOutput());
121
122 return returnValue;
123 }
static vtkSmartPointer< vtkPolyData > convertPointSetToVtkPolyData(mitk::PointSet::Pointer PointSet)
static bool StandardICPPointRegisterAlgorithm(mitk::PointSet::Pointer MovingSet, mitk::PointSet::Pointer StaticSet, double Threshold, itk::Matrix< double, 3, 3 > &TransformationR, itk::Vector< double, 3 > &TransformationT, double &FRE, int &n, std::string &ErrorMessage, int max_iterations=100)
This method executes the standard iterative closest point algorithm to register a moving pointset X o...