Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkAnisotropicIterativeClosestPointRegistrationTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include <mitkIOUtil.h>
18 #include <mitkSurface.h>
19 #include <mitkTestFixture.h>
20 #include <mitkTestingMacros.h>
21 #include <vtkCleanPolyData.h>
22 
26 
31 class mitkAnisotropicIterativeClosestPointRegistrationTestSuite : public mitk::TestFixture
32 {
33  CPPUNIT_TEST_SUITE(mitkAnisotropicIterativeClosestPointRegistrationTestSuite);
34  MITK_TEST(testAicpRegistration);
35  MITK_TEST(testTrimmedAicpregistration);
36  CPPUNIT_TEST_SUITE_END();
37 
38 private:
39  typedef itk::Matrix<double, 3, 3> Matrix3x3;
40  typedef itk::Vector<double, 3> Vector3;
41  typedef std::vector<Matrix3x3> CovarianceMatrixList;
42 
43  mitk::Surface::Pointer m_MovingSurface;
44  mitk::Surface::Pointer m_FixedSurface;
45 
46  mitk::PointSet::Pointer m_TargetsMovingSurface;
47  mitk::PointSet::Pointer m_TargetsFixedSurface;
48 
49  CovarianceMatrixList m_SigmasMovingSurface;
50  CovarianceMatrixList m_SigmasFixedSurface;
51 
52  double m_FRENormalizationFactor;
53 
54 public:
60  void setUp() override
61  {
63 
64  m_MovingSurface = mitk::IOUtil::LoadSurface(GetTestDataFilePath("AICPRegistration/head_green.stl"));
65  m_FixedSurface = mitk::IOUtil::LoadSurface(GetTestDataFilePath("AICPRegistration/head_red.stl"));
66 
67  m_TargetsMovingSurface = mitk::IOUtil::LoadPointSet(GetTestDataFilePath("AICPRegistration/targets_head_green.mps"));
68  m_TargetsFixedSurface = mitk::IOUtil::LoadPointSet(GetTestDataFilePath("AICPRegistration/targets_head_red.mps"));
69 
70  // compute covariance matrices
71  matrixCalculator->SetInputSurface(m_MovingSurface);
72  matrixCalculator->ComputeCovarianceMatrices();
73  m_SigmasMovingSurface = matrixCalculator->GetCovarianceMatrices();
74  const double meanVarX = matrixCalculator->GetMeanVariance();
75 
76  matrixCalculator->SetInputSurface(m_FixedSurface);
77  matrixCalculator->ComputeCovarianceMatrices();
78  m_SigmasFixedSurface = matrixCalculator->GetCovarianceMatrices();
79  const double meanVarY = matrixCalculator->GetMeanVariance();
80 
81  m_FRENormalizationFactor = sqrt(meanVarX + meanVarY);
82  }
83 
84  void tearDown() override
85  {
86  m_MovingSurface = NULL;
87  m_FixedSurface = NULL;
88 
89  m_TargetsMovingSurface = NULL;
90  m_TargetsFixedSurface = NULL;
91 
92  m_SigmasMovingSurface.clear();
93  m_SigmasFixedSurface.clear();
94  }
95 
96  void testAicpRegistration()
97  {
98  const double expFRE = 27.5799;
99  const double expTRE = 1.68835;
102 
103  // set up parameters
104  aICP->SetMovingSurface(m_MovingSurface);
105  aICP->SetFixedSurface(m_FixedSurface);
106  aICP->SetCovarianceMatricesMovingSurface(m_SigmasMovingSurface);
107  aICP->SetCovarianceMatricesFixedSurface(m_SigmasFixedSurface);
108  aICP->SetFRENormalizationFactor(m_FRENormalizationFactor);
109  aICP->SetThreshold(0.000001);
110 
111  // run the algorithm
112  aICP->Update();
113 
114  MITK_INFO << "FRE: Expected: " << expFRE << ", computed: " << aICP->GetFRE();
115  CPPUNIT_ASSERT_MESSAGE("mitkAnisotropicIterativeClosestPointRegistrationTest:AicpRegistration Test FRE",
116  mitk::Equal(aICP->GetFRE(), expFRE, 0.0001));
117 
118  // compute the target registration Error
119  const double tre =
121  m_TargetsFixedSurface.GetPointer(),
122  aICP->GetRotation(),
123  aICP->GetTranslation());
124 
125  // MITK_INFO << "R:\n" << aICP->GetRotation() << "T: "<< aICP->GetTranslation();
126 
127  MITK_INFO << "TRE: Expected: " << expTRE << ", computed: " << tre;
128  CPPUNIT_ASSERT_MESSAGE("mitkAnisotropicIterativeClosestPointRegistrationTest:AicpRegistration Test TRE",
129  mitk::Equal(tre, expTRE, 0.00001));
130  }
131 
132  void testTrimmedAicpregistration()
133  {
134  const double expFRE = 4.8912;
135  const double expTRE = 0.0484215;
136 
139 
140  // Swap X and Y for partial overlapping registration
141  aICP->SetMovingSurface(m_MovingSurface);
142  aICP->SetFixedSurface(m_FixedSurface);
143  aICP->SetCovarianceMatricesMovingSurface(m_SigmasMovingSurface);
144  aICP->SetCovarianceMatricesFixedSurface(m_SigmasFixedSurface);
145  aICP->SetFRENormalizationFactor(m_FRENormalizationFactor);
146  aICP->SetThreshold(0.000001);
147  aICP->SetTrimmFactor(0.50);
148 
149  // run the algorithm
150  aICP->Update();
151 
152  MITK_INFO << "FRE: Expected: " << expFRE << ", computed: " << aICP->GetFRE();
153 
154  CPPUNIT_ASSERT_MESSAGE("mitkAnisotropicIterativeClosestPointRegistrationTest:AicpRegistration Test FRE",
155  mitk::Equal(aICP->GetFRE(), expFRE, 0.01));
156 
157  // compute the target registration Error
158  const double tre =
160  m_TargetsFixedSurface.GetPointer(),
161  aICP->GetRotation(),
162  aICP->GetTranslation());
163 
164  MITK_INFO << "TRE: Expected: " << expTRE << ", computed: " << tre;
165  CPPUNIT_ASSERT_MESSAGE("mitkAnisotropicIterativeClosestPointRegistrationTest:AicpRegistration Test TRE",
166  mitk::Equal(tre, expTRE, 0.01));
167  }
168 };
169 
170 MITK_TEST_SUITE_REGISTRATION(mitkAnisotropicIterativeClosestPointRegistration)
static mitk::Surface::Pointer LoadSurface(const std::string &path)
LoadSurface Convenience method to load an arbitrary mitkSurface.
Definition: mitkIOUtil.cpp:608
itk::SmartPointer< Self > Pointer
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
static double ComputeTargetRegistrationError(const mitk::PointSet *movingTargets, const mitk::PointSet *fixedTargets, const Rotation &rotation, const Translation &translation)
Compute the target registration error between two point sets.
Test fixture for parameterized tests.
static mitk::PointSet::Pointer LoadPointSet(const std::string &path)
LoadPointSet Convenience method to load an arbitrary mitkPointSet.
Definition: mitkIOUtil.cpp:619
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
itk::Matrix< double, 3, 3 > Matrix3x3
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.