250 likes | 334 Views
Slicer and ITK. Raul San Jose. Foreword. ITK as a library of “source code” “Box” of structured reusable source code. Library compile when you compile your application. What did I miss in my C++ book? Standard Template Library (STL) framework: containers and iterators. Template.
E N D
Slicer and ITK Raul San Jose
Foreword • ITK as a library of “source code” • “Box” of structuredreusablesource code. • Library compile when you compile your application. • What did I miss in my C++ book? • Standard Template Library (STL) framework: containers and iterators. • Template. • Typename. • Typedef. • ITK push the envelope of software design into abstraction.
How to use ITK? • Way 1: Develop your own application My application Rendering Library GUI My Algorithm My classes ITK pipeline
How to use ITK? • Way 2: Develop inside your platform (Slicer way) My platform Rendering Module GUI Module ITK Pipeline Core Library Library wrappers ITK
How to make the wrapper? • Low level: as another object of your library. • Each ITK filter/pipeline is seen as another class of your library. • High level:wrapper into other languages as tcl/tk, phyton or java. • ITK supports this approach through CableSwig.
vtkConnectVTKITK vtkITK Slicer and ITK • Architecture: 3D Slicer TCL / TK (GUI, VTK Interface) wrapper VTK ITK
vtkImageExport vtkImageImport Slicer and ITK • Data Flow: VTK – ITK – VTK VTK VTK ITK itk::VTKImageImport itk::VTKImageExport
vtkDataObject Slicer and ITK • Data Flow: ITK – VTK ITK VTK itk::ImportImageContainer
vtkDataObject Slicer and ITK • Data Flow: VTK – ITK VTK ITK itk::ImportImageFilter
vtkITKMyFilter VTK VTK ITK itk::VTKImageImport vtkImageExport vtkImageImport itk::MyFilter itk::VTKImageExport vtkITK: Overview
vtkITK: Base classes vtkITKImageToImageFilter2DFF vtkImageToImageFilter vtkITKImageToImageFilterUSUS vtkITKImageToImageFilterF2F2 vtkITKImageToImageFilter vtkITKMyFilter vtkITKImageToImageFilterF3F3 vtkImageExport vtkImageImport vtkITKImageToImageFilterFF itk::VTKImageExport<itk::Image<float>,3>> Itk::VTKImageImport<itk::Image<float>,3>>
vtkITK: Example • Case: Perform a edge-preserving filtering as a preprocessing before segmentation. • Algorithm: Anisotropic diffusion process. • Code: itk::GradientAnisotropicDiffusionImageFilter. • http://www.itk.org/Doxygen16/html/classitk_1_1GradientAnisotropicDiffusionImageFilter.html
vtkITK: Wrapping #include "vtkITKImageToImageFilterFF.h" #include "itkGradientAnisotropicDiffusionImageFilter.h" #include "vtkObjectFactory.h" class VTK_EXPORT vtkITKGradientAnisotropicDiffusionImageFilter : public vtkITKImageToImageFilterFF { public: static vtkITKGradientAnisotropicDiffusionImageFilter *New(); vtkTypeRevisionMacro(vtkITKGradientAnisotropicDiffusionImageFilter, vtkITKImageToImageFilterFF);
vtkITK: Wrapping void SetConductanceParameter ( double value ) { DelegateITKInputMacro ( SetConductanceParameter, value ); }; double GetConductanceParameter () { DelegateITKOutputMacro(GetConductanceParameter) ; }; double GetTimeStep () { DelegateITKOutputMacro(GetTimeStep) ; }; m_Filter.GetPointer()->SetConductanceParameter(value)
vtkITK: Wrapping protected: //BTX typedef itk::GradientAnisotropicDiffusionImageFilter<Superclass::InputImageType, Superclass::InputImageType> ImageFilterType; vtkITKGradientAnisotropicDiffusionImageFilter() : Superclass ( ImageFilterType::New() ){}; ~vtkITKGradientAnisotropicDiffusionImageFilter() {}; ImageFilterType* GetImageFilterPointer() { return dynamic_cast<ImageFilterType*> ( m_Filter.->GetPointer() ); //ETX private: vtkITKGradientAnisotropicDiffusionImageFilter(const vtkITKGradientAnisotropicDiffusionImageFilter&); // Not implemented. void operator=(const vtkITKGradientAnisotropicDiffusionImageFilter&); // Not implemented. }; vtkStandardNewMacro(vtkITKGradientAnisotropicDiffusionImageFilter);
Slicer Module ITKFilters.tcl • Modules methods: core methods • procITKFiltersInit • procITKFiltersBuildGUI • procITKFiltersBuildVTK • procITKFiltersEnter • procITKFiltersExit • Other methods: callback methods • procITKFiltersApply • …..
Slicer Module procITKFiltersInit set m ITKFilters set Module($m,author) “NAMIC people" set Module($m,row1List) "Help Main" set Module($m,row1Name) "{Help} {Main}" set Module($m,row1,tab) Main set Module($m,procGUI) ITKFiltersBuildGUI set Module($m,procVTK) ITKFiltersBuildVTK set Module($m,procMRML) ITKFiltersUpdateGUI set Module($m,procEnter) ITKFiltersEnter set Module($m,procExit) ITKFiltersExit
Slicer Module procITKFiltersInit set ITKFilters(filters) " GradientAnisotropicDiffusionImageFilter “ set ITKFilters($filter,params) "SetConductanceParameter SetNumberOfIterations \ SetTimeStep" set param SetConductanceParameter set ITKFilters($filter,$param) 1 set ITKFilters($filter,$param,text) "Conductance" set ITKFilters($filter,$param,maxmin) "1 10“ set ITKFilters($filter,$param,res) 0.1 set ITKFilters($filter,$param,widget) "scale"
Slicer Module procITKFiltersBuildGUI set fMain $Module(ITKFilters,fMain) set f $fMain foreach frame "Top Middle Floating Bottom" { frame $f.f$frame -bg $Gui(activeWorkspace) pack $f.f$frame -side top -padx 0 -pady $Gui(pad) -fill x } …..
Slicer Module procITKFiltersBuildGUI "scale" { eval {label $fwidget.l$param -text $ITKFilters($filter,$param,text)\ -width 12 -justify right } $Gui(WLA) eval {entry $fwidget.e$param -justify right -width 4 \ -textvariable ITKFilters($filter,$param) } $Gui(WEA) eval {scale $fwidget.s$param -from [lindex $ITKFilters($filter,$param,maxmin) 0] \ -to [lindex $ITKFilters($filter,$param,maxmin) 1] \ -variable ITKFilters($filter,$param)\ -orient vertical \ -resolution $ITKFilters($filter,$param,res) \ } $Gui(WSA) pack $fwidget.l$param $fwidget.e$param $fwidget.s$param -side left -padx $Gui(pad) -pady 0 }
Slicer Module procITKFiltersApply #Preparing INPUT and OUTPUT volume If {$v2 == -5} { set name [Volume($v1,node) GetName] set v2 [DevCreateNewCopiedVolume $v1 "" ${name}_filter ] set node [Volume($v2,vol) GetMrmlNode] Mrml(dataTree) RemoveItem $node set nodeBefore [Volume($v1,vol) GetMrmlNode] Mrml(dataTree) InsertAfterItem $nodeBefore $node MainUpdateMRML } else { set v2name [Volume($v2,node) GetName] set continue [DevOKCancel "Overwrite $v2name?"] if {$continue == "cancel"} { return 1 } # They say it is OK, so overwrite! Volume($v2,node) Copy Volume($v1,node) }
Slicer Module procITKFiltersApply #Caster vtkImageCast _cast _cast SetOutputScalarTypeToFloat _cast SetInput [Volume($v1,vol) GetOutput] _cast Update #Create Object vtkITK$filter _filter foreach param $ITKFilters($filter,params) { _filter $param $ITKFilters($filter,$param) } _filter SetInput [_cast GetOutput]
Slicer Module procITKFiltersApply _filter AddObserver StartEvent MainStartProgress _filter AddObserver EndEvent MainEndProgress _filter AddObserver ProgressEvent "MainShowProgress _filter" _filter Update #Assign output [Volume($v2,vol) GetOutput] DeepCopy [_filter GetOutput] #Destroy pipeline _cast Delete _filter SetOutput "" _filter Delete
itk::VTKImageImport vtkImageExport vtkImageImport itk::VTKImageExport vtkConnectVTKITK ITK CableSwig VTK VTK ITK itkMyFilterFF Slicer Module vtkConnectVTKITK