Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkPointSetDataInteractorTest.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 
19 #include <mitkIOUtil.h>
20 #include <mitkPointSet.h>
22 
23 #include <vtkDebugLeaks.h>
24 
25 class mitkPointSetDataInteractorTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkPointSetDataInteractorTestSuite);
28 
30  vtkDebugLeaks::SetExitError(0);
31 
32  MITK_TEST(AddPointInteraction);
33  MITK_TEST(MoveDeletePointInteraction);
34  // MITK_TEST(RotatedPlanesInteraction);
35  CPPUNIT_TEST_SUITE_END();
36 
37 private:
38  mitk::DataNode::Pointer m_TestPointSetNode;
40  mitk::PointSet::Pointer m_TestPointSet;
41 
42 public:
43  void setUp()
44  {
45  // Create DataNode as a container for our PointSet to be tested
46  m_TestPointSetNode = mitk::DataNode::New();
47 
48  // Create PointSetData Interactor
49  m_DataInteractor = mitk::PointSetDataInteractor::New();
50  // Load the according state machine for regular point set interaction
51  m_DataInteractor->LoadStateMachine("PointSet.xml");
52  // Set the configuration file that defines the triggers for the transitions
53  m_DataInteractor->SetEventConfig("PointSetConfig.xml");
54 
55  // Create new PointSet which will receive the interaction input
56  m_TestPointSet = mitk::PointSet::New();
57  m_TestPointSetNode->SetData(m_TestPointSet);
58  // set the DataNode (which already is added to the DataStorage)
59  m_DataInteractor->SetDataNode(m_TestPointSetNode);
60  }
61 
62  void tearDown()
63  {
64  // destroy all objects
65  if (m_TestPointSetNode != nullptr)
66  {
67  m_TestPointSetNode->SetDataInteractor(nullptr);
68  }
69  m_TestPointSetNode = nullptr;
70  m_TestPointSet = nullptr;
71  m_DataInteractor = nullptr;
72  }
73 
74  void AddPointInteraction()
75  {
76  // Path to the reference PointSet
77  std::string referencePointSetPath = GetTestDataFilePath("InteractionTestData/ReferenceData/TestAddPoints.mps");
78 
79  // Path to the interaction xml file
80  std::string interactionXmlPath = GetTestDataFilePath("InteractionTestData/Interactions/TestAddPoints.xml");
81 
82  std::string pic3D = GetTestDataFilePath("Pic3D.nrrd");
83  mitk::Image::Pointer referenceImage = mitk::IOUtil::Load<mitk::Image>(pic3D);
85  refDN->SetData(referenceImage);
86 
87  // Create test helper to initialize all necessary objects for interaction
88  mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath);
89 
90  // Add our test node to the DataStorage of our test helper
91  interactionTestHelper.AddNodeToStorage(m_TestPointSetNode);
92  interactionTestHelper.AddNodeToStorage(refDN);
93 
94  // Start Interaction
95  interactionTestHelper.PlaybackInteraction();
96 
97  // Load the reference PointSet
98  mitk::PointSet::Pointer referencePointSet = mitk::IOUtil::Load<mitk::PointSet>(referencePointSetPath);
99 
100  // Compare reference with the result of the interaction. Last parameter (false) is set to ignore the geometries.
101  // They are not stored in a file and therefore not equal.
102  CPPUNIT_ASSERT_MESSAGE("", mitk::Equal(referencePointSet, m_TestPointSet, .001, true, false));
103  }
104 
105  void RotatedPlanesInteraction()
106  {
107  // Path to the reference PointSet
108  std::string referencePointSetPath =
109  GetTestDataFilePath("InteractionTestData/ReferenceData/PointSetDataInteractor_PointsAdd2d3d.mps");
110 
111  // Path to the interaction xml file
112  std::string interactionXmlPath =
113  GetTestDataFilePath("InteractionTestData/Interactions/PointSetDataInteractor_PointsAdd2d3d.xml");
114 
115  std::string pic3D = GetTestDataFilePath("Pic3D.nrrd");
116  mitk::Image::Pointer referenceImage = mitk::IOUtil::Load<mitk::Image>(pic3D);
118  refDN->SetData(referenceImage);
119 
120  // Create test helper to initialize all necessary objects for interaction
121  mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath);
122 
123  // Add our test node to the DataStorage of our test helper
124  interactionTestHelper.AddNodeToStorage(m_TestPointSetNode);
125  interactionTestHelper.AddNodeToStorage(refDN);
126 
127  // Start Interaction
128  interactionTestHelper.PlaybackInteraction();
129 
130  // Load the reference PointSet
131  mitk::PointSet::Pointer referencePointSet = mitk::IOUtil::Load<mitk::PointSet>(referencePointSetPath);
132 
133  // Compare reference with the result of the interaction. Last parameter (false) is set to ignore the geometries.
134  // They are not stored in a file and therefore not equal.
135  CPPUNIT_ASSERT_MESSAGE("", mitk::Equal(referencePointSet, m_TestPointSet, .001, true, false));
136  }
137 
138  void PlayInteraction(std::string &xmlFile, mitk::DataNode *node)
139  {
140  mitk::InteractionTestHelper interactionTestHelper(xmlFile);
141  interactionTestHelper.AddNodeToStorage(node);
142  interactionTestHelper.PlaybackInteraction();
143  }
144 
145  void EvaluateState(std::string &refPsFile, mitk::PointSet::Pointer ps, int selected)
146  {
147  mitk::PointSet::Pointer refPs = mitk::IOUtil::Load<mitk::PointSet>(refPsFile);
148  refPs->UpdateOutputInformation();
149  ps->UpdateOutputInformation();
150 
151  MITK_ASSERT_EQUAL(ps, refPs, "");
152 
153  MITK_TEST_CONDITION_REQUIRED(true, "Test against reference point set.");
154  MITK_TEST_CONDITION_REQUIRED(ps->GetNumberOfSelected() == 1, "One selected point.");
155  MITK_TEST_CONDITION_REQUIRED(ps->GetSelectInfo(selected), "Testing if proper point is selected.");
156  }
157 
158  void SetupInteractor(mitk::PointSetDataInteractor *dataInteractor, mitk::DataNode *node)
159  {
160  dataInteractor->LoadStateMachine("PointSet.xml");
161  dataInteractor->SetEventConfig("PointSetConfig.xml");
162  dataInteractor->SetDataNode(node);
163  }
164 
165  void MoveDeletePointInteraction()
166  {
167  // Path to the reference PointSet
168  std::string referencePointSetPath =
169  GetTestDataFilePath("InteractionTestData/ReferenceData/TestMoveRemovePoints.mps");
170 
171  // Path to the interaction xml file
172  std::string interactionXmlPath = GetTestDataFilePath("InteractionTestData/Interactions/TestMoveRemovePoints.xml");
173 
174  std::string pic3D = GetTestDataFilePath("Pic3D.nrrd");
175  mitk::Image::Pointer referenceImage = mitk::IOUtil::Load<mitk::Image>(pic3D);
177  refDN->SetData(referenceImage);
178 
179  // Create test helper to initialize all necessary objects for interaction
180  mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath);
181 
182  // Add our test node to the DataStorage of our test helper
183  interactionTestHelper.AddNodeToStorage(m_TestPointSetNode);
184  interactionTestHelper.AddNodeToStorage(refDN);
185 
186  // Start Interaction
187  interactionTestHelper.PlaybackInteraction();
188 
189  // Load the reference PointSet
190  mitk::PointSet::Pointer referencePointSet = mitk::IOUtil::Load<mitk::PointSet>(referencePointSetPath);
191 
192  // Compare reference with the result of the interaction. Last parameter (false) is set to ignore the geometries.
193  // They are not stored in a file and therefore not equal.
194  CPPUNIT_ASSERT_MESSAGE("", mitk::Equal(referencePointSet, m_TestPointSet, .001, true, false));
195  }
196 
197  // this is only for the OpenGL check
198  mitkPointSetDataInteractorTestSuite() : m_RenderingTestHelper(300, 300) {}
199  private:
200  mitk::RenderingTestHelper m_RenderingTestHelper;
201 };
202 
203 MITK_TEST_SUITE_REGISTRATION(mitkPointSetDataInteractor)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static Pointer New()
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
bool LoadStateMachine(const std::string &filename, const us::Module *module=nullptr)
Loads XML resource.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
Implementation of the PointSetInteractor.
static Pointer New()
Test fixture for parameterized tests.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
Creates everything needed to load and playback interaction events.
virtual void SetDataNode(DataNode *dataNode)
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
bool SetEventConfig(const std::string &filename, const us::Module *module=nullptr)
Loads a configuration from an XML resource.