def test_Part1Ruler(self, enableScreenshotsFlag=0, screenshotScaleFactor=1): """ Test using rulers """ self.enableScreenshots = enableScreenshotsFlag self.screenshotScaleFactor = screenshotScaleFactor self.delayDisplay("Starting the test") # # first, get some data # import SampleData sampleDataLogic = SampleData.SampleDataLogic() tumor = sampleDataLogic.downloadMRBrainTumor1() try: # four up view layoutManager = slicer.app.layoutManager() layoutManager.setLayout( slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView) # annotations module m = slicer.util.mainWindow() m.moduleSelector().selectModule('Annotations') # add ruler 1 rulerNode1 = slicer.vtkMRMLAnnotationRulerNode() rulerNode1.SetName("d1") rulerNode1.SetPosition1(-7.59519, 43.544, 28.6) rulerNode1.SetPosition2(-5.56987, 14.177, 28.6) rulerNode1.Initialize(slicer.mrmlScene) self.delayDisplay("Ruler 1") # add ruler 2 rulerNode2 = slicer.vtkMRMLAnnotationRulerNode() rulerNode2.SetName("d2") rulerNode2.SetPosition1(-3.54455, 27.656, 13.1646) rulerNode2.SetPosition2(-2.5319, 27.656, 47.5949) rulerNode2.Initialize(slicer.mrmlScene) self.delayDisplay("Ruler 2") # scroll annotLogic = slicer.modules.annotations.logic() annotLogic.JumpSlicesToAnnotationCoordinate(rulerNode1.GetID()) # show slices redWidget = layoutManager.sliceWidget('Red') redWidget.sliceController().setSliceLink(True) redWidget.sliceController().setSliceVisible(True) self.takeScreenshot('Ruler', 'Ruler used to measure tumor diameter', -1) except Exception, e: import traceback traceback.print_exc() self.delayDisplay('Test caused exception!\n' + str(e))
def test_Part1Ruler(self,enableScreenshotsFlag=0,screenshotScaleFactor=1): """ Test using rulers """ self.enableScreenshots = enableScreenshotsFlag self.screenshotScaleFactor = screenshotScaleFactor self.delayDisplay("Starting the test") # # first, get some data # import SampleData sampleDataLogic = SampleData.SampleDataLogic() tumor = sampleDataLogic.downloadMRBrainTumor1() try: # four up view layoutManager = slicer.app.layoutManager() layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView) # annotations module m = slicer.util.mainWindow() m.moduleSelector().selectModule('Annotations') # add ruler 1 rulerNode1 = slicer.vtkMRMLAnnotationRulerNode() rulerNode1.SetName("d1") rulerNode1.SetPosition1(-7.59519,43.544,28.6) rulerNode1.SetPosition2(-5.56987,14.177,28.6) rulerNode1.Initialize(slicer.mrmlScene) self.delayDisplay("Ruler 1") # add ruler 2 rulerNode2 = slicer.vtkMRMLAnnotationRulerNode() rulerNode2.SetName("d2") rulerNode2.SetPosition1(-3.54455,27.656,13.1646) rulerNode2.SetPosition2(-2.5319,27.656,47.5949) rulerNode2.Initialize(slicer.mrmlScene) self.delayDisplay("Ruler 2") # scroll annotLogic = slicer.modules.annotations.logic() annotLogic.JumpSlicesToAnnotationCoordinate(rulerNode1.GetID()) # show slices redWidget = layoutManager.sliceWidget('Red') redWidget.sliceController().setSliceLink(True) redWidget.sliceController().setSliceVisible(True); self.takeScreenshot('Ruler','Ruler used to measure tumor diameter',-1) except Exception, e: import traceback traceback.print_exc() self.delayDisplay('Test caused exception!\n' + str(e))
def populateRulers(self, annotationHierarchy, verterbraeNames): completeVerterbraeNames = [] for verterbraeName in verterbraeNames: completeVerterbraeNames.append(verterbraeName + "-s") completeVerterbraeNames.append(verterbraeName + "-i") if annotationHierarchy != None: rulerNodes = vtk.vtkCollection() annotationHierarchy.GetDirectChildren(rulerNodes) rulerNodeNames = [] for nodeIndex in range(rulerNodes.GetNumberOfItems()): if rulerNodes.GetItemAsObject(nodeIndex).GetClassName( ) == "vtkMRMLAnnotationRulerNode": rulerNodeNames.append( rulerNodes.GetItemAsObject(nodeIndex).GetName()) addedRulerNodesList = [] addedVerterbrae = 200 for completeVerterbraeName in completeVerterbraeNames: if completeVerterbraeName not in rulerNodeNames: newRulerNode = slicer.vtkMRMLAnnotationRulerNode() newRulerNode.SetName(completeVerterbraeName) newRulerNode.SetPosition1(0, addedVerterbrae, 0) newRulerNode.SetPosition2(-300, addedVerterbrae, 0) newRulerNode.SetPointColour([0, 0, 1]) newRulerNode.Initialize(slicer.mrmlScene) annotationHierarchy.SetAndObserveDisplayNodeID( newRulerNode.GetDisplayNodeID()) addedVerterbrae -= 50 addedRulerNodesList.append(newRulerNode) else: addedVerterbrae = 200 for completeVerterbraeName in completeVerterbraeNames: newRulerNode = slicer.vtkMRMLAnnotationRulerNode() newRulerNode.SetName(completeVerterbraeName) newRulerNode.SetPosition1(0, addedVerterbrae, 0) newRulerNode.SetPosition2(-300, addedVerterbrae, 0) newRulerNode.Initialize(slicer.mrmlScene) annotationHierarchy.SetAndObserveDisplayNodeID( newRulerNode.GetDisplayNodeID()) addedVerterbrae -= 50 return addedRulerNodesList
def test_LineIntensityProfile1(self): """ Ideally you should have several levels of tests. At the lowest level tests sould exercise the functionality of the logic with different inputs (both valid and invalid). At higher levels your tests should emulate the way the user would interact with your code and confirm that it still works the way you intended. One of the most important features of the tests is that it should alert other developers when their changes will have an impact on the behavior of your module. For example, if a developer removes a feature that you depend on, your test should break so they know that the feature is needed. """ self.delayDisplay("Starting the test") # # first, get some data # import urllib downloads = ( ('http://slicer.kitware.com/midas3/download?items=5767', 'FA.nrrd', slicer.util.loadVolume), ) 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') volumeNode = slicer.util.getNode(pattern="FA") logic = LineIntensityProfileLogic() self.assertTrue( logic.hasImageData(volumeNode) ) # add ruler node rulerNode = slicer.vtkMRMLAnnotationRulerNode() slicer.mrmlScene.AddNode(rulerNode) rulerNode.SetPosition1(-65,110,60) rulerNode.SetPosition2(-15,60,60) rulerNode.SetName('Test') # initialize selectors moduleWidget = slicer.modules.LineIntensityProfileWidget moduleWidget.rulerSelector.setCurrentNode(rulerNode) moduleWidget.inputSelector.setCurrentNode(volumeNode) self.delayDisplay('Inputs initialized!') # run the test moduleWidget.onApplyButton() self.delayDisplay('If you see a ruler and a plot - test passed!')
def __init__(self, markupNode): self.info={} #put the first fiducial coordinates into startPtCoords startPtCoords = [0.0, 0.0, 0.0] markupNode.GetNthFiducialPosition(0,startPtCoords) endPtCoords = [0.0, 0.0, 0.0] #create rulers node in a ruler List the calculate the distances between fiducials #in this way it's easy to manage the distance data in other future modules for fidIndex in xrange(markupNode.GetNumberOfFiducials()): ruler = slicer.mrmlScene.AddNode(slicer.vtkMRMLAnnotationRulerNode()) markupNode.GetNthFiducialPosition(fidIndex,endPtCoords) ruler.SetPosition1(startPtCoords[0],startPtCoords[1],startPtCoords[2]) ruler.SetPosition2(endPtCoords[0],endPtCoords[1],endPtCoords[2])
def test_ReportingAIMRoundTrip(self): print("CTEST_FULL_OUTPUT") """ Load the data using DICOM module """ import os self.delayDisplay("Starting the DICOM test") # # first, get the data - a zip file of dicom data # import urllib downloads = ( ('http://slicer.kitware.com/midas3/download?items=10881', 'JANCT-CT.zip'), ) self.delayDisplay("Downloading") for url,name in downloads: filePath = slicer.app.temporaryPath + '/' + name if not os.path.exists(filePath) or os.stat(filePath).st_size == 0: self.delayDisplay('Requesting download %s from %s...\n' % (name, url)) urllib.urlretrieve(url, filePath) self.delayDisplay('Finished with download\n') reportingTempDir = slicer.app.temporaryPath+'/Reporting' print('Temporary directory location: '+reportingTempDir) qt.QDir().mkpath(reportingTempDir) dicomFilesDirectory = reportingTempDir + '/dicomFiles' self.cleanupDir(dicomFilesDirectory) qt.QDir().mkpath(dicomFilesDirectory) slicer.app.applicationLogic().Unzip(filePath, dicomFilesDirectory) try: self.delayDisplay("Switching to temp database directory") tempDatabaseDirectory = reportingTempDir + '/tempDICOMDatbase' qt.QDir().mkpath(tempDatabaseDirectory) self.cleanupDir(tempDatabaseDirectory) if slicer.dicomDatabase: self.originalDatabaseDirectory = os.path.split(slicer.dicomDatabase.databaseFilename)[0] else: self.originalDatabaseDirectory = None settings = qt.QSettings() settings.setValue('DatabaseDirectory', tempDatabaseDirectory) dicomWidget = slicer.modules.dicom.widgetRepresentation().self() dicomWidget.onDatabaseDirectoryChanged(tempDatabaseDirectory) self.delayDisplay('Importing DICOM') mainWindow = slicer.util.mainWindow() mainWindow.moduleSelector().selectModule('DICOM') #dicomWidget.dicomApp.suspendModel() indexer = ctk.ctkDICOMIndexer() indexer.addDirectory(slicer.dicomDatabase, dicomFilesDirectory, None) indexer.waitForImportFinished() patient = slicer.dicomDatabase.patients()[0] studies = slicer.dicomDatabase.studiesForPatient(patient) series = [slicer.dicomDatabase.seriesForStudy(study) for study in studies] seriesUIDs = [uid for uidList in series for uid in uidList] dicomWidget.detailsPopup.offerLoadables(seriesUIDs, 'SeriesUIDList') dicomWidget.detailsPopup.examineForLoading() loadablesByPlugin = dicomWidget.detailsPopup.loadablesByPlugin self.delayDisplay('Loading Selection') dicomWidget.detailsPopup.loadCheckedLoadables() # initialize the module with the report and volume volumes = slicer.util.getNodes('vtkMRMLScalarVolumeNode*') self.assertTrue(len(volumes) == 1) (name,volume) = volumes.items()[0] self.delayDisplay('Loaded volume name %s' % volume.GetName()) self.delayDisplay('Configure Module') mainWindow = slicer.util.mainWindow() mainWindow.moduleSelector().selectModule('Reporting') reporting = slicer.modules.reporting.widgetRepresentation().self() report = slicer.mrmlScene.CreateNodeByClass('vtkMRMLReportingReportNode') report.SetReferenceCount(report.GetReferenceCount()-1) slicer.mrmlScene.AddNode(report) report.SetFindingLabel(7) reporting.reportSelector.setCurrentNode(report) self.delayDisplay('Setting volume to %s' % volume.GetName()) reporting.volumeSelector.setCurrentNode(volume) slicer.app.processEvents() # place some markups and add a segmentation label # add fiducial fidNode = slicer.vtkMRMLAnnotationFiducialNode() fidName = "AIM Round Trip Test Fiducial" fidNode.SetName(fidName) fidNode.SetSelected(1) fidNode.SetDisplayVisibility(1) fidNode.SetLocked(0) # TODO: ask Nicole where this is assigned in the regular workflow fidNode.SetAttribute('AssociatedNodeID',volume.GetID()) print("Calling set fid coords") startCoords = [15.8, 70.8, -126.7] fidNode.SetFiducialCoordinates(startCoords[0],startCoords[1],startCoords[2]) print("Starting fiducial coordinates: "+str(startCoords)) slicer.mrmlScene.AddNode(fidNode) # add ruler rulerNode = slicer.vtkMRMLAnnotationRulerNode() rulerNode.SetName('Test Ruler') m = vtk.vtkMatrix4x4() volume.GetIJKToRASMatrix(m) ijk0 = [0,0,1,1] ijk1 = [50,50,1,1] ras0 = m.MultiplyPoint(ijk0) ras1 = m.MultiplyPoint(ijk1) rulerNode.SetPosition1(19.386751174926758, 68.528785705566406, -127.69000244140625) rulerNode.SetPosition2(132.72709655761719, -34.349384307861328, -127.69000244140625) rulerNode.SetAttribute('AssociatedNodeID',volume.GetID()) slicer.mrmlScene.AddNode(rulerNode) slicer.app.processEvents() # add label node volumesLogic = slicer.modules.volumes.logic() labelNode = volumesLogic.CreateAndAddLabelVolume(slicer.mrmlScene, volume, "Segmentation") labelDisplayNode = labelNode.GetDisplayNode() labelDisplayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeFileGenericAnatomyColors.txt') image = volume.GetImageData() thresh = vtk.vtkImageThreshold() if vtk.vtkVersion().GetVTKMajorVersion() < 6: thresh.SetInput(image) else: thresh.SetInputData(image) thresh.ThresholdBetween(10,400) thresh.SetInValue(report.GetFindingLabel()) thresh.SetOutValue(0) thresh.Update() labelNode.SetAndObserveImageData(thresh.GetOutput()) reporting.segmentationSelector.setCurrentNode(labelNode) # Save the report exportDir = reportingTempDir+'/Output' qt.QDir().mkpath(exportDir) self.cleanupDir(exportDir) report.SetStorageDirectoryName(exportDir) reportingLogic = slicer.modules.reporting.logic() print("Before saving report") reportingLogic.SaveReportToAIM(report) self.delayDisplay('Report saved') slicer.mrmlScene.Clear(0) # parse on patient level, find segmentation object, load and make sure # it matches the input # close the scene and load the report, check consistency # try to load back the saved AIM import glob print glob.glob(exportDir+'/*') xmlFiles = glob.glob(exportDir+'/*xml') print xmlFiles self.assertTrue(len(xmlFiles) == 1) reporting.importAIMFile = xmlFiles[0] reporting.onReportImport() self.delayDisplay('Report loaded from AIM! Test passed.') self.delayDisplay("Restoring original database directory") if self.originalDatabaseDirectory: dicomWidget.onDatabaseDirectoryChanged(self.originalDatabaseDirectory) except Exception, e: if self.originalDatabaseDirectory: dicomWidget.onDatabaseDirectoryChanged(self.originalDatabaseDirectory) import traceback traceback.print_exc() self.delayDisplay('Test caused exception!\n' + str(e)) self.assertTrue(False)
def onCompute(self): slicer.app.processEvents() self.logic = CalculateDistanceLogic(self.markupSelector.currentNode()) self.DistanceList = slicer.vtkMRMLAnnotationRulerNode()
def test_LineIntensityProfile1(self): """ Ideally you should have several levels of tests. At the lowest level tests sould exercise the functionality of the logic with different inputs (both valid and invalid). At higher levels your tests should emulate the way the user would interact with your code and confirm that it still works the way you intended. One of the most important features of the tests is that it should alert other developers when their changes will have an impact on the behavior of your module. For example, if a developer removes a feature that you depend on, your test should break so they know that the feature is needed. """ self.delayDisplay("Starting the test") # # first, get some data # import urllib downloads = ( ('http://slicer.kitware.com/midas3/download?items=5767', 'FA.nrrd', slicer.util.loadVolume), ) 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') volumeNode = slicer.util.getNode(pattern="FA") logic = LineIntensityProfileLogic() self.assertTrue( logic.hasImageData(volumeNode) ) # initialize ruler node in a known location rulerNode = slicer.vtkMRMLAnnotationRulerNode() slicer.mrmlScene.AddNode(rulerNode) rulerNode.SetPosition1(-65,110,60) rulerNode.SetPosition2(-15,60,60) rulerNode.SetName('Test') numOfPointsField = qt.QSpinBox() numOfPointsField.value = 100 chartNode = slicer.mrmlScene.AddNode(slicer.vtkMRMLChartNode()) # initialize input selectors moduleWidget = slicer.modules.LineIntensityProfileWidget moduleWidget.rulerSelector.setCurrentNode(rulerNode) moduleWidget.inputSelector1.setCurrentNode(volumeNode) moduleWidget.inputSelector2.setCurrentNode(volumeNode) self.delayDisplay('Inputs initialized!') # run the logic with the initialized inputs moduleWidget.onApplyButton() self.delayDisplay('If you see a ruler and a plot - test passed!') # here we check the sample is correct or not GroundTruth = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 \ ,0.0499952547252 ,0.132161304355,0.157250195742,0.182541355491 ,0.224097684026,0.307691186666,0.421751081944,0.539702475071,0.566307783127,0.502181112766,0.466381758451 \ ,0.454870164394 ,0.451874107122 ,0.45154094696,0.445982009172,0.434947699308,0.422306239605,0.413488268852,0.409934103489,0.414202958345,0.409307956696 \ ,0.397122174501,0.397800117731,0.411369532347,0.429417848587,0.439514577389,0.423818171024,0.40110757947,0.386767745018,0.379366248846,0.370953738689,0.36441424489 \ ,0.36140397191,0.367857933044,0.38929861784,0.418379157782,0.408268928528,0.379027366638,0.332919150591,0.297374159098,0.296240001917,0.311986237764,0.350458532572 \ ,0.370930314064,0.357974469662,0.326200008392,0.316009640694,0.312490910292,0.32052642107,0.316521972418,0.279196560383,0.244257837534,0.238702788949,0.255041092634 \ ,0.280225723982,0.320494830608,0.28876376152,0.277780592442,0.253679126501,0.247220918536,0.244660764933] logic.run(volumeNode, volumeNode, rulerNode, numOfPointsField, chartNode) sample = logic.getImageSamples()[0] isTestValid = True for i in range(numOfPointsField.value): if abs(sample.GetTuple1(i)-float(GroundTruth[i])) > 0.000001: isTestValid = False if isTestValid: self.delayDisplay('Sample point test passed!') else: self.delayDisplay('Sample point test failed!')
def test_ReportingAIMRoundTrip(self): print ("CTEST_FULL_OUTPUT") """ Load the data using DICOM module """ import os self.delayDisplay("Starting the DICOM test") # # first, get the data - a zip file of dicom data # import urllib downloads = (("http://slicer.kitware.com/midas3/download?items=10881", "JANCT-CT.zip"),) self.delayDisplay("Downloading") for url, name in downloads: filePath = slicer.app.temporaryPath + "/" + name if not os.path.exists(filePath) or os.stat(filePath).st_size == 0: self.delayDisplay("Requesting download %s from %s...\n" % (name, url)) urllib.urlretrieve(url, filePath) self.delayDisplay("Finished with download\n") reportingTempDir = slicer.app.temporaryPath + "/Reporting" print ("Temporary directory location: " + reportingTempDir) qt.QDir().mkpath(reportingTempDir) dicomFilesDirectory = reportingTempDir + "/dicomFiles" self.cleanupDir(dicomFilesDirectory) qt.QDir().mkpath(dicomFilesDirectory) slicer.app.applicationLogic().Unzip(filePath, dicomFilesDirectory) try: self.delayDisplay("Switching to temp database directory") tempDatabaseDirectory = reportingTempDir + "/tempDICOMDatbase" qt.QDir().mkpath(tempDatabaseDirectory) self.cleanupDir(tempDatabaseDirectory) if slicer.dicomDatabase: self.originalDatabaseDirectory = os.path.split(slicer.dicomDatabase.databaseFilename)[0] else: self.originalDatabaseDirectory = None settings = qt.QSettings() settings.setValue("DatabaseDirectory", tempDatabaseDirectory) dicomWidget = slicer.modules.dicom.widgetRepresentation().self() dicomWidget.onDatabaseDirectoryChanged(tempDatabaseDirectory) self.delayDisplay("Importing DICOM") mainWindow = slicer.util.mainWindow() mainWindow.moduleSelector().selectModule("DICOM") # dicomWidget.dicomApp.suspendModel() indexer = ctk.ctkDICOMIndexer() indexer.addDirectory(slicer.dicomDatabase, dicomFilesDirectory, None) indexer.waitForImportFinished() patient = slicer.dicomDatabase.patients()[0] studies = slicer.dicomDatabase.studiesForPatient(patient) series = [slicer.dicomDatabase.seriesForStudy(study) for study in studies] seriesUIDs = [uid for uidList in series for uid in uidList] dicomWidget.detailsPopup.offerLoadables(seriesUIDs, "SeriesUIDList") dicomWidget.detailsPopup.examineForLoading() loadablesByPlugin = dicomWidget.detailsPopup.loadablesByPlugin self.delayDisplay("Loading Selection") dicomWidget.detailsPopup.loadCheckedLoadables() # initialize the module with the report and volume volumes = slicer.util.getNodes("vtkMRMLScalarVolumeNode*") self.assertTrue(len(volumes) == 1) (name, volume) = volumes.items()[0] self.delayDisplay("Loaded volume name %s" % volume.GetName()) self.delayDisplay("Configure Module") mainWindow = slicer.util.mainWindow() mainWindow.moduleSelector().selectModule("Reporting") reporting = slicer.modules.reporting.widgetRepresentation().self() report = slicer.mrmlScene.CreateNodeByClass("vtkMRMLReportingReportNode") report.SetReferenceCount(report.GetReferenceCount() - 1) slicer.mrmlScene.AddNode(report) report.SetFindingLabel(7) reporting.reportSelector.setCurrentNode(report) self.delayDisplay("Setting volume to %s" % volume.GetName()) reporting.volumeSelector.setCurrentNode(volume) slicer.app.processEvents() # place some markups and add a segmentation label # add fiducial fidNode = slicer.vtkMRMLAnnotationFiducialNode() fidName = "AIM Round Trip Test Fiducial" fidNode.SetName(fidName) fidNode.SetSelected(1) fidNode.SetDisplayVisibility(1) fidNode.SetLocked(0) # TODO: ask Nicole where this is assigned in the regular workflow fidNode.SetAttribute("AssociatedNodeID", volume.GetID()) print ("Calling set fid coords") startCoords = [15.8, 70.8, -126.7] fidNode.SetFiducialCoordinates(startCoords[0], startCoords[1], startCoords[2]) print ("Starting fiducial coordinates: " + str(startCoords)) slicer.mrmlScene.AddNode(fidNode) # add ruler rulerNode = slicer.vtkMRMLAnnotationRulerNode() rulerNode.SetName("Test Ruler") m = vtk.vtkMatrix4x4() volume.GetIJKToRASMatrix(m) ijk0 = [0, 0, 1, 1] ijk1 = [50, 50, 1, 1] ras0 = m.MultiplyPoint(ijk0) ras1 = m.MultiplyPoint(ijk1) rulerNode.SetPosition1(19.386751174926758, 68.528785705566406, -127.69000244140625) rulerNode.SetPosition2(132.72709655761719, -34.349384307861328, -127.69000244140625) rulerNode.SetAttribute("AssociatedNodeID", volume.GetID()) slicer.mrmlScene.AddNode(rulerNode) slicer.app.processEvents() # add label node volumesLogic = slicer.modules.volumes.logic() labelNode = volumesLogic.CreateAndAddLabelVolume(slicer.mrmlScene, volume, "Segmentation") labelDisplayNode = labelNode.GetDisplayNode() labelDisplayNode.SetAndObserveColorNodeID("vtkMRMLColorTableNodeFileGenericAnatomyColors.txt") image = volume.GetImageData() thresh = vtk.vtkImageThreshold() if vtk.vtkVersion().GetVTKMajorVersion() < 6: thresh.SetInput(image) else: thresh.SetInputData(image) thresh.ThresholdBetween(10, 400) thresh.SetInValue(report.GetFindingLabel()) thresh.SetOutValue(0) thresh.Update() labelNode.SetAndObserveImageData(thresh.GetOutput()) reporting.segmentationSelector.setCurrentNode(labelNode) # Save the report exportDir = reportingTempDir + "/Output" qt.QDir().mkpath(exportDir) self.cleanupDir(exportDir) report.SetStorageDirectoryName(exportDir) reportingLogic = slicer.modules.reporting.logic() print ("Before saving report") reportingLogic.SaveReportToAIM(report) self.delayDisplay("Report saved") slicer.mrmlScene.Clear(0) # parse on patient level, find segmentation object, load and make sure # it matches the input # close the scene and load the report, check consistency # try to load back the saved AIM import glob print glob.glob(exportDir + "/*") xmlFiles = glob.glob(exportDir + "/*xml") print xmlFiles self.assertTrue(len(xmlFiles) == 1) reporting.importAIMFile = xmlFiles[0] reporting.onReportImport() self.delayDisplay("Report loaded from AIM! Test passed.") self.delayDisplay("Restoring original database directory") if self.originalDatabaseDirectory: dicomWidget.onDatabaseDirectoryChanged(self.originalDatabaseDirectory) except Exception, e: if self.originalDatabaseDirectory: dicomWidget.onDatabaseDirectoryChanged(self.originalDatabaseDirectory) import traceback traceback.print_exc() self.delayDisplay("Test caused exception!\n" + str(e)) self.assertTrue(False)
def runCaliper(self): inputVolume = self.inputSelector.currentNode() if not (inputVolume): qt.QMessageBox.critical( slicer.util.mainWindow(), 'Deploy Caliper', 'Input volume is required for calculation.') return # If coordinates modified, use for calculation if self.coordinatesWidgetModified: widgetPointsList = slicer.vtkMRMLMarkupsFiducialNode() widgetPointsList.SetName('WPL') # widgetNode = slicer.util.getNode('WPL') slicer.mrmlScene.AddNode(widgetPointsList) # Grab first widget coordinate and display print "PointNum1 is: " pointNum1Str = (str(self.c1Select.coordinates)).split(",") pointNum1 = [float(i) for i in pointNum1Str] print pointNum1 widgetPointsList.AddFiducial(pointNum1[0], pointNum1[1], pointNum1[2], 'WP-1') # Grab second widget coordinate and display print "PointNum2 is: " pointNum2Str = (str(self.c2Select.coordinates)).split(",") pointNum2 = [float(i) for i in pointNum2Str] print pointNum2 widgetPointsList.AddFiducial(pointNum2[0], pointNum2[1], pointNum2[2], 'WP-2') # Center the slices on Point 1 slicer.modules.markups.logic().JumpSlicesToLocation(pointNum1[0], pointNum1[1], pointNum1[2], True) # Calculate distance in mm and print to console distanceValue = math.sqrt( math.pow((pointNum1[0] - pointNum2[0]), 2) + math.pow((pointNum1[1] - pointNum2[1]), 2) + math.pow((pointNum1[2] - pointNum2[2]), 2)) self.distUpdate.setText("Distance: %.2f mm" % distanceValue) # Add a ruler rulerNode = slicer.vtkMRMLAnnotationRulerNode() rulerNode.SetDistanceAnnotationVisibility(1) rulerNode.SetPosition1(pointNum1[0], pointNum1[1], pointNum1[2]) rulerNode.SetPosition2(pointNum2[0], pointNum2[1], pointNum2[2]) rulerNode.SetName('Distance 1') rulerNode.SetDistanceAnnotationVisibility(False) rulerNode.Initialize(slicer.mrmlScene) self.coordinatesWidgetModified = False else: # Get interactive coordinates, if any intNode1 = slicer.util.getNode('IP1') intNode2 = slicer.util.getNode('IP2') if ((intNode1.GetNumberOfFiducials() == 1) and (intNode2.GetNumberOfFiducials() == 1)): z3point1 = [0.0, 0.0, 0.0] z3point2 = [0.0, 0.0, 0.0] intNode1.GetNthFiducialPosition(0, z3point1) intNode2.GetNthFiducialPosition(0, z3point2) print "Interactive Point 1:" print z3point1 print "Interactive Point 2:" print z3point2 interactiveDistance = math.sqrt( math.pow((z3point1[0] - z3point2[0]), 2) + math.pow((z3point1[1] - z3point2[1]), 2) + math.pow((z3point1[2] - z3point2[2]), 2)) self.intDistUpdate.setText("Distance: %.2f mm" % interactiveDistance) intRulerNode = slicer.vtkMRMLAnnotationRulerNode() intRulerNode.SetDistanceAnnotationVisibility(1) intRulerNode.SetPosition1(z3point1[0], z3point1[1], z3point1[2]) intRulerNode.SetPosition2(z3point2[0], z3point2[1], z3point2[2]) intRulerNode.SetName('Distance 2') intRulerNode.SetDistanceAnnotationVisibility(False) intRulerNode.Initialize(slicer.mrmlScene) # Blur if checkbox is checked if self.blur.isChecked(): gauss = vtk.vtkImageGaussianSmooth() gauss.SetInputData(inputVolume.GetImageData()) gauss.SetDimensionality(3) fwhmValue = .01 * distanceValue gauss.SetStandardDeviation(fwhmValue) gauss.Update() ijkToRAS = vtk.vtkMatrix4x4() inputVolume.GetIJKToRASMatrix(ijkToRAS) inputVolume.SetAndObserveImageData(gauss.GetOutput())