Slicer3:Loadable Modules:HOWTO

From Slicer Wiki
Revision as of 02:50, 3 September 2008 by Tgl (talk | contribs) (→‎CMakeLists.txt)
Jump to: navigation, search
Home < Slicer3:Loadable Modules:HOWTO

In order to allow a module to be detected and loaded at runtime (without explicitly being called from the main() routine in Applications/GUI/Slicer3.cxx), do the following:

vtkModuleNameGUI

Required

For your vtkSlicerModuleGUI-derived class, declare and implement:

 virtual void SetModuleLogic(vtkSlicerLogic*)

This is necessary so that the Loadable module code does not need to cast the Logic pointer returned from the defined entry point.

Optional

To add module-specific MRML events to observe, declare and implement:

 virtual vtkIntArray* NewObservableEvents();

To add module-specific initialization code, declare and implement:

 virtual void Init();

This is useful to have your module register callbacks for Picking (See QdecModule).

vtkModuleNameLogic

Optional

To add module-specific MRML events to observe, declare and implement:

 virtual vtkIntArray* NewObservableEvents();

ModuleName.txt

Create ModuleName.txt in the module's directory. ModuleName should follow the naming convention for the *GUI and *Logic classes.

For these two clases:

vtkOpenIGTLinkLogic
vtkOpenIGTLinkGUI

Create:

OpenIGTLink.txt

This file contains naming directives, as well as lists dependencies. At a minimum, the module name must be specified:


 Name: Open IGT Link

Additionally:


 GUIName: OpenIGT
 Dependency: Module One
 Dependency: Module Two

CMakeLists.txt

Most modules will be defined outside of the main Slicer3 build tree. To enable your module to be loaded dynamically, a couple entries in CMakeLists.txt are required.

Near the top of the file, include the directives that will locate the Slicer 3 build tree:

 if(NOT Slicer3_SOURCE_DIR)
   find_package(Slicer3 REQUIRED)
   include(${Slicer3_USE_FILE})
   slicer3_set_default_install_prefix_for_external_projects()
 endif(NOT Slicer3_SOURCE_DIR)

Next, tell CMake to generate the supporting files for Loadable Module:

 generatelm(OpenIGTLink_SRCS OpenIGTLink.txt)

NOTE: The macro should be placed after TCL wrapping is done, as it adds to the source variable. For more details, check the NeuroNav module CMakeLists.txt file, as it provides a good starting point.

Finally, direct CMake to copy the binary files to the Slicer3 library location. This should be the last entry in your CMakeLists file:

 install(TARGETS ${lib_name}
   RUNTIME DESTINATION ${Slicer3_INSTALL_MODULES_BIN_DIR} COMPONENT RuntimeLibraries 
   LIBRARY DESTINATION ${Slicer3_INSTALL_MODULES_LIB_DIR} COMPONENT RuntimeLibraries
   ARCHIVE DESTINATION ${Slicer3_INSTALL_MODULES_LIB_DIR} COMPONENT Development
   )