Files
x11ma/script/imaging/fov_arrows.py
gac-x11ma 1d75bc4535
2023-07-18 11:00:54 +02:00

117 lines
4.4 KiB
Python

arrows_renderer = arrow_x = arrow_y = arrow_a = label_x = label_y = arrow_y =None
"""
FOV_ARROWS = { \
"100um[0.0]": [10.0], \
"50um[0.0]": [20.0], \
"new_entry": [0.0]
}
"""
run("imaging/FOV_table")
FOV_ARROWS_SIZE=80
FOV_XRAY_ARROW_SIZE=120
FOV_LABEL_POS=FOV_ARROWS_SIZE+15
FOV_XRAY_LABEL_POS=FOV_XRAY_ARROW_SIZE+15
#FOV_ARROWS_ORIGIN=Point(image.getData().width/4, image.getData().height*3/4)
#FOV_ARROWS_ORIGIN=Point(image.getData().width*3/4, image.getData().height/4)
FOV_ARROWS_ORIGIN=Point(image.getData().width-(FOV_LABEL_POS+5), FOV_LABEL_POS+5)
FOV_FUTURE=None
FOV_FUTURE=None
FOV_LABEL_FONT=java.awt.Font("Verdana", java.awt.Font.PLAIN, 12)
FOV_OFFSET=0.0
FOV_COLOR_X = Color.GREEN
FOV_COLOR_Y = Color(173,216,230) # Light Blue
FOV_COLOR_A = Color.YELLOW
AZIMUTH_ROT=0.0
def get_azimuth():
return AZIMUTH_ROT
def set_fov_offset(value):
global FOV_OFFSET
FOV_OFFSET = value
update_arrows()
def set_azimuth_rot(value):
global AZIMUTH_ROT
AZIMUTH_ROT = value
update_arrows()
def update_arrows():
global arrows_renderer, arrow_x, arrow_y, arrow_a, label_x, label_y, label_a
if arrows_renderer is not None:
args = FOV_ARROWS.get(fov.take(), None)
if args is not None:
azimuth=get_azimuth()
angle=args[0] + FOV_OFFSET
angle=angle+180
x,y = FOV_ARROWS_ORIGIN.x, FOV_ARROWS_ORIGIN.y
a=math.radians(angle)
xa,ya=int(x+FOV_XRAY_ARROW_SIZE*math.cos(a)), int(y-FOV_XRAY_ARROW_SIZE*math.sin(a))
arrow_a.update(FOV_ARROWS_ORIGIN, Point(xa,ya))
xa,ya=int(x+FOV_XRAY_LABEL_POS*math.cos(a)), int(y-FOV_XRAY_LABEL_POS*math.sin(a))
label_a.update(Point(xa,ya))
angle=angle-azimuth
a=math.radians(angle)
xa,ya=int(x+FOV_ARROWS_SIZE*math.cos(a)), int(y-FOV_ARROWS_SIZE*math.sin(a))
arrow_x.update(FOV_ARROWS_ORIGIN, Point(xa,ya))
xa,ya=int(x+FOV_LABEL_POS*math.cos(a)), int(y-FOV_LABEL_POS*math.sin(a))
label_x.update(Point(xa,ya))
angle=angle-90
a=math.radians(angle)
xa,ya=int(x+FOV_ARROWS_SIZE*math.cos(a)), int(y-FOV_ARROWS_SIZE*math.sin(a))
arrow_y.update(FOV_ARROWS_ORIGIN, Point(xa,ya))
xa,ya=int(x+FOV_LABEL_POS*math.cos(a)), int(y-FOV_LABEL_POS*math.sin(a))
label_y.update(Point(xa,ya))
else:
log("Cannot draw reference arrows - Invalid microscope preset label: " + fov, False)
arrow_x.update(FOV_ARROWS_ORIGIN, FOV_ARROWS_ORIGIN)
arrow_y.update(FOV_ARROWS_ORIGIN, FOV_ARROWS_ORIGIN)
arrow_a.update(FOV_ARROWS_ORIGIN, FOV_ARROWS_ORIGIN)
label_a.update(label_a.UNDEFINED_POINT)
label_x.update(label_x.UNDEFINED_POINT)
label_y.update(label_y.UNDEFINED_POINT)
arrows_renderer.refresh()
def task_update_arrows():
global arrows_renderer
while arrows_renderer is not None:
try:
if arrows_renderer.isShowing():
update_arrows()
time.sleep(5.0)
time.sleep(1.0)
except:
pass
def start_arrows(renderer=None):
global arrows_renderer, arrow_x, arrow_y, arrow_a, label_x, label_y, label_a, FOV_FUTURE
if arrows_renderer is None:
arrows_renderer = renderer if renderer else show_panel(image)
arrow_x = Overlays.Arrow(Pen(FOV_COLOR_X))
arrow_y = Overlays.Arrow(Pen(FOV_COLOR_Y))
arrow_a = Overlays.Arrow(Pen(FOV_COLOR_A))
label_x = Overlays.Text(arrow_x.pen, "X",FOV_LABEL_FONT)
label_y = Overlays.Text(arrow_y.pen, "Y",FOV_LABEL_FONT)
label_a = Overlays.Text(arrow_a.pen, "X-rays",FOV_LABEL_FONT)
arrows_renderer.addOverlays([arrow_a, label_a, arrow_x,arrow_y,label_x, label_y])
#update_arrows()
FOV_FUTURE = fork(task_update_arrows,)[0]
def stop_arrows(renderer=None):
global arrows_renderer, arrow_x, arrow_y, label_x, label_y, label_a, FOV_FUTURE
if arrows_renderer is not None:
arrows_renderer.removeOverlays([arrow_a, label_a, arrow_x,arrow_y, label_x, label_y])
arrows_renderer=None
if FOV_FUTURE is not None:
FOV_FUTURE.cancel(True)
try:
join(FOV_FUTURE)
except:
pass