Skip to content

Instantly share code, notes, and snippets.

/* General styling */
QWidget {
background-color: #2a2a2a;
color: #B7B7B7;
}
QPushButton {
background-color: #434343;
border: 2px #434343;
border-radius: 3px;
@sjh26
sjh26 / subHierarchy.py
Created January 10, 2023 20:30
Subject Hierarchy Fun
slicer.mrmlScene.Clear()
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
import SampleData
node = SampleData.downloadSample('MRHead')
subjectItem = shNode.CreateSubjectItem(shNode.GetSceneItemID(),'Greg')
studyItem = shNode.CreateStudyItem(subjectItem, 'Study1')
nodeItem = shNode.GetItemByDataNode(node)
shNode.SetItemParent(nodeItem, studyItem)
widget = slicer.qMRMLSubjectHierarchyTreeView()
widget.setMRMLScene(slicer.mrmlScene)
def getActiveVolume():
lm = slicer.app.layoutManager()
sliceLogic = lm.sliceWidget('Red').sliceLogic()
compositeNode = sliceLogic.GetSliceCompositeNode()
return compositeNode.GetBackgroundVolumeID()
@sjh26
sjh26 / gist:42500b8421ac2258c5c4454122c439f8
Created October 14, 2022 14:50
Example of volume rendering
def toggleVolumeRenderVisibility(self, visible):
volumeNode = <volume node however you get it>
NodeCombo = slicer.util.findChild(self.volumerenderWidget, 'VolumeNodeComboBox')
VisibilityCheckBox = slicer.util.findChild(self.volumerenderWidget, 'VisibilityCheckBox')
volRenLogic = slicer.modules.volumerendering.logic()
if volumeNode is not NodeCombo.currentNode():
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode)
displayNode.SetVisibility(visible)
displayNode.GetVolumePropertyNode().Copy(volRenLogic.GetPresetByName("CT-AAA"))
@sjh26
sjh26 / Embedding.py
Last active August 9, 2022 14:50
Embedding external app into slicer
def onConnectAppButton(self):
import win32gui
import win32con
import time
# Launch the application
proc = qt.QProcess()
proc.setProgram("/path/to/application")
proc.startDetached()
@sjh26
sjh26 / SequenceToImageStack.py
Created August 20, 2021 21:12
SequenceToImageStack
import os
import unittest
import logging
import vtk, qt, ctk, slicer
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixin
#
# SequenceToImageStack
#