morphonets/SNT

Feature request: decompose one path into multiple single points

alexyangalexyang opened this issue · 5 comments

Is your feature request related to a problem? Please describe.

When tracing the filaments, I sometimes want to show the "2 ends" with a disk-like marks. I found it is not available. Therefore, I collected all the ends coordinates, trying to show that disks in separate paths. However, the program will automatically link all the ends, which I don't want. I tried to use "disconnect" or "rebuild" function but it doesn't work.
Describe the solution you'd like

I wonder if there is an easier way to "decompose" single filament to "several single points", one path for each point. Of course I could do it one by one but it is very inconvenient.

Describe alternatives you've considered

I show the "2 ends" in the 3D view with a disk-like marks. Now the program allows "lines and disks" but it shows all nodes with disks. I only want the ends.

Additional context
Thank you!

tferr commented

@alexyangalexyang , I am convinced that this could be achieved through scripting. E.g., the following groovy snippet should highlight the terminal nodes in all the paths listed in the Path Manager:

#@SNTService snt

if (!snt.isActive()) {
	println(">>>> SNT is not running <<<<")
	return
}
for (p in snt.getPaths()) {
	lastIdx = p.size()-1
	p.setEditableNode(lastIdx)
}
snt.updateViewers() // ensure viewers are repainted

There are a couple of ways to highlight nodes,. This snippet exploits the fact that nodes tagged for editing operations are rendered different in the image being traced, so it just tags them as editable

Does this solve your issue?

Correct. that snippet only highlights the nodes in the image being traced. To have them highlighted in the Reconstruction Viewer you could use something like this snippet (Groovy):

#@SNTService snt

import sc.fiji.snt.*
import sc.fiji.snt.analysis.*
import sc.fiji.snt.viewer.*
import net.imagej.display.ColorTables

// load a reconstruction
try {
	tree = new Tree("/path/to/a/reconstruction.file")
} catch (Exception ignored) { // invalid file, load demo instead
	tree = snt.demoTrees().get(0)
}

// retrieve tips
treeStats = new TreeStatistics(tree)
tips = treeStats.getTips()

// add tree to a new instance of an interactive viewer
viewer = new Viewer3D(true)
tree.setColor("yellow")
viewer.add(tree)

// add tips as 3D annotations: as monochrome collection
annotations = viewer.annotatePoints(tips, "annotated tips: monochrome")
annotations.setSize(20)
annotations.setColor("cyan")

// add tips as 3D annotations: as collection color-mapped to a morphometric trait
nodeStats = treeStats.getNodeStatistics("tips")
mapper = new NodeColorMapper(nodeStats)
mapper.map("x-coord", ColorTables.ICE)
annotations = viewer.annotatePoints(mapper.getNodes(), "annotated tips: color-mapped")
annotations.setSize(20)

// display
viewer.show()

Which displays the following:

image

image

@alexyangalexyang , did this solve the issue? Shall we close it?