diff --git a/Core/Code/Testing/mitkGeometry3DEqualTest.cpp b/Core/Code/Testing/mitkGeometry3DEqualTest.cpp index 8ed6270216..7106f982f8 100644 --- a/Core/Code/Testing/mitkGeometry3DEqualTest.cpp +++ b/Core/Code/Testing/mitkGeometry3DEqualTest.cpp @@ -1,126 +1,126 @@ /*=================================================================== 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 "mitkGeometry3D.h" #include "mitkTestingMacros.h" -#include "cppunit/TestFixture.h" +#include class mitkGeometry3DEqualTestSuite : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(mitkGeometry3DEqualTestSuite); CPPUNIT_TEST(Equal_CloneAndOriginal_ReturnsTrue); CPPUNIT_TEST(Equal_DifferentOrigin_ReturnsFalse); CPPUNIT_TEST(Equal_DifferentIndexToWorldTransform_ReturnsFalse); CPPUNIT_TEST(Equal_DifferentSpacing_ReturnsFalse); CPPUNIT_TEST(Equal_InputIsNull_ReturnsFalse); CPPUNIT_TEST(Equal_DifferentImageGeometry_ReturnsFalse); CPPUNIT_TEST(Equal_DifferentBoundingBox_ReturnsFalse); CPPUNIT_TEST_SUITE_END(); private: /** Members used inside the different test methods. All members are initialized via setUp().*/ mitk::Geometry3D::Pointer m_Geometry3D; mitk::Geometry3D::Pointer m_AnotherGeometry3D; public: /** * @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). */ void setUp() { m_Geometry3D = mitk::Geometry3D::New(); m_Geometry3D->Initialize(); m_AnotherGeometry3D = m_Geometry3D->Clone(); } void tearDown() { m_Geometry3D = NULL; m_AnotherGeometry3D = NULL; } void Equal_CloneAndOriginal_ReturnsTrue() { MITK_ASSERT_EQUAL( m_Geometry3D, m_AnotherGeometry3D, "A clone should be equal to its original."); } void Equal_DifferentOrigin_ReturnsFalse() { mitk::Point3D origin; origin[0] = 0.0; origin[1] = 0.0; origin[2] = 1.0 + 2*mitk::eps; m_AnotherGeometry3D->SetOrigin(origin); MITK_ASSERT_NOT_EQUAL( m_Geometry3D, m_AnotherGeometry3D, "Origin was modified. Result should be false."); } void Equal_DifferentIndexToWorldTransform_ReturnsFalse() { //Create another index to world transform and make it different somehow mitk::AffineTransform3D::Pointer differentIndexToWorldTransform = mitk::AffineTransform3D::New(); mitk::AffineTransform3D::MatrixType differentMatrix; differentMatrix.SetIdentity(); differentMatrix(1,1) = 2; differentIndexToWorldTransform->SetMatrix( differentMatrix ); m_AnotherGeometry3D->SetIndexToWorldTransform(differentIndexToWorldTransform); MITK_ASSERT_NOT_EQUAL( m_Geometry3D, m_AnotherGeometry3D, "IndexToWorldTransform was modified. Result should be false."); } void Equal_DifferentSpacing_ReturnsFalse() { mitk::Vector3D differentSpacing; differentSpacing[0] = 1.0; differentSpacing[1] = 1.0 + 2*mitk::eps; differentSpacing[2] = 1.0; m_AnotherGeometry3D->SetSpacing(differentSpacing); MITK_ASSERT_NOT_EQUAL( m_Geometry3D, m_AnotherGeometry3D, "Spacing was modified. Result should be false."); } void Equal_InputIsNull_ReturnsFalse() { mitk::Geometry3D::Pointer geometry3D = NULL; MITK_ASSERT_NOT_EQUAL( geometry3D, geometry3D, "Input is NULL. Result should be false."); } void Equal_DifferentImageGeometry_ReturnsFalse() { m_AnotherGeometry3D->SetImageGeometry(true); MITK_ASSERT_NOT_EQUAL( m_Geometry3D, m_AnotherGeometry3D, "One Geometry is image, the other is not. Result should be false."); } void Equal_DifferentBoundingBox_ReturnsFalse() { //create different bounds to make the comparison false float bounds[ ] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; m_AnotherGeometry3D->SetBounds(bounds); MITK_ASSERT_NOT_EQUAL( m_Geometry3D, m_AnotherGeometry3D, "Bounds are different. Result should be false."); } }; MITK_TEST_SUITE_REGISTRATION(mitkGeometry3DEqual) diff --git a/Core/Code/Testing/mitkImageEqualTest.cpp b/Core/Code/Testing/mitkImageEqualTest.cpp index f4cf2f1612..41354cfb7b 100644 --- a/Core/Code/Testing/mitkImageEqualTest.cpp +++ b/Core/Code/Testing/mitkImageEqualTest.cpp @@ -1,119 +1,120 @@ /*=================================================================== 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 "mitkImage.h" #include "mitkImageGenerator.h" #include "mitkTestingMacros.h" #include "mitkImageSliceSelector.h" -/** Members used inside the different (sub-)tests. All members are initialized via Setup().*/ -mitk::Image::Pointer m_Image; -mitk::Image::Pointer m_AnotherImage; +#include -/** -* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). -*/ -static void Setup() -{ - //generate a gradient test image - m_Image = mitk::ImageGenerator::GenerateGradientImage(3u, 3u, 1u); - m_AnotherImage = m_Image->Clone(); -} - -void Equal_CloneAndOriginal_ReturnsTrue() +class mitkImageEqualTestSuite : public CppUnit::TestFixture { - Setup(); - MITK_TEST_EQUAL( m_Image, m_AnotherImage, "A clone should be equal to its original."); -} -static void Equal_InputIsNull_ReturnsFalse() -{ - mitk::Image::Pointer image = NULL; - MITK_TEST_NOT_EQUAL( image, image, "Input is NULL. Result should be false."); -} - -static void Equal_DifferentImageGeometry_ReturnsFalse() -{ - Setup(); + CPPUNIT_TEST_SUITE(mitkImageEqualTestSuite); + CPPUNIT_TEST(Equal_CloneAndOriginal_ReturnsTrue); + CPPUNIT_TEST(Equal_InputIsNull_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentImageGeometry_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentPixelTypes_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentDimensions_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentDimensionalities_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentPixelValues_ReturnsFalse); + CPPUNIT_TEST_SUITE_END(); - mitk::Point3D origin; - origin[0] = 0.0; - origin[1] = 0.0; - origin[2] = mitk::eps * 1.01; +private: - m_AnotherImage->GetGeometry()->SetOrigin(origin); + /** Members used inside the different (sub-)tests. All members are initialized via setUp().*/ + mitk::Image::Pointer m_Image; + mitk::Image::Pointer m_AnotherImage; - MITK_TEST_NOT_EQUAL( m_Image, m_AnotherImage, "One origin was modified. Result should be false."); -} - -static void Equal_DifferentPixelTypes_ReturnsFalse() -{ - Setup(); - - m_AnotherImage = mitk::ImageGenerator::GenerateGradientImage(3u, 3u, 1u); - - MITK_TEST_NOT_EQUAL( m_Image, m_AnotherImage, "One pixel type is float, the other unsigned char. Result should be false."); -} - -static void Equal_DifferentDimensions_ReturnsFalse() -{ - Setup(); +public: - m_AnotherImage = mitk::ImageGenerator::GenerateGradientImage(5u, 7u, 3u); - - MITK_TEST_NOT_EQUAL( m_Image, m_AnotherImage, "Dimensions of first image are: (3, 3, 1). Dimensions of second image are: (5, 7, 3). Result should be false."); -} - -static void Equal_DifferentDimensionalities_ReturnsFalse() -{ - Setup(); - - //Select the first slice of a 2D image and compare it to the 3D original - mitk::ImageSliceSelector::Pointer sliceSelector = mitk::ImageSliceSelector::New(); - sliceSelector->SetInput( m_Image ); - sliceSelector->SetSliceNr( 0 ); - sliceSelector->Update(); - m_AnotherImage = sliceSelector->GetOutput(); - - MITK_TEST_NOT_EQUAL( m_Image, m_AnotherImage, "First image is 3D. Second image is 2D. Result should be false."); -} - -static void Equal_DifferentPixelValues_ReturnsFalse() -{ - //todo: Replace the random images via simpler images with fixed values. - m_Image = mitk::ImageGenerator::GenerateRandomImage(3u, 3u); - m_AnotherImage = mitk::ImageGenerator::GenerateRandomImage(3u, 3u); - - MITK_TEST_NOT_EQUAL( m_Image, m_AnotherImage, "We compare two random images. Result should be false."); -} - -/** - * @brief mitkImageAreEqualTest A test class for Equal methods in mitk::Image. - */ -int mitkImageEqualTest(int /*argc*/, char* /*argv*/[]) -{ - MITK_TEST_BEGIN(mitkImageAreEqualTest); - - Equal_CloneAndOriginal_ReturnsTrue(); - Equal_InputIsNull_ReturnsFalse(); - Equal_DifferentImageGeometry_ReturnsFalse(); - Equal_DifferentPixelTypes_ReturnsFalse(); - Equal_DifferentDimensions_ReturnsFalse(); - Equal_DifferentDimensionalities_ReturnsFalse(); - Equal_DifferentPixelValues_ReturnsFalse(); - - MITK_TEST_END(); -} + /** +* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). +*/ + void setUp() + { + //generate a gradient test image + m_Image = mitk::ImageGenerator::GenerateGradientImage(3u, 3u, 1u); + m_AnotherImage = m_Image->Clone(); + } + + void tearDown() + { + m_Image = NULL; + m_AnotherImage = NULL; + } + + void Equal_CloneAndOriginal_ReturnsTrue() + { + MITK_ASSERT_EQUAL( m_Image, m_Image->Clone(), "A clone should be equal to its original."); + } + + void Equal_InputIsNull_ReturnsFalse() + { + mitk::Image::Pointer image = NULL; + MITK_ASSERT_NOT_EQUAL( image, image, "Input is NULL. Result should be false."); + } + + void Equal_DifferentImageGeometry_ReturnsFalse() + { + mitk::Point3D origin; + origin[0] = 0.0; + origin[1] = 0.0; + origin[2] = mitk::eps * 1.01; + + m_AnotherImage->GetGeometry()->SetOrigin(origin); + + MITK_ASSERT_NOT_EQUAL( m_Image, m_AnotherImage, "One origin was modified. Result should be false."); + } + + void Equal_DifferentPixelTypes_ReturnsFalse() + { + m_AnotherImage = mitk::ImageGenerator::GenerateGradientImage(3u, 3u, 1u); + + MITK_ASSERT_NOT_EQUAL( m_Image, m_AnotherImage, "One pixel type is float, the other unsigned char. Result should be false."); + } + + void Equal_DifferentDimensions_ReturnsFalse() + { + m_AnotherImage = mitk::ImageGenerator::GenerateGradientImage(5u, 7u, 3u); + + MITK_ASSERT_NOT_EQUAL( m_Image, m_AnotherImage, "Dimensions of first image are: (3, 3, 1). Dimensions of second image are: (5, 7, 3). Result should be false."); + } + + void Equal_DifferentDimensionalities_ReturnsFalse() + { + //Select the first slice of a 2D image and compare it to the 3D original + mitk::ImageSliceSelector::Pointer sliceSelector = mitk::ImageSliceSelector::New(); + sliceSelector->SetInput( m_Image ); + sliceSelector->SetSliceNr( 0 ); + sliceSelector->Update(); + m_AnotherImage = sliceSelector->GetOutput(); + + MITK_ASSERT_NOT_EQUAL( m_Image, m_AnotherImage, "First image is 3D. Second image is 2D. Result should be false."); + } + + void Equal_DifferentPixelValues_ReturnsFalse() + { + //todo: Replace the random images via simpler images with fixed values. + m_Image = mitk::ImageGenerator::GenerateRandomImage(3u, 3u); + m_AnotherImage = mitk::ImageGenerator::GenerateRandomImage(3u, 3u); + + MITK_ASSERT_NOT_EQUAL( m_Image, m_AnotherImage, "We compare two random images. Result should be false."); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkImageEqual) diff --git a/Core/Code/Testing/mitkPointSetEqualTest.cpp b/Core/Code/Testing/mitkPointSetEqualTest.cpp index bf98632e93..81dc959a8f 100644 --- a/Core/Code/Testing/mitkPointSetEqualTest.cpp +++ b/Core/Code/Testing/mitkPointSetEqualTest.cpp @@ -1,105 +1,115 @@ /*=================================================================== 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 "mitkPointSet.h" #include "mitkTestingMacros.h" -#include -/** Members used inside the different (sub-)tests. All members are initialized via Setup().*/ -mitk::PointSet::Pointer m_PointSet; -mitk::PointSet::Pointer m_AnotherPointSet; +#include -/** -* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). -*/ -static void Setup() -{ - m_PointSet = mitk::PointSet::New(); - m_AnotherPointSet = m_PointSet->Clone(); -} -static void Equal_CloneAndOriginal_ReturnsTrue() -{ - Setup(); - MITK_TEST_EQUAL( m_PointSet, m_AnotherPointSet, "A clone should be equal to its original."); -} - -static void Equal_DifferentGeometries_ReturnsFalse() -{ - Setup(); - - mitk::Point3D origin; - origin[0] = 0.0; - origin[1] = 0.0; - origin[2] = 1.0 + 2*mitk::eps; - m_AnotherPointSet->GetGeometry()->SetOrigin(origin); - - MITK_TEST_NOT_EQUAL( m_PointSet, m_AnotherPointSet, "Origin was modified. Result should be false."); -} - -static void Equal_InputIsNull_ReturnsFalse() -{ - mitk::PointSet::Pointer pointSet = NULL; - MITK_TEST_NOT_EQUAL( pointSet, pointSet, "Input is NULL. Result should be false."); -} - -static void Equal_DifferentNumberOfPoints_ReturnsFalse() -{ - Setup(); - mitk::Point3D tmpPoint; - tmpPoint[0] = 1.0; - tmpPoint[1] = 1.0; - tmpPoint[2] = 1.0; - - m_PointSet->InsertPoint( 1, tmpPoint ); - m_PointSet->InsertPoint( 2, tmpPoint ); - - m_AnotherPointSet->InsertPoint( 1, tmpPoint ); - - MITK_TEST_NOT_EQUAL( m_PointSet, m_AnotherPointSet, "One pointset has two points the other has one. Result should be false."); -} +/** + * @brief mitkPointSetEqualTestSuite A test class for Equal methods in mitk::PointSet. + */ -static void Equal_DifferentPoints_ReturnsFalse() +class mitkPointSetEqualTestSuite : public CppUnit::TestFixture { - Setup(); - - mitk::Point3D tmpPoint; - tmpPoint[0] = 1.0; - tmpPoint[1] = 1.0; - tmpPoint[2] = 1.0; - m_PointSet->InsertPoint( 1, tmpPoint ); + CPPUNIT_TEST_SUITE(mitkPointSetEqualTestSuite); + CPPUNIT_TEST(Equal_CloneAndOriginal_ReturnsTrue); + CPPUNIT_TEST(Equal_DifferentGeometries_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentNumberOfPoints_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentPoints_ReturnsFalse); + CPPUNIT_TEST(Equal_InputIsNull_ReturnsFalse); + CPPUNIT_TEST_SUITE_END(); - tmpPoint[0] = 1.0 + 2*mitk::eps; - m_AnotherPointSet->InsertPoint( 1, tmpPoint ); +private: - MITK_TEST_NOT_EQUAL( m_PointSet, m_AnotherPointSet, "Two pointsets with different points. Result should be false."); -} + /** Members used inside the different (sub-)tests. All members are initialized via setUp().*/ + mitk::PointSet::Pointer m_PointSet; + mitk::PointSet::Pointer m_AnotherPointSet; -/** - * @brief mitkPointSetEqualTest A test class for Equal methods in mitk::PointSet. - */ -int mitkPointSetEqualTest(int /*argc*/, char* /*argv*/[]) -{ - MITK_TEST_BEGIN(mitkPointSetEqualTest); +public: - Equal_CloneAndOriginal_ReturnsTrue(); - Equal_InputIsNull_ReturnsFalse(); - Equal_DifferentGeometries_ReturnsFalse(); - Equal_DifferentNumberOfPoints_ReturnsFalse(); - Equal_DifferentPoints_ReturnsFalse(); - - MITK_TEST_END(); -} + /** +* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). +*/ + void setUp() + { + m_PointSet = mitk::PointSet::New(); + m_AnotherPointSet = m_PointSet->Clone(); + } + + void tearDown() + { + m_PointSet = NULL; + m_AnotherPointSet = NULL; + } + + void Equal_CloneAndOriginal_ReturnsTrue() + { + mitk::PointSet::Pointer newPointSet = mitk::PointSet::New(); + MITK_ASSERT_EQUAL( newPointSet, newPointSet->Clone(), "A clone should be equal to its original."); + } + + void Equal_DifferentGeometries_ReturnsFalse() + { + mitk::Point3D origin; + origin[0] = 0.0; + origin[1] = 0.0; + origin[2] = 1.0 + 2*mitk::eps; + m_AnotherPointSet->GetGeometry()->SetOrigin(origin); + + MITK_ASSERT_NOT_EQUAL( m_PointSet, m_AnotherPointSet, "Origin was modified. Result should be false."); + } + + void Equal_InputIsNull_ReturnsFalse() + { + mitk::PointSet::Pointer pointSet = NULL; + MITK_ASSERT_NOT_EQUAL( pointSet, pointSet, "Input is NULL. Result should be false."); + } + + void Equal_DifferentNumberOfPoints_ReturnsFalse() + { + mitk::Point3D tmpPoint; + tmpPoint[0] = 1.0; + tmpPoint[1] = 1.0; + tmpPoint[2] = 1.0; + + m_PointSet->InsertPoint( 1, tmpPoint ); + m_PointSet->InsertPoint( 2, tmpPoint ); + + m_AnotherPointSet->InsertPoint( 1, tmpPoint ); + + MITK_ASSERT_NOT_EQUAL( m_PointSet, m_AnotherPointSet, "One pointset has two points the other has one. Result should be false."); + } + + void Equal_DifferentPoints_ReturnsFalse() + { + mitk::Point3D tmpPoint; + tmpPoint[0] = 1.0; + tmpPoint[1] = 1.0; + tmpPoint[2] = 1.0; + + m_PointSet->InsertPoint( 1, tmpPoint ); + + tmpPoint[0] = 1.0 + 2*mitk::eps; + m_AnotherPointSet->InsertPoint( 1, tmpPoint ); + + MITK_ASSERT_NOT_EQUAL( m_PointSet, m_AnotherPointSet, "Two pointsets with different points. Result should be false."); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkPointSetEqual) diff --git a/Core/Code/Testing/mitkSurfaceEqualTest.cpp b/Core/Code/Testing/mitkSurfaceEqualTest.cpp index 072abba9f6..f07a0a6487 100644 --- a/Core/Code/Testing/mitkSurfaceEqualTest.cpp +++ b/Core/Code/Testing/mitkSurfaceEqualTest.cpp @@ -1,181 +1,191 @@ /*=================================================================== 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 "mitkSurface.h" #include "mitkTestingMacros.h" #include #include #include #include #include -/** Members used inside the different (sub-)tests. All members are initialized via Setup().*/ -mitk::Surface::Pointer m_Surface3D; -mitk::Surface::Pointer m_Surface3DTwoTimeSteps; +#include -vtkSmartPointer m_PointsOne; -vtkSmartPointer m_PointsTwo; -vtkSmartPointer m_PolygonArrayTwo; -vtkSmartPointer m_PolyDataOne; /** -* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). -*/ -static void Setup() -{ - //generate two sets of points - m_PointsOne = vtkSmartPointer::New(); - m_PointsOne->InsertNextPoint( 0.0, 0.0, 0.0 ); - m_PointsOne->InsertNextPoint( 1.0, 0.0, 0.0 ); - m_PointsOne->InsertNextPoint( 0.0, 1.0, 0.0 ); - m_PointsOne->InsertNextPoint( 1.0, 1.0, 0.0 ); - - m_PointsTwo = vtkSmartPointer::New(); - m_PointsTwo->InsertNextPoint( 0.0, 0.0, 0.0 ); - m_PointsTwo->InsertNextPoint( 0.0, 0.0, 2.0 ); - m_PointsTwo->InsertNextPoint( 0.0, 1.0, 0.0 ); - m_PointsTwo->InsertNextPoint( 0.0, 1.0, 2.0 ); - - //generate two polygons - vtkSmartPointer polygonOne = vtkSmartPointer::New(); - polygonOne->GetPointIds()->SetNumberOfIds(4); - polygonOne->GetPointIds()->SetId(0,0); - polygonOne->GetPointIds()->SetId(1,1); - polygonOne->GetPointIds()->SetId(2,2); - polygonOne->GetPointIds()->SetId(3,3); - - vtkSmartPointer polygonTwo = vtkSmartPointer::New(); - polygonTwo->GetPointIds()->SetNumberOfIds(4); - polygonTwo->GetPointIds()->SetId(0,3); - polygonTwo->GetPointIds()->SetId(1,2); - polygonTwo->GetPointIds()->SetId(2,0); - polygonTwo->GetPointIds()->SetId(3,1); - - //generate polydatas - vtkSmartPointer polygonArrayOne = vtkSmartPointer::New(); - polygonArrayOne->InsertNextCell(polygonOne); - - m_PolyDataOne = vtkSmartPointer::New(); - m_PolyDataOne->SetPoints(m_PointsOne); - m_PolyDataOne->SetPolys(polygonArrayOne); - - m_PolygonArrayTwo = vtkSmartPointer::New(); - m_PolygonArrayTwo->InsertNextCell(polygonTwo); - - vtkSmartPointer polyDataTwo = vtkSmartPointer::New(); - polyDataTwo->SetPoints(m_PointsOne); - polyDataTwo->SetPolys(m_PolygonArrayTwo); - - //generate surfaces - m_Surface3D = mitk::Surface::New(); - m_Surface3D->SetVtkPolyData( m_PolyDataOne ); - - m_Surface3DTwoTimeSteps = mitk::Surface::New(); - m_Surface3DTwoTimeSteps->SetVtkPolyData( m_PolyDataOne, 0 ); - m_Surface3DTwoTimeSteps->SetVtkPolyData( polyDataTwo, 1 ); -} - -static void Equal_InputIsNull_ReturnsFalse() -{ - mitk::Surface::Pointer surface = NULL; - MITK_TEST_NOT_EQUAL( surface, surface, "Input is NULL. Result should be false."); -} - -static void Equal_CloneAndOriginalOneTimestep_ReturnsTrue() -{ - Setup(); - MITK_TEST_EQUAL( m_Surface3D, m_Surface3D->Clone(), "A one timestep clone should be equal to its original."); -} - -static void Equal_CloneAndOriginalTwoTimesteps_ReturnsTrue() -{ - Setup(); - MITK_TEST_EQUAL( m_Surface3DTwoTimeSteps, m_Surface3DTwoTimeSteps->Clone(), "A two timestep clone should be equal to its original."); -} - -static void Equal_OneTimeStepVSTwoTimeStep_ReturnsFalse() -{ - Setup(); - MITK_TEST_NOT_EQUAL( m_Surface3D, m_Surface3DTwoTimeSteps, "A one timestep and two timestep surface should not be equal."); -} + * @brief mitkPointSetEqualTestSuite A test class for Equal methods in mitk::PointSet. + */ -static void Equal_TwoTimeStepsDifferentPoints_ReturnsFalse() +class mitkSurfaceEqualTestSuite : public CppUnit::TestFixture { - Setup(); - - vtkSmartPointer polyDataDifferentPoints = vtkSmartPointer::New(); - polyDataDifferentPoints->SetPoints(m_PointsTwo); - polyDataDifferentPoints->SetPolys(m_PolygonArrayTwo); - - mitk::Surface::Pointer surface3DTwoTimeStepsDifferentPoints = mitk::Surface::New(); - surface3DTwoTimeStepsDifferentPoints->SetVtkPolyData( m_PolyDataOne, 0 ); - surface3DTwoTimeStepsDifferentPoints->SetVtkPolyData( polyDataDifferentPoints, 1 ); - - //The geometry also changes, because the second pointset has a different geometry/extent. - MITK_TEST_NOT_EQUAL( surface3DTwoTimeStepsDifferentPoints, m_Surface3DTwoTimeSteps, "A surface with the same timesteps and different points should not be equal."); -} - -static void Equal_SurfaceWithPolygonSurfaceWithPolyLine_ReturnsFalse() -{ - Setup(); - - //generate a line - vtkSmartPointer polyLineOne = vtkSmartPointer::New(); - polyLineOne->GetPointIds()->SetNumberOfIds(2); - polyLineOne->GetPointIds()->SetId(0,0); - polyLineOne->GetPointIds()->SetId(1,1); - - vtkSmartPointer polyLineArrayOne = vtkSmartPointer::New(); - polyLineArrayOne->InsertNextCell(polyLineOne); - - vtkSmartPointer polyDataLine = vtkSmartPointer::New(); - polyDataLine->SetPoints(m_PointsOne); - polyDataLine->SetLines(polyLineArrayOne); - - mitk::Surface::Pointer surface3DLine = mitk::Surface::New(); - surface3DLine->SetVtkPolyData( polyDataLine ); - - MITK_TEST_NOT_EQUAL( m_Surface3D, surface3DLine, "A surface with the same timesteps and points and the same number of cells, but different types of cells should not be equal."); -} - -static void Equal_DifferentPoints_ReturnsFalse() -{ - Setup(); - mitk::Surface::Pointer surfaceWithADifferentPoint = m_Surface3D->Clone(); - //modify points. m_Surface3D contains m_PointsOne - surfaceWithADifferentPoint->GetVtkPolyData()->SetPoints( m_PointsTwo ); - - MITK_TEST_NOT_EQUAL( m_Surface3D, surfaceWithADifferentPoint, "A surface with a single timestep and different points should not be equal."); -} - -/** -* @brief mitkSurfaceEqualTest A test class for Equal methods in mitk::Surface. + CPPUNIT_TEST_SUITE(mitkSurfaceEqualTestSuite); + CPPUNIT_TEST(Equal_InputIsNull_ReturnsFalse); + CPPUNIT_TEST(Equal_CloneAndOriginalOneTimestep_ReturnsTrue); + CPPUNIT_TEST(Equal_CloneAndOriginalTwoTimesteps_ReturnsTrue); + CPPUNIT_TEST(Equal_OneTimeStepVSTwoTimeStep_ReturnsFalse); + CPPUNIT_TEST(Equal_TwoTimeStepsDifferentPoints_ReturnsFalse); + CPPUNIT_TEST(Equal_DifferentPoints_ReturnsFalse); + CPPUNIT_TEST(Equal_SurfaceWithPolygonSurfaceWithPolyLine_ReturnsFalse); + CPPUNIT_TEST_SUITE_END(); + +private: + + /** Members used inside the different (sub-)tests. All members are initialized via setUp().*/ + mitk::Surface::Pointer m_Surface3D; + mitk::Surface::Pointer m_Surface3DTwoTimeSteps; + + vtkSmartPointer m_PointsOne; + vtkSmartPointer m_PointsTwo; + vtkSmartPointer m_PolygonArrayTwo; + vtkSmartPointer m_PolyDataOne; + +public: + + /** +* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). */ -int mitkSurfaceEqualTest(int /*argc*/, char* /*argv*/[]) -{ - MITK_TEST_BEGIN(mitkSurfaceEqualTest); - - Equal_InputIsNull_ReturnsFalse(); - Equal_CloneAndOriginalOneTimestep_ReturnsTrue(); - Equal_CloneAndOriginalTwoTimesteps_ReturnsTrue(); - Equal_OneTimeStepVSTwoTimeStep_ReturnsFalse(); - Equal_TwoTimeStepsDifferentPoints_ReturnsFalse(); - Equal_DifferentPoints_ReturnsFalse(); - Equal_SurfaceWithPolygonSurfaceWithPolyLine_ReturnsFalse(); - - MITK_TEST_END(); -} + void setUp() + { + //generate two sets of points + m_PointsOne = vtkSmartPointer::New(); + m_PointsOne->InsertNextPoint( 0.0, 0.0, 0.0 ); + m_PointsOne->InsertNextPoint( 1.0, 0.0, 0.0 ); + m_PointsOne->InsertNextPoint( 0.0, 1.0, 0.0 ); + m_PointsOne->InsertNextPoint( 1.0, 1.0, 0.0 ); + + m_PointsTwo = vtkSmartPointer::New(); + m_PointsTwo->InsertNextPoint( 0.0, 0.0, 0.0 ); + m_PointsTwo->InsertNextPoint( 0.0, 0.0, 2.0 ); + m_PointsTwo->InsertNextPoint( 0.0, 1.0, 0.0 ); + m_PointsTwo->InsertNextPoint( 0.0, 1.0, 2.0 ); + + //generate two polygons + vtkSmartPointer polygonOne = vtkSmartPointer::New(); + polygonOne->GetPointIds()->SetNumberOfIds(4); + polygonOne->GetPointIds()->SetId(0,0); + polygonOne->GetPointIds()->SetId(1,1); + polygonOne->GetPointIds()->SetId(2,2); + polygonOne->GetPointIds()->SetId(3,3); + + vtkSmartPointer polygonTwo = vtkSmartPointer::New(); + polygonTwo->GetPointIds()->SetNumberOfIds(4); + polygonTwo->GetPointIds()->SetId(0,3); + polygonTwo->GetPointIds()->SetId(1,2); + polygonTwo->GetPointIds()->SetId(2,0); + polygonTwo->GetPointIds()->SetId(3,1); + + //generate polydatas + vtkSmartPointer polygonArrayOne = vtkSmartPointer::New(); + polygonArrayOne->InsertNextCell(polygonOne); + + m_PolyDataOne = vtkSmartPointer::New(); + m_PolyDataOne->SetPoints(m_PointsOne); + m_PolyDataOne->SetPolys(polygonArrayOne); + + m_PolygonArrayTwo = vtkSmartPointer::New(); + m_PolygonArrayTwo->InsertNextCell(polygonTwo); + + vtkSmartPointer polyDataTwo = vtkSmartPointer::New(); + polyDataTwo->SetPoints(m_PointsOne); + polyDataTwo->SetPolys(m_PolygonArrayTwo); + + //generate surfaces + m_Surface3D = mitk::Surface::New(); + m_Surface3D->SetVtkPolyData( m_PolyDataOne ); + + m_Surface3DTwoTimeSteps = mitk::Surface::New(); + m_Surface3DTwoTimeSteps->SetVtkPolyData( m_PolyDataOne, 0 ); + m_Surface3DTwoTimeSteps->SetVtkPolyData( polyDataTwo, 1 ); + } + + void tearDown() + { + m_Surface3D = NULL; + m_Surface3DTwoTimeSteps = NULL; + m_PolyDataOne = NULL; + m_PolygonArrayTwo = NULL; + m_PointsOne = NULL; + m_PointsTwo = NULL; + } + + void Equal_InputIsNull_ReturnsFalse() + { + mitk::Surface::Pointer surface = NULL; + MITK_ASSERT_NOT_EQUAL( surface, surface, "Input is NULL. Result should be false."); + } + + void Equal_CloneAndOriginalOneTimestep_ReturnsTrue() + { + MITK_ASSERT_EQUAL( m_Surface3D, m_Surface3D->Clone(), "A one timestep clone should be equal to its original."); + } + + void Equal_CloneAndOriginalTwoTimesteps_ReturnsTrue() + { + MITK_ASSERT_EQUAL( m_Surface3DTwoTimeSteps, m_Surface3DTwoTimeSteps->Clone(), "A two timestep clone should be equal to its original."); + } + + void Equal_OneTimeStepVSTwoTimeStep_ReturnsFalse() + { + MITK_ASSERT_NOT_EQUAL( m_Surface3D, m_Surface3DTwoTimeSteps, "A one timestep and two timestep surface should not be equal."); + } + + void Equal_TwoTimeStepsDifferentPoints_ReturnsFalse() + { + vtkSmartPointer polyDataDifferentPoints = vtkSmartPointer::New(); + polyDataDifferentPoints->SetPoints(m_PointsTwo); + polyDataDifferentPoints->SetPolys(m_PolygonArrayTwo); + + mitk::Surface::Pointer surface3DTwoTimeStepsDifferentPoints = mitk::Surface::New(); + surface3DTwoTimeStepsDifferentPoints->SetVtkPolyData( m_PolyDataOne, 0 ); + surface3DTwoTimeStepsDifferentPoints->SetVtkPolyData( polyDataDifferentPoints, 1 ); + + //The geometry also changes, because the second pointset has a different geometry/extent. + MITK_ASSERT_NOT_EQUAL( surface3DTwoTimeStepsDifferentPoints, m_Surface3DTwoTimeSteps, "A surface with the same timesteps and different points should not be equal."); + } + + void Equal_SurfaceWithPolygonSurfaceWithPolyLine_ReturnsFalse() + { + //generate a line + vtkSmartPointer polyLineOne = vtkSmartPointer::New(); + polyLineOne->GetPointIds()->SetNumberOfIds(2); + polyLineOne->GetPointIds()->SetId(0,0); + polyLineOne->GetPointIds()->SetId(1,1); + + vtkSmartPointer polyLineArrayOne = vtkSmartPointer::New(); + polyLineArrayOne->InsertNextCell(polyLineOne); + + vtkSmartPointer polyDataLine = vtkSmartPointer::New(); + polyDataLine->SetPoints(m_PointsOne); + polyDataLine->SetLines(polyLineArrayOne); + + mitk::Surface::Pointer surface3DLine = mitk::Surface::New(); + surface3DLine->SetVtkPolyData( polyDataLine ); + + MITK_ASSERT_NOT_EQUAL( m_Surface3D, surface3DLine, "A surface with the same timesteps and points and the same number of cells, but different types of cells should not be equal."); + } + + void Equal_DifferentPoints_ReturnsFalse() + { + mitk::Surface::Pointer surfaceWithADifferentPoint = m_Surface3D->Clone(); + //modify points. m_Surface3D contains m_PointsOne + surfaceWithADifferentPoint->GetVtkPolyData()->SetPoints( m_PointsTwo ); + + MITK_ASSERT_NOT_EQUAL( m_Surface3D, surfaceWithADifferentPoint, "A surface with a single timestep and different points should not be equal."); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkSurfaceEqual)