Skip to content

Commit

Permalink
More stable track coloring.
Browse files Browse the repository at this point in the history
Prior to this commit, the track color was determine by the position
of a track in the sorted track array, based on the root labels.
In practice, for large number of tracks, this was not so great when
editing tracks a lot. Indeed, the slightest track additon of link
removal could completely change the order, hence the track coloring.
Here we simply use the hash of the root label of a track to determine
its color, making it independent of the other ones. The color of a track
now only depends on the label of its root.
  • Loading branch information
tinevez committed Nov 11, 2024
1 parent 449a401 commit f049c2e
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
import org.mastodon.graph.Vertex;
import org.mastodon.graph.algorithm.traversal.InverseDepthFirstIterator;
import org.mastodon.model.HasLabel;
import org.mastodon.views.trackscheme.util.AlphanumCompare;

public class TrackGraphColorGenerator< V extends Vertex< E > & HasLabel, E extends Edge< V > >
implements GraphColorGenerator< V, E >
{

private final RefIntMap< V > cache;

private final GlasbeyLut lut;
private final int[] lut;

private final InverseDepthFirstIterator< V, E > iterator;

Expand All @@ -62,7 +61,7 @@ public TrackGraphColorGenerator( final ListenableReadOnlyGraph< V, E > graph )
this.rootsProvider = new RootProvider<>( graph );
this.graph = graph;
this.cache = RefMaps.createRefIntMap( graph.vertices(), 0 );
this.lut = GlasbeyLut.create();
this.lut = GlasbeyLut.intColors;
this.iterator = new InverseDepthFirstIterator<>( graph );
this.toUpdate = RefCollections.createRefList( graph.vertices() );

Expand Down Expand Up @@ -137,12 +136,8 @@ private synchronized void rebuildRoots()
if ( rootsUpToDate )
return;

final RefList< V > sortedRoots = RefCollections.createRefList( graph.vertices() );
sortedRoots.addAll( rootsProvider.get() );
sortedRoots.sort( ( v1, v2 ) -> AlphanumCompare.compare( v1.getLabel(), v2.getLabel() ) );
cache.clear();
lut.reset();
sortedRoots.forEach( r -> cache.put( r, lut.next() ) );
rootsProvider.get().forEach( r -> cache.put( r, lut[ Math.abs( r.getLabel().hashCode() ) % lut.length ] ) );
rootsUpToDate = true;
}

Expand Down

0 comments on commit f049c2e

Please sign in to comment.