Skip to content

Commit 4c29759

Browse files
authored
Merge pull request #594 from scenerygraphics/fix-scene-rebuilds
Only rebuild scene graph once per Renderer frame
2 parents c53ccda + 4286604 commit 4c29759

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/main/kotlin/sc/iview/SciView.kt

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,21 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
213213
*/
214214
private var animating = false
215215

216+
/**
217+
* Track whether the scene changed and needs an update in the next tick
218+
*/
219+
public var needSceneUpdate: Boolean = false
220+
216221
/**
217222
* This tracks the actively selected Node in the scene
218223
*/
219224
var activeNode: Node? = null
220225
private set
221226

222-
/*
223-
* Return the SciJava Display that contains SciView
224-
*//*
225-
* Set the SciJava Display
226-
*/ var display: Display<*>? = null
227+
/**
228+
* The SciJava Display that contains SciView
229+
*/
230+
var display: Display<*>? = null
227231

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

412416
imageToVolumeMap = HashMap<Any, Volume>()
417+
418+
// Create a hook for running after each frame is rendered
419+
renderer?.runAfterRendering?.add { this.updateAferRendering() }
420+
}
421+
422+
/**
423+
* A method that is run after the scene is rendered
424+
*/
425+
private fun updateAferRendering() {
426+
if(needSceneUpdate) {
427+
mainWindow.rebuildSceneTree()
428+
if (activeNode == null){
429+
(mainWindow as SwingMainWindow).nodePropertyEditor.updateProperties(null)
430+
}
431+
needSceneUpdate = false
432+
}
413433
}
414434

415435
fun toggleSidebar(): Boolean {
@@ -1026,13 +1046,13 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
10261046
@Suppress("UNUSED_PARAMETER")
10271047
@EventHandler
10281048
protected fun onNodeAdded(event: NodeAddedEvent?) {
1029-
mainWindow.rebuildSceneTree()
1049+
needSceneUpdate = true
10301050
}
10311051

10321052
@Suppress("UNUSED_PARAMETER")
10331053
@EventHandler
10341054
protected fun onNodeRemoved(event: NodeRemovedEvent?) {
1035-
mainWindow.rebuildSceneTree()
1055+
needSceneUpdate = true
10361056
}
10371057

10381058
@Suppress("UNUSED_PARAMETER")

src/main/kotlin/sc/iview/ui/SwingNodePropertyEditor.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ class SwingNodePropertyEditor(private val sciView: SciView) : UIComponent<JPanel
149149
private fun onEvent(evt: NodeRemovedEvent) {
150150
val node = evt.node ?: return
151151
log.trace("Node removed: $node");
152-
rebuildTree()
153-
if (sciView.activeNode == null){
154-
updateProperties(null)
155-
}
152+
sciView.needSceneUpdate = true
156153
}
157154

158155
@EventHandler

0 commit comments

Comments
 (0)