|
@@ -38,11 +38,13 @@ def main(configFile):
|
|
|
pythonScripts=os.path.join(pwdUp,'pythonScripts')
|
|
|
sys.path.append(pythonScripts)
|
|
|
import config
|
|
|
+ import getData
|
|
|
print('Config loaded')
|
|
|
|
|
|
net=labkeyInterface.labkeyInterface()
|
|
|
fnet=os.path.join(os.path.expanduser('~'),'.labkey',xconfig['network'])
|
|
|
net.init(fnet)
|
|
|
+ r['CT']=
|
|
|
net.getCSRF()
|
|
|
fb=labkeyFileBrowser.labkeyFileBrowser(net)
|
|
|
db=labkeyDatabaseBrowser.labkeyDB(net)
|
|
@@ -98,14 +100,29 @@ def main(configFile):
|
|
|
for node in nodes:
|
|
|
print('\t{}'.format(node.GetName()))
|
|
|
storeNode(fb,r,xconfig,node)
|
|
|
+
|
|
|
+ nodes=slicer.mrmlScene.GetNodesByClass('vtkMRMLTableNode')
|
|
|
+ print('Nodes (table)')
|
|
|
+ for node in nodes:
|
|
|
+ print('\t{}'.format(node.GetName()))
|
|
|
+ storeNode(fb,r,xconfig,node)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
clearNodes(r,xconfig)
|
|
|
+ #addCT and addFrames fill r['ct'] and r['spect']
|
|
|
+ db.modifyRows('update',xconfig['project'],xconfig['schemaName'],xconfig['queryName'],[r])
|
|
|
+ getData.updateStatus(db,r,setup,'convertToNRRD')
|
|
|
|
|
|
|
|
|
def clearNodes(row,xconfig):
|
|
|
nodes=slicer.mrmlScene.GetNodesByClass('vtkMRMLScalarVolumeNode')
|
|
|
nodes1=slicer.mrmlScene.GetNodesByClass('vtkMRMLDoubleArrayNode')
|
|
|
+ nodes2=slicer.mrmlScene.GetNodesByClass('vtkMRMLTableNode')
|
|
|
for n in nodes1:
|
|
|
nodes.AddItem(n)
|
|
|
+ for n in nodes2:
|
|
|
+ nodes.AddItem(n)
|
|
|
|
|
|
res=[slicer.mrmlScene.RemoveNode(f) for f in nodes]
|
|
|
|
|
@@ -188,6 +205,7 @@ def addCT(r,patient,xconfig):
|
|
|
vtkData=vtkInterface.numpyToVTK(ct['data'],ct['data'].shape)
|
|
|
nodeName=config.getNodeName(r,xconfig,'CT')
|
|
|
addNode(nodeName,vtkData,ct['origin'],ct['pixel_size'],ct['orientation'],0)
|
|
|
+ r['ct']=f'{nodeName}.nrrd'
|
|
|
|
|
|
|
|
|
def addFrames(r,patient,xconfig):
|
|
@@ -202,7 +220,8 @@ def addFrames(r,patient,xconfig):
|
|
|
nodeName=config.getNodeName(r,xconfig,'NM',it)
|
|
|
vtkData=vtkInterface.numpyToVTK(frame_data,frame_data.shape)
|
|
|
addNode(nodeName,vtkData,nm['origin'],nm['pixel_size'],nm['orientation'],1)
|
|
|
-
|
|
|
+ #last one will be kept
|
|
|
+ r['spect']=f'{nodeName}.nrrd'
|
|
|
|
|
|
|
|
|
def addNode(nodeName,v,origin,pixel_size,orientation,dataType):
|
|
@@ -241,8 +260,11 @@ def addDummyInputFunction(r,patient,xconfig):
|
|
|
dnsNodeName=config.getNodeName(r,xconfig,'Dummy')
|
|
|
dns = slicer.mrmlScene.GetNodesByClassByName('vtkMRMLDoubleArrayNode',dnsNodeName)
|
|
|
if dns.GetNumberOfItems() == 0:
|
|
|
- dn = slicer.mrmlScene.AddNode(slicer.vtkMRMLDoubleArrayNode())
|
|
|
- dn.SetName(dnsNodeName)
|
|
|
+ try:
|
|
|
+ dn = slicer.mrmlScene.AddNode(slicer.vtkMRMLDoubleArrayNode())
|
|
|
+ except AttributeError:
|
|
|
+ addDummyTable(dnsNodeName,n,nm)
|
|
|
+ return
|
|
|
else:
|
|
|
dn = dns.GetItemAsObject(0)
|
|
|
|
|
@@ -258,12 +280,43 @@ def addDummyInputFunction(r,patient,xconfig):
|
|
|
dn.SetValue(i, 2, 0)
|
|
|
print('{} ({},{})'.format(i,fx,fy))
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+def addDummyTable(dnsNodeName,n,nm):
|
|
|
+
|
|
|
+ #add vtkMRMLTableNodes
|
|
|
+ dns = slicer.mrmlScene.GetNodesByClassByName('vtkMRMLTableNode',dnsNodeName)
|
|
|
+ if dns.GetNumberOfItems() == 0:
|
|
|
+ dn = slicer.mrmlScene.AddNode(slicer.vtkMRMLTableNode())
|
|
|
+ dn.SetName(dnsNodeName)
|
|
|
+ else:
|
|
|
+ dn = dns.GetItemAsObject(0)
|
|
|
+ dn.RemoveAllColumns()
|
|
|
+
|
|
|
+
|
|
|
+ ft=nm['time']
|
|
|
+ dt=nm['duration']
|
|
|
+ tCol=vtk.vtkDoubleArray()
|
|
|
+ dCol=vtk.vtkDoubleArray()
|
|
|
+ for i in range(n):
|
|
|
+ tCol.InsertNextValue(ft[i])
|
|
|
+ dCol.InsertNextValue(dt[i])
|
|
|
+
|
|
|
+ tcol=dn.AddColumn(tCol)
|
|
|
+ tcol.SetName('time')
|
|
|
+ dcol=dn.AddColumn(dCol)
|
|
|
+ dcol.SetName('duration')
|
|
|
+
|
|
|
def storeNode(fb,row,xconfig,node):
|
|
|
import config
|
|
|
|
|
|
suffix=".nrrd"
|
|
|
+ isTable=False
|
|
|
if node.__class__.__name__=="vtkMRMLDoubleArrayNode":
|
|
|
suffix=".mcsv"
|
|
|
+ if node.__class__.__name__=="vtkMRMLTableNode":
|
|
|
+ suffix=".mcsv"
|
|
|
+ isTable=True
|
|
|
if (node.__class__.__name__=="vtkMRMLTransformNode" or \
|
|
|
node.__class__.__name__=="vtkMRMLGridTransformNode"):
|
|
|
suffix=".h5"
|
|
@@ -272,7 +325,10 @@ def storeNode(fb,row,xconfig,node):
|
|
|
|
|
|
localPath=os.path.join(config.getLocalDir(row,xconfig),fileName)
|
|
|
|
|
|
- slicer.util.saveNode(node,localPath)
|
|
|
+ if isTable:
|
|
|
+ storeTable(node,localPath)
|
|
|
+ else:
|
|
|
+ slicer.util.saveNode(node,localPath)
|
|
|
print("Stored to: {}".format(localPath))
|
|
|
labkeyPath=fb.buildPathURL(xconfig['project'],config.getPathList(row,xconfig))
|
|
|
print ("Remote: {}".format(labkeyPath))
|
|
@@ -281,7 +337,23 @@ def storeNode(fb,row,xconfig,node):
|
|
|
fb.writeFileToFile(localPath,remoteFile)
|
|
|
|
|
|
|
|
|
-
|
|
|
+def storeTable(node,filename):
|
|
|
+ #mimic old vtkMRMLDoubleArray format
|
|
|
+ table=node.GetTable()
|
|
|
+ ft=table.GetColumnByName('time')
|
|
|
+ fd=table.GetColumnByName('duration')
|
|
|
+ n=ft.GetNumberOfValues()
|
|
|
+ print(f'Storing {n} values')
|
|
|
+ with open(filename,'w') as f:
|
|
|
+ f.write(f'# measurement file {filename}\n')
|
|
|
+ f.write('# no labels\n')
|
|
|
+ for i in range(n):
|
|
|
+ _t=ft.GetTuple1(i)
|
|
|
+ _d=fd.GetTuple1(i)
|
|
|
+ print(f'{_t},{_d},0')
|
|
|
+ f.write(f'{_t},{_d},0\n')
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|