diff --git a/src/main/java/fiji/plugin/trackmate/features/FeatureUtils.java b/src/main/java/fiji/plugin/trackmate/features/FeatureUtils.java index defdc7069..30243a53d 100644 --- a/src/main/java/fiji/plugin/trackmate/features/FeatureUtils.java +++ b/src/main/java/fiji/plugin/trackmate/features/FeatureUtils.java @@ -41,6 +41,7 @@ import fiji.plugin.trackmate.features.manual.ManualSpotColorAnalyzerFactory; import fiji.plugin.trackmate.features.spot.SpotAnalyzerFactoryBase; import fiji.plugin.trackmate.features.track.TrackAnalyzer; +import fiji.plugin.trackmate.features.track.TrackIndexAnalyzer; import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings; import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings.TrackMateObject; import fiji.plugin.trackmate.visualization.FeatureColorGenerator; @@ -51,6 +52,7 @@ import fiji.plugin.trackmate.visualization.PerEdgeFeatureColorGenerator; import fiji.plugin.trackmate.visualization.PerSpotFeatureColorGenerator; import fiji.plugin.trackmate.visualization.PerTrackFeatureColorGenerator; +import fiji.plugin.trackmate.visualization.RandomSpotColorGenerator; import fiji.plugin.trackmate.visualization.SpotColorGenerator; import fiji.plugin.trackmate.visualization.SpotColorGeneratorPerEdgeFeature; import fiji.plugin.trackmate.visualization.SpotColorGeneratorPerTrackFeature; @@ -65,6 +67,10 @@ public class FeatureUtils public static final String USE_UNIFORM_COLOR_KEY = "UNIFORM_COLOR"; + private static final String USE_RANDOM_COLOR_NAME = "Random color"; + + public static final String USE_RANDOM_COLOR_KEY = "RANDOM_COLOR"; + public static final Map< String, String > collectFeatureKeys( final TrackMateObject target, final Model model, final Settings settings ) { final Map< String, String > inverseMap = new HashMap<>(); @@ -131,6 +137,7 @@ public static final Map< String, String > collectFeatureKeys( final TrackMateObj case DEFAULT: { inverseMap.put( USE_UNIFORM_COLOR_NAME, USE_UNIFORM_COLOR_KEY ); + inverseMap.put( USE_RANDOM_COLOR_NAME, USE_RANDOM_COLOR_KEY ); break; } @@ -218,7 +225,14 @@ public static final FeatureColorGenerator< Spot > createSpotColorGenerator( fina switch ( displaySettings.getSpotColorByType() ) { case DEFAULT: - return new UniformSpotColorGenerator( displaySettings.getSpotUniformColor() ); + switch ( displaySettings.getSpotColorByFeature() ) + { + case FeatureUtils.USE_RANDOM_COLOR_KEY: + return new RandomSpotColorGenerator(); + default: + case FeatureUtils.USE_UNIFORM_COLOR_KEY: + return new UniformSpotColorGenerator( displaySettings.getSpotUniformColor() ); + } case EDGES: @@ -267,7 +281,21 @@ public static final FeatureColorGenerator< DefaultWeightedEdge > createTrackColo switch ( displaySettings.getTrackColorByType() ) { case DEFAULT: - return new UniformTrackColorGenerator( displaySettings.getTrackUniformColor() ); + switch ( displaySettings.getTrackColorByFeature() ) + { + case FeatureUtils.USE_RANDOM_COLOR_KEY: + return new PerTrackFeatureColorGenerator( + model, + TrackIndexAnalyzer.TRACK_INDEX, + displaySettings.getMissingValueColor(), + displaySettings.getUndefinedValueColor(), + displaySettings.getColormap(), + displaySettings.getTrackMin(), + displaySettings.getTrackMax() ); + default: + case FeatureUtils.USE_UNIFORM_COLOR_KEY: + return new UniformTrackColorGenerator( displaySettings.getTrackUniformColor() ); + } case EDGES: diff --git a/src/main/java/fiji/plugin/trackmate/gui/components/FeatureDisplaySelector.java b/src/main/java/fiji/plugin/trackmate/gui/components/FeatureDisplaySelector.java index 2da41598c..b7cfc5086 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/components/FeatureDisplaySelector.java +++ b/src/main/java/fiji/plugin/trackmate/gui/components/FeatureDisplaySelector.java @@ -76,6 +76,7 @@ public class FeatureDisplaySelector private static final List< String > FEATURES_WITHOUT_MIN_MAX = Arrays.asList( new String[] { FeatureUtils.USE_UNIFORM_COLOR_KEY, + FeatureUtils.USE_RANDOM_COLOR_KEY, TrackIndexAnalyzer.TRACK_INDEX, ManualEdgeColorAnalyzer.FEATURE, ManualSpotColorAnalyzerFactory.FEATURE diff --git a/src/main/java/fiji/plugin/trackmate/visualization/GlasbeyLut.java b/src/main/java/fiji/plugin/trackmate/visualization/GlasbeyLut.java index 7a92df7e3..8ec78a1cf 100644 --- a/src/main/java/fiji/plugin/trackmate/visualization/GlasbeyLut.java +++ b/src/main/java/fiji/plugin/trackmate/visualization/GlasbeyLut.java @@ -26,7 +26,7 @@ public class GlasbeyLut { - private static final Color[] colors = new Color[] { + public static final Color[] colors = new Color[] { new Color( 255, 255, 255 ), new Color( 20, 20, 255 ), new Color( 255, 20, 20 ), diff --git a/src/main/java/fiji/plugin/trackmate/visualization/RandomSpotColorGenerator.java b/src/main/java/fiji/plugin/trackmate/visualization/RandomSpotColorGenerator.java new file mode 100644 index 000000000..8bec9b28e --- /dev/null +++ b/src/main/java/fiji/plugin/trackmate/visualization/RandomSpotColorGenerator.java @@ -0,0 +1,16 @@ +package fiji.plugin.trackmate.visualization; + +import java.awt.Color; + +import fiji.plugin.trackmate.Spot; + +public class RandomSpotColorGenerator implements FeatureColorGenerator< Spot > +{ + + @Override + public Color color( final Spot spot ) + { + final int i = spot.ID() % GlasbeyLut.colors.length; + return GlasbeyLut.colors[ i ]; + } +}