Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkUnstructuredGridClusteringFilterTest.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"
14 #include <mitkTestFixture.h>
15 #include <mitkUnstructuredGrid.h>
18 
19 #include <mitkIOUtil.h>
20 
21 #include <vtkPoints.h>
22 #include <vtkSmartPointer.h>
23 #include <vtkUnstructuredGrid.h>
24 
25 class mitkUnstructuredGridClusteringFilterTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkUnstructuredGridClusteringFilterTestSuite);
28 
29  MITK_TEST(testUnstructuredGridClusteringFilterInitialization);
30  MITK_TEST(testInput);
31  MITK_TEST(testUnstructuredGridGeneration);
32  MITK_TEST(testReturnedCluster);
33  MITK_TEST(testClusterVector);
34  MITK_TEST(testGetNumberOfFoundClusters);
35  CPPUNIT_TEST_SUITE_END();
36 
37 private:
38  mitk::UnstructuredGrid::Pointer m_UnstructuredGrid;
39 
40 public:
41  void setUp() override
42  {
43  m_UnstructuredGrid = mitk::UnstructuredGrid::New();
44 
45  // Loading the test data
46  std::vector<mitk::BaseData::Pointer> vector =
47  mitk::IOUtil::Load(GetTestDataFilePath("UnstructuredGrid/scoredGrid.vtu"));
48  mitk::BaseData::Pointer base = vector.at(0);
49  m_UnstructuredGrid = dynamic_cast<mitk::UnstructuredGrid *>(base.GetPointer());
50  }
51 
52  void testUnstructuredGridClusteringFilterInitialization()
53  {
55  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of filter object", clusterFilter.IsNotNull());
56  }
57 
58  void testInput()
59  {
61  clusterFilter->SetInput(m_UnstructuredGrid);
62  CPPUNIT_ASSERT_MESSAGE("Testing set / get input!", clusterFilter->GetInput() == m_UnstructuredGrid);
63  }
64 
65  void testUnstructuredGridGeneration()
66  {
68  clusterFilter->SetInput(m_UnstructuredGrid);
69  clusterFilter->SetMeshing(false);
70  clusterFilter->SetMinPts(4);
71  clusterFilter->Seteps(1.2);
72  clusterFilter->Update();
73  CPPUNIT_ASSERT_MESSAGE("Testing output generation!", clusterFilter->GetOutput() != nullptr);
74  }
75 
76  void testReturnedCluster()
77  {
79  clusterFilter->SetInput(m_UnstructuredGrid);
80  clusterFilter->SetMeshing(false);
81  clusterFilter->SetMinPts(4);
82  clusterFilter->Seteps(1.2);
83  clusterFilter->Update();
84  mitk::UnstructuredGrid::Pointer cluster = clusterFilter->GetOutput();
85  CPPUNIT_ASSERT_MESSAGE("Testing the output cluster!",
86  cluster->GetVtkUnstructuredGrid()->GetPoints()->GetNumberOfPoints() == 620);
87  }
88 
89  void testClusterVector()
90  {
92  clusterFilter->SetInput(m_UnstructuredGrid);
93  clusterFilter->SetMeshing(false);
94  clusterFilter->SetMinPts(4);
95  clusterFilter->Seteps(1.2);
96  clusterFilter->Update();
97  std::vector<mitk::UnstructuredGrid::Pointer> clustervector = clusterFilter->GetAllClusters();
98  // test that all clusters have points:
99  bool havePoints = true;
100  for (unsigned int i = 0; i < clustervector.size(); i++)
101  {
102  mitk::UnstructuredGrid::Pointer grid = clustervector.at(i);
103  if (grid->GetVtkUnstructuredGrid()->GetPoints()->GetNumberOfPoints() < 1)
104  havePoints = false;
105  }
106  CPPUNIT_ASSERT_MESSAGE("Testing number of found clusters!", havePoints && clustervector.size() == 17);
107  }
108 
109  void testGetNumberOfFoundClusters()
110  {
112  clusterFilter->SetInput(m_UnstructuredGrid);
113  clusterFilter->SetMeshing(false);
114  clusterFilter->SetMinPts(4);
115  clusterFilter->Seteps(1.2);
116  clusterFilter->Update();
117  CPPUNIT_ASSERT_MESSAGE("Testing number of found clusters!", clusterFilter->GetNumberOfFoundClusters() == 17);
118  }
119 };
120 
121 MITK_TEST_SUITE_REGISTRATION(mitkUnstructuredGridClusteringFilter)
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.
static Pointer New()
Test fixture for parameterized tests.
Class for storing unstructured grids (vtkUnstructuredGrid)
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:489