Skip to content

Commit

Permalink
In case the highlighting is triggered from a branch view / branch tab…
Browse files Browse the repository at this point in the history
…le, 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
  • Loading branch information
stefanhahmann authored and tinevez committed Dec 20, 2024
1 parent 8b3fba9 commit 2080503
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/mastodon/mamut/views/MamutBranchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@
*/
package org.mastodon.model.branch;

import java.util.Iterator;

import org.mastodon.graph.Edge;
import org.mastodon.graph.GraphIdBimap;
import org.mastodon.graph.ReadOnlyGraph;
import org.mastodon.graph.Vertex;
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 > >
Expand All @@ -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
Expand Down

0 comments on commit 2080503

Please sign in to comment.