<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.4%2FScriptRepository</id>
	<title>Documentation/4.4/ScriptRepository - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.4%2FScriptRepository"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.4/ScriptRepository&amp;action=history"/>
	<updated>2026-05-04T12:09:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.4/ScriptRepository&amp;diff=40463&amp;oldid=prev</id>
		<title>UpdateBot: Nightly -&gt; 4.4</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.4/ScriptRepository&amp;diff=40463&amp;oldid=prev"/>
		<updated>2014-12-25T06:53:10Z</updated>

		<summary type="html">&lt;p&gt;Nightly -&amp;gt; 4.4&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Community-contributed modules=&lt;br /&gt;
&lt;br /&gt;
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 &amp;gt;&amp;gt; next to Additional module paths, click Add, and choose the .py file's location).&lt;br /&gt;
&lt;br /&gt;
==Filters==&lt;br /&gt;
* [https://raw.github.com/pieper/VolumeMasker/master/VolumeMasker.py VolumeMasker.py]: Update a target volume with the results of setting all input volume voxels to 0 except for those that correspond to a selected label value in an input label map (Used for example in the volume rendering in [https://www.youtube.com/watch?v=dfu2gugHLHs this video).&lt;br /&gt;
&lt;br /&gt;
==DICOM==&lt;br /&gt;
* [https://gist.github.com/pieper/6186477 dicom header browser] to easily scroll through dicom files using dcmdump.&lt;br /&gt;
&lt;br /&gt;
==Informatics==&lt;br /&gt;
* [https://subversion.assembla.com/svn/slicerrt/trunk/SlicerRt/sandbox/MarkupsInfoModule/MarkupsInfo.py MarkupsInfo.py]: Compute the total length between all the points of a markup list.&lt;br /&gt;
* [https://subversion.assembla.com/svn/slicerrt/trunk/SlicerRt/sandbox/LineProfile/LineProfile.py LineProfile.py]: Compute intensity profile in a volume along a line.&lt;br /&gt;
&lt;br /&gt;
=Community-contributed examples=&lt;br /&gt;
&lt;br /&gt;
Usage: Copy-paste the shown code lines or linked .py file contents into Python console in Slicer.&lt;br /&gt;
&lt;br /&gt;
==Capture==&lt;br /&gt;
* Get a MRML node in the scene based on the node name and call methods of that object. For the MRHead sample data:&lt;br /&gt;
  vol=slicer.util.getNode('MR*')&lt;br /&gt;
  vol.GetImageData().GetDimensions()&lt;br /&gt;
* Capture the full Slicer screen and save it into a file&lt;br /&gt;
  img = qt.QPixmap.grabWidget(slicer.util.mainWindow()).toImage()&lt;br /&gt;
  img.save('c:/tmp/test.png')&lt;br /&gt;
* [https://subversion.assembla.com/svn/slicerrt/trunk/SlicerRt/sandbox/CaptureRotationVideo/CaptureRotationVideo.py CaptureRotationVideo.py]: Capture a video of the scene rotating in the 3D view&lt;br /&gt;
&lt;br /&gt;
==Launching Slicer==&lt;br /&gt;
* How to open an .mrb file with Slicer at the command line?&lt;br /&gt;
  Slicer.exe --python-code &amp;quot;slicer.util.loadScene( 'f:/2013-08-23-Scene.mrb' )&amp;quot;&lt;br /&gt;
* How to run a script in the Slicer environment in batch mode (without showing any graphical user interface)?&lt;br /&gt;
  Slicer.exe --python-code &amp;quot;doSomething; doSomethingElse; etc.&amp;quot; --testing --no-splash --no-main-window&lt;br /&gt;
&lt;br /&gt;
==DICOM==&lt;br /&gt;
* How to access tags of DICOM images imported into Slicer? For example, to print the first patient's first study's first series' &amp;quot;0020,0032&amp;quot; field:&lt;br /&gt;
  db=slicer.dicomDatabase&lt;br /&gt;
  patientList=db.patients()&lt;br /&gt;
  studyList=db.studiesForPatient(patientList[0])&lt;br /&gt;
  seriesList=db.seriesForStudy(studyList[0])&lt;br /&gt;
  fileList=db.filesForSeries(seriesList[0])&lt;br /&gt;
  print db.fileValue(fileList[0],'0020,0032')&lt;br /&gt;
&lt;br /&gt;
* How to access tag of a volume loaded from DICOM? For example, get the patient position stored in a volume:&lt;br /&gt;
  volumeName='2: ENT IMRT'&lt;br /&gt;
  n=slicer.util.getNode(volumeName)&lt;br /&gt;
  instUids=n.GetAttribute('DICOM.instanceUIDs').split()&lt;br /&gt;
  filename=slicer.dicomDatabase.fileForInstance(instUids[0])&lt;br /&gt;
  print slicer.dicomDatabase.fileValue(filename,'0018,5100')&lt;br /&gt;
&lt;br /&gt;
==Toolbar functions==&lt;br /&gt;
* How to turn on slice intersections in the crosshair menu on the toolbar:&lt;br /&gt;
  viewNodes = slicer.mrmlScene.GetNodesByClass('vtkMRMLSliceCompositeNode')&lt;br /&gt;
  viewNodes.UnRegister(slicer.mrmlScene)&lt;br /&gt;
  viewNodes.InitTraversal()&lt;br /&gt;
  viewNode = viewNodes.GetNextItemAsObject()&lt;br /&gt;
  while viewNode:&lt;br /&gt;
    viewNode.SetSliceIntersectionVisibility(1)&lt;br /&gt;
    viewNode = viewNodes.GetNextItemAsObject()&lt;br /&gt;
&lt;br /&gt;
How to find similar functions? For this one I searched for &amp;quot;slice intersections&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
==Manipulating objects in the slice viewer==&lt;br /&gt;
* How to define/edit a circular region of interest in a slice viewer?&lt;br /&gt;
&lt;br /&gt;
Drop two markup points on a slice view and copy-paste the code below into the Python console. After this, as you move the markups you’ll see a circle following the markups.&lt;br /&gt;
&lt;br /&gt;
  # Update the sphere from the fiducial points&lt;br /&gt;
  def UpdateSphere(param1, param2):  &lt;br /&gt;
    centerPointCoord = [0.0, 0.0, 0.0]&lt;br /&gt;
    markups.GetNthFiducialPosition(0,centerPointCoord)&lt;br /&gt;
    circumferencePointCoord = [0.0, 0.0, 0.0]&lt;br /&gt;
    markups.GetNthFiducialPosition(1,circumferencePointCoord)&lt;br /&gt;
    sphere.SetCenter(centerPointCoord)&lt;br /&gt;
    radius=math.sqrt((centerPointCoord[0]-circumferencePointCoord[0])**2+(centerPointCoord[1]-circumferencePointCoord[1])**2+(centerPointCoord[2]-circumferencePointCoord[2])**2)&lt;br /&gt;
    sphere.SetRadius(radius)&lt;br /&gt;
    sphere.SetPhiResolution(30)&lt;br /&gt;
    sphere.SetThetaResolution(30)&lt;br /&gt;
    sphere.Update()&lt;br /&gt;
  &lt;br /&gt;
  # Get a reference to the markup&lt;br /&gt;
  markups=slicer.util.getNode('F')&lt;br /&gt;
  # Create the sphere that will intersect the slice viewer&lt;br /&gt;
  sphere = vtk.vtkSphereSource()&lt;br /&gt;
  # Initial positioning of the sphere&lt;br /&gt;
  UpdateSphere(0,0)&lt;br /&gt;
  # Create model node and add to scene&lt;br /&gt;
  model = slicer.vtkMRMLModelNode()&lt;br /&gt;
  model.SetAndObservePolyData(sphere.GetOutput())&lt;br /&gt;
  modelDisplay = slicer.vtkMRMLModelDisplayNode()&lt;br /&gt;
  modelDisplay.SetSliceIntersectionVisibility(True) # Show in slice view&lt;br /&gt;
  modelDisplay.SetVisibility(False) # Hide in 3D view&lt;br /&gt;
  slicer.mrmlScene.AddNode(modelDisplay)&lt;br /&gt;
  model.SetAndObserveDisplayNodeID(modelDisplay.GetID())&lt;br /&gt;
  modelDisplay.SetInputPolyData(model.GetPolyData())&lt;br /&gt;
  slicer.mrmlScene.AddNode(model) &lt;br /&gt;
  # Call UpdateSphere whenever the fiducials are changed&lt;br /&gt;
  markups.AddObserver(&amp;quot;ModifiedEvent&amp;quot;, UpdateSphere, 2)&lt;br /&gt;
&lt;br /&gt;
== Add a texture mapped plane to the scene as a model ==&lt;br /&gt;
Note that model textures are not exposed in the GUI and are not saved in the scene&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# use dummy image data here&lt;br /&gt;
e = vtk.vtkImageEllipsoidSource()&lt;br /&gt;
&lt;br /&gt;
scene = slicer.mrmlScene&lt;br /&gt;
&lt;br /&gt;
# Create model node&lt;br /&gt;
model = slicer.vtkMRMLModelNode()&lt;br /&gt;
model.SetScene(scene)&lt;br /&gt;
model.SetName(scene.GenerateUniqueName(&amp;quot;2DImageModel&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
planeSource = vtk.vtkPlaneSource()&lt;br /&gt;
model.SetAndObservePolyData(planeSource.GetOutput())&lt;br /&gt;
&lt;br /&gt;
# Create display node&lt;br /&gt;
modelDisplay = slicer.vtkMRMLModelDisplayNode()&lt;br /&gt;
modelDisplay.SetColor(1,1,0) # yellow&lt;br /&gt;
modelDisplay.SetBackfaceCulling(0)&lt;br /&gt;
modelDisplay.SetScene(scene)&lt;br /&gt;
scene.AddNode(modelDisplay)&lt;br /&gt;
model.SetAndObserveDisplayNodeID(modelDisplay.GetID())&lt;br /&gt;
&lt;br /&gt;
# Add to scene&lt;br /&gt;
modelDisplay.SetAndObserveTextureImageData(e.GetOutput())&lt;br /&gt;
scene.AddNode(model) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
transform = slicer.vtkMRMLLinearTransformNode()&lt;br /&gt;
scene.AddNode(transform) &lt;br /&gt;
model.SetAndObserveTransformNodeID(transform.GetID())&lt;br /&gt;
&lt;br /&gt;
vTransform = vtk.vtkTransform()&lt;br /&gt;
vTransform.Scale(50,50,50)&lt;br /&gt;
vTransform.RotateX(30)&lt;br /&gt;
transform.SetAndObserveMatrixTransformToParent(vTransform.GetMatrix())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Clone a volume ==&lt;br /&gt;
This example shows how to clone the MRHead sample volume, including its pixel data and display settings.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sourceVolumeNode = slicer.util.getNode('MRHead')&lt;br /&gt;
volumesLogic = slicer.modules.volumes.logic()&lt;br /&gt;
clonedVolumeNode = volumesLogic.CloneVolume(slicer.mrmlScene, sourceVolumeNode, 'Cloned volume')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Modify voxels in a volume ==&lt;br /&gt;
This example shows how to change voxels values of the MRHead sample volume.&lt;br /&gt;
The values will be computed by function f(r,a,s,) = (r-10)*(r-10)+(a+15)*(a+15)+s*s.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
volumeNode=slicer.util.getNode('MRHead')&lt;br /&gt;
ijkToRas = vtk.vtkMatrix4x4()&lt;br /&gt;
volumeNode.GetIJKToRASMatrix(ijkToRas)&lt;br /&gt;
imageData=volumeNode.GetImageData()&lt;br /&gt;
extent = imageData.GetExtent()&lt;br /&gt;
for k in xrange(extent[4], extent[5]+1):&lt;br /&gt;
  for j in xrange(extent[2], extent[3]+1):&lt;br /&gt;
    for i in xrange(extent[0], extent[1]+1):&lt;br /&gt;
      position_Ijk=[i, j, k, 1]&lt;br /&gt;
      position_Ras=ijkToRas.MultiplyPoint(position_Ijk)&lt;br /&gt;
      r=position_Ras[0]&lt;br /&gt;
      a=position_Ras[1]&lt;br /&gt;
      s=position_Ras[2]      &lt;br /&gt;
      functionValue=(r-10)*(r-10)+(a+15)*(a+15)+s*s&lt;br /&gt;
      imageData.SetScalarComponentFromDouble(i,j,k,0,functionValue)&lt;br /&gt;
imageData.SetScalarComponentFromFloat(distortionVectorPosition_Ijk[0], distortionVectorPosition_Ijk[1], distortionVectorPosition_Ijk[2], 0, fillValue)&lt;br /&gt;
imageData.Modified()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manipulate a Slice View ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; lm = slicer.app.layoutManager()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; red = lm.sliceWidget('Red')&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; redLogic = red.sliceLogic()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; redLogic.GetSliceOffset()&lt;br /&gt;
-10.214302062988281&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; redLogic.SetSliceOffset(20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
</feed>