本文整理汇总了Python中SegmentStatistics.SegmentStatisticsLogic.registerPlugin方法的典型用法代码示例。如果您正苦于以下问题:Python SegmentStatisticsLogic.registerPlugin方法的具体用法?Python SegmentStatisticsLogic.registerPlugin怎么用?Python SegmentStatisticsLogic.registerPlugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SegmentStatistics.SegmentStatisticsLogic
的用法示例。
在下文中一共展示了SegmentStatisticsLogic.registerPlugin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SegmentStatisticsPlugins
# 需要导入模块: from SegmentStatistics import SegmentStatisticsLogic [as 别名]
# 或者: from SegmentStatistics.SegmentStatisticsLogic import registerPlugin [as 别名]
#.........这里部分代码省略.........
# We add/remove representations, so we temporarily block segment modifications
# to make sure display managers don't try to access data while it is in an
# inconsistent state.
wasModified = segmentationNode.StartModify()
for i in range(len(segmentGeometriesNew)):
segmentGeometry = segmentGeometriesNew[i]
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(segmentGeometry[0])
sphereSource.SetCenter(segmentGeometry[1], segmentGeometry[2], segmentGeometry[3])
sphereSource.Update()
segment = segmentationNode.GetSegmentation().GetNthSegment(i)
segment.RemoveAllRepresentations()
closedSurfaceName = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName()
segment.AddRepresentation(closedSurfaceName,
sphereSource.GetOutput())
segmentationNode.EndModify(wasModified)
self.assertEqual( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"], 2948)
self.assertEqual( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"], 23281)
segStatLogic.updateStatisticsForSegment('Test_1')
self.assertEqual( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"], 2948)
self.assertTrue( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"]!=23281)
segStatLogic.updateStatisticsForSegment('Test')
self.assertTrue( segStatLogic.getStatistics()["Test","LabelmapSegmentStatisticsPlugin.voxel_count"]!=2948)
self.assertTrue( segStatLogic.getStatistics()["Test_1","LabelmapSegmentStatisticsPlugin.voxel_count"]!=23281)
# test enabling/disabling of individual measurements
self.delayDisplay("Test disabling of individual measurements")
segStatLogic = SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.voxel_count.enabled",str(False))
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.volume_cm3.enabled",str(False))
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertFalse('Number of voxels [voxels] (1)' in columnHeaders)
self.assertTrue('Volume [mm3] (1)' in columnHeaders)
self.assertFalse('Volume [cm3] (3)' in columnHeaders)
self.delayDisplay("Test re-enabling of individual measurements")
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.voxel_count.enabled",str(True))
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.volume_cm3.enabled",str(True))
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertTrue('Number of voxels [voxels] (1)' in columnHeaders)
self.assertTrue('Volume [mm3] (1)' in columnHeaders)
self.assertTrue('Volume [cm3] (1)' in columnHeaders)
# test enabling/disabling of individual plugins
self.delayDisplay("Test disabling of plugin")
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.enabled",str(False))
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertFalse('Number of voxels [voxels] (3)' in columnHeaders)
self.assertFalse('Volume [mm3] (3)' in columnHeaders)
self.assertTrue('Volume [mm3] (2)' in columnHeaders)
self.delayDisplay("Test re-enabling of plugin")
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.enabled",str(True))
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertTrue('Number of voxels [voxels] (2)' in columnHeaders)
self.assertTrue('Volume [mm3] (3)' in columnHeaders)
# test unregistering/registering of plugins
self.delayDisplay("Test of removing all registered plugins")
SegmentStatisticsLogic.registeredPlugins = [] # remove all registered plugins
segStatLogic = SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertEqual(len(columnHeaders),1) # only header element should be "Segment"
self.assertEqual(columnHeaders[0],"Segment") # only header element should be "Segment"
self.delayDisplay("Test registering plugins")
SegmentStatisticsLogic.registerPlugin(LabelmapSegmentStatisticsPlugin())
SegmentStatisticsLogic.registerPlugin(ScalarVolumeSegmentStatisticsPlugin())
SegmentStatisticsLogic.registerPlugin(ClosedSurfaceSegmentStatisticsPlugin())
segStatLogic = SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)
columnHeaders = [resultsTableNode.GetColumnName(i) for i in range(resultsTableNode.GetNumberOfColumns())]
self.assertTrue('Number of voxels [voxels] (1)' in columnHeaders)
self.assertTrue('Number of voxels [voxels] (2)' in columnHeaders)
self.assertTrue('Surface area [mm2]' in columnHeaders)
self.delayDisplay('test_SegmentStatisticsPlugins passed!')