Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recursive options for node deletion, set LUT, and toggle bounding boxes #526

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/sc/iview/commands/edit/DeleteObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ 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;

@Override
public void run() {
if( sciView.getActiveNode() != null ) {
sciView.deleteActiveNode(false);
sciView.deleteActiveNode(false, runRecursive);
}
}

Expand Down
54 changes: 31 additions & 23 deletions src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
/**
* 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(
Expand All @@ -1167,7 +1167,11 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
return
}
}
deleteNode(activeNode)
if (runRecursive) {
activeNode?.runRecursive( { node: Node -> this.deleteNode(node) })
} else {
deleteNode(activeNode)
}
}

/**
Expand Down Expand Up @@ -1278,29 +1282,33 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @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
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/sc/iview/commands/view/SetLUT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*


/**
Expand All @@ -68,6 +65,9 @@ class SetLUT : DynamicCommand() {
@Parameter
private lateinit var prefs: PrefService

@Parameter(label = "Apply to child nodes?")
private var runRecursive: Boolean = false

protected fun initLutName() {
lutName = "Fire.lut"
}
Expand Down Expand Up @@ -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)
}

}
19 changes: 18 additions & 1 deletion src/main/kotlin/sc/iview/commands/view/ToggleBoundingGrid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -63,4 +72,12 @@ class ToggleBoundingGrid : Command {
sciView.publishNode(newBg)
}
}

override fun run() {
if (runRecursive) {
node.runRecursive({node: Node -> toggleBoundingGrid(node)})
} else {
toggleBoundingGrid(node)
}
}
}