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