Difference between revisions of "Documentation/Nightly/ScriptRepository"

From Slicer Wiki
Jump to: navigation, search
Line 46: Line 46:
 
   fileList=db.filesForSeries(seriesList[0])
 
   fileList=db.filesForSeries(seriesList[0])
 
   print db.fileValue(fileList[0],'0020,0032')
 
   print db.fileValue(fileList[0],'0020,0032')
 +
 +
==Toolbar functions==
 +
* How to turn on slice intersections in the crosshair menu on the toolbar:
 +
  viewNodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLSliceCompositeNode')
 +
  viewNodes.UnRegister(slicer.mrmlScene)
 +
  viewNodes.InitTraversal()
 +
  viewNode = viewNodes.GetNextItemAsObject()
 +
  while viewNode:
 +
    viewNode.SetSliceIntersectionVisibility(1)
 +
    viewNode = viewNodes.GetNextItemAsObject()
 +
 +
How to find similar functions? For this one I searched for "slice intersections" text in the whole slicer source code, found that the function is implemented in Base\QTGUI\qSlicerViewersToolBar.cxx, then translated the qSlicerViewersToolBarPrivate::setSliceIntersectionVisible(bool visible) method to Python.

Revision as of 16:22, 19 November 2013

Home < Documentation < Nightly < ScriptRepository


For the latest Slicer documentation, visit the read-the-docs.



Community-contributed modules

Usage: save the .py file to a directory, add the directory to the additional module paths in the Slicer application settings (choose in the menu: Edit / Application settings, click Modules, click >> next to Additional module paths, click Add, and choose the .py file's location).

Segmentation

  • FillRoi.py: Fill a region of interest in a labelmap volume with a constant value. This can be used after an automatic segmentation for removing certain regions of a volume.

Filters

DICOM

Informatics

  • MarkupsInfo.py: Compute the total length between all the points of a markup list.

Community-contributed examples

Usage: Copy-paste the shown code lines or linked .py file contents into Python console in Slicer.

Capture

  • Get a MRML node in the scene based on the node name and call methods of that object. For the MRHead sample data:
 vol=slicer.util.getNode('MR*')
 vol.GetImageData().GetDimensions()
  • Capture the full Slicer screen and save it into a file
 img = qt.QPixmap.grabWidget(slicer.util.mainWindow()).toImage()
 img.save('c:/tmp/test.png')

Launching Slicer

  • How to open an .mrb file with Slicer at the command line?
 Slicer.exe --python-code "slicer.util.loadScene( 'f:/2013-08-23-Scene.mrb' )"
  • How to run a script in the Slicer environment in batch mode (without showing any graphical user interface)?
 Slicer.exe --python-code "doSomething; doSomethingElse; etc." --testing --no-splash --no-main-window

DICOM

  • How to access tags of DICOM images imported into Slicer? For example, to print the first patient's first study's first series' "0020,0032" field:
 db=slicer.dicomDatabase
 patientList=db.patients()
 studyList=db.studiesForPatient(patientList[0])
 seriesList=db.seriesForStudy(studyList[0])
 fileList=db.filesForSeries(seriesList[0])
 print db.fileValue(fileList[0],'0020,0032')

Toolbar functions

  • How to turn on slice intersections in the crosshair menu on the toolbar:
 viewNodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLSliceCompositeNode')
 viewNodes.UnRegister(slicer.mrmlScene)
 viewNodes.InitTraversal()
 viewNode = viewNodes.GetNextItemAsObject()
 while viewNode:
   viewNode.SetSliceIntersectionVisibility(1)
   viewNode = viewNodes.GetNextItemAsObject()

How to find similar functions? For this one I searched for "slice intersections" text in the whole slicer source code, found that the function is implemented in Base\QTGUI\qSlicerViewersToolBar.cxx, then translated the qSlicerViewersToolBarPrivate::setSliceIntersectionVisible(bool visible) method to Python.