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