Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkLineTest.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 <mitkLine.h>
14 #include <mitkTestFixture.h>
15 #include <mitkTestingMacros.h>
16 
17 class mitkLineTestSuite : public mitk::TestFixture
18 {
19  CPPUNIT_TEST_SUITE(mitkLineTestSuite);
20  MITK_TEST(Line_Instantiation);
21  MITK_TEST(Line_TestPoints);
22  MITK_TEST(Line_TestParallel);
23  MITK_TEST(Test2DLine);
24  MITK_TEST(Test3DLine);
25  CPPUNIT_TEST_SUITE_END();
26 
27 private:
28  mitk::Line<double, 3> m_Line;
29  mitk::Line<double, 2> m_2DLine;
30  mitk::Line<double, 3> m_3DLine;
31 
32 public:
33  void setUp() override
34  {
35  m_Line = mitk::Line<double, 3>();
36 
37  // set up simple 2D Line
38  m_2DLine = mitk::Line<double, 2>();
39  itk::Point<double, 2> p;
40  p[0] = 1;
41  p[1] = 2;
42  m_2DLine.SetPoint(p);
43 
44  itk::Vector<double, 2> direction;
45  direction[0] = 0;
46  direction[1] = 1;
47  m_2DLine.SetDirection(direction);
48 
49  // set up simple 3D Line
50  m_3DLine = mitk::Line<double, 3>();
51  mitk::Point3D p3D;
52  mitk::FillVector3D(p3D, 0, 1, 2);
53  m_3DLine.SetPoint(p3D);
54  mitk::Vector3D direction3D;
55  mitk::FillVector3D(direction3D, 4, 5, 6);
56  m_3DLine.SetDirection(direction3D);
57  }
58 
59  void Line_Instantiation()
60  {
63  CPPUNIT_ASSERT(myLineDouble.GetPoint1()[0] == 0);
64  CPPUNIT_ASSERT(myLineFloat.GetPoint1()[0] == 0);
65  }
66 
67  void Line_TestPoints()
68  {
69  mitk::Point3D point1, point2;
70  mitk::FillVector3D(point1, 0, 1, 0);
71  mitk::FillVector3D(point2, 0, 2.5, 0);
72  m_Line.SetPoint1(point1);
73  m_Line.SetPoint2(point2);
74  CPPUNIT_ASSERT_MESSAGE("Test if point 1 was set correctly.", mitk::Equal(m_Line.GetPoint1(), point1));
75  CPPUNIT_ASSERT_MESSAGE("Test if point 2 was set correctly.", mitk::Equal(m_Line.GetPoint2(), point2));
76  }
77 
78  void Line_TestParallel()
79  {
80  // first line
81  mitk::Point3D point1, point2;
82  mitk::FillVector3D(point1, 0, 1, 0);
83  mitk::FillVector3D(point2, 0, 2.5, 0);
84  m_Line.SetPoint1(point1);
85  m_Line.SetPoint2(point2);
86 
87  // parallel line
88  mitk::Point3D point3;
89  mitk::Vector3D directionLine2;
90  mitk::FillVector3D(point1, 1, 1, 0);
91  mitk::FillVector3D(directionLine2, 0, 1, 0);
92  mitk::Line<double, 3> parallelLine = mitk::Line<double, 3>(point1, directionLine2);
93  CPPUNIT_ASSERT_MESSAGE("Test if lines are parallel.", m_Line.IsParallel(parallelLine));
94 
95  /* Seems as this method is broken, so disabled the test for the moment, see bug 17938
96  MITK_INFO << "Distance: " << m_Line.Distance(point3);
97  CPPUNIT_ASSERT_MESSAGE("Test line distance.",m_Line.Distance(point3)==1.0);
98  */
99  }
100 
101  void Test2DLine()
102  {
103  CPPUNIT_ASSERT_MESSAGE("Testing 2D Line (point[0])", m_2DLine.GetPoint()[0] == 1);
104  CPPUNIT_ASSERT_MESSAGE("Testing 2D Line (point[1])", m_2DLine.GetPoint()[1] == 2);
105  CPPUNIT_ASSERT_MESSAGE("Testing 2D Line (direction[0])", m_2DLine.GetDirection()[0] == 0);
106  CPPUNIT_ASSERT_MESSAGE("Testing 2D Line (direction[1])", m_2DLine.GetDirection()[1] == 1);
107  }
108 
109  void Test3DLine()
110  {
111  CPPUNIT_ASSERT_MESSAGE("Testing 3D Line (point[0])", m_3DLine.GetPoint()[0] == 0);
112  CPPUNIT_ASSERT_MESSAGE("Testing 3D Line (point[1])", m_3DLine.GetPoint()[1] == 1);
113  CPPUNIT_ASSERT_MESSAGE("Testing 3D Line (point[2])", m_3DLine.GetPoint()[2] == 2);
114  CPPUNIT_ASSERT_MESSAGE("Testing 3D Line (direction[0])", m_3DLine.GetDirection()[0] == 4);
115  CPPUNIT_ASSERT_MESSAGE("Testing 3D Line (direction[1])", m_3DLine.GetDirection()[1] == 5);
116  CPPUNIT_ASSERT_MESSAGE("Testing 3D Line (direction[2])", m_3DLine.GetDirection()[2] == 6);
117  }
118 };
119 
void SetPoint2(const itk::Point< TCoordRep, NPointDimension > &point2)
Set/change end point of the line.
Definition: mitkLine.h:114
bool IsParallel(const Line< TCoordRep, NPointDimension > &line) const
Test if a lines is parallel to this line.
Definition: mitkLine.h:201
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
void SetDirection(const itk::Vector< TCoordRep, NPointDimension > &direction)
Set the direction vector of the line.
Definition: mitkLine.h:76
void SetPoint(const itk::Point< TCoordRep, NPointDimension > &point1)
Set/change start point of the line.
Definition: mitkLine.h:60
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:106
const itk::Point< TCoordRep, NPointDimension > & GetPoint() const
Get start point of the line.
Definition: mitkLine.h:49
const itk::Point< TCoordRep, NPointDimension > & GetPoint1() const
Get start point of the line.
Definition: mitkLine.h:111
const itk::Vector< TCoordRep, NPointDimension > & GetDirection() const
Get the direction vector of the line.
Definition: mitkLine.h:70
Test fixture for parameterized tests.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
itk::Point< TCoordRep, NPointDimension > GetPoint2() const
Get end point of the line.
Definition: mitkLine.h:117
void SetPoint1(const itk::Point< TCoordRep, NPointDimension > &point1)
Set/change start point of the line.
Definition: mitkLine.h:100