Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slicer3 for developers – Sonia Pujol, Ph.D. -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning.

Similar presentations


Presentation on theme: "Slicer3 for developers – Sonia Pujol, Ph.D. -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning."— Presentation transcript:

1 Slicer3 for developers – Sonia Pujol, Ph.D. -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning Laboratory Harvard Medical School

2 Slicer3 for developers – Sonia Pujol, Ph.D. -2- National Alliance for Medical Image Computing Slicer3 An end-user application for image analysis An open-source environment for software development A software platform that is both easy to use for clinical researchers and easy to extend for programmers

3 Slicer3 for developers – Sonia Pujol, Ph.D. -3- National Alliance for Medical Image Computing Learning objective Following this course, youll be able 1)to plug-in an external program into Slicer3 2)to implement an image filter and to run the analysis from Slicer3 3)to write and run a test using the CTest tool

4 Slicer3 for developers – Sonia Pujol, Ph.D. -4- National Alliance for Medical Image Computing Material This course requires a user compiled version of the Slicer3 software and the training dataset: Slicer 3 Software and building instructions HelloWorld.zip archive Disclaimer It is the responsibility of the user of 3DSlicer to comply with both the terms of the license and with the applicable laws, regulations and rules.

5 Slicer3 for developers – Sonia Pujol, Ph.D. -5- National Alliance for Medical Image Computing Overview Part A: integration of the HelloWorld program into Slicer3 Part B: implementation of a Discrete Gaussian filter within the HelloWorld module Part C: implementation of a test for the HelloWorld module

6 Slicer3 for developers – Sonia Pujol, Ph.D. -6- National Alliance for Medical Image Computing Part A: Integrating an executable into Slicer3

7 Slicer3 for developers – Sonia Pujol, Ph.D. -7- National Alliance for Medical Image Computing Slicer3 Execution Model This course is based on the Execution Model which provides a mechanism for incorporating command line programs as Slicer modules. The Slicer modules are described using XML files which are used to generate the C++ command line code and the Graphical User Interface (GUI).

8 Slicer3 for developers – Sonia Pujol, Ph.D. -8- National Alliance for Medical Image Computing HelloWorld_CourseMaterial.tgz archive unzip the HelloWorld.zip archive spgr.* (124 SPGR images) HelloWorld.cxx (application) HelloWorld.xml (Execution Model)

9 Slicer3 for developers – Sonia Pujol, Ph.D. -9- National Alliance for Medical Image Computing HelloWorld.xml Demonstration Hello World Slicer Developer Course 1.0 Sonia Pujol, Ph.D. This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB Input/Output Input/output parameters helloWorldInputVolume Input Volume input 0 None Input volume helloWorldOutputVolume Output Volume output 1 Output filtered Module Description Module Parameters Open the file HelloWorld.xml

10 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Module Description Demonstration Hello World Slicer Developer Course 1.0 Sonia Pujol, Ph.D. This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB

11 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Module Parameters Input/Output Input/output parameters helloWorldInputVolume Input Volume input 0 None Input volume helloWorldOutputVolume Output Volume output 1 None Output filtered Input Volume Output Volume A file that specifies the image

12 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Open the file HelloWorld.cxx # include int main(int argc, char * argv []) { std::cout<< Hello World !<

13 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Modifying the source code # include #include HelloWorldCLP.h int main(int argc, char * argv []) { PARSE_ARGS; std::cout<< Hello World !<

14 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Slicer architecture Applications Base CMake Libs Modules Resources Scripts Testing.svn Utilities Slicer3 Slicer3-build Slicer3-lib

15 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Slicer architecture Applications Base CMake Libs Modules Resources Scripts Testing.svn Utilities Slicer3 CLI Copy the 2 files HelloWorld.cxx HelloWorld.xml into the directory Slicer3\Applications\CLI

16 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Slicer architecture Applications Base CMake Libs Modules Resources Scripts Testing.svn Utilities Slicer3 CLI Open the file CMakeLists.txt into the directory Slicer3\Applications\CLI

17 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Editing CMakeLists.txt – part 1 Add the following lines to CMakeLists.txt located in Slicer3/Applications/CLI (above the SUBDIRS lines): SET (CLP HelloWorld) SET (${CLP}_SOURCE ${CLP}.cxx) GENERATECLP(${CLP}_SOURCE ${CLP}.xml) GENERATECLP generates the file HelloWorldCLP.h for parsing the command line arguments. CLP means Command Line Processing

18 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Editing CMakeLists.txt – part 2 ADD_EXECUTABLE creates the stand-alone executable HelloWorld.exe that can be run from a command line. Add the following lines to CMakeLists.txt located in Slicer3/Applications/CLI after the GENERATECLP line you just added ADD_EXECUTABLE(${CLP} ${${CLP}_SOURCE}) TARGET_LINK_LIBRARIES (${CLP} ITKIO ITKBasicFilters ITKCommon)

19 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Mac/Linux Run make in the directory Slicer3-build/Applications/CLI Windows Step1: Select Build Build Slicer3 to build the solution Slicer3.sln located in Slicer3-build/ Step2: Close the solution Slicer3, and re-load it again in the building environment Step3: Select the solution HelloWorld, and launch BuildHelloWorld Building Slicer3

20 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Mac/Linux Run./Slicer3 in Slicer3-build/ Windows Run./Slicer3.exe in Slicer3-build/ Running Slicer3

21 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing HelloWorld module in Slicer3 Select the categoryDemonstration, and the module HelloWorld in the Modules menu

22 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing HelloWorld Module in Slicer3 The program HelloWorld is now integrated into Slicer3

23 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Part B: Implementing an image filter

24 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Goal In this section, well implement a Gaussian smoothing operator to blur the images and remove detail and noise. This implementation will allow us to run the filter on volumes loaded in Slicer, and to integrate the resulting filtered volumes as MRML nodes.

25 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Discrete Gaussian Filter Input volumeOutput volume Variance Discrete Gaussian Filter

26 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Demonstration Hello World Slicer Developer Example 1.0 Sonia Pujol This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB Input/Output Input/output parameters …. Discrete Gaussian Parameters Parameters of the Discrete Gaussian Filter Editing the file HelloWorld.xml Add a new parameter group to HelloWorld.xml

27 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Editing the file HelloWorld.xml Discrete Gaussian Parameters Parameters of the Discrete Gaussian Filter variance --variance Variance ( width of the filter kernel) Variance 0.5 Add the parameter variance which corresponds to the variance of the Discrete Gaussian Filter to HelloWorld.xml

28 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Implementing I/O functionalities Add the following lines to HelloWorld.cxx #include #include "HelloWorldCLP.h" int main(int argc, char * argv []) { PARSE_ARGS; std::cout << "Hello World!" << std::endl; return EXIT_SUCCESS ; } #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h "

29 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing int main ( int argc, char * argv[]) { PARSE_ARGS; std::cout << "Hello World!" << std::endl; typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); return EXIT_SUCCESS; } Implementing Input/Output functionalities Add the following command lines to set-up the reading and writing functionalities in the main procedure in HelloWorld.cxx

30 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing int main ( int argc, char * argv[]) { PARSE_ARGS; std::cout << "Hello World!" << std::endl; typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName(helloWorldInputVolume.c_str() ); writer->SetFileName (helloWorldOutputVolume.c_str()); return EXIT_SUCCESS; } Implementing Input/Output functionalities Set the input and output volumes parameters defined in HelloWorld.xml

31 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing #include "itkDiscreteGaussianImageFilter.h" int main ( int argc, char * argv[]) { PARSE_ARGS; std::cout << "Hello World!" << std::endl; typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName( helloWorldInputVolume.c_str() ); writer->SetFileName(helloWorldOutputVolume.c_str()); typedef itk::DiscreteGaussianImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); return EXIT_SUCCESS; } Implementing the filter in HelloWorld.cxx Implement the filter itk::DiscreteGaussianImageFilter

32 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing int main ( int argc, char * argv[]) { PARSE_ARGS; std::cout << "Hello World!" << std::endl; typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName( helloWorldInputVolume.c_str() ); writer->SetFileName (helloWorldOutputVolume.c_str()); typedef itk::DiscreteGaussianImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); try { filter->SetInput(reader->GetOutput()); filter->SetVariance(variance); writer->SetInput(filter->GetOutput()); writer->Update(); } catch (itk::ExceptionObject &excep){ std::cerr << argv[0] << ": exception caught !" << std::endl; return EXIT_FAILURE;} return EXIT_SUCCESS;} Implementing the filter in HelloWorld.cxx Add the following lines for the filter execution:

33 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing int main ( int argc, char * argv[]) { PARSE_ARGS; std::cout << "Hello World!" << std::endl; typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); reader->SetFileName( helloWorldInputVolume.c_str() ); writer->SetFileName (helloWorldOutputVolume.c_str()); typedef itk::DiscreteGaussianImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); try { filter->SetInput(reader->GetOutput()); filter->SetVariance(variance); writer->SetInput(filter->GetOutput()); writer->Update();} catch (itk::ExceptionObject &excep){ std::cerr << argv[0] << ": exception caught !" << std::endl; return EXIT_FAILURE;} return EXIT_SUCCESS;} Final Version of HelloWorld.cxx - Linux and Mac: Type make in Slicer3-build/ - Windows: build Slicer3.sln

34 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Mac/Linux Run./Slicer3 in Slicer3-build/ Windows Run./Slicer3.exe in Slicer3-build/ Running Slicer3

35 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Running the Filter Go in File Add Volume and load the dataset spgr.nrrd

36 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Browse to the Category Demonstration in the Modules menu, and select the module HelloWorld Running the Filter

37 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Select the input volume spgr.nhdr, the output volume Create New. Enter the value 0.9 for the variance and click on Apply Running the Filter

38 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Slicer displays the filtered volume HelloWorldVolume1. Running the Filter

39 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Select the Foreground volume spgr.nhdr and fade between the Background and Foreground images to visualize the effect of the filter. Running the Filter

40 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Part C: Testing

41 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Goal This section describes a simple example for testing that the help functionality of our newly implemented module HelloWorld works correctly. CTest is a core element of Slicer3s quality control system for software development. The goal of HelloWorldTest1 is to test the following command:./HelloWorld --help

42 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing HelloWorld Test 1 To implement this test, add the following lines to the CMakeLists.txt file located in the directory: Slicer3\Applications\CLI\CMakeLists.txt and build Slicer3 SET (SLICER_EXE ${Slicer3_BINARY_DIR}/Slicer3 ) IF (WIN32) ADD_TEST(HelloWorldTest1 ${SLICER_EXE} --launch ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${CLP} --help) ELSE(WIN32) ADD_TEST(HelloWorldTest1 ${SLICER_EXE} --launch ${EXECUTABLE_OUTPUT_PATH}/${CLP} --help) ENDIF (WIN32)

43 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing HelloWorld Test 1 SET( SLICER_EXE ${Slicer3_BINARY_DIR}/Slicer3 ) IF (WIN32) ADD_TEST(HelloWorldTest1 ${SLICER_EXE} --launch ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${CLP} --help) ELSE(WIN32) ADD_TEST(HelloWorldTest1 ${SLICER_EXE} --launch ${EXECUTABLE_OUTPUT_PATH}/${CLP} --help) ENDIF (WIN32)

44 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Mac/Linux In Slicer3-build/ run../Slicer3-lib/CMake-build/bin/ctest -R HelloWorldTest1 Windows In Slicer3-build/ run../Slicer3-lib/CMake-build/bin/ctest.exe -R HelloWorldTest1 Running HelloWorldTest1

45 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Running HelloWorldTest1 When the module successfully passes the test, the output below is generated:

46 Slicer3 for developers – Sonia Pujol, Ph.D National Alliance for Medical Image Computing Conclusion This course described functionalities for integrating, developing and testing external program within Slicer3. The Execution Model of Slicer3 provides a simple mechanism for incorporating command line programs as Slicer modules.


Download ppt "Slicer3 for developers – Sonia Pujol, Ph.D. -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning."

Similar presentations


Ads by Google