-
Notifications
You must be signed in to change notification settings - Fork 4
/
XTInteractiveShell.py
executable file
·66 lines (52 loc) · 1.79 KB
/
XTInteractiveShell.py
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
#
#
# Python Interactive Shell XTension
#
# Copyright (c) 2013 Egor Zindy ([email protected]), BSD-style copyright and disclaimer apply
#
# <CustomTools>
# <Menu>
# <Item name="Interactive Shell" icon="Python" tooltip="Opens an interactive shell.">
# <Command>PythonXT::XTInteractiveShell(%i)</Command>
# </Item>
# </Menu>
# </CustomTools>
import ImarisLib
import time
import code
import numpy
def GetType(dataset):
imaris_types = {'eTypeUInt8':numpy.uint8,'eTypeUInt16':numpy.uint16,'eTypeFloat':numpy.float32}
return imaris_types[str(dataset.GetType())]
def GetDataSlice(dataset,z,c,t):
dtype = GetType(dataset)
if dtype == numpy.uint8 or dtype == numpy.uint16:
arr = numpy.array(dataset.GetDataSliceShorts(z,c,t),dtype)
else:
arr = numpy.array(dataset.GetDataSliceFloats(z,c,t),dtype)
return arr
def SetDataSlice(dataset,arr,z,c,t):
dtype = GetType(dataset)
if dtype == numpy.uint8 or dtype == numpy.uint16:
dataset.SetDataSliceShorts(arr.tolist(),z,c,t)
else:
dataset.SetDataSliceFloats(arr.tolist(),z,c,t)
def XTInteractiveShell(aImarisId):
# Create an ImarisLib object
vImarisLib = ImarisLib.ImarisLib()
# Get an imaris object with id aImarisId
vImaris = vImarisLib.GetApplication(aImarisId)
# Check if the object is valid
if vImaris is None:
print "Could not connect to Imaris!"
time.sleep(2)
return
# Get the dataset
vDataSet = vImaris.GetDataSet()
# Check if the object is valid
if vDataSet is None:
print "Warning: No dataset!\n"
vars = globals().copy()
vars.update(locals())
shell = code.InteractiveConsole(vars)
shell.interact()