Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol,

Slides:



Advertisements
Similar presentations
ITK-Overview Insight Software Consortium. What is ITK Image Processing Segmentation Registration No Graphical User Interface (GUI) No Visualization.
Advertisements

Surgical Planning Laboratory -1- Brigham and Womens Hospital Slicer Tutorial 7 Saving Data Sonia Pujol, Ph.D. Randy Gollub, M.D.,
Pujol S, Gollub R -1- National Alliance for Medical Image Computing Stochastic Tractography Module Tri Ngo Slicer3 Training Compendium.
Slicer3 for developers – Sonia Pujol, Ph.D. -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning.
NA-MIC National Alliance for Medical Image Computing © 2010, All Rights Reserved Diffusion Tensor Imaging Tutorial Sonia Pujol, Ph.D.
Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School National Alliance for Medical Image Computing ©2010,ARR
Tokuda, J National Alliance for Medical Image Computing NA-MIC© 2010, ARR Connecting IGT Device with OpenIGTLink Junichi Tokuda, PhD Slicer3 Training Compendium.
National Alliance for Medical Image Computing © 2010, All Rights Reserved Sonia Pujol, PhD Slicer3Minute Tutorial Sonia.
National Alliance for Medical Image Computing © 2010, ARR Sonia Pujol, PhD Slicer3Minute Tutorial Slicer3 minute tutorial.
NA-MIC National Alliance for Medical Image Computing Diffusion Tensor Imaging tutorial Sonia Pujol, PhD Surgical Planning Laboratory.
NA-MIC National Alliance for Medical Image Computing © 2010, All Rights Reserved Diffusion Tensor Imaging Tutorial Sonia Pujol, Ph.D.
Data Loading & and Visualization Sonia Pujol, Ph.D. Surgical Planning Laboratory Harvard Medical School National Alliance for Medical Image Computing Neuroimage.
National Alliance for Medical Image Computing ITK The Image Segmentation and Registration Toolkit Julien Jomier Kitware Inc.
Slicer Welcome Tutorial
1 Visual Basic.NET Application Overview. 2 Objectives Discuss what a typical Visual Basic.NET application looks like Configure the Visual Studio.NET Integrated.
National Alliance for Medical Image Computing User Desktop Slicer 3.0 Architecure AlgorithmsITKVTK Slicer Modules VTK Apps Using ITK.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Slicer Training 1 Loading and Viewing Data Sonia Pujol, Ph.D. Randy.
Pohl K, Konukoglu E -1- National Alliance for Medical Image Computing Measuring Volume Change in Tumors Kilian M Pohl, PhD Ender Konugolu Slicer3 Training.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Slicer Training 1: Loading and Viewing Data.
NA-MIC National Alliance for Medical Image Computing Interactive Editor tutorial Sonia Pujol, Ph.D. Surgical Planning Laboratory Harvard.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
NA-MIC National Alliance for Medical Image Computing IGT Software Design and Process Bill Lorensen GE Research.
-1- Pujol S et al. National Alliance for Medical Image Computing 3D Visualization of FreeSurfer Data Sonia Pujol, Ph.D. Silas Mann, B.Sc. Randy Gollub,
Image Registration Lecture 7: Getting Started with ITK March 15, 2005 Prof. Charlene Tsai.
-- CTSA at RSNA 2009 PET/CT Analysis using 3D Slicer Jeffrey Yap PhD Ron Kikinis MD Wendy Plesniak PhD Slicer3 Training Compendium.
NA-MIC National Alliance for Medical Image Computing shapeAnalysisMANCOVA_Wizar d Lucile Bompard, Clement Vacher, Beatriz Paniagua, Martin.
Slicer3 Training Tutorial IA-FEMesh v1.0
IE 411/511: Visual Programming for Industrial Applications
NA-MIC National Alliance for Medical Image Computing Fiducials Nicole Aucoin Brigham and Women's Hospital
NA-MIC National Alliance for Medical Image Computing Slicer3 and the NA-MIC kit Sonia Pujol, Ph.D. Instructor of Radiology Surgical Planning.
-1- 3D Visualization. Sonia Pujol, Ph.D., Harvard Medical School National Alliance for Medical Image Computing 3D Visualization Sonia Pujol, Ph.D. Surgical.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Slicer Training 10 EMAtlasBrainClassifier Sonia Pujol, Ph.D. Randy.
ITK Input/Output Kitware Inc.. Overview IO Factory Mechanism Image File IO Transform File IO SpatialObject File IO Logger.
0 eCPIC User Training: Dependency Mapper These training materials are owned by the Federal Government. They can be used or modified only by FESCOM member.
Pujol S., Plesniak, W. -1- National Alliance for Medical Image Computing Neuroimage Analysis Center Harvard CTSC Slicer3 minute tutorial Sonia Pujol, PhD.
DICOM to NRRD Conversion Tutorial Martin Styner 1 University of North Carolina Neuro Image Research and Analysis Lab.
Sonia Pujol, PhD National Alliance for Medical Image Computing © 2010, ARR.
Chapter 2 – Introduction to the Visual Studio .NET IDE
NA-MIC National Alliance for Medical Image Computing Slicer and ITK Raul San Jose.
Slicer3 for developers – S.Pujol -1- National Alliance for Medical Image Computing Slicer3 Course for developers Sonia Pujol, Ph.D. Surgical Planning Laboratory.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Slicer Training 1 Loading and Viewing Data Sonia Pujol, Ph.D. Randy.
Exploring Peritumoral White Matter Fibers for Neurosurgical Planning Sonia Pujol, Ph.D. Ron Kikinis, M.D. Surgical Planning Laboratory Harvard University.
NA-MIC National Alliance for Medical Image Computing Shape analysis using spherical harmonics Lucile Bompard, Clement Vachet, Beatriz.
Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School National Alliance for Medical Image Computing ©
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Converting DTI data into Nrrd file format Sonia Pujol, Ph.D. Gordon.
NA-MIC National Alliance for Medical Image Computing Diffusion Tensor Imaging tutorial Sonia Pujol, PhD Surgical Planning Laboratory.
Sonia Pujol, PhD -1- National Alliance for Medical Image Computing Neuroimage Analysis Center Diffusion Tensor Imaging tutorial Sonia Pujol, Ph.D. Surgical.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital 3DSlicer Hands-on session Sonia Pujol, Ph.D.
NA-MIC National Alliance for Medical Image Computing Slicer3 Tutorial Nonrigid Atlas Registration Dominik Meier, Ron Kikinis February.
Read a DICOM File typedef unsigned charInputPixelType; const unsigned intInputDimension = 2; typedef itk::Image InputImageType; typedef itk::ImageFileReader.
-1- National Alliance for Medical Image Computing MR-guided prostate interventions using the NA-MIC Kit Danielle Pace, B.CmpH and Sota Oguro, M.D. Surgical.
Pujol S, Gollub R -1- National Alliance for Medical Image Computing Slicer3 Training Tutorial Python Stochastic Tractography Module Doug Terry, Julien.
NA-MIC National Alliance for Medical Image Computing BRAINSCut General Tutorial Eun Young(Regina) Kim University of Iowa
Standard Response Evaluation Criteria in Solid Tumors (RECIST) using 3D Slicer Slicer3 Training Compendium Image here. Jeffrey Yap, PhD Wendy Plesniak,
ITK Statistical Classification Kitware Inc.. Statistical Classification Multiple Components Images K-Means Markov Random Fields.
Debugging Lab Antonio Gómez-Iglesias Texas Advanced Computing Center.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
National Alliance for Medical Image Computing Slicer3 Plugins Common architecture for interactive and batch processing.
NA-MIC National Alliance for Medical Image Computing Three ways to use the NA-MIC kit Sonia Pujol, Ph.D. Instructor of Radiology Surgical.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Slicer Tutorial 4 Module: DTMRI Data: Sample Slicer DTI Sonia Pujol,
3D Visualization Sonia Pujol, Ph.D. Instructor of Radiology
Fiber Bundle Volume Measurement
Chapter 2 – Introduction to the Visual Studio .NET IDE
shapeAnalysisMANCOVA_Wizard
ITK-Overview Insight Software Consortium.
3D Visualization of FreeSurfer Data
Automatic SPHARM Shape Analysis in 3D Slicer
Interactive Editor tutorial
Presentation transcript:

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol, Ph.D. Surgical Planning Laboratory Harvard University Ferdinand Bol ( ), The Officers of the Amsterdam Guild of Wine Merchants Alte Pinakothek, München NA-MIC Training Workshop, Stanford University, September 3, 2008

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -2- National Alliance for Medical Image Computing The NA-MIC Kit

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -3- 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 Integrated Volume Rendering. R.Kikinis

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -4- National Alliance for Medical Image Computing Before Slicer3 Slicer2

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -5- National Alliance for Medical Image Computing Programming into Slicer2 # # 1. Step # set f $fSeg.fStep1 DevAddLabel $f.lTitle "1. Select Input Channels: " WTA pack $f.lTitle -side top -padx $Gui(pad) -pady 1 -anchor w frame $f.fInput -bg $Gui(activeWorkspace) pack $f.fInput -side top -padx 0 -pady 0 -anchor w foreach frame "Left Right" { frame $f.fInput.f$frame -bg $Gui(activeWorkspace) pack $f.fInput.f$frame -side left -padx 0 -pady $Gui(pad) } foreach LABEL "T1 T2" Input "SPGR T2W" { DevAddLabel $f.fInput.fLeft.l$Input " ${LABEL}:" pack $f.fInput.fLeft.l$Input -side top -padx $Gui(pad) -pady 1 -anchor w set menubutton $f.fInput.fRight.m${Input}Select set menu $f.fInput.fRight.m${Input}Select.m eval {menubutton $menubutton -text [Volume($EMAtlasBrainClassifier(Volume,${Input}),node) GetName] -relief raised -bd 2 -width 9 -menu $menu} $Gui(WMBA) eval {menu $menu} $Gui(WMA) TooltipAdd $menubutton "Select Volume defining ${Input}" set EMAtlasBrainClassifier(mbSeg-${Input}Select) $menubutton set EMAtlasBrainClassifier(mSeg-${Input}Select) $menu # Have to update at UpdateMRML too DevUpdateNodeSelectButton Volume EMAtlasBrainClassifier Seg-${Input}Select Volume,$Input pack $menubutton -side top -padx $Gui(pad) -pady 1 -anchor w } frame $f.fAlign -bg $Gui(activeWorkspace) TooltipAdd $f.fAlign "If the input T1 and T2 are not aligned with each other set flag here" pack $f.fAlign -side top -padx 0 -pady 2 -padx $Gui(pad) -anchor w DevAddLabel $f.fAlign.lAlign "Align T2 to T1? " pack $f.fAlign.lAlign -side left -padx $Gui(pad) -pady 1 -anchor w foreach value "1 0" text "On Off" width "4 4" { eval {radiobutton $f.fAlign.r$value -width $width -indicatoron 0\ -text "$text" -value "$value" -variable EMAtlasBrainClassifier(AlignInput) } $Gui(WCA) pack $f.fAlign.r$value -side left -padx 0 -pady 0 }

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -6- National Alliance for Medical Image Computing From Slicer2 to Slicer3 Slicer2Slicer3

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -7- National Alliance for Medical Image Computing The New Execution Model Demonstration Hello World Slicer Developer Course 1.0 Sonia Pujol, Ph.D., Surgical Planning Laboratory, Harvard Medical School National Alliance for Medical Image Computing (NAMIC), Grant U54 EB Input/Output Input/output parameters helloWorldInputVolume Input Volume input 0 None Input volume helloWorldOutputVolume Output Volume output 1 None Output filtered

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -8- 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. Slicer Communication with external executables Jim Miller, Dan Blezek, Bill Lorensen (GE)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -9- National Alliance for Medical Image Computing Learning objective Following this course, you’ll 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -10- National Alliance for Medical Image Computing Material This course requires the following material Slicer 3 Software HelloWorld_Plugin.tar.gz 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.

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -11- National Alliance for Medical Image Computing HelloWorld_CourseMaterial.tgz archive tar –zxvf the HelloWorld_Plugin.tar.gz spgr.nhdr spgr.raw.gz (124 SPGR images) HelloWorld.cxx (application) HelloWorld.xml (Execution Model) CMakeLists.txt (CMake)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -12- 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -13- National Alliance for Medical Image Computing Slicer Programming Course

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -14- National Alliance for Medical Image Computing Part A: Integrating an executable into Slicer3

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -15- National Alliance for Medical Image Computing Slicer3 Execution Model 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 –the Graphical User Interface (GUI).

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -16- National Alliance for Medical Image Computing Open the file CMakeLists.txt located in the directory /HelloWorld_Plugin/HelloWorld/ Modifying CMakeLists.txt

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -17- National Alliance for Medical Image Computing Editing CMakeLists.txt – part 1 Add the following lines to CMakeLists.txt 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -18- 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 after the ‘generateclp’ line you just added add_executable(${CLP} ${${CLP}_SOURCE}) slicer3_set_plugins_output_path(${CLP}) target_link_libraries (${CLP} ${ITK_LIBRARIES}) Save the file after editing

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -19- National Alliance for Medical Image Computing Launch the CMake executable located in the directory Slicer3-lib/CMake-build/bin Configuring HelloWorld - WINDOWS (1/5)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -20- National Alliance for Medical Image Computing Configuring HelloWorld - WINDOWS (2/5) Enter the path to the \HelloWorld directory that contains the source code Enter the path to the \HelloWorld-build directory where the binaries will be built Click on Configure

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -21- National Alliance for Medical Image Computing Select the compiler which is installed on your machine, and click on OK Configuring HelloWorld - WINDOWS (3/5)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -22- National Alliance for Medical Image Computing Configuring HelloWorld - WINDOWS (3/5) A CMake message appears as CMake cannot find the path to Slicer3 Click on Cancel

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -23- National Alliance for Medical Image Computing Enter the path to the \Slicer3-build directory, and click on Configure. Configuring HelloWorld - WINDOWS (4/5)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -24- National Alliance for Medical Image Computing Click on OK to generate the build files in the HelloWorld-build directory, and exit Configuring HelloWorld - WINDOWS (5/5)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -25- National Alliance for Medical Image Computing Configuring HelloWorld (Linux & Mac) 1/4 From the HelloWorld-build/ directory, launch the ccmake executable located in the Slicer3-lib/CMake-build/bin/ directory cd HelloWorld_Plugin/HelloWorld-build/ /projects/na-mic/spujol/software/slicer3- developer/slicer3Stanford2008/Slicer3-lib/CMake-build/bin/ccmake../HelloWorld

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -26- National Alliance for Medical Image Computing Hit c to configure You need to enter the path to Slicer3 manually: Press e to get to the configuration options Configuring HelloWorld (Linux & Mac) 2/4

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -27- National Alliance for Medical Image Computing Enter the path to the directory Slicer3-build/: Arrow down to the Slicer3_DIR and Hit Enter to edit the path Arrow up once you have finished editing the path Configuring HelloWorld (Linux & Mac) 3/4

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -28- National Alliance for Medical Image Computing Press C to configure Press C to configure again Press G to generate the Makefile Configuring HelloWorld (Linux & Mac) 4/4

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -29- National Alliance for Medical Image Computing HelloWorld.xml Demonstration Hello World Slicer Developer Course Sonia Pujol, Ph.D., Surgical Planning Laboratory, Harvard Medical School 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 None Output filtered Module Description Module Parameters Open the file HelloWorld.xml located in the directory HelloWorld_Plugin/HelloWorld

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -30- National Alliance for Medical Image Computing Module Description Demonstration Hello World Slicer Developer Course 1.0 Sonia Pujol, Ph.D., Surgical Planning Laboratory, Harvard Medical School 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -31- 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -32- National Alliance for Medical Image Computing Open the file HelloWorld.cxx # include int main(int argc, char * argv []) { std::cout<< “Hello World !”<<std::endl; return 0 ; } Modifying the source code

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -33- 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 !”<<std::endl; return EXIT_SUCCESS ; } Add the following lines to the file HelloWorld.cxx

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -34- National Alliance for Medical Image Computing Mac/Linux Run ‘make’ in the directory HelloWorld-build/ Windows In Visual Studio, select Build  Build Solution to build the solution HelloWorld.sln located in HelloWorld-build/ Building HelloWorld.exe

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -35- National Alliance for Medical Image Computing Mac/Linux HelloWorld.exe is located in /HelloWorld-build/lib/slicer3/plugins Windows HelloWorld.exe is located in /HelloWorld-build/lib/slicer3/plugins/debug Building HelloWorld.exe

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -36- National Alliance for Medical Image Computing Mac/Linux Run ‘./Slicer3’ in Slicer3-build/ Windows Run ‘./Slicer3’ in Slicer3-build/ Running Slicer3

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -37- National Alliance for Medical Image Computing Running Slicer3 Click on the View  Application Settings in the main menu

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -38- National Alliance for Medical Image Computing Setting the HelloWorld plugin path Select View  Application Settings from the Main Menu Select Module Settings from the Application Settings GUI

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -39- National Alliance for Medical Image Computing Setting the HelloWorld plugin path Click on the ‘Add a preset’ button, and enter the path to HelloWorld.exe.

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -40- National Alliance for Medical Image Computing Setting the HelloWorld plugin path The path to the HelloWorld executable is set-up in Slicer3. Click on the Close to exit the Application Settings window.

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -41- National Alliance for Medical Image Computing Setting the HelloWorld plugin path Select File  Exit to exit Slicer3.

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -42- National Alliance for Medical Image Computing Mac/Linux Run ‘./Slicer3’ in Slicer3-build/ Windows Run ‘./Slicer3.exe’ in Slicer3-build/ Running Slicer3

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -43- National Alliance for Medical Image Computing HelloWorld module in Slicer3 Select the category ‘Demonstration’, and the module ‘HelloWorld’ in the Modules menu

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -44- National Alliance for Medical Image Computing HelloWorld Module in Slicer3 The program ‘HelloWorld’ is now integrated into Slicer3

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -45- National Alliance for Medical Image Computing Part B: Implementing an image filter

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -46- National Alliance for Medical Image Computing Goal In this section, we’ll 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.

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -47- National Alliance for Medical Image Computing Discrete Gaussian Filter Input volumeOutput volume Variance Discrete Gaussian Filter

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -48- National Alliance for Medical Image Computing Demonstration Hello World Slicer Developer Example 1.0 Sonia Pujol, Ph.D, Surgical Planning Laboratory, Harvard Medical School 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -49- 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -50- 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 "

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -51- 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 I/O functionalities Add the following command lines to set-up the reading and writing functionalities in the ‘main’ procedure in HelloWorld.cxx

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -52- 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 I/O functionalities Set the input and output volumes parameters defined in HelloWorld.xml

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -53- 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -54- 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:

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -55- National Alliance for Medical Image Computing Mac/Linux Run ‘make’ in the directory HelloWorld-build/ Windows Select Build  Build Solution to build the solution HelloWorld.sln located in HelloWorld-build/ Building HelloWorld

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -56- National Alliance for Medical Image Computing Mac/Linux Run ‘./Slicer3’ in Slicer3-build/ Windows Run ‘./Slicer3.exe’ in Slicer3-build/ Running Slicer3

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -57- National Alliance for Medical Image Computing Running the Filter Go in File  Add Volume and load the dataset spgr.nrrd located in the directory HelloWorld_Plugin/data/

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -58- National Alliance for Medical Image Computing Browse to the Category ‘Demonstration’ in the Modules menu, and select the module ‘HelloWorld’ Running the Filter

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -59- 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -60- National Alliance for Medical Image Computing Slicer displays the filtered volume ‘HelloWorldVolume1’. Running the Filter

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -61- 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

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -62- National Alliance for Medical Image Computing Part C: Testing

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -63- 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 Slicer3’s quality control system for software development. The goal of ‘HelloWorldTest1’ is to test the following command:./HelloWorld --help

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -64- National Alliance for Medical Image Computing HelloWorld Test 1 To implement the test HelloWorldTest1, add the following lines to the CMakeLists.txt file located in the HelloWorld\ directory: set (SLICER_EXE ${Slicer3_HOME}/Slicer3) set(BUILD_SUBDIR "") if(WIN32) set(BUILD_SUBDIR Debug) endif(WIN32) add_test(HelloWorldTest1 ${SLICER_EXE} --launch ${Slicer3_INSTALL_PLUGINS_BIN_DIR}/${BUILD_SUBDIR}/${CLP} --help)

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -65- National Alliance for Medical Image Computing Mac/Linux Run ‘make’ in the directory HelloWorld-build/ Windows Select Build  Build Solution to build the solution HelloWorld.sln located in HelloWorld-build/ Building HelloWorld

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -66- National Alliance for Medical Image Computing Mac/Linux In the directory /HelloWorld-build/ run the following command: Slicer3-lib/CMake-build/bin/ctest –R HelloWorldTest1 Windows In the directory /HelloWorld-build/ run the following command: /cygdrive/c/slicer3Stanford2008/Slicer3-lib/CMake-build/bin/ctest.exe –R HelloWorldTest1 Testing HelloWorld

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -67- National Alliance for Medical Image Computing Running HelloWorldTest1 When the module successfully passes the test, the output below is generated:

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -68- National Alliance for Medical Image Computing Conclusion This course described functionalities for integrating, developing and testing an external program within Slicer3. The Execution Model of Slicer3 provides a simple mechanism for incorporating command line programs as Slicer modules. The pipeline guided you through 6 components of the NA-MIC kit.

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -69- National Alliance for Medical Image Computing Slicer Programming Course

Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -70- National Alliance for Medical Image Computing Acknowledgments National Alliance for Medical Image Computing NIH U54EB Neuroimage Analysis Center NIH P41RR013218