forked from nilesh-patil/python-XTensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXTSimpleSpotsExample.py
More file actions
77 lines (59 loc) · 2.21 KB
/
XTSimpleSpotsExample.py
File metadata and controls
77 lines (59 loc) · 2.21 KB
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
# PythonXT Simple Spots Example for Imaris
#
# Copyright Bitplane AG
#
# <CustomTools>
# <Menu name = "Python plugins">
# <Submenu name = "Default">
# <Item name="Simple Spots Example" icon="Python" tooltip="Simple XTension creating a Spot in the Center of the Dataset">
# <Command>PythonXT::XTSimpleSpotsExample(%i)</Command>
# </Item>
# </Submenu>
# </Menu>
# </CustomTools>
import time
import ImarisLib
def XTSimpleSpotsExample(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!'
# Sleep 2 seconds to give the user a chance to see the printed message
time.sleep(2)
return
# Get the currently loaded dataset
vImage = vImaris.GetDataSet()
# This xtension requires a loaded dataset
if vImage is None:
print 'An image has to be loaded into Imaris first'
time.sleep(2)
return
# Get the extents of the image
vExtentMinX = vImage.GetExtendMinX();
vExtentMinY = vImage.GetExtendMinY();
vExtentMinZ = vImage.GetExtendMinZ();
vExtentMaxX = vImage.GetExtendMaxX();
vExtentMaxY = vImage.GetExtendMaxY();
vExtentMaxZ = vImage.GetExtendMaxZ();
vImageSizeX = vExtentMaxX - vExtentMinX;
vImageSizeY = vExtentMaxY - vExtentMinY;
vImageSizeZ = vExtentMaxZ - vExtentMinZ;
vMinRadius = min(vImageSizeX, vImageSizeY, vImageSizeZ) / 2;
# Calculate the center of the image
vCenterX = (vExtentMinX + vExtentMaxX) / 2;
vCenterY = (vExtentMinY + vExtentMaxY) / 2;
vCenterZ = (vExtentMinZ + vExtentMaxZ) / 2;
# Create a spots component
vSpotsComponent = vImaris.GetFactory().CreateSpots();
# Add one spot in the center
# The positions array is 2 dimensional
vSpotsComponent.Set([[vCenterX, vCenterY, vCenterZ]], [0], [vMinRadius]);
# Give the component are nice name
vSpotsComponent.SetName('Image Center Spot');
# Color the one spot red
vSpotsComponent.SetColorRGBA(255);
# Add the spots component at the end of the surpass tree
vImaris.GetSurpassScene().AddChild(vSpotsComponent, -1);