Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSurfaceToSurfaceFilterTest.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 "mitkCommon.h"
14 #include "mitkNumericTypes.h"
15 #include "mitkSurface.h"
17 #include "mitkTestingMacros.h"
18 
19 #include "vtkPolyData.h"
20 #include "vtkSphereSource.h"
21 
22 int mitkSurfaceToSurfaceFilterTest(int /*argc*/, char * /*argv*/ [])
23 {
24  mitk::Surface::Pointer surface;
25  surface = mitk::Surface::New();
26  vtkSphereSource *sphereSource = vtkSphereSource::New();
27  sphereSource->SetCenter(0, 0, 0);
28  sphereSource->SetRadius(5.0);
29  sphereSource->SetThetaResolution(10);
30  sphereSource->SetPhiResolution(10);
31  sphereSource->Update();
32 
33  vtkPolyData *polys = sphereSource->GetOutput();
34  surface->SetVtkPolyData(polys);
35  sphereSource->Delete();
36 
38  MITK_TEST_OUTPUT(<< "Testing mitk::SurfaceToSurfaceFilter::SetInput() and ::GetNumberOfInputs() : ");
39  filter->SetInput(surface);
40  MITK_TEST_CONDITION(filter->GetNumberOfInputs() == 1, "Number of inputs must be 1");
41 
42  MITK_TEST_OUTPUT(<< "Testing if GetInput returns the right Input : ");
43  mitk::Surface::Pointer input = const_cast<mitk::Surface *>(filter->GetInput());
44  MITK_ASSERT_EQUAL(input, surface, "GetInput() should return correct input. ");
45 
46  MITK_TEST_CONDITION(filter->GetInput(5) == nullptr, "GetInput(5) should return nullptr. ");
47 
48  MITK_TEST_OUTPUT(<< "Testing whether Output is created correctly : ");
49  MITK_TEST_CONDITION(filter->GetNumberOfOutputs() == filter->GetNumberOfInputs(),
50  "Test if number of outputs == number of inputs");
51 
52  mitk::Surface::Pointer outputSurface = filter->GetOutput();
53  MITK_ASSERT_EQUAL(outputSurface, surface, "Test if output == input");
54 
55  filter->Update();
56  outputSurface = filter->GetOutput();
57  MITK_TEST_CONDITION(outputSurface->GetSizeOfPolyDataSeries() == surface->GetSizeOfPolyDataSeries(),
58  "Test if number of PolyDatas in PolyDataSeries of output == number of PolyDatas of input");
59 
61  MITK_TEST_FOR_EXCEPTION(mitk::Exception, s2sFilter->CreateOutputForInput(500));
62 
63  std::vector<vtkPolyData *> polydatas;
64  for (unsigned int i = 0; i < 5; ++i)
65  {
66  sphereSource = vtkSphereSource::New();
67  sphereSource->SetCenter(0, i, 0);
68  sphereSource->SetRadius(5.0 + i);
69  sphereSource->SetThetaResolution(10);
70  sphereSource->SetPhiResolution(10);
71  sphereSource->Update();
72 
73  vtkPolyData *poly = sphereSource->GetOutput();
75  s->SetVtkPolyData(poly);
76  s2sFilter->SetInput(i, s);
77  polydatas.push_back(s2sFilter->GetOutput(i)->GetVtkPolyData());
78  sphereSource->Delete();
79  }
80 
81  // Test if the outputs are not recreated each time another input is added
82  for (unsigned int i = 0; i < 5; ++i)
83  {
84  MITK_TEST_CONDITION(s2sFilter->GetOutput(i)->GetVtkPolyData() == polydatas.at(i),
85  "Test if pointers are still equal");
86  }
87 
88  // Test if the outputs are recreated after calling CreateOutputsForAllInputs()
89  s2sFilter->CreateOutputsForAllInputs();
90  for (unsigned int i = 0; i < 5; ++i)
91  {
92  MITK_TEST_CONDITION(s2sFilter->GetOutput(i)->GetVtkPolyData() != polydatas.at(i), "Test if pointers are not equal");
93  }
94 
95  // std::cout << "Testing RemoveInputs() : " << std::endl;
96  // unsigned int numOfInputs = filter->GetNumberOfInputs();
97  // filter->RemoveInputs( mitk::Surface::New() );
98  // if ( filter->GetNumberOfInputs() != numOfInputs )
99  //{
100  // std::cout << "[FAILED] : input was removed that was not set." << std::endl;
101  // return EXIT_FAILURE;
102  //}
103  // std::cout << "[SUCCESS] : no input was removed that was not set." << std::endl;
104  // filter->RemoveInputs( surface );
105  // if ( filter->GetNumberOfInputs() != 0 )
106  //{
107  // std::cout << "[FAILED] : existing input was not removed correctly." << std::endl;
108  // return EXIT_FAILURE;
109  //}
110  // std::cout << "[SUCCESS] : existing input was removed correctly." << std::endl;
111 
112  return EXIT_SUCCESS;
113 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:28
int mitkSurfaceToSurfaceFilterTest(int, char *[])
#define MITK_TEST_FOR_EXCEPTION(EXCEPTIONCLASS, STATEMENT)
Simplified version of MITK_TEST_FOR_EXCEPTION_BEGIN / END for a single statement. ...
#define MITK_TEST_OUTPUT(x)
Output some text.
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
#define MITK_TEST_CONDITION(COND, MSG)
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
static Pointer New()