Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
""" Do whatever is needed to reset the state - typically a scene clear will be enough.
"""
slicer.mrmlScene.Clear(0)
#
# first, get some data
#
import urllib
downloads = (
('http://slicer.kitware.com/midas3/download?items=5768', 'tract1.vtk', slicer.util.loadFiberBundle),
)
for url,name,loader in downloads:
filePath = slicer.app.temporaryPath + '/' + name
if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
print('Requesting download %s from %s...\n' % (name, url))
urllib.urlretrieve(url, filePath)
if loader:
print('Loading %s...\n' % (name,))
loader(filePath)
self.delayDisplay('Finished with download and loading\n')
# use the volumes module to replicate the bug report
m = slicer.util.mainWindow()
m.moduleSelector().selectModule('TractographyDisplay')
self.delayDisplay("Entered Tractography module")
def setUp(self):
""" Do whatever is needed to reset the state - typically a scene clear will be enough.
"""
slicer.mrmlScene.Clear(0)
#
# first, get some data
#
import urllib
downloads = (
('http://slicer.kitware.com/midas3/download?items=5768', 'tract1.vtk', slicer.util.loadFiberBundle),
)
for url,name,loader in downloads:
filePath = slicer.app.temporaryPath + '/' + name
if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
print('Requesting download %s from %s...\n' % (name, url))
urllib.urlretrieve(url, filePath)
if loader:
print('Loading %s...\n' % (name,))
loader(filePath)
color_by_strategies = [
('Solid Color', displayNode.colorModeSolid),
('Of Tensor Property', displayNode.colorModeScalar),
# (, displayNode.colorModeFunctionOfScalar),
# ('Color Fibers By Mean Orientation', displayNode.colorModeUseCellScalars),
('Of Scalar Value', displayNode.colorModeScalarData),
('Color Fibers By Segment Orientation', displayNode.colorModePointFiberOrientation),
('Color Fibers By Mean Orientation', displayNode.colorModeMeanFiberOrientation),
]
for widget_text, color_code in color_by_strategies:
if not visibility.checked:
visibility.click()
solidColor = slicer.util.findChildren(tubeTab, text=widget_text)
if len(solidColor) == 0:
raise ValueError("Widget %s not found" % widget_text)
else:
solidColor = solidColor[0]
solidColor.click()
if displayNode and displayNode.GetColorMode() != color_code:
self.delayDisplay('Setting Color Mode To %s Did not Work' % widget_text)
raise Exception()
else:
self.delayDisplay("Setting Color Mode To %s Worked" % widget_text)
visibility.click()
def test_TestTractographyDisplayColorBy(self, display_node='Tube'):
self.delayDisplay("Starting the test")
self.delayDisplay('Showing Advanced Display\n')
advancedDisplay = slicer.util.findChildren(text='Advanced Display')[0]
advancedDisplay.collapsed = False
self.delayDisplay('Selecting tract1\n')
tractNode = slicer.util.getNode('tract1')
displayNode = getattr(tractNode, 'Get%sDisplayNode' % display_node)()
tree = slicer.util.findChildren(name='TractographyDisplayTreeView')[0]
model = tree.model()
modelIndex = model.indexFromMRMLNode(tractNode)
tree.setCurrentIndex(modelIndex)
tubeTab = slicer.util.findChildren(advancedDisplay, name='%sTab' % display_node)[0]
visibility = slicer.util.findChildren(tubeTab, text='Visibility')[0]
color_by_strategies = [
('Solid Color', displayNode.colorModeSolid),
if len(freesurfer_found_segments) != len(self.freesurfer_wanted_segments):
unpresent_segments = self.freesurfer_wanted_segments[:]
for seg in freesurfer_found_segments:
del unpresent_segments[unpresent_segments.index(seg)]
unpresent_segments = map(lambda x: self.freesurfer_lut_dict[x.split('_')[-1]]['name'], unpresent_segments)
logging.warning('Unable to find all segments, {} have not been found.'.format(unpresent_segments))
logging.warning('LabelMap in path: {} has not been loaded into segmentationDict.'.format(path))
return False
for segmentId in to_remove_ids:
segmentationNode.GetSegmentation().RemoveSegment(segmentId)
elif self.color_table_id != 'None':
segment_number = segmentationNode.GetSegmentation().GetNumberOfSegments()
color_node = slicer.util.getNode(pattern=self.color_table_id)
if (segment_number > 1):
for segmentIndex in range(segment_number):
segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(segmentIndex)
label_id = int(segmentId.split('_')[-1])
color = [.0, .0, .0, .0]
color_node.GetColor(label_id, color)
segment_name = color_node.GetColorName(label_id)
segment = segmentationNode.GetSegmentation().GetSegment(segmentId)
segment.SetName(segment_name)
segment.SetColor(color[:3])
elif (segment_number==1):
segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0)
color = [.0, .0, .0, .0]
# Apply Button
self.applyButton = qt.QPushButton("Apply")
self.applyButton.toolTip = "Run the algorithm."
self.applyButton.enabled = True
self.layout.addWidget(self.applyButton)
### Output Area
outputCollapsibleButton = ctk.ctkCollapsibleButton()
outputCollapsibleButton.text = "Output"
self.layout.addWidget(outputCollapsibleButton)
# Layout within the dummy collapsible button
outputFormLayout = qt.QFormLayout(outputCollapsibleButton)
# Jacobian image (mrml output)
self.outputJacobian = slicer.qMRMLNodeComboBox()
self.outputJacobian.nodeTypes = ["vtkMRMLScalarVolumeNode"]
self.outputJacobian.setMRMLScene( slicer.mrmlScene )
self.outputJacobian.addEnabled = True
self.outputJacobian.renameEnabled = True
#self.outputJacobian.layout().addWidget(self.outputSelector)
self.outputJacobian.setToolTip( "Output image of Jacobian matrix.vtkSlicerPlastimatchModuleLogicPython" )
outputFormLayout.addRow("Jacobian image: ", self.outputJacobian)
# output directory selector
# self.outputDirectory = ctk.ctkDirectoryButton()
# self.outputDirectory.directory = qt.QDir.homePath()
# outputFormLayout.addRow("Output Directory: ", self.outputDirectory)
# output statistics
buttonLayout = qt.QHBoxLayout()
self.minJacobian = qt.QLineEdit()
def runRegistration(self, start, end):
assert start != -1 and end != -1
seriesNumber = self.inputVolume.GetName().split(":")[0]
self.outputTransform = self.createLinearTransformNode(seriesNumber + "-" + self.ZFRAME_TRANSFORM_NAME)
params = {'inputVolume': self.inputVolume, 'startSlice': start, 'endSlice': end,
'outputTransform': self.outputTransform}
slicer.cli.run(slicer.modules.zframeregistration, None, params, wait_for_completion=True)