Skip to content

Commit

Permalink
Merge pull request #594 from scenerygraphics/fix-scene-rebuilds
Browse files Browse the repository at this point in the history
Only rebuild scene graph once per Renderer frame
  • Loading branch information
kephale authored Jun 13, 2024
2 parents c53ccda + 4286604 commit 4c29759
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
34 changes: 27 additions & 7 deletions src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,21 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
*/
private var animating = false

/**
* Track whether the scene changed and needs an update in the next tick
*/
public var needSceneUpdate: Boolean = false

/**
* This tracks the actively selected Node in the scene
*/
var activeNode: Node? = null
private set

/*
* Return the SciJava Display that contains SciView
*//*
* Set the SciJava Display
*/ var display: Display<*>? = null
/**
* The SciJava Display that contains SciView
*/
var display: Display<*>? = null

/**
* List of available LUTs for caching
Expand Down Expand Up @@ -410,6 +414,22 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
controls = Controls(this)

imageToVolumeMap = HashMap<Any, Volume>()

// Create a hook for running after each frame is rendered
renderer?.runAfterRendering?.add { this.updateAferRendering() }
}

/**
* A method that is run after the scene is rendered
*/
private fun updateAferRendering() {
if(needSceneUpdate) {
mainWindow.rebuildSceneTree()
if (activeNode == null){
(mainWindow as SwingMainWindow).nodePropertyEditor.updateProperties(null)
}
needSceneUpdate = false
}
}

fun toggleSidebar(): Boolean {
Expand Down Expand Up @@ -1026,13 +1046,13 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
@Suppress("UNUSED_PARAMETER")
@EventHandler
protected fun onNodeAdded(event: NodeAddedEvent?) {
mainWindow.rebuildSceneTree()
needSceneUpdate = true
}

@Suppress("UNUSED_PARAMETER")
@EventHandler
protected fun onNodeRemoved(event: NodeRemovedEvent?) {
mainWindow.rebuildSceneTree()
needSceneUpdate = true
}

@Suppress("UNUSED_PARAMETER")
Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/sc/iview/ui/SwingNodePropertyEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ class SwingNodePropertyEditor(private val sciView: SciView) : UIComponent<JPanel
private fun onEvent(evt: NodeRemovedEvent) {
val node = evt.node ?: return
log.trace("Node removed: $node");
rebuildTree()
if (sciView.activeNode == null){
updateProperties(null)
}
sciView.needSceneUpdate = true
}

@EventHandler
Expand Down

0 comments on commit 4c29759

Please sign in to comment.