Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPlanarArrowTest.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 "mitkPlanarArrow.h"
18 #include "mitkPlaneGeometry.h"
19 #include "mitkTestingMacros.h"
20 
21 class mitkPlanarArrowTestClass
22 {
23 public:
24  static void TestPlanarArrowPlacement(mitk::PlanarArrow::Pointer PlanarArrow)
25  {
26  // Test for correct minimum number of control points in cross-mode
27  MITK_TEST_CONDITION(PlanarArrow->GetMinimumNumberOfControlPoints() == 2, "Minimum number of control points");
28 
29  // Test for correct maximum number of control points in cross-mode
30  MITK_TEST_CONDITION(PlanarArrow->GetMaximumNumberOfControlPoints() == 2, "Maximum number of control points");
31 
32  // Initial placement of PlanarArrow
33  mitk::Point2D p0;
34  p0[0] = 00.0;
35  p0[1] = 0.0;
36  PlanarArrow->PlaceFigure(p0);
37 
38  // Add second control point
39  mitk::Point2D p1;
40  p1[0] = 50.0;
41  p1[1] = 00.0;
42  PlanarArrow->SetControlPoint(1, p1);
43 
44  // Test for number of control points
45  MITK_TEST_CONDITION(PlanarArrow->GetNumberOfControlPoints() == 2, "Number of control points after placement");
46 
47  // Test for number of polylines
48  const mitk::PlanarFigure::PolyLineType polyLine0 = PlanarArrow->GetPolyLine(0);
49  auto iter = polyLine0.begin();
50  MITK_TEST_CONDITION(PlanarArrow->GetPolyLinesSize() == 1, "Number of polylines after placement");
51 
52  // Get polylines and check if the generated coordinates are OK
53  const mitk::Point2D &pp0 = *iter;
54  iter++;
55  const mitk::Point2D &pp1 = *iter;
56  MITK_TEST_CONDITION((pp0 == p0) && (pp1 == p1), "Correct polyline 1");
57 
58  // Test for number of measurement features
59  // none yet
60  }
61 };
68 int mitkPlanarArrowTest(int /* argc */, char * /*argv*/ [])
69 {
70  // always start with this!
71  MITK_TEST_BEGIN("PlanarArrow")
72 
73  // create PlaneGeometry on which to place the PlanarArrow
75  planeGeometry->InitializeStandardPlane(100.0, 100.0);
76 
77  // **************************************************************************
78  // 1. Instantiation and basic tests
80  PlanarArrow->SetPlaneGeometry(planeGeometry);
81 
82  // first test: did this work?
83  MITK_TEST_CONDITION_REQUIRED(PlanarArrow.IsNotNull(), "Testing instantiation");
84 
85  // Test placement of PlanarArrow by control points
86  mitkPlanarArrowTestClass::TestPlanarArrowPlacement(PlanarArrow);
87  PlanarArrow->EvaluateFeatures();
88 
89  mitk::PlanarArrow::Pointer clonedArrow = PlanarArrow->Clone();
90  MITK_TEST_CONDITION_REQUIRED(clonedArrow.IsNotNull(), "Testing cloning");
91  bool identical(true);
92  identical &= clonedArrow->GetMinimumNumberOfControlPoints() == PlanarArrow->GetMinimumNumberOfControlPoints();
93  identical &= clonedArrow->GetMaximumNumberOfControlPoints() == PlanarArrow->GetMaximumNumberOfControlPoints();
94  identical &= clonedArrow->IsClosed() == PlanarArrow->IsClosed();
95  identical &= clonedArrow->IsPlaced() == PlanarArrow->IsPlaced();
96  identical &= clonedArrow->GetNumberOfControlPoints() == PlanarArrow->GetNumberOfControlPoints();
97  identical &= clonedArrow->GetNumberOfControlPoints() == PlanarArrow->GetNumberOfControlPoints();
98  identical &= clonedArrow->GetSelectedControlPoint() == PlanarArrow->GetSelectedControlPoint();
99  identical &= clonedArrow->IsPreviewControlPointVisible() == PlanarArrow->IsPreviewControlPointVisible();
100  identical &= clonedArrow->GetPolyLinesSize() == PlanarArrow->GetPolyLinesSize();
101  identical &= clonedArrow->GetHelperPolyLinesSize() == PlanarArrow->GetHelperPolyLinesSize();
102  identical &= clonedArrow->ResetOnPointSelect() == PlanarArrow->ResetOnPointSelect();
103 
104  for (unsigned int i = 0; i < clonedArrow->GetNumberOfControlPoints(); ++i)
105  {
106  identical &= clonedArrow->GetControlPoint(i) == PlanarArrow->GetControlPoint(i);
107  }
108 
109  for (unsigned int i = 0; i < clonedArrow->GetPolyLinesSize(); ++i)
110  {
111  mitk::PlanarFigure::PolyLineType polyLine = clonedArrow->GetPolyLine(i);
112  for (unsigned int j = 0; j < polyLine.size(); ++j)
113  {
114  identical &= polyLine.at(j) == PlanarArrow->GetPolyLine(i).at(j);
115  }
116  }
117 
118  MITK_TEST_CONDITION_REQUIRED(identical, "Cloning completely successful");
119 
120  // always end with this!
121  MITK_TEST_END();
122 }
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()
std::vector< PolyLineElement > PolyLineType
and MITK_TEST_END()
int mitkPlanarArrowTest(int, char *[])