├── Applications ├── ExampleApp │ ├── target_libraries.cmake │ ├── CMakeLists.txt │ └── src │ │ ├── main.cpp │ │ ├── MainWindow.h │ │ └── MainWindow.cpp └── AppList.cmake ├── Modules ├── ModuleList.cmake └── ExampleModule │ ├── CMakeLists.txt │ ├── cmdapps │ ├── CMakeLists.txt │ └── ExampleCmdApp.cpp │ ├── files.cmake │ ├── resource │ ├── Interactions │ │ ├── PaintConfig.xml │ │ └── Paint.xml │ └── ExampleIcon.svg │ ├── src │ ├── ExampleModule.cpp │ ├── ExampleSegTool2DGUI.cpp │ ├── ExampleSegTool2DGUI.ui │ ├── ExampleSegTool2D.cpp │ ├── ExampleImageFilter.cpp │ └── ExampleImageInteractor.cpp │ └── include │ ├── ExampleModule.h │ ├── ExampleSegTool2DGUI.h │ ├── ExampleImageInteractor.h │ ├── ExampleImageFilter.h │ └── ExampleSegTool2D.h ├── Plugins ├── PluginList.cmake ├── org.mitk.exampleplugin.eageractivation │ ├── files.cmake │ ├── manifest_headers.cmake │ ├── CMakeLists.txt │ └── src │ │ └── internal │ │ ├── PluginActivator.cpp │ │ └── PluginActivator.h └── org.mitk.gui.qt.exampleplugin │ ├── manifest_headers.cmake │ ├── CMakeLists.txt │ ├── plugin.xml │ ├── documentation │ └── UserManual │ │ └── ExamplePlugin.dox │ ├── files.cmake │ ├── src │ └── internal │ │ ├── PluginActivator.cpp │ │ ├── PluginActivator.h │ │ ├── QmitkExampleView.h │ │ ├── ExampleViewControls.ui │ │ └── QmitkExampleView.cpp │ └── resources │ └── ExampleIcon.svg ├── CMakeExternals ├── ExternalProjectList.cmake ├── Customization │ └── ITK.cmake └── GuidelinesSupportLibrary.cmake ├── CMake ├── PackageDepends │ └── MITK_GuidelinesSupportLibrary_Config.cmake └── FindGuidelinesSupportLibrary.cmake ├── .arcconfig ├── LICENSE └── README.md /Applications/ExampleApp/target_libraries.cmake: -------------------------------------------------------------------------------- 1 | set(target_libraries) 2 | -------------------------------------------------------------------------------- /Modules/ModuleList.cmake: -------------------------------------------------------------------------------- 1 | set(MITK_MODULES 2 | ExampleModule 3 | ) 4 | -------------------------------------------------------------------------------- /Plugins/PluginList.cmake: -------------------------------------------------------------------------------- 1 | set(MITK_PLUGINS 2 | org.mitk.exampleplugin.eageractivation:ON 3 | org.mitk.gui.qt.exampleplugin:ON 4 | ) 5 | -------------------------------------------------------------------------------- /CMakeExternals/ExternalProjectList.cmake: -------------------------------------------------------------------------------- 1 | mitkFunctionAddExternalProject(NAME GuidelinesSupportLibrary ON DOC "Use Microsoft's implementation of the Guidelines Support Library (GSL)") 2 | -------------------------------------------------------------------------------- /Plugins/org.mitk.exampleplugin.eageractivation/files.cmake: -------------------------------------------------------------------------------- 1 | set(CPP_FILES 2 | src/internal/PluginActivator.cpp 3 | ) 4 | 5 | set(MOC_H_FILES 6 | src/internal/PluginActivator.h 7 | ) 8 | -------------------------------------------------------------------------------- /Applications/AppList.cmake: -------------------------------------------------------------------------------- 1 | option(MITK_BUILD_APP_ExampleApp "Build the MITK ExampleApp executable" ON) 2 | 3 | set(MITK_APPS 4 | ExampleApp^^MITK_BUILD_APP_ExampleApp^^MitkExampleApp 5 | ) 6 | -------------------------------------------------------------------------------- /Modules/ExampleModule/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mitk_create_module(ExampleModule 2 | DEPENDS PUBLIC MitkSegmentationUI 3 | PACKAGE_DEPENDS PRIVATE GuidelinesSupportLibrary 4 | ) 5 | 6 | add_subdirectory(cmdapps) 7 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/manifest_headers.cmake: -------------------------------------------------------------------------------- 1 | set(Plugin-Name "Example Plugin") 2 | set(Plugin-Version "1.0") 3 | set(Plugin-Vendor "CAMIC") 4 | set(Plugin-ContactAddress "https://mitk.org") 5 | set(Require-Plugin org.mitk.gui.qt.common) 6 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(org_mitk_gui_qt_exampleplugin) 2 | 3 | mitk_create_plugin( 4 | EXPORT_DIRECTIVE EXAMPLE_EXPORT 5 | EXPORTED_INCLUDE_SUFFIXES src 6 | MODULE_DEPENDS PRIVATE MitkQtWidgetsExt MitkExampleModule 7 | ) 8 | -------------------------------------------------------------------------------- /Plugins/org.mitk.exampleplugin.eageractivation/manifest_headers.cmake: -------------------------------------------------------------------------------- 1 | set(Plugin-Name "Eager Activation Example Plugin") 2 | set(Plugin-Version "1.0") 3 | set(Plugin-Vendor "CAMIC") 4 | set(Plugin-ContactAddress "https://mitk.org") 5 | set(Plugin-ActivationPolicy eager) 6 | -------------------------------------------------------------------------------- /CMake/PackageDepends/MITK_GuidelinesSupportLibrary_Config.cmake: -------------------------------------------------------------------------------- 1 | #[[ This file is empty as everything is already set up in 2 | CMake/FindGuidelinesSupportLibrary.cmake. However, 3 | MITK relies on the existence of this file to 4 | determine if the package was found. ]] 5 | -------------------------------------------------------------------------------- /Modules/ExampleModule/cmdapps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | option(BUILD_ExtExampleCmdApps "Build command-line apps for the Example module" ON) 2 | 3 | if(BUILD_ExtExampleCmdApps) 4 | mitkFunctionCreateCommandLineApp( 5 | NAME ExampleCmdApp 6 | DEPENDS MitkExampleModule 7 | ) 8 | endif() 9 | -------------------------------------------------------------------------------- /Plugins/org.mitk.exampleplugin.eageractivation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(org_mitk_exampleplugin_eageractivation) 2 | 3 | mitk_create_plugin( 4 | EXPORT_DIRECTIVE EXAMPLE_EXPORT 5 | EXPORTED_INCLUDE_SUFFIXES src 6 | MODULE_DEPENDS PRIVATE MitkExampleModule 7 | PACKAGE_DEPENDS PRIVATE CTK|CTKPluginFramework 8 | ) 9 | -------------------------------------------------------------------------------- /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "arc.feature.start.default": "develop", 3 | "arc.land.onto": ["develop"], 4 | "arc.land.strategy": "merge", 5 | "base": "git:merge-base(origin/develop)", 6 | "history.immutable": true, 7 | "phabricator.uri": "https://phabricator.mitk.org/", 8 | "repository.callsign": "MPT" 9 | } 10 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/documentation/UserManual/ExamplePlugin.dox: -------------------------------------------------------------------------------- 1 | /** 2 | \page org_mitk_views_exampleview Example View 3 | 4 | This is the user guide of the Example View. 5 | It is shown to a user if the context-specific help page was requested (F1 key). 6 | Its page id must be equal to the corresponding view id located in plugin.xml. 7 | Replace dots by underscores. 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /Applications/ExampleApp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ExampleApp) 2 | 3 | add_executable(MitkExampleApp 4 | src/main.cpp 5 | src/MainWindow.h 6 | src/MainWindow.cpp 7 | ) 8 | 9 | target_link_libraries(MitkExampleApp 10 | PRIVATE 11 | MitkQtWidgets 12 | ) 13 | 14 | set_target_properties(MitkExampleApp PROPERTIES 15 | AUTOMOC ON 16 | ) 17 | 18 | mitkFunctionConfigureVisualStudioUserProjectFile(NAME MitkExampleApp) 19 | -------------------------------------------------------------------------------- /Modules/ExampleModule/files.cmake: -------------------------------------------------------------------------------- 1 | set(CPP_FILES 2 | ExampleImageFilter.cpp 3 | ExampleImageInteractor.cpp 4 | ExampleModule.cpp 5 | ExampleSegTool2D.cpp 6 | ExampleSegTool2DGUI.cpp 7 | ) 8 | 9 | set(UI_FILES 10 | src/ExampleSegTool2DGUI.ui 11 | ) 12 | 13 | set(MOC_H_FILES 14 | include/ExampleSegTool2DGUI.h 15 | ) 16 | 17 | set(RESOURCE_FILES 18 | Interactions/Paint.xml 19 | Interactions/PaintConfig.xml 20 | ExampleIcon.svg 21 | ) 22 | -------------------------------------------------------------------------------- /Modules/ExampleModule/resource/Interactions/PaintConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Modules/ExampleModule/src/ExampleModule.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | 15 | void ExampleModule::ForceLinkage() 16 | { 17 | } 18 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/files.cmake: -------------------------------------------------------------------------------- 1 | set(CPP_FILES 2 | src/internal/PluginActivator.cpp 3 | src/internal/QmitkExampleView.cpp 4 | ) 5 | 6 | set(UI_FILES 7 | src/internal/ExampleViewControls.ui 8 | ) 9 | 10 | set(MOC_H_FILES 11 | src/internal/PluginActivator.h 12 | src/internal/QmitkExampleView.h 13 | ) 14 | 15 | # List of resource files that can be used by the plugin system without loading 16 | # the actual plugin. For example, the icon that is typically displayed in the 17 | # plugin view menu at the top of the application window. 18 | set(CACHED_RESOURCE_FILES 19 | resources/ExampleIcon.svg 20 | plugin.xml 21 | ) 22 | 23 | set(QRC_FILES 24 | ) 25 | -------------------------------------------------------------------------------- /Modules/ExampleModule/include/ExampleModule.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef ExampleModule_h 14 | #define ExampleModule_h 15 | 16 | #include 17 | 18 | namespace ExampleModule 19 | { 20 | MITKEXAMPLEMODULE_EXPORT void ForceLinkage(); 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include "PluginActivator.h" 14 | #include 15 | 16 | void PluginActivator::start(ctkPluginContext*) 17 | { 18 | ExampleModule::ForceLinkage(); 19 | } 20 | 21 | void PluginActivator::stop(ctkPluginContext*) 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /Applications/ExampleApp/src/main.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include "MainWindow.h" 14 | #include 15 | 16 | #include 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | QApplication app(argc, argv); 21 | QmitkRegisterClasses(); 22 | 23 | MainWindow window; 24 | window.show(); 25 | 26 | return app.exec(); 27 | } 28 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include "PluginActivator.h" 14 | #include "QmitkExampleView.h" 15 | 16 | void PluginActivator::start(ctkPluginContext* context) 17 | { 18 | BERRY_REGISTER_EXTENSION_CLASS(QmitkExampleView, context) 19 | } 20 | 21 | void PluginActivator::stop(ctkPluginContext*) 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /Modules/ExampleModule/src/ExampleSegTool2DGUI.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | #include 15 | 16 | MITK_TOOL_GUI_MACRO(MITKEXAMPLEMODULE_EXPORT, ExampleSegTool2DGUI, "") 17 | 18 | ExampleSegTool2DGUI::ExampleSegTool2DGUI() 19 | : m_Ui(new Ui::ExampleSegTool2DGUI) 20 | { 21 | m_Ui->setupUi(this); 22 | } 23 | 24 | ExampleSegTool2DGUI::~ExampleSegTool2DGUI() 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /Modules/ExampleModule/resource/Interactions/Paint.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CMakeExternals/Customization/ITK.cmake: -------------------------------------------------------------------------------- 1 | #[[ Customize MITK's external projects. This feature is supported only 2 | rudimentary and not all of MITK's external projects may take these 3 | customizations into account. 4 | 5 | The file's name must be equal to the external project's name. It may 6 | contain the following three variables: 7 | 8 | - CUSTOM_CMAKE_ARGS 9 | - CUSTOM_CMAKE_CACHE_ARGS 10 | - CUSTOM_CMAKE_DEFAULT_CACHE_ARGS 11 | 12 | You can lookup the meaning of these variables without the CUSTOM_ prefix 13 | in the official CMake documentation. The custom variables are simply added 14 | to the respective variables of the external project. ]] 15 | 16 | set(CUSTOM_CMAKE_ARGS 17 | -DModule_TextureFeatures:BOOL=ON 18 | -DModule_RLEImage:BOOL=ON 19 | -DModule_IsotropicWavelets:BOOL=ON 20 | -DModule_PrincipalComponentsAnalysis:BOOL=ON 21 | ) 22 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef PluginActivator_h 14 | #define PluginActivator_h 15 | 16 | #include 17 | 18 | class PluginActivator : public QObject, public ctkPluginActivator 19 | { 20 | Q_OBJECT 21 | Q_PLUGIN_METADATA(IID "org_mitk_gui_qt_exampleplugin") 22 | Q_INTERFACES(ctkPluginActivator) 23 | 24 | public: 25 | void start(ctkPluginContext* context); 26 | void stop(ctkPluginContext* context); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef PluginActivator_h 14 | #define PluginActivator_h 15 | 16 | #include 17 | 18 | class PluginActivator : public QObject, public ctkPluginActivator 19 | { 20 | Q_OBJECT 21 | Q_PLUGIN_METADATA(IID "org_mitk_exampleplugin_eageractivation") 22 | Q_INTERFACES(ctkPluginActivator) 23 | 24 | public: 25 | void start(ctkPluginContext* context); 26 | void stop(ctkPluginContext* context); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Applications/ExampleApp/src/MainWindow.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef MainWindow_h 14 | #define MainWindow_h 15 | 16 | #include 17 | #include 18 | 19 | class QmitkStdMultiWidget; 20 | 21 | class MainWindow : public QMainWindow 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | MainWindow(); 27 | ~MainWindow() override; 28 | 29 | private: 30 | void OnOpenFile(); 31 | 32 | mitk::StandaloneDataStorage::Pointer m_DataStorage; 33 | QmitkStdMultiWidget* m_MultiWidget; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Modules/ExampleModule/src/ExampleSegTool2DGUI.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ExampleSegTool2DGUI 4 | 5 | 6 | 7 | 0 8 | 0 9 | 320 10 | 240 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 22 | 23 | CTRL-click in image to produce log output. 24 | 25 | 26 | true 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /CMake/FindGuidelinesSupportLibrary.cmake: -------------------------------------------------------------------------------- 1 | #[[ Custom find script for Microsofts Guidelines Support Library (GSL) as 2 | CMake doesn't provide one yet. 3 | 4 | Creates an imported interface target called GuidelinesSupportLibrary that 5 | can be added to the package dependencies of an MITK module or plugin. ]] 6 | 7 | find_path(GuidelinesSupportLibrary_INCLUDE_DIR 8 | NAMES gsl/gsl 9 | PATHS ${MITK_EXTERNAL_PROJECT_PREFIX} 10 | PATH_SUFFIXES include 11 | ) 12 | 13 | if(NOT TARGET GuidelinesSupportLibrary) 14 | add_library(GuidelinesSupportLibrary INTERFACE IMPORTED GLOBAL) 15 | target_include_directories(GuidelinesSupportLibrary INTERFACE ${GuidelinesSupportLibrary_INCLUDE_DIR}) 16 | if(CMAKE_CXX_COMPILER_ID MATCHES Clang OR CMAKE_CXX_COMPILER_ID STREQUAL GNU) 17 | target_compile_options(GuidelinesSupportLibrary INTERFACE -fno-strict-aliasing) 18 | endif() 19 | endif() 20 | 21 | find_package_handle_standard_args(GuidelinesSupportLibrary 22 | FOUND_VAR GuidelinesSupportLibrary_FOUND 23 | REQUIRED_VARS GuidelinesSupportLibrary_INCLUDE_DIR 24 | ) 25 | -------------------------------------------------------------------------------- /Modules/ExampleModule/include/ExampleSegTool2DGUI.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef ExampleSegTool2DGUI_h 14 | #define ExampleSegTool2DGUI_h 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace Ui 21 | { 22 | class ExampleSegTool2DGUI; 23 | } 24 | 25 | // Look into ExampleSegTool2D.h for more information. 26 | 27 | class MITKEXAMPLEMODULE_EXPORT ExampleSegTool2DGUI : public QmitkToolGUI 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | mitkClassMacro(ExampleSegTool2DGUI, QmitkToolGUI) 33 | itkFactorylessNewMacro(Self) 34 | 35 | protected: 36 | ExampleSegTool2DGUI(); 37 | ~ExampleSegTool2DGUI() override; 38 | 39 | private: 40 | QScopedPointer m_Ui; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /Modules/ExampleModule/include/ExampleImageInteractor.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef ExampleImageInteractor_h 14 | #define ExampleImageInteractor_h 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | // See ExampleImageFilter.h for details on typical class declarations 22 | // in MITK. The actual functionality of this class is commented in its 23 | // implementation file. 24 | 25 | class MITKEXAMPLEMODULE_EXPORT ExampleImageInteractor final : public mitk::DataInteractor 26 | { 27 | public: 28 | mitkClassMacro(ExampleImageInteractor, DataInteractor) 29 | itkFactorylessNewMacro(Self) 30 | 31 | private: 32 | ExampleImageInteractor(); 33 | ~ExampleImageInteractor(); 34 | 35 | void ConnectActionsAndFunctions() override; 36 | void DataNodeChanged() override; 37 | 38 | void Paint(mitk::StateMachineAction* action, mitk::InteractionEvent* event); 39 | 40 | itk::Index<3> m_LastPixelIndex; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /CMakeExternals/GuidelinesSupportLibrary.cmake: -------------------------------------------------------------------------------- 1 | #[[ The Guidelines Support Library isn't really used in the project template. 2 | It serves as an example of how to add external projects, though. 3 | 4 | Also see the following files to get an overview of what is 5 | necessary to add an external project: 6 | 7 | - CMakeExternals/ExternalProjectList.cmake 8 | - CMake/FindGuidlinesSupportLibrary.cmake 9 | - CMake/PackageDepends/MITK_GuidelinesSupportLibrary_Config.cmake ]] 10 | 11 | set(proj GuidelinesSupportLibrary) 12 | set(proj_DEPENDENCIES "") 13 | 14 | if(MITK_USE_${proj}) 15 | set(${proj}_DEPENDS ${proj}) 16 | 17 | if(DEFINED ${proj}_DIR AND NOT EXISTS ${${proj}_DIR}) 18 | message(FATAL_ERROR "${proj}_DIR variable is defined but corresponds to non-existing directory!") 19 | endif() 20 | 21 | if(NOT DEFINED ${proj}_DIR) 22 | ExternalProject_Add(${proj} 23 | GIT_REPOSITORY https://github.com/Microsoft/GSL.git 24 | GIT_TAG v2.0.0 25 | CMAKE_ARGS ${ep_common_args} 26 | CMAKE_CACHE_ARGS ${ep_common_cache_args} 27 | -DGSL_CXX_STANDARD:STRING=${MITK_CXX_STANDARD} 28 | -DGSL_TEST:BOOL=OFF 29 | CMAKE_CACHE_DEFAULT_ARGS ${ep_common_cache_default_args} 30 | DEPENDS ${proj_DEPENDENCIES} 31 | ) 32 | 33 | set(${proj}_DIR ${ep_prefix}) 34 | else() 35 | mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") 36 | endif() 37 | endif() 38 | -------------------------------------------------------------------------------- /Modules/ExampleModule/src/ExampleSegTool2D.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | MITK_TOOL_MACRO(MITKEXAMPLEMODULE_EXPORT, ExampleSegTool2D, "Example tool"); 19 | 20 | ExampleSegTool2D::ExampleSegTool2D() 21 | : SegTool2D("Paint", us::GetModuleContext()->GetModule()) 22 | { 23 | } 24 | 25 | ExampleSegTool2D::~ExampleSegTool2D() 26 | { 27 | } 28 | 29 | void ExampleSegTool2D::ConnectActionsAndFunctions() 30 | { 31 | CONNECT_FUNCTION("paint", Paint) 32 | } 33 | 34 | void ExampleSegTool2D::Paint(mitk::StateMachineAction*, mitk::InteractionEvent*) 35 | { 36 | MITK_INFO << "Hello from the other side!"; 37 | } 38 | 39 | us::ModuleResource ExampleSegTool2D::GetIconResource() const 40 | { 41 | auto moduleContext = us::GetModuleContext(); 42 | auto module = moduleContext->GetModule(); 43 | auto resource = module->GetResource("ExampleIcon.svg"); 44 | return resource; 45 | } 46 | 47 | const char *ExampleSegTool2D::GetName() const 48 | { 49 | return "Example"; 50 | } 51 | 52 | const char **ExampleSegTool2D::GetXPM() const 53 | { 54 | return nullptr; 55 | } 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2003-2021, German Cancer Research Center (DKFZ) 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Modules/ExampleModule/include/ExampleImageFilter.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef ExampleImageFilter_h 14 | #define ExampleImageFilter_h 15 | 16 | #include 17 | 18 | // The following header file is generated by CMake and thus it's located in 19 | // the build directory. It provides an export macro for classes and functions 20 | // that you want to be part of the public interface of your module. 21 | #include 22 | 23 | // While you are free to derive directly from ITK filter base classes, 24 | // MITK filter base classes provide typed accessor methods for the inputs 25 | // and outputs, which will save you and your clients lots of manual casting. 26 | class MITKEXAMPLEMODULE_EXPORT ExampleImageFilter final : public mitk::ImageToImageFilter 27 | { 28 | public: 29 | // All classes that derive from an ITK-based MITK class need at least the 30 | // following two macros. Make sure you don't declare the constructor public 31 | // to force clients of your class to follow the ITK convention for 32 | // instantiating classes via the static New() method. 33 | mitkClassMacro(ExampleImageFilter, mitk::ImageToImageFilter) 34 | itkFactorylessNewMacro(Self) 35 | 36 | itkSetMacro(Offset, int) 37 | itkGetMacro(Offset, int) 38 | 39 | private: 40 | ExampleImageFilter(); 41 | ~ExampleImageFilter(); 42 | 43 | void GenerateData() override; 44 | 45 | int m_Offset; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The MITK Project Template 2 | ========================= 3 | 4 | This project provides a complete CMake-based set-up to get started with [MITK](https://github.com/MITK/MITK). 5 | 6 | Features 7 | -------- 8 | 9 | - Example module 10 | - ITK-based image filter 11 | - Interactor to paint in images 12 | - Example command-line app 13 | - Uses the image filter of the example module 14 | - Example plugin 15 | - GUI for the image filter and interactor of the example module 16 | - Example external project 17 | - Microsoft's Guidelines Support Library (GSL) 18 | 19 | How it works 20 | ------------ 21 | 22 | 1. Clone [MITK](https://github.com/MITK/MITK) and checkout the latest release tag or at least the stable master branch 23 | 2. Click on "Use this template", or clone/fork the MITK-ProjectTemplate, checking out the matching tag or branch 24 | 3. Configure the MITK superbuild and set the CMake cache variable `MITK_EXTENSION_DIRS` to your working copy of the project template 25 | 4. Generate and build the MITK superbuild 26 | 27 | The project template is virtually integrated right into the MITK superbuild and MITK build as if it would be part of MITK. You can extend MITK with your own modules, plugins, command-line apps, and external projects without touching the MITK source code resp. repository. 28 | 29 | Supported platforms and other requirements 30 | ------------------------------------------ 31 | 32 | See the [MITK documentation](http://docs.mitk.org/nightly/). 33 | 34 | License 35 | ------- 36 | 37 | Copyright (c) [German Cancer Research Center (DKFZ)](https://www.dkfz.de)
38 | All rights reserved. 39 | 40 | The MITK-ProjectTemplate is part of [MITK](https://github.com/MITK/MITK) and as such available as free open-source software under a [3-clause BSD license](https://github.com/MITK/MITK-ProjectTemplate/blob/master/LICENSE). 41 | -------------------------------------------------------------------------------- /Applications/ExampleApp/src/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include "MainWindow.h" 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | MainWindow::MainWindow() 22 | : m_DataStorage(mitk::StandaloneDataStorage::New()), 23 | m_MultiWidget(new QmitkStdMultiWidget(this)) 24 | { 25 | setWindowTitle("ExampleApp"); 26 | resize(800, 600); 27 | 28 | auto openAction = new QAction(tr("&Open..."), this); 29 | openAction->setShortcut(QKeySequence::Open); 30 | connect(openAction, &QAction::triggered, this, &MainWindow::OnOpenFile); 31 | 32 | auto fileMenu = menuBar()->addMenu(tr("&File")); 33 | fileMenu->addAction(openAction); 34 | 35 | m_MultiWidget->SetDataStorage(m_DataStorage); 36 | m_MultiWidget->InitializeMultiWidget(); 37 | m_MultiWidget->AddPlanesToDataStorage(); 38 | 39 | setCentralWidget(m_MultiWidget); 40 | } 41 | 42 | MainWindow::~MainWindow() 43 | { 44 | } 45 | 46 | void MainWindow::OnOpenFile() 47 | { 48 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open File")); 49 | 50 | if (fileName.isEmpty()) 51 | return; 52 | 53 | try 54 | { 55 | QmitkIOUtil::Load(fileName, *m_DataStorage, this); 56 | } 57 | catch (const mitk::Exception& e) 58 | { 59 | MITK_ERROR << e.GetDescription(); 60 | return; 61 | } 62 | 63 | m_MultiWidget->ResetCrosshair(); 64 | m_MultiWidget->RequestUpdateAll(); 65 | } 66 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef QmitkExampleView_h 14 | #define QmitkExampleView_h 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // There's an item "ExampleViewControls.ui" in the UI_FILES list in 21 | // files.cmake. The Qt UI Compiler will parse this file and generate a 22 | // header file prefixed with "ui_", which is located in the build directory. 23 | // Use Qt Creator to view and edit .ui files. The generated header file 24 | // provides a class that contains all of the UI widgets. 25 | #include 26 | 27 | // All views in MITK derive from QmitkAbstractView. You have to override 28 | // at least the two methods CreateQtPartControl() and SetFocus(). 29 | class QmitkExampleView : public QmitkAbstractView 30 | { 31 | // As ExampleView derives from QObject and we want to use the Qt 32 | // signal and slot mechanism, we must not forget the Q_OBJECT macro. 33 | // This header file also has to be listed in MOC_H_FILES in files.cmake 34 | // so that the Qt Meta-Object compiler can find and process this 35 | // class declaration. 36 | Q_OBJECT 37 | 38 | public: 39 | // This is a tricky one and will give you some headache later on in 40 | // your debug sessions if it has been forgotten. Also, don't forget 41 | // to initialize it in the implementation file. 42 | static const std::string VIEW_ID; 43 | 44 | // In this method we initialize the GUI components and connect the 45 | // associated signals and slots. 46 | void CreateQtPartControl(QWidget* parent) override; 47 | 48 | private slots: 49 | void OnImageChanged(const QmitkSingleNodeSelectionWidget::NodeList& nodes); 50 | void ProcessSelectedImage(); 51 | 52 | private: 53 | // Typically a one-liner. Set the focus to the default widget. 54 | void SetFocus() override; 55 | 56 | void EnableWidgets(bool enable); 57 | 58 | // Generated from the associated UI file, it encapsulates all the widgets 59 | // of our view. 60 | Ui::ExampleViewControls m_Controls; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Modules/ExampleModule/resource/ExampleIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 57 | 66 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/resources/ExampleIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 57 | 66 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Modules/ExampleModule/include/ExampleSegTool2D.h: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #ifndef ExampleSegTool2D_h 14 | #define ExampleSegTool2D_h 15 | 16 | #include 17 | #include 18 | 19 | namespace us 20 | { 21 | class ModuleResource; 22 | } 23 | 24 | // This is an example on how to add a segmentation tool to the standard 25 | // MITK Segmentation Views. Here's the crucial points to make it work: 26 | // 27 | // * The name of the class MUST end in either SegTool2D or SegTool3D 28 | // 29 | // * Derive directly or indirectly from mitk::Tool, for example 30 | // mitk::SegTool2D is a typical choice for 2d tools and 31 | // mitk::AutoSegmentationTool is a typical choice for 3d tools. 32 | // 33 | // * Don't forget the MITK_TOOL_MACRO in the implementation file 34 | // 35 | // * You don't have to provide your own state machine if the state 36 | // machines of the MitkSegmentation module are sufficient, but if 37 | // you do, you MUST provide both, the state machine and an event 38 | // config file, for example Paint.xml and PaintConfig.xml. The 39 | // file name of the event config file MUST be "equal" to the file 40 | // name of the state machine, suffixed by Config.xml instead of 41 | // .xml. The file name is passed to the base class constructor 42 | // without any extension, for example simply "Paint". 43 | // 44 | // * Look into ExampleSegTool2DGUI.h for an example of how to provide 45 | // a custom tool GUI. The naming is important and basically "equals" 46 | // the class name of the tool class, suffixed by GUI. Don't forget 47 | // the MITK_TOOL_GUI_MACRO in the implementation file of the tool GUI. 48 | // 49 | // * Ensure that the module containing your tool is loaded at runtime 50 | // before the MITK Segmentation Views are opened. Otherwise it cannot 51 | // be found. One way is to call anything from that module in a plugin 52 | // with eager activation policy. Such plugins are loaded very early 53 | // in MITK. For an example of how this works, look into ExampleModule.h 54 | // and the org_mitk_exampleplugin_eageractivation plugin. 55 | 56 | class MITKEXAMPLEMODULE_EXPORT ExampleSegTool2D : public mitk::SegTool2D 57 | { 58 | public: 59 | mitkClassMacro(ExampleSegTool2D, SegTool2D) 60 | itkFactorylessNewMacro(Self) 61 | 62 | us::ModuleResource GetIconResource() const override; 63 | const char *GetName() const override; 64 | const char **GetXPM() const override; 65 | 66 | protected: 67 | ExampleSegTool2D(); 68 | ~ExampleSegTool2D() override; 69 | 70 | virtual void Paint(mitk::StateMachineAction* action, mitk::InteractionEvent* event); 71 | 72 | private: 73 | void ConnectActionsAndFunctions() override; 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ExampleViewControls 4 | 5 | 6 | 7 | 0 8 | 0 9 | 227 10 | 356 11 | 12 | 13 | 14 | Example View 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 0 24 | 0 25 | 26 | 27 | 28 | 9999 29 | 30 | 31 | 32 | 33 | 34 | 35 | Process selected image 36 | 37 | 38 | Add Offset 39 | 40 | 41 | 42 | 43 | 44 | 45 | Offset 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Image 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 0 64 | 40 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | CTRL-click in result images to paint. 75 | 76 | 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | Qt::Vertical 85 | 86 | 87 | QSizePolicy::Expanding 88 | 89 | 90 | 91 | 20 92 | 220 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | QmitkSingleNodeSelectionWidget 103 | QWidget 104 |
QmitkSingleNodeSelectionWidget.h
105 | 1 106 |
107 |
108 | 109 | 110 |
111 | -------------------------------------------------------------------------------- /Modules/ExampleModule/src/ExampleImageFilter.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | // See definition of ExampleImageFilter::GenerateData() further below for 21 | // a rationale behind this function template. 22 | template 23 | static void AddOffset(const itk::Image* inputImage, int offset, mitk::Image::Pointer outputImage) 24 | { 25 | typedef itk::Image ImageType; 26 | typedef itk::ShiftScaleImageFilter FilterType; 27 | 28 | auto filter = FilterType::New(); 29 | filter->SetInput(inputImage); 30 | filter->SetShift(offset); 31 | 32 | filter->Update(); 33 | 34 | // This is the tricky part that is done wrong very often. As the image data 35 | // of ITK images and MITK images are binary compatible, we don't need to 36 | // cast or copy the ITK output image. Instead, we just want to reference 37 | // the image data and tell ITK that we took the ownership. 38 | mitk::GrabItkImageMemory(filter->GetOutput(), outputImage); 39 | } 40 | 41 | ExampleImageFilter::ExampleImageFilter() 42 | : m_Offset(0) 43 | { 44 | this->SetNumberOfRequiredInputs(1); 45 | this->SetNumberOfRequiredOutputs(1); 46 | } 47 | 48 | ExampleImageFilter::~ExampleImageFilter() 49 | { 50 | } 51 | 52 | void ExampleImageFilter::GenerateData() 53 | { 54 | mitk::Image::Pointer inputImage = this->GetInput(0); 55 | 56 | if (m_Offset == 0) 57 | { 58 | // Nothing to calculate in this case, just copy the input image. 59 | this->SetPrimaryOutput(inputImage->Clone().GetPointer()); 60 | } 61 | else 62 | { 63 | mitk::Image::Pointer outputImage = this->GetOutput(); 64 | 65 | try 66 | { 67 | // We want to apply an ITK filter to the MITK input image. While MITK 68 | // images are not templated, ITK images are templated by both pixel type 69 | // and image dimension. The actual image data is binary compatible, though. 70 | // MITK provides ITK access macros that enable you to directly operate 71 | // on MITK images without any superfluous copying. 72 | // To allow ITK filters to work with different image types at runtime you 73 | // would be required to instantiate your function templates for each and 74 | // every expected combination of pixel type and image dimension. Luckily, 75 | // MITK provides a whole bunch of multiplexer macros to save you doing this 76 | // manually (see mitkImageAccessByItk.h). 77 | // These macros range from being completely generic to partly constrained 78 | // variants. For example, you may want to constrain the image dimension or 79 | // the pixel type. As your function template is compiled for each allowed 80 | // combination, compile time and code size may increase dramatically. 81 | // As a rule of thumb, use a suitable multiplexer macro that is as 82 | // constrained as possible and yet as generic as necessary. 83 | // To prevent a combinatorial explosion, image dimension is restricted to 84 | // 2 and 3 even for the dimension-variable multiplexer macros. 85 | // Thus, the following multiplexer macro allows for 2-dimensional and 86 | // 3-dimensional images with an integer pixel type, for example, 87 | // (un)signed char, short, and int, resulting in a total of 12 distinct 88 | // combinations. 89 | AccessIntegralPixelTypeByItk_n(inputImage, AddOffset, (m_Offset, outputImage)); 90 | } 91 | catch (const mitk::AccessByItkException& e) 92 | { 93 | MITK_ERROR << "Unsupported pixel type or image dimension: " << e.what(); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | /** \brief Example command-line app that demonstrates the example image filter 22 | * 23 | * This command-line app will take the first given image and add the 24 | * provided offset to each voxel. 25 | */ 26 | 27 | int main(int argc, char* argv[]) 28 | { 29 | mitkCommandLineParser parser; 30 | 31 | // Set general information about your command-line app 32 | parser.setCategory("Example Cmd App Category"); 33 | parser.setTitle("Example Cmd App"); 34 | parser.setContributor("CAMIC"); 35 | parser.setDescription( 36 | "This command-line app takes the given image and adds the provided offset to each voxel."); 37 | 38 | // How should arguments be prefixed 39 | parser.setArgumentPrefix("--", "-"); 40 | 41 | // Add arguments. Unless specified otherwise, each argument is optional. 42 | // See mitkCommandLineParser::addArgument() for more information. 43 | parser.addArgument( 44 | "input", 45 | "i", 46 | mitkCommandLineParser::File, 47 | "Input Image", 48 | "Any image format known to MITK.", 49 | us::Any(), 50 | false); 51 | parser.addArgument( 52 | "output", 53 | "o", 54 | mitkCommandLineParser::File, 55 | "Output file", 56 | "Where to save the output.", 57 | us::Any(), 58 | false); 59 | parser.addArgument( 60 | "offset", 61 | "f", 62 | mitkCommandLineParser::Int, 63 | "Offset", 64 | "the offset integer to add to each voxel.", 65 | us::Any(), 66 | false); 67 | parser.addArgument( // optional 68 | "verbose", 69 | "v", 70 | mitkCommandLineParser::Bool, 71 | "Verbose Output", 72 | "Whether to produce verbose output"); 73 | 74 | // Parse arguments. This method returns a mapping of long argument names to 75 | // their values. 76 | auto parsedArgs = parser.parseArguments(argc, argv); 77 | 78 | if (parsedArgs.empty()) 79 | return EXIT_FAILURE; // Just exit, usage information was already printed. 80 | 81 | if (parsedArgs["input"].Empty() || parsedArgs["output"].Empty() || parsedArgs["offset"].Empty()) 82 | { 83 | MITK_INFO << parser.helpText(); 84 | return EXIT_FAILURE; 85 | } 86 | 87 | // Parse, cast and set required arguments 88 | auto inFilename = us::any_cast(parsedArgs["input"]); 89 | auto outFilename = us::any_cast(parsedArgs["output"]); 90 | auto offset = us::any_cast(parsedArgs["offset"]); 91 | 92 | // Default values for optional arguments 93 | auto verbose = false; 94 | 95 | // Parse, cast and set optional arguments 96 | if (parsedArgs.end() != parsedArgs.find("verbose")) 97 | verbose = us::any_cast(parsedArgs["verbose"]); 98 | 99 | try 100 | { 101 | if (verbose) 102 | MITK_INFO << "Read input file"; 103 | 104 | auto inImage = mitk::IOUtil::Load(inFilename); 105 | 106 | if (inImage.IsNull()) 107 | { 108 | MITK_ERROR << "Could not read \"" << inFilename << "\"!"; 109 | return EXIT_FAILURE; 110 | } 111 | 112 | if (verbose) 113 | MITK_INFO << "Add offset to image"; 114 | 115 | auto exampleFilter = ExampleImageFilter::New(); 116 | exampleFilter->SetInput(inImage); 117 | exampleFilter->SetOffset(offset); 118 | exampleFilter->Update(); 119 | 120 | auto outImage = exampleFilter->GetOutput(); 121 | 122 | if (nullptr == outImage) 123 | { 124 | MITK_ERROR << "Image processing failed!"; 125 | return EXIT_FAILURE; 126 | } 127 | 128 | if (verbose) 129 | MITK_INFO << "Write output file"; 130 | 131 | mitk::IOUtil::Save(outImage, outFilename); 132 | 133 | return EXIT_SUCCESS; 134 | } 135 | catch (const std::exception &e) 136 | { 137 | MITK_ERROR << e.what(); 138 | return EXIT_FAILURE; 139 | } 140 | catch (...) 141 | { 142 | MITK_ERROR << "Unexpected error!"; 143 | return EXIT_FAILURE; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include "QmitkExampleView.h" 30 | 31 | namespace 32 | { 33 | // Helper function to create a fully set up instance of our 34 | // ExampleImageInteractor, based on the state machine specified in Paint.xml 35 | // as well as its configuration in PaintConfig.xml. Both files are compiled 36 | // into MitkExampleModule as resources. 37 | static ExampleImageInteractor::Pointer CreateExampleImageInteractor() 38 | { 39 | auto exampleModule = us::ModuleRegistry::GetModule("MitkExampleModule"); 40 | 41 | if (nullptr != exampleModule) 42 | { 43 | auto interactor = ExampleImageInteractor::New(); 44 | interactor->LoadStateMachine("Paint.xml", exampleModule); 45 | interactor->SetEventConfig("PaintConfig.xml", exampleModule); 46 | return interactor; 47 | } 48 | 49 | return nullptr; 50 | } 51 | } 52 | 53 | // Don't forget to initialize the VIEW_ID. 54 | const std::string QmitkExampleView::VIEW_ID = "org.mitk.views.exampleview"; 55 | 56 | void QmitkExampleView::CreateQtPartControl(QWidget* parent) 57 | { 58 | // Setting up the UI is a true pleasure when using .ui files, isn't it? 59 | m_Controls.setupUi(parent); 60 | 61 | m_Controls.selectionWidget->SetDataStorage(this->GetDataStorage()); 62 | m_Controls.selectionWidget->SetSelectionIsOptional(true); 63 | m_Controls.selectionWidget->SetEmptyInfo(QStringLiteral("Select an image")); 64 | m_Controls.selectionWidget->SetNodePredicate(mitk::NodePredicateAnd::New( 65 | mitk::TNodePredicateDataType::New(), 66 | mitk::NodePredicateNot::New(mitk::NodePredicateOr::New( 67 | mitk::NodePredicateProperty::New("helper object"), 68 | mitk::NodePredicateProperty::New("hidden object"))))); 69 | 70 | // Wire up the UI widgets with our functionality. 71 | connect(m_Controls.selectionWidget, &QmitkSingleNodeSelectionWidget::CurrentSelectionChanged, this, &QmitkExampleView::OnImageChanged); 72 | connect(m_Controls.processImageButton, SIGNAL(clicked()), this, SLOT(ProcessSelectedImage())); 73 | 74 | // Make sure to have a consistent UI state at the very beginning. 75 | this->OnImageChanged(m_Controls.selectionWidget->GetSelectedNodes()); 76 | } 77 | 78 | void QmitkExampleView::SetFocus() 79 | { 80 | m_Controls.processImageButton->setFocus(); 81 | } 82 | 83 | void QmitkExampleView::OnImageChanged(const QmitkSingleNodeSelectionWidget::NodeList&) 84 | { 85 | this->EnableWidgets(m_Controls.selectionWidget->GetSelectedNode().IsNotNull()); 86 | } 87 | 88 | void QmitkExampleView::EnableWidgets(bool enable) 89 | { 90 | m_Controls.processImageButton->setEnabled(enable); 91 | } 92 | 93 | void QmitkExampleView::ProcessSelectedImage() 94 | { 95 | auto selectedDataNode = m_Controls.selectionWidget->GetSelectedNode(); 96 | auto data = selectedDataNode->GetData(); 97 | 98 | // We don't use the auto keyword here, which would evaluate to a native 99 | // image pointer. Instead, we want a smart pointer to ensure that 100 | // the image isn't deleted somewhere else while we're using it. 101 | mitk::Image::Pointer image = dynamic_cast(data); 102 | 103 | auto imageName = selectedDataNode->GetName(); 104 | auto offset = m_Controls.offsetSpinBox->value(); 105 | 106 | MITK_INFO << "Process image \"" << imageName << "\" ..."; 107 | 108 | // We're finally using the ExampleImageFilter from MitkExampleModule. 109 | auto filter = ExampleImageFilter::New(); 110 | filter->SetInput(image); 111 | filter->SetOffset(offset); 112 | 113 | filter->Update(); 114 | 115 | mitk::Image::Pointer processedImage = filter->GetOutput(); 116 | 117 | if (processedImage.IsNull() || !processedImage->IsInitialized()) 118 | return; 119 | 120 | MITK_INFO << " done"; 121 | 122 | // Stuff the resulting image into a data node, set some properties, 123 | // and add it to the data storage, which will eventually display the 124 | // image in the application. 125 | auto processedImageDataNode = mitk::DataNode::New(); 126 | processedImageDataNode->SetData(processedImage); 127 | 128 | QString name = QString("%1 (Offset: %2)").arg(imageName.c_str()).arg(offset); 129 | processedImageDataNode->SetName(name.toStdString()); 130 | 131 | // We don't really need to copy the level window, but if we wouldn't 132 | // do it, the new level window would be initialized to display the image 133 | // with optimal contrast in order to capture the whole range of pixel 134 | // values. This is also true for the input image as long as one didn't 135 | // modify its level window manually. Thus, the images would appear 136 | // identical unless you compare the level window widget for both images. 137 | mitk::LevelWindow levelWindow; 138 | 139 | if (selectedDataNode->GetLevelWindow(levelWindow)) 140 | processedImageDataNode->SetLevelWindow(levelWindow); 141 | 142 | // We also attach our ExampleImageInteractor, which allows us to paint 143 | // on the resulting images by using the mouse as long as the CTRL key 144 | // is pressed. 145 | auto interactor = CreateExampleImageInteractor(); 146 | 147 | if (interactor.IsNotNull()) 148 | interactor->SetDataNode(processedImageDataNode); 149 | 150 | this->GetDataStorage()->Add(processedImageDataNode); 151 | } 152 | -------------------------------------------------------------------------------- /Modules/ExampleModule/src/ExampleImageInteractor.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================ 2 | 3 | The Medical Imaging Interaction Toolkit (MITK) 4 | 5 | Copyright (c) German Cancer Research Center (DKFZ) 6 | All rights reserved. 7 | 8 | Use of this source code is governed by a 3-clause BSD license that can be 9 | found in the LICENSE file. 10 | 11 | ============================================================================*/ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace 22 | { 23 | // Helper function to get an image from a data node. 24 | mitk::Image::Pointer GetImage(mitk::DataNode::Pointer dataNode) 25 | { 26 | if (dataNode.IsNull()) 27 | mitkThrow(); 28 | 29 | mitk::Image::Pointer image = dynamic_cast(dataNode->GetData()); 30 | 31 | if (image.IsNull()) 32 | mitkThrow(); 33 | 34 | return image; 35 | } 36 | 37 | // Helper function to get a geometry of an image for a specific time step. 38 | mitk::BaseGeometry::Pointer GetGeometry(mitk::Image::Pointer image, unsigned int timeStep) 39 | { 40 | mitk::TimeGeometry::Pointer timeGeometry = image->GetTimeGeometry(); 41 | 42 | if (timeGeometry.IsNull()) 43 | mitkThrow(); 44 | 45 | auto geometry = timeGeometry->GetGeometryForTimeStep(timeStep); 46 | 47 | if (geometry.IsNull()) 48 | mitkThrow(); 49 | 50 | return geometry; 51 | } 52 | } 53 | 54 | // The actual painting happens here. We're using a write accessor to gain safe 55 | // write access to our image. The whole image volume for a given time step is 56 | // locked. However, it's also possible - and preferable - to lock the slice of 57 | // interest only. 58 | template 59 | static void Paint(mitk::Image::Pointer image, itk::Index<3> index, unsigned int timeStep) 60 | { 61 | // As soon as the ImagePixelWriteAccessor object goes out of scope at the 62 | // end of this function, the image will be unlocked again (RAII). 63 | mitk::ImagePixelWriteAccessor writeAccessor(image, image->GetVolumeData(timeStep)); 64 | writeAccessor.SetPixelByIndex(index, std::numeric_limits::min()); 65 | 66 | // Don't forget to update the modified time stamp of the image. Otherwise, 67 | // everything downstream wouldn't recognize that the image changed, 68 | // including the rendering system. 69 | image->Modified(); 70 | } 71 | 72 | // Helper function to multiplex the actual Paint function call for different 73 | // pixel types. As it's cumbersome and ugly, you may want to avoid such 74 | // functions by using ITK for the actual painting and use the ITK access 75 | // macros like we did for the AwesomeImageFilter. 76 | static void Paint(mitk::Image::Pointer image, itk::Index<3> index, unsigned int timeStep) 77 | { 78 | switch (image->GetPixelType().GetComponentType()) 79 | { 80 | case itk::IOComponentEnum::CHAR: 81 | Paint(image, index, timeStep); 82 | break; 83 | 84 | case itk::IOComponentEnum::UCHAR: 85 | Paint(image, index, timeStep); 86 | break; 87 | 88 | case itk::IOComponentEnum::SHORT: 89 | Paint(image, index, timeStep); 90 | break; 91 | 92 | case itk::IOComponentEnum::USHORT: 93 | Paint(image, index, timeStep); 94 | break; 95 | 96 | case itk::IOComponentEnum::INT: 97 | Paint(image, index, timeStep); 98 | break; 99 | 100 | case itk::IOComponentEnum::UINT: 101 | Paint(image, index, timeStep); 102 | break; 103 | 104 | default: 105 | mitkThrow(); 106 | } 107 | } 108 | 109 | ExampleImageInteractor::ExampleImageInteractor() 110 | { 111 | } 112 | 113 | ExampleImageInteractor::~ExampleImageInteractor() 114 | { 115 | } 116 | 117 | void ExampleImageInteractor::ConnectActionsAndFunctions() 118 | { 119 | // Wire up this interactor with the state machine that is described by 120 | // resource/Interactions/Paint.xml. 121 | CONNECT_FUNCTION("paint", Paint) 122 | } 123 | 124 | void ExampleImageInteractor::DataNodeChanged() 125 | { 126 | // You almost always want to reset the state machine when the interactor 127 | // has been attached to another data node. 128 | this->ResetToStartState(); 129 | } 130 | 131 | // The state machine is wired up with this Paint method. We wrote a few helper 132 | // functions at the top of this files to keep this method clear and easy to 133 | // read. 134 | void ExampleImageInteractor::Paint(mitk::StateMachineAction*, mitk::InteractionEvent* event) 135 | { 136 | try 137 | { 138 | auto renderer = event->GetSender(); 139 | 140 | auto image = GetImage(this->GetDataNode()); 141 | auto timeStep = renderer->GetTimeStep(); 142 | auto geometry = GetGeometry(image, timeStep); 143 | 144 | // This method is wired up to mouse events. Thus, we can safely assume 145 | // that the following cast will succeed and we have access to the mouse 146 | // position and the first intersection point of a ray originating at the 147 | // mouse position and shot into the scene. Convenient, isn't it? :-) 148 | auto positionEvent = dynamic_cast(event); 149 | auto position = positionEvent->GetPositionInWorld(); 150 | 151 | if (!geometry->IsInside(position)) 152 | return; // Nothing to paint, as we're not inside the image bounds. 153 | 154 | // Okay, we're safe. Convert the mouse position to the index of the pixel 155 | // we're pointing at. 156 | itk::Index<3> index; 157 | geometry->WorldToIndex<3>(position, index); 158 | 159 | // We don't need to paint over and over again while moving the mouse 160 | // pointer inside the same pixel. That's especially relevant when operating 161 | // on zoomed images. 162 | if (index != m_LastPixelIndex) 163 | { 164 | // And finally... 165 | ::Paint(image, index, timeStep); 166 | 167 | // Nearly done. We request the renderer to update the render window in 168 | // order to see the result immediately. Actually, we should update all 169 | // of the render windows by caling RequestUpdateAll() instead, as the 170 | // painted pixels are possibly visible in other render windows, too. 171 | // However, we decided to prefer performance here. 172 | mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow()); 173 | MITK_INFO << index[0] << " " << index[1] << " " << index[2]; 174 | 175 | m_LastPixelIndex = index; 176 | } 177 | } 178 | catch (...) 179 | { 180 | return; 181 | } 182 | } 183 | --------------------------------------------------------------------------------