Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkImageToSurfaceFilterTest.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #include "mitkException.h"
14 #include "mitkTestFixture.h"
15 #include "mitkTestingMacros.h"
16 
17 #include <mitkIOUtil.h>
18 
20 {
21  vtkPoints *p1 = s1->GetVtkPolyData()->GetPoints();
22  vtkPoints *p2 = s2->GetVtkPolyData()->GetPoints();
23 
24  if (p1->GetNumberOfPoints() != p2->GetNumberOfPoints())
25  return false;
26 
27  for (int i = 0; i < p1->GetNumberOfPoints(); ++i)
28  {
29  if (p1->GetPoint(i)[0] != p2->GetPoint(i)[0] || p1->GetPoint(i)[1] != p2->GetPoint(i)[1] ||
30  p1->GetPoint(i)[2] != p2->GetPoint(i)[2])
31  {
32  return true;
33  }
34  }
35  return false;
36 }
37 
38 class mitkImageToSurfaceFilterTestSuite : public mitk::TestFixture
39 {
40  CPPUNIT_TEST_SUITE(mitkImageToSurfaceFilterTestSuite);
41  MITK_TEST(testImageToSurfaceFilterInitialization);
42  MITK_TEST(testInput);
43  MITK_TEST(testSurfaceGeneration);
44  MITK_TEST(testDecimatePromeshDecimation);
45  MITK_TEST(testQuadricDecimation);
46  MITK_TEST(testSmoothingOfSurface);
47  CPPUNIT_TEST_SUITE_END();
48 
49 private:
51  mitk::Image::Pointer m_BallImage;
52 
53 public:
58  void setUp() override { m_BallImage = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("BallBinary30x30x30.nrrd")); }
59  void tearDown() override {}
60  void testImageToSurfaceFilterInitialization()
61  {
63  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of test object", testObject.IsNotNull());
64 
65  // testing initialization of member variables!
66  CPPUNIT_ASSERT_MESSAGE("Testing initialization of threshold member variable", testObject->GetThreshold() == 1.0f);
67  CPPUNIT_ASSERT_MESSAGE("Testing initialization of smooth member variable", testObject->GetSmooth() == false);
68  CPPUNIT_ASSERT_MESSAGE("Testing initialization of decimate member variable",
69  testObject->GetDecimate() == mitk::ImageToSurfaceFilter::NoDecimation);
70  CPPUNIT_ASSERT_MESSAGE("Testing initialization of target reduction member variable",
71  testObject->GetTargetReduction() == 0.95f);
72  }
73 
74  void testInput()
75  {
77  testObject->SetInput(m_BallImage);
78  CPPUNIT_ASSERT_MESSAGE("Testing set / get input!", testObject->GetInput() == m_BallImage);
79  }
80 
81  void testSurfaceGeneration()
82  {
84  testObject->SetInput(m_BallImage);
85  testObject->Update();
86  mitk::Surface::Pointer resultSurface = nullptr;
87  resultSurface = testObject->GetOutput();
88  CPPUNIT_ASSERT_MESSAGE("Testing surface generation!", testObject->GetOutput() != nullptr);
89  }
90 
91  void testDecimatePromeshDecimation()
92  {
94  testObject->SetInput(m_BallImage);
95  testObject->Update();
96  mitk::Surface::Pointer resultSurface = nullptr;
97  resultSurface = testObject->GetOutput();
98 
99  mitk::Surface::Pointer testSurface1 = testObject->GetOutput()->Clone();
100 
101  testObject->SetDecimate(mitk::ImageToSurfaceFilter::DecimatePro);
102  testObject->SetTargetReduction(0.5f);
103  testObject->Update();
104  mitk::Surface::Pointer testSurface2 = testObject->GetOutput()->Clone();
105 
106  CPPUNIT_ASSERT_MESSAGE("Testing DecimatePro mesh decimation!",
107  testSurface1->GetVtkPolyData()->GetPoints()->GetNumberOfPoints() >
108  testSurface2->GetVtkPolyData()->GetPoints()->GetNumberOfPoints());
109  }
110 
111  void testQuadricDecimation()
112  {
114  testObject->SetInput(m_BallImage);
115  testObject->Update();
116  mitk::Surface::Pointer resultSurface = nullptr;
117  resultSurface = testObject->GetOutput();
118 
119  mitk::Surface::Pointer testSurface1 = testObject->GetOutput()->Clone();
120 
121  testObject->SetDecimate(mitk::ImageToSurfaceFilter::QuadricDecimation);
122  testObject->SetTargetReduction(0.5f);
123  testObject->Update();
124  mitk::Surface::Pointer testSurface3 = testObject->GetOutput()->Clone();
125 
126  CPPUNIT_ASSERT_MESSAGE("Testing QuadricDecimation mesh decimation!",
127  testSurface1->GetVtkPolyData()->GetPoints()->GetNumberOfPoints() >
128  testSurface3->GetVtkPolyData()->GetPoints()->GetNumberOfPoints());
129  }
130 
131  void testSmoothingOfSurface()
132  {
134  testObject->SetInput(m_BallImage);
135  testObject->Update();
136  mitk::Surface::Pointer resultSurface = nullptr;
137  resultSurface = testObject->GetOutput();
138 
139  mitk::Surface::Pointer testSurface1 = testObject->GetOutput()->Clone();
140 
141  testObject->SetSmooth(true);
142  testObject->SetDecimate(mitk::ImageToSurfaceFilter::NoDecimation);
143  testObject->Update();
144  mitk::Surface::Pointer testSurface4 = testObject->GetOutput()->Clone();
145  CPPUNIT_ASSERT_MESSAGE("Testing smoothing of surface changes point data!",
146  CompareSurfacePointPositions(testSurface1, testSurface4));
147  }
148 };
149 
150 MITK_TEST_SUITE_REGISTRATION(mitkImageToSurfaceFilter)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
bool CompareSurfacePointPositions(mitk::Surface::Pointer s1, mitk::Surface::Pointer s2)
#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.