Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkPlanarFigureInteractionTest.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 <mitkTestingConfig.h>
16 
17 #include <mitkIOUtil.h>
21 #include <mitkPlanarFigureReader.h>
22 #include <mitkPlanarFigureWriter.h>
23 
24 #include <mitkPlanarAngle.h>
25 #include <mitkPlanarArrow.h>
26 #include <mitkPlanarBezierCurve.h>
27 #include <mitkPlanarCircle.h>
29 #include <mitkPlanarEllipse.h>
31 #include <mitkPlanarLine.h>
32 #include <mitkPlanarPolygon.h>
33 #include <mitkPlanarRectangle.h>
35 
36 #include <vtkDebugLeaks.h>
37 
38 #include "usModuleRegistry.h"
39 
40 class mitkPlanarFigureInteractionTestSuite : public mitk::TestFixture
41 {
42  CPPUNIT_TEST_SUITE(mitkPlanarFigureInteractionTestSuite);
43  MITK_TEST(AngleInteractionCreate);
44  MITK_TEST(Angle2InteractionCreate);
45  MITK_TEST(BezierCurveInteractionCreate);
46  MITK_TEST(CircleInteractionCreate);
47  MITK_TEST(DoubleEllipseInteractionCreate);
48  MITK_TEST(PlanarFourPointAngleInteractionCreate);
49  MITK_TEST(PlanarLineInteractionCreate);
50  MITK_TEST(PlanarPolygonInteractionCreate);
51  MITK_TEST(NonClosedPlanarPolygonInteractionCreate);
52  MITK_TEST(RectangleInteractionCreate);
53  // BUG 19304
54  // MITK_TEST(PlanarSubdivisionInteractionCreate);
55 
56  CPPUNIT_TEST_SUITE_END();
57 
58 public:
59  void setUp()
60  {
62  vtkDebugLeaks::SetExitError(0);
63  }
64 
65  void tearDown() {}
66  void RunTest(mitk::PlanarFigure::Pointer figure, std::string interactionXmlPath, std::string referenceFigurePath)
67  {
70 
71  // Create DataNode as a container for our PlanarFigure
72  node = mitk::DataNode::New();
73  node->SetData(figure);
74 
75  mitk::InteractionTestHelper interactionTestHelper(GetTestDataFilePath(interactionXmlPath));
76 
77  // Load a bounding image
78  mitk::Image::Pointer testImage = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("Pic3D.nrrd"));
79  figure->SetGeometry(testImage->GetGeometry());
80 
82  dn->SetData(testImage);
83  interactionTestHelper.AddNodeToStorage(dn);
84  interactionTestHelper.GetDataStorage()->Add(node, dn);
85 
86  node->SetName("PLANAR FIGURE");
87  // set as selected
88  node->SetSelected(true);
89  node->AddProperty("selected", mitk::BoolProperty::New(true));
90 
91  // Load state machine
92  figureInteractor = mitk::PlanarFigureInteractor::New();
93  us::Module *planarFigureModule = us::ModuleRegistry::GetModule("MitkPlanarFigure");
94  figureInteractor->LoadStateMachine("PlanarFigureInteraction.xml", planarFigureModule);
95  figureInteractor->SetEventConfig("PlanarFigureConfig.xml", planarFigureModule);
96  figureInteractor->SetDataNode(node);
97 
98  // Start Interaction
99  interactionTestHelper.PlaybackInteraction();
100 
101  // Load reference PlanarFigure
103  reader->SetFileName(GetTestDataFilePath(referenceFigurePath));
104  reader->Update();
105  mitk::PlanarFigure::Pointer reference = reader->GetOutput(0);
106 
107  // Compare figures
108  MITK_ASSERT_EQUAL(figure, reference, "Compare figure with reference");
109  }
110 
111  void AngleInteractionCreate()
112  {
114  figure = mitk::PlanarAngle::New();
115  RunTest(figure, "InteractionTestData/Interactions/Angle1.xml", "InteractionTestData/ReferenceData/Angle1.pf");
116  }
117 
118  void Angle2InteractionCreate()
119  {
121  figure = mitk::PlanarAngle::New();
122  RunTest(figure, "InteractionTestData/Interactions/Angle2.xml", "InteractionTestData/ReferenceData/Angle2.pf");
123  }
124 
125  void BezierCurveInteractionCreate()
126  {
128  figure = mitk::PlanarBezierCurve::New();
129  RunTest(figure, "InteractionTestData/Interactions/Bezier.xml", "InteractionTestData/ReferenceData/Bezier.pf");
130  }
131 
132  void CircleInteractionCreate()
133  {
135  figure = mitk::PlanarCircle::New();
136  RunTest(figure, "InteractionTestData/Interactions/Circle.xml", "InteractionTestData/ReferenceData/Circle.pf");
137  }
138 
139  void DoubleEllipseInteractionCreate()
140  {
143  RunTest(figure,
144  "InteractionTestData/Interactions/DoubleEllipse.xml",
145  "InteractionTestData/ReferenceData/DoubleEllipse.pf");
146  }
147 
148  void PlanarSubdivisionInteractionCreate()
149  {
152  RunTest(figure,
153  "InteractionTestData/Interactions/SubdivisionPolygon.xml",
154  "InteractionTestData/ReferenceData/SubDivision.pf");
155  }
156 
157  void PlanarFourPointAngleInteractionCreate()
158  {
161  RunTest(figure,
162  "InteractionTestData/Interactions/Planar4PointAngle.xml",
163  "InteractionTestData/ReferenceData/Planar4PointAngle.pf");
164  }
165 
166  void PlanarLineInteractionCreate()
167  {
169  figure = mitk::PlanarLine::New();
170  RunTest(figure, "InteractionTestData/Interactions/Line.xml", "InteractionTestData/ReferenceData/Line.pf");
171  }
172 
173  void PlanarPolygonInteractionCreate()
174  {
176  figure = mitk::PlanarPolygon::New();
177  RunTest(figure, "InteractionTestData/Interactions/Polygon.xml", "InteractionTestData/ReferenceData/Polygon.pf");
178  }
179 
180  void NonClosedPlanarPolygonInteractionCreate()
181  {
183  figure = mitk::PlanarPolygon::New();
184  figure->ClosedOff();
185  RunTest(
186  figure.GetPointer(), "InteractionTestData/Interactions/Path.xml", "InteractionTestData/ReferenceData/Path.pf");
187  }
188 
189  void RectangleInteractionCreate()
190  {
192  figure = mitk::PlanarRectangle::New();
193  RunTest(figure, "InteractionTestData/Interactions/Rectangle.xml", "InteractionTestData/ReferenceData/Rectangle.pf");
194  }
195 
196  // this is only for the OpenGL check
197  mitkPlanarFigureInteractionTestSuite() : m_RenderingTestHelper(300, 300) {}
198  private:
199  mitk::RenderingTestHelper m_RenderingTestHelper;
200 };
201 
202 MITK_TEST_SUITE_REGISTRATION(mitkPlanarFigureInteraction)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static Pointer New()
static Pointer New()
static Module * GetModule(long id)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New()
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
static Pointer New()
static Pointer New()
static Pointer New()
Test fixture for parameterized tests.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
static Pointer New()
Creates everything needed to load and playback interaction events.
static Pointer New()
static Pointer New()