public static void main(final String args[]) { final File file = new File(AppUtils.getBaseDirectory(TrackMate.class), "samples/FakeTracks.xml"); // 1 - Load test spots System.out.println("Opening file: " + file.getAbsolutePath()); final TmXmlReader reader = new TmXmlReader(file); final Model model = reader.getModel(); final Settings gs = new Settings(); reader.readSettings(gs, null, null, null, null, null); System.out.println("Spots: " + model.getSpots()); System.out.println("Found " + model.getTrackModel().nTracks(false) + " tracks in the file:"); System.out.println("Track features: "); System.out.println(); // 2 - Track the test spots final long start = System.currentTimeMillis(); final Map<String, Object> settings = new HashMap<String, Object>(); settings.put(KEY_LINKING_MAX_DISTANCE, 15d); final NearestNeighborTracker tracker = new NearestNeighborTracker(model.getSpots(), settings); tracker.setLogger(Logger.DEFAULT_LOGGER); if (!tracker.checkInput()) System.err.println("Error checking input: " + tracker.getErrorMessage()); if (!tracker.process()) System.err.println("Error in process: " + tracker.getErrorMessage()); final long end = System.currentTimeMillis(); model.setTracks(tracker.getResult(), true); // 3 - Print out results for testing System.out.println(); System.out.println(); System.out.println(); System.out.println("Found " + model.getTrackModel().nTracks(false) + " final tracks."); System.out.println("Whole tracking done in " + (end - start) + " ms."); System.out.println(); // 5 - Display tracks // Load Image ij.ImageJ.main(args); final ImagePlus imp = gs.imp; final TrackMateModelView sd2d = new HyperStackDisplayer(model, new SelectionModel(model), imp); sd2d.render(); sd2d.setDisplaySettings( TrackMateModelView.KEY_TRACK_DISPLAY_MODE, TrackMateModelView.TRACK_DISPLAY_MODE_WHOLE); }
/** * Links all the spots in the selection, in time-forward order. * * @param model the model to modify. * @param selectionModel the selection that contains the spots to link. */ public static void linkSpots(final Model model, final SelectionModel selectionModel) { /* * Configure tracker */ final TrackableObjectCollection<Spot> spots = new DefaultTOCollection<Spot>(selectionModel.getSpotSelection()); final Map<String, Object> settings = new HashMap<String, Object>(1); settings.put(KEY_LINKING_MAX_DISTANCE, Double.POSITIVE_INFINITY); final NearestNeighborTracker<Spot> tracker = new NearestNeighborTracker<Spot>(spots, settings); tracker.setNumThreads(1); /* * Execute tracking */ if (!tracker.checkInput() || !tracker.process()) { System.err.println("Problem while computing spot links: " + tracker.getErrorMessage()); return; } final SimpleWeightedGraph<Spot, DefaultWeightedEdge> graph = tracker.getResult(); /* * Copy found links in source model */ model.beginUpdate(); try { for (final DefaultWeightedEdge edge : graph.edgeSet()) { final Spot source = graph.getEdgeSource(edge); final Spot target = graph.getEdgeTarget(edge); model.addEdge(source, target, graph.getEdgeWeight(edge)); } } finally { model.endUpdate(); } }