def loadPhilipsAffinity3DUS(self, loadable): """Load files in the traditional Slicer manner using the volume logic helper class and the vtkITK archetype helper code """ name = slicer.util.toVTKString(loadable.name) filePath = loadable.files[0] fileList = vtk.vtkStringArray() fileList.InsertNextValue(slicer.util.toVTKString(filePath)) volumesLogic = slicer.modules.volumes.logic() outputVolume = volumesLogic.AddArchetypeScalarVolume( filePath, name, 0, fileList) # Override spacing, as GDCM cannot retreive image spacing correctly for this type of image ds = dicom.read_file(filePath, stop_before_pixels=True) outputSpacingStr = ds[findPrivateTag(ds, 0x200d, 0x03, "Philips US Imaging DD 036")] outputVolume.SetSpacing(float(outputSpacingStr[0]), float(outputSpacingStr[1]), float(outputSpacingStr[2])) appLogic = slicer.app.applicationLogic() selectionNode = appLogic.GetSelectionNode() selectionNode.SetReferenceActiveVolumeID(outputVolume.GetID()) appLogic.PropagateVolumeSelection(0) appLogic.FitSliceToAll() return outputVolume
def examineForImport(self,fileLists): """ Returns a list of qSlicerDICOMLoadable instances corresponding to ways of interpreting the fileLists parameter. """ import vtkSlicerDicomRtImportExportModuleLogic # Create loadables for each file list loadables = [] for fileList in fileLists: # Each file list corresponds to one series, so do loadables # Convert file list to VTK object to be able to pass it for examining # (VTK class cannot have Qt object as argument, otherwise it is not python wrapped) vtkFileList = vtk.vtkStringArray() for file in fileList: vtkFileList.InsertNextValue(file) # Examine files loadablesCollection = vtk.vtkCollection() slicer.modules.dicomrtimportexport.logic().ExamineForLoad(vtkFileList, loadablesCollection) for loadableIndex in xrange(0,loadablesCollection.GetNumberOfItems()): vtkLoadable = loadablesCollection.GetItemAsObject(loadableIndex) # Create Qt loadable if confidence is greater than 0 if vtkLoadable.GetConfidence() > 0: # Convert to Qt loadable to pass it back qtLoadable = slicer.qSlicerDICOMLoadable() qtLoadable.copyFromVtkLoadable(vtkLoadable) qtLoadable.tooltip = 'Valid RT object in selection' qtLoadable.selected = True loadables.append(qtLoadable) return loadables
def loadEigenArtemis3DUS(self, loadable): name = slicer.util.toVTKString(loadable.name) filePath = loadable.files[0] fileList = vtk.vtkStringArray() fileList.InsertNextValue(slicer.util.toVTKString(filePath)) volumesLogic = slicer.modules.volumes.logic() outputVolume = volumesLogic.AddArchetypeScalarVolume( filePath, name, 0, fileList) outputVolume.SetSpacing(loadable.spacing, loadable.spacing, loadable.spacing) outputVolume.SetOrigin(loadable.origin[0], loadable.origin[1], loadable.origin[2]) ijk2ras = vtk.vtkMatrix4x4() outputVolume.GetIJKToRASMatrix(ijk2ras) rot = vtk.vtkMatrix4x4() rot.DeepCopy((0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1)) ijk2ras_updated = vtk.vtkMatrix4x4() ijk2ras.Multiply4x4(rot, ijk2ras, ijk2ras_updated) outputVolume.SetIJKToRASMatrix(ijk2ras_updated) appLogic = slicer.app.applicationLogic() selectionNode = appLogic.GetSelectionNode() selectionNode.SetReferenceActiveVolumeID(outputVolume.GetID()) appLogic.PropagateVolumeSelection(0) appLogic.FitSliceToAll() return outputVolume
def loadFilesWithArchetype(self,files,name): """Load files in the traditional Slicer manner using the volume logic helper class and the vtkITK archetype helper code """ fileList = vtk.vtkStringArray() for f in files: fileList.InsertNextValue(f) volumesLogic = slicer.modules.volumes.logic() return (volumesLogic.AddArchetypeVolume( files[0], name, 0, fileList ))
def loadFilesWithArchetype(self, files, name): """Load files in the traditional Slicer manner using the volume logic helper class and the vtkITK archetype helper code """ fileList = vtk.vtkStringArray() for f in files: fileList.InsertNextValue(f) volumesLogic = slicer.modules.volumes.logic() return (volumesLogic.AddArchetypeVolume(files[0], name, 0, fileList))
def loadFilesWithArchetype(self): """Load files in the traditional Slicer manner using the volume logic helper class and the vtkITK archetype helper code """ fileList = vtk.vtkStringArray() for f in self.files: fileList.InsertNextValue(f) vl = slicer.modules.volumes.logic() self.volumeNode = vl.AddArchetypeVolume( self.files[0], self.name, 0, fileList )
def loadFiles(self, files, name): fileList = vtk.vtkStringArray() for f in files: fileList.InsertNextValue(f) vl = slicer.modules.volumes.logic() # TODO: pass in fileList once it is known to be in the right order volumeNode = vl.AddArchetypeVolume( files[0], name, 0 ) # automatically select the volume to display appLogic = slicer.app.applicationLogic() selNode = appLogic.GetSelectionNode() selNode.SetReferenceActiveVolumeID(volumeNode.GetID()) appLogic.PropagateVolumeSelection()
def InitializeMetricsTable( metricsTable ): if ( metricsTable == None ): return metricsTable.GetTable().Initialize() # TODO: Make the more robust (e.g. qSlicerMetricsTableWidget::METRIC_TABLE_COLUMNS) metricsTableColumnNames = [ "MetricName", "MetricRoles", "MetricUnit", "MetricValue" ] for columnName in metricsTableColumnNames: column = vtk.vtkStringArray() column.SetName( columnName ) metricsTable.GetTable().AddColumn( column )
def loadFilesWithArchetype(self,files,name): """Load files in the traditional Slicer manner using the volume logic helper class and the vtkITK archetype helper code """ #name = slicer.util.unicodeify(name) name = name.encode('latin1', 'ignore') fileList = vtk.vtkStringArray() for f in files: fileList.InsertNextValue(f) volumesLogic = slicer.modules.volumes.logic() return(volumesLogic.AddArchetypeScalarVolume(files[0],name,0,fileList))
def requestDeviceIDsCompleted(self, object=None, event=None, caller=None): wasBlocked = self.deviceIDComboBox.blockSignals(True) self.deviceIDComboBox.clear() deviceIDs = vtk.vtkStringArray() self.plusRemoteNode.GetDeviceIDs(deviceIDs) currentDeviceID = self.plusRemoteNode.GetCurrentDeviceID() for valueIndex in range(deviceIDs.GetNumberOfValues()): deviceID = deviceIDs.GetValue(valueIndex) self.deviceIDComboBox.addItem(deviceID) currentIndex = self.deviceIDComboBox.findText(currentDeviceID) self.deviceIDComboBox.setCurrentIndex(currentIndex) self.deviceIDComboBox.blockSignals(wasBlocked) self.onDeviceIdChanged()
def ConvertStructureSetToLabelmap(self): import vtkSlicerDicomRtImportExportModuleLogic import vtkSegmentationCore import vtkSlicerSegmentationsModuleMRML import vtkSlicerSegmentationsModuleLogic labelmapsToSave = [] # Get all segmentation nodes from the scene segmentationNodes = slicer.util.getNodes('vtkMRMLSegmentationNode*') for segmentationNode in segmentationNodes.values(): logging.info(' Converting structure set ' + segmentationNode.GetName()) # Set referenced volume as rasterization reference referenceVolume = vtkSlicerDicomRtImportExportModuleLogic.vtkSlicerDicomRtImportExportModuleLogic.GetReferencedVolumeByDicomForSegmentation(segmentationNode) if referenceVolume == None: logging.error('No reference volume found for segmentation ' + segmentationNode.GetName()) continue # Perform conversion binaryLabelmapRepresentationName = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName() segmentation = segmentationNode.GetSegmentation() segmentation.CreateRepresentation(binaryLabelmapRepresentationName) # Create labelmap volume nodes from binary labelmaps segmentIDs = vtk.vtkStringArray() segmentation.GetSegmentIDs(segmentIDs) for segmentIndex in xrange(0,segmentIDs.GetNumberOfValues()): segmentID = segmentIDs.GetValue(segmentIndex) segment = segmentation.GetSegment(segmentID) binaryLabelmap = segment.GetRepresentation(vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName()) if not binaryLabelmap: logging.error('Failed to retrieve binary labelmap from segment ' + segmentID + ' in segmentation ' + segmentationNode.GetName()) continue labelmapNode = slicer.vtkMRMLLabelMapVolumeNode() slicer.mrmlScene.AddNode(labelmapNode) labelmapName = segmentationNode.GetName() + "_" + segmentID labelmapNode.SetName(labelmapName) if not vtkSlicerSegmentationsModuleLogic.vtkSlicerSegmentationsModuleLogic.CreateLabelmapVolumeFromOrientedImageData(binaryLabelmap,labelmapNode): logging.error('Failed to create labelmap from segment ' + segmentID + ' in segmentation ' + segmentationNode.GetName()) continue # Append volume to list labelmapsToSave.append(labelmapNode) return labelmapsToSave
def loadFiles(self,files=None,name=None): if not files: files = self.files if not name: name = self.name fileList = vtk.vtkStringArray() for f in files: fileList.InsertNextValue(f) vl = slicer.modules.volumes.logic() # TODO: pass in fileList once it is known to be in the right order self.volumeNode = vl.AddArchetypeVolume( files[0], name, 0 ) # automatically select the volume to display appLogic = slicer.app.applicationLogic() selNode = appLogic.GetSelectionNode() if self.volumeNode: selNode.SetReferenceActiveVolumeID(self.volumeNode.GetID()) appLogic.PropagateVolumeSelection()
def copyNodeContentToNewScriptedModuleNode(oldDataNode, shNode): newDataNode = slicer.vtkMRMLScriptedModuleNode() newDataNode.HideFromEditorsOff() # Copy node attributes attributeNames = vtk.vtkStringArray() oldDataNode.GetAttributeNames(attributeNames) for index in range(attributeNames.GetNumberOfValues()): attributeName = attributeNames.GetValue(index) newDataNode.SetAttribute(attributeName, oldDataNode.GetAttribute(attributeName)) slicer.mrmlScene.AddNode(newDataNode) newDataNode.SetName(oldDataNode.GetName()) # Copy node references newDataNode.CopyReferences(oldDataNode) # Move children childItemIDs = vtk.vtkIdList() #shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene) shNode.GetItemChildren(shNode.GetItemByDataNode(oldDataNode), childItemIDs) for index in range(childItemIDs.GetNumberOfIds()): childItemID = childItemIDs.GetId(index) shNode.ReparentItemByDataNode(childItemID, newDataNode) return newDataNode