Skip to content

Commit 2841903

Browse files
committed
Merge branch 'master' of github.com:fiji/TrackMate
2 parents 895d00a + df9d401 commit 2841903

13 files changed

Lines changed: 325 additions & 304 deletions

src/main/java/fiji/plugin/trackmate/LoadTrackMatePlugIn.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
import fiji.plugin.trackmate.gui.wizard.WizardSequence;
4040
import fiji.plugin.trackmate.gui.wizard.descriptors.ConfigureViewsDescriptor;
4141
import fiji.plugin.trackmate.gui.wizard.descriptors.LogPanelDescriptor2;
42-
import fiji.plugin.trackmate.gui.wizard.descriptors.SomeDialogDescriptor;
42+
import fiji.plugin.trackmate.gui.wizard.descriptors.StartDialogDescriptor;
4343
import fiji.plugin.trackmate.io.IOUtils;
44+
import fiji.plugin.trackmate.io.SettingsPersistence;
4445
import fiji.plugin.trackmate.io.TmXmlReader;
4546
import fiji.plugin.trackmate.util.TMUtils;
4647
import fiji.plugin.trackmate.visualization.TrackMateModelView;
@@ -70,22 +71,15 @@ public void run( final String filePath )
7071
*/
7172
GuiUtils.setSystemLookAndFeel();
7273

73-
final Logger logger = Logger.IJ_LOGGER; // logPanel.getLogger();
74-
File file = SomeDialogDescriptor.file;
74+
final Logger logger = Logger.IJ_LOGGER;
75+
File file;
7576
if ( null == filePath || filePath.length() == 0 )
7677
{
77-
78-
if ( null == file || file.length() == 0 )
79-
{
80-
final File folder = new File( System.getProperty( "user.dir" ) );
81-
final File parent = folder.getParentFile();
82-
final File parent2 = parent == null ? null : parent.getParentFile();
83-
file = new File( parent2 != null ? parent2 : parent != null ? parent : folder, "TrackMateData.xml" );
84-
}
85-
final File tmpFile = IOUtils.askForFileForLoading( file, "Load a TrackMate XML file", null, logger );
86-
if ( null == tmpFile )
78+
final Settings lastUsedSettings = SettingsPersistence.readLastUsedSettings( null, logger );
79+
file = TMUtils.proposeTrackMateSaveFile( lastUsedSettings, logger );
80+
file = IOUtils.askForFileForLoading( file, "Load a TrackMate XML file", null, logger );
81+
if ( null == file )
8782
return;
88-
file = tmpFile;
8983
}
9084
else
9185
{
@@ -230,7 +224,19 @@ public void run( final String filePath )
230224
+ logText
231225
+ "--------------------\n",
232226
Color.GRAY );
227+
233228
logger2.log( "File loaded on " + TMUtils.getCurrentTimeString() + '\n', Logger.BLUE_COLOR );
229+
final String welcomeMessage = TrackMate.PLUGIN_NAME_STR + " v" + TrackMate.PLUGIN_NAME_VERSION + '\n';
230+
// Log GUI processing start
231+
logger2.log( welcomeMessage, Logger.BLUE_COLOR );
232+
logger2.log( "Please note that TrackMate is available through Fiji, and is based on a publication. "
233+
+ "If you use it successfully for your research please be so kind to cite our work:\n" );
234+
logger2.log( StartDialogDescriptor.PUB1_TXT + "\n", Logger.GREEN_COLOR );
235+
logger2.log( StartDialogDescriptor.PUB1_URL + "\n", Logger.BLUE_COLOR );
236+
logger2.log( "and / or:\n" );
237+
logger2.log( "Tinevez, JY.; Perry, N. & Schindelin, J. et al. (2017), 'TrackMate: An open and extensible platform for single-particle tracking.', "
238+
+ "Methods 115: 80-90, PMID 27713081.\n", Logger.GREEN_COLOR );
239+
logger2.log( "https://www.sciencedirect.com/science/article/pii/S1046202316303346\n", Logger.BLUE_COLOR );
234240

235241
if ( !reader.isReadingOk() )
236242
{
@@ -277,7 +283,8 @@ public static void main( final String[] args )
277283
ImageJ.main( args );
278284
final LoadTrackMatePlugIn plugIn = new LoadTrackMatePlugIn();
279285
// plugIn.run( "samples/FakeTracks.xml" );
280-
plugIn.run( "samples/MAX_Merged.xml" );
281-
// plugIn.run( "" );
286+
// plugIn.run( "samples/MAX_Merged.xml" );
287+
// plugIn.run( "c:/Users/tinevez/Development/TrackMateWS/TrackMate-Cellpose/samples/R2_multiC.xml" );
288+
plugIn.run( null );
282289
}
283290
}

src/main/java/fiji/plugin/trackmate/TrackMateRunner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import fiji.plugin.trackmate.visualization.TrackMateModelView;
5454
import fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer;
5555
import fiji.util.SplitString;
56-
import ij.IJ;
5756
import ij.ImageJ;
5857
import ij.ImagePlus;
5958
import ij.Macro;

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

Lines changed: 126 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,26 @@
4949
import fiji.plugin.trackmate.io.IOUtils;
5050
import fiji.plugin.trackmate.util.TMUtils;
5151

52-
public class ExportTracksToXML extends AbstractTMAction {
52+
public class ExportTracksToXML extends AbstractTMAction
53+
{
5354

5455
public static final String NAME = "Export tracks to XML file";
5556

5657
public static final String KEY = "EXPORT_TRACKS_TO_XML_SIMPLE";
58+
5759
public static final String INFO_TEXT = "<html>" +
58-
"Export the tracks in the current model content to a XML " +
59-
"file in a simple format. " +
60-
"<p> " +
61-
"The file will have one element per track, and each track " +
62-
"contains several spot elements. These spots are " +
63-
"sorted by frame number, and have 4 numerical attributes: " +
64-
"the frame number this spot is in, and its X, Y, Z position in " +
65-
"physical units as specified in the image properties. " +
66-
"<p>" +
67-
"As such, this format <u>cannot</u> handle track merging and " +
68-
"splitting properly, and is suited only for non-branching tracks." +
69-
"</html>";
60+
"Export the tracks in the current model content to a XML " +
61+
"file in a simple format. " +
62+
"<p> " +
63+
"The file will have one element per track, and each track " +
64+
"contains several spot elements. These spots are " +
65+
"sorted by frame number, and have 4 numerical attributes: " +
66+
"the frame number this spot is in, and its X, Y, Z position in " +
67+
"physical units as specified in the image properties. " +
68+
"<p>" +
69+
"As such, this format <u>cannot</u> handle track merging and " +
70+
"splitting properly, and is suited only for non-branching tracks." +
71+
"</html>";
7072

7173
/**
7274
* Static utility that silently exports tracks in a simplified xml format,
@@ -84,125 +86,156 @@ public class ExportTracksToXML extends AbstractTMAction {
8486
* @throws IOException
8587
* if there is a problem writing the file.
8688
*/
87-
public static void export(final Model model, final Settings settings, final File file) throws FileNotFoundException, IOException {
88-
final Element root = marshall(model, settings, Logger.VOID_LOGGER);
89-
final Document document = new Document(root);
90-
final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
91-
outputter.output(document, new FileOutputStream(file));
89+
public static void export( final Model model, final Settings settings, final File file ) throws FileNotFoundException, IOException
90+
{
91+
final Element root = marshall( model, settings, Logger.VOID_LOGGER );
92+
final Document document = new Document( root );
93+
final XMLOutputter outputter = new XMLOutputter( Format.getPrettyFormat() );
94+
outputter.output( document, new FileOutputStream( file ) );
9295
}
9396

9497
@Override
9598
public void execute( final TrackMate trackmate, final SelectionModel selectionModel, final DisplaySettings displaySettings, final Frame parent )
9699
{
97-
logger.log("Exporting tracks to simple XML format.\n");
100+
logger.log( "Exporting tracks to simple XML format.\n" );
98101
final Model model = trackmate.getModel();
99-
final int ntracks = model.getTrackModel().nTracks(true);
100-
if (ntracks == 0) {
101-
logger.log("No visible track found. Aborting.\n");
102+
final int ntracks = model.getTrackModel().nTracks( true );
103+
if ( ntracks == 0 )
104+
{
105+
logger.log( "No visible track found. Aborting.\n" );
102106
return;
103107
}
104108

105-
logger.log(" Preparing XML data.\n");
106-
final Element root = marshall(model, trackmate.getSettings(), logger);
109+
logger.log( " Preparing XML data.\n" );
110+
final Element root = marshall( model, trackmate.getSettings(), logger );
107111

108112
File folder;
109-
try {
110-
folder = new File(trackmate.getSettings().imp.getOriginalFileInfo().directory);
111-
} catch (final NullPointerException npe) {
112-
folder = new File(System.getProperty("user.dir")).getParentFile().getParentFile();
113+
try
114+
{
115+
folder = new File( trackmate.getSettings().imp.getOriginalFileInfo().directory );
116+
}
117+
catch ( final NullPointerException npe )
118+
{
119+
folder = new File( System.getProperty( "user.dir" ) ).getParentFile().getParentFile();
113120
}
114121

115122
File file;
116-
try {
123+
try
124+
{
117125
String filename = trackmate.getSettings().imageFileName;
118-
final int dot = filename.indexOf(".");
119-
filename = dot < 0 ? filename : filename.substring(0, dot);
120-
file = new File(folder.getPath() + File.separator + filename +"_Tracks.xml");
121-
} catch (final NullPointerException npe) {
122-
file = new File(folder.getPath() + File.separator + "Tracks.xml");
126+
final int dot = filename.indexOf( "." );
127+
filename = dot < 0 ? filename : filename.substring( 0, dot );
128+
file = new File( folder.getPath() + File.separator + filename + "_Tracks.xml" );
129+
}
130+
catch ( final NullPointerException npe )
131+
{
132+
file = new File( folder.getPath() + File.separator + "Tracks.xml" );
123133
}
124-
file = IOUtils.askForFileForSaving( file, parent, logger );
125-
if (null == file) {
134+
file = IOUtils.askForFileForSaving( file, parent );
135+
if ( null == file )
136+
{
137+
logger.log( "Exporting to simple XML aborted.\n" );
126138
return;
127139
}
128140

129-
logger.log(" Writing to file.\n");
130-
final Document document = new Document(root);
131-
final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
132-
try {
133-
outputter.output(document, new FileOutputStream(file));
134-
} catch (final FileNotFoundException e) {
135-
logger.error("Trouble writing to "+file+":\n" + e.getMessage());
136-
} catch (final IOException e) {
137-
logger.error("Trouble writing to "+file+":\n" + e.getMessage());
141+
logger.log( " Writing to file.\n" );
142+
final Document document = new Document( root );
143+
final XMLOutputter outputter = new XMLOutputter( Format.getPrettyFormat() );
144+
try
145+
{
146+
outputter.output( document, new FileOutputStream( file ) );
147+
}
148+
catch ( final FileNotFoundException e )
149+
{
150+
logger.error( "Trouble writing to " + file + ":\n" + e.getMessage() );
151+
}
152+
catch ( final IOException e )
153+
{
154+
logger.error( "Trouble writing to " + file + ":\n" + e.getMessage() );
138155
}
139-
logger.log("Done.\n");
156+
logger.log( "Done.\n" );
140157
}
141158

142-
private static Element marshall(final Model model, final Settings settings, final Logger logger) {
143-
logger.setStatus("Marshalling...");
144-
final Element content = new Element(CONTENT_KEY);
159+
private static Element marshall( final Model model, final Settings settings, final Logger logger )
160+
{
161+
logger.setStatus( "Marshalling..." );
162+
final Element content = new Element( CONTENT_KEY );
145163

146-
content.setAttribute(NTRACKS_ATT, ""+model.getTrackModel().nTracks(true));
147-
content.setAttribute(PHYSUNIT_ATT, model.getSpaceUnits());
148-
content.setAttribute(FRAMEINTERVAL_ATT, ""+settings.dt);
149-
content.setAttribute(FRAMEINTERVALUNIT_ATT, ""+model.getTimeUnits());
150-
content.setAttribute(DATE_ATT, TMUtils.getCurrentTimeString());
151-
content.setAttribute(FROM_ATT, TrackMate.PLUGIN_NAME_STR + " v" + TrackMate.PLUGIN_NAME_VERSION);
164+
content.setAttribute( NTRACKS_ATT, "" + model.getTrackModel().nTracks( true ) );
165+
content.setAttribute( PHYSUNIT_ATT, model.getSpaceUnits() );
166+
content.setAttribute( FRAMEINTERVAL_ATT, "" + settings.dt );
167+
content.setAttribute( FRAMEINTERVALUNIT_ATT, "" + model.getTimeUnits() );
168+
content.setAttribute( DATE_ATT, TMUtils.getCurrentTimeString() );
169+
content.setAttribute( FROM_ATT, TrackMate.PLUGIN_NAME_STR + " v" + TrackMate.PLUGIN_NAME_VERSION );
152170

153-
final Set<Integer> trackIDs = model.getTrackModel().trackIDs(true);
171+
final Set< Integer > trackIDs = model.getTrackModel().trackIDs( true );
154172
int i = 0;
155-
for (final Integer trackID : trackIDs) {
173+
for ( final Integer trackID : trackIDs )
174+
{
156175

157-
final Set<Spot> track = model.getTrackModel().trackSpots(trackID);
176+
final Set< Spot > track = model.getTrackModel().trackSpots( trackID );
158177

159-
final Element trackElement = new Element(TRACK_KEY);
160-
trackElement.setAttribute(NSPOTS_ATT, ""+track.size());
178+
final Element trackElement = new Element( TRACK_KEY );
179+
trackElement.setAttribute( NSPOTS_ATT, "" + track.size() );
161180

162181
// Sort them by time
163-
final TreeSet<Spot> sortedTrack = new TreeSet<>(Spot.timeComparator);
164-
sortedTrack.addAll(track);
165-
166-
for (final Spot spot : sortedTrack) {
167-
final int frame = spot.getFeature(Spot.FRAME).intValue();
168-
final double x = spot.getFeature(Spot.POSITION_X);
169-
final double y = spot.getFeature(Spot.POSITION_Y);
170-
final double z = spot.getFeature(Spot.POSITION_Z);
171-
172-
final Element spotElement = new Element(SPOT_KEY);
173-
spotElement.setAttribute(T_ATT, ""+frame);
174-
spotElement.setAttribute(X_ATT, ""+x);
175-
spotElement.setAttribute(Y_ATT, ""+y);
176-
spotElement.setAttribute(Z_ATT, ""+z);
177-
trackElement.addContent(spotElement);
182+
final TreeSet< Spot > sortedTrack = new TreeSet<>( Spot.timeComparator );
183+
sortedTrack.addAll( track );
184+
185+
for ( final Spot spot : sortedTrack )
186+
{
187+
final int frame = spot.getFeature( Spot.FRAME ).intValue();
188+
final double x = spot.getFeature( Spot.POSITION_X );
189+
final double y = spot.getFeature( Spot.POSITION_Y );
190+
final double z = spot.getFeature( Spot.POSITION_Z );
191+
192+
final Element spotElement = new Element( SPOT_KEY );
193+
spotElement.setAttribute( T_ATT, "" + frame );
194+
spotElement.setAttribute( X_ATT, "" + x );
195+
spotElement.setAttribute( Y_ATT, "" + y );
196+
spotElement.setAttribute( Z_ATT, "" + z );
197+
trackElement.addContent( spotElement );
178198
}
179-
content.addContent(trackElement);
180-
logger.setProgress(i++ / (0d + model.getTrackModel().nTracks(true)));
199+
content.addContent( trackElement );
200+
logger.setProgress( i++ / ( 0d + model.getTrackModel().nTracks( true ) ) );
181201
}
182202

183-
logger.setStatus("");
184-
logger.setProgress(1);
203+
logger.setStatus( "" );
204+
logger.setProgress( 1 );
185205
return content;
186206
}
187207

188208
/*
189209
* XML KEYS
190210
*/
191211

192-
private static final String CONTENT_KEY = "Tracks";
193-
private static final String DATE_ATT = "generationDateTime";
194-
private static final String PHYSUNIT_ATT = "spaceUnits";
195-
private static final String FRAMEINTERVAL_ATT = "frameInterval";
196-
private static final String FRAMEINTERVALUNIT_ATT = "timeUnits";
197-
private static final String FROM_ATT = "from";
198-
private static final String NTRACKS_ATT = "nTracks";
199-
private static final String NSPOTS_ATT = "nSpots";
200-
private static final String TRACK_KEY = "particle";
201-
private static final String SPOT_KEY = "detection";
202-
private static final String X_ATT = "x";
203-
private static final String Y_ATT = "y";
204-
private static final String Z_ATT = "z";
205-
private static final String T_ATT = "t";
212+
private static final String CONTENT_KEY = "Tracks";
213+
214+
private static final String DATE_ATT = "generationDateTime";
215+
216+
private static final String PHYSUNIT_ATT = "spaceUnits";
217+
218+
private static final String FRAMEINTERVAL_ATT = "frameInterval";
219+
220+
private static final String FRAMEINTERVALUNIT_ATT = "timeUnits";
221+
222+
private static final String FROM_ATT = "from";
223+
224+
private static final String NTRACKS_ATT = "nTracks";
225+
226+
private static final String NSPOTS_ATT = "nSpots";
227+
228+
private static final String TRACK_KEY = "particle";
229+
230+
private static final String SPOT_KEY = "detection";
231+
232+
private static final String X_ATT = "x";
233+
234+
private static final String Y_ATT = "y";
235+
236+
private static final String Z_ATT = "z";
237+
238+
private static final String T_ATT = "t";
206239

207240
@Plugin( type = TrackMateActionFactory.class )
208241
public static class Factory implements TrackMateActionFactory

0 commit comments

Comments
 (0)