Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkPlanarPolygonTest.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 "mitkPlanarPolygon.h"
14 #include "mitkPlaneGeometry.h"
15 #include "mitkTestingMacros.h"
16 
17 class mitkPlanarPolygonTestClass
18 {
19 public:
20  static void TestPlanarPolygonPlacement(mitk::PlanarPolygon::Pointer planarPolygon)
21  {
22  // Test for correct minimum number of control points in cross-mode
23  MITK_TEST_CONDITION(planarPolygon->GetMinimumNumberOfControlPoints() == 3, "Minimum number of control points");
24 
25  // Test for correct maximum number of control points in cross-mode
26  MITK_TEST_CONDITION(planarPolygon->GetMaximumNumberOfControlPoints() == 1000, "Maximum number of control points");
27 
28  // Initial placement of PlanarPolygon
29  mitk::Point2D p0;
30  p0[0] = 00.0;
31  p0[1] = 0.0;
32  planarPolygon->PlaceFigure(p0);
33 
34  // Add second control point
35  mitk::Point2D p1;
36  p1[0] = 50.0;
37  p1[1] = 00.0;
38  planarPolygon->SetControlPoint(1, p1);
39 
40  // Add third control point
41  mitk::Point2D p2;
42  p2[0] = 50.0;
43  p2[1] = 50.0;
44  planarPolygon->AddControlPoint(p2);
45 
46  // Add fourth control point
47  mitk::Point2D p3;
48  p3[0] = 0.0;
49  p3[1] = 50.0;
50  planarPolygon->AddControlPoint(p3);
51 
52  // Test for number of control points
53  MITK_TEST_CONDITION(planarPolygon->GetNumberOfControlPoints() == 4, "Number of control points after placement");
54 
55  // Test if PlanarFigure is closed
56  MITK_TEST_CONDITION(planarPolygon->IsClosed(), "planar polygon should not be closed, yet, right?");
57 
58  planarPolygon->SetClosed(true);
59 
60  MITK_TEST_CONDITION(planarPolygon->IsClosed(), "planar polygon should be closed after function call, right?");
61 
62  // Test for number of polylines
63  const mitk::PlanarFigure::PolyLineType polyLine0 = planarPolygon->GetPolyLine(0);
64  auto iter = polyLine0.begin();
65  MITK_TEST_CONDITION(planarPolygon->GetPolyLinesSize() == 1, "Number of polylines after placement");
66 
67  // Get polylines and check if the generated coordinates are OK
68  const mitk::Point2D &pp0 = *iter;
69  ++iter;
70  const mitk::Point2D &pp1 = *iter;
71  MITK_TEST_CONDITION(((pp0 == p0) && (pp1 == p1)) || ((pp0 == p1) && (pp1 == p0)), "Correct polyline 1");
72 
73  // Test for number of measurement features
74  planarPolygon->EvaluateFeatures();
75  MITK_TEST_CONDITION(planarPolygon->GetNumberOfFeatures() == 2, "Number of measurement features");
76 
77  // Test for correct feature evaluation
78  double length0 = 4 * 50.0; // circumference
79  MITK_TEST_CONDITION(fabs(planarPolygon->GetQuantity(0) - length0) < mitk::eps, "Size of longest diameter");
80 
81  double length1 = 50.0 * 50.0; // area
82  MITK_TEST_CONDITION(fabs(planarPolygon->GetQuantity(1) - length1) < mitk::eps, "Size of short axis diameter");
83  }
84 
85  static void TestPlanarPolygonEditing(mitk::PlanarPolygon::Pointer planarPolygon)
86  {
87  unsigned int initialNumberOfControlPoints = planarPolygon->GetNumberOfControlPoints();
88 
89  mitk::Point2D pnt;
90  pnt[0] = 75.0;
91  pnt[1] = 25.0;
92  planarPolygon->AddControlPoint(pnt);
93 
94  MITK_TEST_CONDITION(planarPolygon->GetNumberOfControlPoints() == initialNumberOfControlPoints + 1,
95  "A new control-point shall be added");
96  MITK_TEST_CONDITION(planarPolygon->GetControlPoint(planarPolygon->GetNumberOfControlPoints() - 1) == pnt,
97  "Control-point shall be added at the end.");
98 
99  planarPolygon->RemoveControlPoint(3);
100  MITK_TEST_CONDITION(planarPolygon->GetNumberOfControlPoints() == initialNumberOfControlPoints,
101  "A control-point has been removed");
102  MITK_TEST_CONDITION(planarPolygon->GetControlPoint(3) == pnt, "It shall be possible to remove any control-point.");
103 
104  planarPolygon->RemoveControlPoint(0);
105  planarPolygon->RemoveControlPoint(0);
106  planarPolygon->RemoveControlPoint(0);
107  MITK_TEST_CONDITION(planarPolygon->GetNumberOfControlPoints() == 3,
108  "Control-points cannot be removed if only three points remain.");
109 
110  mitk::Point2D pnt1;
111  pnt1[0] = 33.0;
112  pnt1[1] = 33.0;
113  planarPolygon->AddControlPoint(pnt1, 0);
114  MITK_TEST_CONDITION(planarPolygon->GetNumberOfControlPoints() == 4, "A control-point has been added");
115  MITK_TEST_CONDITION(planarPolygon->GetControlPoint(0) == pnt1,
116  "It shall be possible to insert a control-point at any position.");
117  }
118 };
125 int mitkPlanarPolygonTest(int /* argc */, char * /*argv*/ [])
126 {
127  // always start with this!
128  MITK_TEST_BEGIN("planarPolygon")
129 
130  // create PlaneGeometry on which to place the planarPolygon
132  planeGeometry->InitializeStandardPlane(100.0, 100.0);
133 
134  // **************************************************************************
135  // 1. Instantiation and basic tests, including feature evaluation
137  planarPolygon->SetPlaneGeometry(planeGeometry);
138 
139  // first test: did this work?
140  MITK_TEST_CONDITION_REQUIRED(planarPolygon.IsNotNull(), "Testing instantiation");
141 
142  // Test placement of planarPolygon by control points
143  mitkPlanarPolygonTestClass::TestPlanarPolygonPlacement(planarPolygon);
144 
145  mitkPlanarPolygonTestClass::TestPlanarPolygonEditing(planarPolygon);
146 
147  // always end with this!
148  MITK_TEST_END();
149 }
int mitkPlanarPolygonTest(int, char *[])
static Pointer New()
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_CONDITION(COND, MSG)
static Pointer New()
MITKCORE_EXPORT const ScalarType eps
std::vector< PolyLineElement > PolyLineType
and MITK_TEST_END()