Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkUnstructuredGridToUnstructuredGridFilterTest.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>
17 
18 #include <mitkIOUtil.h>
19 
20 #include <vtkDebugLeaks.h>
21 #include <vtkPoints.h>
22 #include <vtkSmartPointer.h>
23 #include <vtkUnstructuredGrid.h>
24 
25 class mitkUnstructuredGridToUnstructuredGridFilterTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkUnstructuredGridToUnstructuredGridFilterTestSuite);
28 
29  vtkDebugLeaks::SetExitError(0);
30 
31  MITK_TEST(testUnstructuredGridToUnstructuredGridFilterInitialization);
32  MITK_TEST(testInput);
33  MITK_TEST(testMultipleInputs);
34  MITK_TEST(testUnstructuredGridGeneration);
35  CPPUNIT_TEST_SUITE_END();
36 
37 private:
38  mitk::UnstructuredGrid::Pointer m_UnstructuredGrid;
39  mitk::UnstructuredGrid::Pointer m_2ndUnstructuredGrid;
40 
41 public:
42  void setUp() override
43  {
44  m_UnstructuredGrid = mitk::UnstructuredGrid::New();
45  m_2ndUnstructuredGrid = mitk::UnstructuredGrid::New();
46  vtkSmartPointer<vtkUnstructuredGrid> vtkGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
47  vtkSmartPointer<vtkUnstructuredGrid> vtkGrid2 = vtkSmartPointer<vtkUnstructuredGrid>::New();
48  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
49  vtkSmartPointer<vtkPoints> points2 = vtkSmartPointer<vtkPoints>::New();
50 
51  for (int i = 0; i < 3; i++)
52  {
53  for (int j = 0; j < 3; j++)
54  {
55  for (int k = 0; k < 3; k++)
56  {
57  mitk::Point3D point;
58  point[0] = i;
59  point[1] = j;
60  point[2] = k;
61 
62  points->InsertNextPoint(point[0], point[1], point[2]);
63  points2->InsertNextPoint(point[0] + 5, point[1] + 5, point[2] + 5);
64  }
65  }
66  }
67 
68  vtkGrid->SetPoints(points);
69  vtkGrid2->SetPoints(points2);
70  m_UnstructuredGrid->SetVtkUnstructuredGrid(vtkGrid);
71  m_2ndUnstructuredGrid->SetVtkUnstructuredGrid(vtkGrid2);
72  }
73 
74  void testUnstructuredGridToUnstructuredGridFilterInitialization()
75  {
78  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of test object", testFilter.IsNotNull());
79  }
80 
81  void testInput()
82  {
85  testFilter->SetInput(m_UnstructuredGrid);
86  CPPUNIT_ASSERT_MESSAGE("Testing set / get input!", testFilter->GetInput() == m_UnstructuredGrid);
87  }
88 
89  void testMultipleInputs()
90  {
93  testFilter->SetInput(0, m_UnstructuredGrid);
94  testFilter->SetInput(1, m_2ndUnstructuredGrid);
95  CPPUNIT_ASSERT_MESSAGE("Testing first input!", testFilter->GetInput(0) == m_UnstructuredGrid);
96  CPPUNIT_ASSERT_MESSAGE("Testing second input!", testFilter->GetInput(1) == m_2ndUnstructuredGrid);
97  }
98 
99  void testUnstructuredGridGeneration()
100  {
103  testFilter->SetInput(m_UnstructuredGrid);
104  testFilter->Update();
105  CPPUNIT_ASSERT_MESSAGE("Testing unstructured grid generation!", testFilter->GetOutput() != nullptr);
106  }
107 };
108 
109 MITK_TEST_SUITE_REGISTRATION(mitkUnstructuredGridToUnstructuredGridFilter)
float k(1.0)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New()
Test fixture for parameterized tests.