From 20805031771cbb697b9d30396bffa2714e94286f Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Wed, 18 Dec 2024 15:51:42 +0100 Subject: [PATCH] In case the highlighting is triggered from a branch view / branch table, try to highlight the spot in the branch at the current timepoint instead of the always the last spot in graph * In coupled views this allows to show the highlighted spot in the BDV --- .../mastodon/mamut/views/MamutBranchView.java | 12 ++--- .../mamut/views/table/MamutViewTable.java | 8 ++-- .../branch/BranchGraphHighlightAdapter.java | 44 ++++++++++++++++--- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/mastodon/mamut/views/MamutBranchView.java b/src/main/java/org/mastodon/mamut/views/MamutBranchView.java index 470edcbb1..db0597562 100644 --- a/src/main/java/org/mastodon/mamut/views/MamutBranchView.java +++ b/src/main/java/org/mastodon/mamut/views/MamutBranchView.java @@ -157,12 +157,6 @@ public MamutBranchView( final ProjectModel appModel, final VG viewGraph, final S final ModelBranchGraph branchGraph = appModel.getModel().getBranchGraph(); final ModelGraph graph = appModel.getModel().getGraph(); - // Highlight. - final HighlightModel< Spot, Link > graphHighlightModel = appModel.getHighlightModel(); - final HighlightModel< BranchSpot, BranchLink > branchHighlightModel = - new BranchGraphHighlightAdapter<>( branchGraph, graph, graph.getGraphIdBimap(), graphHighlightModel ); - this.highlightModel = new HighlightModelAdapter<>( branchHighlightModel, vertexMap, edgeMap ); - // Focus final FocusModel< Spot > graphFocusModel = appModel.getFocusModel(); final FocusModel< BranchSpot > branchFocusfocusModel = @@ -185,6 +179,12 @@ public MamutBranchView( final ProjectModel appModel, final VG viewGraph, final S // Time-point. this.timepointModel = new TimepointModelAdapter( groupHandle.getModel( appModel.TIMEPOINT ) ); + // Highlight. + final HighlightModel< Spot, Link > graphHighlightModel = appModel.getHighlightModel(); + final HighlightModel< BranchSpot, BranchLink > branchHighlightModel = + new BranchGraphHighlightAdapter<>( branchGraph, graph, graph.getGraphIdBimap(), graphHighlightModel, timepointModel ); + this.highlightModel = new HighlightModelAdapter<>( branchHighlightModel, vertexMap, edgeMap ); + // Tag-set. this.tagSetModel = branchTagSetModel( appModel ); diff --git a/src/main/java/org/mastodon/mamut/views/table/MamutViewTable.java b/src/main/java/org/mastodon/mamut/views/table/MamutViewTable.java index 1dc0b7022..e6147fd3e 100644 --- a/src/main/java/org/mastodon/mamut/views/table/MamutViewTable.java +++ b/src/main/java/org/mastodon/mamut/views/table/MamutViewTable.java @@ -67,6 +67,7 @@ import org.mastodon.model.HighlightModel; import org.mastodon.model.NavigationHandler; import org.mastodon.model.SelectionModel; +import org.mastodon.model.TimepointModel; import org.mastodon.model.branch.BranchGraphEdgeBimap; import org.mastodon.model.branch.BranchGraphFocusAdapter; import org.mastodon.model.branch.BranchGraphHighlightAdapter; @@ -162,7 +163,7 @@ protected MamutViewTable( final ProjectModel projectModel, final boolean selecti .featureModel( featureModel ) .tagSetModel( branchTagSetModel( projectModel ) ) .selectionModel( branchSelectionModel( projectModel ) ) - .highlightModel( branchHighlightModel( projectModel ) ) + .highlightModel( branchHighlightModel( projectModel, this.timepointModel ) ) .coloring( branchColoringAdapter ) .focusModel( branchFocusfocusModel( projectModel ) ) .navigationHandler( branchGraphNavigation( projectModel, navigationHandler ) ) @@ -337,13 +338,14 @@ private static NavigationHandler< BranchSpot, BranchLink > branchGraphNavigation return branchGraphNavigation; } - private static HighlightModel< BranchSpot, BranchLink > branchHighlightModel( final ProjectModel appModel ) + private static HighlightModel< BranchSpot, BranchLink > branchHighlightModel( final ProjectModel appModel, + final TimepointModel timepointModel ) { final ModelGraph graph = appModel.getModel().getGraph(); final ModelBranchGraph branchGraph = appModel.getModel().getBranchGraph(); final HighlightModel< Spot, Link > graphHighlightModel = appModel.getHighlightModel(); final HighlightModel< BranchSpot, BranchLink > branchHighlightModel = - new BranchGraphHighlightAdapter<>( branchGraph, graph, graph.getGraphIdBimap(), graphHighlightModel ); + new BranchGraphHighlightAdapter<>( branchGraph, graph, graph.getGraphIdBimap(), graphHighlightModel, timepointModel ); return branchHighlightModel; } diff --git a/src/main/java/org/mastodon/model/branch/BranchGraphHighlightAdapter.java b/src/main/java/org/mastodon/model/branch/BranchGraphHighlightAdapter.java index 5bc6b8daf..1ce789ce2 100644 --- a/src/main/java/org/mastodon/model/branch/BranchGraphHighlightAdapter.java +++ b/src/main/java/org/mastodon/model/branch/BranchGraphHighlightAdapter.java @@ -28,6 +28,8 @@ */ package org.mastodon.model.branch; +import java.util.Iterator; + import org.mastodon.graph.Edge; import org.mastodon.graph.GraphIdBimap; import org.mastodon.graph.ReadOnlyGraph; @@ -35,10 +37,12 @@ import org.mastodon.graph.branch.BranchGraph; import org.mastodon.model.HighlightListener; import org.mastodon.model.HighlightModel; +import org.mastodon.model.TimepointModel; +import org.mastodon.spatial.HasTimepoint; import org.scijava.listeners.Listeners; public class BranchGraphHighlightAdapter< - V extends Vertex< E >, + V extends Vertex< E > & HasTimepoint, E extends Edge< V >, BV extends Vertex< BE >, BE extends Edge< BV > > @@ -48,28 +52,54 @@ public class BranchGraphHighlightAdapter< private final HighlightModel< V, E > highlight; + private final TimepointModel timepoint; + public BranchGraphHighlightAdapter( final BranchGraph< BV, BE, V, E > branchGraph, final ReadOnlyGraph< V, E > graph, final GraphIdBimap< V, E > idmap, - final HighlightModel< V, E > highlight ) + final HighlightModel< V, E > highlight, + final TimepointModel timepoint ) { super( branchGraph, graph, idmap ); this.highlight = highlight; + this.timepoint = timepoint; } @Override - public void highlightVertex( final BV vertex ) + public void highlightVertex( final BV branchVertex ) { - if ( null == vertex ) + if ( null == branchVertex ) { highlight.highlightVertex( null ); return; } - final V vRef = graph.vertexRef(); - highlight.highlightVertex( branchGraph.getLastLinkedVertex( vertex, vRef ) ); - graph.releaseRef( vRef ); + final V spotRef = graph.vertexRef(); + Iterator< V > vertices = branchGraph.vertexBranchIterator( branchVertex ); + boolean highlighted = false; + try + { + // prefer to highlight the spot at the current timepoint + while ( vertices.hasNext() ) + { + V spotVertex = vertices.next(); + if ( spotVertex.getTimepoint() == timepoint.getTimepoint() ) + { + highlight.highlightVertex( spotVertex ); + highlighted = true; + break; + } + } + // if there is no spot at the current timepoint, highlight the last spot in the branch + if ( !highlighted ) + highlight.highlightVertex( branchGraph.getLastLinkedVertex( branchVertex, spotRef ) ); + } + finally + { + graph.releaseRef( spotRef ); + branchGraph.releaseIterator( vertices ); + } } @Override