Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
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 
17 #include "mitkTestingMacros.h"
18 #include <mitkTestFixture.h>
19 #include <mitkUnstructuredGrid.h>
22 
23 #include <mitkIOUtil.h>
24 
25 #include <vtkPoints.h>
26 #include <vtkSmartPointer.h>
27 #include <vtkUnstructuredGrid.h>
28 
29 class mitkUnstructuredGridClusteringFilterTestSuite : public mitk::TestFixture
30 {
31  CPPUNIT_TEST_SUITE(mitkUnstructuredGridClusteringFilterTestSuite);
32 
33  MITK_TEST(testUnstructuredGridClusteringFilterInitialization);
34  MITK_TEST(testInput);
35  MITK_TEST(testUnstructuredGridGeneration);
36  MITK_TEST(testReturnedCluster);
37  MITK_TEST(testClusterVector);
38  MITK_TEST(testGetNumberOfFoundClusters);
39  CPPUNIT_TEST_SUITE_END();
40 
41 private:
42  mitk::UnstructuredGrid::Pointer m_UnstructuredGrid;
43 
44 public:
45  void setUp() override
46  {
47  m_UnstructuredGrid = mitk::UnstructuredGrid::New();
48 
49  // Loading the test data
50  std::vector<mitk::BaseData::Pointer> vector =
51  mitk::IOUtil::Load(GetTestDataFilePath("UnstructuredGrid/scoredGrid.vtu"));
52  mitk::BaseData::Pointer base = vector.at(0);
53  m_UnstructuredGrid = dynamic_cast<mitk::UnstructuredGrid *>(base.GetPointer());
54  }
55 
56  void testUnstructuredGridClusteringFilterInitialization()
57  {
59  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of filter object", clusterFilter.IsNotNull());
60  }
61 
62  void testInput()
63  {
65  clusterFilter->SetInput(m_UnstructuredGrid);
66  CPPUNIT_ASSERT_MESSAGE("Testing set / get input!", clusterFilter->GetInput() == m_UnstructuredGrid);
67  }
68 
69  void testUnstructuredGridGeneration()
70  {
72  clusterFilter->SetInput(m_UnstructuredGrid);
73  clusterFilter->SetMeshing(false);
74  clusterFilter->SetMinPts(4);
75  clusterFilter->Seteps(1.2);
76  clusterFilter->Update();
77  CPPUNIT_ASSERT_MESSAGE("Testing output generation!", clusterFilter->GetOutput() != NULL);
78  }
79 
80  void testReturnedCluster()
81  {
83  clusterFilter->SetInput(m_UnstructuredGrid);
84  clusterFilter->SetMeshing(false);
85  clusterFilter->SetMinPts(4);
86  clusterFilter->Seteps(1.2);
87  clusterFilter->Update();
88  mitk::UnstructuredGrid::Pointer cluster = clusterFilter->GetOutput();
89  CPPUNIT_ASSERT_MESSAGE("Testing the output cluster!",
90  cluster->GetVtkUnstructuredGrid()->GetPoints()->GetNumberOfPoints() == 620);
91  }
92 
93  void testClusterVector()
94  {
96  clusterFilter->SetInput(m_UnstructuredGrid);
97  clusterFilter->SetMeshing(false);
98  clusterFilter->SetMinPts(4);
99  clusterFilter->Seteps(1.2);
100  clusterFilter->Update();
101  std::vector<mitk::UnstructuredGrid::Pointer> clustervector = clusterFilter->GetAllClusters();
102  // test that all clusters have points:
103  bool havePoints = true;
104  for (unsigned int i = 0; i < clustervector.size(); i++)
105  {
106  mitk::UnstructuredGrid::Pointer grid = clustervector.at(i);
107  if (grid->GetVtkUnstructuredGrid()->GetPoints()->GetNumberOfPoints() < 1)
108  havePoints = false;
109  }
110  CPPUNIT_ASSERT_MESSAGE("Testing number of found clusters!", havePoints && clustervector.size() == 17);
111  }
112 
113  void testGetNumberOfFoundClusters()
114  {
116  clusterFilter->SetInput(m_UnstructuredGrid);
117  clusterFilter->SetMeshing(false);
118  clusterFilter->SetMinPts(4);
119  clusterFilter->Seteps(1.2);
120  clusterFilter->Update();
121  CPPUNIT_ASSERT_MESSAGE("Testing number of found clusters!", clusterFilter->GetNumberOfFoundClusters() == 17);
122  }
123 };
124 
125 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)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
static Pointer New()