Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
22 #include <mitkIOUtil.h>
23 #include <mitkPointSet.h>
25 
26 #include <vtkDebugLeaks.h>
27 
28 class mitkPointSetDataInteractorTestSuite : public mitk::TestFixture
29 {
30  CPPUNIT_TEST_SUITE(mitkPointSetDataInteractorTestSuite);
31 
33  vtkDebugLeaks::SetExitError(0);
34 
35  MITK_TEST(AddPointInteraction);
36  MITK_TEST(MoveDeletePointInteraction);
37  // MITK_TEST(RotatedPlanesInteraction);
38  CPPUNIT_TEST_SUITE_END();
39 
40 private:
41  mitk::DataNode::Pointer m_TestPointSetNode;
43  mitk::PointSet::Pointer m_TestPointSet;
44 
45 public:
46  void setUp()
47  {
48  // Create DataNode as a container for our PointSet to be tested
49  m_TestPointSetNode = mitk::DataNode::New();
50 
51  // Create PointSetData Interactor
52  m_DataInteractor = mitk::PointSetDataInteractor::New();
53  // Load the according state machine for regular point set interaction
54  m_DataInteractor->LoadStateMachine("PointSet.xml");
55  // Set the configuration file that defines the triggers for the transitions
56  m_DataInteractor->SetEventConfig("PointSetConfig.xml");
57 
58  // Create new PointSet which will receive the interaction input
59  m_TestPointSet = mitk::PointSet::New();
60  m_TestPointSetNode->SetData(m_TestPointSet);
61  // set the DataNode (which already is added to the DataStorage)
62  m_DataInteractor->SetDataNode(m_TestPointSetNode);
63  }
64 
65  void tearDown()
66  {
67  // destroy all objects
68  m_TestPointSetNode->SetDataInteractor(NULL);
69  m_TestPointSetNode = NULL;
70  m_TestPointSet = NULL;
71  m_DataInteractor = NULL;
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::LoadImage(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::LoadPointSet(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::LoadImage(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::LoadPointSet(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  {
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::LoadImage(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::LoadPointSet(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 
198 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.
static mitk::PointSet::Pointer LoadPointSet(const std::string &path)
LoadPointSet Convenience method to load an arbitrary mitkPointSet.
Definition: mitkIOUtil.cpp:619
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.
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
bool SetEventConfig(const std::string &filename, const us::Module *module=nullptr)
Loads a configuration from an XML resource.