From 66932640440490251e486b96c8303d6d39576cda Mon Sep 17 00:00:00 2001 From: Kyle Harrington Date: Sun, 16 Jul 2023 11:03:33 -0400 Subject: [PATCH 1/2] Add recursive options for node deletion and set LUT --- .../sc/iview/commands/edit/DeleteObject.java | 5 +- src/main/kotlin/sc/iview/SciView.kt | 54 +++++++++++-------- .../kotlin/sc/iview/commands/view/SetLUT.kt | 9 ++-- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/main/java/sc/iview/commands/edit/DeleteObject.java b/src/main/java/sc/iview/commands/edit/DeleteObject.java index 833c86aad..cb3d00b54 100644 --- a/src/main/java/sc/iview/commands/edit/DeleteObject.java +++ b/src/main/java/sc/iview/commands/edit/DeleteObject.java @@ -52,6 +52,9 @@ public class DeleteObject implements Command { @Parameter private SciView sciView; + @Parameter(label = "Delete children?") + private boolean runRecursive = false; + // TODO it would be good if this could continue to use active node but also use an @Parameter by using a callback or sth // @Parameter // private Node node; @@ -59,7 +62,7 @@ public class DeleteObject implements Command { @Override public void run() { if( sciView.getActiveNode() != null ) { - sciView.deleteActiveNode(false); + sciView.deleteActiveNode(false, runRecursive); } } diff --git a/src/main/kotlin/sc/iview/SciView.kt b/src/main/kotlin/sc/iview/SciView.kt index 74cb3c893..653875aaa 100644 --- a/src/main/kotlin/sc/iview/SciView.kt +++ b/src/main/kotlin/sc/iview/SciView.kt @@ -1155,7 +1155,7 @@ class SciView : SceneryBase, CalibratedRealInterval { /** * Delete the current active node */ - fun deleteActiveNode(askUser: Boolean = false) { + fun deleteActiveNode(askUser: Boolean = false, runRecursive: Boolean = false) { if(askUser && activeNode != null){ val options = arrayOf("Cancel", "Delete ${activeNode!!.name}") val x = JOptionPane.showOptionDialog( @@ -1167,7 +1167,11 @@ class SciView : SceneryBase, CalibratedRealInterval { return } } - deleteNode(activeNode) + if (runRecursive) { + activeNode?.runRecursive( { node: Node -> this.deleteNode(node) }) + } else { + deleteNode(activeNode) + } } /** @@ -1278,29 +1282,33 @@ class SciView : SceneryBase, CalibratedRealInterval { * @param n node to apply colortable to * @param colorTable ColorTable to use */ - fun setColormap(n: Node, colorTable: ColorTable) { - val copies = 16 - val byteBuffer = ByteBuffer.allocateDirect( - 4 * colorTable.length * copies) // Num bytes * num components * color map length * height of color map texture - val tmp = ByteArray(4 * colorTable.length) - for (k in 0 until colorTable.length) { - for (c in 0 until colorTable.componentCount) { - // TODO this assumes numBits is 8, could be 16 - tmp[4 * k + c] = colorTable[c, k].toByte() + fun setColormap(n: Node, colorTable: ColorTable, runRecursive: Boolean = false) { + if (runRecursive) { + n.runRecursive( {node -> this.setColormap(node, colorTable) }) + } else { + val copies = 16 + val byteBuffer = ByteBuffer.allocateDirect( + 4 * colorTable.length * copies) // Num bytes * num components * color map length * height of color map texture + val tmp = ByteArray(4 * colorTable.length) + for (k in 0 until colorTable.length) { + for (c in 0 until colorTable.componentCount) { + // TODO this assumes numBits is 8, could be 16 + tmp[4 * k + c] = colorTable[c, k].toByte() + } + if (colorTable.componentCount == 3) { + tmp[4 * k + 3] = 255.toByte() + } } - if (colorTable.componentCount == 3) { - tmp[4 * k + 3] = 255.toByte() + for (i in 0 until copies) { + byteBuffer.put(tmp) + } + byteBuffer.flip() + n.metadata["sciviewColormap"] = colorTable + if (n is Volume) { + n.colormap = Colormap.fromColorTable(colorTable) + n.geometryOrNull()?.dirty = true + n.spatial().needsUpdate = true } - } - for (i in 0 until copies) { - byteBuffer.put(tmp) - } - byteBuffer.flip() - n.metadata["sciviewColormap"] = colorTable - if (n is Volume) { - n.colormap = Colormap.fromColorTable(colorTable) - n.geometryOrNull()?.dirty = true - n.spatial().needsUpdate = true } } diff --git a/src/main/kotlin/sc/iview/commands/view/SetLUT.kt b/src/main/kotlin/sc/iview/commands/view/SetLUT.kt index e8adafe95..d5f61979e 100644 --- a/src/main/kotlin/sc/iview/commands/view/SetLUT.kt +++ b/src/main/kotlin/sc/iview/commands/view/SetLUT.kt @@ -31,7 +31,6 @@ package sc.iview.commands.view import graphics.scenery.Node import net.imglib2.display.ColorTable import org.scijava.command.Command -import org.scijava.command.CommandService import org.scijava.command.DynamicCommand import org.scijava.plugin.Menu import org.scijava.plugin.Parameter @@ -40,9 +39,7 @@ import org.scijava.prefs.PrefService import sc.iview.SciView import sc.iview.commands.MenuWeights.VIEW import sc.iview.commands.MenuWeights.VIEW_SET_LUT -import sc.iview.commands.demo.basic.VolumeRenderDemo import java.io.IOException -import java.util.* /** @@ -68,6 +65,9 @@ class SetLUT : DynamicCommand() { @Parameter private lateinit var prefs: PrefService + @Parameter + private var runRecursive: Boolean = false + protected fun initLutName() { lutName = "Fire.lut" } @@ -97,8 +97,9 @@ class SetLUT : DynamicCommand() { override fun run() { node.metadata["sciview.colormapName"] = lutName - sciView.setColormap(node, colorTable) + sciView.setColormap(node, colorTable, runRecursive) // Trigger an update to the UI for the colormap sciView.publishNode(node) } + } From 5174d4653174f72a081cbadadf7576622d1486e8 Mon Sep 17 00:00:00 2001 From: Kyle Harrington Date: Sun, 16 Jul 2023 11:24:31 -0400 Subject: [PATCH 2/2] Add run recursive fro ToggleBoundingGrid --- .../kotlin/sc/iview/commands/view/SetLUT.kt | 2 +- .../iview/commands/view/ToggleBoundingGrid.kt | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/sc/iview/commands/view/SetLUT.kt b/src/main/kotlin/sc/iview/commands/view/SetLUT.kt index d5f61979e..f8d4107cc 100644 --- a/src/main/kotlin/sc/iview/commands/view/SetLUT.kt +++ b/src/main/kotlin/sc/iview/commands/view/SetLUT.kt @@ -65,7 +65,7 @@ class SetLUT : DynamicCommand() { @Parameter private lateinit var prefs: PrefService - @Parameter + @Parameter(label = "Apply to child nodes?") private var runRecursive: Boolean = false protected fun initLutName() { diff --git a/src/main/kotlin/sc/iview/commands/view/ToggleBoundingGrid.kt b/src/main/kotlin/sc/iview/commands/view/ToggleBoundingGrid.kt index fcfa365af..37279f528 100644 --- a/src/main/kotlin/sc/iview/commands/view/ToggleBoundingGrid.kt +++ b/src/main/kotlin/sc/iview/commands/view/ToggleBoundingGrid.kt @@ -30,6 +30,7 @@ package sc.iview.commands.view import graphics.scenery.BoundingGrid import graphics.scenery.Node +import graphics.scenery.primitives.TextBoard import org.scijava.command.Command import org.scijava.log.LogService import org.scijava.plugin.Menu @@ -52,7 +53,15 @@ class ToggleBoundingGrid : Command { @Parameter private lateinit var node: Node - override fun run() { + @Parameter(label = "Apply to child nodes?") + private var runRecursive: Boolean = false + + fun toggleBoundingGrid(node: Node) { + // We need to skip BoundingGrid and TextBoard otherwise we get an infinite loop + if (node is BoundingGrid || node is TextBoard) { + return + } + val bg = node.children.findLast { it is BoundingGrid } as? BoundingGrid if (bg != null) { bg.node = null @@ -63,4 +72,12 @@ class ToggleBoundingGrid : Command { sciView.publishNode(newBg) } } + + override fun run() { + if (runRecursive) { + node.runRecursive({node: Node -> toggleBoundingGrid(node)}) + } else { + toggleBoundingGrid(node) + } + } } \ No newline at end of file