1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
import os
import h5py
import Object3DStack
try:
from PyMca.Object3D import Object3DFileDialogs
except ImportError:
from Object3D import Object3DFileDialogs
qt = Object3DFileDialogs.qt
class ChimeraStack(Object3DStack.Object3DStack):
pass
MENU_TEXT = '4D Chimera'
def getObject3DInstance(config=None):
#for the time being a former configuration
#for serializing purposes is not implemented
#I do the import here for the case PyMca is not installed
#because the modules could be instanstiated without using
#this method
try:
from PyMca.PyMcaIO import EDFStack
except ImportError:
import EDFStack
fileTypeList = ['Chimera Stack (*cmp)',
'Chimera Stack (*)']
old = Object3DFileDialogs.Object3DDirs.nativeFileDialogs * 1
#Object3DFileDialogs.Object3DDirs.nativeFileDialogs = False
fileList, filterUsed = Object3DFileDialogs.getFileList(None, fileTypeList,
"Please select the object file(s)",
"OPEN",
True)
Object3DFileDialogs.Object3DDirs.nativeFileDialogs = old
if not len(fileList):
return None
if filterUsed == fileTypeList[0]:
fileindex = 2
else:
fileindex = 1
#file index is irrelevant in case of an actual 3D stack.
filename = fileList[0]
legend = os.path.basename(filename)
f = h5py.File(filename)
stack = f['Image']['data'].value
f = None
if stack is None:
raise IOError("Problem reading stack.")
object3D = ChimeraStack(name=legend)
object3D.setStack(stack)
return object3D
if __name__ == "__main__":
import sys
from Object3D import SceneGLWindow
import os
try:
from PyMca.PyMcaIO import EDFStack
from PyMca.PyMcaIO import EdfFile
except ImportError:
import EDFStack
import EdfFile
import getopt
options = ''
longoptions = ["fileindex=","begin=", "end="]
try:
opts, args = getopt.getopt(
sys.argv[1:],
options,
longoptions)
except getopt.error,msg:
print msg
sys.exit(1)
fileindex = 2
begin = None
end = None
for opt, arg in opts:
if opt in '--begin':
begin = int(arg)
elif opt in '--end':
end = int(arg)
elif opt in '--fileindex':
fileindex = int(arg)
app = qt.QApplication(sys.argv)
window = SceneGLWindow.SceneGLWindow()
window.show()
if len(sys.argv) == 1:
object3D = getObject3DInstance()
if object3D is not None:
window.addObject(object3D)
else:
filename = sys.argv[1]
if not os.path.exists(filename):
print "File does not exists"
sys.exit(1)
f = h5py.File(filename)
stack = f['Image']['data'].value
if stack is None:
raise IOError, "Problem reading stack."
object3D = ChimeraStack(name=os.path.basename(filename))
object3D.setStack(stack)
f = None
window.addObject(object3D, os.path.basename(filename))
window.setSelectedObject(os.path.basename(filename))
window.glWidget.setZoomFactor(1.0)
window.show()
app.exec_()
|