Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPlanarSubdivisionPolygonTest.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 
14 #include "mitkPlaneGeometry.h"
15 #include "mitkProperties.h"
16 #include "mitkTestingMacros.h"
17 
18 class mitkPlanarSubdivisionPolygonTestClass
19 {
20 public:
21  static void TestPlanarSubdivisionPolygonPlacement(mitk::PlanarSubdivisionPolygon::Pointer planarSubdivisionPolygon)
22  {
23  // Test for correct minimum number of control points in cross-mode
24  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetMinimumNumberOfControlPoints() == 3,
25  "Minimum number of control points");
26 
27  // Test for correct maximum number of control points in cross-mode
28  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetMaximumNumberOfControlPoints() == 1000,
29  "Maximum number of control points");
30 
31  // Test for correct rounds of subdivisionPoints
32  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetSubdivisionRounds() == 5, "Subdivision point generation depth");
33 
34  // Test for correct tension parameter
35  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetTensionParameter() == 0.0625, "Tension parameter");
36 
37  planarSubdivisionPolygon->SetProperty("initiallyplaced", mitk::BoolProperty::New(true));
38 
39  // Initial placement of planarSubdivisionPolygon
40  mitk::Point2D p0;
41  p0[0] = 25.0;
42  p0[1] = 25.0;
43  planarSubdivisionPolygon->PlaceFigure(p0);
44 
45  // Add second control point
46  mitk::Point2D p1;
47  p1[0] = 75.0;
48  p1[1] = 25.0;
49  planarSubdivisionPolygon->SetControlPoint(1, p1);
50 
51  // Add third control point
52  mitk::Point2D p2;
53  p2[0] = 75.0;
54  p2[1] = 75.0;
55  planarSubdivisionPolygon->AddControlPoint(p2);
56 
57  // Add fourth control point
58  mitk::Point2D p3;
59  p3[0] = 25.0;
60  p3[1] = 75.0;
61  planarSubdivisionPolygon->AddControlPoint(p3);
62 
63  // Test for number of control points
64  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetNumberOfControlPoints() == 4,
65  "Number of control points after placement");
66 
67  // Test if PlanarFigure is closed
68  MITK_TEST_CONDITION(planarSubdivisionPolygon->IsClosed(), "Test if property 'closed' is set by default");
69 
70  // Test for number of polylines
71  const mitk::PlanarFigure::PolyLineType polyLine0 = planarSubdivisionPolygon->GetPolyLine(0);
72  auto iter = polyLine0.begin();
73  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetPolyLinesSize() == 1, "Number of polylines after placement");
74 
75  // Test if subdivision point count is correct
76  MITK_TEST_CONDITION(polyLine0.size() == 128, "correct number of subdivision points for this depth level");
77 
78  // Test if control points are in correct order between subdivision points
79  bool correctPoint = true;
80  iter = polyLine0.begin();
81 
82  if (static_cast<mitk::Point2D>(*iter) != p0)
83  {
84  correctPoint = false;
85  }
86  advance(iter, 32);
87  if (static_cast<mitk::Point2D>(*iter) != p1)
88  {
89  correctPoint = false;
90  }
91  advance(iter, 32);
92  if (static_cast<mitk::Point2D>(*iter) != p2)
93  {
94  correctPoint = false;
95  }
96  advance(iter, 32);
97  if (static_cast<mitk::Point2D>(*iter) != p3)
98  {
99  correctPoint = false;
100  }
101  MITK_TEST_CONDITION(correctPoint, "Test if control points are in correct order in polyline");
102 
103  // Test if a picked point has the correct coordinates
104  correctPoint = true;
105 
106  mitk::Point2D testPoint;
107  testPoint[0] = 81.25;
108  testPoint[1] = 48.243;
109  iter = polyLine0.begin();
110  advance(iter, 47);
111 
112  mitk::ScalarType testEps = 1E-5;
113 
114  if ((static_cast<mitk::Point2D>(*iter)[0] - testPoint[0]) + (static_cast<mitk::Point2D>(*iter)[1] - testPoint[1]) >
115  testEps)
116  {
117  correctPoint = false;
118  }
119 
120  testPoint[0] = 39.624;
121  testPoint[1] = 19.3268;
122  iter = polyLine0.begin();
123  advance(iter, 10);
124  if ((static_cast<mitk::Point2D>(*iter)[0] - testPoint[0]) + (static_cast<mitk::Point2D>(*iter)[1] - testPoint[1]) >
125  testEps)
126  {
127  correctPoint = false;
128  }
129 
130  testPoint[0] = 71.2887;
131  testPoint[1] = 77.5248;
132  iter = polyLine0.begin();
133  advance(iter, 67);
134  if ((static_cast<mitk::Point2D>(*iter)[0] - testPoint[0]) + (static_cast<mitk::Point2D>(*iter)[1] - testPoint[1]) >
135  testEps)
136  {
137  correctPoint = false;
138  }
139 
140  MITK_TEST_CONDITION(correctPoint, "Test if subdivision points are calculated correctly")
141 
142  // Test for number of measurement features
143  /*
144  Does not work yet
145 
146  planarSubdivisionPolygon->EvaluateFeatures();
147  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetNumberOfFeatures() == 2, "Number of measurement features" );
148 
149  // Test for correct feature evaluation
150  double length0 = 4 * 50.0; // circumference
151  MITK_TEST_CONDITION( fabs( planarSubdivisionPolygon->GetQuantity( 0 ) - length0) < mitk::eps, "Size of longest
152  diameter" );
153 
154  double length1 = 50.0 * 50.0 ; // area
155  MITK_TEST_CONDITION( fabs( planarSubdivisionPolygon->GetQuantity( 1 ) - length1) < mitk::eps, "Size of short axis
156  diameter" );
157  */
158  }
159 
160  static void TestPlanarSubdivisionPolygonEditing(mitk::PlanarSubdivisionPolygon::Pointer planarSubdivisionPolygon)
161  {
162  unsigned int initialNumberOfControlPoints = planarSubdivisionPolygon->GetNumberOfControlPoints();
163 
164  mitk::Point2D pnt;
165  pnt[0] = 75.0;
166  pnt[1] = 25.0;
167  planarSubdivisionPolygon->AddControlPoint(pnt);
168 
169  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetNumberOfControlPoints() == initialNumberOfControlPoints + 1,
170  "A new control-point shall be added");
172  planarSubdivisionPolygon->GetControlPoint(planarSubdivisionPolygon->GetNumberOfControlPoints() - 1) == pnt,
173  "Control-point shall be added at the end.");
174 
175  planarSubdivisionPolygon->RemoveControlPoint(3);
176  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetNumberOfControlPoints() == initialNumberOfControlPoints,
177  "A control-point has been removed");
178  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetControlPoint(3) == pnt,
179  "It shall be possible to remove any control-point.");
180 
181  planarSubdivisionPolygon->RemoveControlPoint(0);
182  planarSubdivisionPolygon->RemoveControlPoint(0);
183  planarSubdivisionPolygon->RemoveControlPoint(0);
184  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetNumberOfControlPoints() == 3,
185  "Control-points cannot be removed if only three points remain.");
186 
187  mitk::Point2D pnt1;
188  pnt1[0] = 33.0;
189  pnt1[1] = 33.0;
190  planarSubdivisionPolygon->AddControlPoint(pnt1, 0);
191  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetNumberOfControlPoints() == 4, "A control-point has been added");
192  MITK_TEST_CONDITION(planarSubdivisionPolygon->GetControlPoint(0) == pnt1,
193  "It shall be possible to insert a control-point at any position.");
194  }
195 };
202 int mitkPlanarSubdivisionPolygonTest(int /* argc */, char * /*argv*/ [])
203 {
204  // always start with this!
205  MITK_TEST_BEGIN("planarSubdivisionPolygon")
206 
207  // create PlaneGeometry on which to place the planarSubdivisionPolygon
209  planeGeometry->InitializeStandardPlane(100.0, 100.0);
210 
211  // **************************************************************************
212  // 1. Instantiation and basic tests, including feature evaluation
214  planarSubdivisionPolygon->SetPlaneGeometry(planeGeometry);
215 
216  // first test: did this work?
217  MITK_TEST_CONDITION_REQUIRED(planarSubdivisionPolygon.IsNotNull(), "Testing instantiation");
218 
219  // Test placement of planarSubdivisionPolygon by control points
220  mitkPlanarSubdivisionPolygonTestClass::TestPlanarSubdivisionPolygonPlacement(planarSubdivisionPolygon);
221 
222  mitkPlanarSubdivisionPolygonTestClass::TestPlanarSubdivisionPolygonEditing(planarSubdivisionPolygon);
223 
224  // always end with this!
225  MITK_TEST_END();
226 }
double ScalarType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static Pointer New()
#define MITK_TEST_CONDITION(COND, MSG)
int mitkPlanarSubdivisionPolygonTest(int, char *[])
static const mitk::ScalarType testEps
static Pointer New()
std::vector< PolyLineElement > PolyLineType
and MITK_TEST_END()