|
|
(2 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
− | = Creating a New Loadable Module =
| + | <big>'''Note:''' We are migrating this content to the slicer.org domain - <font color="orange">The newer page is [https://www.slicer.org/wiki/Slicer3:Transition_of_Slicer2.x_Modules:Template_Notes here]</font></big> |
− | | |
− | The following steps detail how to make a new Slicer3 loadable module called MyModule. To create a new command line interface (CLI) module, see [[Slicer3:Execution_Model_Documentation|Execution Model Documentation]] and [http://www.na-mic.org:8000/svn/Slicer3/trunk/Applications/CLI/ Examples].
| |
− | | |
− | Please read the [[Slicer3:Style_and_Conventions|Style and Coding Conventions]] before beginning.
| |
− | | |
− | = Set up =
| |
− | | |
− | * [[Slicer3:Build_Instructions|Build Slicer3]]
| |
− | * Create a directory for your module in Slicer3/Modules
| |
− | | |
− | mkdir Slicer3/Modules/MyModule
| |
− | | |
− | * Add the module to the SUBDIRS variable in Slicer3/Modules/CMakeLists.txt
| |
− | | |
− | SUBDIRS(
| |
− | BaseClasses
| |
− | MyModule
| |
− | [...]
| |
− | )
| |
− | | |
− | = CMakeLists.txt =
| |
− | | |
− | * Create a CMakeLists.txt file in Slicer3/Modules/MyModule with the following contents:
| |
− | | |
− | PROJECT(MyModule)
| |
− | # Sources
| |
− | SET(MyModule_SRCS
| |
− | vtkMyModuleGUI.cxx
| |
− | vtkMyModuleLogic.cxx
| |
− | # vtkMRMLMyModuleNode.cxx
| |
− | )
| |
− | # Include dirs
| |
− | INCLUDE_DIRECTORIES(
| |
− | ${ModulesBaseClasses_SOURCE_DIR}
| |
− | ${ModulesBaseClasses_BINARY_DIR}
| |
− | ${MyModule_SOURCE_DIR}
| |
− | ${MyModule_BINARY_DIR)
| |
− | ${SlicerBase_SOURCE_DIR}
| |
− | ${SlicerBase_BINARY_DIR}
| |
− | ${SlicerBaseLogic_SOURCE_DIR}
| |
− | ${SlicerBaseLogic_BINARY_DIR}
| |
− | ${SlicerBaseGUI_SOURCE_DIR}
| |
− | ${SlicerBaseGUI_BINARY_DIR}
| |
− | ${vtkITK_SOURCE_DIR}
| |
− | ${vtkITK_BINARY_DIR}
| |
− | ${ITK_INCLUDE_DIR}
| |
− | ${VTK_INCLUDE_DIR}
| |
− | ${MRML_SOURCE_DIR}
| |
− | ${MRML_BINARY_DIR}
| |
− | )
| |
− | # Wrapping
| |
− | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
| |
− | INCLUDE("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
| |
− | VTK_WRAP_TCL3(MyModule MyModule_TCL_SRCS "${MyModule_SRCS}" "")
| |
− | # Build the library
| |
− | ADD_LIBRARY(MyModule
| |
− | ${MyModule_SRCS}
| |
− | ${MyModule_TCL_SRCS}
| |
− | )
| |
− | IF(BUILD_SHARED_LIBS)
| |
− | INSTALL_TARGETS(${SLICER3_LIB_INSTALL_DIR} MyModule)
| |
− | ENDIF(BUILD_SHARED_LIBS)
| |
− | TARGET_LINK_LIBRARIES(MyModule
| |
− | ModulesBaseClasses
| |
− | SlicerBaseLogic
| |
− | SlicerBaseGUI
| |
− | MRML
| |
− | vtkITK
| |
− | vtkCommonTCL
| |
− | vtkImagingTCL
| |
− | vtkFilteringTCL
| |
− | vtkIOTCL
| |
− | ITKAlgorithms
| |
− | ITKNumerics
| |
− | ITKCommon
| |
− | ITKBasicFilters
| |
− | ITKNumerics
| |
− | ITKStatistics
| |
− | ITKBasicFilters
| |
− | ITKIO
| |
− | ITKDICOMParser
| |
− | ${KWWidgets_LIBRARIES} )
| |
− | # Testing
| |
− | IF(BUILD_TESTING)
| |
− | SUBDIRS(Testing)
| |
− | ENDIF(BUILD_TESTING)
| |
− | CONFIGURE_FILE(
| |
− | ${MyModule_SOURCE_DIR}/vtkMyModuleConfigure.h.in
| |
− | ${MyModule_BINARY_DIR}/vtkMyModuleConfigure.h
| |
− | )
| |
− | | |
− | = Testing directory =
| |
− | | |
− | Make the Testing subdirctory
| |
− | | |
− | mkdir Slicer3/Modules/MyModule/Testing
| |
− | | |
− | = Configuration files =
| |
− | | |
− | Create the VTK configuration files:
| |
− | | |
− | * Slicer3/Modules/MyModule/vtkMyModuleConfigure.h.in
| |
− | | |
− | #if defined(WIN32) && !defined(VTKSLICER_STATIC)
| |
− | #pragma warning ( disable : 4275 )
| |
− | #endif
| |
− | #cmakedefine CMAKE_WORDS_BIGENDIAN
| |
− | #ifdef CMAKE_WORDS_BIGENDIAN
| |
− | #define WORDS_BIGENDIAN
| |
− | #else
| |
− | #define WORDS_LITTLEENDIAN
| |
− | #endif
| |
− | #cmakedefine BUILD_SHARED_LIBS
| |
− | #ifndef BUILD_SHARED_LIBS
| |
− | #define VTKSLICER_STATIC
| |
− | #endif
| |
− | | |
− | * Slicer3/Modules/MyModule/vtkMyModuleWin32Header.h
| |
− | | |
− | #ifndef __vtkMyModule_h
| |
− | #define __vtkMyModule_h
| |
− | #include <vtkMyModuleConfigure.h>
| |
− | #if defined(WIN32) && !defined(VTKSLICER_STATIC)
| |
− | #if defined(MyModule_EXPORTS)
| |
− | #define VTK_MYMODULE_EXPORT __declspec( dllexport )
| |
− | #else
| |
− | #define VTK_MYMODULE_EXPORT __declspec( dllimport )
| |
− | #endif
| |
− | #else
| |
− | #define VTK_MYMODULE_EXPORT
| |
− | #endif
| |
− | #endif
| |
− | | |
− | * Create the header file vtkMyModule.h
| |
− | | |
− | #include "vtkMyModuleWin32Header.h"
| |
− | | |
− | = Logic =
| |
− | | |
− | Create the Logic files:
| |
− | | |
− | * vtkMyModuleLogic.cxx
| |
− | * vtkMyModuleLogic.h
| |
− | | |
− | = Gui =
| |
− | | |
− | Create the GUI files:
| |
− | | |
− | * vtkMyModuleGUI.h
| |
− | | |
− | <nowiki>#ifndef __vtkMyModuleGUI_h
| |
− | #define __vtkMyModuleGUI_h
| |
− |
| |
− | #include "vtkSlicerBaseGUIWin32Header.h"
| |
− | #include "vtkSlicerModuleGUI.h"
| |
− |
| |
− | #include "vtkMRMLScene.h"
| |
− | #include "vtkMyModuleLogic.h"
| |
− |
| |
− | class vtkKWFrame;
| |
− | class vtkKWScaleWithEntry;
| |
− | class vtkKWPushButton;
| |
− | class vtkSlicerNodeSelectorWidget;
| |
− |
| |
− | class VTK_MYMODULE_EXPORT vtkMyModuleGUI : public vtkSlicerModuleGUI
| |
− | {
| |
− | public:
| |
− | static vtkMyModuleGUI *New();
| |
− | vtkTypeMacro(vtkMyModuleGUI,vtkSlicerModuleGUI);
| |
− | void PrintSelf(osstream& os, vtkIndent indent);
| |
− |
| |
− | // Description: Get/Set the Logic
| |
− | vtkGetObjectMacro(Logic, vtkMyModuleLogic);
| |
− | vtkSetObjectMacro(Logic, vtkMyModuleLogic);
| |
− |
| |
− | // Description: Get/Set the MRML node
| |
− | vtkGetObjectMacro(MyModuleNode, vtkMRMLMyModuleNode);
| |
− | vtkSetObjectMacro(MyModuleNode, vtkMRMLMyModuleNode);
| |
− | // Create widgets
| |
− | virtual void BuildGUI ( );
| |
− |
| |
− | // Description:
| |
− | // Add obsereves to GUI widgets
| |
− | virtual void AddGUIObservers ( );
| |
− |
| |
− | // Description:
| |
− | // Remove obsereves to GUI widgets
| |
− | virtual void RemoveGUIObservers ( );
| |
− |
| |
− | // Description:
| |
− | // Process events generated by Logic
| |
− | virtual void ProcessLogicEvents ( vtkObject *caller, unsigned long event,
| |
− | void *callData ){};
| |
− |
| |
− | // Description:
| |
− | // Process events generated by GUI widgets
| |
− | virtual void ProcessGUIEvents ( vtkObject *caller, unsigned long event,
| |
− | void *callData );
| |
− |
| |
− | // Description:
| |
− | // Process events generated by MRML
| |
− | virtual void ProcessMRMLEvents ( vtkObject *caller, unsigned long event,
| |
− | void *callData);
| |
− | // Description:
| |
− | // Describe behavior at module startup and exit.
| |
− | virtual void Enter ( ){};
| |
− | virtual void Exit ( ){};
| |
− |
| |
− | protected:
| |
− | vtkMyModuleGUI();
| |
− | ~vtkMyModuleGUI();
| |
− | vtkMyModuleGUI(const vtkMyModuleGUI&);
| |
− | void operator=(const vtkMyModuleGUI&);
| |
− |
| |
− | // Description:
| |
− | // Updates GUI widgets based on parameters values in MRML node
| |
− | void UpdateGUI();
| |
− |
| |
− | // Description:
| |
− | // Updates parameters values in MRML node based on GUI widgets
| |
− | void UpdateMRML();
| |
− |
| |
− | // Description: widgets
| |
− | vtkKWScaleWithEntry* MyModuleScale;
| |
− | vtkSlicerNodeSelectorWidget* VolumeSelector;
| |
− | vtkKWPushButton* ApplyButton;
| |
− |
| |
− | vtkMyModuleLogic *Logic;
| |
− | vtkMRMLMyModuleNode* MyModuleNode;
| |
− | };
| |
− |
| |
− | #endif
| |
− | </nowiki>
| |
− | | |
− | * vtkMyModuleGUI.cxx
| |
− | | |
− | <nowiki>#include <string>
| |
− | #include <iostream>
| |
− | #include <sstream>
| |
− |
| |
− | #include "vtkObjectFactory.h"
| |
− |
| |
− | #include "vtkMyModuleGUI.h"
| |
− |
| |
− | #include "vtkCommand.h"
| |
− | #include "vtkKWApplication.h"
| |
− | #include "vtkKWWidget.h"
| |
− | #include "vtkSlicerApplication.h"
| |
− | #include "vtkSlicerApplicationLogic.h"
| |
− | #include "vtkSlicerNodeSelectorWidget.h"
| |
− | #include "vtkKWScaleWithEntry.h"
| |
− | #include "vtkKWEntryWithLabel.h"
| |
− | #include "vtkKWMenuButtonWithLabel.h"
| |
− | #include "vtkKWMenuButton.h"
| |
− | #include "vtkKWScale.h"
| |
− | #include "vtkKWMenu.h"
| |
− | #include "vtkKWEntry.h"
| |
− | #include "vtkKWFrame.h"
| |
− | #include "vtkSlicerApplication.h"
| |
− | #include "vtkKWFrameWithLabel.h"
| |
− | #include "vtkKWPushButton.h"
| |
− |
| |
− | //------------------------------------------------------------------------------
| |
− | vtkMyModuleGUI* vtkMyModuleGUI::New()
| |
− | { | |
− | // First try to create the object from the vtkObjectFactory
| |
− | vtkObject* ret = vtkObjectFactory::CreateInstance("vtkMyModuleGUI");
| |
− | if(ret)
| |
− | {
| |
− | return (vtkMyModuleGUI*)ret;
| |
− | }
| |
− | // If the factory was unable to create the object, then create it here.
| |
− | return new vtkMyModuleGUI;
| |
− | }
| |
− |
| |
− | //----------------------------------------------------------------------------
| |
− | vtkMyModuleGUI::vtkMyModuleGUI()
| |
− | {
| |
− | this->MyModuleScale = vtkKWScaleWithEntry::New();
| |
− | this->VolumeSelector = vtkSlicerNodeSelectorWidget::New();
| |
− | this->ApplyButton = vtkKWPushBUtton::New();
| |
− | this->Logic = NULL;
| |
− | this->MyModuleNode = NULL;
| |
− | }
| |
− |
| |
− | //----------------------------------------------------------------------------
| |
− | vtkMyModuleGUI::~vtkMyModuleGUI()
| |
− | {
| |
− | if (this->MyModuleScale) {
| |
− | this->MyModuleScale->Delete();
| |
− | this->MyModuleScale = NULL;
| |
− | }
| |
− | if (this->VolumeSelector) {
| |
− | this->VolumeSelector->Delete();
| |
− | this->VolumeSelector = NULL;
| |
− | }
| |
− | if ( this->ApplyButton ) {
| |
− | this->ApplyButton->Delete();
| |
− | this->ApplyButton = NULL;
| |
− | }
| |
− |
| |
− | this->SetLogic (NULL);
| |
− | if ( this->MyModuleNode ) {
| |
− | this->SetAndObserveMRML( vtkObjectPointer(&this->MyModuleNode), NULL );
| |
− | }
| |
− | this->SetMyModuleNode (NULL);
| |
− | }
| |
− |
| |
− | //----------------------------------------------------------------------------
| |
− | void vtkMyModuleGUI::PrintSelf(ostream& os, vtkIndent indent)
| |
− | {
| |
− | os << indent << "MyModule:";
| |
− | }
| |
− | </nowiki>
| |
− | | |
− | = MRML Node =
| |
− | | |
− | If you need a MRML node, create:
| |
− | | |
− | * vtkMRMLMyModuleNode.cxx
| |
− | * vtkMRMLMyModuleNode.h
| |
− | | |
− | And uncomment out the relevant lines in the files above.
| |
− | | |
− | <br /> | |
− | | |
− | ----
| |
− | | |
− | [[Slicer3:Transition_of_Slicer2.x_Modules|Back to Transition of Slicer 2.x modules]]
| |