Пример #1
0
  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);
  }
Пример #2
0
  /**
   * 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();
    }
  }
Пример #3
0
  /**
   * Check the validity of the given settings map for the target {@link SpotDetector} set in this
   * provider. The validity check is strict: we check that all needed parameters are here and are of
   * the right class, and that there is no extra unwanted parameters.
   *
   * @return true if the settings map can be used with the target factory. If not, check {@link
   *     #getErrorMessage()}
   */
  public boolean checkSettingsValidity(final Map<String, Object> settings) {
    if (null == settings) {
      errorMessage = "Settings map is null.\n";
      return false;
    }

    final StringBuilder str = new StringBuilder();
    boolean ok = true;

    if (currentKey.equals(FastLAPTracker.TRACKER_KEY)
        || currentKey.equals(SimpleFastLAPTracker.TRACKER_KEY)) {

      ok = LAPUtils.checkSettingsValidity(settings, str);
      if (!ok) {
        errorMessage = str.toString();
      }
      return ok;

    } else if (currentKey.equals(NearestNeighborTracker.TRACKER_KEY)) {

      ok = NearestNeighborTracker.checkInput(settings, str);
      if (!ok) {
        errorMessage = str.toString();
      }
      return ok;

    } else if (currentKey.equals(ManualTracker.TRACKER_KEY)) {

      return true;

    } else {

      errorMessage = "Unknow detector factory key: " + currentKey + ".\n";
      return false;
    }
  }