Medical Imaging Interaction Toolkit  2016.11.0
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,
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 #include "mitkException.h"
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 #include <mitkIOUtil.h>
22 
24 {
25  vtkPoints *p1 = s1->GetVtkPolyData()->GetPoints();
26  vtkPoints *p2 = s2->GetVtkPolyData()->GetPoints();
27 
28  if (p1->GetNumberOfPoints() != p2->GetNumberOfPoints())
29  return false;
30 
31  for (int i = 0; i < p1->GetNumberOfPoints(); ++i)
32  {
33  if (p1->GetPoint(i)[0] != p2->GetPoint(i)[0] || p1->GetPoint(i)[1] != p2->GetPoint(i)[1] ||
34  p1->GetPoint(i)[2] != p2->GetPoint(i)[2])
35  {
36  return true;
37  }
38  }
39  return false;
40 }
41 
42 class mitkImageToSurfaceFilterTestSuite : public mitk::TestFixture
43 {
44  CPPUNIT_TEST_SUITE(mitkImageToSurfaceFilterTestSuite);
45  MITK_TEST(testImageToSurfaceFilterInitialization);
46  MITK_TEST(testInput);
47  MITK_TEST(testSurfaceGeneration);
48  MITK_TEST(testDecimatePromeshDecimation);
49  MITK_TEST(testQuadricDecimation);
50  MITK_TEST(testSmoothingOfSurface);
51  CPPUNIT_TEST_SUITE_END();
52 
53 private:
55  mitk::Image::Pointer m_BallImage;
56 
57 public:
62  void setUp() override { m_BallImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("BallBinary30x30x30.nrrd")); }
63  void tearDown() override {}
64  void testImageToSurfaceFilterInitialization()
65  {
67  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of test object", testObject.IsNotNull());
68 
69  // testing initialization of member variables!
70  CPPUNIT_ASSERT_MESSAGE("Testing initialization of threshold member variable", testObject->GetThreshold() == 1.0f);
71  CPPUNIT_ASSERT_MESSAGE("Testing initialization of smooth member variable", testObject->GetSmooth() == false);
72  CPPUNIT_ASSERT_MESSAGE("Testing initialization of decimate member variable",
73  testObject->GetDecimate() == mitk::ImageToSurfaceFilter::NoDecimation);
74  CPPUNIT_ASSERT_MESSAGE("Testing initialization of target reduction member variable",
75  testObject->GetTargetReduction() == 0.95f);
76  }
77 
78  void testInput()
79  {
81  testObject->SetInput(m_BallImage);
82  CPPUNIT_ASSERT_MESSAGE("Testing set / get input!", testObject->GetInput() == m_BallImage);
83  }
84 
85  void testSurfaceGeneration()
86  {
88  testObject->SetInput(m_BallImage);
89  testObject->Update();
90  mitk::Surface::Pointer resultSurface = NULL;
91  resultSurface = testObject->GetOutput();
92  CPPUNIT_ASSERT_MESSAGE("Testing surface generation!", testObject->GetOutput() != NULL);
93  }
94 
95  void testDecimatePromeshDecimation()
96  {
98  testObject->SetInput(m_BallImage);
99  testObject->Update();
100  mitk::Surface::Pointer resultSurface = NULL;
101  resultSurface = testObject->GetOutput();
102 
103  mitk::Surface::Pointer testSurface1 = testObject->GetOutput()->Clone();
104 
105  testObject->SetDecimate(mitk::ImageToSurfaceFilter::DecimatePro);
106  testObject->SetTargetReduction(0.5f);
107  testObject->Update();
108  mitk::Surface::Pointer testSurface2 = testObject->GetOutput()->Clone();
109 
110  CPPUNIT_ASSERT_MESSAGE("Testing DecimatePro mesh decimation!",
111  testSurface1->GetVtkPolyData()->GetPoints()->GetNumberOfPoints() >
112  testSurface2->GetVtkPolyData()->GetPoints()->GetNumberOfPoints());
113  }
114 
115  void testQuadricDecimation()
116  {
118  testObject->SetInput(m_BallImage);
119  testObject->Update();
120  mitk::Surface::Pointer resultSurface = NULL;
121  resultSurface = testObject->GetOutput();
122 
123  mitk::Surface::Pointer testSurface1 = testObject->GetOutput()->Clone();
124 
125  testObject->SetDecimate(mitk::ImageToSurfaceFilter::QuadricDecimation);
126  testObject->SetTargetReduction(0.5f);
127  testObject->Update();
128  mitk::Surface::Pointer testSurface3 = testObject->GetOutput()->Clone();
129 
130  CPPUNIT_ASSERT_MESSAGE("Testing QuadricDecimation mesh decimation!",
131  testSurface1->GetVtkPolyData()->GetPoints()->GetNumberOfPoints() >
132  testSurface3->GetVtkPolyData()->GetPoints()->GetNumberOfPoints());
133  }
134 
135  void testSmoothingOfSurface()
136  {
138  testObject->SetInput(m_BallImage);
139  testObject->Update();
140  mitk::Surface::Pointer resultSurface = NULL;
141  resultSurface = testObject->GetOutput();
142 
143  mitk::Surface::Pointer testSurface1 = testObject->GetOutput()->Clone();
144 
145  testObject->SetSmooth(true);
146  testObject->SetDecimate(mitk::ImageToSurfaceFilter::NoDecimation);
147  testObject->Update();
148  mitk::Surface::Pointer testSurface4 = testObject->GetOutput()->Clone();
149  CPPUNIT_ASSERT_MESSAGE("Testing smoothing of surface changes point data!",
150  CompareSurfacePointPositions(testSurface1, testSurface4));
151  }
152 };
153 
154 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.
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597