|
@@ -3,6 +3,8 @@ import sys
|
|
|
import dicom
|
|
|
import numpy as np
|
|
|
import re
|
|
|
+import slicer
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -28,16 +30,60 @@ class parseDicom:
|
|
|
""" # replace with organization, grant and thanks.
|
|
|
self.parent = parent
|
|
|
|
|
|
-def read_dynamic_SPECT(mypath):
|
|
|
+def filelist(mypath):
|
|
|
|
|
|
|
|
|
- onlyfiles = [f for f in os.listdir(mypath)
|
|
|
- if os.path.isfile(os.path.join(mypath, f))]
|
|
|
+ if mypath.find('labkey://')==0:
|
|
|
+ print("Using labkey")
|
|
|
+ labkeyPath=re.sub('labkey://','',mypath)
|
|
|
+
|
|
|
+ net=slicer.modules.labkeySlicerPythonExtensionWidget.network
|
|
|
+ print("Found network")
|
|
|
+ url=slicer.modules.labkeySlicerPythonExtensionWidget.serverURL.text
|
|
|
+ print("Seting url={}".format(url))
|
|
|
+ files=net.listDir(str(url),labkeyPath)
|
|
|
+ print files
|
|
|
+
|
|
|
+ if mypath.find('file://')==0:
|
|
|
+ print("Using local files")
|
|
|
+ localPath=re.sub('file://','',mypath)
|
|
|
+ files = [os.path.join(localPath,f) for f in os.listdir(localPath)
|
|
|
+ if os.path.isfile(os.path.join(localPath, f))]
|
|
|
+
|
|
|
+ return files
|
|
|
+
|
|
|
+def getfile(origin,f):
|
|
|
+
|
|
|
+ if origin.find('labkey')==0:
|
|
|
+ try:
|
|
|
+
|
|
|
+ net=slicer.modules.labkeySlicerPythonExtensionWidget.network
|
|
|
+ print("Using labkey")
|
|
|
+ url=slicer.modules.labkeySlicerPythonExtensionWidget.serverURL.text
|
|
|
+ print("Sever:{0}, file:{1}".format(url,f))
|
|
|
+ return [net.readFile(str(url),f),1]
|
|
|
+ except:
|
|
|
+ print('Could not access labkey. Exiting')
|
|
|
+ return ['NULL',0]
|
|
|
|
|
|
+ if origin.find('file')==0:
|
|
|
+ print("Using local directory")
|
|
|
+ return [f,1]
|
|
|
+
|
|
|
+ return ['NULL',0]
|
|
|
+
|
|
|
+def read_dynamic_SPECT(mypath):
|
|
|
+ origin=re.sub('([^:/])://(.*)$',r'\1',mypath)
|
|
|
+ onlyfiles=filelist(mypath)
|
|
|
for f in onlyfiles:
|
|
|
print '{}:'.format(f)
|
|
|
+
|
|
|
+ g,ok=getfile(origin,f)
|
|
|
+ if not(ok):
|
|
|
+ return
|
|
|
+
|
|
|
try:
|
|
|
- plan = dicom.read_file(os.path.join(mypath,f))
|
|
|
+ plan = dicom.read_file(g)
|
|
|
except:
|
|
|
print ("Not a dicom file")
|
|
|
continue
|
|
@@ -77,8 +123,13 @@ def read_dynamic_SPECT(mypath):
|
|
|
pixel_size =[0,0,0]
|
|
|
frame_orientation=[0,0,0,0,0,0]
|
|
|
for f in onlyfiles:
|
|
|
+
|
|
|
+ g,ok=getfile(origin,f)
|
|
|
+ if not(ok):
|
|
|
+ return
|
|
|
+
|
|
|
try:
|
|
|
- plan = dicom.read_file(os.path.join(mypath,f))
|
|
|
+ plan = dicom.read_file(g)
|
|
|
except:
|
|
|
print ("Not a dicom file")
|
|
|
continue
|
|
@@ -155,8 +206,8 @@ def read_dynamic_SPECT(mypath):
|
|
|
return [frame_data,frame_time,center,pixel_size,frame_orientation]
|
|
|
|
|
|
def read_CT(mypath):
|
|
|
- onlyfiles = [f for f in os.listdir(mypath)
|
|
|
- if os.path.isfile(os.path.join(mypath, f))]
|
|
|
+ onlyfiles=filelist(mypath)
|
|
|
+ origin=re.sub('([^:/])://(.*)$',r'\1',mypath)
|
|
|
|
|
|
ct_data = []
|
|
|
ct_idx = []
|
|
@@ -166,8 +217,13 @@ def read_CT(mypath):
|
|
|
ct_orientation=[0,0,0,0,0,0]
|
|
|
for f in onlyfiles:
|
|
|
print '{}:'.format(f)
|
|
|
+
|
|
|
+ g,ok=getfile(origin,f)
|
|
|
+ if not(ok):
|
|
|
+ return
|
|
|
+
|
|
|
try:
|
|
|
- plan = dicom.read_file(os.path.join(mypath,f))
|
|
|
+ plan = dicom.read_file(g)
|
|
|
except:
|
|
|
print ("Not a dicom file")
|
|
|
continue
|