diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index eef2aadd40..f20af9b8d9 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,180 +1,187 @@ # tests with no extra command line parameter set(MODULE_TESTS mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkDispatcherTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry2DTest.cpp mitkGeometry3DTest.cpp mitkGeometry3DEqualTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageEqualTest.cpp mitkImageDataItemTest.cpp #mitkImageMapper2DTest.cpp mitkImageGeneratorTest.cpp mitkBaseDataTest.cpp #mitkImageToItkTest.cpp mitkImportItkImageTest.cpp mitkGrabItkImageMemoryTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkInteractorTest.cpp #mitkITKThreadingTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetEqualTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetWriterTest.cpp mitkPointSetReaderTest.cpp mitkPointSetInteractorTest.cpp mitkPropertyTest.cpp mitkPropertyListTest.cpp #mitkRegistrationBaseTest.cpp #mitkSegmentationInterpolationTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp ##mitkStateMachineContainerTest.cpp ## rewrite test, indirect since no longer exported Bug 14529 mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceEqualTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp #mitkAbstractTransformGeometryTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp mitkExceptionTest.cpp mitkExtractSliceFilterTest.cpp mitkLogTest.cpp mitkImageDimensionConverterTest.cpp mitkLoggingAdapterTest.cpp mitkUIDGeneratorTest.cpp mitkShaderRepositoryTest.cpp mitkPlanePositionManagerTest.cpp mitkAffineTransformBaseTest.cpp mitkPropertyAliasesTest.cpp mitkPropertyDescriptionsTest.cpp mitkPropertyExtensionsTest.cpp mitkPropertyFiltersTest.cpp mitkTinyXMLTest.cpp mitkTypePointConversionTest.cpp mitkTypeVectorConversionTest.cpp mitkTypeMatrixConversionTest.cpp mitkTypeOperationTest.cpp ) +IF(MITK_USE_OpenCV) + set(MODULE_TESTS ${MODULE_TESTS} + mitkTypeConversionOpenCVTest.cpp + ) +endif(MITK_USE_OpenCV) + + # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkImageTimeSelectorTest.cpp #only runs on images mitkImageAccessorTest.cpp #only runs on images mitkDataNodeFactoryTest.cpp #runs on all types of data ) set(MODULE_SURFACE_TESTS mitkSurfaceVtkWriterTest.cpp #only runs on surfaces mitkDataNodeFactoryTest.cpp #runs on all types of data ) # list of images for which the tests are run set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) set(MODULE_TESTSURFACES binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS #mitkLabeledImageToSurfaceFilterTest.cpp #mitkExternalToolsTest.cpp mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkDicomSeriesReaderTest.cpp mitkDICOMLocaleTest.cpp mitkEventMapperTest.cpp mitkEventConfigTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkStateMachineFactoryTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageWriterTest.cpp mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp mitkImageVtkMapper2DTransferFunctionTest.cpp mitkImageVtkMapper2DLookupTableTest.cpp mitkIOUtilTest.cpp mitkSurfaceVtkMapper3DTest mitkSurfaceVtkMapper3DTexturedSphereTest.cpp mitkSurfaceGLMapper2DColorTest.cpp mitkSurfaceGLMapper2DOpacityTest.cpp mitkVolumeCalculatorTest.cpp mitkLevelWindowManagerTest.cpp mitkPointSetVtkMapper2DTest.cpp mitkPointSetVtkMapper2DImageTest.cpp mitkPointSetVtkMapper2DGlyphTypeTest.cpp mitkPointSetVtkMapper2DTransformedPointsTest.cpp mitkLabelOverlay3DRendering2DTest.cpp mitkLabelOverlay3DRendering3DTest.cpp mitkTextOverlay2DRenderingTest.cpp mitkTextOverlay2DLayouterRenderingTest.cpp mitkTextOverlay3DRendering2DTest.cpp mitkTextOverlay3DRendering3DTest.cpp mitkTextOverlay3DColorRenderingTest.cpp mitkVTKRenderWindowSizeTest.cpp ) if (${VTK_MAJOR_VERSION} VERSION_LESS 6) # test can be removed with VTK 6 set(MODULE_TESTS ${MODULE_TESTS} mitkVTKRenderWindowSizeTest.cpp) endif() set(MODULE_RESOURCE_FILES Interactions/AddAndRemovePoints.xml Interactions/globalConfig.xml Interactions/StatemachineTest.xml Interactions/StatemachineConfigTest.xml ) # Create an artificial module initializing class for # the usServiceListenerTest.cpp usFunctionGenerateExecutableInit(testdriver_init_file IDENTIFIER ${MODULE_NAME}TestDriver ) # Embed the resources set(testdriver_resources ) usFunctionEmbedResources(testdriver_resources EXECUTABLE_NAME ${MODULE_NAME}TestDriver ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Resources FILES ${MODULE_RESOURCE_FILES} ) set(TEST_CPP_FILES ${testdriver_init_file} ${testdriver_resources}) diff --git a/Core/Code/Testing/mitkTypeConversionOpenCVTest.cpp b/Core/Code/Testing/mitkTypeConversionOpenCVTest.cpp new file mode 100644 index 0000000000..fe3e30e13c --- /dev/null +++ b/Core/Code/Testing/mitkTypeConversionOpenCVTest.cpp @@ -0,0 +1,104 @@ +/*=================================================================== + +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 + +#include "itkVector.h" + +#include +#include +#include "vnl/vnl_math.h" + +#include "mitkTestingMacros.h" +#include "mitkTypeBasics.h" +#include "mitkVector.h" +#include "mitkTypes.h" // for Equals + +#include + +using namespace mitk; + +/** + * these static variables are used in the test functions + * + * The variable which should be copied into is set to its original value. + * The value which should be copied is set to valuesToCopy. + * + * Then the copying takes place. The test is successful, if the variable which + * should be copied into holds the valuesToCopy afterwards and is equal to the + * vector which should be copied. + */ +static const ScalarType originalValues[] = {1.123456789987, 2.789456321456, 3.123654789987456}; +static const ScalarType valuesToCopy[] = {4.654789123321, 5.987456789321, 6.321654987789546}; + +/** + * @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) +{ + MITK_TEST_CONDITION( EqualArray(v1, v2, 3, eps), "\nAssigning " << v2Name << " to " << v1Name << ":\n both are equal") +} + +const float epsDouble2Float = vnl_math::float_eps * 10.0; + + + + +static void Test_mitk2opencv() +{ + cv::Vec3d opencvVector(originalValues[0], originalValues[1], originalValues[2]); + mitk::Vector3D vector3D = valuesToCopy; + + opencvVector = vector3D.ToArray(); + + TestForEquality(opencvVector, vector3D, "cv::Vec3d", "mitk::Vector3D"); +} + + +static void Test_opencv2mitk() +{ + mitk::Vector3D vector3D = originalValues; + cv::Vec3d opencvVector(valuesToCopy[0], valuesToCopy[1], valuesToCopy[2]); + + vector3D.FromArray(opencvVector); + + TestForEquality(vector3D, opencvVector, "mitk::Vector3D", "cv::Vec3d"); +} + + +/** +* @brief Test the conversions from and to opencv from mitk types. +* +*/ +int mitkTypeConversionOpenCVTest(int /*argc*/ , char* /*argv*/[]) +{ + // always start with this! + MITK_TEST_BEGIN("OpenCVConversionTest") + + Test_mitk2opencv(); + Test_opencv2mitk(); + + MITK_TEST_END() +} diff --git a/Core/Code/Testing/mitkTypeVectorConversionTest.cpp b/Core/Code/Testing/mitkTypeVectorConversionTest.cpp index 0e714f17aa..19767d98dc 100644 --- a/Core/Code/Testing/mitkTypeVectorConversionTest.cpp +++ b/Core/Code/Testing/mitkTypeVectorConversionTest.cpp @@ -1,269 +1,242 @@ /*=================================================================== 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 #include "itkVector.h" #include #include #include "vnl/vnl_math.h" #include "mitkTestingMacros.h" #include "mitkTypeBasics.h" #include "mitkVector.h" #include "mitkTypes.h" // for Equals -// TODO SW: here we will need a guard in case opencv is not activated in a build. -#include - using namespace mitk; /** * these static variables are used in the test functions * * The variable which should be copied into is set to its original value. * The value which should be copied is set to valuesToCopy. * * Then the copying takes place. The test is successful, if the variable which * should be copied into holds the valuesToCopy afterwards and is equal to the * vector which should be copied. */ static const ScalarType originalValues[] = {1.123456789987, 2.789456321456, 3.123654789987456}; static const ScalarType valuesToCopy[] = {4.654789123321, 5.987456789321, 6.321654987789546}; /** * @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) { MITK_TEST_CONDITION( EqualArray(v1, v2, 3, eps), "\nAssigning " << v2Name << " to " << v1Name << ":\n both are equal") } const float epsDouble2Float = vnl_math::float_eps * 10.0; static void Test_pod2mitk(void) { mitk::Vector3D vector3D = valuesToCopy; TestForEquality(vector3D, valuesToCopy, "mitk::Vector3D", "double POD"); } static void Test_mitk2pod(void) { ScalarType podArray[3]; mitk::Vector3D vector3D = valuesToCopy; vector3D.ToArray(podArray); TestForEquality(podArray, vector3D, "double POD", "mitk::Vector3D"); } static void Test_oneElement2mitk(void) { double twos[] = {2.0, 2.0, 2.0}; mitk::Vector vector3D(2.0); MITK_TEST_CONDITION(EqualArray(vector3D, twos, 3), "\none values initializes all elements to this value") } static void Test_itk2mitk(void) { Vector3D vector3D = originalValues; itk::Vector itkVector = valuesToCopy; vector3D = itkVector; TestForEquality(vector3D, itkVector, "mitk::Vector3D", "itk::Vector"); } static void Test_mitk2itk(void) { Vector3D vector3D = valuesToCopy; itk::Vector itkVector = originalValues; itkVector = vector3D; TestForEquality(itkVector, vector3D, "itk::Vector", "mitk::Vector3D"); } static void Test_vnlfixed2mitk(void) { mitk::Vector3D vector3D = originalValues; vnl_vector_fixed vnlVectorFixed(valuesToCopy); vector3D = vnlVectorFixed; TestForEquality(vector3D, vnlVectorFixed, "mitk::Vector3D", "vnl_vector_fixed"); } static void Test_mitk2vnlfixed(void) { vnl_vector_fixed vnlVectorFixed(originalValues); mitk::Vector3D vector3D = valuesToCopy; vnlVectorFixed = vector3D; TestForEquality(vnlVectorFixed, vector3D, "vnl_vector_fixed", "mitk::Vector3D"); } static void Test_vnl2mitk(void) { mitk::Vector3D vector3D = originalValues; vnl_vector vnlVector(3); vnlVector.set(valuesToCopy); vector3D = vnlVector; TestForEquality(vector3D, vnlVector, "mitk::Vector3D", "vnl_vector"); } static void Test_mitk2vnl(void) { vnl_vector vnlVector(3); vnlVector.set(originalValues); mitk::Vector3D vector3D = valuesToCopy; vnlVector = vector3D; TestForEquality(vnlVector, vector3D, "vnl_vector", "mitk::Vector3D"); } /** * @brief Tests if an exception is thrown when constructing an mitk::Vector form a vnl_vector of not suited size. */ static void Test_vnl2mitk_WrongVnlVectorSize() { ScalarType largerValuesToCopy[] = {4.12345678910, 5.10987654321, 6.123456789132456, 7.123456987789456}; mitk::Vector3D vector3D = originalValues; vnl_vector vnlVector(4); vnlVector.set(largerValuesToCopy); MITK_TEST_FOR_EXCEPTION(mitk::Exception&, vector3D = vnlVector;) } -static void Test_mitk2opencv() -{ - cv::Vec3d opencvVector(originalValues[0], originalValues[1], originalValues[2]); - mitk::Vector3D vector3D = valuesToCopy; - - opencvVector = vector3D.ToArray(); - - TestForEquality(opencvVector, vector3D, "cv::Vec3d", "mitk::Vector3D"); -} - - -static void Test_opencv2mitk() -{ - mitk::Vector3D vector3D = originalValues; - cv::Vec3d opencvVector(valuesToCopy[0], valuesToCopy[1], valuesToCopy[2]); - - vector3D.FromArray(opencvVector); - - TestForEquality(vector3D, opencvVector, "mitk::Vector3D", "cv::Vec3d"); -} - static void Test_ToArray_DifferentType(void) { float podArray[3]; for (int var = 0; var < 3; ++var) { podArray[var] = originalValues[var]; } mitk::Vector3D vector3D = valuesToCopy; vector3D.ToArray(podArray); TestForEquality(podArray, vector3D, "float POD", "mitk::Vector3D", epsDouble2Float); } static void Test_FromArray_DifferentType(void) { mitk::Vector3D vector3D = originalValues; float podArray[3]; for (int var = 0; var < 3; ++var) { podArray[var] = valuesToCopy[var]; } vector3D.FromArray(podArray); TestForEquality(vector3D, podArray, "mitk::Vector3D", "float POD", epsDouble2Float); } /** * @brief Test the conversions from and to the mitk::Vector type. * * Tests for every conversion, if it can be done and in a second test, if the assignment of a * different type succeeds. E.g., assign a double vnl_vector to a float mitk::Vector * In cases where the size can not be determined during compile time it is checked if the assignment of * a differently sized vector yields an error. */ int mitkTypeVectorConversionTest(int /*argc*/ , char* /*argv*/[]) { // always start with this! MITK_TEST_BEGIN("VectorConversionTest") Test_pod2mitk(); Test_mitk2pod(); Test_oneElement2mitk(); Test_itk2mitk(); Test_mitk2itk(); Test_vnlfixed2mitk(); Test_mitk2vnlfixed(); Test_vnl2mitk(); Test_mitk2vnl(); Test_vnl2mitk_WrongVnlVectorSize(); - Test_mitk2opencv(); - Test_opencv2mitk(); - /** * The ToArray and FromArray can assign non equal types by implicit primitive type conversion. * The next two tests show this behavior */ Test_ToArray_DifferentType(); Test_FromArray_DifferentType(); MITK_TEST_END() }