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
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,
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 "mitkCommon.h"
18 #include "mitkNumericTypes.h"
19 #include "mitkSurface.h"
21 #include "mitkTestingMacros.h"
22 
23 #include "vtkPolyData.h"
24 #include "vtkSphereSource.h"
25 
26 int mitkSurfaceToSurfaceFilterTest(int /*argc*/, char * /*argv*/ [])
27 {
28  mitk::Surface::Pointer surface;
29  surface = mitk::Surface::New();
30  vtkSphereSource *sphereSource = vtkSphereSource::New();
31  sphereSource->SetCenter(0, 0, 0);
32  sphereSource->SetRadius(5.0);
33  sphereSource->SetThetaResolution(10);
34  sphereSource->SetPhiResolution(10);
35  sphereSource->Update();
36 
37  vtkPolyData *polys = sphereSource->GetOutput();
38  surface->SetVtkPolyData(polys);
39  sphereSource->Delete();
40 
42  MITK_TEST_OUTPUT(<< "Testing mitk::SurfaceToSurfaceFilter::SetInput() and ::GetNumberOfInputs() : ");
43  filter->SetInput(surface);
44  MITK_TEST_CONDITION(filter->GetNumberOfInputs() == 1, "Number of inputs must be 1");
45 
46  MITK_TEST_OUTPUT(<< "Testing if GetInput returns the right Input : ");
47  mitk::Surface::Pointer input = const_cast<mitk::Surface *>(filter->GetInput());
48  MITK_ASSERT_EQUAL(input, surface, "GetInput() should return correct input. ");
49 
50  MITK_TEST_CONDITION(filter->GetInput(5) == nullptr, "GetInput(5) should return NULL. ");
51 
52  MITK_TEST_OUTPUT(<< "Testing whether Output is created correctly : ");
53  MITK_TEST_CONDITION(filter->GetNumberOfOutputs() == filter->GetNumberOfInputs(),
54  "Test if number of outputs == number of inputs");
55 
56  mitk::Surface::Pointer outputSurface = filter->GetOutput();
57  MITK_ASSERT_EQUAL(outputSurface, surface, "Test if output == input");
58 
59  filter->Update();
60  outputSurface = filter->GetOutput();
61  MITK_TEST_CONDITION(outputSurface->GetSizeOfPolyDataSeries() == surface->GetSizeOfPolyDataSeries(),
62  "Test if number of PolyDatas in PolyDataSeries of output == number of PolyDatas of input");
63 
65  MITK_TEST_FOR_EXCEPTION(mitk::Exception, s2sFilter->CreateOutputForInput(500));
66 
67  std::vector<vtkPolyData *> polydatas;
68  for (unsigned int i = 0; i < 5; ++i)
69  {
70  sphereSource = vtkSphereSource::New();
71  sphereSource->SetCenter(0, i, 0);
72  sphereSource->SetRadius(5.0 + i);
73  sphereSource->SetThetaResolution(10);
74  sphereSource->SetPhiResolution(10);
75  sphereSource->Update();
76 
77  vtkPolyData *poly = sphereSource->GetOutput();
79  s->SetVtkPolyData(poly);
80  s2sFilter->SetInput(i, s);
81  polydatas.push_back(s2sFilter->GetOutput(i)->GetVtkPolyData());
82  sphereSource->Delete();
83  }
84 
85  // Test if the outputs are not recreated each time another input is added
86  for (unsigned int i = 0; i < 5; ++i)
87  {
88  MITK_TEST_CONDITION(s2sFilter->GetOutput(i)->GetVtkPolyData() == polydatas.at(i),
89  "Test if pointers are still equal");
90  }
91 
92  // Test if the outputs are recreated after calling CreateOutputsForAllInputs()
93  s2sFilter->CreateOutputsForAllInputs();
94  for (unsigned int i = 0; i < 5; ++i)
95  {
96  MITK_TEST_CONDITION(s2sFilter->GetOutput(i)->GetVtkPolyData() != polydatas.at(i), "Test if pointers are not equal");
97  }
98 
99  // std::cout << "Testing RemoveInputs() : " << std::endl;
100  // unsigned int numOfInputs = filter->GetNumberOfInputs();
101  // filter->RemoveInputs( mitk::Surface::New() );
102  // if ( filter->GetNumberOfInputs() != numOfInputs )
103  //{
104  // std::cout << "[FAILED] : input was removed that was not set." << std::endl;
105  // return EXIT_FAILURE;
106  //}
107  // std::cout << "[SUCCESS] : no input was removed that was not set." << std::endl;
108  // filter->RemoveInputs( surface );
109  // if ( filter->GetNumberOfInputs() != 0 )
110  //{
111  // std::cout << "[FAILED] : existing input was not removed correctly." << std::endl;
112  // return EXIT_FAILURE;
113  //}
114  // std::cout << "[SUCCESS] : existing input was removed correctly." << std::endl;
115 
116  return EXIT_SUCCESS;
117 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
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't instantiate exceptions manually...
Definition: mitkException.h:49
#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()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.