Skip to content

Instantly share code, notes, and snippets.

View pieper's full-sized avatar

Steve Pieper pieper

View GitHub Profile
import os
import slicer
from __main__ import qt
from __main__ import ctk
#########################################################
#
#
comment = """
@pieper
pieper / gist:5270696
Created March 29, 2013 13:03
Save a slicer 3D view to an obj file
>>> o = vtk.vtkOBJExporter()
>>> o.SetFilePrefix('/tmp/obj/fibers')
>>> lm = slicer.app.layoutManager()
>>> tdv = lm.threeDWidget(0).threeDView()
>>> rw = tdv.renderWindow()
>>> o.SetRenderWindow(rw)
>>> o.Write()
@pieper
pieper / gist:5770098
Last active November 5, 2020 08:38
This is the final edited version of the VolumeScroller.py example script for this tutorial: http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python
import os
import unittest
from __main__ import vtk, qt, ctk, slicer
#
# VolumeScroller
#
class VolumeScroller:
def __init__(self, parent):
@pieper
pieper / decruft.py
Last active December 20, 2015 18:38
decruft.py - does some math morphology operations to clean up a segmentation so that only the big connected regions are kept.
"""
Run this with a label map loaded in the slicer editor.
Change this path to be wherever you save this file and then paste
the line into the slicer python console:
execfile('/Users/pieper/Dropbox/hacks/slicer/decruft.py')
This script will apply the algorithm and display the result.
You can use the editor's undo operation to get back to the
@pieper
pieper / gist:6186477
Last active December 20, 2015 19:58
"""
The following can be pasted into the python console to examine the headers
of all the dicom objects in the database
"""
import DICOMLib
parent = qt.QWidget()
layout = qt.QVBoxLayout()
parent.setLayout(layout)
@pieper
pieper / renderSmooth
Created September 17, 2014 23:06
render a smoothed image by supersampling - hack for slicer4
lm = slicer.app.layoutManager()
tw = lm.threeDWidget(0)
tv = tw.threeDView()
rw = tv.renderWindow()
ren = rw.GetRenderers().GetItemAsObject(0)
wti = vtk.vtkWindowToImageFilter()
wti.SetMagnification(4)
var current = document.createElement('p');
document.body.appendChild(current);
@pieper
pieper / gist:59de820ad08cf3c0f7a33926397e612d
Created January 30, 2017 14:47
slicer-qt5 mac build work in progress
diffs:
#6 Slicer (support-qt5 *$>)$ git diff
diff --git a/Base/QTGUI/qSlicerWebWidget.h b/Base/QTGUI/qSlicerWebWidget.h
index 4eb852681..362115fd8 100644
--- a/Base/QTGUI/qSlicerWebWidget.h
+++ b/Base/QTGUI/qSlicerWebWidget.h
@@ -40,7 +40,8 @@ class QWebEngineView;
#endif
import os
import WebServer
tracts = ['AF', 'CST_M1', 'IFOF', 'ILF', 'UF'];
exportDirectory = '/Volumes/encrypted/data/AG/AG1611-SlicerWeb/tracts'
targetTubeCount = 100
for tract in tracts:
tubeNodes = slicer.util.getNodes('vtkMRMLFiberBundleTubeDisplayNode*', useLists=True).values()
for tubeNode in tubeNodes[0]:
@pieper
pieper / stowSR.js
Last active May 8, 2018 13:17
save OHIFVIewer length as SR
// This can be pasted into the wip-add-dcmjs branch of [email protected]:ohif/Viewers
// to store current length measurements back to the source DICOMweb server.
function parametersFromImageId(imageId) {
const decodedImageId = decodeURIComponent(imageId);
return(new URLSearchParams(decodedImageId));
}
function parametersFromToolState() {
const imageToolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();