Skip to content

Commit

Permalink
ENH: Moves some code to DICOMPlugin base class
Browse files Browse the repository at this point in the history
Make these methods available for us in other classes.
  • Loading branch information
pieper committed Nov 15, 2023
1 parent 79132dc commit beb4e7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
28 changes: 28 additions & 0 deletions Modules/Scripted/DICOMLib/DICOMPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ def cacheLoadables(self, files, loadables):
key = self.hashFiles(files)
self.loadableCache[key] = loadables

def cleanNodeName(self, value):
cleanValue = value
cleanValue = cleanValue.replace("|", "-")
cleanValue = cleanValue.replace("/", "-")
cleanValue = cleanValue.replace("\\", "-")
cleanValue = cleanValue.replace("*", "(star)")
cleanValue = cleanValue.replace("\\", "-")
return cleanValue

def seriesSorter(self, x, y):
""" returns -1, 0, 1 for sorting of strings like: "400: series description"
Works for DICOMLoadable or other objects with name attribute
Use like:
from functools import cmp_to_key
loadables.sort(key=cmp_to_key(lambda x, y: self.seriesSorter(x, y)))
"""
if not (hasattr(x, 'name') and hasattr(y, 'name')):
return 0
xName = x.name
yName = y.name
try:
xNumber = int(xName[:xName.index(':')])
yNumber = int(yName[:yName.index(':')])
except ValueError:
return 0
cmp = xNumber - yNumber
return cmp

def examineForImport(self, fileList):
"""Look at the list of lists of filenames and return
a list of DICOMLoadables that are options for loading
Expand Down
25 changes: 0 additions & 25 deletions Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ def examineForImport(self, fileLists):

return loadables

def cleanNodeName(self, value):
cleanValue = value
cleanValue = cleanValue.replace("|", "-")
cleanValue = cleanValue.replace("/", "-")
cleanValue = cleanValue.replace("\\", "-")
cleanValue = cleanValue.replace("*", "(star)")
cleanValue = cleanValue.replace("\\", "-")
return cleanValue

def examineFiles(self, files):
""" Returns a list of DICOMLoadable instances
corresponding to ways of interpreting the
Expand Down Expand Up @@ -345,22 +336,6 @@ def examineFiles(self, files):

return loadables

def seriesSorter(self, x, y):
""" returns -1, 0, 1 for sorting of strings like: "400: series description"
Works for DICOMLoadable or other objects with name attribute
"""
if not (hasattr(x, 'name') and hasattr(y, 'name')):
return 0
xName = x.name
yName = y.name
try:
xNumber = int(xName[:xName.index(':')])
yNumber = int(yName[:yName.index(':')])
except ValueError:
return 0
cmp = xNumber - yNumber
return cmp

#
# different ways to load a set of dicom files:
# - Logic: relies on the same loading mechanism used
Expand Down

0 comments on commit beb4e7d

Please sign in to comment.