Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPointSetPointOperationsTest.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 /*
14  * mitkPoinSetPointOperationsTest.cpp
15  *
16  * Created on: Apr 23, 2014
17  * Author: wirkert
18  */
19 
20 #include "mitkTestFixture.h"
21 #include "mitkTestingMacros.h"
22 
23 #include <mitkInteractionConst.h>
24 #include <mitkPointOperation.h>
25 #include <mitkPointSet.h>
26 #include <mitkVector.h>
27 
28 #include <fstream>
29 
33 class mitkPointSetPointOperationsTestSuite : public mitk::TestFixture
34 {
35  CPPUNIT_TEST_SUITE(mitkPointSetPointOperationsTestSuite);
36 
37  MITK_TEST(TestCreateOperationAndAddPoint);
38  MITK_TEST(TestPointOperationOpMove);
39  MITK_TEST(TestPointOperationOpRemove);
40  MITK_TEST(TestPointOperationOpSelectPoint);
41  MITK_TEST(TestOpDeselectPoint);
42  MITK_TEST(TestOpMovePointUp);
43  MITK_TEST(TestOpMovePointDown);
44  MITK_TEST(TestOpMovePointUpOnFirstPoint);
45 
46  CPPUNIT_TEST_SUITE_END();
47 
48 private:
49  mitk::PointSet::Pointer pointSet;
51 
52 public:
53  void setUp() override
54  {
55  // Create PointSet
56  pointSet = mitk::PointSet::New();
57 
58  // add some points
59  mitk::Point3D point2, point3, point4;
60  point2.Fill(3);
61  point3.Fill(4);
62  point4.Fill(5);
63  pointSet->InsertPoint(2, point2);
64  pointSet->InsertPoint(3, point3);
65  pointSet->InsertPoint(4, point4);
66  }
67 
68  void tearDown() override
69  {
70  pointSet = nullptr;
71  delete doOp;
72  }
73 
74  void TestCreateOperationAndAddPoint()
75  {
76  int id = 0;
77  mitk::Point3D point;
78  point.Fill(1);
79 
80  doOp = new mitk::PointOperation(mitk::OpINSERT, point, id);
81 
82  pointSet->ExecuteOperation(doOp);
83  CPPUNIT_ASSERT_EQUAL_MESSAGE(
84  "check if added points exists", true, pointSet->GetSize() == 4 && pointSet->IndexExists(id));
85 
86  mitk::Point3D tempPoint;
87  tempPoint.Fill(0);
88 
89  tempPoint = pointSet->GetPoint(id);
90 
91  CPPUNIT_ASSERT_EQUAL_MESSAGE("check if added point contains real value", true, point == tempPoint);
92  }
93 
94  void TestPointOperationOpMove()
95  {
96  // check opMOVE ExecuteOperation
97  int id = 1;
98  mitk::Point3D point1;
99  mitk::Point3D tempPoint;
100  point1.Fill(2);
101 
102  doOp = new mitk::PointOperation(mitk::OpMOVE, point1, id);
103 
104  pointSet->ExecuteOperation(doOp);
105  tempPoint = pointSet->GetPoint(id);
106 
107  CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpMove ", true, tempPoint == point1);
108 
109  /*
110  if (tempPoint != point1)
111  {
112  std::cout<<"[FAILED]"<<std::endl;
113  return EXIT_FAILURE;
114  }
115  delete doOp;
116  std::cout<<"[PASSED]"<<std::endl;
117  */
118  }
119 
120  void TestPointOperationOpRemove()
121  {
122  // check OpREMOVE ExecuteOperation
123  int id = 0;
124  mitk::Point3D point;
125  mitk::Point3D tempPoint;
126 
127  point = pointSet->GetPoint(id);
128 
129  doOp = new mitk::PointOperation(mitk::OpREMOVE, point, id);
130 
131  pointSet->ExecuteOperation(doOp);
132  tempPoint = pointSet->GetPoint(id);
133 
134  CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpREMOVE ", false, pointSet->IndexExists(id));
135 
136  /*
137  if(pointSet->IndexExists(id))
138  {
139  std::cout<<"[FAILED]"<<std::endl;
140  return EXIT_FAILURE;
141  }
142  delete doOp;
143  std::cout<<"[PASSED]"<<std::endl;
144  */
145  }
146 
147  void TestPointOperationOpSelectPoint()
148  {
149  mitk::Point3D point3(0.);
150  // check OpSELECTPOINT ExecuteOperation
151 
152  doOp = new mitk::PointOperation(mitk::OpSELECTPOINT, point3, 3);
153 
154  pointSet->ExecuteOperation(doOp);
155 
156  CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpSELECTPOINT ", true, pointSet->GetSelectInfo(3));
157 
158  /*
159  if (!pointSet->GetSelectInfo(4))
160  {
161  std::cout<<"[FAILED]"<<std::endl;
162  return EXIT_FAILURE;
163  }
164  delete doOp;
165  std::cout<<"[PASSED]"<<std::endl;
166  */
167  }
168 
169  void TestOpDeselectPoint()
170  {
171  // check OpDESELECTPOINT ExecuteOperation
172  mitk::Point3D point4(0.);
173 
174  doOp = new mitk::PointOperation(mitk::OpDESELECTPOINT, point4, 4);
175 
176  pointSet->ExecuteOperation(doOp);
177 
178  CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpDESELECTPOINT ", false, pointSet->GetSelectInfo(4));
179  CPPUNIT_ASSERT_EQUAL_MESSAGE("check GetNumeberOfSelected ", true, pointSet->GetNumberOfSelected() == 0);
180 
181  /*
182  if (pointSet->GetSelectInfo(4))
183  {
184  std::cout<<"[FAILED]"<<std::endl;
185  return EXIT_FAILURE;
186  }
187  delete doOp;
188  std::cout<<"[PASSED]"<<std::endl;
189 
190 
191  if(pointSet->GetNumberOfSelected() != 0)
192  {
193  std::cout<<"[FAILED]"<<std::endl;
194  return EXIT_FAILURE;
195  }
196  std::cout<<"[PASSED]"<<std::endl;
197  */
198  }
199 
200  void TestOpMovePointUp()
201  {
202  // check OpMOVEPOINTUP ExecuteOperation
203  const int id = 4;
204 
205  mitk::Point3D point = pointSet->GetPoint(id);
206 
207  mitk::Point3D point4(0.);
208  doOp = new mitk::PointOperation(mitk::OpMOVEPOINTUP, point4, id);
209 
210  pointSet->ExecuteOperation(doOp);
211  mitk::Point3D tempPoint = pointSet->GetPoint(id - 1);
212 
213  CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpMOVEPOINTUP ", true, tempPoint == point);
214 
215  /*
216  if (tempPoint != point)
217  {
218  std::cout<<"[FAILED]"<<std::endl;
219  return EXIT_FAILURE;
220  }
221  delete doOp;
222  std::cout<<"[PASSED]"<<std::endl;
223  */
224  }
225 
226  void TestOpMovePointDown()
227  {
228  // check OpMOVEPOINTDown ExecuteOperation
229 
230  const int id = 2;
231 
232  mitk::Point3D point = pointSet->GetPoint(id);
233  mitk::Point3D point2(0.);
234  doOp = new mitk::PointOperation(mitk::OpMOVEPOINTDOWN, point2, id);
235  pointSet->ExecuteOperation(doOp);
236  mitk::Point3D tempPoint = pointSet->GetPoint(id + 1);
237 
238  CPPUNIT_ASSERT_EQUAL_MESSAGE("check PointOperation OpMOVEPOINTDOWN ", true, tempPoint == point);
239 
240  /*
241  if (tempPoint != point)
242  {
243  std::cout<<"[FAILED]"<<std::endl;
244  return EXIT_FAILURE;
245  }
246  std::cout<<"[PASSED]"<<std::endl;
247  */
248  }
249 
250  void TestOpMovePointUpOnFirstPoint()
251  {
252  // check OpMOVEPOINTUP on first point ExecuteOperation
253 
254  mitk::PointSet::PointType p1 = pointSet->GetPoint(1);
255  mitk::PointSet::PointType p2 = pointSet->GetPoint(2);
256 
257  doOp = new mitk::PointOperation(mitk::OpMOVEPOINTUP, p1, 1);
258 
259  pointSet->ExecuteOperation(doOp);
260 
261  mitk::PointSet::PointType newP1 = pointSet->GetPoint(1);
262  mitk::PointSet::PointType newP2 = pointSet->GetPoint(2);
263 
264  CPPUNIT_ASSERT_EQUAL_MESSAGE(
265  "check PointOperation OpMOVEPOINTUP for point id 1: ", true, ((newP1 == p1) && (newP2 == p2)));
266 
267  /*
268  if (((newP1 == p1) && (newP2 == p2)) == false)
269  {
270  std::cout<<"[FAILED]"<<std::endl;
271  return EXIT_FAILURE;
272  }
273  std::cout<<"[PASSED]"<<std::endl;
274  */
275  }
276 };
277 
278 MITK_TEST_SUITE_REGISTRATION(mitkPointSetPointOperations)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static Pointer New()
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Constants for most interaction classes, due to the generic StateMachines.
Test fixture for parameterized tests.
Operation that handles all actions on one Point.