diff --git a/CMake/mitkMacroCreateModule.cmake b/CMake/mitkMacroCreateModule.cmake index d9d6f7e590..afdff7873b 100644 --- a/CMake/mitkMacroCreateModule.cmake +++ b/CMake/mitkMacroCreateModule.cmake @@ -1,438 +1,440 @@ ################################################################## # # MITK_CREATE_MODULE # #! Creates a module for the automatic module dependency system within MITK. #! Configurations are generated in the moduleConf directory. #! #! USAGE: #! #! \code #! MITK_CREATE_MODULE( #! [INCLUDE_DIRS ] #! [INTERNAL_INCLUDE_DIRS ] #! [DEPENDS ] #! [PACKAGE_DEPENDS ] #! [TARGET_DEPENDS #! [EXPORT_DEFINE ] #! [QT_MODULE] #! [HEADERS_ONLY] #! [WARNINGS_AS_ERRORS] #! \endcode #! #! \param MODULE_NAME_IN The name for the new module #! \param HEADERS_ONLY specify this if the modules just contains header files. ################################################################## macro(MITK_CREATE_MODULE MODULE_NAME_IN) set(_macro_params SUBPROJECTS # list of CDash labels VERSION # module version number, e.g. "1.2.0" INCLUDE_DIRS # exported include dirs (used in mitkMacroCreateModuleConf.cmake) INTERNAL_INCLUDE_DIRS # include dirs internal to this module DEPENDS # list of modules this module depends on DEPENDS_INTERNAL # list of modules this module internally depends on PACKAGE_DEPENDS # list of "packages this module depends on (e.g. Qt, VTK, etc.) TARGET_DEPENDS # list of CMake targets this module should depend on EXPORT_DEFINE # export macro name for public symbols of this module AUTOLOAD_WITH # a module target name identifying the module which will trigger the # automatic loading of this module ADDITIONAL_LIBS # list of addidtional libraries linked to this module GENERATED_CPP # not used (?) DEPRECATED_SINCE # marks this modules as deprecated ) set(_macro_options QT_MODULE # the module makes use of Qt features and needs moc and ui generated files FORCE_STATIC # force building this module as a static library HEADERS_ONLY # this module is a headers-only library GCC_DEFAULT_VISIBILITY # do not use gcc visibility flags - all symbols will be exported NO_INIT # do not create CppMicroServices initialization code WARNINGS_AS_ERRORS # treat all compiler warnings as errors ) MACRO_PARSE_ARGUMENTS(MODULE "${_macro_params}" "${_macro_options}" ${ARGN}) set(MODULE_NAME ${MODULE_NAME_IN}) if(MODULE_HEADERS_ONLY) set(MODULE_PROVIDES ) if(MODULE_AUTOLOAD_WITH) message(SEND_ERROR "A headers only module cannot be auto-loaded") endif() else() set(MODULE_PROVIDES ${MODULE_NAME}) if(NOT MODULE_NO_INIT AND NOT MODULE_NAME STREQUAL "Mitk") # Add a dependency to the "Mitk" module #list(APPEND MODULE_DEPENDS Mitk) endif() endif() if(MODULE_DEPRECATED_SINCE) set(MODULE_IS_DEPRECATED 1) else() set(MODULE_IS_DEPRECATED 0) endif() if(NOT MODULE_SUBPROJECTS) if(MITK_DEFAULT_SUBPROJECTS) set(MODULE_SUBPROJECTS ${MITK_DEFAULT_SUBPROJECTS}) endif() endif() # check if the subprojects exist as targets if(MODULE_SUBPROJECTS) foreach(subproject ${MODULE_SUBPROJECTS}) if(NOT TARGET ${subproject}) message(SEND_ERROR "The subproject ${subproject} does not have a corresponding target") endif() endforeach() endif() # check and set-up auto-loading if(MODULE_AUTOLOAD_WITH) if(NOT TARGET "${MODULE_AUTOLOAD_WITH}") message(SEND_ERROR "The module target \"${MODULE_AUTOLOAD_WITH}\" specified as the auto-loading module for \"${MODULE_NAME}\" does not exist") endif() # create a meta-target if it does not already exist set(_module_autoload_meta_target "${MODULE_AUTOLOAD_WITH}-universe") if(NOT TARGET ${_module_autoload_meta_target}) add_custom_target(${_module_autoload_meta_target}) endif() endif() # assume worst case set(MODULE_IS_ENABLED 0) # first we check if we have an explicit module build list if(MITK_MODULES_TO_BUILD) list(FIND MITK_MODULES_TO_BUILD ${MODULE_NAME} _MOD_INDEX) if(_MOD_INDEX EQUAL -1) set(MODULE_IS_EXCLUDED 1) endif() endif() if(NOT MODULE_IS_EXCLUDED AND NOT (MODULE_QT_MODULE AND NOT MITK_USE_QT)) # first of all we check for the dependencies MITK_CHECK_MODULE(_MISSING_DEP ${MODULE_DEPENDS}) if(_MISSING_DEP) message("Module ${MODULE_NAME} won't be built, missing dependency: ${_MISSING_DEP}") set(MODULE_IS_ENABLED 0) else(_MISSING_DEP) set(MODULE_IS_ENABLED 1) # now check for every package if it is enabled. This overlaps a bit with # MITK_CHECK_MODULE ... foreach(_package ${MODULE_PACKAGE_DEPENDS}) if((DEFINED MITK_USE_${_package}) AND NOT (MITK_USE_${_package})) message("Module ${MODULE_NAME} won't be built. Turn on MITK_USE_${_package} if you want to use it.") set(MODULE_IS_ENABLED 0) endif() endforeach() if(MODULE_IS_ENABLED) # clear variables defined in files.cmake set(RESOURCE_FILES ) set(CPP_FILES ) set(H_FILES ) set(TXX_FILES ) set(DOX_FILES ) set(UI_FILES ) set(MOC_H_FILES ) set(QRC_FILES ) # clear other variables set(Q${KITNAME}_GENERATED_MOC_CPP ) set(Q${KITNAME}_GENERATED_QRC_CPP ) set(Q${KITNAME}_GENERATED_UI_CPP ) set(Q${KITNAME}_GENERATED_CPP ) _MITK_CREATE_MODULE_CONF() if(NOT MODULE_EXPORT_DEFINE) set(MODULE_EXPORT_DEFINE ${MODULE_NAME}_EXPORT) endif(NOT MODULE_EXPORT_DEFINE) if(MITK_GENERATE_MODULE_DOT) message("MODULEDOTNAME ${MODULE_NAME}") foreach(dep ${MODULE_DEPENDS}) message("MODULEDOT \"${MODULE_NAME}\" -> \"${dep}\" ; ") endforeach(dep) endif(MITK_GENERATE_MODULE_DOT) set(DEPENDS "${MODULE_DEPENDS}") if(NOT MODULE_NO_INIT) # Add a CppMicroServices dependency implicitly, since it is # needed for the generated "module initialization" code. set(DEPENDS "CppMicroServices;${DEPENDS}") endif() set(DEPENDS_BEFORE "not initialized") set(PACKAGE_DEPENDS "${MODULE_PACKAGE_DEPENDS}") MITK_USE_MODULE(${DEPENDS}) # ok, now create the module itself include_directories(. ${ALL_INCLUDE_DIRECTORIES}) include(files.cmake) set(module_c_flags ) set(module_c_flags_debug ) set(module_c_flags_release ) set(module_cxx_flags ) set(module_cxx_flags_debug ) set(module_cxx_flags_release ) if(MODULE_GCC_DEFAULT_VISIBILITY) set(use_visibility_flags 0) else() # We only support hidden visibility for gcc for now. Clang 3.0 still has troubles with # correctly marking template declarations and explicit template instantiations as exported. # See http://comments.gmane.org/gmane.comp.compilers.clang.scm/50028 # and http://llvm.org/bugs/show_bug.cgi?id=10113 if(CMAKE_COMPILER_IS_GNUCXX) set(use_visibility_flags 1) else() # set(use_visibility_flags 0) endif() endif() if(CMAKE_COMPILER_IS_GNUCXX) # MinGW does not export all symbols automatically, so no need to set flags. # # With gcc < 4.5, RTTI symbols from classes declared in third-party libraries # which are not "gcc visibility aware" are marked with hidden visibility in # DSOs which include the class declaration and which are compiled with # hidden visibility. This leads to dynamic_cast and exception handling problems. # While this problem could be worked around by sandwiching the include # directives for the third-party headers between "#pragma visibility push/pop" # statements, it is generally safer to just use default visibility with # gcc < 4.5. if(${GCC_VERSION} VERSION_LESS "4.5" OR MINGW) set(use_visibility_flags 0) endif() endif() if(use_visibility_flags) mitkFunctionCheckCAndCXXCompilerFlags("-fvisibility=hidden" module_c_flags module_cxx_flags) mitkFunctionCheckCAndCXXCompilerFlags("-fvisibility-inlines-hidden" module_c_flags module_cxx_flags) endif() configure_file(${MITK_SOURCE_DIR}/CMake/moduleExports.h.in ${CMAKE_BINARY_DIR}/${MODULES_CONF_DIRNAME}/${MODULE_NAME}Exports.h @ONLY) if(MODULE_WARNINGS_AS_ERRORS) if(MSVC_VERSION) mitkFunctionCheckCAndCXXCompilerFlags("/WX" module_c_flags module_cxx_flags) else() mitkFunctionCheckCAndCXXCompilerFlags("-Werror" module_c_flags module_cxx_flags) # The flag "c++0x-static-nonintegral-init" has been renamed in newer Clang # versions to "static-member-init", see # http://clang-developers.42468.n3.nabble.com/Wc-0x-static-nonintegral-init-gone-td3999651.html # # Also, older Clang and seemingly all gcc versions do not warn if unknown # "-no-*" flags are used, so CMake will happily append any -Wno-* flag to the # command line. This may get confusing if unrelated compiler errors happen and # the error output then additionally contains errors about unknown flags (which # is not the case if there were no compile errors). # # So instead of using -Wno-* we use -Wno-error=*, which will be properly rejected by # the compiler and if applicable, prints the specific warning as a real warning and # not as an error (although -Werror was given). mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=c++0x-static-nonintegral-init" module_c_flags module_cxx_flags) mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=static-member-init" module_c_flags module_cxx_flags) mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=unknown-warning" module_c_flags module_cxx_flags) mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=gnu" module_c_flags module_cxx_flags) # VNL headers throw a lot of these, not fixable for us at least in ITK 3 mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=unused-parameter" module_c_flags module_cxx_flags) # Some DICOM header file in ITK mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=cast-align" module_c_flags module_cxx_flags) endif() endif(MODULE_WARNINGS_AS_ERRORS) if(MODULE_FORCE_STATIC) set(_STATIC STATIC) else() set(_STATIC ) endif(MODULE_FORCE_STATIC) if(NOT MODULE_HEADERS_ONLY) set(MODULE_LIBNAME ${MODULE_PROVIDES}) if(NOT MODULE_NO_INIT) usFunctionGenerateModuleInit(CPP_FILES NAME ${MODULE_NAME} LIBRARY_NAME ${MODULE_LIBNAME} DEPENDS ${MODULE_DEPENDS} ${MODULE_DEPENDS_INTERNAL} ${MODULE_PACKAGE_DEPENDS} #VERSION ${MODULE_VERSION} ) endif() if(RESOURCE_FILES) set(res_dir Resources) set(binary_res_files ) set(source_res_files ) foreach(res_file ${RESOURCE_FILES}) if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}/${res_file}) list(APPEND binary_res_files "${res_file}") else() list(APPEND source_res_files "${res_file}") endif() endforeach() set(res_macro_args ) if(binary_res_files) list(APPEND res_macro_args ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${res_dir} FILES ${binary_res_files}) endif() if(source_res_files) list(APPEND res_macro_args ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${res_dir} FILES ${source_res_files}) endif() usFunctionEmbedResources(CPP_FILES LIBRARY_NAME ${MODULE_LIBNAME} ${res_macro_args}) endif() endif() if(MODULE_QT_MODULE) if(UI_FILES) QT4_WRAP_UI(Q${KITNAME}_GENERATED_UI_CPP ${UI_FILES}) endif(UI_FILES) if(MOC_H_FILES) QT4_WRAP_CPP(Q${KITNAME}_GENERATED_MOC_CPP ${MOC_H_FILES} OPTIONS -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) endif(MOC_H_FILES) if(QRC_FILES) QT4_ADD_RESOURCES(Q${KITNAME}_GENERATED_QRC_CPP ${QRC_FILES}) endif(QRC_FILES) set(Q${KITNAME}_GENERATED_CPP ${Q${KITNAME}_GENERATED_CPP} ${Q${KITNAME}_GENERATED_UI_CPP} ${Q${KITNAME}_GENERATED_MOC_CPP} ${Q${KITNAME}_GENERATED_QRC_CPP}) endif() ORGANIZE_SOURCES(SOURCE ${CPP_FILES} HEADER ${H_FILES} TXX ${TXX_FILES} DOC ${DOX_FILES} UI ${UI_FILES} QRC ${QRC_FILES} MOC ${Q${KITNAME}_GENERATED_MOC_CPP} GEN_QRC ${Q${KITNAME}_GENERATED_QRC_CPP} GEN_UI ${Q${KITNAME}_GENERATED_UI_CPP}) set(coverage_sources ${CPP_FILES} ${H_FILES} ${GLOBBED__H_FILES} ${CORRESPONDING__H_FILES} ${TXX_FILES} ${TOOL_CPPS} ${TOOL_GUI_CPPS}) if(MODULE_SUBPROJECTS) set_property(SOURCE ${coverage_sources} APPEND PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK) endif() if(NOT MODULE_HEADERS_ONLY) if(ALL_LIBRARY_DIRS) # LINK_DIRECTORIES applies only to targets which are added after the call to LINK_DIRECTORIES link_directories(${ALL_LIBRARY_DIRS}) endif(ALL_LIBRARY_DIRS) add_library(${MODULE_PROVIDES} ${_STATIC} ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP} ${DOX_FILES} ${UI_FILES} ${QRC_FILES}) if(MODULE_TARGET_DEPENDS) add_dependencies(${MODULE_PROVIDES} ${MODULE_TARGET_DEPENDS}) endif() if(MODULE_SUBPROJECTS) set_property(TARGET ${MODULE_PROVIDES} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK) foreach(subproject ${MODULE_SUBPROJECTS}) add_dependencies(${subproject} ${MODULE_PROVIDES}) endforeach() endif() if(ALL_LIBRARIES) target_link_libraries(${MODULE_PROVIDES} ${ALL_LIBRARIES}) endif(ALL_LIBRARIES) if(MODULE_QT_MODULE AND QT_LIBRARIES) target_link_libraries(${MODULE_PROVIDES} ${QT_LIBRARIES}) endif() if(MINGW) target_link_libraries(${MODULE_PROVIDES} ssp) # add stack smash protection lib endif() # Apply properties to the module target. # We cannot use set_target_properties like below since there is no way to # differentiate C/C++ and Releas/Debug flags using target properties. # See http://www.cmake.org/Bug/view.php?id=6493 #set_target_properties(${MODULE_PROVIDES} PROPERTIES # COMPILE_FLAGS "${module_compile_flags}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${module_c_flags}") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${module_c_flags_debug}") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${module_c_flags_release}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${module_cxx_flags}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${module_cxx_flags_debug}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${module_cxx_flags_release}") # Add additional library search directories to a global property which # can be evaluated by other CMake macros, e.g. our install scripts. if(MODULE_ADDITIONAL_LIBS) get_property(_mitk_additional_library_search_paths GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS) foreach(_lib_filepath ${MODULE_ADDITIONAL_LIBS}) get_filename_component(_search_path "${_lib_filepath}" PATH) if(_search_path) list(APPEND _mitk_additional_library_search_paths "${_search_path}") endif() endforeach() if(_mitk_additional_library_search_paths) list(REMOVE_DUPLICATES _mitk_additional_library_search_paths) set_property(GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS ${_mitk_additional_library_search_paths}) endif() endif() # add the target name to a global property which is used in the top-level # CMakeLists.txt file to export the target set_property(GLOBAL APPEND PROPERTY MITK_MODULE_TARGETS ${MODULE_PROVIDES}) if(MODULE_AUTOLOAD_WITH) # for auto-loaded modules, adapt the output directory add_dependencies(${_module_autoload_meta_target} ${MODULE_PROVIDES}) if(WIN32) set(_module_output_prop RUNTIME_OUTPUT_DIRECTORY) else() set(_module_output_prop LIBRARY_OUTPUT_DIRECTORY) endif() set(_module_output_dir ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH}) get_target_property(_module_is_imported ${MODULE_AUTOLOAD_WITH} IMPORTED) if(NOT _module_is_imported) # if the auto-loading module is not imported, get its location # and put the auto-load module relative to it. get_target_property(_module_output_dir ${MODULE_AUTOLOAD_WITH} ${_module_output_prop}) set_target_properties(${MODULE_PROVIDES} PROPERTIES ${_module_output_prop} ${_module_output_dir}/${MODULE_AUTOLOAD_WITH}) else() set_target_properties(${MODULE_PROVIDES} PROPERTIES ${_module_output_prop} ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH}) endif() set_target_properties(${MODULE_PROVIDES} PROPERTIES MITK_AUTOLOAD_DIRECTORY ${MODULE_AUTOLOAD_WITH}) # add the auto-load module name as a property set_property(TARGET ${MODULE_AUTOLOAD_WITH} APPEND PROPERTY MITK_AUTOLOAD_TARGETS ${MODULE_PROVIDES}) else() # Add meta dependencies (e.g. on auto-load modules from depending modules) if(ALL_META_DEPENDENCIES) add_dependencies(${MODULE_PROVIDES} ${ALL_META_DEPENDENCIES}) endif() endif() endif() endif(MODULE_IS_ENABLED) endif(_MISSING_DEP) endif(NOT MODULE_IS_EXCLUDED AND NOT (MODULE_QT_MODULE AND NOT MITK_USE_QT)) if(NOT MODULE_IS_ENABLED) _MITK_CREATE_MODULE_CONF() endif(NOT MODULE_IS_ENABLED) + unset(MODULE_IS_DEPRECATED) + endmacro(MITK_CREATE_MODULE) diff --git a/CMake/moduleConf.cmake.in b/CMake/moduleConf.cmake.in index 8671104186..2205564a8a 100644 --- a/CMake/moduleConf.cmake.in +++ b/CMake/moduleConf.cmake.in @@ -1,15 +1,17 @@ set(@MODULE_NAME@_IS_ENABLED "@MODULE_IS_ENABLED@") set(@MODULE_NAME@_IS_DEPRECATED "@MODULE_IS_DEPRECATED@") set(@MODULE_NAME@_DEPRECATED_SINCE "@MODULE_DEPRECATED_SINCE@") if(@MODULE_NAME@_IS_ENABLED) @MODULE_EXTRA_CMAKE_CODE@ set(@MODULE_NAME@_INCLUDE_DIRS "@MODULE_INCLUDE_DIRS@") set(@MODULE_NAME@_PROVIDES "@MODULE_PROVIDES@") set(@MODULE_NAME@_DEPENDS "@MODULE_DEPENDS@") set(@MODULE_NAME@_PACKAGE_DEPENDS "@MODULE_PACKAGE_DEPENDS@") set(@MODULE_NAME@_LIBRARY_DIRS "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") - if(@MODULE_NAME@_IS_DEPRECATED) + if(@MODULE_NAME@_IS_DEPRECATED AND NOT MODULE_IS_DEPRECATED) + # Only print the message if the dependent module + # is not deprecated itself. message(WARNING "Module @MODULE_NAME@ is deprecated since ${@MODULE_NAME@_DEPRECATED_SINCE}") endif() endif(@MODULE_NAME@_IS_ENABLED) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7aefd8ce2..c468c431a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,991 +1,994 @@ 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.5) endif() #----------------------------------------------------------------------------- # Include ctest launchers for dashboard in case of makefile generator #----------------------------------------------------------------------------- if(${CMAKE_VERSION} VERSION_GREATER "2.8.9") include(CTestUseLaunchers) 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_ACVD "Use Approximated Centroidal Voronoi Diagrams" OFF) option(MITK_USE_GLEW "Use the GLEW library" ON) 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_USE_OpenCV "Use Intel's OpenCV library" OFF) option(MITK_USE_OpenCL "Use OpenCL GPU-Computing library" OFF) option(MITK_USE_Poco "Use the Poco library" ON) 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}) -if(MITK_USE_Python) - FIND_PACKAGE(PythonLibs REQUIRED) - FIND_PACKAGE(PythonInterp REQUIRED) -endif() + +option(MITK_ENABLE_PIC_READER "Enable support for reading the DKFZ pic file format." ON) mark_as_advanced(MITK_BUILD_ALL_APPS MITK_USE_GLEW MITK_USE_CTK MITK_USE_DCMTK + MITK_ENABLE_PIC_READER ) +if(MITK_USE_Python) + FIND_PACKAGE(PythonLibs REQUIRED) + FIND_PACKAGE(PythonInterp REQUIRED) +endif() 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() if(MITK_USE_SOFA) # SOFA requires at least CMake 2.8.8 set(SOFA_CMAKE_VERSION 2.8.8) if(${CMAKE_VERSION} VERSION_LESS ${SOFA_CMAKE_VERSION}) set(MITK_USE_SOFA OFF CACHE BOOL "" FORCE) message(WARNING "Switched off MITK_USE_SOFA\n Minimum required CMake version: ${SOFA_CMAKE_VERSION}\n Installed CMake version: ${CMAKE_VERSION}") endif() # SOFA doesn't support Clang if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(MITK_USE_SOFA OFF CACHE BOOL "" FORCE) message(WARNING "Switched off MITK_USE_SOFA\n Clang is not supported, use GCC instead.") endif() # SOFA/ITK combination requires at least MSVC 2010 if(MSVC_VERSION AND MSVC_VERSION LESS 1600) set(MITK_USE_SOFA OFF CACHE BOOL "" FORCE) message(WARNING "Switched off MITK_USE_SOFA\n MSVC versions less than 2010 are not supported.") endif() # SOFA requires boost library if(MITK_USE_SOFA AND NOT MITK_USE_Boost) message("Forcing MITK_USE_Boost to ON because of MITK_USE_SOFA") set(MITK_USE_Boost ON CACHE BOOL "" FORCE) endif() # SOFA requires boost system library list(FIND MITK_USE_Boost_LIBRARIES system _result) if(_result LESS 0) message("Adding 'system' to MITK_USE_Boost_LIBRARIES.") list(APPEND MITK_USE_Boost_LIBRARIES system) endif() # SOFA requires boost thread library list(FIND MITK_USE_Boost_LIBRARIES thread _result) if(_result LESS 0) message("Adding 'thread' to MITK_USE_Boost_LIBRARIES.") list(APPEND MITK_USE_Boost_LIBRARIES thread) endif() set(MITK_USE_Boost_LIBRARIES ${MITK_USE_Boost_LIBRARIES} CACHE STRING "" FORCE) 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() #----------------------------------------------------------------------------- # 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(mitkFunctionGetLibrarySearchPaths) 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) include(mitkMacroGetPMDPlatformString) #----------------------------------------------------------------------------- # Prerequesites #----------------------------------------------------------------------------- find_package(ITK REQUIRED) find_package(VTK REQUIRED) find_package(GDCM PATHS ${ITK_GDCM_DIR} REQUIRED) #----------------------------------------------------------------------------- # 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}") set(MITK_C_FLAGS_DEBUG ) set(MITK_C_FLAGS_RELEASE ) set(MITK_CXX_FLAGS "${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS}") set(MITK_CXX_FLAGS_DEBUG ) set(MITK_CXX_FLAGS_RELEASE ) set(MITK_EXE_LINKER_FLAGS ) set(MITK_SHARED_LINKER_FLAGS ) include(mitkSetupC++0xVariables) if(WIN32) set(MITK_CXX_FLAGS "${MITK_CXX_FLAGS} -D_WIN32_WINNT=0x0501 -DPOCO_NO_UNWINDOWS -DWIN32_LEAN_AND_MEAN") set(MITK_CXX_FLAGS "${MITK_CXX_FLAGS} /wd4231") # warning C4231: nonstandard extension used : 'extern' before template explicit instantiation endif() if(NOT MSVC_VERSION) foreach(_flag -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=gnu -Wno-error=unknown-pragmas -Woverloaded-virtual -Wstrict-null-sentinel #-Wold-style-cast #-Wsign-promo # the following two lines should be removed after ITK-3097 has # been resolved, see also MITK bug 15279 -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option ) mitkFunctionCheckCAndCXXCompilerFlags(${_flag} MITK_C_FLAGS MITK_CXX_FLAGS) endforeach() endif() if(CMAKE_COMPILER_IS_GNUCXX) mitkFunctionCheckCompilerFlags("-Wl,--no-undefined" MITK_SHARED_LINKER_FLAGS) mitkFunctionCheckCompilerFlags("-Wl,--as-needed" MITK_SHARED_LINKER_FLAGS) 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")) mitkFunctionCheckCAndCXXCompilerFlags("-fstack-protector-all" MITK_C_FLAGS MITK_CXX_FLAGS) endif() if(MINGW) # suppress warnings about auto imported symbols set(MITK_SHARED_LINKER_FLAGS "-Wl,--enable-auto-import ${MITK_SHARED_LINKER_FLAGS}") endif() set(MITK_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2 ${MITK_CXX_FLAGS_RELEASE}") endif() set(MITK_MODULE_LINKER_FLAGS ${MITK_SHARED_LINKER_FLAGS}) set(MITK_EXE_LINKER_FLAGS ${MITK_SHARED_LINKER_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_RENDERING_TESTING OFF "Enable the MITK rendering tests. Requires x-server in Linux.") #Rendering testing does not work for Linux nightlies, thus it is disabled per default #and activated for Mac and Windows. if(WIN32 OR APPLE) set(MITK_ENABLE_RENDERING_TESTING ON) endif() mark_as_advanced( MITK_ENABLE_RENDERING_TESTING ) # 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() set(BLUEBERRY_XPDOC_OUTPUT_DIR ${MITK_DOXYGEN_OUTPUT_DIR}/html/extension-points/html/) 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 and linker flags for MITK code #----------------------------------------------------------------------------- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MITK_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MITK_CXX_FLAGS_DEBUG}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MITK_CXX_FLAGS_RELEASE}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MITK_C_FLAGS}") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${MITK_C_FLAGS_DEBUG}") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${MITK_C_FLAGS_RELEASE}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MITK_EXE_LINKER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${MITK_SHARED_LINKER_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${MITK_MODULE_LINKER_FLAGS}") #----------------------------------------------------------------------------- # 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() if(MITK_BUILD_EXAMPLES) include("${CMAKE_CURRENT_SOURCE_DIR}/Examples/Plugins/PluginList.cmake") set(mitk_example_plugins_fullpath ) foreach(mitk_example_plugin ${MITK_EXAMPLE_PLUGINS}) list(APPEND mitk_example_plugins_fullpath Examples/Plugins/${mitk_example_plugin}) list(APPEND mitk_plugins_fullpath Examples/Plugins/${mitk_example_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() # 11.3.13, change, muellerm: activate python bundle if python and blueberry is active if( MITK_USE_Python ) set(MITK_BUILD_org.mitk.gui.qt.python ON) endif() endif() #----------------------------------------------------------------------------- # Python Wrapping #----------------------------------------------------------------------------- option(MITK_USE_Python "Build Python integration for MITK (requires CableSwig)." OFF) #----------------------------------------------------------------------------- # 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() get_property(MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS_CONFIG GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS) 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(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/Modules/CMakeLists.txt b/Modules/CMakeLists.txt index c7cb304e1f..53a3f18f4b 100644 --- a/Modules/CMakeLists.txt +++ b/Modules/CMakeLists.txt @@ -1,69 +1,73 @@ set(LIBPOSTFIX "Ext") # Modules must be listed according to their dependencies set(module_dirs MitkDataTypesExt MitkAlgorithmsExt MitkMapperExt MitkIOExt SceneSerializationBase PlanarFigure ImageExtraction ImageStatistics LegacyAdaptors IpPicSupport MitkExt SceneSerialization GraphAlgorithms ContourModel SurfaceInterpolation Segmentation PlanarFigureSegmentation Qmitk QmitkExt SegmentationUI DiffusionImaging GPGPU IGTBase IGT CameraCalibration IGTUI RigidRegistration RigidRegistrationUI DeformableRegistration DeformableRegistrationUI OpenCL OpenCVVideoSupport Overlays InputDevices ToFHardware ToFProcessing ToFUI US ClippingTools USUI DicomUI Simulation Remeshing Python ) +if(MITK_ENABLE_PIC_READER) + list(APPEND module_dirs IpPicSupportIO) +endif() + 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/IpPicSupport/CMakeLists.txt b/Modules/IpPicSupport/CMakeLists.txt index 63900a7b73..b45b5a429b 100644 --- a/Modules/IpPicSupport/CMakeLists.txt +++ b/Modules/IpPicSupport/CMakeLists.txt @@ -1,7 +1,8 @@ mitkFunctionCheckCompilerFlags("-Wno-deprecated-declarations" CMAKE_CXX_FLAGS) MITK_CREATE_MODULE( IpPicSupport DEPENDS Mitk LegacyAdaptors mitkIpPic + DEPRECATED_SINCE 2013.12 ) add_subdirectory(Testing) diff --git a/Modules/IpPicSupportIO/CMakeLists.txt b/Modules/IpPicSupportIO/CMakeLists.txt new file mode 100644 index 0000000000..d38f80ebda --- /dev/null +++ b/Modules/IpPicSupportIO/CMakeLists.txt @@ -0,0 +1,10 @@ +#mitkFunctionCheckCompilerFlags("-Wno-deprecated-declarations" CMAKE_CXX_FLAGS) + +MITK_CREATE_MODULE( IpPicSupportIO + DEPENDS Mitk mitkIpPic LegacyAdaptors + AUTOLOAD_WITH Mitk + ) + +if(BUILD_TESTING) + #add_subdirectory(Testing) +endif() diff --git a/Modules/IpPicSupportIO/Internal/mitkIpPicGet.c b/Modules/IpPicSupportIO/Internal/mitkIpPicGet.c new file mode 100755 index 0000000000..db1e1b7b28 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkIpPicGet.c @@ -0,0 +1,646 @@ +/***************************************************************************** + + Copyright (c) 1993-2000, Div. Medical and Biological Informatics, + Deutsches Krebsforschungszentrum, Heidelberg, Germany + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + - All advertising materials mentioning features or use of this software must + display the following acknowledgement: + + "This product includes software developed by the Div. Medical and + Biological Informatics, Deutsches Krebsforschungszentrum, Heidelberg, + Germany." + + - Neither the name of the Deutsches Krebsforschungszentrum nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE DIVISION MEDICAL AND BIOLOGICAL + INFORMATICS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE DIVISION MEDICAL AND BIOLOGICAL INFORMATICS, + THE DEUTSCHES KREBSFORSCHUNGSZENTRUM OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Send comments and/or bug reports to: + mbi-software@dkfz-heidelberg.de + +*****************************************************************************/ + + +/* + * $RCSfile$ + *-------------------------------------------------------------------- + * DESCRIPTION + * reads a PicFile from disk + * + * $Log$ + * Revision 1.11 2006/09/18 13:55:50 nolden + * FIX: removed define USE_ITKZLIB, crashes on windows + * + * Revision 1.10 2006/09/18 12:57:40 nolden + * CHG: added USE_ITKZLIB define + * + * Revision 1.9 2006/09/15 17:29:57 nolden + * CHG: simplified ipPic include for non-plugin builds + * + * Revision 1.8 2006/01/10 16:53:09 hasselberg + * FIX: ANSI C conformance (required for MSVC7.0) + * + * Revision 1.7 2005/12/21 08:28:42 max + * FIX: renamed ipSize_t to size_t, since ipSize_t is only available in the 64Bit branch op ipPic. + * + * Revision 1.6 2005/12/20 12:56:35 max + * ENH: Added possibility to read beyond 2GB limit. + * + * Revision 1.5 2005/10/19 11:19:43 ivo + * ENH: Chili ipPic compatibility + * + * Revision 1.4 2005/10/13 11:21:12 ivo + * FIX: linker warning (unused var) + * + * Revision 1.3 2005/10/13 08:35:47 ivo + * FIX: warnings + * + * Revision 1.2 2005/10/13 07:52:55 max + * fixed warnings Algorithms/mitkImageFilters/mitkImageToSurfaceFilter.h Algorithms/mitkImageFilters/mitkManualSegmentationToSurfaceFilter.h Algorithms/mitkImageIO/mitkIpPicGet.c + * + * Revision 1.1 2005/10/12 19:08:51 ivo + * ADD: substitute for mitkIpPicGet: original always deletes data pointer and re-allocs it using malloc, which is not compatible with mitk::ImageDataItem. + * + * Revision 1.16 2004/01/16 22:11:59 andre + * big endian bug fix + * + * Revision 1.15 2002/11/13 17:53:00 ivo + * new ipPic added. + * + * Revision 1.13 2002/02/27 09:02:56 andre + * zlib changes + * + * Revision 1.12 2002/02/27 08:54:43 andre + * zlib changes + * + * Revision 1.11 2000/05/04 12:52:37 ivo + * inserted BSD style license + * + * Revision 1.10 2000/02/16 14:29:20 andre + * *** empty log message *** + * + * Revision 1.9 1999/11/28 18:22:42 andre + * *** empty log message *** + * + * Revision 1.8 1999/11/28 16:29:43 andre + * *** empty log message *** + * + * Revision 1.7 1999/11/27 20:03:48 andre + * *** empty log message *** + * + * Revision 1.6 1999/11/27 19:29:43 andre + * *** empty log message *** + * + * Revision 1.5 1998/09/04 17:45:54 andre + * *** empty log message *** + * + * Revision 1.4 1998/05/06 14:13:15 andre + * added info->pixel_start_in_file + * + * Revision 1.3 1997/10/20 13:35:39 andre + * *** empty log message *** + * + * Revision 1.2 1997/09/15 13:21:13 andre + * switched to new what string format + * + * Revision 1.1.1.1 1997/09/06 19:09:59 andre + * initial import + * + * Revision 0.1 1993/04/02 16:18:39 andre + * now works on PC, SUN and DECstation + * + * Revision 0.0 1993/03/26 12:56:26 andre + * Initial revision, NO error checking + * + * + *-------------------------------------------------------------------- + * COPYRIGHT (c) 1993 by DKFZ (Dept. MBI) Heidelberg, FRG + */ + +#ifdef CHILIPLUGIN +#include + +mitkIpPicDescriptor * +MITKipPicGetTags( char *infile_name, mitkIpPicDescriptor *pic ) +{ + return mitkIpPicGetTags(infile_name, pic); +} + +_mitkIpPicTagsElement_t * +_MITKipPicReadTags( _mitkIpPicTagsElement_t *head, mitkIpUInt4_t bytes_to_read, FILE *stream, char encryption_type ) +{ + return _mitkIpPicReadTags(head, bytes_to_read, stream, encryption_type); +} + +//mitkIpPicDescriptor * _MITKipPicOldGet( FILE *infile, mitkIpPicDescriptor *pic ) +//{ +// return _mitkIpPicOldGet(infile, pic); +//} + +mitkIpPicDescriptor * +MITKipPicGet( char *infile_name, mitkIpPicDescriptor *pic ) +{ + if(pic != NULL) + { + mitkIpPicDescriptor * tmpPic; + size_t sizePic, sizeTmpPic; + tmpPic = mitkIpPicGet(infile_name, NULL); + sizePic = _mitkIpPicSize(pic); + sizeTmpPic = _mitkIpPicSize(tmpPic); + if(sizePic != sizeTmpPic) + { + fprintf( stderr, "Critical: MITKipPicGet was given a pic with wrong size\n" ); + return tmpPic; + } + memcpy(pic->data, tmpPic->data, sizePic); + pic->info->tags_head = tmpPic->info->tags_head; + tmpPic->info->tags_head = NULL; + mitkIpPicFree(tmpPic); + return pic; + } + else + return mitkIpPicGet(infile_name, pic); +} + +#else + +#include "mitkIpPic.h" +#ifdef DOS +#include "mitkIpPicOP.h" +#else +#include "mitkIpPicOldP.h" +#endif + +char * MITKstrdup (const char * string) +{ + char *memory; + + if (string==NULL) + return NULL; + + if ( ( memory = (char*)malloc(strlen(string) + 1) ) ) + return strcpy(memory,string); + + return NULL; +} + +_mitkIpPicTagsElement_t * +_MITKipPicReadTags( _mitkIpPicTagsElement_t *head, mitkIpUInt4_t bytes_to_read, FILE *stream, char encryption_type ); + +mitkIpPicDescriptor * _MITKipPicOldGet( FILE *infile, mitkIpPicDescriptor *pic ) +{ + _mitkIpPicOldHeader old_pic; + + size_t elements; + + size_t size = 0; + + size_t number_of_elements; + size_t bytes_per_element; + size_t number_of_bytes; + size_t block_size; + size_t number_of_blocks; + size_t remaining_bytes; + size_t bytes_read; + size_t block_nr; + + size_t ignored; + + mitkIpUInt1_t* data; + + if( pic == NULL ) + pic = mitkIpPicNew(); + else + { + size= _mitkIpPicSize(pic); + if(pic->data == NULL) + size = 0; + } + + /* read infile */ + ignored = mitkIpFReadLE( &(old_pic.dummy1), sizeof(mitkIpUInt4_t), 4, infile ); + if( old_pic.conv <= 0 || old_pic.conv > 6 ) + { + old_pic.conv = 3; + old_pic.rank = 2; + } + + ignored = mitkIpFReadLE( &(old_pic.n1), sizeof(mitkIpUInt4_t), old_pic.rank, infile ); + if( old_pic.rank == 3 && old_pic.n3 == 1 ) + old_pic.rank = 2; + + ignored = mitkIpFReadLE( &(old_pic.type), sizeof(mitkIpUInt4_t), 3, infile ); + if( old_pic.ntxt ) + { + fseek( infile, old_pic.ltxt, SEEK_CUR ); + } + + + elements = old_pic.n1 * old_pic.n2; + if( old_pic.rank == 3 ) + elements *= old_pic.n3; + + if((size == 0) || (size != _mitkIpPicSize(pic))) + { + if( pic->data != NULL ) + { + free( pic->data ); + pic->data = NULL; + } + pic->data = malloc( _mitkIpPicSize(pic) ); + } + + /* + * data is read in blocks of size 'block_size' to prevent from + * errors due to large file sizes (>=2GB) + */ + number_of_elements = elements; + bytes_per_element = old_pic.type; + number_of_bytes = number_of_elements * bytes_per_element; + block_size = 1024*1024; /* Use 1 MB blocks. Make sure that block size is smaller than 2^31 */ + number_of_blocks = number_of_bytes / block_size; + remaining_bytes = number_of_bytes % block_size; + bytes_read = 0; + block_nr = 0; + + data = (mitkIpUInt1_t*) pic->data; + for ( block_nr = 0 ; block_nr < number_of_blocks ; ++block_nr ) + bytes_read += mitkIpPicFReadLE( data + ( block_nr * block_size ), 1, (unsigned int) block_size, infile ); + bytes_read += mitkIpPicFReadLE( data + ( number_of_blocks * block_size ), 1, (unsigned int) remaining_bytes, infile ); + + if ( bytes_read != number_of_bytes ) + fprintf( stderr, "Error while reading (ferror indicates %u), only %lu bytes were read! Eof indicator is %u.\n", ferror(infile), (long unsigned int)bytes_read, feof(infile) ); + + /* convert to the new pic3 format */ + + if( old_pic.type == 1 ) + pic->type = mitkIpPicUInt; + else + pic->type = (mitkIpPicType_t)old_pic.conv; + pic->bpe = old_pic.type*8; + pic->dim = old_pic.rank; + pic->n[0] = old_pic.n1; + pic->n[1] = old_pic.n2; + pic->n[2] = old_pic.n3; + pic->n[3] = old_pic.n4; + pic->n[4] = old_pic.n5; + pic->n[5] = old_pic.n6; + pic->n[6] = old_pic.n7; + pic->n[7] = old_pic.n8; + + return( pic ); +} + +mitkIpUInt4_t _MITKipPicTSVElements( mitkIpPicTSV_t *tsv ) +{ + mitkIpUInt4_t i; + mitkIpUInt4_t elements; + + if( tsv->dim == 0 ) + return( 0 ); + + elements = tsv->n[0]; + for( i = 1; i < tsv->dim; i++ ) + elements *= tsv->n[i]; + + return( elements ); +} + + +_mitkIpPicTagsElement_t * +_MITKipPicReadTags( _mitkIpPicTagsElement_t *head, mitkIpUInt4_t bytes_to_read, FILE *stream, char encryption_type ) +{ + while( bytes_to_read > 0 ) + { + mitkIpPicTSV_t *tsv; + + mitkIpPicTag_t tag_name; + mitkIpUInt4_t len; + + size_t ignored; + + /*printf( "bytes_to_read: %i\n", bytes_to_read ); */ + + tsv = malloc( sizeof(mitkIpPicTSV_t) ); + + ignored = mitkIpPicFRead( &tag_name, 1, sizeof(mitkIpPicTag_t), stream ); + strncpy( tsv->tag, tag_name, _mitkIpPicTAGLEN ); + tsv->tag[_mitkIpPicTAGLEN] = '\0'; + + ignored = mitkIpPicFReadLE( &len, sizeof(mitkIpUInt4_t), 1, stream ); + + ignored = mitkIpPicFReadLE( &(tsv->type), sizeof(mitkIpUInt4_t), 1, stream ); + ignored = mitkIpPicFReadLE( &(tsv->bpe), sizeof(mitkIpUInt4_t), 1, stream ); + ignored = mitkIpPicFReadLE( &(tsv->dim), sizeof(mitkIpUInt4_t), 1, stream ); + + + ignored = mitkIpPicFReadLE( &(tsv->n), sizeof(mitkIpUInt4_t), tsv->dim, stream ); + + if( tsv->type == mitkIpPicTSV ) + { + tsv->value = NULL; + tsv->value = _mitkIpPicReadTags( tsv->value, + len - 3 * sizeof(mitkIpUInt4_t) + - tsv->dim * sizeof(mitkIpUInt4_t), + stream, + encryption_type ); + } + else + { + mitkIpUInt4_t elements; + + elements = _MITKipPicTSVElements( tsv ); + + if( tsv->type == mitkIpPicASCII + || tsv->type == mitkIpPicNonUniform ) + tsv->bpe = 8; + +assert( elements * tsv->bpe / 8 == len + - 3 * sizeof(mitkIpUInt4_t) + - tsv->dim * sizeof(mitkIpUInt4_t) ); + + if( tsv->type == mitkIpPicASCII ) + tsv->value = malloc( elements+1 * tsv->bpe / 8 ); + else + tsv->value = malloc( elements * tsv->bpe / 8 ); + + ignored = mitkIpPicFReadLE( tsv->value, tsv->bpe / 8, elements, stream ); + + if( tsv->type == mitkIpPicASCII ) + ((char *)(tsv->value))[elements] = '\0'; + + if( encryption_type == 'e' + && ( tsv->type == mitkIpPicASCII + || tsv->type == mitkIpPicNonUniform ) ) + { + if( tsv->type == mitkIpPicNonUniform ) + { + sprintf( tsv->tag, "*** ENCRYPTED ***" ); + tsv->tag[_mitkIpPicTAGLEN] = '\0'; + } + + free( tsv->value ); + + tsv->value = MITKstrdup( "*** ENCRYPTED ***" ); + tsv->n[0] = (mitkIpUInt4_t)strlen(tsv->value); + tsv->type = mitkIpPicASCII; + tsv->dim = 1; + } + } + + head = _mitkIpPicInsertTag( head, tsv ); + + bytes_to_read -= 32 /* name */ + + sizeof(mitkIpUInt4_t) /* len */ + + len; /* type + bpe + dim + n[] + data */ + } + return( head ); +} + +mitkIpPicDescriptor * +MITKipPicGetTags( char *infile_name, mitkIpPicDescriptor *pic ) +{ + mitkIpPicFile_t infile; + + mitkIpPicTag_t tag_name; + mitkIpUInt4_t dummy; + mitkIpUInt4_t len; + mitkIpUInt4_t dim; + mitkIpUInt4_t n[_mitkIpPicNDIM]; + + mitkIpUInt4_t to_read; + + size_t ignored; + + infile = _mitkIpPicOpenPicFileIn( infile_name ); + + if( infile == NULL ) + { + /*ipPrintErr( "mitkIpPicGetTags: sorry, error opening infile\n" );*/ + return( NULL ); + } + + if( pic != NULL ) + pic->info->write_protect = mitkIpFalse; + + /* read infile */ + ignored = mitkIpPicFRead( &(tag_name[0]), 1, 4, infile ); + + if( strncmp( mitkIpPicVERSION, tag_name, 4 ) != 0 ) + { + if( infile != stdin ) + mitkIpPicFClose( infile ); + return( pic ); + } + + if( pic == NULL ) + pic = mitkIpPicNew(); + + ignored = mitkIpPicFRead( &(tag_name[4]), 1, sizeof(mitkIpPicTag_t)-4, infile ); + /*strncpy( pic->info->version, tag_name, _mitkIpPicTAGLEN );*/ + + ignored = mitkIpPicFReadLE( &len, sizeof(mitkIpUInt4_t), 1, infile ); + + ignored = mitkIpPicFReadLE( &dummy, sizeof(mitkIpUInt4_t), 1, infile ); + ignored = mitkIpPicFReadLE( &dummy, sizeof(mitkIpUInt4_t), 1, infile ); + ignored = mitkIpPicFReadLE( &dim, sizeof(mitkIpUInt4_t), 1, infile ); + + ignored = mitkIpPicFReadLE( n, sizeof(mitkIpUInt4_t), dim, infile ); + + + to_read = len - 3 * sizeof(mitkIpUInt4_t) + - dim * sizeof(mitkIpUInt4_t); + + pic->info->tags_head = _MITKipPicReadTags( pic->info->tags_head, to_read, infile, mitkIpPicEncryptionType(pic) ); + + pic->info->pixel_start_in_file = mitkIpPicFTell( infile ); + + if( infile != stdin ) + mitkIpPicFClose( infile ); + + return( pic ); +} + +mitkIpPicDescriptor * +MITKipPicGet( char *infile_name, mitkIpPicDescriptor *pic ) +{ + mitkIpPicFile_t infile; + + mitkIpPicTag_t tag_name; + mitkIpUInt4_t len; + + mitkIpUInt4_t to_read; + size_t size; + + size_t number_of_elements; + size_t bytes_per_element; + size_t number_of_bytes; + size_t block_size; + size_t number_of_blocks; + size_t remaining_bytes; + size_t bytes_read; + size_t block_nr; + + mitkIpUInt1_t* data; + + size_t ignored; + + infile = _mitkIpPicOpenPicFileIn( infile_name ); + + if( !infile ) + { + /*ipPrintErr( "mitkIpPicGet: sorry, error opening infile\n" );*/ + return( NULL ); + } + + /* read infile */ + ignored = mitkIpPicFRead( tag_name, 1, 4, infile ); + + if( strncmp( "\037\213", tag_name, 2 ) == 0 ) + { + fprintf( stderr, "mitkIpPicGetHeader: sorry, can't read compressed file\n" ); + return( NULL ); + } + else if( strncmp( mitkIpPicVERSION, tag_name, 4 ) != 0 ) + { +#ifndef CHILIPLUGIN + if( pic == NULL ) + pic = _MITKipPicOldGet( infile, + NULL ); + else + _MITKipPicOldGet( infile, + pic ); + if( infile != stdin ) + mitkIpPicFClose( infile ); +#else + return NULL; +#endif + return( pic ); + } + + size = 0; + if( pic == NULL ) + pic = mitkIpPicNew(); + else + { + size= _mitkIpPicSize(pic); + if(pic->data == NULL) + size = 0; + } + + if( pic->info != NULL ) + { + _mitkIpPicFreeTags( pic->info->tags_head ); + pic->info->tags_head = NULL; + } + + ignored = mitkIpPicFRead( &(tag_name[4]), 1, sizeof(mitkIpPicTag_t)-4, infile ); + strncpy( pic->info->version, tag_name, _mitkIpPicTAGLEN ); + + ignored = mitkIpPicFReadLE( &len, sizeof(mitkIpUInt4_t), 1, infile ); + + ignored = mitkIpPicFReadLE( &(pic->type), sizeof(mitkIpUInt4_t), 1, infile ); + ignored = mitkIpPicFReadLE( &(pic->bpe), sizeof(mitkIpUInt4_t), 1, infile ); + ignored = mitkIpPicFReadLE( &(pic->dim), sizeof(mitkIpUInt4_t), 1, infile ); + + ignored = mitkIpPicFReadLE( &(pic->n), sizeof(mitkIpUInt4_t), pic->dim, infile ); + + (void *)ignored; + + to_read = len - 3 * sizeof(mitkIpUInt4_t) + - pic->dim * sizeof(mitkIpUInt4_t); +#if 0 + mitkIpPicFSeek( infile, to_read, SEEK_CUR ); +#else + pic->info->tags_head = _MITKipPicReadTags( pic->info->tags_head, to_read, infile, mitkIpPicEncryptionType(pic) ); +#endif + + pic->info->write_protect = mitkIpFalse; + + if((size == 0) || (size != _mitkIpPicSize(pic))) + { + if( pic->data != NULL ) + { + free( pic->data ); + pic->data = NULL; + } +#ifdef WIN + if ((pic->hdata = GlobalAlloc( GMEM_MOVEABLE, _mitkIpPicSize(pic) )) != 0) + pic->data = GlobalLock( pic->hdata ); +#else + pic->data = malloc( _mitkIpPicSize(pic) ); +#endif + } + + pic->info->pixel_start_in_file = mitkIpPicFTell( infile ); + /* + * data is read in blocks of size 'block_size' to prevent from + * errors due to large file sizes (>=2GB) + */ + number_of_elements = _mitkIpPicElements(pic); + bytes_per_element = pic->bpe / 8; + number_of_bytes = number_of_elements * bytes_per_element; + block_size = 1024*1024; /* Use 1 MB blocks. Make sure that block size is smaller than 2^31 */ + number_of_blocks = number_of_bytes / block_size; + remaining_bytes = number_of_bytes % block_size; + bytes_read = 0; + block_nr = 0; + /*printf( "mitkIpPicGet: number of blocks to read is %ul.\n", number_of_blocks ); */ + + data = (mitkIpUInt1_t*) pic->data; + if( pic->type == mitkIpPicNonUniform ) + { + for ( block_nr = 0 ; block_nr < number_of_blocks ; ++block_nr ) + bytes_read += mitkIpPicFRead( data + ( block_nr * block_size ), 1, (unsigned int) block_size, infile ); + bytes_read += mitkIpPicFRead( data + ( number_of_blocks * block_size ), 1, (unsigned int) remaining_bytes, infile ); + } + else + { + for ( block_nr = 0 ; block_nr < number_of_blocks ; ++block_nr ) + bytes_read += mitkIpPicFReadLE( data + ( block_nr * block_size ), 1, (unsigned int) block_size, infile ); + bytes_read += mitkIpPicFReadLE( data + ( number_of_blocks * block_size ), 1, (unsigned int) remaining_bytes, infile ); + } + + if ( bytes_read != number_of_bytes ) + { + fprintf( stderr, "Error while reading, only %lu bytes were read! Eof indicator is %u.\n", (long unsigned int)bytes_read, mitkIpPicFEOF(infile) ); +#ifndef USE_ZLIB + fprintf( stderr, "(ferror indicates %u).\n", ferror(infile)); +#endif + } + + if( infile != stdin ) + mitkIpPicFClose( infile ); + +#ifdef WIN + GlobalUnlock( pic->hdata ); +#endif + + return( pic ); +} + +#endif // CHILIPLUGIN diff --git a/Modules/IpPicSupportIO/Internal/mitkPicFileIOFactory.cpp b/Modules/IpPicSupportIO/Internal/mitkPicFileIOFactory.cpp new file mode 100644 index 0000000000..f9858b8f20 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicFileIOFactory.cpp @@ -0,0 +1,68 @@ +/*=================================================================== + +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 "mitkPicFileIOFactory.h" +#include "mitkIOAdapter.h" +#include "mitkPicFileReader.h" +#include "mitkCoreObjectFactory.h" + +#include "itkVersion.h" + + +namespace mitk +{ +PicFileIOFactory::PicFileIOFactory() +{ + this->RegisterOverride("mitkIOAdapter", + "mitkPicFileReader", + "mitk Pic Image IO", + 1, + itk::CreateObjectFunction >::New()); +} + +PicFileIOFactory::~PicFileIOFactory() +{ +} + +const char* PicFileIOFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char* PicFileIOFactory::GetDescription() const +{ + return "PicFile IO Factory, allows the loading of DKFZ Pic images"; +} + +} // end namespace mitk + +struct RegisterIpPicIOFactory{ + RegisterIpPicIOFactory() + : m_Factory( mitk::PicFileIOFactory::New() ) + { + MITK_DEBUG << "Registering PicFileIOFactory "; + itk::ObjectFactoryBase::RegisterFactory( m_Factory ); + } + + ~RegisterIpPicIOFactory() + { + itk::ObjectFactoryBase::UnRegisterFactory( m_Factory ); + } + + mitk::PicFileIOFactory::Pointer m_Factory; +}; + +static RegisterIpPicIOFactory registerIpPicIOFactory; diff --git a/Modules/IpPicSupportIO/Internal/mitkPicFileIOFactory.h b/Modules/IpPicSupportIO/Internal/mitkPicFileIOFactory.h new file mode 100644 index 0000000000..521fdfbfd6 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicFileIOFactory.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 __mitkPicFileIOFactory_h +#define __mitkPicFileIOFactory_h + +#ifdef _MSC_VER +#pragma warning ( disable : 4786 ) +#endif + +#include "itkObjectFactoryBase.h" +#include "mitkBaseData.h" + +namespace mitk +{ +//##Documentation +//## @brief Create instances of PicFileReader objects using an object factory. +class PicFileIOFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef PicFileIOFactory Self; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char* GetITKSourceVersion(void) const; + virtual const char* GetDescription(void) const; + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + static PicFileIOFactory* FactoryNew() { return new PicFileIOFactory;} + /** Run-time type information (and related methods). */ + itkTypeMacro(PicFileIOFactory, ObjectFactoryBase); + + /** Register one factory of this type */ +/* static void RegisterOneFactory(void) + { + std::cout << "Register PicFile Factory."; + + PicFileIOFactory::Pointer PicFileIOFactory = PicFileIOFactory::New(); + ObjectFactoryBase::RegisterFactory(PicFileIOFactory); + } +*/ +protected: + PicFileIOFactory(); + ~PicFileIOFactory(); + +private: + PicFileIOFactory(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + + +} // end namespace mitk + +#endif diff --git a/Modules/IpPicSupportIO/Internal/mitkPicFileReader.cpp b/Modules/IpPicSupportIO/Internal/mitkPicFileReader.cpp new file mode 100644 index 0000000000..6d7ef8b786 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicFileReader.cpp @@ -0,0 +1,376 @@ +/*=================================================================== + +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 "mitkPicFileReader.h" +#include "mitkPicHelper.h" +#include +#include "mitkImageWriteAccessor.h" +#include + +extern "C" +{ + mitkIpPicDescriptor * MITKipPicGet( char *infile_name, mitkIpPicDescriptor *pic ); + mitkIpPicDescriptor * MITKipPicGetTags( char *infile_name, mitkIpPicDescriptor *pic ); +} + +void mitk::PicFileReader::GenerateOutputInformation() +{ + Image::Pointer output = this->GetOutput(); + + if ((output->IsInitialized()) && (this->GetMTime() <= m_ReadHeaderTime.GetMTime())) + return; + + itkDebugMacro(<<"Reading file for GenerateOutputInformation()" << m_FileName); + + // Check to see if we can read the file given the name or prefix + // + if ( m_FileName == "" && m_FilePrefix == "" ) + { + throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty"); + } + + if( m_FileName != "") + { + mitkIpPicDescriptor* header=mitkIpPicGetHeader(const_cast(m_FileName.c_str()), NULL); + + if ( !header ) + { + throw itk::ImageFileReaderException(__FILE__, __LINE__, "File could not be read."); + } + + header=MITKipPicGetTags(const_cast(m_FileName.c_str()), header); + + int channels = 1; + + mitkIpPicTSV_t *tsv; + if ( (tsv = mitkIpPicQueryTag( header, "SOURCE HEADER" )) != NULL) + { + if(tsv->n[0]>1e+06) + { + mitkIpPicTSV_t *tsvSH; + tsvSH = mitkIpPicDelTag( header, "SOURCE HEADER" ); + mitkIpPicFreeTag(tsvSH); + } + } + if ( (tsv = mitkIpPicQueryTag( header, "ICON80x80" )) != NULL) + { + mitkIpPicTSV_t *tsvSH; + tsvSH = mitkIpPicDelTag( header, "ICON80x80" ); + mitkIpPicFreeTag(tsvSH); + } + if ( (tsv = mitkIpPicQueryTag( header, "VELOCITY" )) != NULL) + { + ++channels; + mitkIpPicDelTag( header, "VELOCITY" ); + } + + if( header == NULL || header->bpe == 0) + { + itk::ImageFileReaderException e(__FILE__, __LINE__); + std::ostringstream msg; + msg << " Could not read file " + << m_FileName.c_str(); + e.SetDescription(msg.str().c_str()); + throw e; + return; + } + + // if pic image only 2D, the n[2] value is not initialized + unsigned int slices = 1; + if( header->dim == 2 ) + header->n[2] = slices; + + // First initialize the geometry of the output image by the pic-header + SlicedGeometry3D::Pointer slicedGeometry = mitk::SlicedGeometry3D::New(); + PicHelper::InitializeEvenlySpaced(header, header->n[2], slicedGeometry); + + // if pic image only 3D, the n[3] value is not initialized + unsigned int timesteps = 1; + if( header->dim > 3 ) + timesteps = header->n[3]; + + slicedGeometry->ImageGeometryOn(); + ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New(); + timeGeometry->Initialize(slicedGeometry, timesteps); + + // Cast the pic descriptor to ImageDescriptor and initialize the output + + output->Initialize( CastToImageDescriptor(header)); + output->SetTimeGeometry( timeGeometry ); + mitkIpPicFree ( header ); + } + else + { + int numberOfImages=0; + m_StartFileIndex=0; + + mitkIpPicDescriptor* header=NULL; + + char fullName[1024]; + + while(m_StartFileIndex<10) + { + sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+numberOfImages); + FILE * f=fopen(fullName,"r"); + if(f==NULL) + { + //already found an image? + if(numberOfImages>0) + break; + //no? let's increase start + ++m_StartFileIndex; + } + else + { + fclose(f); + //only open the header of the first file found, + //@warning what to do when images do not have the same size?? + if(header==NULL) + { + header=mitkIpPicGetHeader(fullName, NULL); + header=MITKipPicGetTags(fullName, header); + } + ++numberOfImages; + } + } + + printf("\n numberofimages %d\n",numberOfImages); + + if(numberOfImages==0) + { + itk::ImageFileReaderException e(__FILE__, __LINE__); + std::ostringstream msg; + msg << "no images found"; + e.SetDescription(msg.str().c_str()); + throw e; + return; + } + + //@FIXME: was ist, wenn die Bilder nicht alle gleich gross sind? + if(numberOfImages>1) + { + printf("\n numberofimages %d > 1\n",numberOfImages); + header->dim=3; + header->n[2]=numberOfImages; + } + + printf(" \ninitialisize output\n"); + output->Initialize( CastToImageDescriptor(header) ); + mitkIpPicFree ( header ); + } + + m_ReadHeaderTime.Modified(); +} + +void mitk::PicFileReader::ConvertHandedness(mitkIpPicDescriptor* pic) +{ + //left to right handed conversion + if(pic->dim>=3) + { + mitkIpPicDescriptor* slice=mitkIpPicCopyHeader(pic, NULL); + slice->dim=2; + size_t size=_mitkIpPicSize(slice); + slice->data=malloc(size); + + size_t v, volumes = (pic->dim>3? pic->n[3] : 1); + size_t volume_size = size*pic->n[2]; + + for(v=0; vdata; + unsigned char *p_last=(unsigned char *)pic->data; + p_first+=v*volume_size; + p_last+=size*(pic->n[2]-1)+v*volume_size; + + size_t i, smid=pic->n[2]/2; + for(i=0; idata, p_last, size); + memcpy(p_last, p_first, size); + memcpy(p_first, slice->data, size); + } + } + mitkIpPicFree(slice); + } +} + +void mitk::PicFileReader::GenerateData() +{ + Image::Pointer output = this->GetOutput(); + + // Check to see if we can read the file given the name or prefix + // + if ( m_FileName == "" && m_FilePrefix == "" ) + { + throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty"); + } + + if( m_FileName != "") + { + mitkIpPicDescriptor* outputPic = mitkIpPicNew(); + mitk::ImageWriteAccessor imageAccess(output); + outputPic = CastToIpPicDescriptor(output, &imageAccess, outputPic); + mitkIpPicDescriptor* pic=MITKipPicGet(const_cast(m_FileName.c_str()), + outputPic); + // comes upside-down (in MITK coordinates) from PIC file + ConvertHandedness(pic); + + mitkIpPicTSV_t *tsv; + if ( (tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" )) != NULL) + { + if(tsv->n[0]>1e+06) + { + mitkIpPicTSV_t *tsvSH; + tsvSH = mitkIpPicDelTag( pic, "SOURCE HEADER" ); + mitkIpPicFreeTag(tsvSH); + } + } + if ( (tsv = mitkIpPicQueryTag( pic, "ICON80x80" )) != NULL) + { + mitkIpPicTSV_t *tsvSH; + tsvSH = mitkIpPicDelTag( pic, "ICON80x80" ); + mitkIpPicFreeTag(tsvSH); + } + if ( (tsv = mitkIpPicQueryTag( pic, "VELOCITY" )) != NULL) + { + mitkIpPicDescriptor* header = mitkIpPicCopyHeader(pic, NULL); + header->data = tsv->value; + ConvertHandedness(header); + output->SetChannel(header->data, 1); + header->data = NULL; + mitkIpPicFree(header); + mitkIpPicDelTag( pic, "VELOCITY" ); + } + + //slice-wise reading + //currently much too slow. + //else + //{ + // int sstart, smax; + // int tstart, tmax; + + // sstart=output->GetRequestedRegion().GetIndex(2); + // smax=sstart+output->GetRequestedRegion().GetSize(2); + + // tstart=output->GetRequestedRegion().GetIndex(3); + // tmax=tstart+output->GetRequestedRegion().GetSize(3); + + // int s,t; + // for(s=sstart; s(m_FileName.c_str()), NULL, t*smax+s+1); + // output->SetPicSlice(pic,s,t); + // } + // } + //} + } + else + { + int position; + mitkIpPicDescriptor* pic=NULL; + + int zDim=(output->GetDimension()>2?output->GetDimensions()[2]:1); + printf("\n zdim is %u \n",zDim); + + for (position = 0; position < zDim; ++position) + { + char fullName[1024]; + + sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+position); + + pic=MITKipPicGet(fullName, pic); + if(pic==NULL) + { + itkDebugMacro("Pic file '" << fullName << "' does not exist."); + } + /* FIXME else + if(output->SetPicSlice(pic, position)==false) + { + itkDebugMacro("Image '" << fullName << "' could not be added to Image."); + }*/ + } + if(pic!=NULL) + mitkIpPicFree(pic); + } +} + +void mitk::PicFileReader::EnlargeOutputRequestedRegion(itk::DataObject *output) +{ + output->SetRequestedRegionToLargestPossibleRegion(); +} + +bool mitk::PicFileReader::CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern) +{ + // First check the extension + if( filename == "" ) + { + //MITK_INFO<<"No filename specified."<(aPic); + + mitkIpPicTSV_t *tsv; + bool pixelSize = false; + + tsv = mitkIpPicQueryTag( pic, "REAL PIXEL SIZE" ); + if(tsv==NULL) + { + tsv = mitkIpPicQueryTag( pic, "PIXEL SIZE" ); + pixelSize = true; + } + if(tsv) + { + bool tagFound = false; + if((tsv->dim*tsv->n[0]>=3) && (tsv->type==mitkIpPicFloat)) + { + if(tsv->bpe==32) + { + FillVector3D(spacing,((mitkIpFloat4_t*)tsv->value)[0], ((mitkIpFloat4_t*)tsv->value)[1],((mitkIpFloat4_t*)tsv->value)[2]); + tagFound = true; + } + else + if(tsv->bpe==64) + { + FillVector3D(spacing,((mitkIpFloat8_t*)tsv->value)[0], ((mitkIpFloat8_t*)tsv->value)[1],((mitkIpFloat8_t*)tsv->value)[2]); + tagFound = true; + } + } + if(tagFound && pixelSize) + { + tsv = mitkIpPicQueryTag( pic, "PIXEL SPACING" ); + if(tsv) + { + mitk::ScalarType zSpacing = 0; + if((tsv->dim*tsv->n[0]>=3) && (tsv->type==mitkIpPicFloat)) + { + if(tsv->bpe==32) + { + zSpacing = ((mitkIpFloat4_t*)tsv->value)[2]; + } + else + if(tsv->bpe==64) + { + zSpacing = ((mitkIpFloat8_t*)tsv->value)[2]; + } + if(zSpacing != 0) + { + spacing[2] = zSpacing; + } + } + } + } + if(tagFound) return true; + } +#ifdef HAVE_IPDICOM + tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" ); + if( tsv ) + { + void *data; + mitkIpUInt4_t len; + mitkIpFloat8_t spacing_z = 0; + mitkIpFloat8_t thickness = 1; + mitkIpFloat8_t fx = 1; + mitkIpFloat8_t fy = 1; + bool ok=false; + + if( dicomFindElement( (unsigned char *) tsv->value, 0x0018, 0x0088, &data, &len ) ) + { + ok=true; + sscanf( (char *) data, "%lf", &spacing_z ); +// itkGenericOutputMacro( "spacing: " << spacing_z << " mm"); + } + if( dicomFindElement( (unsigned char *) tsv->value, 0x0018, 0x0050, &data, &len ) ) + { + ok=true; + sscanf( (char *) data, "%lf", &thickness ); +// itkGenericOutputMacro( "thickness: " << thickness << " mm"); + + if( thickness == 0 ) + thickness = 1; + } + if( dicomFindElement( (unsigned char *) tsv->value, 0x0028, 0x0030, &data, &len ) + && len>0 && ((char *)data)[0] ) + { + sscanf( (char *) data, "%lf\\%lf", &fy, &fx ); // row / column value +// itkGenericOutputMacro( "fx, fy: " << fx << "/" << fy << " mm"); + } + else + ok=false; + if(ok) + FillVector3D(spacing, fx, fy,( spacing_z > 0 ? spacing_z : thickness)); + return ok; + } +#endif /* HAVE_IPDICOM */ + if(spacing[0]<=0 || spacing[1]<=0 || spacing[2]<=0) + { + itkGenericOutputMacro(<< "illegal spacing by pic tag: " << spacing << ". Setting spacing to (1,1,1)."); + spacing.Fill(1); + } + return false; +} + +bool mitk::PicHelper::GetTimeSpacing(const mitkIpPicDescriptor* aPic, float& timeSpacing) +{ + + mitkIpPicDescriptor* pic = const_cast(aPic); + + mitkIpPicTSV_t *tsv; + + tsv = mitkIpPicQueryTag( pic, "PIXEL SIZE" ); + if(tsv) + { + timeSpacing = ((mitkIpFloat4_t*)tsv->value)[3]; + if( timeSpacing <=0 ) timeSpacing = 1; + } + else timeSpacing = 1; + return true; +} + +bool mitk::PicHelper::SetSpacing(const mitkIpPicDescriptor* aPic, SlicedGeometry3D* slicedgeometry) +{ + mitkIpPicDescriptor* pic = const_cast(aPic); + + Vector3D spacing(slicedgeometry->GetSpacing()); + + mitkIpPicTSV_t *tsv; + if ( (tsv = mitkIpPicQueryTag( pic, "REAL PIXEL SIZES" )) != NULL) + { + int count = tsv->n[1]; + float* value = (float*) tsv->value; + mitk::Vector3D pixelSize; + spacing.Fill(0); + + for ( int s=0; s < count; s++ ) + { + pixelSize[0] = (ScalarType) *value++; + pixelSize[1] = (ScalarType) *value++; + pixelSize[2] = (ScalarType) *value++; + spacing += pixelSize; + } + spacing *= 1.0f/count; + slicedgeometry->SetSpacing(spacing); + + itkGenericOutputMacro(<< "the slices are inhomogeneous" ); + } + else + if(GetSpacing(pic, spacing)) + { + slicedgeometry->SetSpacing(spacing); + return true; + } + return false; +} + +void mitk::PicHelper::InitializeEvenlySpaced(const mitkIpPicDescriptor* pic, unsigned int slices, SlicedGeometry3D* slicedgeometry) +{ + assert(pic!=NULL); + assert(slicedgeometry!=NULL); + + mitk::PlaneGeometry::Pointer planegeometry=mitk::PlaneGeometry::New(); + + mitkIpPicTSV_t *geometryTag; + if ( (geometryTag = mitkIpPicQueryTag( const_cast(pic), "ISG" )) != NULL) + { + mitk::Point3D origin; + mitk::Vector3D rightVector; + mitk::Vector3D downVector; + mitk::Vector3D spacing; + + mitk::vtk2itk(((float*)geometryTag->value+0), origin); + mitk::vtk2itk(((float*)geometryTag->value+3), rightVector); + mitk::vtk2itk(((float*)geometryTag->value+6), downVector); + mitk::vtk2itk(((float*)geometryTag->value+9), spacing); + + mitk::PlaneGeometry::Pointer planegeometry = PlaneGeometry::New(); + planegeometry->InitializeStandardPlane(pic->n[0], pic->n[1], rightVector, downVector, &spacing); + planegeometry->SetOrigin(origin); + slicedgeometry->InitializeEvenlySpaced(planegeometry, slices); + } + else + { + Vector3D spacing; + spacing.Fill(1); + GetSpacing(pic, spacing); + planegeometry->InitializeStandardPlane(pic->n[0], pic->n[1], spacing); + slicedgeometry->InitializeEvenlySpaced(planegeometry, spacing[2], slices); + } + + if(pic->dim>=4) + { + float ts = 0; + GetTimeSpacing(pic, ts); + TimeBounds timebounds; + timebounds[0] = 0.0; + timebounds[1] = ts; + slicedgeometry->SetTimeBounds(timebounds); + } +} + +bool mitk::PicHelper::SetGeometry2D(const mitkIpPicDescriptor* aPic, int s, SlicedGeometry3D* slicedgeometry) +{ + mitkIpPicDescriptor* pic = const_cast(aPic); + if((pic!=NULL) && (slicedgeometry->IsValidSlice(s))) + { + //construct standard view + mitk::Point3D origin; + mitk::Vector3D rightDV, bottomDV; + mitkIpPicTSV_t *tsv; + if ( (tsv = mitkIpPicQueryTag( pic, "REAL PIXEL SIZES" )) != NULL) + { + unsigned int count = (unsigned int) tsv->n[1]; + float* value = (float*) tsv->value; + mitk::Vector3D pixelSize; + ScalarType zPosition = 0.0f; + + if(s >= 0) + { + if(count < (unsigned int) s) + return false; + count = s; + } + else + { + if(count < slicedgeometry->GetSlices()) + return false; + count = slicedgeometry->GetSlices(); + } + + unsigned int slice; + for (slice=0; slice < count; ++slice ) + { + pixelSize[0] = (ScalarType) *value++; + pixelSize[1] = (ScalarType) *value++; + pixelSize[2] = (ScalarType) *value++; + + zPosition += pixelSize[2] / 2.0f; // first half slice thickness + + if((s==-1) || (slice== (unsigned int) s)) + { + Vector3D spacing; + spacing = pixelSize; + FillVector3D(origin, 0, 0, zPosition); + FillVector3D(rightDV, pic->n[0], 0, 0); + FillVector3D(bottomDV, 0, pic->n[1], 0); + + mitk::PlaneGeometry::Pointer planegeometry=mitk::PlaneGeometry::New(); + planegeometry->InitializeStandardPlane(pic->n[0], pic->n[1], rightDV.GetVnlVector(), bottomDV.GetVnlVector(), &spacing); + planegeometry->SetOrigin(origin); + slicedgeometry->SetGeometry2D(planegeometry, s); + } + + zPosition += pixelSize[2] / 2.0f; // second half slice thickness + } + + } + else + { + FillVector3D(origin,0,0,s); slicedgeometry->IndexToWorld(origin, origin); + FillVector3D(rightDV,pic->n[0],0,0); + FillVector3D(bottomDV,0,pic->n[1],0); + + mitk::PlaneGeometry::Pointer planegeometry=mitk::PlaneGeometry::New(); + planegeometry->InitializeStandardPlane(pic->n[0], pic->n[1], rightDV.GetVnlVector(), bottomDV.GetVnlVector(), &slicedgeometry->GetSpacing()); + planegeometry->SetOrigin(origin); + slicedgeometry->SetGeometry2D(planegeometry, s); + } + return true; + } + return false; +} diff --git a/Modules/IpPicSupportIO/Internal/mitkPicHelper.h b/Modules/IpPicSupportIO/Internal/mitkPicHelper.h new file mode 100644 index 0000000000..a7fe95264b --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicHelper.h @@ -0,0 +1,50 @@ +/*=================================================================== + +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 MITKPICHELPER_H_HEADER_INCLUDED_C1F4DAB4 +#define MITKPICHELPER_H_HEADER_INCLUDED_C1F4DAB4 + +#include "mitkVector.h" +#include + +namespace mitk { + +class SlicedGeometry3D; + +//##Documentation +//## @brief Internal class for managing references on sub-images +class PicHelper +{ +public: + static const char *GetNameOfClass() { return "PicHelper"; } + + static bool GetSpacing(const mitkIpPicDescriptor* pic, Vector3D & spacing); + + static bool SetSpacing(const mitkIpPicDescriptor* pic, SlicedGeometry3D* slicedgeometry); + + static bool GetTimeSpacing(const mitkIpPicDescriptor* pic, float& timeSpacing); + + static void InitializeEvenlySpaced(const mitkIpPicDescriptor* pic, unsigned int slices, SlicedGeometry3D* slicedgeometry); + + static bool SetGeometry2D(const mitkIpPicDescriptor* pic, int s, SlicedGeometry3D* slicedgeometry); +}; + +} // namespace mitk + + + +#endif /* MITKPICHELPER_H_HEADER_INCLUDED_C1F4DAB4 */ diff --git a/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesIOFactory.cpp b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesIOFactory.cpp new file mode 100644 index 0000000000..061b94e7f9 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesIOFactory.cpp @@ -0,0 +1,49 @@ +/*=================================================================== + +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 "mitkPicVolumeTimeSeriesIOFactory.h" +#include "mitkIOAdapter.h" +#include "mitkPicVolumeTimeSeriesReader.h" + +#include "itkVersion.h" + + +namespace mitk +{ +PicVolumeTimeSeriesIOFactory::PicVolumeTimeSeriesIOFactory() +{ + this->RegisterOverride("mitkIOAdapter", + "mitkPicVolumeTimeSeriesReader", + "mitk Pic Image IO", + 1, + itk::CreateObjectFunction >::New()); +} + +PicVolumeTimeSeriesIOFactory::~PicVolumeTimeSeriesIOFactory() +{ +} + +const char* PicVolumeTimeSeriesIOFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char* PicVolumeTimeSeriesIOFactory::GetDescription() const +{ + return "PicVolumeTimeSeries IO Factory, allows the loading of DKFZ Pic images"; +} + +} // end namespace mitk diff --git a/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesIOFactory.h b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesIOFactory.h new file mode 100644 index 0000000000..8d961036c1 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesIOFactory.h @@ -0,0 +1,70 @@ +/*=================================================================== + +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 __mitkPicVolumeTimeSeriesIOFactory_h +#define __mitkPicVolumeTimeSeriesIOFactory_h + +#ifdef _MSC_VER +#pragma warning ( disable : 4786 ) +#endif + +#include "itkObjectFactoryBase.h" +#include "mitkBaseData.h" + +namespace mitk +{ +//##Documentation +//## @brief Create instances of PicVolumeTimeSeriesReader objects using an object factory. +//## +class PicVolumeTimeSeriesIOFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef PicVolumeTimeSeriesIOFactory Self; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char* GetITKSourceVersion(void) const; + virtual const char* GetDescription(void) const; + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + static PicVolumeTimeSeriesIOFactory* FactoryNew() { return new PicVolumeTimeSeriesIOFactory;} + /** Run-time type information (and related methods). */ + itkTypeMacro(PicVolumeTimeSeriesIOFactory, ObjectFactoryBase); + + /** Register one factory of this type */ + static void RegisterOneFactory(void) + { + PicVolumeTimeSeriesIOFactory::Pointer PicVolumeTimeSeriesIOFactory = PicVolumeTimeSeriesIOFactory::New(); + ObjectFactoryBase::RegisterFactory(PicVolumeTimeSeriesIOFactory); + } + +protected: + PicVolumeTimeSeriesIOFactory(); + ~PicVolumeTimeSeriesIOFactory(); + +private: + PicVolumeTimeSeriesIOFactory(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + + +} // end namespace mitk + +#endif diff --git a/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesReader.cpp b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesReader.cpp new file mode 100644 index 0000000000..9038d7d7bf --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesReader.cpp @@ -0,0 +1,178 @@ +/*=================================================================== + +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 "mitkPicVolumeTimeSeriesReader.h" +#include "mitkPicFileReader.h" +#include +#include + +#include + +extern "C" +{ +mitkIpPicDescriptor * MITKipPicGet( char *infile_name, mitkIpPicDescriptor *pic ); +mitkIpPicDescriptor * MITKipPicGetTags( char *infile_name, mitkIpPicDescriptor *pic ); +} + + +void mitk::PicVolumeTimeSeriesReader::GenerateOutputInformation() +{ + mitk::Image::Pointer output = this->GetOutput(); + + if ( ( output->IsInitialized() ) && ( this->GetMTime() <= m_ReadHeaderTime.GetMTime() ) ) + return ; + + itkDebugMacro( << "Reading file for GenerateOutputInformation()" << m_FileName ); + + if ( ! this->GenerateFileList() ) + { + itkWarningMacro( "Sorry, file list could not be generated!" ); + return ; + } + + // + // Read the first file of the image sequence. Assume equal size and spacings for all + // other volumes. @TODO Integrate support for different sizes and spacings + // + char* filename = const_cast ( m_MatchedFileNames[ 0 ].c_str() ); + mitkIpPicDescriptor * header = mitkIpPicGetHeader( filename, NULL ); + header = MITKipPicGetTags( filename, header ); + + if ( header == NULL ) + { + itk::ImageFileReaderException e( __FILE__, __LINE__ ); + std::ostringstream msg; + msg << " Could not read file " << m_FileName.c_str(); + e.SetDescription( msg.str().c_str() ); + throw e; + return ; + } + if ( header->dim != 3 ) + { + itk::ImageFileReaderException e( __FILE__, __LINE__ , "Only 3D-pic volumes are supported! " ); + throw e; + return ; + } + + // + // modify the header to match the real temporal extent + // + header->dim = 4; + header->n[ 3 ] = m_MatchedFileNames.size(); + + output->Initialize( CastToImageDescriptor( header) ); + + mitkIpPicFree( header ); + + m_ReadHeaderTime.Modified(); +} + + +void mitk::PicVolumeTimeSeriesReader::GenerateData() +{ + mitk::Image::Pointer output = this->GetOutput(); + + // + // Check to see if we can read the file given the name or prefix + // + if ( m_FilePrefix == "" || m_FilePattern == "" ) + { + throw itk::ImageFileReaderException( __FILE__, __LINE__, "Both FilePattern and FilePrefix must be non-empty" ); + } + + if ( m_MatchedFileNames.size() == 0 ) + { + throw itk::ImageFileReaderException( __FILE__, __LINE__, "Sorry, there are no files to read!" ); + } + + + // + // read 3d volumes and copy them to the 4d volume + // + mitkIpPicDescriptor* volume3d = NULL; + for ( unsigned int t = 0 ; t < m_MatchedFileNames.size() ; ++t ) + { + char* filename = const_cast< char* >( m_MatchedFileNames[ t ].c_str() ); + MITK_INFO << "Reading file " << filename << "..." << std::endl; + volume3d = MITKipPicGet( filename, NULL ); + + if ( volume3d == NULL ) + { + std::ostringstream message; + message << "mitk::ERROR: " << this->GetNameOfClass() << "(" << this << "): " + << "File (" << filename << ") of time frame " << t << " could not be read!"; + throw itk::ImageFileReaderException( __FILE__, __LINE__, message.str().c_str() ); + } + + // + // @TODO do some error checking + // + + // + // copy the 3d data volume to the 4d volume + // + + // \todo use memory of Image as in PicFileReader (or integrate everything into the PicFileReader!) + PicFileReader::ConvertHandedness(volume3d); + bool result = false; + // FIXME + //result = output->SetPicVolume( volume3d, t ); + if(result==false) + { + std::ostringstream message; + message << "mitk::ERROR: " << this->GetNameOfClass() << "(" << this << "): " + << "Volume of time frame " << t << " did not match size of other time frames."; + throw itk::ImageFileReaderException( __FILE__, __LINE__, message.str().c_str() ); + } + mitkIpPicFree ( volume3d ); + } +} + +bool mitk::PicVolumeTimeSeriesReader::CanReadFile(const std::string /*filename*/, const std::string filePrefix, const std::string filePattern) +{ + if( filePattern == "" && filePrefix == "" ) + return false; + + bool extensionFound = false; + std::string::size_type PICPos = filePattern.rfind(".pic"); + if ((PICPos != std::string::npos) + && (PICPos == filePattern.length() - 4)) + { + extensionFound = true; + } + + PICPos = filePattern.rfind(".pic.gz"); + if ((PICPos != std::string::npos) + && (PICPos == filePattern.length() - 7)) + { + extensionFound = true; + } + + if( !extensionFound ) + return false; + + return true; +} + +mitk::PicVolumeTimeSeriesReader::PicVolumeTimeSeriesReader() +{ + //this->DebugOn(); +} + +mitk::PicVolumeTimeSeriesReader::~PicVolumeTimeSeriesReader() +{} + diff --git a/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesReader.h b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesReader.h new file mode 100644 index 0000000000..41585110f4 --- /dev/null +++ b/Modules/IpPicSupportIO/Internal/mitkPicVolumeTimeSeriesReader.h @@ -0,0 +1,67 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + + +#ifndef _PIC_VOLUME_TIME_SERIES_READER__H_ +#define _PIC_VOLUME_TIME_SERIES_READER__H_ + +#include "mitkFileSeriesReader.h" +#include "mitkImageSource.h" +#include + +namespace mitk +{ +//##Documentation +//## @brief Reader to read a series of volume files in DKFZ-pic-format +class PicVolumeTimeSeriesReader : public ImageSource, public FileSeriesReader +{ +public: + mitkClassMacro( PicVolumeTimeSeriesReader, FileReader ); + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + itkSetStringMacro(FileName); + itkGetStringMacro(FileName); + + itkSetStringMacro(FilePrefix); + itkGetStringMacro(FilePrefix); + + itkSetStringMacro(FilePattern); + itkGetStringMacro(FilePattern); + + static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern); + +protected: + virtual void GenerateData(); + + virtual void GenerateOutputInformation(); + + PicVolumeTimeSeriesReader(); + + ~PicVolumeTimeSeriesReader(); + + //##Description + //## @brief Time when Header was last read + itk::TimeStamp m_ReadHeaderTime; + +}; + +} // namespace mitk + +#endif + + diff --git a/Modules/IpPicSupportIO/Testing/CMakeLists.txt b/Modules/IpPicSupportIO/Testing/CMakeLists.txt new file mode 100644 index 0000000000..46d2f08276 --- /dev/null +++ b/Modules/IpPicSupportIO/Testing/CMakeLists.txt @@ -0,0 +1,5 @@ +MITK_CREATE_MODULE_TESTS(LABELS MITK-Modules) + +mitkAddCustomModuleTest(mitkPicFileReaderTest_emptyFile mitkPicFileReaderTest ${CMAKE_CURRENT_SOURCE_DIR}/Data/emptyFile.pic) +mitkAddCustomModuleTest(mitkPicFileReaderTest_emptyGzipFile mitkPicFileReaderTest ${CMAKE_CURRENT_SOURCE_DIR}/Data/emptyFile.pic.gz) + diff --git a/Modules/IpPicSupportIO/Testing/files.cmake b/Modules/IpPicSupportIO/Testing/files.cmake new file mode 100644 index 0000000000..c973b7441e --- /dev/null +++ b/Modules/IpPicSupportIO/Testing/files.cmake @@ -0,0 +1,11 @@ +set(MODULE_IMAGE_TESTS + #mitkPicFileIOTest.cpp + mitkPicFileReaderTest.cpp +) + +set(MODULE_TESTIMAGES + US4DCyl.pic.gz + Pic3D.pic.gz + Pic2DplusT.pic.gz + BallBinary30x30x30.pic.gz +) diff --git a/Modules/IpPicSupportIO/Testing/mitkPicFileIOTest.cpp b/Modules/IpPicSupportIO/Testing/mitkPicFileIOTest.cpp new file mode 100644 index 0000000000..ffeb5225a2 --- /dev/null +++ b/Modules/IpPicSupportIO/Testing/mitkPicFileIOTest.cpp @@ -0,0 +1,197 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkImage.h" +#include "mitkPicFileReader.h" +#include "mitkImageWriter.h" +#include "mitkImageAccessByItk.h" + +#include + +unsigned int numberOfTestImages = 3; + +// create one test image +mitk::Image::Pointer CreateTestImage(unsigned int which) +{ + mitk::Image::Pointer image = mitk::Image::New(); + + switch (which) + { + case 0: + { + unsigned int dim[]={10,10,20}; // image dimensions + + image->Initialize(mitk::PixelType(typeid(int)), 3, dim); + int *p = (int*)image->GetData(); // pointer to pixel data + int size = dim[0]*dim[1]*dim[2]; + for(int i=0; iInitialize(mitk::PixelType(typeid(float)), 3, dim); + float *p = (float*)image->GetData(); // pointer to pixel data + int size = dim[0]*dim[1]*dim[2]; + for(int i=0; iInitialize(mitk::PixelType(typeid(double)), 3, dim); + double *p = (double*)image->GetData(); // pointer to pixel data + int size = dim[0]*dim[1]*dim[2]; + for(int i=0; iInitialize(mitk::PixelType(typeid(int)), 3, dim); + int *p = (int*)image->GetData(); // pointer to pixel data + int size = dim[0]*dim[1]*dim[2]; + for(int i=0; i +void ItkImageProcessing( itk::Image< TPixel, VImageDimension >* itkImage, mitk::Image* mitkImage, bool& identical ) +{ + typename itk::Image< TPixel, VImageDimension >::Pointer itkImage2; + + mitk::CastToItkImage( mitkImage, itkImage2 ); + + if (!itkImage2 || !itkImage2.GetPointer()) + { + identical = false; + return; + } + + itk::ImageRegionConstIterator > iterItkImage1( itkImage, itkImage->GetLargestPossibleRegion() ); + itk::ImageRegionConstIterator > iterItkImage2( itkImage, itkImage2->GetLargestPossibleRegion() ); + + iterItkImage1.GoToBegin(); + iterItkImage2.GoToBegin(); + + while (!iterItkImage1.IsAtEnd()) + { + if (iterItkImage1.Get() != iterItkImage2.Get()) + { + std::cout << iterItkImage1.Get() << " != " << iterItkImage2.Get() << std::endl; + identical = false; + return; + } + + ++iterItkImage1; + ++iterItkImage2; + } + + // if we reach this point, all pixel are the same + identical = true; +} + +int mitkPicFileIOTest(int, char*[]) +{ + unsigned int numberFailed(0); + + for (unsigned int i = 0; i < numberOfTestImages; ++i) + { + mitk::Image::Pointer originalImage = CreateTestImage(i); + mitk::Image::Pointer secondImage; + + // write + try + { + mitk::ImageWriter::Pointer imageWriter = mitk::ImageWriter::New(); + imageWriter->SetInput(originalImage); + + imageWriter->SetFileName("test_image"); + imageWriter->SetExtension(".pic"); + imageWriter->Write(); + } + catch ( std::exception& e ) + { + std::cerr << "Error during attempt to write 'test_image.pic' Exception says:" << std::endl; + std::cerr << e.what() << std::endl; + ++numberFailed; + continue; + } + + // load + try + { + mitk::PicFileReader::Pointer imageReader = mitk::PicFileReader::New(); + + imageReader->SetFileName("test_image.pic"); + imageReader->Update(); + + secondImage = imageReader->GetOutput(); + } + catch ( std::exception& e ) + { + std::cerr << "Error during attempt to read 'test_image.pic' Exception says:" << std::endl; + std::cerr << e.what() << std::endl; + ++numberFailed; + continue; + } + + if (secondImage.IsNull()) + { + std::cerr << "Error reading 'test_image.pic'. No image created." << std::endl; + ++numberFailed; + continue; + } + + std::remove( "test_image.pic" ); + + // compare + + bool identical(false); + AccessFixedDimensionByItk_2( secondImage.GetPointer(), ItkImageProcessing, 3, originalImage.GetPointer(), identical ); + + if (!identical) + { + std::cerr << "Images differ for testimage " << i << std::endl; + ++numberFailed; + continue; + } + } + + // if one fails, whole test fails + if (numberFailed > 0) + { + std::cout << "[FAILED]: " << numberFailed << " of " << numberOfTestImages << " sub-tests failed." << std::endl; + return EXIT_FAILURE; + } + else + { + std::cout << "[PASSED]" << std::endl; + return EXIT_SUCCESS; + } +} + diff --git a/Modules/IpPicSupportIO/Testing/mitkPicFileReaderTest.cpp b/Modules/IpPicSupportIO/Testing/mitkPicFileReaderTest.cpp new file mode 100644 index 0000000000..01cda35ab7 --- /dev/null +++ b/Modules/IpPicSupportIO/Testing/mitkPicFileReaderTest.cpp @@ -0,0 +1,189 @@ +/*=================================================================== + +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 "mitkTestingMacros.h" + +#include "mitkImage.h" +#include "mitkPicFileReader.h" +#include "mitkPicHelper.h" +#include "mitkSlicedGeometry3D.h" +#include +#include +#include + +#include +int mitkPicFileReaderTest(int argc, char* argv[]) +{ + MITK_TEST_BEGIN(mitkPicFileReaderTest) + + if(argc>=1) + { + if(itksys::SystemTools::FileLength(argv[1]) == 0) + { + + mitk::PicFileReader::Pointer emptyFileReader = mitk::PicFileReader::New(); + emptyFileReader->SetFileName(argv[1]); + MITK_TEST_FOR_EXCEPTION(itk::ImageFileReaderException,emptyFileReader->Update()); + } + else + { + + + //independently read header of pic file + mitkIpPicDescriptor *picheader=NULL; + if(itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameExtension(argv[1])).find(".pic")!=std::string::npos) + { + picheader = mitkIpPicGetHeader(argv[1], NULL); + } + if(picheader==NULL) + { + std::cout<<"file not found/not a pic-file - test not applied [PASSED]"<SetFileName(argv[1]); + reader->Update(); + + std::cout << "Testing IsInitialized(): "; + if(reader->GetOutput()->IsInitialized()==false) + { + std::cout<<"[FAILED]"<GetOutput()->IsSliceSet(0)==false) + { + std::cout<<"[FAILED]"<GetOutput()->GetGeometry()==NULL) + { + std::cout<<"[FAILED]"<GetOutput()->GetTimeGeometry(); + if(timeGeometry==NULL) + { + std::cout<<"[FAILED]"<GetGeometryForTimeStep(0).IsNull()) + { + std::cout<<"[FAILED]"<(timeGeometry->GetGeometryForTimeStep(0).GetPointer()); + if(slicedgeometry==NULL) + { + std::cout<<"[FAILED]"<GetGeometry2D(0); + if(geometry2d==NULL) + { + std::cout<<"[FAILED]"<GetExtent(0)-picheader->n[0])>mitk::eps) || (fabs(geometry2d->GetExtent(1)-picheader->n[1])>mitk::eps)) + { + std::cout<<"[FAILED]"<GetExtent(0)-picheader->n[0])>mitk::eps) || (fabs(slicedgeometry->GetExtent(1)-picheader->n[1])>mitk::eps) + || (picheader->dim>2 && (fabs(slicedgeometry->GetExtent(2)-picheader->n[2])>mitk::eps)) + ) + { + std::cout<<"[FAILED]"<GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0).two_norm(); + spacing[1] = slicedgeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1).two_norm(); + spacing[2] = slicedgeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2).two_norm(); + mitk::Vector3D readspacing=slicedgeometry->GetSpacing(); + mitk::Vector3D dist = spacing-readspacing; + if(dist.GetSquaredNorm()>mitk::eps) + { + std::cout<<"[FAILED]"<mitk::eps) + { + std::cout<<"[FAILED]"<dim==4) + { + std::cout << "4D dataset: Testing that timebounds are not infinite: "; + if((slicedgeometry->GetTimeBounds()[0] == mitk::ScalarTypeNumericTraits::NonpositiveMin()) && + (slicedgeometry->GetTimeBounds()[1] == mitk::ScalarTypeNumericTraits::max()) + ) + { + std::cout<<"[FAILED]"<