Medical Imaging Interaction Toolkit  2016.11.0
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,
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 <mitkTestingConfig.h>
20 
21 #include <mitkIOUtil.h>
24 #include <mitkPlanarFigureReader.h>
25 #include <mitkPlanarFigureWriter.h>
26 
27 #include <mitkPlanarAngle.h>
28 #include <mitkPlanarArrow.h>
29 #include <mitkPlanarBezierCurve.h>
30 #include <mitkPlanarCircle.h>
32 #include <mitkPlanarEllipse.h>
34 #include <mitkPlanarLine.h>
35 #include <mitkPlanarPolygon.h>
36 #include <mitkPlanarRectangle.h>
38 
39 #include <vtkDebugLeaks.h>
40 
41 #include "usModuleRegistry.h"
42 
43 class mitkPlanarFigureInteractionTestSuite : public mitk::TestFixture
44 {
45  CPPUNIT_TEST_SUITE(mitkPlanarFigureInteractionTestSuite);
46  MITK_TEST(AngleInteractionCreate);
47  MITK_TEST(Angle2InteractionCreate);
48  MITK_TEST(BezierCurveInteractionCreate);
49  MITK_TEST(CircleInteractionCreate);
50  MITK_TEST(DoubleEllipseInteractionCreate);
51  MITK_TEST(PlanarFourPointAngleInteractionCreate);
52  MITK_TEST(PlanarLineInteractionCreate);
53  MITK_TEST(PlanarPolygonInteractionCreate);
54  MITK_TEST(NonClosedPlanarPolygonInteractionCreate);
55  MITK_TEST(RectangleInteractionCreate);
56  // BUG 19304
57  // MITK_TEST(PlanarSubdivisionInteractionCreate);
58 
59  CPPUNIT_TEST_SUITE_END();
60 
61 public:
62  void setUp()
63  {
65  vtkDebugLeaks::SetExitError(0);
66  }
67 
68  void tearDown() {}
69  void RunTest(mitk::PlanarFigure::Pointer figure, std::string interactionXmlPath, std::string referenceFigurePath)
70  {
73 
74  // Create DataNode as a container for our PlanarFigure
75  node = mitk::DataNode::New();
76  node->SetData(figure);
77 
78  mitk::InteractionTestHelper interactionTestHelper(GetTestDataFilePath(interactionXmlPath));
79 
80  // Load a bounding image
82  figure->SetGeometry(testImage->GetGeometry());
83 
85  dn->SetData(testImage);
86  interactionTestHelper.AddNodeToStorage(dn);
87  interactionTestHelper.GetDataStorage()->Add(node, dn);
88 
89  node->SetName("PLANAR FIGURE");
90  // set as selected
91  node->SetSelected(true);
92  node->AddProperty("selected", mitk::BoolProperty::New(true));
93 
94  // Load state machine
95  figureInteractor = mitk::PlanarFigureInteractor::New();
96  us::Module *planarFigureModule = us::ModuleRegistry::GetModule("MitkPlanarFigure");
97  figureInteractor->LoadStateMachine("PlanarFigureInteraction.xml", planarFigureModule);
98  figureInteractor->SetEventConfig("PlanarFigureConfig.xml", planarFigureModule);
99  figureInteractor->SetDataNode(node);
100 
101  // Start Interaction
102  interactionTestHelper.PlaybackInteraction();
103 
104  // Load reference PlanarFigure
106  reader->SetFileName(GetTestDataFilePath(referenceFigurePath));
107  reader->Update();
108  mitk::PlanarFigure::Pointer reference = reader->GetOutput(0);
109 
110  // Compare figures
111  MITK_ASSERT_EQUAL(figure, reference, "Compare figure with reference");
112  }
113 
114  void AngleInteractionCreate()
115  {
117  figure = mitk::PlanarAngle::New();
118  RunTest(figure, "InteractionTestData/Interactions/Angle1.xml", "InteractionTestData/ReferenceData/Angle1.pf");
119  }
120 
121  void Angle2InteractionCreate()
122  {
124  figure = mitk::PlanarAngle::New();
125  RunTest(figure, "InteractionTestData/Interactions/Angle2.xml", "InteractionTestData/ReferenceData/Angle2.pf");
126  }
127 
128  void BezierCurveInteractionCreate()
129  {
131  figure = mitk::PlanarBezierCurve::New();
132  RunTest(figure, "InteractionTestData/Interactions/Bezier.xml", "InteractionTestData/ReferenceData/Bezier.pf");
133  }
134 
135  void CircleInteractionCreate()
136  {
138  figure = mitk::PlanarCircle::New();
139  RunTest(figure, "InteractionTestData/Interactions/Circle.xml", "InteractionTestData/ReferenceData/Circle.pf");
140  }
141 
142  void DoubleEllipseInteractionCreate()
143  {
146  RunTest(figure,
147  "InteractionTestData/Interactions/DoubleEllipse.xml",
148  "InteractionTestData/ReferenceData/DoubleEllipse.pf");
149  }
150 
151  void PlanarSubdivisionInteractionCreate()
152  {
155  RunTest(figure,
156  "InteractionTestData/Interactions/SubdivisionPolygon.xml",
157  "InteractionTestData/ReferenceData/SubDivision.pf");
158  }
159 
160  void PlanarFourPointAngleInteractionCreate()
161  {
164  RunTest(figure,
165  "InteractionTestData/Interactions/Planar4PointAngle.xml",
166  "InteractionTestData/ReferenceData/Planar4PointAngle.pf");
167  }
168 
169  void PlanarLineInteractionCreate()
170  {
172  figure = mitk::PlanarLine::New();
173  RunTest(figure, "InteractionTestData/Interactions/Line.xml", "InteractionTestData/ReferenceData/Line.pf");
174  }
175 
176  void PlanarPolygonInteractionCreate()
177  {
179  figure = mitk::PlanarPolygon::New();
180  RunTest(figure, "InteractionTestData/Interactions/Polygon.xml", "InteractionTestData/ReferenceData/Polygon.pf");
181  }
182 
183  void NonClosedPlanarPolygonInteractionCreate()
184  {
186  figure = mitk::PlanarPolygon::New();
187  figure->ClosedOff();
188  RunTest(
189  figure.GetPointer(), "InteractionTestData/Interactions/Path.xml", "InteractionTestData/ReferenceData/Path.pf");
190  }
191 
192  void RectangleInteractionCreate()
193  {
195  figure = mitk::PlanarRectangle::New();
196  RunTest(figure, "InteractionTestData/Interactions/Rectangle.xml", "InteractionTestData/ReferenceData/Rectangle.pf");
197  }
198 };
199 
200 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()
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597