diff --git a/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake b/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake index 727a37cca8..9252e12b8c 100644 --- a/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake +++ b/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake @@ -1,213 +1,215 @@ #----------------------------------------------------------------------------- # MITK #----------------------------------------------------------------------------- set(MITK_DEPENDS) set(proj_DEPENDENCIES) set(proj MITK) if(NOT MITK_DIR) #----------------------------------------------------------------------------- # Create CMake options to customize the MITK build #----------------------------------------------------------------------------- option(MITK_USE_SUPERBUILD "Use superbuild for MITK" ON) option(MITK_USE_BLUEBERRY "Build the BlueBerry platform in MITK" ON) option(MITK_BUILD_EXAMPLES "Build the MITK examples" OFF) option(MITK_BUILD_ALL_PLUGINS "Build all MITK plugins" OFF) option(MITK_BUILD_TESTING "Build the MITK unit tests" OFF) option(MITK_USE_CTK "Use CTK in MITK" ${MITK_USE_BLUEBERRY}) option(MITK_USE_DCMTK "Use DCMTK in MITK" ON) option(MITK_USE_QT "Use Nokia's Qt library in MITK" ON) option(MITK_USE_Boost "Use the Boost library in MITK" OFF) option(MITK_USE_OpenCV "Use Intel's OpenCV library" OFF) + option(MITK_USE_SOFA "Use Simulation Open Framework Architecture" OFF) option(MITK_USE_Python "Enable Python wrapping in MITK" OFF) if(MITK_USE_BLUEBERRY AND NOT MITK_USE_CTK) message("Forcing MITK_USE_CTK to ON because of MITK_USE_BLUEBERRY") set(MITK_USE_CTK ON CACHE BOOL "Use CTK in MITK" FORCE) endif() if(MITK_USE_CTK AND NOT MITK_USE_QT) message("Forcing MITK_USE_QT to ON because of MITK_USE_CTK") set(MITK_USE_QT ON CACHE BOOL "Use Nokia's Qt library in MITK" FORCE) endif() set(MITK_USE_CableSwig ${MITK_USE_Python}) set(MITK_USE_GDCM 1) set(MITK_USE_ITK 1) set(MITK_USE_VTK 1) mark_as_advanced(MITK_USE_SUPERBUILD MITK_BUILD_ALL_PLUGINS MITK_BUILD_TESTING ) set(mitk_cmake_boolean_args MITK_USE_SUPERBUILD MITK_USE_BLUEBERRY MITK_BUILD_EXAMPLES MITK_BUILD_ALL_PLUGINS MITK_USE_CTK MITK_USE_DCMTK MITK_USE_QT MITK_USE_Boost MITK_USE_OpenCV + MITK_USE_SOFA MITK_USE_Python ) if(MITK_USE_QT) # Look for Qt at the superbuild level, to catch missing Qt libs early find_package(Qt4 4.6.0 REQUIRED) endif() set(additional_mitk_cmakevars ) # Configure the set of default pixel types set(MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES "int, unsigned int, short, unsigned short, char, unsigned char" CACHE STRING "List of integral pixel types used in AccessByItk and InstantiateAccessFunction macros") set(MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES "double, float" CACHE STRING "List of floating pixel types used in AccessByItk and InstantiateAccessFunction macros") set(MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES "" CACHE STRING "List of composite pixel types used in AccessByItk and InstantiateAccessFunction macros") set(MITK_ACCESSBYITK_DIMENSIONS "2,3" CACHE STRING "List of dimensions used in AccessByItk and InstantiateAccessFunction macros") foreach(_arg MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES MITK_ACCESSBYITK_DIMENSIONS) mark_as_advanced(${_arg}) list(APPEND additional_mitk_cmakevars "-D${_arg}:STRING=${${_arg}}") endforeach() #----------------------------------------------------------------------------- # Create options to inject pre-build dependencies #----------------------------------------------------------------------------- - foreach(proj CTK DCMTK GDCM VTK ITK OpenCV CableSwig) + foreach(proj CTK DCMTK GDCM VTK ITK OpenCV SOFA CableSwig) if(MITK_USE_${proj}) set(MITK_${proj}_DIR "${${proj}_DIR}" CACHE PATH "Path to ${proj} build directory") mark_as_advanced(MITK_${proj}_DIR) if(MITK_${proj}_DIR) list(APPEND additional_mitk_cmakevars "-D${proj}_DIR:PATH=${MITK_${proj}_DIR}") endif() endif() endforeach() if(MITK_USE_Boost) set(MITK_BOOST_ROOT "${BOOST_ROOT}" CACHE PATH "Path to Boost directory") mark_as_advanced(MITK_BOOST_ROOT) if(MITK_BOOST_ROOT) list(APPEND additional_mitk_cmakevars "-DBOOST_ROOT:PATH=${MITK_BOOST_ROOT}") endif() endif() set(MITK_SOURCE_DIR "" CACHE PATH "MITK source code location. If empty, MITK will be cloned from MITK_GIT_REPOSITORY") set(MITK_GIT_REPOSITORY "http://git.mitk.org/MITK.git" CACHE STRING "The git repository for cloning MITK") set(MITK_GIT_TAG "origin/master" CACHE STRING "The git tag/hash to be used when cloning from MITK_GIT_REPOSITORY") mark_as_advanced(MITK_SOURCE_DIR MITK_GIT_REPOSITORY MITK_GIT_TAG) #----------------------------------------------------------------------------- # Create the final variable containing superbuild boolean args #----------------------------------------------------------------------------- set(mitk_boolean_args) foreach(mitk_cmake_arg ${mitk_cmake_boolean_args}) list(APPEND mitk_boolean_args -D${mitk_cmake_arg}:BOOL=${${mitk_cmake_arg}}) endforeach() #----------------------------------------------------------------------------- # Additional MITK CMake variables #----------------------------------------------------------------------------- if(MITK_USE_QT AND QT_QMAKE_EXECUTABLE) list(APPEND additional_mitk_cmakevars "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}") endif() if(MITK_USE_CTK) list(APPEND additional_mitk_cmakevars "-DGIT_EXECUTABLE:FILEPATH=${GIT_EXECUTABLE}") endif() if(MITK_INITIAL_CACHE_FILE) list(APPEND additional_mitk_cmakevars "-DMITK_INITIAL_CACHE_FILE:INTERNAL=${MITK_INITIAL_CACHE_FILE}") endif() if(MITK_USE_SUPERBUILD) set(MITK_BINARY_DIR ${proj}-superbuild) else() set(MITK_BINARY_DIR ${proj}-build) endif() set(proj_DEPENDENCIES) set(MITK_DEPENDS ${proj}) # Configure the MITK souce code location if(NOT MITK_SOURCE_DIR) set(mitk_source_location SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj} GIT_REPOSITORY ${MITK_GIT_REPOSITORY} GIT_TAG ${MITK_GIT_TAG} ) else() set(mitk_source_location SOURCE_DIR ${MITK_SOURCE_DIR} ) endif() ExternalProject_Add(${proj} ${mitk_source_location} BINARY_DIR ${MITK_BINARY_DIR} PREFIX ${proj}${ep_suffix} INSTALL_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_ARGS ${ep_common_args} ${mitk_boolean_args} ${additional_mitk_cmakevars} -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_TESTING:BOOL=${MITK_BUILD_TESTING} DEPENDS ${proj_DEPENDENCIES} ) if(MITK_USE_SUPERBUILD) set(MITK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MITK_BINARY_DIR}/MITK-build") else() set(MITK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MITK_BINARY_DIR}") endif() else() # The project is provided using MITK_DIR, nevertheless since other # projects may depend on MITK, let's add an 'empty' one MacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") # Further, do some sanity checks in the case of a pre-built MITK set(my_itk_dir ${ITK_DIR}) set(my_vtk_dir ${VTK_DIR}) set(my_qmake_executable ${QT_QMAKE_EXECUTABLE}) find_package(MITK REQUIRED) if(my_itk_dir AND NOT my_itk_dir STREQUAL ${ITK_DIR}) message(FATAL_ERROR "ITK packages do not match:\n ${MY_PROJECT_NAME}: ${my_itk_dir}\n MITK: ${ITK_DIR}") endif() if(my_vtk_dir AND NOT my_vtk_dir STREQUAL ${VTK_DIR}) message(FATAL_ERROR "VTK packages do not match:\n ${MY_PROJECT_NAME}: ${my_vtk_dir}\n MITK: ${VTK_DIR}") endif() if(my_qmake_executable AND NOT my_qmake_executable STREQUAL ${MITK_QMAKE_EXECUTABLE}) message(FATAL_ERROR "Qt qmake does not match:\n ${MY_PROJECT_NAME}: ${my_qmake_executable}\n MITK: ${MITK_QMAKE_EXECUTABLE}") endif() endif() diff --git a/CMake/MITKDashboardSetup.cmake b/CMake/MITKDashboardSetup.cmake index 488f8651ab..d8ca933c66 100644 --- a/CMake/MITKDashboardSetup.cmake +++ b/CMake/MITKDashboardSetup.cmake @@ -1,131 +1,137 @@ # This file is intended to be included at the end of a custom MITKDashboardScript.TEMPLATE.cmake file list(APPEND CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}") # # Automatically determined properties # set(MY_OPERATING_SYSTEM "${CMAKE_HOST_SYSTEM}") # Windows 7, Linux-2.6.32, Darwin... site_name(CTEST_SITE) if(QT_BINARY_DIR) set(QT_QMAKE_EXECUTABLE "${QT_BINARY_DIR}/qmake") else() set(QT_QMAKE_EXECUTABLE "qmake") endif() execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} --version OUTPUT_VARIABLE MY_QT_VERSION RESULT_VARIABLE qmake_error) if(qmake_error) message(FATAL_ERROR "Error when executing ${QT_QMAKE_EXECUTABLE} --version\n${qmake_error}") endif() string(REGEX REPLACE ".*Qt version ([0-9.]+) .*" "\\1" MY_QT_VERSION ${MY_QT_VERSION}) # # Project specific properties # if(NOT CTEST_BUILD_NAME) set(CTEST_BUILD_NAME "${MY_OPERATING_SYSTEM}-${MY_COMPILER}-Qt-${MY_QT_VERSION}-${CTEST_BUILD_CONFIGURATION}") endif() set(PROJECT_BUILD_DIR "MITK-build") set(CTEST_PATH "$ENV{PATH}") if(WIN32) set(VTK_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/VTK-build/bin/${CTEST_BUILD_CONFIGURATION}") set(ITK_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/ITK-build/bin/${CTEST_BUILD_CONFIGURATION}") set(BOOST_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/Boost-src/stage/lib") set(GDCM_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/GDCM-build/bin/${CTEST_BUILD_CONFIGURATION}") set(OPENCV_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/OpenCV-build/bin/${CTEST_BUILD_CONFIGURATION}") + set(SOFA_BINARY_DIR "${CTEST_BINARY_DIRECTORY}/SOFA-build/bin/${CTEST_BUILD_CONFIGURATION}") set(BLUEBERRY_OSGI_DIR "${CTEST_BINARY_DIRECTORY}/MITK-build/bin/BlueBerry/org.blueberry.osgi/bin/${CTEST_BUILD_CONFIGURATION}") set(CTEST_PATH "${CTEST_PATH};${QT_BINARY_DIR};${VTK_BINARY_DIR};${ITK_BINARY_DIR};${BOOST_BINARY_DIR};${GDCM_BINARY_DIR};${OPENCV_BINARY_DIR};${BLUEBERRY_OSGI_DIR}") endif() set(ENV{PATH} "${CTEST_PATH}") set(SUPERBUILD_TARGETS "") # If the dashscript doesn't define a GIT_REPOSITORY variable, let's define it here. if(NOT DEFINED GIT_REPOSITORY OR GIT_REPOSITORY STREQUAL "") set(GIT_REPOSITORY "http://git.mitk.org/MITK.git") endif() # # Display build info # message("Site name: ${CTEST_SITE}") message("Build name: ${CTEST_BUILD_NAME}") message("Script Mode: ${SCRIPT_MODE}") message("Coverage: ${WITH_COVERAGE}, MemCheck: ${WITH_MEMCHECK}") # # Set initial cache options # if(CMAKE_GENERATOR MATCHES "[Mm]ake") set(CTEST_USE_LAUNCHERS 1) else() set(CTEST_USE_LAUNCHERS 0) endif() # Remove this if block after all dartclients work if(DEFINED ADDITIONNAL_CMAKECACHE_OPTION) message(WARNING "Rename ADDITIONNAL to ADDITIONAL in your dartlclient script: ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}") set(ADDITIONAL_CMAKECACHE_OPTION ${ADDITIONNAL_CMAKECACHE_OPTION}) endif() if(NOT DEFINED MITK_USE_Boost) set(MITK_USE_Boost 1) endif() if(NOT DEFINED MITK_USE_OpenCV) set(MITK_USE_OpenCV 1) endif() +if(NOT DEFINED MITK_USE_SOFA) + set(MITK_USE_SOFA 1) +endif() + if(NOT DEFINED MITK_BUILD_ALL_APPS) set(MITK_BUILD_ALL_APPS TRUE) endif() if(NOT DEFINED BLUEBERRY_BUILD_ALL_PLUGINS) set(BLUEBERRY_BUILD_ALL_PLUGINS TRUE) endif() if(NOT DEFINED MITK_BUILD_ALL_PLUGINS) set(MITK_BUILD_ALL_PLUGINS TRUE) endif() if(NOT DEFINED MITK_BUILD_EXAMPLES) set(MITK_BUILD_EXAMPLES TRUE) endif() set(INITIAL_CMAKECACHE_OPTIONS " BLUEBERRY_BUILD_ALL_PLUGINS:BOOL=${MITK_BUILD_ALL_PLUGINS} MITK_BUILD_ALL_PLUGINS:BOOL=${MITK_BUILD_ALL_PLUGINS} MITK_BUILD_ALL_APPS:BOOL=${MITK_BUILD_ALL_APPS} MITK_BUILD_EXAMPLES:BOOL=${MITK_BUILD_EXAMPLES} SUPERBUILD_EXCLUDE_MITKBUILD_TARGET:BOOL=TRUE MITK_USE_Boost:BOOL=${MITK_USE_Boost} MITK_USE_OpenCV:BOOL=${MITK_USE_OpenCV} +MITK_USE_SOFA:BOOL=${MITK_USE_SOFA} ${ADDITIONAL_CMAKECACHE_OPTION} ") # Write a cache file for populating the MITK initial cache (not the superbuild cache). # This can be used to provide variables which are not passed through the # superbuild process to the MITK configure step) if(MITK_INITIAL_CACHE) set(mitk_cache_file "${CTEST_SCRIPT_DIRECTORY}/mitk_initial_cache.txt") file(WRITE "${mitk_cache_file}" "${MITK_INITIAL_CACHE}") set(INITIAL_CMAKECACHE_OPTIONS "${INITIAL_CMAKECACHE_OPTIONS} MITK_INITIAL_CACHE_FILE:INTERNAL=${mitk_cache_file} ") endif() # # Download and include dashboard driver script # set(url "http://mitk.org/git/?p=MITK.git;a=blob_plain;f=CMake/MITKDashboardDriverScript.cmake;hb=${hb}") set(dest ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}.driver) downloadFile("${url}" "${dest}") include(${dest}) diff --git a/CMake/PackageDepends/MITK_SOFA_Config.cmake b/CMake/PackageDepends/MITK_SOFA_Config.cmake new file mode 100644 index 0000000000..ef28d61b0c --- /dev/null +++ b/CMake/PackageDepends/MITK_SOFA_Config.cmake @@ -0,0 +1,4 @@ +find_package(SOFA REQUIRED) +list(APPEND ALL_INCLUDE_DIRECTORIES ${SOFA_INCLUDE_DIRS}) +list(APPEND ALL_LIBRARIES ${SOFA_LIBRARIES}) +link_directories(${SOFA_LIBRARY_DIRS}) diff --git a/CMake/mitkFunctionCreateWindowsBatchScript.cmake b/CMake/mitkFunctionCreateWindowsBatchScript.cmake index a640e60fae..f8e542428d 100644 --- a/CMake/mitkFunctionCreateWindowsBatchScript.cmake +++ b/CMake/mitkFunctionCreateWindowsBatchScript.cmake @@ -1,25 +1,31 @@ function(mitkFunctionCreateWindowsBatchScript in out build_type) if(GDCM_DIR) set(GDCM_BIN_DIR "${GDCM_DIR}/bin/${build_type}") else() set(GDCM_BIN_DIR) endif() if(OpenCV_DIR) set(OpenCV_BIN_DIR "${OpenCV_DIR}/bin/${build_type}") else() set(OpenCV_BIN_DIR) endif() + if(SOFA_DIR) + set(SOFA_BIN_DIR "${SOFA_DIR}/bin/${build_type}") + else() + set(SOFA_BIN_DIR) + endif() + set(MITK_LIBRARY_DIRS_WITH_BUILD_TYPE) if(MITK_LIBRARY_DIRS) foreach(lib_dir ${MITK_LIBRARY_DIRS}) list(APPEND MITK_LIBRARY_DIRS_WITH_BUILD_TYPE "${lib_dir}/${build_type}") endforeach() endif() set(VS_BUILD_TYPE ${build_type}) string(REPLACE "%VS_BUILD_TYPE%" "${VS_BUILD_TYPE}" MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH}") configure_file(${in} ${out} @ONLY) endfunction() \ No newline at end of file diff --git a/CMake/mitkMacroInstallTargets.cmake b/CMake/mitkMacroInstallTargets.cmake index 1fb46f5118..4a9319a957 100644 --- a/CMake/mitkMacroInstallTargets.cmake +++ b/CMake/mitkMacroInstallTargets.cmake @@ -1,141 +1,144 @@ # # MITK specific cross plattform install macro # # Usage: MITK_INSTALL_TARGETS(target1 [target2] ....) # macro(MITK_INSTALL_TARGETS) MACRO_PARSE_ARGUMENTS(_install "TARGETS;EXECUTABLES;PLUGINS;LIBRARY_DIRS" "GLOB_PLUGINS" ${ARGN}) list(APPEND _install_TARGETS ${_install_DEFAULT_ARGS}) # TODO: how to supply the correct intermediate directory?? # CMAKE_CFG_INTDIR is not expanded to actual values inside the install(CODE "...") macro ... set(intermediate_dir ) if(WIN32 AND NOT MINGW) set(intermediate_dir Release) endif() set(DIRS ${MITK_VTK_LIBRARY_DIRS}/${intermediate_dir} ${MITK_ITK_LIBRARY_DIRS}/${intermediate_dir} ${QT_LIBRARY_DIR} ${QT_LIBRARY_DIR}/../bin ${MITK_BINARY_DIR}/bin/${intermediate_dir} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${intermediate_dir} ) foreach(_lib_dir ${_install_LIBRARY_DIRS}) list(APPEND DIRS ${_lib_dir}/${intermediate_dir}) endforeach() if(MITK_USE_Boost AND MITK_USE_Boost_LIBRARIES AND NOT MITK_USE_SYSTEM_Boost) list(APPEND DIRS ${Boost_LIBRARY_DIRS}) endif() if(GDCM_DIR) list(APPEND DIRS ${GDCM_DIR}/bin/${intermediate_dir}) endif() if(OpenCV_DIR) list(APPEND DIRS ${OpenCV_DIR}/bin/${intermediate_dir}) endif() + if(SOFA_DIR) + list(APPEND DIRS ${SOFA_DIR}/bin/${intermediate_dir}) + endif() if(MITK_USE_BLUEBERRY) list(APPEND DIRS ${CTK_RUNTIME_LIBRARY_DIRS}/${intermediate_dir}) endif() list(REMOVE_DUPLICATES DIRS) if(QT_LIBRARY_DIR MATCHES "^(/lib/|/lib32/|/lib64/|/usr/lib/|/usr/lib32/|/usr/lib64/|/usr/X11R6/)") set(_qt_is_system_qt 1) endif() foreach(_target ${_install_EXECUTABLES}) get_target_property(_is_bundle ${_target} MACOSX_BUNDLE) set(_qt_plugins_install_dirs "") set(_qt_conf_install_dirs "") set(_target_locations "") if(APPLE) if(_is_bundle) set(_target_locations ${_target}.app) set(${_target_locations}_qt_plugins_install_dir ${_target}.app/Contents/MacOS) set(_bundle_dest_dir ${_target}.app/Contents/MacOS) set(_qt_plugins_for_current_bundle ${_target}.app/Contents/MacOS) set(_qt_conf_install_dirs ${_target}.app/Contents/Resources) install(TARGETS ${_target} BUNDLE DESTINATION . ) else() if(NOT MACOSX_BUNDLE_NAMES) set(_qt_conf_install_dirs bin) set(_target_locations bin/${_target}) set(${_target_locations}_qt_plugins_install_dir bin) install(TARGETS ${_target} RUNTIME DESTINATION bin) else() foreach(bundle_name ${MACOSX_BUNDLE_NAMES}) list(APPEND _qt_conf_install_dirs ${bundle_name}.app/Contents/Resources) set(_current_target_location ${bundle_name}.app/Contents/MacOS/${_target}) list(APPEND _target_locations ${_current_target_location}) set(${_current_target_location}_qt_plugins_install_dir ${bundle_name}.app/Contents/MacOS) message( " set(${_current_target_location}_qt_plugins_install_dir ${bundle_name}.app/Contents/MacOS) ") install(TARGETS ${_target} RUNTIME DESTINATION ${bundle_name}.app/Contents/MacOS/) endforeach() endif() endif() else() set(_target_locations bin/${_target}${CMAKE_EXECUTABLE_SUFFIX}) set(${_target_locations}_qt_plugins_install_dir bin) set(_qt_conf_install_dirs bin) install(TARGETS ${_target} RUNTIME DESTINATION bin) endif() foreach(_target_location ${_target_locations}) if(NOT _qt_is_system_qt) if(QT_PLUGINS_DIR) if(WIN32) install(DIRECTORY "${QT_PLUGINS_DIR}" DESTINATION ${${_target_location}_qt_plugins_install_dir} CONFIGURATIONS Release FILES_MATCHING REGEX "[^4d]4?${CMAKE_SHARED_LIBRARY_SUFFIX}" ) install(DIRECTORY "${QT_PLUGINS_DIR}" DESTINATION ${${_target_location}_qt_plugins_install_dir} CONFIGURATIONS Debug FILES_MATCHING REGEX "d4?${CMAKE_SHARED_LIBRARY_SUFFIX}" ) else(WIN32) # install everything, see bug 7143 install(DIRECTORY "${QT_PLUGINS_DIR}" DESTINATION ${${_target_location}_qt_plugins_install_dir} FILES_MATCHING REGEX "${CMAKE_SHARED_LIBRARY_SUFFIX}" ) endif(WIN32) endif() endif() _fixup_target() endforeach() if(NOT _qt_is_system_qt) #-------------------------------------------------------------------------------- # install a qt.conf file # this inserts some cmake code into the install script to write the file set(_qt_conf_plugin_install_prefix .) if(APPLE) set(_qt_conf_plugin_install_prefix ./MacOS) endif() foreach(_qt_conf_install_dir ${_qt_conf_install_dirs}) install(CODE "file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${_qt_conf_install_dir}/qt.conf\" \" [Paths] Prefix=${_qt_conf_plugin_install_prefix} \")") endforeach() endif() endforeach() endmacro() diff --git a/CMakeExternals/PatchSOFA-rev8935.cmake b/CMakeExternals/PatchSOFA-rev8935.cmake new file mode 100644 index 0000000000..e10c1bbd70 --- /dev/null +++ b/CMakeExternals/PatchSOFA-rev8935.cmake @@ -0,0 +1,7 @@ +set(baseDir "framework/sofa/helper/system/") +foreach(sourceFile "${baseDir}gl.h" "${baseDir}glu.h" "${baseDir}glut.h" "${baseDir}../gl/glfont.cpp") + file(STRINGS ${sourceFile} sourceCode NEWLINE_CONSUME) + string(REGEX REPLACE "<(Open)?GL(UT)?/" "<" sourceCode ${sourceCode}) + set(CONTENTS ${sourceCode}) + configure_file(${TEMPLATE_FILE} ${sourceFile} @ONLY) +endforeach() \ No newline at end of file diff --git a/CMakeExternals/SOFA.cmake b/CMakeExternals/SOFA.cmake new file mode 100644 index 0000000000..e1f77bd8c1 --- /dev/null +++ b/CMakeExternals/SOFA.cmake @@ -0,0 +1,37 @@ +#----------------------------------------------------------------------------- +# SOFA +#----------------------------------------------------------------------------- + +if(MITK_USE_SOFA) + # Sanity checks + if(DEFINED SOFA_DIR AND NOT EXISTS ${SOFA_DIR}) + message(FATAL_ERROR "SOFA_DIR variable is defined but corresponds to non-existing directory") + endif() + + set(proj SOFA) + set(proj_DEPENDENCIES) + set(SOFA_DEPENDS ${proj}) + + set(SOFA_PATCH_COMMAND ${CMAKE_COMMAND} -DTEMPLATE_FILE:FILEPATH=${MITK_SOURCE_DIR}/CMakeExternals/EmptyFileForPatching.dummy -P ${MITK_SOURCE_DIR}/CMakeExternals/PatchSOFA-rev8935.cmake) + + if(NOT DEFINED SOFA_DIR) + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}-src + BINARY_DIR ${proj}-build + PREFIX ${proj}-cmake + URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/SOFA_29180826.tar.gz + URL_MD5 9e4bf55a3b872a1db53c9ad399faa6c0 + PATCH_COMMAND ${SOFA_PATCH_COMMAND} + INSTALL_COMMAND "" + CMAKE_GENERATOR ${gen} + CMAKE_ARGS + ${ep_common_args} + ${additional_cmake_args} + DEPENDS ${proj_DEPENDENCIES} + ) + + set(SOFA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build) + else() + mitkMacroEmptyExternalProject(${proj} "${proj}_DEPENDENCIES}") + endif() +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d31e5d2e0..a24d4a94cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,942 +1,947 @@ if(APPLE) # With XCode 4.3, the SDK location changed. Older CMake # versions are not able to find it. cmake_minimum_required(VERSION 2.8.8) else() cmake_minimum_required(VERSION 2.8.4) endif() #----------------------------------------------------------------------------- # Set a default build type if none was specified #----------------------------------------------------------------------------- if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to 'Debug' as none was specified.") set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() #----------------------------------------------------------------------------- # Superbuild Option - Enabled by default #----------------------------------------------------------------------------- option(MITK_USE_SUPERBUILD "Build MITK and the projects it depends on via SuperBuild.cmake." ON) if(MITK_USE_SUPERBUILD) project(MITK-superbuild) set(MITK_SOURCE_DIR ${PROJECT_SOURCE_DIR}) set(MITK_BINARY_DIR ${PROJECT_BINARY_DIR}) else() project(MITK) endif() #----------------------------------------------------------------------------- # Warn if source or build path is too long #----------------------------------------------------------------------------- if(WIN32) set(_src_dir_length_max 50) set(_bin_dir_length_max 50) if(MITK_USE_SUPERBUILD) set(_src_dir_length_max 43) # _src_dir_length_max - strlen(ITK-src) set(_bin_dir_length_max 40) # _bin_dir_length_max - strlen(MITK-build) endif() string(LENGTH "${MITK_SOURCE_DIR}" _src_n) string(LENGTH "${MITK_BINARY_DIR}" _bin_n) # The warnings should be converted to errors if(_src_n GREATER _src_dir_length_max) message(WARNING "MITK source code directory path length is too long (${_src_n} > ${_src_dir_length_max})." "Please move the MITK source code directory to a directory with a shorter path." ) endif() if(_bin_n GREATER _bin_dir_length_max) message(WARNING "MITK build directory path length is too long (${_bin_n} > ${_bin_dir_length_max})." "Please move the MITK build directory to a directory with a shorter path." ) endif() endif() #----------------------------------------------------------------------------- # See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details #----------------------------------------------------------------------------- set(project_policies CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used. CMP0002 # NEW: Logical target names must be globally unique. CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths. CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace. CMP0005 # NEW: Preprocessor definition values are now escaped automatically. CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION. CMP0007 # NEW: List command no longer ignores empty elements. CMP0008 # NEW: Libraries linked by full-path must have a valid library file name. CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default. CMP0010 # NEW: Bad variable reference syntax is an error. CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP. CMP0012 # NEW: if() recognizes numbers and boolean constants. CMP0013 # NEW: Duplicate binary directories are not allowed. CMP0014 # NEW: Input directories must have CMakeLists.txt ) foreach(policy ${project_policies}) if(POLICY ${policy}) cmake_policy(SET ${policy} NEW) endif() endforeach() #----------------------------------------------------------------------------- # Update CMake module path #------------------------------------------------------------------------------ set(CMAKE_MODULE_PATH ${MITK_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH} ) #----------------------------------------------------------------------------- # CMake function(s) and macro(s) #----------------------------------------------------------------------------- include(mitkMacroEmptyExternalProject) include(mitkFunctionGenerateProjectXml) include(mitkFunctionSuppressWarnings) SUPPRESS_VC_DEPRECATED_WARNINGS() #----------------------------------------------------------------------------- # Output directories. #----------------------------------------------------------------------------- foreach(type LIBRARY RUNTIME ARCHIVE) # Make sure the directory exists if(DEFINED MITK_CMAKE_${type}_OUTPUT_DIRECTORY AND NOT EXISTS ${MITK_CMAKE_${type}_OUTPUT_DIRECTORY}) message("Creating directory MITK_CMAKE_${type}_OUTPUT_DIRECTORY: ${MITK_CMAKE_${type}_OUTPUT_DIRECTORY}") file(MAKE_DIRECTORY "${MITK_CMAKE_${type}_OUTPUT_DIRECTORY}") endif() if(MITK_USE_SUPERBUILD) set(output_dir ${MITK_BINARY_DIR}/bin) if(NOT DEFINED MITK_CMAKE_${type}_OUTPUT_DIRECTORY) set(MITK_CMAKE_${type}_OUTPUT_DIRECTORY ${MITK_BINARY_DIR}/MITK-build/bin) endif() else() if(NOT DEFINED MITK_CMAKE_${type}_OUTPUT_DIRECTORY) set(output_dir ${MITK_BINARY_DIR}/bin) else() set(output_dir ${MITK_CMAKE_${type}_OUTPUT_DIRECTORY}) endif() endif() set(CMAKE_${type}_OUTPUT_DIRECTORY ${output_dir} CACHE INTERNAL "Single output directory for building all libraries.") mark_as_advanced(CMAKE_${type}_OUTPUT_DIRECTORY) endforeach() #----------------------------------------------------------------------------- # Additional MITK Options (also shown during superbuild) #----------------------------------------------------------------------------- option(BUILD_SHARED_LIBS "Build MITK with shared libraries" ON) option(WITH_COVERAGE "Enable/Disable coverage" OFF) option(BUILD_TESTING "Test the project" ON) option(MITK_BUILD_ALL_APPS "Build all MITK applications" OFF) set(MITK_BUILD_TUTORIAL OFF CACHE INTERNAL "Deprecated! Use MITK_BUILD_EXAMPLES instead!") option(MITK_BUILD_EXAMPLES "Build the MITK Examples" ${MITK_BUILD_TUTORIAL}) option(MITK_USE_Boost "Use the Boost C++ library" OFF) option(MITK_USE_BLUEBERRY "Build the BlueBerry platform" ON) option(MITK_USE_CTK "Use CTK in MITK" ${MITK_USE_BLUEBERRY}) option(MITK_USE_QT "Use Nokia's Qt library" ${MITK_USE_CTK}) option(MITK_USE_DCMTK "EXPERIMENTAL, superbuild only: Use DCMTK in MITK" ${MITK_USE_CTK}) option(MITK_DCMTK_BUILD_SHARED_LIBS "EXPERIMENTAL, superbuild only: build DCMTK as shared libs" OFF) option(MITK_USE_OpenCV "Use Intel's OpenCV library" OFF) option(MITK_USE_OpenCL "Use OpenCL GPU-Computing library" OFF) +option(MITK_USE_SOFA "Use Simulation Open Framework Architecture" OFF) option(MITK_USE_Python "Use Python wrapping in MITK" OFF) set(MITK_USE_CableSwig ${MITK_USE_Python}) mark_as_advanced(MITK_BUILD_ALL_APPS MITK_USE_CTK MITK_USE_DCMTK ) if(MITK_USE_Boost) option(MITK_USE_SYSTEM_Boost "Use the system Boost" OFF) set(MITK_USE_Boost_LIBRARIES "" CACHE STRING "A semi-colon separated list of required Boost libraries") endif() if(MITK_USE_BLUEBERRY) option(MITK_BUILD_ALL_PLUGINS "Build all MITK plugins" OFF) mark_as_advanced(MITK_BUILD_ALL_PLUGINS) if(NOT MITK_USE_CTK) message("Forcing MITK_USE_CTK to ON because of MITK_USE_BLUEBERRY") set(MITK_USE_CTK ON CACHE BOOL "Use CTK in MITK" FORCE) endif() endif() if(MITK_USE_CTK) if(NOT MITK_USE_QT) message("Forcing MITK_USE_QT to ON because of MITK_USE_CTK") set(MITK_USE_QT ON CACHE BOOL "Use Nokia's Qt library in MITK" FORCE) endif() if(NOT MITK_USE_DCMTK) message("Setting MITK_USE_DCMTK to ON because DCMTK needs to be build for CTK") set(MITK_USE_DCMTK ON CACHE BOOL "Use DCMTK in MITK" FORCE) endif() endif() if(MITK_USE_QT) # find the package at the very beginning, so that QT4_FOUND is available find_package(Qt4 4.6.2 REQUIRED) endif() # Customize the default pixel types for multiplex macros set(MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES "int, unsigned int, short, unsigned short, char, unsigned char" CACHE STRING "List of integral pixel types used in AccessByItk and InstantiateAccessFunction macros") set(MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES "double, float" CACHE STRING "List of floating pixel types used in AccessByItk and InstantiateAccessFunction macros") set(MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES "itk::RGBPixel, itk::RGBAPixel" CACHE STRING "List of composite pixel types used in AccessByItk and InstantiateAccessFunction macros") set(MITK_ACCESSBYITK_DIMENSIONS "2,3" CACHE STRING "List of dimensions used in AccessByItk and InstantiateAccessFunction macros") mark_as_advanced(MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES MITK_ACCESSBYITK_DIMENSIONS ) # consistency checks if(NOT MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES) set(MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES "int, unsigned int, short, unsigned short, char, unsigned char" CACHE STRING "List of integral pixel types used in AccessByItk and InstantiateAccessFunction macros" FORCE) endif() if(NOT MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES) set(MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES "double, float" CACHE STRING "List of floating pixel types used in AccessByItk and InstantiateAccessFunction macros" FORCE) endif() if(NOT MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES) set(MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES "itk::RGBPixel, itk::RGBAPixel" CACHE STRING "List of composite pixel types used in AccessByItk and InstantiateAccessFunction macros" FORCE) endif() if(NOT MITK_ACCESSBYITK_DIMENSIONS) set(MITK_ACCESSBYITK_DIMENSIONS "2,3" CACHE STRING "List of dimensions used in AccessByItk and InstantiateAccessFunction macros") endif() #----------------------------------------------------------------------------- # Additional CXX/C Flags #----------------------------------------------------------------------------- set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags") mark_as_advanced(ADDITIONAL_C_FLAGS) set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags") mark_as_advanced(ADDITIONAL_CXX_FLAGS) #----------------------------------------------------------------------------- # Project.xml #----------------------------------------------------------------------------- # A list of topologically ordered targets set(CTEST_PROJECT_SUBPROJECTS) if(MITK_USE_BLUEBERRY) list(APPEND CTEST_PROJECT_SUBPROJECTS BlueBerry) endif() list(APPEND CTEST_PROJECT_SUBPROJECTS MITK-Core MITK-CoreUI MITK-IGT MITK-ToF MITK-DTI MITK-Registration MITK-Modules # all modules not contained in a specific subproject MITK-Plugins # all plugins not contained in a specific subproject MITK-Examples Unlabeled # special "subproject" catching all unlabeled targets and tests ) # Configure CTestConfigSubProject.cmake that could be used by CTest scripts configure_file(${MITK_SOURCE_DIR}/CTestConfigSubProject.cmake.in ${MITK_BINARY_DIR}/CTestConfigSubProject.cmake) if(CTEST_PROJECT_ADDITIONAL_TARGETS) # those targets will be executed at the end of the ctest driver script # and they also get their own subproject label set(subproject_list "${CTEST_PROJECT_SUBPROJECTS};${CTEST_PROJECT_ADDITIONAL_TARGETS}") else() set(subproject_list "${CTEST_PROJECT_SUBPROJECTS}") endif() # Generate Project.xml file expected by the CTest driver script mitkFunctionGenerateProjectXml(${MITK_BINARY_DIR} MITK "${subproject_list}" ${MITK_USE_SUPERBUILD}) #----------------------------------------------------------------------------- # Superbuild script #----------------------------------------------------------------------------- if(MITK_USE_SUPERBUILD) include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake") return() endif() #***************************************************************************** #**************************** END OF SUPERBUILD **************************** #***************************************************************************** #----------------------------------------------------------------------------- # CMake function(s) and macro(s) #----------------------------------------------------------------------------- include(CheckCXXSourceCompiles) include(mitkFunctionCheckCompilerFlags) include(mitkFunctionGetGccVersion) include(MacroParseArguments) include(mitkFunctionSuppressWarnings) # includes several functions include(mitkFunctionOrganizeSources) include(mitkFunctionGetVersion) include(mitkFunctionGetVersionDescription) include(mitkFunctionCreateWindowsBatchScript) include(mitkFunctionInstallProvisioningFiles) include(mitkFunctionInstallAutoLoadModules) include(mitkFunctionCompileSnippets) include(mitkMacroCreateModuleConf) include(mitkMacroCreateModule) include(mitkMacroCheckModule) include(mitkMacroCreateModuleTests) include(mitkFunctionAddCustomModuleTest) include(mitkMacroUseModule) include(mitkMacroMultiplexPicType) include(mitkMacroInstall) include(mitkMacroInstallHelperApp) include(mitkMacroInstallTargets) include(mitkMacroGenerateToolsLibrary) include(mitkMacroGetLinuxDistribution) #----------------------------------------------------------------------------- # Prerequesites #----------------------------------------------------------------------------- find_package(ITK REQUIRED) find_package(VTK REQUIRED) if(ITK_USE_SYSTEM_GDCM) find_package(GDCM PATHS ${ITK_GDCM_DIR} REQUIRED) endif() #----------------------------------------------------------------------------- # Set MITK specific options and variables (NOT available during superbuild) #----------------------------------------------------------------------------- # ASK THE USER TO SHOW THE CONSOLE WINDOW FOR CoreApp and mitkWorkbench option(MITK_SHOW_CONSOLE_WINDOW "Use this to enable or disable the console window when starting MITK GUI Applications" ON) mark_as_advanced(MITK_SHOW_CONSOLE_WINDOW) # TODO: check if necessary option(USE_ITKZLIB "Use the ITK zlib for pic compression." ON) mark_as_advanced(USE_ITKZLIB) if(NOT MITK_FAST_TESTING) if(DEFINED MITK_CTEST_SCRIPT_MODE AND (MITK_CTEST_SCRIPT_MODE STREQUAL "continuous" OR MITK_CTEST_SCRIPT_MODE STREQUAL "experimental") ) set(MITK_FAST_TESTING 1) endif() endif() #----------------------------------------------------------------------------- # Get MITK version info #----------------------------------------------------------------------------- mitkFunctionGetVersion(${MITK_SOURCE_DIR} MITK) mitkFunctionGetVersionDescription(${MITK_SOURCE_DIR} MITK) #----------------------------------------------------------------------------- # Installation preparation # # These should be set before any MITK install macros are used #----------------------------------------------------------------------------- # on Mac OSX all BlueBerry plugins get copied into every # application bundle (.app directory) specified here if(MITK_USE_BLUEBERRY AND APPLE) include("${CMAKE_CURRENT_SOURCE_DIR}/Applications/AppList.cmake") foreach(mitk_app ${MITK_APPS}) # extract option_name string(REPLACE "^^" "\\;" target_info ${mitk_app}) set(target_info_list ${target_info}) list(GET target_info_list 1 option_name) list(GET target_info_list 0 app_name) # check if the application is enabled if(${option_name} OR MITK_BUILD_ALL_APPS) set(MACOSX_BUNDLE_NAMES ${MACOSX_BUNDLE_NAMES} ${app_name}) endif() endforeach() endif() #----------------------------------------------------------------------------- # Set symbol visibility Flags #----------------------------------------------------------------------------- # MinGW does not export all symbols automatically, so no need to set flags if(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW) set(VISIBILITY_CXX_FLAGS ) #"-fvisibility=hidden -fvisibility-inlines-hidden") endif() #----------------------------------------------------------------------------- # Set coverage Flags #----------------------------------------------------------------------------- if(WITH_COVERAGE) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG") set(COVERAGE_CXX_FLAGS ${coverage_flags}) set(COVERAGE_C_FLAGS ${coverage_flags}) endif() endif() #----------------------------------------------------------------------------- # MITK C/CXX Flags #----------------------------------------------------------------------------- set(MITK_C_FLAGS "${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}") set(MITK_CXX_FLAGS "${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}") include(mitkSetupC++0xVariables) set(cflags ) if(WIN32) set(cflags "${cflags} -DPOCO_NO_UNWINDOWS -DWIN32_LEAN_AND_MEAN") endif() if(CMAKE_COMPILER_IS_GNUCXX) set(cflags "${cflags} -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings") mitkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags) mitkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags) mitkFunctionCheckCompilerFlags("-Wl,--as-needed" cflags) if(MITK_USE_C++0x) mitkFunctionCheckCompilerFlags("-std=c++0x" MITK_CXX_FLAGS) endif() mitkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION) # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag. # Doing so should allow to build package made for distribution using older linux distro. if(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0")) mitkFunctionCheckCompilerFlags("-fstack-protector-all" cflags) endif() if(MINGW) # suppress warnings about auto imported symbols set(MITK_CXX_FLAGS "-Wl,--enable-auto-import ${MITK_CXX_FLAGS}") # we need to define a Windows version set(MITK_CXX_FLAGS "-D_WIN32_WINNT=0x0500 ${MITK_CXX_FLAGS}") endif() #set(MITK_CXX_FLAGS "-Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${MITK_CXX_FLAGS}") set(MITK_CXX_FLAGS "-Woverloaded-virtual -Wstrict-null-sentinel ${MITK_CXX_FLAGS}") set(MITK_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2 ${MITK_CXX_FLAGS_RELEASE}") endif() set(MITK_C_FLAGS "${cflags} ${MITK_C_FLAGS}") set(MITK_CXX_FLAGS "${cflags} ${MITK_CXX_FLAGS}") #----------------------------------------------------------------------------- # MITK Packages #----------------------------------------------------------------------------- set(MITK_MODULES_PACKAGE_DEPENDS_DIR ${MITK_SOURCE_DIR}/CMake/PackageDepends) set(MODULES_PACKAGE_DEPENDS_DIRS ${MITK_MODULES_PACKAGE_DEPENDS_DIR}) #----------------------------------------------------------------------------- # Testing #----------------------------------------------------------------------------- if(BUILD_TESTING) enable_testing() include(CTest) mark_as_advanced(TCL_TCLSH DART_ROOT) option(MITK_ENABLE_GUI_TESTING OFF "Enable the MITK GUI tests") # Setup file for setting custom ctest vars configure_file( CMake/CTestCustom.cmake.in ${MITK_BINARY_DIR}/CTestCustom.cmake @ONLY ) # Configuration for the CMake-generated test driver set(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include ") set(CMAKE_TESTDRIVER_BEFORE_TESTMAIN " try {") set(CMAKE_TESTDRIVER_AFTER_TESTMAIN " } catch( std::exception & excp ) { fprintf(stderr,\"%s\\n\",excp.what()); return EXIT_FAILURE; } catch( ... ) { printf(\"Exception caught in the test driver\\n\"); return EXIT_FAILURE; } ") set(MITK_TEST_OUTPUT_DIR "${MITK_BINARY_DIR}/test_output") if(NOT EXISTS ${MITK_TEST_OUTPUT_DIR}) file(MAKE_DIRECTORY ${MITK_TEST_OUTPUT_DIR}) endif() # Test the external project template if(MITK_USE_BLUEBERRY) include(mitkTestProjectTemplate) endif() # Test the package target include(mitkPackageTest) endif() configure_file(mitkTestingConfig.h.in ${MITK_BINARY_DIR}/mitkTestingConfig.h) #----------------------------------------------------------------------------- # MITK_SUPERBUILD_BINARY_DIR #----------------------------------------------------------------------------- # If MITK_SUPERBUILD_BINARY_DIR isn't defined, it means MITK is *NOT* build using Superbuild. # In that specific case, MITK_SUPERBUILD_BINARY_DIR should default to MITK_BINARY_DIR if(NOT DEFINED MITK_SUPERBUILD_BINARY_DIR) set(MITK_SUPERBUILD_BINARY_DIR ${MITK_BINARY_DIR}) endif() #----------------------------------------------------------------------------- # Compile Utilities and set-up MITK variables #----------------------------------------------------------------------------- include(mitkSetupVariables) #----------------------------------------------------------------------------- # Cleanup #----------------------------------------------------------------------------- file(GLOB _MODULES_CONF_FILES ${PROJECT_BINARY_DIR}/${MODULES_CONF_DIRNAME}/*.cmake) if(_MODULES_CONF_FILES) file(REMOVE ${_MODULES_CONF_FILES}) endif() add_subdirectory(Utilities) if(MITK_USE_BLUEBERRY) # We need to hack a little bit because MITK applications may need # to enable certain BlueBerry plug-ins. However, these plug-ins # are validated separately from the MITK plug-ins and know nothing # about potential MITK plug-in dependencies of the applications. Hence # we cannot pass the MITK application list to the BlueBerry # ctkMacroSetupPlugins call but need to extract the BlueBerry dependencies # from the applications and set them explicitly. include("${CMAKE_CURRENT_SOURCE_DIR}/Applications/AppList.cmake") foreach(mitk_app ${MITK_APPS}) # extract target_dir and option_name string(REPLACE "^^" "\\;" target_info ${mitk_app}) set(target_info_list ${target_info}) list(GET target_info_list 0 target_dir) list(GET target_info_list 1 option_name) # check if the application is enabled and if target_libraries.cmake exists if((${option_name} OR MITK_BUILD_ALL_APPS) AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${target_dir}/target_libraries.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/Applications/${target_dir}/target_libraries.cmake") foreach(_target_dep ${target_libraries}) if(_target_dep MATCHES org_blueberry_) string(REPLACE _ . _app_bb_dep ${_target_dep}) # explicitly set the build option for the BlueBerry plug-in set(BLUEBERRY_BUILD_${_app_bb_dep} ON CACHE BOOL "Build the ${_app_bb_dep} plug-in") endif() endforeach() endif() endforeach() set(mbilog_DIR "${mbilog_BINARY_DIR}") if(MITK_BUILD_ALL_PLUGINS) set(BLUEBERRY_BUILD_ALL_PLUGINS ON) endif() add_subdirectory(BlueBerry) set(BlueBerry_DIR ${CMAKE_CURRENT_BINARY_DIR}/BlueBerry CACHE PATH "The directory containing a CMake configuration file for BlueBerry" FORCE) include(mitkMacroCreateCTKPlugin) endif() #----------------------------------------------------------------------------- # Set C/CXX Flags for MITK code #----------------------------------------------------------------------------- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MITK_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MITK_CXX_FLAGS_RELEASE}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MITK_C_FLAGS}") if(MITK_USE_QT) add_definitions(-DQWT_DLL) endif() #----------------------------------------------------------------------------- # Add custom targets representing CDash subprojects #----------------------------------------------------------------------------- foreach(subproject ${CTEST_PROJECT_SUBPROJECTS}) if(NOT TARGET ${subproject} AND NOT subproject MATCHES "Unlabeled") add_custom_target(${subproject}) endif() endforeach() #----------------------------------------------------------------------------- # Add subdirectories #----------------------------------------------------------------------------- link_directories(${MITK_LINK_DIRECTORIES}) add_subdirectory(Core) add_subdirectory(Modules) if(MITK_USE_BLUEBERRY) find_package(BlueBerry REQUIRED) set(MITK_DEFAULT_SUBPROJECTS MITK-Plugins) # Plug-in testing (needs some work to be enabled again) if(BUILD_TESTING) include(berryTestingHelpers) set(BLUEBERRY_UI_TEST_APP "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CoreApp") get_target_property(_is_macosx_bundle CoreApp MACOSX_BUNDLE) if(APPLE AND _is_macosx_bundle) set(BLUEBERRY_UI_TEST_APP "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CoreApp.app/Contents/MacOS/CoreApp") endif() set(BLUEBERRY_TEST_APP_ID "org.mitk.qt.coreapplication") endif() include("${CMAKE_CURRENT_SOURCE_DIR}/Plugins/PluginList.cmake") set(mitk_plugins_fullpath ) foreach(mitk_plugin ${MITK_EXT_PLUGINS}) list(APPEND mitk_plugins_fullpath Plugins/${mitk_plugin}) endforeach() if(EXISTS ${MITK_PRIVATE_MODULES}/PluginList.cmake) include(${MITK_PRIVATE_MODULES}/PluginList.cmake) foreach(mitk_plugin ${MITK_PRIVATE_PLUGINS}) list(APPEND mitk_plugins_fullpath ${MITK_PRIVATE_MODULES}/${mitk_plugin}) endforeach() endif() # Specify which plug-ins belong to this project macro(GetMyTargetLibraries all_target_libraries varname) set(re_ctkplugin_mitk "^org_mitk_[a-zA-Z0-9_]+$") set(re_ctkplugin_bb "^org_blueberry_[a-zA-Z0-9_]+$") set(_tmp_list) list(APPEND _tmp_list ${all_target_libraries}) ctkMacroListFilter(_tmp_list re_ctkplugin_mitk re_ctkplugin_bb OUTPUT_VARIABLE ${varname}) endmacro() # Get infos about application directories and build options include("${CMAKE_CURRENT_SOURCE_DIR}/Applications/AppList.cmake") set(mitk_apps_fullpath ) foreach(mitk_app ${MITK_APPS}) list(APPEND mitk_apps_fullpath "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${mitk_app}") endforeach() ctkMacroSetupPlugins(${mitk_plugins_fullpath} BUILD_OPTION_PREFIX MITK_BUILD_ APPS ${mitk_apps_fullpath} BUILD_ALL ${MITK_BUILD_ALL_PLUGINS} COMPACT_OPTIONS) set(MITK_PLUGIN_USE_FILE "${MITK_BINARY_DIR}/MitkPluginUseFile.cmake") if(${PROJECT_NAME}_PLUGIN_LIBRARIES) ctkFunctionGeneratePluginUseFile(${MITK_PLUGIN_USE_FILE}) else() file(REMOVE ${MITK_PLUGIN_USE_FILE}) set(MITK_PLUGIN_USE_FILE ) endif() endif() # Construct a list of paths containing runtime directories # for MITK applications on Windows set(MITK_RUNTIME_PATH "${VTK_LIBRARY_DIRS}/%VS_BUILD_TYPE%;${ITK_LIBRARY_DIRS}/%VS_BUILD_TYPE%;${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/%VS_BUILD_TYPE%" ) if(QT4_FOUND) set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${QT_LIBRARY_DIR}/../bin") endif() if(MITK_USE_BLUEBERRY) set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${CTK_RUNTIME_LIBRARY_DIRS}/%VS_BUILD_TYPE%") if(DEFINED CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY) if(IS_ABSOLUTE "${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}") set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}/%VS_BUILD_TYPE%") else() set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}/%VS_BUILD_TYPE%") endif() else() set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plugins/%VS_BUILD_TYPE%") endif() endif() if(GDCM_DIR) set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${GDCM_DIR}/bin/%VS_BUILD_TYPE%") endif() if(OpenCV_DIR) set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${OpenCV_DIR}/bin/%VS_BUILD_TYPE%") endif() +if(SOFA_DIR) + set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${SOFA_DIR}/bin/%VS_BUILD_TYPE%") +endif() + # DCMTK is statically build #if(DCMTK_DIR) # set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${DCMTK_DIR}/bin/%VS_BUILD_TYPE%") #endif() if(MITK_USE_Boost AND MITK_USE_Boost_LIBRARIES AND NOT MITK_USE_SYSTEM_Boost) set(MITK_RUNTIME_PATH "${MITK_RUNTIME_PATH};${Boost_LIBRARY_DIRS}") endif() #----------------------------------------------------------------------------- # Python Wrapping #----------------------------------------------------------------------------- set(MITK_WRAPPING_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Wrapping) set(MITK_WRAPPING_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Wrapping) option(MITK_USE_Python "Build cswig Python wrapper support (requires CableSwig)." OFF) if(MITK_USE_Python) add_subdirectory(Wrapping) endif() #----------------------------------------------------------------------------- # Documentation #----------------------------------------------------------------------------- add_subdirectory(Documentation) #----------------------------------------------------------------------------- # Installation #----------------------------------------------------------------------------- # set MITK cpack variables # These are the default variables, which can be overwritten ( see below ) include(mitkSetupCPack) set(use_default_config ON) # MITK_APPS is set in Applications/AppList.cmake (included somewhere above # if MITK_USE_BLUEBERRY is set to ON). if(MITK_APPS) set(activated_apps_no 0) list(LENGTH MITK_APPS app_count) # Check how many apps have been enabled # If more than one app has been activated, the we use the # default CPack configuration. Otherwise that apps configuration # will be used, if present. foreach(mitk_app ${MITK_APPS}) # extract option_name string(REPLACE "^^" "\\;" target_info ${mitk_app}) set(target_info_list ${target_info}) list(GET target_info_list 1 option_name) # check if the application is enabled if(${option_name} OR MITK_BUILD_ALL_APPS) MATH(EXPR activated_apps_no "${activated_apps_no} + 1") endif() endforeach() if(app_count EQUAL 1 AND (activated_apps_no EQUAL 1 OR MITK_BUILD_ALL_APPS)) # Corner case if there is only one app in total set(use_project_cpack ON) elseif(activated_apps_no EQUAL 1 AND NOT MITK_BUILD_ALL_APPS) # Only one app is enabled (no "build all" flag set) set(use_project_cpack ON) else() # Less or more then one app is enabled set(use_project_cpack OFF) endif() foreach(mitk_app ${MITK_APPS}) # extract target_dir and option_name string(REPLACE "^^" "\\;" target_info ${mitk_app}) set(target_info_list ${target_info}) list(GET target_info_list 0 target_dir) list(GET target_info_list 1 option_name) # check if the application is enabled if(${option_name} OR MITK_BUILD_ALL_APPS) # check whether application specific configuration files will be used if(use_project_cpack) # use files if they exist if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${target_dir}/CPackOptions.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/Applications/${target_dir}/CPackOptions.cmake") endif() if(EXISTS "${PROJECT_SOURCE_DIR}/Applications/${target_dir}/CPackConfig.cmake.in") set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/Applications/${target_dir}/CPackConfig.cmake") configure_file(${PROJECT_SOURCE_DIR}/Applications/${target_dir}/CPackConfig.cmake.in ${CPACK_PROJECT_CONFIG_FILE} @ONLY) set(use_default_config OFF) endif() endif() # add link to the list list(APPEND CPACK_CREATE_DESKTOP_LINKS "${target_dir}") endif() endforeach() endif() # if no application specific configuration file was used, use default if(use_default_config) configure_file(${MITK_SOURCE_DIR}/MITKCPackOptions.cmake.in ${MITK_BINARY_DIR}/MITKCPackOptions.cmake @ONLY) set(CPACK_PROJECT_CONFIG_FILE "${MITK_BINARY_DIR}/MITKCPackOptions.cmake") endif() # include CPack model once all variables are set include(CPack) # Additional installation rules include(mitkInstallRules) #----------------------------------------------------------------------------- # Last configuration steps #----------------------------------------------------------------------------- # This is for installation support of external projects depending on # MITK plugins and modules. The export file should not be used for linking to MITK # libraries without using LINK_DIRECTORIES, since the exports are incomplete # yet (depending libraries are not exported). set(MITK_EXPORTS_FILE "${MITK_BINARY_DIR}/MitkExports.cmake") file(REMOVE ${MITK_EXPORTS_FILE}) set(targets_to_export) get_property(module_targets GLOBAL PROPERTY MITK_MODULE_TARGETS) if(module_targets) list(APPEND targets_to_export ${module_targets}) endif() if(MITK_USE_BLUEBERRY) if(MITK_PLUGIN_LIBRARIES) list(APPEND targets_to_export ${MITK_PLUGIN_LIBRARIES}) endif() endif() export(TARGETS ${targets_to_export} APPEND FILE ${MITK_EXPORTS_FILE}) set(MITK_EXPORTED_TARGET_PROPERTIES ) foreach(target_to_export ${targets_to_export}) get_target_property(autoload_targets ${target_to_export} MITK_AUTOLOAD_TARGETS) if(autoload_targets) set(MITK_EXPORTED_TARGET_PROPERTIES "${MITK_EXPORTED_TARGET_PROPERTIES} set_target_properties(${target_to_export} PROPERTIES MITK_AUTOLOAD_TARGETS \"${autoload_targets}\")") endif() get_target_property(autoload_dir ${target_to_export} MITK_AUTOLOAD_DIRECTORY) if(autoload_dir) set(MITK_EXPORTED_TARGET_PROPERTIES "${MITK_EXPORTED_TARGET_PROPERTIES} set_target_properties(${target_to_export} PROPERTIES MITK_AUTOLOAD_DIRECTORY \"${autoload_dir}\")") endif() endforeach() configure_file(${MITK_SOURCE_DIR}/CMake/ToolExtensionITKFactory.cpp.in ${MITK_BINARY_DIR}/ToolExtensionITKFactory.cpp.in COPYONLY) configure_file(${MITK_SOURCE_DIR}/CMake/ToolExtensionITKFactoryLoader.cpp.in ${MITK_BINARY_DIR}/ToolExtensionITKFactoryLoader.cpp.in COPYONLY) configure_file(${MITK_SOURCE_DIR}/CMake/ToolGUIExtensionITKFactory.cpp.in ${MITK_BINARY_DIR}/ToolGUIExtensionITKFactory.cpp.in COPYONLY) set(VISIBILITY_AVAILABLE 0) set(visibility_test_flag "") mitkFunctionCheckCompilerFlags("-fvisibility=hidden" visibility_test_flag) if(visibility_test_flag) # The compiler understands -fvisiblity=hidden (probably gcc >= 4 or Clang) set(VISIBILITY_AVAILABLE 1) endif() configure_file(mitkExportMacros.h.in ${MITK_BINARY_DIR}/mitkExportMacros.h) configure_file(mitkVersion.h.in ${MITK_BINARY_DIR}/mitkVersion.h) configure_file(mitkConfig.h.in ${MITK_BINARY_DIR}/mitkConfig.h) set(VECMATH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/vecmath) set(IPFUNC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/ipFunc) set(UTILITIES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities) file(GLOB _MODULES_CONF_FILES RELATIVE ${PROJECT_BINARY_DIR}/${MODULES_CONF_DIRNAME} ${PROJECT_BINARY_DIR}/${MODULES_CONF_DIRNAME}/*.cmake) set(MITK_MODULE_NAMES) foreach(_module ${_MODULES_CONF_FILES}) string(REPLACE Config.cmake "" _module_name ${_module}) list(APPEND MITK_MODULE_NAMES ${_module_name}) endforeach() configure_file(mitkConfig.h.in ${MITK_BINARY_DIR}/mitkConfig.h) configure_file(MITKConfig.cmake.in ${MITK_BINARY_DIR}/MITKConfig.cmake @ONLY) # If we are under Windows, create two batch files which correctly # set up the environment for the application and for Visual Studio if(WIN32) include(mitkFunctionCreateWindowsBatchScript) set(VS_SOLUTION_FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.sln") foreach(VS_BUILD_TYPE debug release) mitkFunctionCreateWindowsBatchScript("${MITK_SOURCE_DIR}/CMake/StartVS.bat.in" ${PROJECT_BINARY_DIR}/StartVS_${VS_BUILD_TYPE}.bat ${VS_BUILD_TYPE}) endforeach() endif(WIN32) #----------------------------------------------------------------------------- # MITK Applications #----------------------------------------------------------------------------- # This must come after MITKConfig.h was generated, since applications # might do a find_package(MITK REQUIRED). add_subdirectory(Applications) #----------------------------------------------------------------------------- # MITK Examples #----------------------------------------------------------------------------- if(MITK_BUILD_EXAMPLES) # This must come after MITKConfig.h was generated, since applications # might do a find_package(MITK REQUIRED). add_subdirectory(Examples) endif() diff --git a/Documentation/Doxygen/DeveloperManual/BuildInstructions.dox b/Documentation/Doxygen/DeveloperManual/BuildInstructions.dox index bb17b3b64a..785b8ad672 100644 --- a/Documentation/Doxygen/DeveloperManual/BuildInstructions.dox +++ b/Documentation/Doxygen/DeveloperManual/BuildInstructions.dox @@ -1,201 +1,203 @@ /** \page BuildInstructionsPage Build Instructions \section BuildInstructions_Introduction Introduction The MITK build system (which is based on CMake) supports a "superbuild" process, meaning that it will download, configure, and build all required third-party libraries (except Qt) automatically. These instructions will show you how to use the MITK superbuild. \note This page explains explicitly how to build MITK itself. If you want to create your own project based on MITK, the process described below is completely automated. Please see \ref HowToNewProject. For more advanced users, the last sections explain how to inject custom build libraries into the superbuild process. \section BuildInstructions_Prerequisites Prerequisites You need: -# Git from http://git-scm.com (there are also numerous third-party graphical clients available). We recomment using Git, but see below for a way how to get the current source code without using it. -# CMake (version 2.8.4 or higher) -# Qt 4.x if you plan to develop Qt-based applications (version 4.6 or above is recommended, we cannot guarantee compatibility with lower versions) -# If you are using Mac OS X you need an Xcode installation as this provides the neccessary compilers and SDKs \attention For Mac OS X it is strongly recommended to use CMake version 2.8.8 or higher \section BuildInstructions_Qt A note about Qt Nokia provides several binary packages for Qt. You must make sure that the package you download matches your toolchain. On Linux, getting Qt by installing the packages provided by your Linux package manager is the preferred way. On Windows, the Nokia provided binaries are compiled for 32bit architectures. You cannot build your own project for a 64bit machine and use the 32bit Qt libraries. You have two options for a 64bit Qt-based application: -# Download an inofficial 64bit installer, for example here. Note that we cannot offer support for problems with MITK due to the usage of this kind of installers. -# Compile Qt yourself. This is shortly described below. To compile Qt on Windows using Visual Studio, follow the steps below: -# Download the Qt sources and unpack them, e.g. to C:/qt-everywhere-opensource-src-4.7.4 -# Open a Visual Studio command prompt. Make sure to use the appropriate command prompt for either a 32 bit or 64 bit build. Note that Visual Studio Express does not come with 64bit compilers out of the box (the Professional version does). -# Configure Qt by executing the configure.exe command in your Qt source directory. The following configure options will build a Qt compatible with MITK: \verbatim configure.exe -prefix C:\Qt\4.7.4_vc9_x64 -debug-and-release -qt-sql-sqlite -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-declarative -mp -nomake examples -nomake demos -nomake docs \endverbatim -# Build and install the Qt libraries \verbatim nmake nmake install \endverbatim After "nmake install" completed successfully, you may delete your Qt source directory. \section BuildInstructions_Get_Source Get a source tree Since MITK is under active development we recommend to use git to get the most recent version. To make sure you get a stable tree, check the MITK dashboard before checking out. If the build tree is not clean, you can specify an older revision for the checkout or get a stable tar ball from www.mitk.org. If you don't want to use Git, you may also download the current source code (or any other older version) as a tar.gz package by clicking on the snapshot link. You can then skip the clone step below. To clone MITK's current git repository do: \code git clone http://git.mitk.org/MITK.git \endcode \section BuildInstructions_Build_With_CMake Build MITK with CMake Create a new directory for the superbuild binary tree, change to it and call CMake: In the shell (assuming you current directory is the same as the one where you issued the git clone command): \code mkdir MITK-superbuild cd MITK-superbuild ccmake ../MITK \endcode If you use Windows, then you just start the CMake GUI and enter the location of the source and of the binary tree, choose a suitable generator and configure the project. If you use Mac OS X you will have to tweak the CMake configuration: - First of all you have to check the selected compilers, i.e.: - CMAKE_CXX_COMPILER - CMAKE_C_COMPILER - both should be either apple's clang or apple's gcc compiler - Next you have to assure hat CMAKE_OSX_SYSROOT points to the correct SDK location: - This is either /Developer/SDKs/Developer/SDKs/MacOSX10.7.sdk or if you have installed Xcode 4.3+ it is located in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/ - Finally you should set the cmake variable MITK_USE_VTK_5_8_IN_SUPERBUILD to ON CMake will present you a couple of options, these are the most important ones: - MITK_USE_BLUEBERRY Build the BlueBerry application framework - MITK_USE_Boost Build MITK code which depends on Boost (this will download Boost 1.45.0) - MITK_USE_Boost_LIBRARIES If you need binary Boost libraries, specify them here. - MITK_USE_OpenCV Build MITK code which depends on OpenCV (this will download and build OpenCV 2.3) - MITK_USE_Python Enables Python wrapping in MITK. This will also configure ITK, VTK, and OpenCV (if enabled) to build Python wrappers. - MITK_USE_QT Build MITK code which depends on Qt + - MITK_USE_SOFA Build MITK code which depends on SOFA (this will download and build SOFA 1.0 RC1) - QT_QMAKE_EXECUTABLE The path to the qmake executable of your Qt installation If you are satisfied with the configuration of your MITK superbuild, generate the project files with CMake by pressing "Generate". Linux and Mac OS X users usually just enter "make" (optionally supplying the number threads to be used for a parallel build): \code make -j4 \endcode \note On Mac OS X: If you follow these steps CMake will produce Makefiles and therefore you cannot use Xcode but you have to use e.g. the QtCreator for programming. At the moment developing MITK with Xcode is not supported and using Xcode the superbuild doesn't complete without errors. Windows users using Visual Studio can open the generated MITK-superbuild.sln solution file in the MITK-superbuild directory and start the build by building the BUILD_ALL project. \section BuildInstructions_Customize Customize your MITK superbuild The MITK superbuild configured MITK with all needed external libraries. The build directories of these libraries, and of MITK itself are located inside the MITK-superbuild directory. For example, the directory layout may look like: \code MITK-superbuild |- ITK-build |- VTK-build |- MITK-build \endcode To change the configuration of the MITK build, choose the MITK-build directory as the binary directory in the CMake GUI. After generating the project files, build the MITK project by either issuing "make" in the MITK-build directory (Linux), or by opening MITK-build/MITK.sln and building the project with Visual Studio. You may also change the configuration of any project configured via the superbuild process. Make sure to also build the changed project and also the projects which depend on it. \section BuildInstructions_Running Running Applications On Linux, just execute the application you want to run. MITK executables are located in MITK-superbuild/MITK-build/bin On Windows, the PATH environment variable must contain the directories containging third-party libraries. The MITK build system generated Windows Batch files in the MITK-build directory which set up a correct environment and opens the appropriate Visual Studio solution file. Use (and maybe modify/enhance) these Batch files to be able to start and debug MITK applications from inside Visual Studio. \section BuildInstructions_Documentation Documentation If you have the Doxygen documentation tool installed, you get a new project (Visual Studio) or "make" target named "doc". You can build this to generate the HTML documentation of MITK in the Documentation/Doxygen directory of your MITK-build binary tree or in the MITK_DOXYGEN_OUTPUT_DIR CMake variable (if specified). \section BuildInstructions_Extending Extend MITK on your own (using the application framework BlueBerry) Please see \ref NewPluginPage \section BuildInstructions_As_Toolkit Use MITK in your own project (as a toolkit) To use MITK in your external project, add the CMake command find_package(MITK REQUIRED) to your CMakeLists.txt and make use of the CMake macros MITK_CHECK_MODULE(result_var ) and MITK_USE_MODULE() provided by MITK. Here is an example CMakeLists.txt (from the Examples/QtAppExample/ directory) which allows you to create a Qt based application using MITK to display an image. \include QtAppExample/CMakeLists.txt \section BuildInstructions_Advanced_Customization Superbuild Customization You can inject pre-build third-party libraries into the MITK superbuild by setting certain CMake variables before the first configure step. MITK will then use these third-party libraries instead of downloading and building them itself. Note you must take care to configure those libraries with all options MITK requires. The variables listed below are provided for injecting third-party libraries. Their occurrence in the CMake GUI or in ccmake may depend on specific MITK_USE_* options set to ON. You may also use the variable names below without the EXTERNAL_ prefix, for example when providing their values on a command line call to CMake. - EXTERNAL_BOOST_ROOT Set this variable to your custom Boost installation - EXTERNAL_CTK_DIR Set this variable to your CTK binary tree (the directory containing the CTKConfig.cmake file) - EXTERNAL_CableSwig_DIR Set this variable to your CableSwig binary tree for Python wrapping (the directory containing the CableSwigConfig.cmake file) - EXTERNAL_DCMTK_DIR Set this variable to your DCMTK binary tree (the directory containing the DCMTKConfig.cmake file) - EXTERNAL_GDCM_DIR Set this variable to your GDCM binary tree (the directory containing the GDCMConfig.cmake file) - EXTERNAL_ITK_DIR Set this variable to your ITK binary tree (the directory containing the ITKConfig.cmake file) - EXTERNAL_OpenCV_DIR Set this variable to your OpenCV binary tree (the directory containing the OpenCVConfig.cmake file) + - EXTERNAL_SOFA_DIR Set this variable to your SOFA binary tree (the directory containing the SOFAConfig.cmake file) - EXTERNAL_VTK_DIR Set this variable to your VTK binary tree (the directory containing the VTKConfig.cmake file) To set CMake options before the first configure step is invoked, supply them on the command line, i.e. \code ccmake -DITK_DIR:PATH=/opt/ITK-release ../MITK \endcode See the following link for more information about how to configure third-party libraries: \subpage BuildToolkits "How to build ITK, VTK and QT" */ diff --git a/Documentation/Doxygen/DeveloperManual/ThirdPartyLibs.dox b/Documentation/Doxygen/DeveloperManual/ThirdPartyLibs.dox index 9d2180deed..b5545acbba 100644 --- a/Documentation/Doxygen/DeveloperManual/ThirdPartyLibs.dox +++ b/Documentation/Doxygen/DeveloperManual/ThirdPartyLibs.dox @@ -1,73 +1,77 @@ /** \page thirdpartylibs Third-party libraries The following third-party libraries can be used with MITK by default and can, in part, be automatically downloaded during superbuild. \par Boost http://www.boost.org/ \par CTK http://www.commontk.org/ \par DCMTK http://dicom.offis.de/dcmtk.php.en \par GDCM http://gdcm.sourceforge.net/ \par KWStlye http://public.kitware.com/KWStyle/ \par ITK http://www.itk.org/ \par OpenCV http://opencv.willowgarage.com/wiki/Welcome +\par SOFA + +http://www.sofa-framework.org/ + \par Qt http://qt.nokia.com/ \par VTK http://www.vtk.org/ The following third-party libraries are distributed with MITK and used in several places. \par ANN (A Library for Approximate Nearest Neighbor Searching) http://www.cs.umd.edu/~mount/ANN/ (Version 1.1) \par GLEW (The OpenGL Extension Wrangler Library) http://glew.sourceforge.net/ (Version 1.5.1?) \par POCO (Portable Components, Basic Edition) http://pocoproject.org (Version 1.3.5) \par Qwt (Qt Widgets for Technical Applications) http://qwt.sourceforge.net/ (Version 5.2.0) \par LibQxt (the Qt eXTension library) http://www.libqxt.org/ (Version 0.5.1) \par tinyxml http://www.grinninglizard.com/tinyxml/index.html (Version 2.5.5) \par vecmath http://www.objectclub.jp/download/vecmath_e (Version 1.2-1.4) For copyright information on any of the above toolkits see the corresponding home page or the corresponding source folder. */ diff --git a/Documentation/Doxygen/UserManual/MITKModuleManualsList.dox b/Documentation/Doxygen/UserManual/MITKModuleManualsList.dox index 81677a5fea..1cd4e1e54e 100644 --- a/Documentation/Doxygen/UserManual/MITKModuleManualsList.dox +++ b/Documentation/Doxygen/UserManual/MITKModuleManualsList.dox @@ -1,19 +1,20 @@ /** \page MITKModuleManualsListPage MITK Module Manuals \section MITKModuleManualsListPageOverview Overview The modules are shared libraries that provide functionality that can be used by developers. \section MITKModuleManualsListPageModuleManualList List of Module Manuals \li \subpage IGTGeneralModulePage \li \subpage MitkOpenCL_Overview + \li \subpage SimulationManualPage \section MITKModuleManualsListPageAdditionalInformation Additional Information on Certain Modules \li \ref PlanarPropertiesPage \li \subpage DiffusionImagingPropertiesPage \li \subpage ConnectomicsRenderingPropertiesPage */ diff --git a/MITKConfig.cmake.in b/MITKConfig.cmake.in index 026107a54d..c3d18ee22b 100644 --- a/MITKConfig.cmake.in +++ b/MITKConfig.cmake.in @@ -1,148 +1,150 @@ # Update the CMake module path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "@MITK_SOURCE_DIR@/CMake") set(CppMicroServices_SOURCE_DIR @MITK_SOURCE_DIR@/Core/Code/CppMicroServices) # Include MITK macros include(MacroParseArguments) include(@CppMicroServices_SOURCE_DIR@/CMake/usFunctionGenerateModuleInit.cmake) include(mitkFunctionCheckMitkCompatibility) include(mitkFunctionOrganizeSources) include(mitkFunctionCreateWindowsBatchScript) include(mitkFunctionInstallProvisioningFiles) include(mitkFunctionInstallAutoLoadModules) include(mitkMacroCreateModuleConf) include(mitkMacroCreateModule) include(mitkMacroCheckModule) include(mitkMacroCreateModuleTests) include(mitkFunctionAddCustomModuleTest) include(mitkMacroUseModule) include(mitkMacroMultiplexPicType) include(mitkMacroInstall) include(mitkMacroInstallHelperApp) include(mitkMacroInstallTargets) include(mitkMacroGenerateToolsLibrary) include(mitkMacroCreateCTKPlugin) # The MITK version number set(MITK_VERSION_MAJOR "@MITK_VERSION_MAJOR@") set(MITK_VERSION_MINOR "@MITK_VERSION_MINOR@") set(MITK_VERSION_PATCH "@MITK_VERSION_PATCH@") set(MITK_VERSION_STRING "@MITK_VERSION_STRING@") # Internal version numbers, used for approximate compatibility checks # of a MITK development version (non-release). set(MITK_VERSION_PLUGIN_SYSTEM 2) # dropped legacy BlueBerry plug-in CMake support # MITK specific variables set(MITK_SOURCE_DIR "@MITK_SOURCE_DIR@") set(MITK_BINARY_DIR "@MITK_BINARY_DIR@") set(UTILITIES_DIR "@UTILITIES_DIR@") set(REGISTER_QFUNCTIONALITY_CPP_IN "@REGISTER_QFUNCTIONALITY_CPP_IN@") set(MITK_MODULES_PACKAGE_DEPENDS_DIR "@MITK_MODULES_PACKAGE_DEPENDS_DIR@") set(MODULES_PACKAGE_DEPENDS_DIRS "@MODULES_PACKAGE_DEPENDS_DIRS@") set(MITK_DOXYGEN_TAGFILE_NAME "@MITK_DOXYGEN_TAGFILE_NAME@") if(MODULES_CONF_DIRS) list(APPEND MODULES_CONF_DIRS "@MODULES_CONF_DIRS@") list(REMOVE_DUPLICATES MODULES_CONF_DIRS) -else() +else() set(MODULES_CONF_DIRS "@MODULES_CONF_DIRS@") endif() set(MODULES_CONF_DIRNAME "@MODULES_CONF_DIRNAME@") foreach(_module @MITK_MODULE_NAMES@) set(${_module}_CONFIG_FILE "@MITK_BINARY_DIR@/@MODULES_CONF_DIRNAME@/${_module}Config.cmake") endforeach() # Include directory variables set(MITK_INCLUDE_DIRS "@MITK_INCLUDE_DIRS@") set(QMITK_INCLUDE_DIRS "@QMITK_INCLUDE_DIRS@") set(ANN_INCLUDE_DIR "@ANN_INCLUDE_DIR@") set(IPSEGMENTATION_INCLUDE_DIR "@IPSEGMENTATION_INCLUDE_DIR@") set(VECMATH_INCLUDE_DIR "@VECMATH_INCLUDE_DIR@") set(IPFUNC_INCLUDE_DIR "@IPFUNC_INCLUDE_DIR@") set(MITK_IGT_INCLUDE_DIRS "@MITK_IGT_INCLUDE_DIRS@") # Library variables set(MITK_LIBRARIES "@MITK_LIBRARIES@") set(QMITK_LIBRARIES "@QMITK_LIBRARIES@") # Link directory variables set(MITK_LINK_DIRECTORIES "@MITK_LINK_DIRECTORIES@") set(QMITK_LINK_DIRECTORIES "@QMITK_LINK_DIRECTORIES@") set(MITK_LIBRARY_DIRS "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@" "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@/plugins") set(MITK_VTK_LIBRARY_DIRS "@MITK_VTK_LIBRARY_DIRS@") set(MITK_ITK_LIBRARY_DIRS "@MITK_ITK_LIBRARY_DIRS@") # External projects set(ITK_DIR "@ITK_DIR@") set(VTK_DIR "@VTK_DIR@") set(DCMTK_DIR "@DCMTK_DIR@") set(GDCM_DIR "@GDCM_DIR@") set(BOOST_ROOT "@BOOST_ROOT@") set(OpenCV_DIR "@OpenCV_DIR@") +set(SOFA_DIR "@SOFA_DIR@") set(MITK_QMAKE_EXECUTABLE "@QT_QMAKE_EXECUTABLE@") set(MITK_DATA_DIR "@MITK_DATA_DIR@") set(MITK_RUNTIME_PATH "@MITK_RUNTIME_PATH@") # MITK use variables set(MITK_USE_QT @MITK_USE_QT@) set(MITK_USE_BLUEBERRY @MITK_USE_BLUEBERRY@) set(MITK_USE_SYSTEM_Boost @MITK_USE_SYSTEM_Boost@) set(MITK_USE_Boost @MITK_USE_Boost@) set(MITK_USE_Boost_LIBRARIES @MITK_USE_Boost_LIBRARIES@) set(MITK_USE_CTK @MITK_USE_CTK@) set(MITK_USE_DCMTK @MITK_USE_DCMTK@) set(MITK_USE_OpenCV @MITK_USE_OpenCV@) +set(MITK_USE_SOFA @MITK_USE_SOFA@) set(MITK_USE_Python @MITK_USE_Python@) # There is no PocoConfig.cmake, so we set Poco specific CMake variables # here. This way the call to find_package(Poco) in BlueBerryConfig.cmake # finds the Poco distribution supplied by MITK set(Poco_INCLUDE_DIR "@MITK_SOURCE_DIR@/Utilities/Poco") set(Poco_LIBRARY_DIR "@MITK_BINARY_DIR@/bin") if(MITK_USE_IGT) #include(${MITK_DIR}/mitkIGTConfig.cmake) endif() if(NOT MITK_EXPORTS_FILE_INCLUDED) if(EXISTS "@MITK_EXPORTS_FILE@") set(MITK_EXPORTS_FILE_INCLUDED 1) include("@MITK_EXPORTS_FILE@") endif(EXISTS "@MITK_EXPORTS_FILE@") endif() # BlueBerry support if(MITK_USE_BLUEBERRY) set(BlueBerry_DIR "@MITK_BINARY_DIR@/BlueBerry") - + # Don't include the BlueBerry exports file, since the targets are # also exported in the MITK exports file set(BB_PLUGIN_EXPORTS_FILE_INCLUDED 1) find_package(BlueBerry) if(NOT BlueBerry_FOUND) message(SEND_ERROR "MITK does not seem to be configured with BlueBerry support. Set MITK_USE_BLUEBERRY to ON in your MITK build configuration.") endif(NOT BlueBerry_FOUND) set(MITK_PLUGIN_USE_FILE @MITK_PLUGIN_USE_FILE@) if(MITK_PLUGIN_USE_FILE) if(EXISTS ${MITK_PLUGIN_USE_FILE}) include(${MITK_PLUGIN_USE_FILE}) endif() endif() set(MITK_PLUGIN_PROVISIONING_FILE "@MITK_EXTAPP_PROVISIONING_FILE@") set(MITK_PROVISIONING_FILES "${BLUEBERRY_PLUGIN_PROVISIONING_FILE}" "${MITK_PLUGIN_PROVISIONING_FILE}") endif(MITK_USE_BLUEBERRY) # Set properties on exported targets @MITK_EXPORTED_TARGET_PROPERTIES@ diff --git a/Modules/CMakeLists.txt b/Modules/CMakeLists.txt index e7492ae6aa..632474b83d 100644 --- a/Modules/CMakeLists.txt +++ b/Modules/CMakeLists.txt @@ -1,57 +1,58 @@ set(LIBPOSTFIX "Ext") # Modules must be listed according to their dependencies set(module_dirs SceneSerializationBase PlanarFigure ImageExtraction ImageStatistics LegacyAdaptors IpPicSupport MitkExt SceneSerialization Segmentation Qmitk QmitkExt GraphAlgorithms DiffusionImaging GPGPU IGT CameraCalibration IGTUI RigidRegistration RigidRegistrationUI DeformableRegistration DeformableRegistrationUI OpenCL OpenCVVideoSupport Overlays InputDevices ToFHardware ToFProcessing ToFUI US ClippingTools USUI DicomUI + Simulation ) set(MITK_DEFAULT_SUBPROJECTS MITK-Modules) foreach(module_dir ${module_dirs}) add_subdirectory(${module_dir}) endforeach() if(MITK_PRIVATE_MODULES) file(GLOB all_subdirs RELATIVE ${MITK_PRIVATE_MODULES} ${MITK_PRIVATE_MODULES}/*) foreach(subdir ${all_subdirs}) string(FIND ${subdir} "." _result) if(_result EQUAL -1) if(EXISTS ${MITK_PRIVATE_MODULES}/${subdir}/CMakeLists.txt) message(STATUS "Found private module ${subdir}") add_subdirectory(${MITK_PRIVATE_MODULES}/${subdir} private_modules/${subdir}) endif() endif() endforeach() endif(MITK_PRIVATE_MODULES) diff --git a/Modules/Simulation/CMakeLists.txt b/Modules/Simulation/CMakeLists.txt new file mode 100644 index 0000000000..d6ebacd0fb --- /dev/null +++ b/Modules/Simulation/CMakeLists.txt @@ -0,0 +1,10 @@ +if(MITK_USE_SOFA) + MITK_CREATE_MODULE(Simulation + PACKAGE_DEPENDS SOFA + ) + + if(MSVC) + set(module_compile_flags "${module_compile_flags} /wd4250 /wd4251 /wd4275") + set_target_properties(${MODULE_PROVIDES} PROPERTIES COMPILE_FLAGS "${module_compile_flags}") + endif() +endif() diff --git a/Modules/Simulation/Documentation/doxygen/Manual.dox b/Modules/Simulation/Documentation/doxygen/Manual.dox new file mode 100644 index 0000000000..283292abf0 --- /dev/null +++ b/Modules/Simulation/Documentation/doxygen/Manual.dox @@ -0,0 +1,103 @@ +/** +\page SimulationManualPage The MITK Simulation Module + +The MITK Simulation Module provides medical simulation capabilities by integrating the Simulation Open Framework Architecture (SOFA) into MITK. + +\section SimulationManualBuildInstructions Build Instructions + +Activate the %CMake option MITK_USE_SOFA to automatically download and build SOFA as well as the MITK Simulation Module during the superbuild process. +Afterwards you can activate simulation-enabled plugins during the MITK build configuration, e.g. MITK_BUILD_org.mitk.gui.qt.simulation. + +\section SimulationManualIntroduction Introduction + +It is strongly recommended that you are at least familiar with the basic concepts of SOFA before you proceed reading. + +SOFA is intended to be used as a framework by itself. It is split into the following three parts: + +
    +
  • Framework +
  • Modules +
  • Applications +
+ +While the former two parts make up the actual framework, the latter part is built on top of them and provides end user applications, e.g. runSofa. + +To be able to integrate SOFA into MITK, the MITK Simulation Module conceptionally replaces the application layer and solely uses the framework and module layer as a toolkit. + +\section SimulationManualHowToUpdate How to update SOFA + +SOFA is deployed to the MITK superbuild in three ZIP archives, namely + +
    +
  • sofa-rev[rev].zip +
  • sofa-rev[rev]-cmake.zip +
  • sofa-rev[rev]-gl.zip +
+ +where [rev] is a substitute for the SVN revision of SOFA, e.g. 8935. +The follwing process was proven suitable to create these ZIP archives out of a certain SOFA revision. +Since it is a very time-consuming task you should only update SOFA if it is really necessary! + +
    +
  1. Follow the instructions of the SOFA framework download website to check out a recent revsion of the trunk form their SVN server into a newly created directory named SOFA-svn (check the dashboard first to see if that revision is likely to compile properly on all supported platforms). +
  2. To get rid of all SVN files in the source directory use SVN export to export the source code to a separate directory named SOFA-rev[rev]. +
  3. Delete all irrelevant directories and files in SOFA-rev[rev]. Relevant directories and files are: +
      +
    • extlibs/eigen-3.1.1, extlibs/miniBoost, extlibs/miniFlowVR, extlibs/newmat, extlibs/tinyxml +
    • framework +
    • modules/sofa/component, modules/sofa/simulation, modules/copyright.txt, modules/LGPL-license.txt +
    • Authors.txt, LICENCE.txt, readme.txt +
    +
  4. Create sofa-rev[rev].zip out of the SOFA-rev[rev] directory. +
  5. Download the old sofa-rev[old_rev].zip and extract it to SOFA-rev[old_rev]. +
  6. Download the old sofa-rev[old_rev]-cmake.zip and extract it to SOFA-CMake. +
  7. Download the old sofa-rev[old_rev]-gl.zip and extract it to SOFA-GL. +
  8. Download a directory diff tool like DirDiff for Windows and compare sofa-rev[old_rev] with sofa_rev[rev] to get an overview of what has changed. Note that you have to look at the .pro files to see which files were added or removed to the projects. Just looking at the files in a project directory is not sufficient! +
  9. Adapt the CMake files in SOFA-CMake to the changes. +
  10. Copy SOFA-rev[rev] to SOFA-rev[rev]-Test and also copy SOFA-CMake and SOFA-GL into that directory. +
  11. Manually apply the patch for SOFA you find in the MITK source tree (MITK/CMakeExternals/PatchSOFA-rev[old_rev].cmake. +
  12. Try to build SOFA-rev[rev]-Test. Make changes to SOFA-CMake and SOFA-GL files (don't forget to reapply the patch or even change the patch if necessary) until you can build everything successfully. +
  13. Create sofa-rev[rev]-cmake.zip out of SOFA-CMake and sofa-rev[rev]-gl.zip out of SOFA-GL. +
  14. Upload all three ZIP archives to a easily accessible location like your public DropBox folder. +
  15. Update MITK/CMakeExternals/SOFA.cmake to point to the temporary locations and don't forget to update the MD5 hashes and to use an up-to-date patch file, i.e. PatchSOFA-rev[rev].cmake. +
  16. Try to build MITK. Repeat any of the above steps until you are able to compile and use MITK with SOFA on every supprted plattform. +
  17. Upload the new SOFA archives to mitk.org and adapt the URLs in MITK/CMakeExternals/SOFA.cmake. +
+ +\section SimulationManualDrawing Drawing + +Drawing is done by SOFA at three different places: + +
    +
  • sofa::component::visualmodel classes +
  • sofa::core::visual::DrawTool class +
  • sofa::helper::gl classes and functions +
+ +These cases are handled by the MITK Simulation Module as follows. + +\subsection SimulationManualDrawingVisualModel sofa::component::visualmodel + +One of the most important drawing classes is OglModel since it makes up most of the visual part of a simulation scene. +It inherits from VisualModel (which encapsulates all API-independent drawing code) and contains OpenGL-related code to draw the visual model. + +To hook into the drawing of visual models, the MITK Simulation Module creates an alias in the SOFA object system so that every OglModel and VisualModel node found in a scene file is used to instantiate a MITK SimulationModel class instead. +This class creates VTK actors that contain the visual model rather than drawing it directly. +The simulation mapper, which is responsible for drawing a simulation scene, utilizes the visitor mechanism of SOFA to collect all VTK actors of the scene tree and finally draws them. + +\subsection SimulationManualDrawingDrawToolGL sofa::core::visual::DrawTool + +The abstract class DrawTool and its default OpenGL implementation DrawToolGL provide the interface to draw basic primitives, e.g. points, lines, spheres, arrows, and so forth. +It is usually set by a call to sofa::core::visual::VisualParams::defaultInstance()->drawTool() at application initialization. + +The MITK Simulation Module provide its own VTK-based implementation of DrawTool, namely SimulationDrawTool. +This class creates VTK actors instead of drawing anything directly. +There is one SimulationDrawTool per simulation scene and the simulation mapper draws all current VTK actors according to which simulation scene is drawn. + +\subsection SimulationManualDrawingGL sofa::helper::gl + +Classes and functions in this namespace are problematic since they don't support the SOFA object system and therefore cannot be easily replaced by own implementations. +Currently they are not handled by MITK at all and an OpenGL stub is injected into SOFA so that all draw related methods and functions in this namespace do practically nothing. +This stub is automatically downloaded during the MITK superbuild process (sofa-rev[rev]-gl.zip). +However, a patch is additionally applied by the superbuild script to SOFA which alters a few header files to include the stub header files instead of the original OpenGL/GLUT/GLEW ones. +*/ \ No newline at end of file diff --git a/Modules/Simulation/files.cmake b/Modules/Simulation/files.cmake new file mode 100644 index 0000000000..92064e233b --- /dev/null +++ b/Modules/Simulation/files.cmake @@ -0,0 +1,10 @@ +set(CPP_FILES + mitkSimulation.cpp + mitkSimulationDrawTool.cpp + mitkSimulationPropAssemblyVisitor.cpp + mitkSimulationIOFactory.cpp + mitkSimulationMapper3D.cpp + mitkSimulationReader.cpp + mitkSimulationObjectFactory.cpp + mitkSimulationModel.cpp +) diff --git a/Modules/Simulation/mitkSimulation.cpp b/Modules/Simulation/mitkSimulation.cpp new file mode 100644 index 0000000000..181bd9f969 --- /dev/null +++ b/Modules/Simulation/mitkSimulation.cpp @@ -0,0 +1,158 @@ +/*=================================================================== + +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 "mitkSimulation.h" +#include +#include +#include +#include + +const float mitk::Simulation::ScaleFactor = 1000.0f; + +static sofa::simulation::Simulation::SPtr CreateSimulation(mitk::Simulation::SimulationType type = mitk::Simulation::Tree) +{ + if (type == mitk::Simulation::DAG) + return sofa::core::objectmodel::New(); + else if (type == mitk::Simulation::Bgl) + return sofa::core::objectmodel::New(); + else + return sofa::core::objectmodel::New(); +} + +void mitk::Simulation::SetActiveSimulation(mitk::Simulation* simulation) +{ + if (simulation == NULL) + { + sofa::simulation::setSimulation(NULL); + sofa::core::visual::VisualParams::defaultInstance()->drawTool() = NULL; + } + else + { + sofa::simulation::Simulation* sofaSimulation = simulation->m_Simulation.get(); + + if (sofa::simulation::getSimulation() != sofaSimulation) + { + sofa::simulation::setSimulation(sofaSimulation); + sofa::core::visual::VisualParams::defaultInstance()->drawTool() = &simulation->m_DrawTool; + } + } +} + +mitk::Simulation::Simulation() + : m_Simulation(CreateSimulation()), + m_DefaultDT(0.0) +{ +} + +mitk::Simulation::~Simulation() +{ + if (m_Simulation != NULL) + { + if (m_RootNode != NULL) + m_Simulation->unload(m_RootNode); + + if (sofa::simulation::getSimulation() == m_Simulation.get()) + SetActiveSimulation(NULL); + } +} + +double mitk::Simulation::GetDefaultDT() const +{ + return m_DefaultDT; +} + +mitk::SimulationDrawTool* mitk::Simulation::GetDrawTool() +{ + return &m_DrawTool; +} + +sofa::simulation::Node::SPtr mitk::Simulation::GetRootNode() const +{ + return m_RootNode; +} + +sofa::simulation::Simulation::SPtr mitk::Simulation::GetSimulation() const +{ + return m_Simulation; +} + +bool mitk::Simulation::RequestedRegionIsOutsideOfTheBufferedRegion() +{ + return false; +} + +void mitk::Simulation::SetAsActiveSimulation() +{ + SetActiveSimulation(this); +} + +void mitk::Simulation::SetDefaultDT(double dt) +{ + m_DefaultDT = std::max(0.0, dt); +} + +void mitk::Simulation::SetRequestedRegion(itk::DataObject*) +{ +} + +void mitk::Simulation::SetRequestedRegionToLargestPossibleRegion() +{ +} + +void mitk::Simulation::SetRootNode(sofa::simulation::Node* rootNode) +{ + m_RootNode.reset(rootNode); +} + +void mitk::Simulation::UpdateOutputInformation() +{ + if (this->GetSource().IsNotNull()) + this->GetSource()->UpdateOutputInformation(); + + if (m_RootNode != NULL) + { + const sofa::defaulttype::BoundingBox& boundingBox = m_RootNode->f_bbox.getValue(); + const sofa::defaulttype::Vector3& min = boundingBox.minBBox(); + const sofa::defaulttype::Vector3& max = boundingBox.maxBBox(); + + mitk::Geometry3D::BoundsArrayType bounds; + + bounds[0] = static_cast(min.x() * ScaleFactor); + bounds[1] = static_cast(max.x() * ScaleFactor); + bounds[2] = static_cast(min.y() * ScaleFactor); + bounds[3] = static_cast(max.y() * ScaleFactor); + bounds[4] = static_cast(min.z() * ScaleFactor); + bounds[5] = static_cast(max.z() * ScaleFactor); + + if(this->GetGeometry() != NULL) + { + this->GetGeometry()->SetBounds(bounds); + } + else + { + Geometry3D::Pointer geometry = Geometry3D::New(); + geometry->SetBounds(bounds); + this->SetGeometry(geometry); + } + } + + this->GetTimeSlicedGeometry()->UpdateInformation(); +} + +bool mitk::Simulation::VerifyRequestedRegion() +{ + return true; +} diff --git a/Modules/Simulation/mitkSimulation.h b/Modules/Simulation/mitkSimulation.h new file mode 100644 index 0000000000..e0324cf73c --- /dev/null +++ b/Modules/Simulation/mitkSimulation.h @@ -0,0 +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. + +===================================================================*/ + +#ifndef mitkSimulation_h +#define mitkSimulation_h + +#include "mitkSimulationDrawTool.h" +#include +#include +#include + +namespace mitk +{ + class Simulation_EXPORT Simulation : public BaseData + { + public: + enum SimulationType + { + Tree, + DAG, + Bgl + }; + + mitkClassMacro(Simulation, BaseData); + itkNewMacro(Self); + + static void SetActiveSimulation(Self* simulation); + + static const float ScaleFactor; + + double GetDefaultDT() const; + SimulationDrawTool* GetDrawTool(); + sofa::simulation::Node::SPtr GetRootNode() const; + sofa::simulation::Simulation::SPtr GetSimulation() const; + bool RequestedRegionIsOutsideOfTheBufferedRegion(); + void SetAsActiveSimulation(); + void SetDefaultDT(double dt); + void SetRequestedRegion(itk::DataObject* data); + void SetRequestedRegionToLargestPossibleRegion(); + void SetRootNode(sofa::simulation::Node* rootNode); + void UpdateOutputInformation(); + bool VerifyRequestedRegion(); + + private: + Simulation(); + ~Simulation(); + + Simulation(Self&); + Self& operator=(const Self&); + + sofa::simulation::Simulation::SPtr m_Simulation; + sofa::simulation::Node::SPtr m_RootNode; + SimulationDrawTool m_DrawTool; + double m_DefaultDT; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationDrawTool.cpp b/Modules/Simulation/mitkSimulationDrawTool.cpp new file mode 100644 index 0000000000..941dbdf00e --- /dev/null +++ b/Modules/Simulation/mitkSimulationDrawTool.cpp @@ -0,0 +1,627 @@ +/*=================================================================== + +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 "mitkSimulation.h" +#include "mitkSimulationDrawTool.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +mitk::SimulationDrawTool::SimulationDrawTool() + : m_PolygonMode(0), + m_Wireframe(false), + m_Update(true) +{ +} + +mitk::SimulationDrawTool::~SimulationDrawTool() +{ + this->DeleteVtkObjects(); +} + +void mitk::SimulationDrawTool::DeleteVtkObjects() +{ + for (std::vector::const_iterator object = m_VtkObjects.begin(); object != m_VtkObjects.end(); ++object) + (*object)->Delete(); + + m_VtkObjects.clear(); + + for (std::vector::const_iterator actor = m_Actors.begin(); actor != m_Actors.end(); ++actor) + (*actor)->Delete(); + + m_Actors.clear(); +} + +void mitk::SimulationDrawTool::DisableUpdate() +{ + m_Update = false; +} + + +std::vector mitk::SimulationDrawTool::GetActors() const +{ + return m_Actors; +} + +void mitk::SimulationDrawTool::InitProperty(vtkProperty* property) const +{ + if (m_Wireframe) + property->SetRepresentationToWireframe(); + else + property->SetRepresentationToSurface(); +} + +void mitk::SimulationDrawTool::Reset() +{ + this->DeleteVtkObjects(); + m_Update = true; +} + +void mitk::SimulationDrawTool::drawPoints(const std::vector& points, float pointSize, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numPoints = points.size(); + + vtkPoints* vtkPoints = vtkPoints::New(); + vtkPoints->SetNumberOfPoints(numPoints); + + vtkCellArray* cellArray = vtkCellArray::New(); + + for (unsigned int i = 0; i < numPoints; ++i) + { + vtkPoints->SetPoint(i, points[i].elems); + cellArray->InsertNextCell(1); + cellArray->InsertCellPoint(i); + } + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(vtkPoints); + polyData->SetVerts(cellArray); + + vtkPoints->Delete(); + cellArray->Delete(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyData); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + property->SetColor(color.x(), color.y(), color.z()); + property->SetPointSize(pointSize); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); +} + +void mitk::SimulationDrawTool::drawLines(const std::vector& points, float lineWidth, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numPoints = points.size(); + std::vector indices; + + for (unsigned int i = 0; i < numPoints; i += 2) + indices.push_back(Vec2i(i, i + 1)); + + this->drawLines(points, indices, lineWidth, color); +} + +void mitk::SimulationDrawTool::drawLines(const std::vector& points, const std::vector& indices, float lineWidth, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numPoints = points.size(); + + vtkPoints* vtkPoints = vtkPoints::New(); + vtkPoints->SetNumberOfPoints(numPoints); + + for (unsigned int i = 0; i < numPoints; ++i) + vtkPoints->SetPoint(i, points[i].elems); + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(vtkPoints); + + vtkPoints->Delete(); + + vtkCellArray* lines = vtkCellArray::New(); + + unsigned int numIndices = indices.size(); + + for (unsigned int i = 0; i < numIndices; ++i) + { + lines->InsertNextCell(2); + lines->InsertCellPoint(indices[i].elems[0]); + lines->InsertCellPoint(indices[i].elems[1]); + } + + polyData->SetLines(lines); + + lines->Delete(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyData); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + property->SetLineWidth(lineWidth); + property->SetColor(color.x(), color.y(), color.z()); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); +} + +void mitk::SimulationDrawTool::drawTriangles(const std::vector& points, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numPoints = points.size(); + + vtkPoints* vtkPoints = vtkPoints::New(); + vtkPoints->SetNumberOfPoints(numPoints); + + for (unsigned int i = 0; i < numPoints; ++i) + vtkPoints->SetPoint(i, points[i].elems); + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(vtkPoints); + + vtkPoints->Delete(); + + vtkCellArray* triangles = vtkCellArray::New(); + + for (unsigned int i = 0; i < points.size(); i += 3) + { + triangles->InsertNextCell(3); + triangles->InsertCellPoint(i); + triangles->InsertCellPoint(i + 1); + triangles->InsertCellPoint(i + 2); + } + + polyData->SetPolys(triangles); + + triangles->Delete(); + + vtkPolyDataNormals* polyDataNormals = vtkPolyDataNormals::New(); + polyDataNormals->ComputeCellNormalsOff(); + polyDataNormals->SetInput(polyData); + polyDataNormals->SplittingOff(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyDataNormals->GetOutput()); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + + this->InitProperty(property); + + property->SetColor(color.x(), color.y(), color.z()); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_VtkObjects.push_back(polyDataNormals); + m_Actors.push_back(actor); +} + +void mitk::SimulationDrawTool::drawTriangles(const std::vector& points, const Vector3 normal, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numPoints = points.size(); + + vtkPoints* vtkPoints = vtkPoints::New(); + vtkPoints->SetNumberOfPoints(numPoints); + + for (unsigned int i = 0; i < numPoints; ++i) + vtkPoints->SetPoint(i, points[i].elems); + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(vtkPoints); + + vtkPoints->Delete(); + + vtkCellArray* triangles = vtkCellArray::New(); + + for (unsigned int i = 0; i < points.size(); i += 3) + { + triangles->InsertNextCell(3); + triangles->InsertCellPoint(i); + triangles->InsertCellPoint(i + 1); + triangles->InsertCellPoint(i + 2); + } + + polyData->SetPolys(triangles); + + triangles->Delete(); + + vtkFloatArray* normals = vtkFloatArray::New(); + normals->SetNumberOfComponents(3); + normals->SetName("Normals"); + + for (int i = 0; i < numPoints; i += 3) + normals->InsertNextTuple(normal.elems); + + polyData->GetCellData()->SetNormals(normals); + + normals->Delete(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyData); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + + this->InitProperty(property); + + property->SetColor(color.x(), color.y(), color.z()); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); +} + +void mitk::SimulationDrawTool::drawTriangles(const std::vector& points, const std::vector& indices, const std::vector& normals, const Vec4f color) +{ + if (!m_Update || points.empty() || indices.empty() || normals.empty()) + return; + + unsigned int numPoints = points.size(); + + vtkPoints* vtkPoints = vtkPoints::New(); + vtkPoints->SetNumberOfPoints(numPoints); + + for (unsigned int i = 0; i < numPoints; ++i) + vtkPoints->SetPoint(i, points[i].elems); + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(vtkPoints); + + vtkPoints->Delete(); + + vtkCellArray* triangles = vtkCellArray::New(); + + unsigned int numIndices = indices.size(); + + for (unsigned int i = 0; i < numIndices; ++i) + { + triangles->InsertNextCell(3); + triangles->InsertCellPoint(indices[i].elems[0]); + triangles->InsertCellPoint(indices[i].elems[1]); + triangles->InsertCellPoint(indices[i].elems[2]); + } + + polyData->SetPolys(triangles); + + triangles->Delete(); + + unsigned int numNormals = normals.size(); + + vtkFloatArray* vtkNormals = vtkFloatArray::New(); + vtkNormals->SetNumberOfComponents(3); + vtkNormals->SetName("Normals"); + + for (int i = 0; i < numNormals; ++i) + vtkNormals->InsertNextTuple(normals[i].elems); + + polyData->GetCellData()->SetNormals(vtkNormals); + + vtkNormals->Delete(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyData); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + + this->InitProperty(property); + + property->SetColor(color.x(), color.y(), color.z()); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); +} + +void mitk::SimulationDrawTool::drawTriangles(const std::vector&, const std::vector&, const std::vector&) +{ +} + +void mitk::SimulationDrawTool::drawTriangleStrip(const std::vector&, const std::vector&, const Vec4f) +{ +} + +void mitk::SimulationDrawTool::drawTriangleFan(const std::vector&, const std::vector&, const Vec4f) +{ +} + +void mitk::SimulationDrawTool::drawFrame(const Vector3& position, const Quaternion& orientation, const Vec3f& size) +{ + if (!m_Update) + return; + + const float radius = 0.05f; + + bool wireframeBackup = m_Wireframe; + m_Wireframe = false; + + std::vector colors; + colors.push_back(Vec4f(0.0f, 0.0f, 1.0f, 1.0f)); + colors.push_back(Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); + colors.push_back(Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); + + if (size.x() != 0.0f) + { + Vector3 point2 = position + orientation.rotate(Vec3f(size.x(), 0.0f, 0.0f)); + this->drawArrow(position, point2, radius, colors.back()); + colors.pop_back(); + } + + if (size.y() != 0.0f) + { + Vector3 point2 = position + orientation.rotate(Vec3f(0.0f, size.y(), 0.0f)); + this->drawArrow(position, point2, radius, colors.back()); + colors.pop_back(); + } + + if (size.z() != 0.0f) + { + Vector3 point2 = position + orientation.rotate(Vec3f(0.0f, 0.0f, size.z())); + this->drawArrow(position, point2, radius, colors.back()); + } + + m_Wireframe = wireframeBackup; +} + +void mitk::SimulationDrawTool::drawSpheres(const std::vector& points, const std::vector& radii, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numSpheres = points.size(); + + for (unsigned int i = 0; i < numSpheres; ++i) + { + vtkSphereSource *sphereSource = vtkSphereSource::New(); + sphereSource->SetCenter(const_cast(points[i].elems)); + sphereSource->SetRadius(radii[i]); + sphereSource->SetPhiResolution(16); + sphereSource->SetThetaResolution(32); + sphereSource->LatLongTessellationOn(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(sphereSource->GetOutput()); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + + this->InitProperty(property); + + property->SetColor(color.x(), color.y(), color.z()); + + m_VtkObjects.push_back(sphereSource); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); + } +} + +void mitk::SimulationDrawTool::drawSpheres(const std::vector& points, float radius, const Vec4f color) +{ + if (!m_Update || points.empty()) + return; + + unsigned int numPoints = points.size(); + std::vector radii(numPoints, radius); + + this->drawSpheres(points, radii, color); +} + +void mitk::SimulationDrawTool::drawCone(const Vector3& point1, const Vector3& point2, float radius1, float radius2, const Vec4f color, int subdivisions) +{ + if (!m_Update) + return; + + vtkPoints* points = vtkPoints::New(); + points->SetNumberOfPoints(2); + points->SetPoint(0, point1.elems); + points->SetPoint(1, point2.elems); + + vtkCellArray* line = vtkCellArray::New(); + line->InsertNextCell(2); + line->InsertCellPoint(0); + line->InsertCellPoint(1); + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(points); + polyData->SetLines(line); + + points->Delete(); + line->Delete(); + + const char* radiiName = "Radii"; + + vtkFloatArray* radii = vtkFloatArray::New(); + radii->SetName(radiiName); + radii->SetNumberOfTuples(2); + radii->SetTuple1(0, radius1); + radii->SetTuple1(1, radius2); + + vtkPointData* pointData = polyData->GetPointData(); + pointData->AddArray(radii); + pointData->SetActiveScalars(radiiName); + + radii->Delete(); + + vtkTubeFilter* tubeFilter = vtkTubeFilter::New(); + tubeFilter->SetInput(polyData); + tubeFilter->CappingOn(); + tubeFilter->SetNumberOfSides(subdivisions); + tubeFilter->SetVaryRadiusToVaryRadiusByAbsoluteScalar(); + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(tubeFilter->GetOutput()); + polyDataMapper->ScalarVisibilityOff(); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + vtkProperty* property = actor->GetProperty(); + + this->InitProperty(property); + + property->SetColor(color.x(), color.y(), color.z()); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(tubeFilter); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); +} + +void mitk::SimulationDrawTool::drawCube(const float&, const Vec4f&, const int&) +{ +} + +void mitk::SimulationDrawTool::drawCylinder(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color, int subdivisions) +{ + if (!m_Update) + return; + + this->drawCone(point1, point2, radius, radius, color, subdivisions); +} + +void mitk::SimulationDrawTool::drawCapsule(const Vector3&, const Vector3&, float, const Vec4f, int) +{ +} + +void mitk::SimulationDrawTool::drawArrow(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color, int subdivisions) +{ + if (!m_Update) + return; + + Vector3 point3 = point1 * 0.2f + point2 * 0.8f; + + this->drawCylinder(point1, point3, radius, color, subdivisions); + this->drawCone(point3, point2, radius * 2.5f, 0.0f, color, subdivisions); +} + +void mitk::SimulationDrawTool::drawPlus(const float& edgeRadius, const Vec4f& color, const int& subdivisions) +{ + if (!m_Update) + return; + + this->drawCylinder(Vector3(-1.0, 0.0, 0.0), Vector3(1.0, 0.0, 0.0), edgeRadius, color, subdivisions); + this->drawCylinder(Vector3(0.0, -1.0, 0.0), Vector3(0.0, 1.0, 0.0), edgeRadius, color, subdivisions); + this->drawCylinder(Vector3(0.0, 0.0, -1.0), Vector3(0.0, 0.0, 1.0), edgeRadius, color, subdivisions); +} + +void mitk::SimulationDrawTool::drawPoint(const Vector3&, const Vec4f&) +{ +} + +void mitk::SimulationDrawTool::drawPoint(const Vector3&, const Vector3&, const Vec4f&) +{ +} + +void mitk::SimulationDrawTool::drawTriangle(const Vector3&, const Vector3&, const Vector3&, const Vector3&) +{ +} + +void mitk::SimulationDrawTool::drawTriangle(const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vec4f&) +{ +} + +void mitk::SimulationDrawTool::drawTriangle(const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vec4f&, const Vec4f&, const Vec4f&) +{ +} + +void mitk::SimulationDrawTool::drawSphere(const Vector3&, float) +{ +} + +void mitk::SimulationDrawTool::pushMatrix() +{ +} + +void mitk::SimulationDrawTool::popMatrix() +{ +} + +void mitk::SimulationDrawTool::multMatrix(float*) +{ +} + +void mitk::SimulationDrawTool::scale(float) +{ +} + +void mitk::SimulationDrawTool::setMaterial(const Vec4f&, std::string) +{ +} + +void mitk::SimulationDrawTool::resetMaterial(const Vec4f&, std::string) +{ +} + +void mitk::SimulationDrawTool::setPolygonMode(int mode, bool wireframe) +{ + if (!m_Update) + return; + + m_PolygonMode = mode; + m_Wireframe = wireframe; +} + +void mitk::SimulationDrawTool::setLightingEnabled(bool) +{ +} + +void mitk::SimulationDrawTool::writeOverlayText(int, int, unsigned int, const Vec4f&, const char*) +{ +} diff --git a/Modules/Simulation/mitkSimulationDrawTool.h b/Modules/Simulation/mitkSimulationDrawTool.h new file mode 100644 index 0000000000..519b39c82b --- /dev/null +++ b/Modules/Simulation/mitkSimulationDrawTool.h @@ -0,0 +1,109 @@ +/*=================================================================== + +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 mitkSimulationDrawTool_h +#define mitkSimulationDrawTool_h + +#include +#include + +class vtkActor; +class vtkObjectBase; +class vtkProperty; + +namespace mitk +{ + /** \brief Utility class used by SOFA classes to draw objects other than visual models. + * + * Implements the sofa::core::visual::DrawTool interface and replaces the default SOFA OpenGL implementation sofa::core::visual::DrawToolGL. + * All draw methods create a VTK actor and append it to an internal list which can be queried by calling GetActors() to finally draw them. + * In contrary to the original concept of DrawToolGL, which is set once during initialization of SOFA applications, every mitk::Simulation has its own exclusive copy of mitk::SimulationDrawTool. + * Since SOFA can handle only a single DrawTool at once it must be ensured that the correct mitk::SimulationDrawTool is set when switching the active simulation. + * + * Each draw method checks if it is necessary to generate a new up-to-date VTK actor, i.e. after a simulation step, or if it is sufficient to use the already generated one. + * This decision is controlled through the methods Reset() and DisableUpdate(). + * The former method must be called right before a simulation step and mitk::SimulationMapper3D calls the latter method during rendering to disable unnecessary updates until the next simulation step. + */ + class Simulation_EXPORT SimulationDrawTool : public sofa::core::visual::DrawTool + { + public: + SimulationDrawTool(); + ~SimulationDrawTool(); + + /** \brief Disables creation of new VTK actors when calling draw methods. + */ + void DisableUpdate(); + + /** \brief Returns current list of VTK actors which were generated by draw methods since the last reset. + * + * \note Do not delete the VTK actors returned by this method. + */ + std::vector GetActors() const; + + /** \brief Clears internal lists of current VTK objects and enables creation of new VTK actors when calling draw methods. + */ + void Reset(); + + void drawPoints(const std::vector& points, float pointSize, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawLines(const std::vector& points, float lineWidth, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawLines(const std::vector& points, const std::vector& indices, float lineWidth, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangles(const std::vector& points, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangles(const std::vector& points, const Vector3 normal, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangles(const std::vector& points, const std::vector& indices, const std::vector& normals, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangles(const std::vector& points, const std::vector& normals, const std::vector& colors); + void drawTriangleStrip(const std::vector& points, const std::vector& normals, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangleFan(const std::vector& points, const std::vector& normals, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawFrame(const Vector3& position, const Quaternion& orientation, const Vec3f& size); + void drawSpheres(const std::vector& points, const std::vector& radii, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawSpheres(const std::vector& points, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawCone(const Vector3& point1, const Vector3& point2, float radius1, float radius2, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); + void drawCube(const float& edgeRadius, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), const int& subdivisions = 16); + void drawCylinder(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); + void drawCapsule(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); + void drawArrow(const Vector3& point1, const Vector3& point2, float radius, const Vec4f color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), int subdivisions = 16); + void drawPlus(const float& edgeRadius, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f), const int& subdivisions = 16); + void drawPoint(const Vector3& position, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawPoint(const Vector3& position, const Vector3& normal, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangle(const Vector3& point1, const Vector3& point2, const Vector3& point3, const Vector3& normal); + void drawTriangle(const Vector3& point1, const Vector3& point2, const Vector3& point3, const Vector3& normal, const Vec4f& color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + void drawTriangle(const Vector3& point1, const Vector3& point2, const Vector3& point3, const Vector3& normal, const Vec4f& color1, const Vec4f& color2, const Vec4f& color3); + void drawSphere(const Vector3& position, float radius); + void pushMatrix(); + void popMatrix(); + void multMatrix(float* matrix); + void scale(float factor); + void setMaterial(const Vec4f& color, std::string name = ""); + void resetMaterial(const Vec4f& color, std::string name = ""); + void setPolygonMode(int mode, bool wireframe); + void setLightingEnabled(bool isEnabled); + void writeOverlayText(int x, int y, unsigned int fontSize, const Vec4f& color, const char* text); + + private: + SimulationDrawTool(const SimulationDrawTool&); + SimulationDrawTool& operator=(const SimulationDrawTool&); + + void DeleteVtkObjects(); + void InitProperty(vtkProperty* property) const; + + std::vector m_VtkObjects; + std::vector m_Actors; + int m_PolygonMode; + bool m_Wireframe; + bool m_Update; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationIOFactory.cpp b/Modules/Simulation/mitkSimulationIOFactory.cpp new file mode 100644 index 0000000000..2f81c6e1d5 --- /dev/null +++ b/Modules/Simulation/mitkSimulationIOFactory.cpp @@ -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. + +===================================================================*/ + +#include "mitkSimulationIOFactory.h" +#include "mitkSimulationReader.h" +#include +#include + +mitk::SimulationIOFactory::SimulationIOFactory() +{ + this->RegisterOverride( + "mitkIOAdapter", + "mitkSimulationReader", + "Simulation IO", + true, + itk::CreateObjectFunction >::New()); +} + +mitk::SimulationIOFactory::~SimulationIOFactory() +{ +} + +const char* mitk::SimulationIOFactory::GetDescription() const +{ + return "mitk::SimulationIOFactory"; +} + +const char* mitk::SimulationIOFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} diff --git a/Modules/Simulation/mitkSimulationIOFactory.h b/Modules/Simulation/mitkSimulationIOFactory.h new file mode 100644 index 0000000000..4d02584def --- /dev/null +++ b/Modules/Simulation/mitkSimulationIOFactory.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 mitkSimulationIOFactory_h +#define mitkSimulationIOFactory_h + +#include +#include +#include + +namespace mitk +{ + class Simulation_EXPORT SimulationIOFactory : public itk::ObjectFactoryBase + { + public: + mitkClassMacro(SimulationIOFactory, itk::ObjectFactoryBase); + itkFactorylessNewMacro(Self); + + const char* GetDescription() const; + const char* GetITKSourceVersion() const; + + private: + SimulationIOFactory(); + ~SimulationIOFactory(); + + SimulationIOFactory(const Self&); + Self& operator=(const Self&); + }; +}; + +#endif diff --git a/Modules/Simulation/mitkSimulationMapper3D.cpp b/Modules/Simulation/mitkSimulationMapper3D.cpp new file mode 100644 index 0000000000..fc65b28ae7 --- /dev/null +++ b/Modules/Simulation/mitkSimulationMapper3D.cpp @@ -0,0 +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 "mitkSimulation.h" +#include "mitkSimulationMapper3D.h" +#include "mitkSimulationModel.h" +#include "mitkSimulationPropAssemblyVisitor.h" +#include +#include + +mitk::SimulationMapper3D::LocalStorage::LocalStorage() + : m_VtkProp(vtkSmartPointer::New()) +{ +} + +mitk::SimulationMapper3D::LocalStorage::~LocalStorage() +{ +} + +void mitk::SimulationMapper3D::SetDefaultProperties(DataNode* node, BaseRenderer* renderer, bool overwrite) +{ + if (node != NULL) + { + mitk::Simulation* simulation = dynamic_cast(node->GetData()); + + if (simulation != NULL) + { + sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); + sofa::component::visualmodel::VisualStyle::SPtr visualStyle; + + rootNode->get(visualStyle); + + if (!visualStyle) + { + visualStyle = sofa::core::objectmodel::New(); + + sofa::core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit(); + displayFlags->setShowVisualModels(); + visualStyle->displayFlags.endEdit(); + + rootNode->addObject(visualStyle); + } + + const sofa::core::visual::DisplayFlags& displayFlags = visualStyle->displayFlags.getValue(); + + node->AddProperty("Simulation.Behavior.Behavior Models", BoolProperty::New(displayFlags.getShowBehaviorModels()), renderer, overwrite); + node->AddProperty("Simulation.Behavior.Force Fields", BoolProperty::New(displayFlags.getShowForceFields()), renderer, overwrite); + node->AddProperty("Simulation.Behavior.Interactions", BoolProperty::New(displayFlags.getShowInteractionForceFields()), renderer, overwrite); + node->AddProperty("Simulation.Collision.Bounding Trees", BoolProperty::New(displayFlags.getShowBoundingCollisionModels()), renderer, overwrite); + node->AddProperty("Simulation.Collision.Collision Models", BoolProperty::New(displayFlags.getShowCollisionModels()), renderer, overwrite); + node->AddProperty("Simulation.Mapping.Mechanical Mappings", BoolProperty::New(displayFlags.getShowMechanicalMappings()), renderer, overwrite); + node->AddProperty("Simulation.Mapping.Visual Mappings", BoolProperty::New(displayFlags.getShowMappings()), renderer, overwrite); + node->AddProperty("Simulation.Options.Normals", BoolProperty::New(displayFlags.getShowNormals()), renderer, overwrite); + node->AddProperty("Simulation.Options.Wire Frame", BoolProperty::New(displayFlags.getShowWireFrame()), renderer, overwrite); + node->AddProperty("Simulation.Visual.Visual Models", BoolProperty::New(displayFlags.getShowVisualModels()), renderer, overwrite); + } + + Superclass::SetDefaultProperties(node, renderer, overwrite); + } +} + +mitk::SimulationMapper3D::SimulationMapper3D() +{ +} + +mitk::SimulationMapper3D::~SimulationMapper3D() +{ +} + +void mitk::SimulationMapper3D::ApplyProperties(vtkActor* actor, mitk::BaseRenderer* renderer) +{ + if (actor == NULL) + { + mitk::DataNode* node = this->GetDataNode(); + + bool showBehaviorModels; + bool showForceFields; + bool showInteractionForceFields; + bool showBoundingCollisionModels; + bool showCollisionModels; + bool showMechanicalMappings; + bool showMappings; + bool showNormals; + bool showWireFrame; + bool showVisualModels; + + node->GetBoolProperty("Simulation.Behavior.Behavior Models", showBehaviorModels, renderer); + node->GetBoolProperty("Simulation.Behavior.Force Fields", showForceFields, renderer); + node->GetBoolProperty("Simulation.Behavior.Interactions", showInteractionForceFields, renderer); + node->GetBoolProperty("Simulation.Collision.Bounding Trees", showBoundingCollisionModels, renderer); + node->GetBoolProperty("Simulation.Collision.Collision Models", showCollisionModels, renderer); + node->GetBoolProperty("Simulation.Mapping.Mechanical Mappings", showMechanicalMappings, renderer); + node->GetBoolProperty("Simulation.Mapping.Visual Mappings", showMappings, renderer); + node->GetBoolProperty("Simulation.Options.Normals", showNormals, renderer); + node->GetBoolProperty("Simulation.Options.Wire Frame", showWireFrame, renderer); + node->GetBoolProperty("Simulation.Visual.Visual Models", showVisualModels, renderer); + + mitk::Simulation* simulation = static_cast(this->GetData()); + sofa::component::visualmodel::VisualStyle::SPtr visualStyle; + simulation->GetRootNode()->get(visualStyle); + + bool update = false; + + sofa::core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit(); + + if (showBehaviorModels != displayFlags->getShowBehaviorModels()) + { + displayFlags->setShowBehaviorModels(showBehaviorModels); + update = true; + } + + if (showForceFields != displayFlags->getShowForceFields()) + { + displayFlags->setShowForceFields(showForceFields); + update = true; + } + + if (showInteractionForceFields != displayFlags->getShowInteractionForceFields()) + { + displayFlags->setShowInteractionForceFields(showInteractionForceFields); + update = true; + } + + if (showBoundingCollisionModels != displayFlags->getShowBoundingCollisionModels()) + { + displayFlags->setShowBoundingCollisionModels(showBoundingCollisionModels); + update = true; + } + + if (showCollisionModels != displayFlags->getShowCollisionModels()) + { + displayFlags->setShowCollisionModels(showCollisionModels); + update = true; + } + + if (showMechanicalMappings != displayFlags->getShowMechanicalMappings()) + { + displayFlags->setShowMechanicalMappings(showMechanicalMappings); + update = true; + } + + if (showMappings != displayFlags->getShowMappings()) + { + displayFlags->setShowMappings(showMappings); + update = true; + } + + displayFlags->setShowNormals(showNormals); + + if (showWireFrame != displayFlags->getShowWireFrame()) + { + displayFlags->setShowWireFrame(showWireFrame); + update = true; + } + + displayFlags->setShowVisualModels(showVisualModels); + + visualStyle->displayFlags.endEdit(); + + if (update) + simulation->GetDrawTool()->Reset(); + } +} + +void mitk::SimulationMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer) +{ + mitk::Simulation* simulation = dynamic_cast(this->GetData()); + + if (sofa::simulation::getSimulation() == NULL) + { + if (simulation != NULL) + { + simulation->SetAsActiveSimulation(); + simulation->GetDrawTool()->Reset(); + } + else + { + return; + } + } + + LocalStorage* localStorage = m_LocalStorageHandler.GetLocalStorage(renderer); + localStorage->m_VtkProp = vtkSmartPointer::New(); + + if (simulation != NULL) + { + sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); + sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); + sofa::core::visual::VisualParams* vParams = sofa::core::visual::VisualParams::defaultInstance(); + SimulationDrawTool* drawTool = simulation->GetDrawTool(); + + sofa::simulation::Simulation* backupSimulation = NULL; + sofa::core::visual::DrawTool* backupDrawTool = NULL; + + if (sofa::simulation::getSimulation() != sofaSimulation.get()) + { + backupSimulation = sofa::simulation::getSimulation(); + backupDrawTool = vParams->drawTool(); + + sofa::simulation::setSimulation(sofaSimulation.get()); + vParams->drawTool() = drawTool; + } + + this->ApplyProperties(NULL, renderer); + + sofaSimulation->updateVisual(rootNode.get()); + sofaSimulation->draw(vParams, rootNode.get()); + drawTool->DisableUpdate(); + + SimulationPropAssemblyVisitor propAssemblyVisitor(localStorage->m_VtkProp); + rootNode->executeVisitor(&propAssemblyVisitor); + + std::vector actors = drawTool->GetActors(); + + for (std::vector::const_iterator actor = actors.begin(); actor != actors.end(); ++actor) + localStorage->m_VtkProp->AddPart(*actor); + + if (backupSimulation != NULL) + { + sofa::simulation::setSimulation(backupSimulation); + vParams->drawTool() = backupDrawTool; + } + } +} + +vtkProp* mitk::SimulationMapper3D::GetVtkProp(mitk::BaseRenderer* renderer) +{ + return m_LocalStorageHandler.GetLocalStorage(renderer)->m_VtkProp; +} diff --git a/Modules/Simulation/mitkSimulationMapper3D.h b/Modules/Simulation/mitkSimulationMapper3D.h new file mode 100644 index 0000000000..d9b854218b --- /dev/null +++ b/Modules/Simulation/mitkSimulationMapper3D.h @@ -0,0 +1,65 @@ +/*=================================================================== + +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 mitkSimulationMapper3D_h +#define mitkSimulationMapper3D_h + +#include +#include +#include +#include + +namespace mitk +{ + class Simulation_EXPORT SimulationMapper3D : public VtkMapper3D + { + class LocalStorage + { + public: + LocalStorage(); + ~LocalStorage(); + + vtkSmartPointer m_VtkProp; + + private: + LocalStorage(const LocalStorage&); + LocalStorage& operator=(const LocalStorage&); + }; + + public: + static void SetDefaultProperties(DataNode* node, BaseRenderer* renderer = NULL, bool overwrite = false); + + mitkClassMacro(SimulationMapper3D, VtkMapper3D); + itkNewMacro(Self); + + void ApplyProperties(vtkActor* actor, BaseRenderer* renderer); + vtkProp* GetVtkProp(BaseRenderer* renderer); + + protected: + void GenerateDataForRenderer(BaseRenderer* renderer); + + private: + SimulationMapper3D(); + ~SimulationMapper3D(); + + SimulationMapper3D(const Self&); + Self& operator=(const Self&); + + mitk::Mapper::LocalStorageHandler m_LocalStorageHandler; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationModel.cpp b/Modules/Simulation/mitkSimulationModel.cpp new file mode 100644 index 0000000000..cebf7e866a --- /dev/null +++ b/Modules/Simulation/mitkSimulationModel.cpp @@ -0,0 +1,337 @@ +/*=================================================================== + +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 "mitkSimulation.h" +#include "mitkSimulationModel.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +mitk::SimulationModel::SimulationModel() + : m_LastTime(-1.0), + m_LastShowNormals(false), + m_LastShowVisualModels(true), + m_LastShowWireFrame(false) +{ +} + +mitk::SimulationModel::~SimulationModel() +{ + this->DeleteVtkTextures(); + this->DeleteVtkObjects(); +} + +void mitk::SimulationModel::DeleteVtkObjects() +{ + for (std::vector::const_iterator object = m_VtkObjects.begin(); object != m_VtkObjects.end(); ++object) + (*object)->Delete(); + + m_VtkObjects.clear(); + + for (std::vector::const_iterator actor = m_Actors.begin(); actor != m_Actors.end(); ++actor) + (*actor)->Delete(); + + m_Actors.clear(); +} + +void mitk::SimulationModel::DeleteVtkTextures() +{ + for (std::map::const_iterator texture = m_Textures.begin(); texture != m_Textures.end(); ++texture) + texture->second->Delete(); + + m_Textures.clear(); +} + +void mitk::SimulationModel::DrawGroup(int ig, const sofa::core::visual::VisualParams* vparams, bool transparent) +{ + const sofa::defaulttype::ResizableExtVector& triangles = this->getTriangles(); + const sofa::defaulttype::ResizableExtVector& quads = this->getQuads(); + FaceGroup g; + + if (ig < 0) + { + g.materialId = -1; + g.tri0 = 0; + g.nbt = triangles.size(); + g.quad0 = 0; + g.nbq = quads.size(); + } + else + { + g = groups.getValue()[ig]; + } + + const sofa::defaulttype::ResizableExtVector& vertices = this->getVertices(); + unsigned int numVertices = vertices.size(); + + vtkPoints* points = vtkPoints::New(); + points->SetNumberOfPoints(numVertices); + + for (unsigned int i = 0; i < numVertices; ++i) + points->SetPoint(i, vertices[i].elems); + + vtkPolyData* polyData = vtkPolyData::New(); + polyData->SetPoints(points); + + points->Delete(); + + vtkCellArray* polys = vtkCellArray::New(); + + int numTriangles = g.tri0 + g.nbt; + int numQuads = g.quad0 + g.nbq; + + for (int i = g.tri0; i < numTriangles; ++i) + { + polys->InsertNextCell(3); + polys->InsertCellPoint(triangles[i].elems[0]); + polys->InsertCellPoint(triangles[i].elems[1]); + polys->InsertCellPoint(triangles[i].elems[2]); + } + + for (int i = g.quad0; i < numQuads; ++i) + { + polys->InsertNextCell(4); + polys->InsertCellPoint(quads[i].elems[0]); + polys->InsertCellPoint(quads[i].elems[1]); + polys->InsertCellPoint(quads[i].elems[2]); + polys->InsertCellPoint(quads[i].elems[3]); + } + + polyData->SetPolys(polys); + + polys->Delete(); + + const sofa::defaulttype::ResizableExtVector& normals = this->getVnormals(); + unsigned int numNormals = normals.size(); + + vtkFloatArray* vtkNormals = vtkFloatArray::New(); + vtkNormals->SetNumberOfComponents(3); + + for (unsigned int i = 0; i < numNormals; ++i) + vtkNormals->InsertNextTuple(normals[i].elems); + + polyData->GetPointData()->SetNormals(vtkNormals); + + vtkNormals->Delete(); + + sofa::core::loader::Material m = g.materialId >= 0 + ? materials.getValue()[g.materialId] + : material.getValue(); + + if (m.useTexture && m.activated) + { + const sofa::defaulttype::ResizableExtVector& texCoords = this->getVtexcoords(); + unsigned int numTexCoords = texCoords.size(); + + vtkFloatArray* vtkTexCoords = vtkFloatArray::New(); + vtkTexCoords->SetNumberOfComponents(2); + + for (unsigned int i = 0; i < numTexCoords; ++i) + vtkTexCoords->InsertNextTuple(texCoords[i].elems); + + polyData->GetPointData()->SetTCoords(vtkTexCoords); + + vtkTexCoords->Delete(); + } + + vtkPolyDataMapper* polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyData); + + vtkActor* actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + if (m.useTexture && m.activated) + actor->SetTexture(m_Textures[g.materialId]); + + sofa::defaulttype::Vec4f ambient = !m.useAmbient + ? sofa::defaulttype::Vec4f() + : m.ambient; + + sofa::defaulttype::Vec4f diffuse = !m.useDiffuse + ? sofa::defaulttype::Vec4f() + : m.diffuse; + + sofa::defaulttype::Vec4f specular = !m.useSpecular + ? sofa::defaulttype::Vec4f() + : m.specular; + + float shininess = m.useShininess + ? m.shininess + : 45.0f; + + if (shininess == 0.0f) + { + specular.clear(); + shininess = 1.0f; + } + + vtkProperty* property = actor->GetProperty(); + + property->SetAmbientColor(ambient.x(), ambient.y(), ambient.z()); + property->SetDiffuseColor(diffuse.x(), diffuse.y(), diffuse.z()); + property->SetSpecular(1.0); + property->SetSpecularColor(specular.x(), specular.y(), specular.z()); + property->SetSpecularPower(shininess); + + if (vparams->displayFlags().getShowWireFrame()) + property->SetRepresentationToWireframe(); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); + + if (!m_LastShowNormals) + return; + + points = vtkPoints::New(); + points->SetNumberOfPoints(numVertices * 2); + + vtkCellArray* lines = vtkCellArray::New(); + + for (unsigned int i = 0; i < numVertices; ++i) + { + unsigned int j = 2 * i; + unsigned int k = j + 1; + + points->SetPoint(j, vertices[i].elems); + points->SetPoint(k, (vertices[i] + normals[i]).elems); + + lines->InsertNextCell(2); + lines->InsertCellPoint(j); + lines->InsertCellPoint(k); + } + + polyData = vtkPolyData::New(); + polyData->SetPoints(points); + polyData->SetLines(lines); + + points->Delete(); + lines->Delete(); + + polyDataMapper = vtkPolyDataMapper::New(); + polyDataMapper->SetInput(polyData); + + actor = vtkActor::New(); + actor->SetMapper(polyDataMapper); + actor->SetScale(Simulation::ScaleFactor); + + m_VtkObjects.push_back(polyData); + m_VtkObjects.push_back(polyDataMapper); + m_Actors.push_back(actor); +} + +std::vector mitk::SimulationModel::GetActors() const +{ + return m_Actors; +} + +void mitk::SimulationModel::internalDraw(const sofa::core::visual::VisualParams* vparams, bool transparent) +{ + double time = this->getContext()->getTime(); + + const sofa::core::visual::DisplayFlags& displayFlags = vparams->displayFlags(); + bool showNormals = displayFlags.getShowNormals(); + bool showVisualModels = displayFlags.getShowVisualModels(); + bool showWireFrame = displayFlags.getShowWireFrame(); + + if (time == m_LastTime && showNormals == m_LastShowNormals && showVisualModels == m_LastShowVisualModels && showWireFrame == m_LastShowWireFrame) + return; + + m_LastTime = time; + m_LastShowNormals = showNormals; + m_LastShowVisualModels = showVisualModels; + m_LastShowWireFrame = showWireFrame; + + if (transparent) + return; + + this->DeleteVtkObjects(); + + if (!vparams->displayFlags().getShowVisualModels()) + return; + + sofa::helper::ReadAccessor > > groups = this->groups; + + if (groups.empty()) + { + this->DrawGroup(-1, vparams, transparent); + } + else + { + for (unsigned int i = 0; i < groups.size(); ++i) + this->DrawGroup(i, vparams, transparent); + } +} + +bool mitk::SimulationModel::loadTexture(const std::string& filename) +{ + return false; +} + +bool mitk::SimulationModel::loadTextures() +{ + this->DeleteVtkTextures(); + + std::vector activatedTextures; + + const sofa::helper::vector& materials = this->materials.getValue(); + unsigned int numMaterials = materials.size(); + + for (unsigned int i = 0; i < numMaterials; ++i) + { + const sofa::core::loader::Material& material = materials[i]; + + if (material.useTexture && material.activated) + activatedTextures.push_back(i); + } + + unsigned int numActivatedTextures = activatedTextures.size(); + + for (unsigned int i = 0; i < numActivatedTextures; ++i) + { + std::string textureFilename = materials[activatedTextures[i]].textureFilename; + + if (!sofa::helper::system::DataRepository.findFile(textureFilename)) + return false; + + vtkImageReader2* imageReader = vtkImageReader2Factory::CreateImageReader2(textureFilename.c_str()); + + if (imageReader == NULL) + return false; + + imageReader->SetFileName(textureFilename.c_str()); + + vtkTexture* texture = vtkTexture::New(); + texture->SetInput(imageReader->GetOutputDataObject(0)); + texture->InterpolateOn(); + + imageReader->Delete(); + + m_Textures.insert(std::make_pair(activatedTextures[i], texture)); + } + + return true; +} diff --git a/Modules/Simulation/mitkSimulationModel.h b/Modules/Simulation/mitkSimulationModel.h new file mode 100644 index 0000000000..b2a06fe9e1 --- /dev/null +++ b/Modules/Simulation/mitkSimulationModel.h @@ -0,0 +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. + +===================================================================*/ + +#ifndef mitkSimulationModel_h +#define mitkSimulationModel_h + +#include +#include + +class vtkActor; +class vtkObjectBase; +class vtkTexture; + +namespace mitk +{ + class Simulation_EXPORT SimulationModel : public sofa::component::visualmodel::VisualModelImpl + { + public: + SOFA_CLASS(SimulationModel, sofa::component::visualmodel::VisualModelImpl); + + std::vector GetActors() const; + + bool loadTexture(const std::string& filename); + bool loadTextures(); + + protected: + void internalDraw(const sofa::core::visual::VisualParams* vparams, bool transparent); + + private: + SimulationModel(); + ~SimulationModel(); + + SimulationModel(const MyType&); + MyType& operator=(const MyType&); + + void DeleteVtkObjects(); + void DeleteVtkTextures(); + void DrawGroup(int ig, const sofa::core::visual::VisualParams* vparams, bool transparent); + + std::vector m_VtkObjects; + std::vector m_Actors; + std::map m_Textures; + + double m_LastTime; + bool m_LastShowNormals; + bool m_LastShowVisualModels; + bool m_LastShowWireFrame; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationObjectFactory.cpp b/Modules/Simulation/mitkSimulationObjectFactory.cpp new file mode 100644 index 0000000000..ff1c0cef4b --- /dev/null +++ b/Modules/Simulation/mitkSimulationObjectFactory.cpp @@ -0,0 +1,128 @@ +/*=================================================================== + +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 "mitkSimulation.h" +#include "mitkSimulationMapper3D.h" +#include "mitkSimulationObjectFactory.h" +#include "mitkSimulationModel.h" +#include +#include +#include +#include + +mitk::SimulationObjectFactory::SimulationObjectFactory() + : m_SimulationIOFactory(SimulationIOFactory::New()) +{ + itk::ObjectFactoryBase::RegisterFactory(m_SimulationIOFactory); + + const std::string description = "SOFA Scene Files"; + m_FileExtensionsMap.insert(std::pair("*.scn", description)); + m_FileExtensionsMap.insert(std::pair("*.xml", description)); + + sofa::component::init(); + sofa::simulation::xml::initXml(); + + int SimulationModelClass = sofa::core::RegisterObject("").add(); + sofa::core::ObjectFactory::AddAlias("OglModel", "SimulationModel", true); + sofa::core::ObjectFactory::AddAlias("VisualModel", "SimulationModel", true); +} + +mitk::SimulationObjectFactory::~SimulationObjectFactory() +{ + itk::ObjectFactoryBase::UnRegisterFactory(m_SimulationIOFactory); +} + +mitk::Mapper::Pointer mitk::SimulationObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId slotId) +{ + mitk::Mapper::Pointer mapper; + + if (dynamic_cast(node->GetData()) != NULL) + { + if (slotId == mitk::BaseRenderer::Standard3D) + mapper = mitk::SimulationMapper3D::New(); + + if (mapper.IsNotNull()) + mapper->SetDataNode(node); + } + + return mapper; +} + +const char* mitk::SimulationObjectFactory::GetDescription() const +{ + return "mitk::SimulationObjectFactory"; +} + +const char* mitk::SimulationObjectFactory::GetFileExtensions() +{ + std::string fileExtensions; + this->CreateFileExtensions(m_FileExtensionsMap, fileExtensions); + return fileExtensions.c_str(); +} + +mitk::CoreObjectFactoryBase::MultimapType mitk::SimulationObjectFactory::GetFileExtensionsMap() +{ + return m_FileExtensionsMap; +} + +const char* mitk::SimulationObjectFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char* mitk::SimulationObjectFactory::GetSaveFileExtensions() +{ + std::string saveFileExtensions; + this->CreateFileExtensions(m_FileExtensionsMap, saveFileExtensions); + return saveFileExtensions.c_str(); +} + +mitk::CoreObjectFactoryBase::MultimapType mitk::SimulationObjectFactory::GetSaveFileExtensionsMap() +{ + return m_SaveFileExtensionsMap; +} + +void mitk::SimulationObjectFactory::SetDefaultProperties(mitk::DataNode* node) +{ + if (node != NULL) + { + if (dynamic_cast(node->GetData()) != NULL) + SimulationMapper3D::SetDefaultProperties(node); + } +} + +class RegisterSimulationObjectFactory +{ +public: + RegisterSimulationObjectFactory() + : m_Factory(mitk::SimulationObjectFactory::New()) + { + mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(m_Factory); + } + + ~RegisterSimulationObjectFactory() + { + mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory(m_Factory); + } + +private: + RegisterSimulationObjectFactory(const RegisterSimulationObjectFactory&); + RegisterSimulationObjectFactory& operator=(const RegisterSimulationObjectFactory&); + + mitk::SimulationObjectFactory::Pointer m_Factory; +}; + +static RegisterSimulationObjectFactory registerSimulationObjectFactory; diff --git a/Modules/Simulation/mitkSimulationObjectFactory.h b/Modules/Simulation/mitkSimulationObjectFactory.h new file mode 100644 index 0000000000..501eb21f84 --- /dev/null +++ b/Modules/Simulation/mitkSimulationObjectFactory.h @@ -0,0 +1,53 @@ +/*=================================================================== + +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 mitkSimulationObjectFactory_h +#define mitkSimulationObjectFactory_h + +#include "mitkSimulationIOFactory.h" +#include + +namespace mitk +{ + class Simulation_EXPORT SimulationObjectFactory : public CoreObjectFactoryBase + { + public: + mitkClassMacro(SimulationObjectFactory, CoreObjectFactoryBase); + itkFactorylessNewMacro(Self); + + Mapper::Pointer CreateMapper(DataNode* node, MapperSlotId slotId); + const char* GetDescription() const; + const char* GetFileExtensions(); + MultimapType GetFileExtensionsMap(); + const char* GetITKSourceVersion() const; + const char* GetSaveFileExtensions(); + MultimapType GetSaveFileExtensionsMap(); + void SetDefaultProperties(DataNode* node); + + private: + SimulationObjectFactory(); + ~SimulationObjectFactory(); + + SimulationObjectFactory(const Self&); + Self& operator=(const Self&); + + SimulationIOFactory::Pointer m_SimulationIOFactory; + MultimapType m_FileExtensionsMap; + MultimapType m_SaveFileExtensionsMap; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationPropAssemblyVisitor.cpp b/Modules/Simulation/mitkSimulationPropAssemblyVisitor.cpp new file mode 100644 index 0000000000..ac546b6e11 --- /dev/null +++ b/Modules/Simulation/mitkSimulationPropAssemblyVisitor.cpp @@ -0,0 +1,51 @@ +/*=================================================================== + +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 "mitkSimulationPropAssemblyVisitor.h" +#include "mitkSimulationModel.h" +#include +#include + +mitk::SimulationPropAssemblyVisitor::SimulationPropAssemblyVisitor(vtkPropAssembly* propAssembly, const sofa::core::ExecParams* params) + : Visitor(params), + m_PropAssembly(propAssembly) +{ +} + +mitk::SimulationPropAssemblyVisitor::~SimulationPropAssemblyVisitor() +{ +} + +sofa::simulation::Visitor::Result mitk::SimulationPropAssemblyVisitor::processNodeTopDown(sofa::simulation::Node* node) +{ + typedef sofa::simulation::Node::Sequence::const_iterator VisualModelIterator; + VisualModelIterator end = node->visualModel.end(); + + for (VisualModelIterator visualModel = node->visualModel.begin(); visualModel != end; ++visualModel) + { + SimulationModel* simulationModel = dynamic_cast(*visualModel); + + if (simulationModel != NULL) + { + std::vector actors = simulationModel->GetActors(); + + for (std::vector::const_iterator actor = actors.begin(); actor != actors.end(); ++actor) + m_PropAssembly->AddPart(*actor); + } + } + + return RESULT_CONTINUE; +} diff --git a/Modules/Simulation/mitkSimulationPropAssemblyVisitor.h b/Modules/Simulation/mitkSimulationPropAssemblyVisitor.h new file mode 100644 index 0000000000..5bb8be8294 --- /dev/null +++ b/Modules/Simulation/mitkSimulationPropAssemblyVisitor.h @@ -0,0 +1,43 @@ +/*=================================================================== + +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 mitkSimulationPropAssemblyVisitor_h +#define mitkSimulationPropAssemblyVisitor_h + +#include +#include + +class vtkPropAssembly; + +namespace mitk +{ + class Simulation_EXPORT SimulationPropAssemblyVisitor : public sofa::simulation::Visitor + { + public: + explicit SimulationPropAssemblyVisitor(vtkPropAssembly* propAssembly, const sofa::core::ExecParams* params = sofa::core::ExecParams::defaultInstance()); + ~SimulationPropAssemblyVisitor(); + + Result processNodeTopDown(sofa::simulation::Node* node); + + private: + SimulationPropAssemblyVisitor(const SimulationPropAssemblyVisitor&); + SimulationPropAssemblyVisitor& operator=(const SimulationPropAssemblyVisitor&); + + vtkPropAssembly* m_PropAssembly; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulationReader.cpp b/Modules/Simulation/mitkSimulationReader.cpp new file mode 100644 index 0000000000..c2f1c84b1f --- /dev/null +++ b/Modules/Simulation/mitkSimulationReader.cpp @@ -0,0 +1,114 @@ +/*=================================================================== + +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 "mitkSimulation.h" +#include "mitkSimulationReader.h" +#include +#include +#include + +bool mitk::SimulationReader::CanReadFile(const std::string& filename, const std::string&, const std::string&) +{ + std::string::size_type length = filename.length(); + + if (length < 5) + return false; + + std::string ext = filename.substr(length - 4); + std::transform(ext.begin(), ext.end(), ext.begin(), tolower); + + if (ext == ".scn" || ext == ".xml") + return true; + + return false; +} + +mitk::SimulationReader::SimulationReader() +{ + mitk::Simulation::Pointer output = mitk::Simulation::New(); + + this->SetNumberOfRequiredOutputs(1); + this->SetNthOutput(0, output.GetPointer()); +} + +mitk::SimulationReader::~SimulationReader() +{ +} + +void mitk::SimulationReader::GenerateData() +{ + Simulation::Pointer simulation = dynamic_cast(this->GetOutput(0)); + sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); + + sofa::simulation::Simulation::SPtr currentSofaSimulation = sofa::simulation::getSimulation(); + sofa::core::visual::VisualParams* visualParams = sofa::core::visual::VisualParams::defaultInstance(); + sofa::core::visual::DrawTool* currentDrawTool = visualParams->drawTool(); + + simulation->SetAsActiveSimulation(); + + std::string path = sofa::helper::system::SetDirectory::GetParentDir(m_FileName.c_str()); + sofa::helper::system::DataRepository.addFirstPath(path); + sofa::simulation::Node::SPtr rootNode = sofa::core::objectmodel::SPtr_dynamic_cast(sofaSimulation->load(m_FileName.c_str())); + + if (rootNode == NULL) + { + sofa::helper::system::DataRepository.removePath(path); + mitkThrow() << "Could not load '" << m_FileName << "'!"; + } + + simulation->SetRootNode(rootNode.get()); + simulation->SetDefaultDT(rootNode->getDt()); + sofaSimulation->init(rootNode.get()); + + sofa::helper::system::DataRepository.removePath(path); + + sofa::simulation::setSimulation(currentSofaSimulation.get()); + visualParams->drawTool() = currentDrawTool; +} + +void mitk::SimulationReader::GenerateOutputInformation() +{ +} + +const char* mitk::SimulationReader::GetFileName() const +{ + return m_FileName.c_str(); +} + +void mitk::SimulationReader::SetFileName(const char* aFileName) +{ + m_FileName = aFileName; +} + +const char* mitk::SimulationReader::GetFilePattern() const +{ + return m_FilePattern.c_str(); +} + +void mitk::SimulationReader::SetFilePattern(const char* aFilePattern) +{ + m_FilePattern = aFilePattern; +} + +const char* mitk::SimulationReader::GetFilePrefix() const +{ + return m_FilePrefix.c_str(); +} + +void mitk::SimulationReader::SetFilePrefix(const char* aFilePrefix) +{ + m_FilePrefix = aFilePrefix; +} diff --git a/Modules/Simulation/mitkSimulationReader.h b/Modules/Simulation/mitkSimulationReader.h new file mode 100644 index 0000000000..8d8783ac6a --- /dev/null +++ b/Modules/Simulation/mitkSimulationReader.h @@ -0,0 +1,59 @@ +/*=================================================================== + +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 mitkSimulationReader_h +#define mitkSimulationReader_h + +#include +#include + +namespace mitk +{ + class Simulation_EXPORT SimulationReader : public BaseProcess, FileReader + { + public: + static bool CanReadFile(const std::string& filename, const std::string& filePrefix, const std::string& filePattern); + + mitkClassMacro(SimulationReader, BaseProcess); + itkNewMacro(Self); + + const char* GetFileName() const; + void SetFileName(const char* aFileName); + + const char* GetFilePattern() const; + void SetFilePattern(const char* aFilePattern); + + const char* GetFilePrefix() const; + void SetFilePrefix(const char* aFilePrefix); + + protected: + void GenerateData(); + void GenerateOutputInformation(); + + private: + SimulationReader(); + ~SimulationReader(); + + SimulationReader(const Self &); + Self & operator=(const Self &); + + std::string m_FileName; + std::string m_FilePattern; + std::string m_FilePrefix; + }; +} + +#endif diff --git a/Plugins/PluginList.cmake b/Plugins/PluginList.cmake index 1cf526d180..fdd1f7f287 100644 --- a/Plugins/PluginList.cmake +++ b/Plugins/PluginList.cmake @@ -1,43 +1,44 @@ # Plug-ins must be ordered according to their dependencies set(MITK_EXT_PLUGINS org.mitk.core.services:ON org.mitk.gui.common:ON org.mitk.planarfigure:ON org.mitk.core.ext:OFF org.mitk.core.jobs:OFF org.mitk.diffusionimaging:OFF org.mitk.gui.qt.application:ON org.mitk.gui.qt.coreapplication:OFF org.mitk.gui.qt.ext:OFF org.mitk.gui.qt.extapplication:OFF org.mitk.gui.qt.common:ON org.mitk.gui.qt.stdmultiwidgeteditor:ON org.mitk.gui.qt.common.legacy:OFF org.mitk.gui.qt.diffusionimagingapp:OFF org.mitk.gui.qt.datamanager:ON org.mitk.gui.qt.basicimageprocessing:OFF org.mitk.gui.qt.dicom:OFF org.mitk.gui.qt.diffusionimaging:OFF org.mitk.gui.qt.dtiatlasapp:OFF org.mitk.gui.qt.examples:OFF org.mitk.gui.qt.examplesopencv:OFF org.mitk.gui.qt.igtexamples:OFF org.mitk.gui.qt.igttracking:OFF org.mitk.gui.qt.imagecropper:OFF org.mitk.gui.qt.imagenavigator:ON org.mitk.gui.qt.materialeditor:OFF org.mitk.gui.qt.measurementtoolbox:OFF org.mitk.gui.qt.meshdecimation:OFF org.mitk.gui.qt.moviemaker:OFF org.mitk.gui.qt.pointsetinteraction:OFF org.mitk.gui.qt.python.console:OFF org.mitk.gui.qt.registration:OFF org.mitk.gui.qt.segmentation:OFF + org.mitk.gui.qt.simulation:OFF org.mitk.gui.qt.toftutorial:OFF org.mitk.gui.qt.tofutil:OFF org.mitk.gui.qt.ugvisualization:OFF org.mitk.gui.qt.ultrasound:OFF org.mitk.gui.qt.volumevisualization:OFF ) diff --git a/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt b/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt new file mode 100644 index 0000000000..84195b260a --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/CMakeLists.txt @@ -0,0 +1,7 @@ +project(org_mitk_gui_qt_simulation) + +MACRO_CREATE_MITK_CTK_PLUGIN( + EXPORT_DIRECTIVE SIMULATION_EXPORT + EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDENCIES Simulation Qmitk +) diff --git a/Plugins/org.mitk.gui.qt.simulation/files.cmake b/Plugins/org.mitk.gui.qt.simulation/files.cmake new file mode 100644 index 0000000000..74291cf11e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/files.cmake @@ -0,0 +1,36 @@ +set(SRC_CPP_FILES +) + +set(INTERNAL_CPP_FILES + org_mitk_gui_qt_simulation_Activator.cpp + QmitkSimulationView.cpp +) + +set(UI_FILES + src/internal/QmitkSimulationViewControls.ui +) + +set(MOC_H_FILES + src/internal/org_mitk_gui_qt_simulation_Activator.h + src/internal/QmitkSimulationView.h +) + +set(CACHED_RESOURCE_FILES + resources/icon.png + plugin.xml +) + +set(QRC_FILES + resources/Simulation.qrc +) + +set(CPP_FILES +) + +foreach(file ${SRC_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/${file}) +endforeach() + +foreach(file ${INTERNAL_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/internal/${file}) +endforeach() diff --git a/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake new file mode 100644 index 0000000000..912e7b0cf4 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/manifest_headers.cmake @@ -0,0 +1,5 @@ +set(Plugin-Name "MITK Simulation") +set(Plugin-Version "0.1") +set(Plugin-Vendor "DKFZ, Medical and Biological Informatics") +set(Plugin-ContactAddress "http://www.mitk.org") +set(Require-Plugin org.mitk.gui.qt.common) diff --git a/Plugins/org.mitk.gui.qt.simulation/plugin.xml b/Plugins/org.mitk.gui.qt.simulation/plugin.xml new file mode 100644 index 0000000000..36271f5cd6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/plugin.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/Plugins/org.mitk.gui.qt.simulation/resources/Simulation.qrc b/Plugins/org.mitk.gui.qt.simulation/resources/Simulation.qrc new file mode 100644 index 0000000000..1a024c4a65 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/resources/Simulation.qrc @@ -0,0 +1,5 @@ + + + icon.png + + diff --git a/Plugins/org.mitk.gui.qt.simulation/resources/icon.png b/Plugins/org.mitk.gui.qt.simulation/resources/icon.png new file mode 100644 index 0000000000..3e0ce703ea Binary files /dev/null and b/Plugins/org.mitk.gui.qt.simulation/resources/icon.png differ diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp new file mode 100644 index 0000000000..3d99571142 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.cpp @@ -0,0 +1,158 @@ +/*=================================================================== + +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 "QmitkSimulationView.h" +#include +#include +#include +#include + +QmitkSimulationView::QmitkSimulationView() + : m_Timer(this) +{ + connect(&m_Timer, SIGNAL(timeout()), this, SLOT(OnTimerTimeout())); +} + +QmitkSimulationView::~QmitkSimulationView() +{ +} + +void QmitkSimulationView::CreateQtPartControl(QWidget* parent) +{ + m_Controls.setupUi(parent); + + m_Controls.cmbSimulation->SetDataStorage(this->GetDataStorage()); + m_Controls.cmbSimulation->SetPredicate(mitk::NodePredicateDataType::New("Simulation")); + + connect(m_Controls.btnAnimate, SIGNAL(toggled(bool)), this, SLOT(OnAnimateButtonToggled(bool))); + connect(m_Controls.btnResetScene, SIGNAL(clicked()), this, SLOT(OnResetSceneButtonClicked())); + connect(m_Controls.btnStep, SIGNAL(clicked()), this, SLOT(OnStepButtonClicked())); + connect(m_Controls.cmbSimulation, SIGNAL(OnSelectionChanged(const mitk::DataNode*)), this, SLOT(OnSimulationComboBoxSelectionChanged(const mitk::DataNode*))); + connect(m_Controls.spnDT, SIGNAL(valueChanged(double)), this, SLOT(OnDTSpinBoxValueChanged(double))); +} + +void QmitkSimulationView::OnAnimateButtonToggled(bool toggled) +{ + if (SetSelectionAsCurrentSimulation()) + { + mitk::Simulation::Pointer simulation = dynamic_cast(m_Controls.cmbSimulation->GetSelectedNode()->GetData()); + sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); + sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); + + rootNode->getContext()->setAnimate(toggled); + + if (toggled) + { + m_Controls.btnStep->setEnabled(false); + m_Timer.start(0); + } + } + + if (!toggled) + { + m_Timer.stop(); + m_Controls.btnStep->setEnabled(true); + } +} + +void QmitkSimulationView::OnDTSpinBoxValueChanged(double value) +{ + if (SetSelectionAsCurrentSimulation()) + { + mitk::Simulation::Pointer simulation = dynamic_cast(m_Controls.cmbSimulation->GetSelectedNode()->GetData()); + sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); + + rootNode->setDt(value == 0.0 + ? simulation->GetDefaultDT() + : value); + } +} + +void QmitkSimulationView::OnResetSceneButtonClicked() +{ + if (SetSelectionAsCurrentSimulation()) + { + mitk::Simulation::Pointer simulation = dynamic_cast(m_Controls.cmbSimulation->GetSelectedNode()->GetData()); + sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); + sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); + + m_Controls.spnDT->setValue(0.0); + sofaSimulation->reset(rootNode.get()); + + rootNode->setTime(0.0); + rootNode->execute(sofa::core::ExecParams::defaultInstance()); + + simulation->GetDrawTool()->Reset(); + + this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS); + } +} + +void QmitkSimulationView::OnSimulationComboBoxSelectionChanged(const mitk::DataNode* node) +{ + if (m_Controls.btnAnimate->isChecked()) + m_Controls.btnAnimate->setChecked(false); + + if (node != NULL) + { + m_Controls.grpSimulation->setEnabled(true); + static_cast(node->GetData())->SetAsActiveSimulation(); + } + else + { + m_Controls.grpSimulation->setEnabled(false); + mitk::Simulation::SetActiveSimulation(NULL); + } +} + +void QmitkSimulationView::OnStepButtonClicked() +{ + if (SetSelectionAsCurrentSimulation()) + { + mitk::Simulation::Pointer simulation = dynamic_cast(m_Controls.cmbSimulation->GetSelectedNode()->GetData()); + sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSimulation(); + sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode(); + + simulation->GetDrawTool()->Reset(); + + sofaSimulation->animate(rootNode.get(), rootNode->getDt()); + + this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS); + } +} + +void QmitkSimulationView::SetFocus() +{ + m_Controls.btnAnimate->setFocus(); +} + +bool QmitkSimulationView::SetSelectionAsCurrentSimulation() const +{ + mitk::DataNode::Pointer selectedNode = m_Controls.cmbSimulation->GetSelectedNode(); + + if (selectedNode.IsNotNull()) + { + static_cast(m_Controls.cmbSimulation->GetSelectedNode()->GetData())->SetAsActiveSimulation(); + return true; + } + + return false; +} + +void QmitkSimulationView::OnTimerTimeout() +{ + this->OnStepButtonClicked(); +} diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.h b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.h new file mode 100644 index 0000000000..ffce7519ae --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationView.h @@ -0,0 +1,53 @@ +/*=================================================================== + +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 QmitkSimulationView_h +#define QmitkSimulationView_h + +#include +#include +#include + +class QmitkSimulationView : public QmitkAbstractView +{ + Q_OBJECT + +public: + QmitkSimulationView(); + ~QmitkSimulationView(); + + void CreateQtPartControl(QWidget* parent); + void SetFocus(); + +private: + QmitkSimulationView(const QmitkSimulationView&); + QmitkSimulationView& operator=(const QmitkSimulationView&); + + bool SetSelectionAsCurrentSimulation() const; + + Ui::QmitkSimulationViewControls m_Controls; + QTimer m_Timer; + +private slots: + void OnAnimateButtonToggled(bool toggled); + void OnDTSpinBoxValueChanged(double value); + void OnResetSceneButtonClicked(); + void OnSimulationComboBoxSelectionChanged(const mitk::DataNode* node); + void OnStepButtonClicked(); + void OnTimerTimeout(); +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationViewControls.ui b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationViewControls.ui new file mode 100644 index 0000000000..5ee48dfb0d --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/QmitkSimulationViewControls.ui @@ -0,0 +1,167 @@ + + + QmitkSimulationViewControls + + + true + + + + 0 + 0 + 301 + 548 + + + + Simulation + + + + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + + + + Simulation + + + + + + + + 0 + 0 + + + + + + + + + + false + + + + + + + + + + 0 + 0 + + + + Animate + + + true + + + false + + + + + + + + 0 + 0 + + + + Step + + + + + + + + 0 + 0 + + + + Reset Scene + + + + + + + + + + 0 + 0 + + + + dt + + + + + + + + 0 + 0 + + + + s + + + 3 + + + 0.010000000000000 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 421 + + + + + + + + + QmitkDataStorageComboBox + QWidget +
QmitkDataStorageComboBox.h
+
+
+ + +
diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp b/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp new file mode 100644 index 0000000000..3a15490521 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.cpp @@ -0,0 +1,40 @@ +/*=================================================================== + +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 "org_mitk_gui_qt_simulation_Activator.h" +#include "QmitkSimulationView.h" +#include +#include +#include + +void mitk::org_mitk_gui_qt_simulation_Activator::start(ctkPluginContext* context) +{ + BERRY_REGISTER_EXTENSION_CLASS(QmitkSimulationView, context); + + QmitkNodeDescriptorManager* nodeDescriptorManager = QmitkNodeDescriptorManager::GetInstance(); + + if (nodeDescriptorManager != NULL) + { + mitk::NodePredicateDataType::Pointer isSimulation = mitk::NodePredicateDataType::New("Simulation"); + nodeDescriptorManager->AddDescriptor(new QmitkNodeDescriptor("Simulation", ":/Simulation/icon.png", isSimulation, nodeDescriptorManager)); + } +} + +void mitk::org_mitk_gui_qt_simulation_Activator::stop(ctkPluginContext*) +{ +} + +Q_EXPORT_PLUGIN2(org_mitk_gui_qt_simulation, mitk::org_mitk_gui_qt_simulation_Activator) diff --git a/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.h b/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.h new file mode 100644 index 0000000000..b84b8a02f5 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.simulation/src/internal/org_mitk_gui_qt_simulation_Activator.h @@ -0,0 +1,35 @@ +/*=================================================================== + +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 org_mitk_gui_qt_simulation_Activator_h +#define org_mitk_gui_qt_simulation_Activator_h + +#include + +namespace mitk +{ + class org_mitk_gui_qt_simulation_Activator : public QObject, public ctkPluginActivator + { + Q_OBJECT + Q_INTERFACES(ctkPluginActivator) + + public: + void start(ctkPluginContext* context); + void stop(ctkPluginContext* context); + }; +} + +#endif diff --git a/SuperBuild.cmake b/SuperBuild.cmake index 7faaab094d..a23d2bce16 100644 --- a/SuperBuild.cmake +++ b/SuperBuild.cmake @@ -1,304 +1,308 @@ #----------------------------------------------------------------------------- # Convenient macro allowing to download a file #----------------------------------------------------------------------------- macro(downloadFile url dest) file(DOWNLOAD ${url} ${dest} STATUS status) list(GET status 0 error_code) list(GET status 1 error_msg) if(error_code) message(FATAL_ERROR "error: Failed to download ${url} - ${error_msg}") endif() endmacro() #----------------------------------------------------------------------------- # MITK Prerequisites #----------------------------------------------------------------------------- if(UNIX AND NOT APPLE) include(mitkFunctionCheckPackageHeader) # Check for libxt-dev mitkFunctionCheckPackageHeader(StringDefs.h libxt-dev /usr/include/X11/) # Check for libtiff4-dev mitkFunctionCheckPackageHeader(tiff.h libtiff4-dev) # Check for libwrap0-dev mitkFunctionCheckPackageHeader(tcpd.h libwrap0-dev) endif() #----------------------------------------------------------------------------- # ExternalProjects #----------------------------------------------------------------------------- set(external_projects VTK GDCM CableSwig ITK Boost DCMTK CTK OpenCV + SOFA MITKData ) set(MITK_USE_CableSwig ${MITK_USE_Python}) set(MITK_USE_GDCM 1) set(MITK_USE_ITK 1) set(MITK_USE_VTK 1) -foreach(proj VTK GDCM CableSwig ITK DCMTK CTK OpenCV) +foreach(proj VTK GDCM CableSwig ITK DCMTK CTK OpenCV SOFA) if(MITK_USE_${proj}) set(EXTERNAL_${proj}_DIR "${${proj}_DIR}" CACHE PATH "Path to ${proj} build directory") mark_as_advanced(EXTERNAL_${proj}_DIR) if(EXTERNAL_${proj}_DIR) set(${proj}_DIR ${EXTERNAL_${proj}_DIR}) endif() endif() endforeach() if(MITK_USE_Boost) set(EXTERNAL_BOOST_ROOT "${BOOST_ROOT}" CACHE PATH "Path to Boost directory") mark_as_advanced(EXTERNAL_BOOST_ROOT) if(EXTERNAL_BOOST_ROOT) set(BOOST_ROOT ${EXTERNAL_BOOST_ROOT}) endif() endif() if(BUILD_TESTING) set(EXTERNAL_MITK_DATA_DIR "${MITK_DATA_DIR}" CACHE PATH "Path to the MITK data directory") mark_as_advanced(EXTERNAL_MITK_DATA_DIR) if(EXTERNAL_MITK_DATA_DIR) set(MITK_DATA_DIR ${EXTERNAL_MITK_DATA_DIR}) endif() endif() # Look for git early on, if needed if((BUILD_TESTING AND NOT EXTERNAL_MITK_DATA_DIR) OR (MITK_USE_CTK AND NOT EXTERNAL_CTK_DIR)) find_package(Git REQUIRED) endif() #----------------------------------------------------------------------------- # External project settings #----------------------------------------------------------------------------- include(ExternalProject) set(ep_base "${CMAKE_BINARY_DIR}/CMakeExternals") set_property(DIRECTORY PROPERTY EP_BASE ${ep_base}) set(ep_install_dir ${ep_base}/Install) #set(ep_build_dir ${ep_base}/Build) set(ep_source_dir ${ep_base}/Source) #set(ep_parallelism_level) set(ep_build_shared_libs ON) set(ep_build_testing OFF) if(NOT MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL) set(MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL http://mitk.org/download/thirdparty) endif() # Compute -G arg for configuring external projects with the same CMake generator: if(CMAKE_EXTRA_GENERATOR) set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}") else() set(gen "${CMAKE_GENERATOR}") endif() # Use this value where semi-colons are needed in ep_add args: set(sep "^^") ## if(MSVC90 OR MSVC10) set(ep_common_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /MP") set(ep_common_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP") else() set(ep_common_C_FLAGS "${CMAKE_C_FLAGS} -DLINUX_EXTRA") set(ep_common_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLINUX_EXTRA") endif() set(ep_common_args -DBUILD_TESTING:BOOL=${ep_build_testing} -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir} -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} -DCMAKE_C_FLAGS:STRING=${ep_common_C_FLAGS} -DCMAKE_CXX_FLAGS:STRING=${ep_common_CXX_FLAGS} #debug flags -DCMAKE_CXX_FLAGS_DEBUG:STRING=${CMAKE_CXX_FLAGS_DEBUG} -DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG} #release flags -DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE} -DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE} #relwithdebinfo -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO} ) # Include external projects foreach(p ${external_projects}) include(CMakeExternals/${p}.cmake) endforeach() #----------------------------------------------------------------------------- # Set superbuild boolean args #----------------------------------------------------------------------------- set(mitk_cmake_boolean_args BUILD_SHARED_LIBS WITH_COVERAGE BUILD_TESTING MITK_USE_QT MITK_BUILD_ALL_PLUGINS MITK_BUILD_ALL_APPS MITK_BUILD_TUTORIAL # Deprecated. Use MITK_BUILD_EXAMPLES instead MITK_BUILD_EXAMPLES MITK_USE_Boost MITK_USE_SYSTEM_Boost MITK_USE_BLUEBERRY MITK_USE_CTK MITK_USE_DCMTK MITK_DCMTK_BUILD_SHARED_LIBS MITK_USE_OpenCV + MITK_USE_SOFA MITK_USE_Python MITK_USE_OpenCL ) #----------------------------------------------------------------------------- # Create the final variable containing superbuild boolean args #----------------------------------------------------------------------------- set(mitk_superbuild_boolean_args) foreach(mitk_cmake_arg ${mitk_cmake_boolean_args}) list(APPEND mitk_superbuild_boolean_args -D${mitk_cmake_arg}:BOOL=${${mitk_cmake_arg}}) endforeach() if(MITK_BUILD_ALL_PLUGINS) list(APPEND mitk_superbuild_boolean_args -DBLUEBERRY_BUILD_ALL_PLUGINS:BOOL=ON) endif() #----------------------------------------------------------------------------- # MITK Utilities #----------------------------------------------------------------------------- set(proj MITK-Utilities) ExternalProject_Add(${proj} DOWNLOAD_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS # Mandatory dependencies ${VTK_DEPENDS} ${ITK_DEPENDS} # Optionnal dependencies ${Boost_DEPENDS} ${CTK_DEPENDS} ${DCMTK_DEPENDS} ${OpenCV_DEPENDS} + ${SOFA_DEPENDS} ${MITK-Data_DEPENDS} ) #----------------------------------------------------------------------------- # MITK Configure #----------------------------------------------------------------------------- if(MITK_INITIAL_CACHE_FILE) set(mitk_initial_cache_arg -C "${MITK_INITIAL_CACHE_FILE}") endif() set(mitk_optional_cache_args ) foreach(type RUNTIME ARCHIVE LIBRARY) if(DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY) list(APPEND mitk_optional_cache_args -DCTK_PLUGIN_${type}_OUTPUT_DIRECTORY:PATH=${CTK_PLUGIN_${type}_OUTPUT_DIRECTORY}) endif() endforeach() set(proj MITK-Configure) ExternalProject_Add(${proj} LIST_SEPARATOR ^^ DOWNLOAD_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_CACHE_ARGS ${ep_common_args} ${mitk_superbuild_boolean_args} ${mitk_optional_cache_args} -DMITK_USE_SUPERBUILD:BOOL=OFF -DMITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${MITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY} -DMITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY} -DMITK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${MITK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY} -DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS} -DMITK_CTEST_SCRIPT_MODE:STRING=${MITK_CTEST_SCRIPT_MODE} -DMITK_SUPERBUILD_BINARY_DIR:PATH=${MITK_BINARY_DIR} -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DMITK_KWSTYLE_EXECUTABLE:FILEPATH=${MITK_KWSTYLE_EXECUTABLE} -DMITK_MODULES_TO_BUILD:INTERNAL=${MITK_MODULES_TO_BUILD} -DCTK_DIR:PATH=${CTK_DIR} -DDCMTK_DIR:PATH=${DCMTK_DIR} -DVTK_DIR:PATH=${VTK_DIR} # FindVTK expects VTK_DIR -DITK_DIR:PATH=${ITK_DIR} # FindITK expects ITK_DIR -DOpenCV_DIR:PATH=${OpenCV_DIR} + -DSOFA_DIR:PATH=${SOFA_DIR} -DGDCM_DIR:PATH=${GDCM_DIR} -DBOOST_ROOT:PATH=${BOOST_ROOT} -DMITK_USE_Boost_LIBRARIES:STRING=${MITK_USE_Boost_LIBRARIES} -DMITK_DATA_DIR:PATH=${MITK_DATA_DIR} -DMITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES} -DMITK_ACCESSBYITK_FLOATING_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES} -DMITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES} -DMITK_ACCESSBYITK_DIMENSIONS:STRING=${MITK_ACCESSBYITK_DIMENSIONS} CMAKE_ARGS ${mitk_initial_cache_arg} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} BINARY_DIR ${CMAKE_BINARY_DIR}/MITK-build BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS MITK-Utilities ) #----------------------------------------------------------------------------- # MITK #----------------------------------------------------------------------------- if(CMAKE_GENERATOR MATCHES ".*Makefiles.*") set(mitk_build_cmd "$(MAKE)") else() set(mitk_build_cmd ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/MITK-build --config ${CMAKE_CFG_INTDIR}) endif() if(NOT DEFINED SUPERBUILD_EXCLUDE_MITKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_MITKBUILD_TARGET) set(MITKBUILD_TARGET_ALL_OPTION "ALL") else() set(MITKBUILD_TARGET_ALL_OPTION "") endif() add_custom_target(MITK-build ${MITKBUILD_TARGET_ALL_OPTION} COMMAND ${mitk_build_cmd} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/MITK-build DEPENDS MITK-Configure ) #----------------------------------------------------------------------------- # Custom target allowing to drive the build of the MITK project itself #----------------------------------------------------------------------------- add_custom_target(MITK COMMAND ${mitk_build_cmd} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/MITK-build )