Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkImageToUnstructuredGridFilterTest.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 
13 #include "mitkTestingMacros.h"
15 #include <mitkTestFixture.h>
16 
17 #include <mitkIOUtil.h>
18 
19 class mitkImageToUnstructuredGridFilterTestSuite : public mitk::TestFixture
20 {
21  CPPUNIT_TEST_SUITE(mitkImageToUnstructuredGridFilterTestSuite);
22  MITK_TEST(testImageToUnstructuredGridFilterInitialization);
23  MITK_TEST(testInput);
24  MITK_TEST(testUnstructuredGridGeneration);
25  MITK_TEST(testThreshold);
26  CPPUNIT_TEST_SUITE_END();
27 
28 private:
30  mitk::Image::Pointer m_BallImage;
31 
32 public:
37  void setUp() override { m_BallImage = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("BallBinary30x30x30.nrrd")); }
38  void testImageToUnstructuredGridFilterInitialization()
39  {
41  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of test object", testFilter.IsNotNull());
42  CPPUNIT_ASSERT_MESSAGE("Testing initialization of threshold member variable", testFilter->GetThreshold() == -0.1);
43  }
44 
45  void testInput()
46  {
48  testFilter->SetInput(m_BallImage);
49  CPPUNIT_ASSERT_MESSAGE("Testing set / get input!", testFilter->GetInput() == m_BallImage);
50  }
51 
52  void testUnstructuredGridGeneration()
53  {
55  testFilter->SetInput(m_BallImage);
56  testFilter->Update();
57  CPPUNIT_ASSERT_MESSAGE("Testing UnstructuredGrid generation!", testFilter->GetOutput() != nullptr);
58  }
59 
60  void testThreshold()
61  {
63  testFilter1->SetInput(m_BallImage);
64  testFilter1->Update();
65 
66  int numberOfPoints1 = testFilter1->GetNumberOfExtractedPoints();
67 
69  testFilter2->SetInput(m_BallImage);
70  testFilter2->SetThreshold(1.0);
71  testFilter2->Update();
72 
73  int numberOfPoints2 = testFilter2->GetNumberOfExtractedPoints();
74 
75  CPPUNIT_ASSERT_MESSAGE("Testing Threshold", numberOfPoints1 > numberOfPoints2);
76  }
77 };
78 
79 MITK_TEST_SUITE_REGISTRATION(mitkImageToUnstructuredGridFilter)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#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.