diff --git a/CMake/mitkFunctionAddCustomModuleTest.cmake b/CMake/mitkFunctionAddCustomModuleTest.cmake index 1ba2fe9890..67b67fe610 100644 --- a/CMake/mitkFunctionAddCustomModuleTest.cmake +++ b/CMake/mitkFunctionAddCustomModuleTest.cmake @@ -1,21 +1,22 @@ #! #! \brief Add a custom test for MITK module #! #! \param test_name Unique identifier for the test #! \param test_function Name of the test function (the one with the argc,argv signature) #! #! Additional parameters will be passed as command line parameters to the test. #! function(mitkAddCustomModuleTest test_name test_function) if (BUILD_TESTING AND MODULE_IS_ENABLED) add_test(${test_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} ${test_function} ${ARGN}) set_property(TEST ${test_name} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK) mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH_RELEASE release) mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH_DEBUG debug) string (REGEX REPLACE "\;" "\\\;" MITK_RUNTIME_PATH_RELEASE "${MITK_RUNTIME_PATH_RELEASE}") string (REGEX REPLACE "\;" "\\\;" MITK_RUNTIME_PATH_DEBUG "${MITK_RUNTIME_PATH_DEBUG}") set_property(TEST ${test_name} PROPERTY ENVIRONMENT "PATH=${MITK_RUNTIME_PATH_RELEASE}\;${MITK_RUNTIME_PATH_DEBUG}" APPEND) + set_property(TEST ${test_name} PROPERTY SKIP_RETURN_CODE 77) endif() endfunction() diff --git a/CMake/mitkMacroCreateDefaultTests.cmake b/CMake/mitkMacroCreateDefaultTests.cmake index 744635b352..d06beb21bc 100644 --- a/CMake/mitkMacroCreateDefaultTests.cmake +++ b/CMake/mitkMacroCreateDefaultTests.cmake @@ -1,68 +1,70 @@ # Create TestDriver and default tests for MITK # # CMake variables used: # # ${${KITNAME}_GUI_TESTS} : filenames of all tests that run without a parameter # ${${KITNAME}_IMAGE_GUI_TESTS : filenames of all tests that run with an image filename as parameter # ${${KITNAME}_TESTS} : filenames of all tests that run without a parameter # ${${KITNAME}_IMAGE_TESTS : filenames of all tests that run with an image filename as parameter # ${${KITNAME}_TESTIMAGES} : list of images passed as parameter for the IMAGE_TESTS # ${${KITNAME}_CUSTOM_TESTS} : filenames of custom tests which are just added to the TestDriver. Execution # of these has to be specified manually with the ADD_TEST CMake command. # macro(MITK_CREATE_DEFAULT_TESTS) # add tests which need a GUI if it is not disabled if(NOT MITK_GUI_TESTS_DISABLED) set( ${KITNAME}_TESTS ${${KITNAME}_TESTS} ${${KITNAME}_GUI_TESTS} ) set( ${KITNAME}_IMAGE_TESTS ${${KITNAME}_IMAGE_TESTS} ${${KITNAME}_IMAGE_GUI_TESTS} ) endif() # # Create the TestDriver binary which contains all the tests. # create_test_sourcelist(MITKTEST_SOURCE ${KITNAME}TestDriver.cpp ${${KITNAME}_TESTS} ${${KITNAME}_IMAGE_TESTS} ${${KITNAME}_CUSTOM_TESTS} ) add_executable(${KITNAME}TestDriver ${MITKTEST_SOURCE}) set_property(TARGET ${KITNAME}TestDriver PROPERTY LABELS ${PROJECT_NAME}) target_link_libraries(${KITNAME}TestDriver ${${KITNAME}_CORE_LIBRARIES} ${${KITNAME}_LIBRARIES} ${LIBRARIES_FOR_${KITNAME}_CORE}) # # Now tell CMake which tests should be run. This is done automatically # for all tests in ${KITNAME}_TESTS and ${KITNAME}_IMAGE_TESTS. The IMAGE_TESTS # are run for each image in the TESTIMAGES list. # foreach( test ${${KITNAME}_TESTS} ) get_filename_component(TName ${test} NAME_WE) add_test(${TName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KITNAME}TestDriver ${TName}) set_property(TEST ${TName} PROPERTY LABELS ${PROJECT_NAME}) mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH_RELEASE release) mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH_DEBUG debug) string (REGEX REPLACE "\;" "\\\;" MITK_RUNTIME_PATH_RELEASE "${MITK_RUNTIME_PATH_RELEASE}") string (REGEX REPLACE "\;" "\\\;" MITK_RUNTIME_PATH_DEBUG "${MITK_RUNTIME_PATH_DEBUG}") set_property(TEST ${TName} PROPERTY ENVIRONMENT "PATH=${MITK_RUNTIME_PATH_RELEASE}\;${MITK_RUNTIME_PATH_DEBUG}" APPEND) + set_property(TEST ${TName} PROPERTY SKIP_RETURN_CODE 77) endforeach() foreach(image ${${KITNAME}_TESTIMAGES} ${ADDITIONAL_TEST_IMAGES} ) if(EXISTS "${image}") set(IMAGE_FULL_PATH ${image}) else() # todo: maybe search other paths as well # yes, please in mitk/Testing/Data, too set(IMAGE_FULL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Data/${image}) endif() if(EXISTS "${IMAGE_FULL_PATH}") foreach( test ${${KITNAME}_IMAGE_TESTS} ) get_filename_component(TName ${test} NAME_WE) get_filename_component(ImageName ${IMAGE_FULL_PATH} NAME) add_test(${TName}_${ImageName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KITNAME}TestDriver ${TName} ${IMAGE_FULL_PATH}) set_property(TEST ${TName}_${ImageName} PROPERTY LABELS ${PROJECT_NAME}) set_property(TEST ${TName}_${ImageName} PROPERTY ENVIRONMENT "PATH=${MITK_RUNTIME_PATH_RELEASE}\;${MITK_RUNTIME_PATH_DEBUG}" APPEND) + set_property(TEST ${TName}_${ImageName} PROPERTY SKIP_RETURN_CODE 77) endforeach() else() message("!!!!! No such file: ${IMAGE_FULL_PATH} !!!!!") endif() endforeach() endmacro() diff --git a/CMake/mitkMacroCreateModuleTests.cmake b/CMake/mitkMacroCreateModuleTests.cmake index 3e512e7686..11eee7d07c 100644 --- a/CMake/mitkMacroCreateModuleTests.cmake +++ b/CMake/mitkMacroCreateModuleTests.cmake @@ -1,96 +1,98 @@ # # Create tests and testdriver for this module # # Usage: MITK_CREATE_MODULE_TESTS( [EXTRA_DRIVER_INIT init_code] ) # # EXTRA_DRIVER_INIT is inserted as c++ code in the testdriver and will be executed before each test # macro(MITK_CREATE_MODULE_TESTS) cmake_parse_arguments(MODULE_TEST "US_MODULE;NO_INIT" "EXTRA_DRIVER_INIT;EXTRA_DRIVER_INCLUDE" "EXTRA_DEPENDS;DEPENDS;PACKAGE_DEPENDS" ${ARGN}) if(BUILD_TESTING AND MODULE_IS_ENABLED) include(files.cmake) include_directories(.) set(TESTDRIVER ${MODULE_NAME}TestDriver) set(MODULE_TEST_EXTRA_DRIVER_INIT "${MODULE_TEST_EXTRA_DRIVER_INIT}") if(MODULE_TEST_US_MODULE) message(WARNING "The US_MODULE argument is deprecated and should be removed") endif() if(MODULE_TEST_US_MODULE AND MODULE_TEST_NO_INIT) message(WARNING "Conflicting arguments US_MODULE and NO_INIT: NO_INIT wins.") endif() set(_no_init) if(MODULE_TEST_NO_INIT) set(_no_init NO_INIT) endif() set(MITK_MODULE_NAME_REGEX_MATCH ) set(MITK_MODULE_NAME_REGEX_NOT_MATCH ) set(_testdriver_file_list ${CMAKE_CURRENT_BINARY_DIR}/testdriver_files.cmake) configure_file(${MITK_CMAKE_DIR}/mitkTestDriverFiles.cmake.in ${_testdriver_file_list} @ONLY) mitk_create_executable(${TESTDRIVER} DEPENDS ${MODULE_NAME} ${MODULE_TEST_DEPENDS} ${MODULE_TEST_EXTRA_DEPENDS} MitkTestingHelper PACKAGE_DEPENDS ${MODULE_TEST_PACKAGE_DEPENDS} SUBPROJECTS ${MODULE_SUBPROJECTS} FILES_CMAKE ${_testdriver_file_list} NO_FEATURE_INFO NO_BATCH_FILE ${_no_init}) # # Now tell CMake which tests should be run. This is done automatically # for all tests in ${KITNAME}_TESTS and ${KITNAME}_IMAGE_TESTS. The IMAGE_TESTS # are run for each image in the TESTIMAGES list. # include(files.cmake) foreach( test ${MODULE_TESTS} ) get_filename_component(TName ${test} NAME_WE) add_test(${TName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} ${TName}) # Add labels for CDash subproject support if(MODULE_SUBPROJECTS) set_property(TEST ${TName} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK) endif() mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH_RELEASE release) mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH_DEBUG debug) string (REGEX REPLACE "\;" "\\\;" MITK_RUNTIME_PATH_RELEASE "${MITK_RUNTIME_PATH_RELEASE}") string (REGEX REPLACE "\;" "\\\;" MITK_RUNTIME_PATH_DEBUG "${MITK_RUNTIME_PATH_DEBUG}") set_property(TEST ${TName} PROPERTY ENVIRONMENT "PATH=${MITK_RUNTIME_PATH_RELEASE}\;${MITK_RUNTIME_PATH_DEBUG}" APPEND) + set_property(TEST ${TName} PROPERTY SKIP_RETURN_CODE 77) endforeach() set(TEST_TYPES IMAGE SURFACE POINTSET) # add other file types here foreach(test_type ${TEST_TYPES}) foreach(test_data ${MODULE_TEST${test_type}} ${ADDITIONAL_TEST_${test_type}}) if(EXISTS ${test_data}) set(TEST_DATA_FULL_PATH ${test_data}) else() # todo: maybe search other paths as well # yes, please in mitk/Testing/Data, too set(TEST_DATA_FULL_PATH ${MITK_DATA_DIR}/${test_data}) endif() if(EXISTS ${TEST_DATA_FULL_PATH}) foreach( test ${MODULE_${test_type}_TESTS}) get_filename_component(TName ${test} NAME_WE) get_filename_component(DName ${TEST_DATA_FULL_PATH} NAME) add_test(${TName}_${DName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} ${TName} ${TEST_DATA_FULL_PATH}) # Add labels for CDash subproject support if(MODULE_SUBPROJECTS) set_property(TEST ${TName}_${DName} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK) endif() set_property(TEST ${TName}_${DName} PROPERTY ENVIRONMENT "PATH=${MITK_RUNTIME_PATH_RELEASE}\;${MITK_RUNTIME_PATH_DEBUG}" APPEND) + set_property(TEST ${TName}_${DName} PROPERTY SKIP_RETURN_CODE 77) endforeach() else() message("!!!!! No such file: ${TEST_DATA_FULL_PATH} !!!!!") endif() endforeach() endforeach() endif() endmacro() diff --git a/Modules/Core/TestingHelper/include/mitkTestNotRunException.h b/Modules/Core/TestingHelper/include/mitkTestNotRunException.h new file mode 100644 index 0000000000..96d63d4590 --- /dev/null +++ b/Modules/Core/TestingHelper/include/mitkTestNotRunException.h @@ -0,0 +1,44 @@ +/*=================================================================== + +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. + +===================================================================*/ + +#ifndef MITKTESTNOTRUNEXCEPTION_H +#define MITKTESTNOTRUNEXCEPTION_H + +#include +#include +#include + + +namespace mitk +{ + /**Documentation + * \brief Specialized mitk::Exception for skipped tests + * + * If a test is unable to run due to circumstances that do not indicate + * a failure (such as a missing openGl for a rendering test) it should throw + * this exception. + * + * Usage: + * mitkThrowException(mitk::TestNotRunException) << "optional reason for skip"; + */ + class MITKTESTINGHELPER_EXPORT TestNotRunException : public mitk::Exception + { + public: + mitkExceptionClassMacro(mitk::TestNotRunException, mitk::Exception); + }; +} + +#endif // MITKTESTNOTRUNEXCEPTION_H diff --git a/Modules/Core/TestingHelper/include/mitkTestingMacros.h b/Modules/Core/TestingHelper/include/mitkTestingMacros.h index 201158df8f..5427a407ad 100644 --- a/Modules/Core/TestingHelper/include/mitkTestingMacros.h +++ b/Modules/Core/TestingHelper/include/mitkTestingMacros.h @@ -1,384 +1,395 @@ /*=================================================================== 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. ===================================================================*/ #ifndef mitkTestingMacros_h #define mitkTestingMacros_h #include #include #include #include #include +#include #include #include #include #include namespace mitk { /** @brief Indicate a failed test. */ class TestFailedException : public std::exception { public: TestFailedException() {} }; } /** * @brief Output some text without generating a terminating newline. Include * * @ingroup MITKTestingAPI */ #define MITK_TEST_OUTPUT_NO_ENDL(x) std::cout x; /** * @brief Output some text. * * @ingroup MITKTestingAPI */ #define MITK_TEST_OUTPUT(x) MITK_TEST_OUTPUT_NO_ENDL(x << "\n") /** * @brief Do some general test preparations. Must be called first in the * main test function. * * @deprecatedSince{2013_09} Use MITK_TEST_SUITE_REGISTRATION instead. * @ingroup MITKTestingAPI */ #define MITK_TEST_BEGIN(testName) \ std::string mitkTestName(#testName); \ mitk::TestManager::GetInstance()->Initialize(); \ try \ { /** * @brief Fail and finish test with message MSG * * @deprecatedSince{2013_09} Use CPPUNIT_FAIL instead * @ingroup MITKTestingAPI */ #define MITK_TEST_FAILED_MSG(MSG) \ MITK_TEST_OUTPUT(MSG) \ throw mitk::TestFailedException(); /** * @brief Must be called last in the main test function. * * @deprecatedSince{2013_09} Use MITK_TEST_SUITE_REGISTRATION instead. * @ingroup MITKTestingAPI */ #define MITK_TEST_END() \ } \ catch (const mitk::TestFailedException &) \ { \ MITK_TEST_OUTPUT(<< "Further test execution skipped.") \ mitk::TestManager::GetInstance()->TestFailed(); \ } \ catch (const std::exception &ex) \ { \ MITK_TEST_OUTPUT(<< "std::exception occured " << ex.what()) \ mitk::TestManager::GetInstance()->TestFailed(); \ } \ if (mitk::TestManager::GetInstance()->NumberOfFailedTests() > 0) \ { \ MITK_TEST_OUTPUT(<< mitkTestName << ": [DONE FAILED] , subtests passed: " \ << mitk::TestManager::GetInstance()->NumberOfPassedTests() \ << " failed: " \ << mitk::TestManager::GetInstance()->NumberOfFailedTests()) \ return EXIT_FAILURE; \ } \ else \ { \ MITK_TEST_OUTPUT(<< mitkTestName << ": " << mitk::TestManager::GetInstance()->NumberOfPassedTests() \ << " tests [DONE PASSED]") \ return EXIT_SUCCESS; \ } /** * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT or CPPUNIT_ASSERT_MESSAGE instead. */ #define MITK_TEST_CONDITION(COND, MSG) \ MITK_TEST_OUTPUT_NO_ENDL(<< MSG) \ if (!(COND)) \ { \ mitk::TestManager::GetInstance()->TestFailed(); \ MITK_TEST_OUTPUT(<< " [FAILED]\n" \ << "In " \ << __FILE__ \ << ", line " \ << __LINE__ \ << ": " #COND " : [FAILED]") \ } \ else \ { \ MITK_TEST_OUTPUT(<< " [PASSED]") \ mitk::TestManager::GetInstance()->TestPassed(); \ } /** * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT or CPPUNIT_ASSERT_MESSAGE instead. */ #define MITK_TEST_CONDITION_REQUIRED(COND, MSG) \ MITK_TEST_OUTPUT_NO_ENDL(<< MSG) \ if (!(COND)) \ { \ MITK_TEST_FAILED_MSG(<< " [FAILED]\n" \ << " +--> in " \ << __FILE__ \ << ", line " \ << __LINE__ \ << ", expression is false: \"" #COND "\"") \ } \ else \ { \ MITK_TEST_OUTPUT(<< " [PASSED]") \ mitk::TestManager::GetInstance()->TestPassed(); \ } /** * \brief Begin block which should be checked for exceptions * * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT_THROW instead. * @ingroup MITKTestingAPI * * This macro, together with MITK_TEST_FOR_EXCEPTION_END, can be used * to test whether a code block throws an expected exception. The test FAILS if the * exception is NOT thrown. A simple example: * MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ImageFileReaderException) typedef itk::ImageFileReader< itk::Image > ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName("/tmp/not-existing"); reader->Update(); MITK_TEST_FOR_EXCEPTION_END(itk::ImageFileReaderException) * */ #define MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS) \ try \ { /** * @deprecatedSince{2013_09} */ #define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS) \ mitk::TestManager::GetInstance()->TestFailed(); \ MITK_TEST_OUTPUT(<< "Expected an '" << #EXCEPTIONCLASS << "' exception. [FAILED]") \ } \ catch (EXCEPTIONCLASS) \ { \ MITK_TEST_OUTPUT(<< "Caught an expected '" << #EXCEPTIONCLASS << "' exception. [PASSED]") \ mitk::TestManager::GetInstance()->TestPassed(); \ } /** * @brief Simplified version of MITK_TEST_FOR_EXCEPTION_BEGIN / END for * a single statement * * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT_THROW instead. * @ingroup MITKTestingAPI */ #define MITK_TEST_FOR_EXCEPTION(EXCEPTIONCLASS, STATEMENT) \ MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS) \ STATEMENT; \ MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS) /** * @brief Testing macro to test if two objects are equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * Feel free to implement mitk::Equal for your own datatype or purpose. * * @param EXPECTED First object. * @param ACTUAL Second object. * @param MSG Message to appear with the test. * @throw Throws mitkException if a nullptr pointer is given as input. */ #define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG) \ if (((EXPECTED).IsNull()) || ((ACTUAL).IsNull())) \ { \ mitkThrow() << "mitk::Equal does not work with nullptr pointer input."; \ } \ CPPUNIT_ASSERT_MESSAGE(MSG, mitk::Equal(*(EXPECTED), *(ACTUAL), mitk::eps, true)) /** * @brief Testing macro to test if two objects are not equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * * @deprecatedSince{2013_09} Use MITK_ASSERT_NOT_EQUAL instead. * * @param OBJ1 First object. * @param OBJ2 Second object. * @param MSG Message to appear with the test. * * \sa MITK_TEST_EQUAL */ #define MITK_TEST_NOT_EQUAL(OBJ1, OBJ2, MSG) \ CPPUNIT_ASSERT_MESSAGE(MSG, !mitk::Equal(*(OBJ1), *(OBJ2), mitk::eps, true)) /** * @brief Testing macro to test if two objects are not equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * * @param OBJ1 First object. * @param OBJ2 Second object. * @param MSG Message to appear with the test. * @throw Throws mitkException if a nullptr pointer is given as input. * * \sa MITK_ASSERT_EQUAL */ #define MITK_ASSERT_NOT_EQUAL(OBJ1, OBJ2, MSG) \ if (((OBJ1).IsNull()) || ((OBJ2).IsNull())) \ { \ mitkThrow() << "mitk::Equal does not work with nullptr pointer input."; \ } \ CPPUNIT_ASSERT_MESSAGE(MSG, !mitk::Equal(*(OBJ1), *(OBJ2), mitk::eps, true)) /** * @brief Registers the given test suite. * * @ingroup MITKTestingAPI * * @param TESTSUITE_NAME The name of the test suite class, without "TestSuite" * at the end. */ #define MITK_TEST_SUITE_REGISTRATION(TESTSUITE_NAME) \ int TESTSUITE_NAME##Test(int /*argc*/, char * /*argv*/ []) \ { \ - CppUnit::TextUi::TestRunner runner; \ - runner.addTest(TESTSUITE_NAME##TestSuite::suite()); \ - return runner.run() ? 0 : 1; \ + int result = 0; \ + try \ + { \ + CppUnit::TextUi::TestRunner runner; \ + runner.addTest(TESTSUITE_NAME##TestSuite::suite()); \ + result = runner.run() ? 0 : 1; \ + } \ + catch (const mitk::TestNotRunException& e) \ + { \ + MITK_WARN << "Test not run: " << e.GetDescription(); \ + result = 77; \ + } \ + return result; \ } /** * @brief Adds a test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases. * The macro internally just calls the CPPUNIT_TEST macro. * * @param TESTMETHOD The name of the member funtion test. */ #define MITK_TEST(TESTMETHOD) CPPUNIT_TEST(TESTMETHOD) /** * @brief Adds a parameterized test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases * which need custom parameters. * * @param TESTMETHOD The name of the member function test. * @param ARGS A std::vector object containing test parameter. * * @note Use the macro MITK_PARAMETERIZED_TEST only if you know what * you are doing. If you are not sure, use MITK_TEST instead. */ #define MITK_PARAMETERIZED_TEST(TESTMETHOD, ARGS) \ \ { \ std::string testName = #TESTMETHOD; \ for (std::size_t i = 0; i < ARGS.size(); ++i) \ { \ testName += "_" + ARGS[i]; \ } \ CPPUNIT_TEST_SUITE_ADD_TEST((new mitk::TestCaller( \ context.getTestNameFor(testName), &TestFixtureType::TESTMETHOD, context.makeFixture(), args))); \ } /** * @brief Adds a parameterized test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases * which need parameters from the command line. * * @warning Use the macro MITK_PARAMETERIZED_CMD_LINE_TEST only * if you know what you are doing. If you are not sure, use * MITK_TEST instead. MITK_PARAMETERIZED_CMD_LINE_TEST is meant * for migrating from ctest to CppUnit. If you implement new * tests, the MITK_TEST macro will be sufficient. * * @param TESTMETHOD The name of the member function test. */ #define MITK_PARAMETERIZED_CMD_LINE_TEST(TESTMETHOD) \ CPPUNIT_TEST_SUITE_ADD_TEST((new mitk::TestCaller( \ context.getTestNameFor(#TESTMETHOD), &TestFixtureType::TESTMETHOD, context.makeFixture()))); /** * @brief Adds a parameterized test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases * which need one custom parameter. * * @param TESTMETHOD The name of the member function test. * @param arg1 A custom string parameter being passed to the fixture. * * @note Use the macro MITK_PARAMETERIZED_TEST_1 only if you know what * you are doing. If you are not sure, use MITK_TEST instead. * * @see MITK_PARAMETERIZED_TEST */ #define MITK_PARAMETERIZED_TEST_1(TESTMETHOD, arg1) \ \ { \ std::vector args; \ args.push_back(arg1); \ MITK_PARAMETERIZED_TEST(TESTMETHOD, args) \ } /** * @brief Adds a parameterized test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases * which need two custom parameter. * * @param TESTMETHOD The name of the member function test. * @param arg1 A custom string parameter being passed to the fixture. * * @note Use the macro MITK_PARAMETERIZED_TEST_2 only if you know what * you are doing. If you are not sure, use MITK_TEST instead. * * @see MITK_PARAMETERIZED_TEST */ #define MITK_PARAMETERIZED_TEST_2(TESTMETHOD, arg1, arg2) \ \ { \ std::vector args; \ args.push_back(arg1); \ args.push_back(arg2); \ MITK_PARAMETERIZED_TEST(TESTMETHOD, args) \ } #endif diff --git a/Modules/Core/TestingHelper/src/mitkRenderingTestHelper.cpp b/Modules/Core/TestingHelper/src/mitkRenderingTestHelper.cpp index 7aa8f971a1..ee741976fb 100644 --- a/Modules/Core/TestingHelper/src/mitkRenderingTestHelper.cpp +++ b/Modules/Core/TestingHelper/src/mitkRenderingTestHelper.cpp @@ -1,307 +1,315 @@ /*=================================================================== 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. ===================================================================*/ // VTK #include #include #include #include #include // MITK #include #include #include #include #include +#include +#include +#include // include gl to read out properties #include #include #if defined _MSC_VER #if _MSC_VER >= 1700 #define RESIZE_WORKAROUND #endif #endif #ifdef RESIZE_WORKAROUND #include "vtkWin32OpenGLRenderWindow.h" #endif // VTK Testing to compare the rendered image pixel-wise against a reference screen shot #include "vtkTesting.h" mitk::RenderingTestHelper::RenderingTestHelper(int width, int height, mitk::BaseRenderer::RenderingMode::Type renderingMode) : m_AutomaticallyCloseRenderWindow(true) { this->Initialize(width, height, renderingMode); } mitk::RenderingTestHelper::RenderingTestHelper( int width, int height, int argc, char *argv[], mitk::BaseRenderer::RenderingMode::Type renderingMode) : m_AutomaticallyCloseRenderWindow(true) { this->Initialize(width, height, renderingMode); this->SetInputFileNames(argc, argv); } void mitk::RenderingTestHelper::Initialize(int width, int height, mitk::BaseRenderer::RenderingMode::Type renderingMode) { mitk::UIDGenerator uidGen = mitk::UIDGenerator("UnnamedRenderer_", 8); m_RenderWindow = mitk::RenderWindow::New(nullptr, uidGen.GetUID().c_str(), nullptr, renderingMode); m_DataStorage = mitk::StandaloneDataStorage::New(); m_RenderWindow->GetRenderer()->SetDataStorage(m_DataStorage); this->SetMapperIDToRender2D(); this->GetVtkRenderWindow()->SetSize(width, height); + if (!IsAdvancedOpenGL()) + { + mitkThrowException(mitk::TestNotRunException) << "Insufficient OpenGL version"; + } + #ifdef RESIZE_WORKAROUND HWND hWnd = static_cast(this->GetVtkRenderWindow())->GetWindowId(); RECT r; r.left = 10; r.top = 10; r.right = r.left + width; r.bottom = r.top + height; LONG style = GetWindowLong(hWnd, GWL_STYLE); AdjustWindowRect(&r, style, FALSE); MITK_INFO << "WANTED:"; MITK_INFO << r.right - r.left; MITK_INFO << r.bottom - r.top; RECT rect; if (GetWindowRect(hWnd, &rect)) { int width = rect.right - rect.left; int height = rect.bottom - rect.top; MITK_INFO << "ACTUAL:"; MITK_INFO << width; MITK_INFO << height; } SetWindowPos(hWnd, HWND_TOP, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOZORDER); GetWindowRect(hWnd, &rect); int width2 = rect.right - rect.left; int height2 = rect.bottom - rect.top; MITK_INFO << "ACTUAL2:"; MITK_INFO << width2; MITK_INFO << height2; SetWindowPos(hWnd, HWND_TOP, 0, 0, 2 * (r.right - r.left) - width2, 2 * (r.bottom - r.top) - height2, SWP_NOZORDER); #endif m_RenderWindow->GetRenderer()->Resize(width, height); // Prints the glinfo after creation of the vtkrenderwindow, we always want to do this for debugging. this->PrintGLInfo(); } mitk::RenderingTestHelper::~RenderingTestHelper() { } bool mitk::RenderingTestHelper::IsAdvancedOpenGL() { const GLubyte *version = glGetString(GL_VERSION); if (!version) return false; return *version >= '2'; } void mitk::RenderingTestHelper::PrintGLInfo() { GLint maxTextureSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); ; //MITK_INFO << "OpenGL Render Context Information: \n" // << "- GL_VENDOR: " << glGetString(GL_VENDOR) << "\n" // << "- GL_RENDERER: " << glGetString(GL_RENDERER) << "\n" // << "- GL_VERSION: " << glGetString(GL_VERSION) << "\n" // << "- GL_MAX_TEXTURE_SIZE: " << maxTextureSize << "\n" // << "- GL_EXTENSIONS: " << glGetString(GL_EXTENSIONS); } void mitk::RenderingTestHelper::SetMapperID(mitk::BaseRenderer::StandardMapperSlot id) { m_RenderWindow->GetRenderer()->SetMapperID(id); } void mitk::RenderingTestHelper::SetMapperIDToRender3D() { this->SetMapperID(mitk::BaseRenderer::Standard3D); mitk::RenderingManager::GetInstance()->InitializeViews( this->GetDataStorage()->ComputeBoundingGeometry3D(this->GetDataStorage()->GetAll())); } void mitk::RenderingTestHelper::SetMapperIDToRender2D() { this->SetMapperID(mitk::BaseRenderer::Standard2D); } void mitk::RenderingTestHelper::Render() { // if the datastorage is initialized and at least 1 image is loaded render it if (m_DataStorage.IsNotNull() || m_DataStorage->GetAll()->Size() >= 1) { // Prepare the VTK camera before rendering. m_RenderWindow->GetRenderer()->PrepareRender(); this->GetVtkRenderWindow()->Render(); this->GetVtkRenderWindow()->WaitForCompletion(); if (m_AutomaticallyCloseRenderWindow == false) { // Use interaction to stop the test this->GetVtkRenderWindow()->GetInteractor()->Start(); } } else { MITK_ERROR << "No images loaded in data storage!"; } } mitk::DataStorage::Pointer mitk::RenderingTestHelper::GetDataStorage() { return m_DataStorage; } void mitk::RenderingTestHelper::SetInputFileNames(int argc, char *argv[]) { // i is set 1, because 0 is the testname as string // parse parameters for (int i = 1; i < argc; ++i) { // add everything to a list but -T and -V std::string tmp = argv[i]; if ((tmp.compare("-T")) && (tmp.compare("-V"))) { this->AddToStorage(tmp); } else { break; } } } void mitk::RenderingTestHelper::SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection) { mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow()) ->GetSliceNavigationController() ->SetDefaultViewDirection(viewDirection); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll())); } void mitk::RenderingTestHelper::ReorientSlices(mitk::Point3D origin, mitk::Vector3D rotation) { mitk::SliceNavigationController::Pointer sliceNavigationController = mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow())->GetSliceNavigationController(); sliceNavigationController->ReorientSlices(origin, rotation); } vtkRenderer *mitk::RenderingTestHelper::GetVtkRenderer() { return m_RenderWindow->GetRenderer()->GetVtkRenderer(); } void mitk::RenderingTestHelper::SetImageProperty(const char *propertyKey, mitk::BaseProperty *property) { this->m_DataStorage->GetNode(mitk::NodePredicateDataType::New("Image"))->SetProperty(propertyKey, property); } vtkRenderWindow *mitk::RenderingTestHelper::GetVtkRenderWindow() { return m_RenderWindow->GetVtkRenderWindow(); } bool mitk::RenderingTestHelper::CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold) { this->Render(); // retVal meanings: (see VTK/Rendering/vtkTesting.h) // 0 = test failed // 1 = test passed // 2 = test not run // 3 = something with vtkInteraction if (vtkTesting::Test(argc, argv, this->GetVtkRenderWindow(), threshold) == 1) return true; else return false; } // method to save a screenshot of the renderwindow (e.g. create a reference screenshot) void mitk::RenderingTestHelper::SaveAsPNG(std::string fileName) { vtkSmartPointer renderer = this->GetVtkRenderer(); bool doubleBuffering(renderer->GetRenderWindow()->GetDoubleBuffer()); renderer->GetRenderWindow()->DoubleBufferOff(); vtkSmartPointer magnifier = vtkSmartPointer::New(); magnifier->SetInput(renderer); magnifier->SetMagnification(1); vtkSmartPointer fileWriter = vtkSmartPointer::New(); fileWriter->SetInputConnection(magnifier->GetOutputPort()); fileWriter->SetFileName(fileName.c_str()); fileWriter->Write(); renderer->GetRenderWindow()->SetDoubleBuffer(doubleBuffering); } void mitk::RenderingTestHelper::SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow) { m_AutomaticallyCloseRenderWindow = automaticallyCloseRenderWindow; } void mitk::RenderingTestHelper::SaveReferenceScreenShot(std::string fileName) { this->SaveAsPNG(fileName); } void mitk::RenderingTestHelper::AddToStorage(const std::string &filename) { try { mitk::IOUtil::Load(filename, *m_DataStorage.GetPointer()); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll())); } catch (itk::ExceptionObject &e) { MITK_ERROR << "Failed loading test data '" << filename << "': " << e.what(); } } void mitk::RenderingTestHelper::AddNodeToStorage(mitk::DataNode::Pointer node) { this->m_DataStorage->Add(node); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll())); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DColorTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DColorTest.cpp index 726c999d34..376cbc6082 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DColorTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DColorTest.cpp @@ -1,52 +1,61 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include int mitkImageVtkMapper2DColorTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // Set the opacity for all images renderingHelper.SetImageProperty("color", mitk::ColorProperty::New(0.0f, 0.0f, 255.0f)); // for now this test renders in sagittal view direction renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); //#################### // Use this to generate a reference screenshot or save the file. //(Only in your local version of the test!) if (false) { renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); } //#################### MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DLevelWindowTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DLevelWindowTest.cpp index 7901c2c379..a264f9afba 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DLevelWindowTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DLevelWindowTest.cpp @@ -1,58 +1,67 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include // VTK #include int mitkImageVtkMapper2DLevelWindowTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // chose a level window: here we randomly chosen the blood preset. mitk::LevelWindowPreset *levelWindowPreset = mitk::LevelWindowPreset::New(); bool loadedPreset = levelWindowPreset->LoadPreset(); MITK_TEST_CONDITION_REQUIRED(loadedPreset == true, "Testing if level window preset could be loaded"); double level = levelWindowPreset->getLevel("Blood"); double window = levelWindowPreset->getWindow("Blood"); levelWindowPreset->Delete(); // apply level window to all images renderingHelper.SetImageProperty("levelwindow", mitk::LevelWindowProperty::New(mitk::LevelWindow(level, window))); // for now this test renders Sagittal renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/tmp/output1.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DLookupTableTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DLookupTableTest.cpp index 04c5f04595..3492ae5299 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DLookupTableTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DLookupTableTest.cpp @@ -1,71 +1,80 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include #include #include // VTK #include int mitkImageVtkMapper2DLookupTableTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DLookupTableTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // define an arbitrary lookupTable vtkSmartPointer lookupTable = vtkSmartPointer::New(); // use linear interpolation lookupTable->SetRampToLinear(); // use the scalar range of the image to have a nice lookuptable lookupTable->SetTableRange(0, 255); lookupTable->Build(); // Fill in a few known colors, the rest will be generated lookupTable->SetTableValue(0, 1.0, 0.0, 0.0, 1.0); // map from red lookupTable->SetTableValue(255, 0.0, 0.0, 1.0, 1.0); // to blue mitk::LookupTable::Pointer myLookupTable = mitk::LookupTable::New(); myLookupTable->SetVtkLookupTable(lookupTable); // set the rendering mode to use the transfer function renderingHelper.SetImageProperty("Image Rendering.Mode", mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::LOOKUPTABLE_COLOR)); // set the property for the image renderingHelper.SetImageProperty("LookupTable", mitk::LookupTableProperty::New(myLookupTable)); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/tmp/output.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DOpacityTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DOpacityTest.cpp index 4509405627..3495b87bbb 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DOpacityTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DOpacityTest.cpp @@ -1,49 +1,58 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include int mitkImageVtkMapper2DOpacityTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // Set the opacity for all images renderingHelper.SetImageProperty("opacity", mitk::FloatProperty::New(0.5f)); // for now this test renders in coronal view direction renderingHelper.SetViewDirection(mitk::SliceNavigationController::Frontal); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("d:/tmp/renderingtest.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DOpacityTransferFunctionTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DOpacityTransferFunctionTest.cpp index 1f52d0ccef..c523c0f1ff 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DOpacityTransferFunctionTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DOpacityTransferFunctionTest.cpp @@ -1,74 +1,83 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include #include #include #include int mitkImageVtkMapper2DOpacityTransferFunctionTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DopacityTransferFunctionTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // define some controlpoints for a scalaropacity mitk::TransferFunction::ControlPoints scalarOpacityPoints; scalarOpacityPoints.push_back(std::make_pair(255, 0)); scalarOpacityPoints.push_back(std::make_pair(0, 0.1)); scalarOpacityPoints.push_back(std::make_pair(127, 0.3)); // define an arbitrary colortransferfunction vtkSmartPointer colorTransferFunction = vtkSmartPointer::New(); colorTransferFunction->SetColorSpaceToRGB(); colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); // black = red colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); // grey = green colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); // white = blue mitk::TransferFunction::Pointer transferFunction = mitk::TransferFunction::New(); transferFunction->SetColorTransferFunction(colorTransferFunction); transferFunction->SetScalarOpacityPoints(scalarOpacityPoints); // set the rendering mode to use the transfer function renderingHelper.SetImageProperty( "Image Rendering.Mode", mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR)); // set the property for the image renderingHelper.SetImageProperty("Image Rendering.Transfer Function", mitk::TransferFunctionProperty::New(transferFunction)); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true, "CompareRenderWindowAgainstReference test result positive?"); // renderingHelper.SetAutomaticallyCloseRenderWindow(false); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("/tmp/output3.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp index 0a2d2e7b6f..feb3847748 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp @@ -1,82 +1,91 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkDataNode.h" #include "mitkIOUtil.h" #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include // VTK #include #include int mitkImageVtkMapper2DResliceInterpolationPropertyTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image // note: this test is supposed to test the reslice interpolation modes not the swiveling itself MITK_TEST_BEGIN("mitkImageVtkMapper2DResliceInterpolationPropertyTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // get resliceInterpolation from comandline arg int resliceInterpolation = atoi(argv[argc - 4]); // Set interpolation mode for rendering renderingHelper.SetImageProperty("reslice interpolation", mitk::VtkResliceInterpolationProperty::New(resliceInterpolation)); /*+++rotate plane+++*/ // center point for rotation mitk::Point3D centerPoint; centerPoint.Fill(0.0f); // vector for rotating the slice mitk::Vector3D rotationVector; rotationVector.SetElement(0, 0.2); rotationVector.SetElement(1, 0.3); rotationVector.SetElement(2, 0.5); // sets a swivel direction for the image // new version of setting the center point: mitk::Image::Pointer image = static_cast( renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData()); // get the center point of the image centerPoint = image->GetGeometry()->GetCenter(); // rotate the image arround its own center renderingHelper.ReorientSlices(centerPoint, rotationVector); // threshold for CompareRenderWindowAgainstReference double threshold = 0.35; // difference between interpolation modes is very small //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, threshold) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.Render(); renderingHelper.SaveReferenceScreenShot("C:\\Users\\schroedt\\Pictures\\RenderingTestData\\Pic3dRefLinear.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DSwivelTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DSwivelTest.cpp index 1dd42be462..8df34b3e24 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DSwivelTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DSwivelTest.cpp @@ -1,67 +1,76 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkImage.h" #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include // VTK #include int mitkImageVtkMapper2DSwivelTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DSwivelTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // center point for rotation mitk::Point3D centerPoint; centerPoint.Fill(0.0f); // vector for rotating the slice mitk::Vector3D rotationVector; rotationVector.SetElement(0, 0.2); rotationVector.SetElement(1, 0.3); rotationVector.SetElement(2, 0.5); // sets a swivel direction for the image // new version of setting the center point: mitk::Image::Pointer image = static_cast( renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData()); // get the center point of the image centerPoint = image->GetGeometry()->GetCenter(); // rotate the image arround its own center renderingHelper.ReorientSlices(centerPoint, rotationVector); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot( "/media/hdd/thomasHdd/Pictures/RenderingTestData/pic3dSwivel640x480REF.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DTest.cpp index 44a6e9b888..cb331dc30e 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DTest.cpp @@ -1,45 +1,54 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include int mitkImageVtkMapper2DTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkImageVtkMapper2DTransferFunctionTest.cpp b/Modules/Core/test/mitkImageVtkMapper2DTransferFunctionTest.cpp index ed8b609937..e4a32f5991 100644 --- a/Modules/Core/test/mitkImageVtkMapper2DTransferFunctionTest.cpp +++ b/Modules/Core/test/mitkImageVtkMapper2DTransferFunctionTest.cpp @@ -1,64 +1,73 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include #include #include #include int mitkImageVtkMapper2DTransferFunctionTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkImageVtkMapper2DTransferFunctionTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // define an arbitrary colortransferfunction vtkSmartPointer colorTransferFunction = vtkSmartPointer::New(); colorTransferFunction->SetColorSpaceToRGB(); colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); // black = red colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); // grey = green colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); // white = blue mitk::TransferFunction::Pointer transferFucntion = mitk::TransferFunction::New(); transferFucntion->SetColorTransferFunction(colorTransferFunction); // set the rendering mode to use the transfer function renderingHelper.SetImageProperty( "Image Rendering.Mode", mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR)); // set the property for the image renderingHelper.SetImageProperty("Image Rendering.Transfer Function", mitk::TransferFunctionProperty::New(transferFucntion)); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/tmp/output2.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkPlaneGeometryDataMapper2DTest.cpp b/Modules/Core/test/mitkPlaneGeometryDataMapper2DTest.cpp index eb17a07889..4bff66ede1 100644 --- a/Modules/Core/test/mitkPlaneGeometryDataMapper2DTest.cpp +++ b/Modules/Core/test/mitkPlaneGeometryDataMapper2DTest.cpp @@ -1,93 +1,102 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include // VTK #include mitk::DataNode::Pointer addPlaneToDataStorage(mitk::RenderingTestHelper &renderingHelper, mitk::Image *image, mitk::PlaneGeometry::PlaneOrientation orientation, mitk::ScalarType zPos) { auto geometry = mitk::PlaneGeometry::New(); geometry->InitializeStandardPlane(image->GetGeometry(), orientation, zPos); auto geometryData = mitk::PlaneGeometryData::New(); geometryData->SetPlaneGeometry(geometry); auto node = mitk::DataNode::New(); node->SetData(geometryData); renderingHelper.AddNodeToStorage(node); return node; } int mitkPlaneGeometryDataMapper2DTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkPlaneGeometryDataMapper2DTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); auto image = static_cast( renderingHelper.GetDataStorage()->GetNode(mitk::TNodePredicateDataType::New())->GetData()); auto zCoord = image->GetGeometry()->GetBoundingBox()->GetCenter()[0]; addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Sagittal, zCoord); addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Frontal, zCoord); auto planeNode = addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Sagittal, zCoord); auto planeGeometry = static_cast(planeNode->GetData())->GetPlaneGeometry(); auto transform = mitk::AffineTransform3D::New(); mitk::Vector3D rotationAxis; rotationAxis.Fill(0.0); rotationAxis[2] = 1; transform->Rotate3D(rotationAxis, vnl_math::pi_over_4); planeGeometry->Compose(transform); auto bounds = planeGeometry->GetBounds(); bounds[1] /= 3; planeGeometry->SetBounds(bounds); planeGeometry->SetReferenceGeometry(nullptr); planeNode->SetIntProperty("Crosshair.Gap Size", 4); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 1) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("output.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkPointSetVtkMapper2DGlyphTypeTest.cpp b/Modules/Core/test/mitkPointSetVtkMapper2DGlyphTypeTest.cpp index 152816ca58..60d0ef6faa 100644 --- a/Modules/Core/test/mitkPointSetVtkMapper2DGlyphTypeTest.cpp +++ b/Modules/Core/test/mitkPointSetVtkMapper2DGlyphTypeTest.cpp @@ -1,62 +1,71 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include #include // VTK #include int mitkPointSetVtkMapper2DGlyphTypeTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkPointSetVtkMapper2DGlyphTypeTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); mitk::EnumerationProperty *eP = dynamic_cast(renderingHelper.GetDataStorage() ->GetNode(mitk::NodePredicateDataType::New("PointSet")) ->GetProperty("Pointset.2D.shape")); // render triangles instead of crosses eP->SetValue(5); // disables anti-aliasing which is enabled on several graphics cards and // causes problems when doing a pixel-wise comparison to a reference image renderingHelper.GetVtkRenderWindow()->SetMultiSamples(0); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("C:/development_ITK4/output.png"); } MITK_TEST_END(); } \ No newline at end of file diff --git a/Modules/Core/test/mitkPointSetVtkMapper2DImageTest.cpp b/Modules/Core/test/mitkPointSetVtkMapper2DImageTest.cpp index f5b046b237..19a1cd6b28 100644 --- a/Modules/Core/test/mitkPointSetVtkMapper2DImageTest.cpp +++ b/Modules/Core/test/mitkPointSetVtkMapper2DImageTest.cpp @@ -1,49 +1,58 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include int mitkPointSetVtkMapper2DImageTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkPointSetVtkMapper2DImageTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // disables anti-aliasing which is enabled on several graphics cards and // causes problems when doing a pixel-wise comparison to a reference image renderingHelper.GetVtkRenderWindow()->SetMultiSamples(0); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("C:/development_ITK4/output.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkPointSetVtkMapper2DTest.cpp b/Modules/Core/test/mitkPointSetVtkMapper2DTest.cpp index 3337582495..4e7144bd9f 100644 --- a/Modules/Core/test/mitkPointSetVtkMapper2DTest.cpp +++ b/Modules/Core/test/mitkPointSetVtkMapper2DTest.cpp @@ -1,52 +1,61 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include int mitkPointSetVtkMapper2DTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkPointSetVtkMapper2DTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // sagittal view direction renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); // disables anti-aliasing which is enabled on several graphics cards and // causes problems when doing a pixel-wise comparison to a reference image renderingHelper.GetVtkRenderWindow()->SetMultiSamples(0); //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("C:/development_ITK4/output.png"); } MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkPointSetVtkMapper2DTransformedPointsTest.cpp b/Modules/Core/test/mitkPointSetVtkMapper2DTransformedPointsTest.cpp index a9d6f179ca..1e122822fc 100644 --- a/Modules/Core/test/mitkPointSetVtkMapper2DTransformedPointsTest.cpp +++ b/Modules/Core/test/mitkPointSetVtkMapper2DTransformedPointsTest.cpp @@ -1,70 +1,80 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include #include // VTK #include int mitkPointSetVtkMapper2DTransformedPointsTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } + // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkPointSetVtkMapper2DTransformedPointsTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); mitk::DataNode *dataNode = renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("PointSet")); if (dataNode) { mitk::PointSet::Pointer pointSet = dynamic_cast(dataNode->GetData()); if (pointSet) { mitk::Point3D origin = pointSet->GetGeometry()->GetOrigin(); origin[1] += 10; origin[2] += 15; pointSet->GetGeometry()->SetOrigin(origin); pointSet->Modified(); dataNode->Update(); } } //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // use this to generate a reference screenshot or save the file: if (false) { renderingHelper.SaveReferenceScreenShot("D:/test/output.png"); } MITK_TEST_END(); } \ No newline at end of file diff --git a/Modules/Core/test/mitkSurfaceDepthPeelingTest.cpp b/Modules/Core/test/mitkSurfaceDepthPeelingTest.cpp index 13e07199d9..283709ca75 100644 --- a/Modules/Core/test/mitkSurfaceDepthPeelingTest.cpp +++ b/Modules/Core/test/mitkSurfaceDepthPeelingTest.cpp @@ -1,55 +1,64 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include // VTK #include int mitkSurfaceDepthPeelingTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkRenderingDepthPeelingTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv, mitk::BaseRenderer::RenderingMode::DepthPeeling); if (renderingHelper.IsAdvancedOpenGL()) { renderingHelper.SetMapperIDToRender3D(); mitk::DataNode *dataNode = renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Surface")); if (dataNode) { dataNode->SetOpacity(0.8); dataNode->Update(); } //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); } MITK_TEST_END(); } \ No newline at end of file diff --git a/Modules/Core/test/mitkSurfaceDepthSortingTest.cpp b/Modules/Core/test/mitkSurfaceDepthSortingTest.cpp index 1697cf2b64..7ff63b72ee 100644 --- a/Modules/Core/test/mitkSurfaceDepthSortingTest.cpp +++ b/Modules/Core/test/mitkSurfaceDepthSortingTest.cpp @@ -1,53 +1,62 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include // VTK #include int mitkSurfaceDepthSortingTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkRenderingDepthSortingTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); renderingHelper.SetMapperIDToRender3D(); mitk::DataNode *dataNode = renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Surface")); if (dataNode) { dataNode->SetOpacity(0.8); dataNode->SetBoolProperty("Depth Sorting", true); dataNode->Update(); } //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); MITK_TEST_END(); } \ No newline at end of file diff --git a/Modules/Core/test/mitkSurfaceVtkMapper3DTest.cpp b/Modules/Core/test/mitkSurfaceVtkMapper3DTest.cpp index 3f345f0aa2..5ef62aa095 100644 --- a/Modules/Core/test/mitkSurfaceVtkMapper3DTest.cpp +++ b/Modules/Core/test/mitkSurfaceVtkMapper3DTest.cpp @@ -1,110 +1,121 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include +#include // VTK #include #include #include #include #include #include #include #include int mitkSurfaceVtkMapper3DTest(int argc, char *argv[]) { // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkSurfaceVtkMapper3DTest") + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } + mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // 3D rendering test, thus 3D mapper ID. renderingHelper.SetMapperID(mitk::BaseRenderer::Standard3D); vtkSmartPointer textureCoordinates = vtkSmartPointer::New(); textureCoordinates->SetNumberOfComponents(2); textureCoordinates->SetName("TextureCoordinates"); mitk::Image::Pointer textureImage = static_cast( renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData()); // generate texture coordinates assuming that surface and texture can be mapped 1 to 1 unsigned int *dims = textureImage->GetDimensions(); for (unsigned int j = 0; j < dims[1]; ++j) { for (unsigned int i = 0; i < dims[0]; ++i) { int pixelID = i + j * dims[0]; float xNorm = (((float)i) / dims[0]); float yNorm = ((float)j) / dims[1]; textureCoordinates->InsertTuple2(pixelID, xNorm, yNorm); } } mitk::Surface::Pointer surfaceToPutTextureOn = static_cast( renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Surface"))->GetData()); surfaceToPutTextureOn->GetVtkPolyData()->GetPointData()->SetTCoords(textureCoordinates); mitk::SmartPointerProperty::Pointer textureProperty = mitk::SmartPointerProperty::New(textureImage); renderingHelper.GetDataStorage() ->GetNode(mitk::NodePredicateDataType::New("Surface")) ->SetProperty("Surface.Texture", textureProperty); // remove the image from the data storage in order to not disturb the world geometry //(only the surface geometry should be used for rendering) renderingHelper.GetDataStorage()->Remove( renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))); // Perform reinit, because we removed data. mitk::RenderingManager::GetInstance()->InitializeViews( renderingHelper.GetDataStorage()->ComputeBoundingGeometry3D(renderingHelper.GetDataStorage()->GetAll())); // Find a nice camera position to view the surface from the front. // This has to be done after calling renderingHelper.Render(), // because it would overwrite the camera position with global reinit. // It is not necessary, but else the surface is ugly rendered from the side. mitk::Point3D surfaceCenter = surfaceToPutTextureOn->GetGeometry()->GetCenter(); vtkCamera *camera3d = renderingHelper.GetVtkRenderer()->GetActiveCamera(); // 1m distance to camera should be a nice default value for most cameras camera3d->SetPosition(0, 0, -1000); camera3d->SetViewUp(0, -1, 0); camera3d->SetFocalPoint(0, 0, surfaceCenter[2]); camera3d->SetViewAngle(40); // camera3d->SetClippingRange(1, 10000); renderingHelper.GetVtkRenderer()->ResetCamera(); // use this to generate a reference screenshot or save the file: bool generateReferenceScreenshot = false; if (generateReferenceScreenshot) { renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); } //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); MITK_TEST_END(); } diff --git a/Modules/Core/test/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp b/Modules/Core/test/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp index 3e836853c4..f76ddb9632 100644 --- a/Modules/Core/test/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp +++ b/Modules/Core/test/mitkSurfaceVtkMapper3DTexturedSphereTest.cpp @@ -1,93 +1,102 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" #include #include #include // VTK #include #include #include #include #include #include #include /** * @brief mitkSurfaceVtkMapper3DTexturedSphereTest This test puts a texture onto a sphere. It is a nice example how to * use VTK methods to generate texture coordinates for MITK surfaces. * @param argv Just any image serving as texture. */ int mitkSurfaceVtkMapper3DTexturedSphereTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkSurfaceVtkMapper3DTexturedSphereTest") mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv); // This is a test for a 3D surface, thus we need to set the mapper ID to 3D renderingHelper.SetMapperID(mitk::BaseRenderer::Standard3D); //######## Exmaple code begin ######## // Generate a sphere in order to map texture on it vtkSmartPointer sphere = vtkSmartPointer::New(); sphere->SetThetaResolution(12); sphere->SetPhiResolution(12); sphere->SetRadius(50.0); // just to make it huge sphere->SetCenter(50, 0, 0); // just to center the sphere in the screen // taken from VTK example: http://www.vtk.org/Wiki/VTK/Examples/Python/Visualization/SphereTexture vtkSmartPointer mapToSphere = vtkSmartPointer::New(); mapToSphere->SetInputConnection(sphere->GetOutputPort()); mapToSphere->PreventSeamOn(); // get the texture image from the helper's data storage mitk::Image::Pointer textureImage = static_cast( renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData()); // Generate MITK surface mitk::Surface::Pointer surfaceToPutTextureOn = mitk::Surface::New(); surfaceToPutTextureOn->SetVtkPolyData(static_cast(mapToSphere->GetOutput())); // Generate a node mitk::DataNode::Pointer surfaceNode = mitk::DataNode::New(); surfaceNode->SetData(surfaceToPutTextureOn); // Make a Property and add to the node mitk::SmartPointerProperty::Pointer textureProperty = mitk::SmartPointerProperty::New(textureImage); surfaceNode->SetProperty("Surface.Texture", textureProperty); // add to data storage renderingHelper.AddNodeToStorage(surfaceNode); //######## Exmaple code end ######## // use this to generate a reference screenshot or save the file: bool generateReferenceScreenshot = false; if (generateReferenceScreenshot) { renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png"); } //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 50.0) == true, "CompareRenderWindowAgainstReference test result positive?"); MITK_TEST_END(); } diff --git a/Modules/PlanarFigure/test/mitkViewportRenderingTest.cpp b/Modules/PlanarFigure/test/mitkViewportRenderingTest.cpp index 6559258c84..6886fb2ba3 100644 --- a/Modules/PlanarFigure/test/mitkViewportRenderingTest.cpp +++ b/Modules/PlanarFigure/test/mitkViewportRenderingTest.cpp @@ -1,149 +1,160 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkColorProperty.h" #include "mitkImage.h" #include "mitkLevelWindowProperty.h" #include "mitkLevelWindowProperty.h" #include "mitkNodePredicateDataType.h" #include "mitkPlanarFigure.h" #include "mitkRenderingTestHelper.h" #include "mitkSurface.h" #include "mitkTestingMacros.h" +#include // ITK #include // VTK #include #include // stdlib #include int mitkViewportRenderingTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } + // load all arguments into a datastorage, take last argument as reference rendering // setup a renderwindow of fixed size X*Y // render the datastorage // compare rendering to reference image MITK_TEST_BEGIN("mitkViewportRenderingTest") /// \todo Fix leaks of vtkObjects. Bug 18095. vtkDebugLeaks::SetExitError(0); // enough parameters? if (argc < 2) { MITK_TEST_OUTPUT(<< "Usage: " << std::string(*argv) << " [file1 file2 ...] outputfile") MITK_TEST_OUTPUT(<< "Will render a central axial slice of all given files into outputfile") exit(EXIT_FAILURE); } double renderWindowWidth = atof(argv[1]); double renderWindowHeight = atof(argv[2]); double left = atof(argv[3]); double bottom = atof(argv[4]); double right = atof(argv[5]); double top = atof(argv[6]); std::string referenceFilename = argv[8 + 6]; argv += 6; // DO NOT attempt to read these as files, this just makes no sense argc -= 6; // DO NOT attempt to read these as files, this just makes no sense MITK_INFO << "Testing viewport " << right - left << "x" << top - bottom << " (" << left << ", " << bottom << ") to (" << right << ", " << top << ") " << "in render window of size " << renderWindowWidth << "x" << renderWindowHeight << "px"; mitk::RenderingTestHelper renderingHelper(renderWindowWidth, renderWindowHeight, argc, argv); // non-power-of-2 // for now this test renders Sagittal // renderingHelper.SetViewDirection(mitk::SliceNavigationController::Axial); renderingHelper.SetViewDirection(mitk::SliceNavigationController::Axial); typedef mitk::DataStorage::SetOfObjects ObjectsSet; ObjectsSet::ConstPointer figures = renderingHelper.GetDataStorage()->GetSubset(mitk::TNodePredicateDataType::New()); for (ObjectsSet::const_iterator iterFigures = figures->begin(); iterFigures != figures->end(); ++iterFigures) { (*iterFigures)->SetProperty("planarfigure.default.line.color", mitk::ColorProperty::New(1.0, 0.0, 0.0)); // red (*iterFigures)->SetProperty("planarfigure.drawcontrolpoints", mitk::BoolProperty::New(false)); (*iterFigures)->SetProperty("planarfigure.drawname", mitk::BoolProperty::New(false)); (*iterFigures)->SetProperty("planarfigure.drawquantities", mitk::BoolProperty::New(true)); } ObjectsSet::ConstPointer surfaces = renderingHelper.GetDataStorage()->GetSubset(mitk::TNodePredicateDataType::New()); for (ObjectsSet::const_iterator iterSurfaces = surfaces->begin(); iterSurfaces != surfaces->end(); ++iterSurfaces) { (*iterSurfaces)->SetProperty("color", mitk::ColorProperty::New(0.0, 1.0, 0.0)); // green } ObjectsSet::ConstPointer images = renderingHelper.GetDataStorage()->GetSubset(mitk::TNodePredicateDataType::New()); for (ObjectsSet::const_iterator iterImages = images->begin(); iterImages != images->end(); ++iterImages) { (*iterImages)->SetProperty("levelwindow", mitk::LevelWindowProperty::New(mitk::LevelWindow(128.0, 256.0))); // green int imageWidth = dynamic_cast((*iterImages)->GetData())->GetDimension(0); int imageHeight = dynamic_cast((*iterImages)->GetData())->GetDimension(1); MITK_INFO << "Image dimension " << imageWidth << "x" << imageHeight; } double vLeft = left / renderWindowWidth; double vBottom = bottom / renderWindowHeight; double vRight = right / renderWindowWidth; double vTop = top / renderWindowHeight; // THIS HERE IS THE ACTUAL TEST PART, all the rest is setup and decoration mitk::RenderingManager::GetInstance()->InitializeViews( renderingHelper.GetDataStorage()->ComputeBoundingGeometry3D(images)); renderingHelper.GetVtkRenderer()->SetViewport(vLeft, vBottom, vRight, vTop); renderingHelper.SetAutomaticallyCloseRenderWindow(true); // set to false for testing the test itself renderingHelper.Render(); // use this to generate a reference screenshot or save the file: bool generateReferenceScreenshot = false; if (generateReferenceScreenshot) { std::string tmpFilename = referenceFilename; std::string::size_type slashpos = referenceFilename.find_last_of('/'); tmpFilename = referenceFilename.substr(slashpos + 1); tmpFilename = std::string("/tmp/") + tmpFilename; renderingHelper.SaveAsPNG(tmpFilename); MITK_INFO << "*********************************"; MITK_INFO << "SAVE TO " << tmpFilename; MITK_INFO << "*********************************"; } //### Usage of vtkRegressionTestImage: // vtkRegressionTestImage( vtkRenderWindow ) // Set a vtkRenderWindow containing the desired scene. // vtkRegressionTestImage automatically searches in argc and argv[] // for a path a valid image with -V. If the test failed with the // first image (foo.png) check if there are images of the form // foo_N.png (where N=1,2,3...) and compare against them. int retVal = vtkRegressionTestImageThreshold(renderingHelper.GetVtkRenderWindow(), 20.0); // retVal meanings: (see VTK/Rendering/vtkTesting.h) // 0 = test failed // 1 = test passed // 2 = test not run // 3 = something with vtkInteraction MITK_TEST_CONDITION(retVal == 1, "VTK rendering result matches expectation"); MITK_TEST_END(); } diff --git a/Modules/SceneSerialization/test/mitkSceneIOCompatibilityTest.cpp b/Modules/SceneSerialization/test/mitkSceneIOCompatibilityTest.cpp index 6683c32147..da11153bfd 100644 --- a/Modules/SceneSerialization/test/mitkSceneIOCompatibilityTest.cpp +++ b/Modules/SceneSerialization/test/mitkSceneIOCompatibilityTest.cpp @@ -1,48 +1,57 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkRenderingTestHelper.h" #include "mitkTestingMacros.h" // VTK #include int mitkSceneIOCompatibilityTest(int argc, char *argv[]) { + try + { + mitk::RenderingTestHelper openGlTest(640, 480); + } + catch (const mitk::TestNotRunException &e) + { + MITK_WARN << "Test not run: " << e.GetDescription(); + return 77; + } // Load all arguments but last into a DataStorage, // Take last argument as reference rendering. // // Setup a renderwindow of fixed size X*Y. // Render the DataStorage. // Compare rendering to reference image. MITK_TEST_BEGIN("mitkSceneIOCompatibilityTest") mitk::RenderingTestHelper renderingHelper(200, 200, argc, argv); // Usage of CompareRenderWindowAgainstReference: See documentation of mitkRenderingTestHelper MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?"); // You can use this to generate a new reference // on your platform or after changes: if (false) { renderingHelper.SaveReferenceScreenShot("/where/you/want.png"); } MITK_TEST_END(); }