Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkCovarianceMatrixCalculatorTest.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 
18 #include <mitkIOUtil.h>
19 #include <mitkSurface.h>
20 #include <mitkTestingMacros.h>
21 #include <mitkVector.h>
22 #include <vtkCleanPolyData.h>
23 
24 #include <mitkTestFixture.h>
25 
29 class mitkCovarianceMatrixCalculatorTestSuite : public mitk::TestFixture
30 {
31  CPPUNIT_TEST_SUITE(mitkCovarianceMatrixCalculatorTestSuite);
32  MITK_TEST(testCovarianceMatrixCalculation_CM_PCA);
33  CPPUNIT_TEST_SUITE_END();
34 
35 private:
36  typedef itk::Matrix<double, 3, 3> CovarianceMatrix;
37  typedef std::vector<CovarianceMatrix> CovarianceMatrixList;
38 
39  mitk::Surface::Pointer m_Surface;
40  CovarianceMatrixList m_Reference;
41 
42 public:
43  void setUp() override
44  {
45  m_Surface = mitk::IOUtil::LoadSurface(GetTestDataFilePath("RenderingTestData/Stanford_bunny.stl"));
46 
47  // saved results
48  CovarianceMatrix m1, m2, m3;
49 
50  // set 3 reference results into the vector. The first in the array, one from
51  // the middle and the last one
52  m1[0][0] = 366.169;
53  m1[1][0] = 39.5242;
54  m1[2][0] = 102.368;
55  m1[0][1] = 39.5242;
56  m1[1][1] = 6.97979;
57  m1[2][1] = 6.91726;
58  m1[0][2] = 102.368;
59  m1[1][2] = 6.91726;
60  m1[2][2] = 389.481;
61  m_Reference.push_back(m1);
62 
63  m2[0][0] = 107.999;
64  m2[1][0] = 71.6708;
65  m2[2][0] = -0.908269;
66  m2[0][1] = 71.6708;
67  m2[1][1] = 133.407;
68  m2[2][1] = 40.8706;
69  m2[0][2] = -0.908269;
70  m2[1][2] = 40.8706;
71  m2[2][2] = 25.1825;
72  m_Reference.push_back(m2);
73 
74  m3[0][0] = 177.916;
75  m3[1][0] = 4.92498;
76  m3[2][0] = 5.86319;
77  m3[0][1] = 4.92498;
78  m3[1][1] = 0.214147;
79  m3[2][1] = -1.98345;
80  m3[0][2] = 5.86319;
81  m3[1][2] = -1.98345;
82  m3[2][2] = 232.092;
83  m_Reference.push_back(m3);
84  }
85 
86  void tearDown() override
87  {
88  m_Surface = NULL;
89  m_Reference.clear();
90  }
91 
92  void testCovarianceMatrixCalculation_CM_PCA()
93  {
95  matrixCalculator->SetInputSurface(m_Surface);
96  matrixCalculator->ComputeCovarianceMatrices();
97  CovarianceMatrixList result = matrixCalculator->GetCovarianceMatrices();
98 
99  CPPUNIT_ASSERT_MESSAGE("mitkCovarianceMatrixCalculatorTestSuite test first matrix",
100  mitk::MatrixEqualElementWise(result.at(0), m_Reference.at(0), 0.001));
101 
102  CPPUNIT_ASSERT_MESSAGE("mitkCovarianceMatrixCalculatorTestSuite test middle matrix",
103  mitk::MatrixEqualElementWise(result.at(result.size() / 2), m_Reference.at(1), 0.001));
104 
105  CPPUNIT_ASSERT_MESSAGE("mitkCovarianceMatrixCalculatorTestSuite test last matrix",
106  mitk::MatrixEqualElementWise(result.at((result.size() - 1)), m_Reference.at(2), 0.001));
107  }
108 };
109 
110 MITK_TEST_SUITE_REGISTRATION(mitkCovarianceMatrixCalculator)
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)
bool MatrixEqualElementWise(const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix1, const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix2, mitk::ScalarType epsilon=mitk::eps)
Check for element-wise matrix equality with a user defined accuracy.
Definition: mitkMatrix.h:144
#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.
Test fixture for parameterized tests.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.