Skip to content

Commit 97cfa79

Browse files
authored
Merge pull request #146 from fiji/imagejan-add-viridis-colormap
Add several colormaps and an option system to pick one.
2 parents db3cb5f + 6349bca commit 97cfa79

35 files changed

Lines changed: 5175 additions & 460 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package fiji.plugin.trackmate;
2+
3+
import org.scijava.Context;
4+
import org.scijava.options.OptionsService;
5+
6+
import ij.IJ;
7+
8+
public class TrackMateOptionUtils
9+
{
10+
private TrackMateOptionUtils()
11+
{}
12+
13+
public static TrackMateOptions getOptions()
14+
{
15+
final Context ctx = ( Context ) IJ.runPlugIn( "org.scijava.Context", "" );
16+
return ctx.getService( OptionsService.class ).getOptions( TrackMateOptions.class );
17+
}
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fiji.plugin.trackmate;
2+
3+
import org.jfree.chart.renderer.InterpolatePaintScale;
4+
import org.scijava.menu.MenuConstants;
5+
import org.scijava.options.OptionsPlugin;
6+
import org.scijava.plugin.Menu;
7+
import org.scijava.plugin.Parameter;
8+
import org.scijava.plugin.Plugin;
9+
10+
@Plugin( type = OptionsPlugin.class,
11+
menu = {
12+
@Menu(
13+
label = MenuConstants.EDIT_LABEL,
14+
weight = MenuConstants.EDIT_WEIGHT,
15+
mnemonic = MenuConstants.EDIT_MNEMONIC ),
16+
@Menu(
17+
label = "Options" ),
18+
@Menu(
19+
label = "TrackMate..." ) } )
20+
public class TrackMateOptions extends OptionsPlugin
21+
{
22+
23+
@Parameter(
24+
label = "Look-up table for scales",
25+
choices = { "Turbo", "Jet", "Viridis", "Algae", "Amp", "Balance", "Curl", "Deep", "Delta", "Dense", "Gray", "Haline", "Ice", "Matter", "Oxy", "Phase", "Solar", "Speed", "Tempo", "Thermal", "Turbid" } )
26+
private String lutChoice = "Turbo";
27+
28+
public InterpolatePaintScale getPaintScale()
29+
{
30+
return InterpolatePaintScale.getAvailableLUTs().get( lutChoice );
31+
}
32+
}

src/main/java/fiji/plugin/trackmate/action/CopyOverlayAction.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fiji.plugin.trackmate.action;
22

3-
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_COLOR_MAP;
43
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_HIGHLIGHT_COLOR;
54
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_SPOT_COLOR;
65
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_TRACK_DISPLAY_DEPTH;
@@ -32,6 +31,7 @@
3231

3332
import fiji.plugin.trackmate.SelectionModel;
3433
import fiji.plugin.trackmate.TrackMate;
34+
import fiji.plugin.trackmate.TrackMateOptionUtils;
3535
import fiji.plugin.trackmate.features.edges.EdgeVelocityAnalyzer;
3636
import fiji.plugin.trackmate.features.track.TrackIndexAnalyzer;
3737
import fiji.plugin.trackmate.gui.DisplaySettingsEvent;
@@ -63,7 +63,13 @@ public class CopyOverlayAction extends AbstractTMAction
6363

6464
public static final String KEY = "COPY_OVERLAY";
6565

66-
public static final String INFO_TEXT = "<html>" + "This action copies the overlay (spots and tracks) to a new existing ImageJ window <br> " + "or to a new 3D viewer window. This can be useful to have the tracks and spots <br> " + "displayed on a modified image. " + "<p>" + "The new view will be independent, and will have its own control panel.<br> " + "</html>";
66+
public static final String INFO_TEXT = "<html>"
67+
+ "This action copies the overlay (spots and tracks) to a new existing ImageJ window <br> "
68+
+ "or to a new 3D viewer window. This can be useful to have the tracks and spots <br> "
69+
+ "displayed on a modified image. "
70+
+ "<p>"
71+
+ "The new view will be independent, and will have its own control panel.<br> "
72+
+ "</html>";
6773

6874
/**
6975
* The {@link ConfigureViewsPanel} created as a new GUI.
@@ -102,8 +108,6 @@ public void actionPerformed( final ActionEvent e )
102108
new Thread( "TrackMate copying thread" )
103109
{
104110

105-
106-
107111
@Override
108112
public void run()
109113
{
@@ -159,7 +163,7 @@ public void run()
159163
displaySettings.put( KEY_TRACK_DISPLAY_MODE, DEFAULT_TRACK_DISPLAY_MODE );
160164
displaySettings.put( KEY_TRACK_DISPLAY_DEPTH, DEFAULT_TRACK_DISPLAY_DEPTH );
161165
displaySettings.put( KEY_TRACK_COLORING, trackColorGenerator );
162-
displaySettings.put( KEY_COLORMAP, DEFAULT_COLOR_MAP );
166+
displaySettings.put( KEY_COLORMAP, TrackMateOptionUtils.getOptions().getPaintScale() );
163167
guimodel.setDisplaySettings( displaySettings );
164168

165169
guimodel.addView( newDisplayer );
Lines changed: 92 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package fiji.plugin.trackmate.features;
22

33
import static fiji.plugin.trackmate.visualization.trackscheme.TrackScheme.TRACK_SCHEME_ICON;
4-
import fiji.plugin.trackmate.Model;
5-
import fiji.plugin.trackmate.Spot;
6-
import fiji.plugin.trackmate.TrackModel;
7-
import fiji.plugin.trackmate.util.ExportableChartPanel;
84

95
import java.awt.Shape;
106
import java.awt.geom.Ellipse2D;
@@ -26,21 +22,32 @@
2622
import org.jfree.chart.renderer.InterpolatePaintScale;
2723
import org.jgrapht.graph.DefaultWeightedEdge;
2824

29-
public abstract class AbstractFeatureGrapher {
30-
31-
protected static final Shape DEFAULT_SHAPE = new Ellipse2D.Double(-3, -3, 6, 6);
25+
import fiji.plugin.trackmate.Model;
26+
import fiji.plugin.trackmate.Spot;
27+
import fiji.plugin.trackmate.TrackMateOptionUtils;
28+
import fiji.plugin.trackmate.TrackModel;
29+
import fiji.plugin.trackmate.util.ExportableChartPanel;
30+
31+
public abstract class AbstractFeatureGrapher
32+
{
33+
34+
protected static final Shape DEFAULT_SHAPE = new Ellipse2D.Double( -3, -3, 6, 6 );
35+
36+
protected final InterpolatePaintScale paints = TrackMateOptionUtils.getOptions().getPaintScale();
3237

33-
protected final InterpolatePaintScale paints = InterpolatePaintScale.Jet;
3438
protected final String xFeature;
35-
protected final Set<String> yFeatures;
39+
40+
protected final Set< String > yFeatures;
41+
3642
protected final Model model;
3743

38-
public AbstractFeatureGrapher(final String xFeature, final Set<String> yFeatures,final Model model) {
44+
public AbstractFeatureGrapher( final String xFeature, final Set< String > yFeatures, final Model model )
45+
{
3946
this.xFeature = xFeature;
4047
this.yFeatures = yFeatures;
4148
this.model = model;
4249
}
43-
50+
4451
/**
4552
* Draw and render the graph.
4653
*/
@@ -49,99 +56,111 @@ public AbstractFeatureGrapher(final String xFeature, final Set<String> yFeatures
4956
/*
5057
* UTILS
5158
*/
52-
59+
5360
/**
54-
* Render and display a frame containing all the char panels, grouped by dimension
61+
* Render and display a frame containing all the char panels, grouped by
62+
* dimension
5563
*/
56-
protected final void renderCharts(final List<ExportableChartPanel> chartPanels) {
64+
protected final void renderCharts( final List< ExportableChartPanel > chartPanels )
65+
{
5766
// The Panel
58-
JPanel panel = new JPanel();
59-
BoxLayout panelLayout = new BoxLayout(panel, BoxLayout.Y_AXIS);
60-
panel.setLayout(panelLayout);
61-
for(ExportableChartPanel chartPanel : chartPanels) {
62-
panel.add(chartPanel);
63-
panel.add(Box.createVerticalStrut(5));
67+
final JPanel panel = new JPanel();
68+
final BoxLayout panelLayout = new BoxLayout( panel, BoxLayout.Y_AXIS );
69+
panel.setLayout( panelLayout );
70+
for ( final ExportableChartPanel chartPanel : chartPanels )
71+
{
72+
panel.add( chartPanel );
73+
panel.add( Box.createVerticalStrut( 5 ) );
6474
}
65-
75+
6676
// Scroll pane
67-
JScrollPane scrollPane = new JScrollPane();
68-
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
69-
scrollPane.setViewportView(panel);
77+
final JScrollPane scrollPane = new JScrollPane();
78+
scrollPane.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
79+
scrollPane.setViewportView( panel );
7080

7181
// The frame
72-
JFrame frame = new JFrame();
73-
frame.setTitle("Feature plot for Track scheme");
74-
frame.setIconImage(TRACK_SCHEME_ICON.getImage());
75-
frame.getContentPane().add(scrollPane);
82+
final JFrame frame = new JFrame();
83+
frame.setTitle( "Feature plot for Track scheme" );
84+
frame.setIconImage( TRACK_SCHEME_ICON.getImage() );
85+
frame.getContentPane().add( scrollPane );
7686
frame.validate();
77-
frame.setSize(new java.awt.Dimension(520, 320));
78-
frame.setVisible(true);
87+
frame.setSize( new java.awt.Dimension( 520, 320 ) );
88+
frame.setVisible( true );
7989
}
8090

81-
8291
/**
83-
* @return the unique mapped values in the given map, for the collection of keys given.
92+
* @return the unique mapped values in the given map, for the collection of
93+
* keys given.
8494
*/
85-
protected final <K, V> Set<V> getUniqueValues(Iterable<K> keys, Map<K,V> map) {
86-
HashSet<V> mapping = new HashSet<>();
87-
for (K key : keys) {
88-
mapping.add(map.get(key));
89-
}
95+
protected final < K, V > Set< V > getUniqueValues( final Iterable< K > keys, final Map< K, V > map )
96+
{
97+
final HashSet< V > mapping = new HashSet<>();
98+
for ( final K key : keys )
99+
mapping.add( map.get( key ) );
100+
90101
return mapping;
91102
}
92103

93104
/**
94-
* @return the collection of keys amongst the given ones,
95-
* that point to the target value in the given map.
96-
* @param targetValue the common value to search
97-
* @param keys the keys to inspect
98-
* @param map the map to search in
105+
* @return the collection of keys amongst the given ones, that point to the
106+
* target value in the given map.
107+
* @param targetValue
108+
* the common value to search
109+
* @param keys
110+
* the keys to inspect
111+
* @param map
112+
* the map to search in
99113
*/
100-
protected final <K, V> List<K> getCommonKeys(final V targetValue, final Iterable<K> keys, final Map<K,V> map) {
101-
ArrayList<K> foundKeys = new ArrayList<>();
102-
for (K key : keys) {
103-
if (map.get(key).equals(targetValue)) {
104-
foundKeys.add(key);
105-
}
114+
protected final < K, V > List< K > getCommonKeys( final V targetValue, final Iterable< K > keys, final Map< K, V > map )
115+
{
116+
final ArrayList< K > foundKeys = new ArrayList<>();
117+
for ( final K key : keys )
118+
{
119+
if ( map.get( key ).equals( targetValue ) )
120+
foundKeys.add( key );
121+
106122
}
107123
return foundKeys;
108124
}
109-
125+
110126
/**
111127
* @return a suitable plot title built from the given target features
112128
*/
113-
114-
protected final String buildPlotTitle(final Iterable<String> lYFeatures, final Map<String, String> featureNames) {
115-
StringBuilder sb = new StringBuilder("Plot of ");
116-
Iterator<String> it = lYFeatures.iterator();
117-
sb.append(featureNames.get(it.next()) );
118-
while(it.hasNext()) {
119-
sb.append(", ");
120-
sb.append(featureNames.get(it.next()));
129+
130+
protected final String buildPlotTitle( final Iterable< String > lYFeatures, final Map< String, String > featureNames )
131+
{
132+
final StringBuilder sb = new StringBuilder( "Plot of " );
133+
final Iterator< String > it = lYFeatures.iterator();
134+
sb.append( featureNames.get( it.next() ) );
135+
while ( it.hasNext() )
136+
{
137+
sb.append( ", " );
138+
sb.append( featureNames.get( it.next() ) );
121139
}
122-
sb.append(" vs ");
123-
sb.append(featureNames.get(xFeature));
124-
sb.append(".");
140+
sb.append( " vs " );
141+
sb.append( featureNames.get( xFeature ) );
142+
sb.append( "." );
125143
return sb.toString();
126144
}
127145

128146
/**
129-
* @return the list of links that have their source and target in the given spot list.
147+
* @return the list of links that have their source and target in the given
148+
* spot list.
130149
*/
131-
protected final List<DefaultWeightedEdge> getInsideEdges(final Collection<Spot> spots) {
132-
int nspots = spots.size();
133-
ArrayList<DefaultWeightedEdge> edges = new ArrayList<>(nspots);
134-
TrackModel trackModel = model.getTrackModel();
135-
for (DefaultWeightedEdge edge : trackModel.edgeSet()) {
136-
Spot source = trackModel.getEdgeSource(edge);
137-
Spot target = trackModel.getEdgeTarget(edge);
138-
if (spots.contains(source) && spots.contains(target)) {
139-
edges.add(edge);
140-
}
150+
protected final List< DefaultWeightedEdge > getInsideEdges( final Collection< Spot > spots )
151+
{
152+
final int nspots = spots.size();
153+
final ArrayList< DefaultWeightedEdge > edges = new ArrayList<>( nspots );
154+
final TrackModel trackModel = model.getTrackModel();
155+
for ( final DefaultWeightedEdge edge : trackModel.edgeSet() )
156+
{
157+
final Spot source = trackModel.getEdgeSource( edge );
158+
final Spot target = trackModel.getEdgeTarget( edge );
159+
if ( spots.contains( source ) && spots.contains( target ) )
160+
edges.add( edge );
161+
141162
}
142163
return edges;
143164
}
144-
145-
146165

147166
}

src/main/java/fiji/plugin/trackmate/gui/TrackMateGUIController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fiji.plugin.trackmate.gui;
22

3-
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_COLOR_MAP;
43
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_HIGHLIGHT_COLOR;
54
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_SPOT_COLOR;
65
import static fiji.plugin.trackmate.visualization.TrackMateModelView.DEFAULT_TRACK_DISPLAY_DEPTH;
@@ -38,6 +37,7 @@
3837
import fiji.plugin.trackmate.SelectionModel;
3938
import fiji.plugin.trackmate.Spot;
4039
import fiji.plugin.trackmate.TrackMate;
40+
import fiji.plugin.trackmate.TrackMateOptionUtils;
4141
import fiji.plugin.trackmate.action.AbstractTMAction;
4242
import fiji.plugin.trackmate.action.ExportAllSpotsStatsAction;
4343
import fiji.plugin.trackmate.action.ExportStatsToIJAction;
@@ -986,7 +986,7 @@ protected Map< String, Object > createDisplaySettings( final Model model )
986986
displaySettings.put( KEY_TRACK_DISPLAY_MODE, DEFAULT_TRACK_DISPLAY_MODE );
987987
displaySettings.put( KEY_TRACK_DISPLAY_DEPTH, DEFAULT_TRACK_DISPLAY_DEPTH );
988988
displaySettings.put( KEY_TRACK_COLORING, trackColorGenerator );
989-
displaySettings.put( KEY_COLORMAP, DEFAULT_COLOR_MAP );
989+
displaySettings.put( KEY_COLORMAP, TrackMateOptionUtils.getOptions().getPaintScale() );
990990
return displaySettings;
991991
}
992992

src/main/java/fiji/plugin/trackmate/gui/panels/components/ColorByFeatureGUIPanel.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
import fiji.plugin.trackmate.Model;
3030
import fiji.plugin.trackmate.SpotCollection;
31+
import fiji.plugin.trackmate.TrackMateOptionUtils;
3132
import fiji.plugin.trackmate.features.manual.ManualEdgeColorAnalyzer;
3233
import fiji.plugin.trackmate.features.manual.ManualSpotColorAnalyzerFactory;
34+
import fiji.plugin.trackmate.gui.GuiUtils;
3335
import fiji.plugin.trackmate.gui.panels.ActionListenablePanel;
3436
import fiji.plugin.trackmate.visualization.MinMaxAdjustable;
3537

@@ -89,7 +91,7 @@ public String toString()
8991

9092
private JComponent canvasColor;
9193

92-
protected InterpolatePaintScale colorMap = InterpolatePaintScale.Jet;
94+
protected InterpolatePaintScale colorMap = TrackMateOptionUtils.getOptions().getPaintScale();
9395

9496
protected final Model model;
9597

@@ -286,18 +288,23 @@ private void repaintColorCanvas( final Graphics g )
286288
final int minStrWidth = fm.stringWidth( minStr );
287289
final int maxStrWidth = fm.stringWidth( maxStr );
288290

291+
g.setColor( GuiUtils.textColorForBackground( colorMap.getPaint( 0. ) ) );
289292
g.drawString( dataMinStr, 1, height / 2 + fm.getHeight() / 2 );
293+
294+
g.setColor( GuiUtils.textColorForBackground( colorMap.getPaint( 1. ) ) );
290295
g.drawString( dataMaxStr, width - dataMaxStrWidth - 1, height / 2 + fm.getHeight() / 2 );
291296

292297
final int iMin = ( int ) ( ( width - 1 ) * ( min - dataMin ) / ( dataMax - dataMin ) );
293298
final int iMax = ( int ) ( ( width - 1 ) * ( max - dataMin ) / ( dataMax - dataMin ) );
294299

295300
if ( ( iMin - minStrWidth ) > dataMinStrWidth + 2 && iMin < ( width - dataMaxStrWidth - 2 ) )
296301
{
302+
g.setColor( GuiUtils.textColorForBackground( colorMap.getPaint( 0. ) ) );
297303
g.drawString( minStr, iMin - minStrWidth, height / 2 );
298304
}
299305
if ( ( iMax + maxStrWidth ) < ( width - dataMaxStrWidth - 2 ) && iMax > dataMinStrWidth + 2 )
300306
{
307+
g.setColor( GuiUtils.textColorForBackground( colorMap.getPaint( 1. ) ) );
301308
g.drawString( maxStr, iMax, height / 2 );
302309
}
303310

0 commit comments

Comments
 (0)