def export(self, exportables): errorMessage = '' for exportable in exportables: # Get transform node shn = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode( slicer.mrmlScene) transformNode = shn.GetItemDataNode( exportable.subjectHierarchyItemID) if transformNode is None or not transformNode.IsA( 'vtkMRMLTransformNode'): return 'Invalid transform node in exportable (ItemID:' + str( exportable.subjectHierarchyItemID) # Get moving and fixed volumes involved in the registration movingVolumeNode = transformNode.GetNodeReference( slicer.vtkMRMLTransformNode.GetMovingNodeReferenceRole()) fixedVolumeNode = transformNode.GetNodeReference( slicer.vtkMRMLTransformNode.GetFixedNodeReferenceRole()) if movingVolumeNode is None or fixedVolumeNode is None: currentError = 'Failed to find moving and/or fixed image for transform ' + transformNode.GetName( ) logging.error( currentError + '. These references are needed in order to export the transform into DICOM SRO. Please make sure the transform is created by a registration module.' ) errorMessage += currentError + '\n' continue import sys loadablePath = os.path.join( slicer.modules.plastimatch_slicer_bspline.path, '..' + os.sep + '..' + os.sep + 'qt-loadable-modules') if loadablePath not in sys.path: sys.path.append(loadablePath) sroExporter = slicer.vtkPlmpyDicomSroExport() sroExporter.SetMRMLScene(slicer.mrmlScene) sroExporter.SetTransformsLogic(slicer.modules.transforms.logic()) sroExporter.SetFixedImageID(fixedVolumeNode.GetID()) sroExporter.SetMovingImageID(movingVolumeNode.GetID()) sroExporter.SetXformID(transformNode.GetID()) sroExporter.SetOutputDirectory(exportable.directory) success = sroExporter.DoExport() if success != 0: currentError = 'Failed to export transform node to DICOM SRO: ' + transformNode.GetName( ) logging.error(currentError) errorMessage += currentError + '\n' continue return errorMessage
def run(self, fixedNode, movingNode, xformNode, outputDir): """ Run the actual algorithm """ import sys loadablePath = os.path.join( slicer.modules.plastimatch_slicer_bspline.path, '..' + os.sep + '..' + os.sep + 'qt-loadable-modules') if loadablePath not in sys.path: sys.path.append(loadablePath) sro = slicer.vtkPlmpyDicomSroExport() sro.SetMRMLScene(slicer.mrmlScene) sro.SetFixedImageID(fixedNode.GetID()) sro.SetMovingImageID(movingNode.GetID()) sro.SetXformID(xformNode.GetID()) sro.SetOutputDirectory(outputDir) sro.DoExport() return True