diff --git a/Core/Code/Testing/mitkTypePointConversionTest.cpp b/Core/Code/Testing/mitkTypePointConversionTest.cpp index bea3c9b0e4..a377ccf187 100644 --- a/Core/Code/Testing/mitkTypePointConversionTest.cpp +++ b/Core/Code/Testing/mitkTypePointConversionTest.cpp @@ -1,156 +1,166 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ +#include "mitkTestFixture.h" #include "mitkTestingMacros.h" #include "mitkConstants.h" #include "mitkTypes.h" // for Equal method #include "mitkPoint.h" #include "itkPoint.h" #include "vtkPoints.h" #include "vtkSmartPointer.h" #include using namespace mitk; -static vtkSmartPointer a_vtkPoints = vtkSmartPointer::New(); -static const ScalarType originalValues[] = {1.0, 2.0, 3.0}; -static const ScalarType valuesToCopy[] = {4.0, 5.0, 6.0}; - -static void Setup(void) -{ - a_vtkPoints->Initialize(); -} - - -/** - * @brief Convenience method to test if one vector has been assigned successfully to the other. - * - * More specifically, tests if v1 = v2 was performed correctly. - * - * @param v1 The vector v1 of the assignment v1 = v2 - * @param v2 The vector v2 of the assignment v1 = v2 - * @param v1Name The type name of v1 (e.g.: mitk::Vector3D). Necessary for the correct test output. - * @param v2Name The type name of v2 (e.g.: mitk::Vector3D). Necessary for the correct test output. -* @param eps defines the allowed tolerance when testing for equality. - */ -template -static void TestForEquality(T1 v1, T2 v2, std::string v1Name, std::string v2Name, ScalarType eps = mitk::eps) +class mitkPointTypeConversionsTestSuite : public mitk::TestFixture { - MITK_TEST_CONDITION( EqualArray(v1, v2, 3, eps), "\nAssigning " << v2Name << " to " << v1Name << ":\n both are equal") -} + CPPUNIT_TEST_SUITE(mitkPointTypeConversionsTestSuite); + MITK_TEST(Mitk2Itk_PointCompatibility); + MITK_TEST(Itk2Mitk_PointCompatibility); -static void Test_Mitk2Itk_PointCompatibility() -{ - Setup(); + MITK_TEST(Vtk2Mitk_PointCompatibility); - itk::Point itkPoint3D = originalValues; - mitk::Point3D point3D = valuesToCopy; + MITK_TEST(Mitk2Pod_PointCompatibility); + MITK_TEST(Pod2Mitk_PointCompatibility); - itkPoint3D = point3D; + MITK_TEST(Point2Vector); - TestForEquality(itkPoint3D, point3D, "itk::Point", "mitk:Point"); -} + CPPUNIT_TEST_SUITE_END(); +private: -static void Test_Itk2Mitk_PointCompatibility() -{ - Setup(); + vtkSmartPointer a_vtkPoints; + ScalarType originalValues[3]; + ScalarType valuesToCopy[3]; - mitk::Point3D point3D = originalValues; - itk::Point itkPoint3D = valuesToCopy; - point3D = itkPoint3D; +public: - TestForEquality(point3D, itkPoint3D, "mitk:Point", "itk::Point"); -} + void setUp(void) + { + FillVector3D(originalValues, 1.0, 2.0, 3.0); + FillVector3D(valuesToCopy, 4.0, 5.0, 6.0); -static void Test_Vtk2Mitk_PointCompatibility() -{ - Setup(); + vtkSmartPointer a_vtkPoints = vtkSmartPointer::New(); + a_vtkPoints->Initialize(); + } - mitk::Point3D point3D = originalValues; - a_vtkPoints->InsertNextPoint(valuesToCopy); - double vtkPoint[3]; - a_vtkPoints->GetPoint(0, vtkPoint); + void tearDown(void) + { + a_vtkPoints = NULL; + } - point3D = vtkPoint; - TestForEquality(point3D, vtkPoint, "mitk:Point", "vtkPoint"); + /** + * @brief Convenience method to test if one vector has been assigned successfully to the other. + * + * More specifically, tests if v1 = v2 was performed correctly. + * + * @param v1 The vector v1 of the assignment v1 = v2 + * @param v2 The vector v2 of the assignment v1 = v2 + * @param v1Name The type name of v1 (e.g.: mitk::Vector3D). Necessary for the correct test output. + * @param v2Name The type name of v2 (e.g.: mitk::Vector3D). Necessary for the correct test output. + * @param eps defines the allowed tolerance when testing for equality. + */ + template + void TestForEquality(T1 v1, T2 v2, std::string v1Name, std::string v2Name, ScalarType eps = mitk::eps) + { + CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE("\nAssigning " + v2Name + " to " + v1Name + ":\n both are equal", EqualArray(v1, v2, 3, eps)); + } -} -static void Test_Mitk2Pod_PointCompatibility() -{ - ScalarType podPoint[] = {1.0, 2.0, 3.0}; - mitk::Point3D point3D = valuesToCopy; + void Mitk2Itk_PointCompatibility() + { + itk::Point itkPoint3D = originalValues; + mitk::Point3D point3D = valuesToCopy; - point3D.ToArray(podPoint); + itkPoint3D = point3D; - TestForEquality(podPoint, point3D, "POD point", "mitk::Point"); + TestForEquality(itkPoint3D, point3D, "itk::Point", "mitk:Point"); + } -} -static void Test_Pod2Mitk_PointCompatibility() -{ - itk::Point point3D = originalValues; - ScalarType podPoint[] = {4.0, 5.0, 6.0}; + void Itk2Mitk_PointCompatibility() + { + mitk::Point3D point3D = originalValues; + itk::Point itkPoint3D = valuesToCopy; - point3D = podPoint; + point3D = itkPoint3D; - TestForEquality(point3D, podPoint, "mitk::Point3D", "POD point"); -} + TestForEquality(point3D, itkPoint3D, "mitk:Point", "itk::Point"); + } -static void Test_Point2Vector() -{ - itk::Point point3D = valuesToCopy; - itk::Vector vector3D = originalValues; + void Vtk2Mitk_PointCompatibility() + { + mitk::Point3D point3D = originalValues; + a_vtkPoints->InsertNextPoint(valuesToCopy); + double vtkPoint[3]; + a_vtkPoints->GetPoint(0, vtkPoint); - point3D = vector3D; + point3D = vtkPoint; - TestForEquality(point3D, vector3D, "mitk::Point", "mitk::Vector"); -} + TestForEquality(point3D, vtkPoint, "mitk:Point", "vtkPoint"); + } -/** -* Test the conversions from and to mitk point types -*/ -int mitkTypePointConversionTest(int /*argc*/ , char* /*argv*/[]) -{ - // always start with this! - MITK_TEST_BEGIN("PointConversionTest") + void Mitk2Pod_PointCompatibility() + { + ScalarType podPoint[] = {1.0, 2.0, 3.0}; + mitk::Point3D point3D = valuesToCopy; + + point3D.ToArray(podPoint); + + TestForEquality(podPoint, point3D, "POD point", "mitk::Point"); + + } + + void Pod2Mitk_PointCompatibility() + { + itk::Point point3D = originalValues; + ScalarType podPoint[] = {4.0, 5.0, 6.0}; + + point3D = podPoint; + + TestForEquality(point3D, podPoint, "mitk::Point3D", "POD point"); + } + + + void Point2Vector() + { + itk::Point point3D = valuesToCopy; + itk::Vector vector3D = originalValues; + + point3D = vector3D; - Test_Point2Vector(); + TestForEquality(point3D, vector3D, "mitk::Point", "mitk::Vector"); + } - Test_Mitk2Itk_PointCompatibility(); - Test_Itk2Mitk_PointCompatibility(); +}; - Test_Vtk2Mitk_PointCompatibility(); - Test_Mitk2Pod_PointCompatibility(); - Test_Pod2Mitk_PointCompatibility(); +MITK_TEST_SUITE_REGISTRATION(mitkPointTypeConversions) - MITK_TEST_END() -}