Skip to content

Instantly share code, notes, and snippets.

@tferr
Created June 18, 2019 17:12
Show Gist options
  • Save tferr/e514f719a2c50b7bf92a6a9ed43d3558 to your computer and use it in GitHub Desktop.
Save tferr/e514f719a2c50b7bf92a6a9ed43d3558 to your computer and use it in GitHub Desktop.
# @LogService log
# @SNTService snt
# @UIService ui
"""
file: Autotrace_OP_1.py
"""
import time
from sc.fiji.snt import (Path, SNT, Tree)
from sc.fiji.snt.util import PointInImage
def run():
# Exit if SNT is already busy doing something
if snt.isActive() and snt.getUI() and not snt.getUI().isReady():
ui.showDialog("Please complete current operation before running this script", "Error")
return
# Prepare plugin for auto-tracing
plugin = snt.initialize("demo", True)
plugin.enableAstar(True)
plugin.getPathAndFillManager().clear();
#plugin.startHessian("primary", 1.15, 14)
ref_tree = snt.demoTree()
new_tree = Tree()
for path in ref_tree.list():
end_point = path.getNode(path.size() - 1)
if path.getStartJoinsPoint() is None:
start_point = path.getNode(0)
primary_path = plugin.autoTrace(start_point, end_point, None)
new_tree.add(primary_path)
else:
# TODO: Simplify this. It is very confusing
source_tree_start_point = path.getStartJoinsPoint()
fork_path_id = path.getStartJoins().getID()
fork_path = new_tree.get(fork_path_id)
closest_index = fork_path.indexNearestTo(source_tree_start_point.x, source_tree_start_point.y,
source_tree_start_point.z, float('inf'))
fork_point = fork_path.getNode(closest_index)
child = plugin.autoTrace([fork_point, end_point], fork_point)
new_tree.add(child)
time.sleep(0.1) # the demo tree is really small: we need a delay
#snt.dispose()
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment