Esempio n. 1
0
 public void run(String arg) {
   ImageJ ij = IJ.getInstance();
   ij.setDropTarget(null);
   new DropTarget(ij, this);
   new DropTarget(Toolbar.getInstance(), this);
   new DropTarget(ij.getStatusBar(), this);
 }
Esempio n. 2
0
 private static Frame getParentFrame() {
   Frame parent =
       WindowManager.getCurrentImage() != null
           ? (Frame) WindowManager.getCurrentImage().getWindow()
           : IJ.getInstance() != null ? IJ.getInstance() : new Frame();
   if (IJ.isMacOSX() && IJ.isJava18()) {
     ImageJ ij = IJ.getInstance();
     if (ij != null && ij.isActive()) parent = ij;
     else parent = null;
   }
   return parent;
 }
 public void runMacro(String name, Editor editor) {
   if (anonymousName != null && name.equals(anonymousName)) {
     ImageJ.setCommandName(name);
     new MacroRunner(pgm, 0, anonymousName, editor);
     return;
   }
   for (int i = 0; i < nMacros; i++)
     if (name.equals(macroNames[i])) {
       ImageJ.setCommandName(name);
       new MacroRunner(pgm, macroStarts[i], name, editor);
       return;
     }
 }
Esempio n. 4
0
    /** Remove both ours and the backed up event handlers. */
    final void clearGui() {
      for (final KeyListener l : canvasKeyListeners) canvas.removeKeyListener(l);
      for (final KeyListener l : windowKeyListeners) window.removeKeyListener(l);
      for (final KeyListener l : ijKeyListeners) ij.removeKeyListener(l);
      for (final MouseListener l : canvasMouseListeners) canvas.removeMouseListener(l);
      for (final MouseMotionListener l : canvasMouseMotionListeners)
        canvas.removeMouseMotionListener(l);
      for (final MouseWheelListener l : windowMouseWheelListeners)
        window.removeMouseWheelListener(l);

      canvas.removeKeyListener(Panorama_View.this);
      window.removeKeyListener(Panorama_View.this);
      ij.removeKeyListener(Panorama_View.this);
      canvas.removeMouseListener(Panorama_View.this);
      canvas.removeMouseMotionListener(Panorama_View.this);
      window.removeMouseWheelListener(Panorama_View.this);
    }
Esempio n. 5
0
  private void progress() {

    if (display()) {
      final ImageJ ij = IJ.getInstance();
      if (ij != null) { // To avoid exceptions in ImageJ batch mode
        final ProgressBar pb = ij.getProgressBar();
        if (pb != null) {
          final double lo = min();
          final double hi = max();
          pb.show(lo + percent * (hi - lo));
          if (enforce()) {
            final Graphics gx = pb.getGraphics();
            if (gx != null) pb.paint(gx); // Enforces a refresh also when called from event stack
          }
        }
      }
    }
  }
Esempio n. 6
0
 /** Restore the previously active Event handlers. */
 final void restoreGui() {
   clearGui();
   for (final KeyListener l : canvasKeyListeners) canvas.addKeyListener(l);
   for (final KeyListener l : windowKeyListeners) window.addKeyListener(l);
   for (final KeyListener l : ijKeyListeners) ij.addKeyListener(l);
   for (final MouseListener l : canvasMouseListeners) canvas.addMouseListener(l);
   for (final MouseMotionListener l : canvasMouseMotionListeners)
     canvas.addMouseMotionListener(l);
   for (final MouseWheelListener l : windowMouseWheelListeners) window.addMouseWheelListener(l);
 }
Esempio n. 7
0
 /** Creates a table mapping legacy ImageJ command labels to menu paths. */
 private Map<String, MenuPath> parseMenus(final ij.ImageJ ij) {
   final Map<String, MenuPath> menuTable = new HashMap<String, MenuPath>();
   if (ij == null) return menuTable;
   final MenuBar menubar = ij.getMenuBar();
   final int menuCount = menubar.getMenuCount();
   for (int i = 0; i < menuCount; i++) {
     final Menu menu = menubar.getMenu(i);
     parseMenu(menu, i, new MenuPath(), menuTable);
   }
   return menuTable;
 }
 public PlugInDialog(String title) {
   super(IJ.isMacOSX() ? IJ.getInstance() : IJ.isJava16() ? null : new Frame(), title);
   enableEvents(AWTEvent.WINDOW_EVENT_MASK);
   this.title = title;
   ImageJ ij = IJ.getInstance();
   if (IJ.isMacOSX() && ij != null) {
     ij.toFront(); // needed for keyboard shortcuts to work
     IJ.wait(250);
   }
   addWindowListener(this);
   addFocusListener(this);
   if (IJ.isLinux()) setBackground(ImageJ.backgroundColor);
   if (ij != null && !IJ.isMacOSX() && IJ.isJava16()) {
     Image img = ij.getIconImage();
     if (img != null)
       try {
         setIconImage(img);
       } catch (Exception e) {
       }
   }
 }
Esempio n. 9
0
    /** Add new event handlers. */
    final void takeOverGui() {
      canvas.addKeyListener(Panorama_View.this);
      window.addKeyListener(Panorama_View.this);

      canvas.addMouseMotionListener(Panorama_View.this);

      canvas.addMouseListener(Panorama_View.this);

      ij.addKeyListener(Panorama_View.this);

      window.addMouseWheelListener(Panorama_View.this);
    }
 public void actionPerformed(ActionEvent evt) {
   String cmd = evt.getActionCommand();
   ImageJ.setCommandName(cmd);
   MenuItem item = (MenuItem) evt.getSource();
   MenuContainer parent = item.getParent();
   if (parent instanceof PopupMenu) {
     for (int i = 0; i < nMacros; i++) {
       if (macroNames[i].equals("Popup Menu")) {
         new MacroRunner(pgm, macroStarts[i], "Popup Menu", cmd);
         return;
       }
     }
   }
   runMacro(cmd);
 }
Esempio n. 11
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);
  }
Esempio n. 12
0
 public static void main(String[] args) {
   ij.ImageJ.main(args);
   IJ.open("/Users/tinevez/Desktop/Data/FakeTracks.tif");
   TrackMate_ model = new TrackMate_();
   model.run(null);
 }
Esempio n. 13
0
  public static void main(final String[] args) {

    // TEST 2D case

    // Parameters
    final int size_x = 200;
    final int size_y = 200;

    final long a = 10;
    final long b = 5;
    final double phi_r = Math.toRadians(30);

    final long max_radius = Math.max(a, b);
    final double[] calibration = new double[] {1, 1};

    // Create blank image
    final Img<UnsignedByteType> img =
        new ArrayImgFactory<UnsignedByteType>()
            .create(new int[] {200, 200}, new UnsignedByteType());
    final ImgPlus<UnsignedByteType> imgplus = new ImgPlus<UnsignedByteType>(img);
    for (int d = 0; d < imgplus.numDimensions(); d++) {
      imgplus.setAxis(new DefaultLinearAxis(imgplus.axis(d).type(), calibration[d]), d);
    }
    final byte on = (byte) 255;

    // Create an ellipse
    long start = System.currentTimeMillis();
    System.out.println(String.format("Creating an ellipse with a = %d, b = %d", a, b));
    System.out.println(String.format("phi = %.1f", Math.toDegrees(phi_r)));
    final long[] center = new long[] {size_x / 2, size_y / 2};
    final long[] radiuses = new long[] {max_radius, max_radius};

    final EllipseNeighborhood<UnsignedByteType> disc =
        new EllipseNeighborhood<UnsignedByteType>(img, center, radiuses);
    final EllipseCursor<UnsignedByteType> sc = disc.cursor();

    double r2, phi, term;
    double cosphi, sinphi;
    while (sc.hasNext()) {
      sc.fwd();
      r2 = sc.getDistanceSquared();
      phi = sc.getPhi();
      cosphi = Math.cos(phi - phi_r);
      sinphi = Math.sin(phi - phi_r);
      term = r2 * cosphi * cosphi / a / a + r2 * sinphi * sinphi / b / b;
      if (term <= 1) sc.get().set(on);
    }
    final long end = System.currentTimeMillis();
    System.out.println("Ellipse creation done in " + (end - start) + " ms.");
    System.out.println();

    ij.ImageJ.main(args);
    ImageJFunctions.show(imgplus);

    start = System.currentTimeMillis();
    final Spot spot = new Spot(center[0], center[1], 0d, max_radius, -1d);

    final SpotMorphologyAnalyzer<UnsignedByteType> bm =
        new SpotMorphologyAnalyzer<UnsignedByteType>(imgplus, null);
    bm.process(spot);

    System.out.println("Blob morphology analyzed in " + (end - start) + " ms.");
    double phiv, thetav, lv;
    for (int j = 0; j < 2; j++) {
      lv = spot.getFeature(featurelist_sa[j]);
      phiv = spot.getFeature(featurelist_phi[j]);
      thetav = spot.getFeature(featurelist_theta[j]);
      System.out.println(
          String.format(
              "For axis of semi-length %.1f, orientation is phi = %.1f°, theta = %.1f°",
              lv, Math.toDegrees(phiv), Math.toDegrees(thetav)));
    }
    System.out.println(spot.echo());

    // TEST 3D case
    /*
     *
     * // Parameters int size_x = 200; int size_y = 200; int size_z = 200;
     *
     * double a = 5.5f; double b = 4.9f; double c = 5; double theta_r =
     * (double) Math.toRadians(0); // I am unable to have it working for
     * theta_r != 0 double phi_r = (double) Math.toRadians(45);
     *
     * double max_radius = Math.max(a, Math.max(b, c)); double[] calibration
     * = new double[] {1, 1, 1};
     *
     * // Create blank image Image<UnsignedByteType> img = new
     * ImageFactory<UnsignedByteType>( new UnsignedByteType(), new
     * ArrayContainerFactory() ).createImage(new int[] {200, 200, 200});
     * final byte on = (byte) 255;
     *
     * // Create an ellipse long start = System.currentTimeMillis();
     * System.out.println(String.format(
     * "Creating an ellipse with a = %.1f, b = %.1f, c = %.1f", a, b, c));
     * System.out.println(String.format("phi = %.1f and theta = %.1f",
     * Math.toDegrees(phi_r), Math.toDegrees(theta_r))); double[] center =
     * new double[] { size_x/2, size_y/2, size_z/2 };
     * SphereCursor<UnsignedByteType> sc = new
     * SphereCursor<UnsignedByteType>(img, center, max_radius, calibration);
     * double r2, theta, phi, term; double cosphi, sinphi, costheta,
     * sintheta; while (sc.hasNext()) { sc.fwd(); r2 =
     * sc.getDistanceSquared(); phi = sc.getPhi(); theta = sc.getTheta();
     * cosphi = Math.cos(phi-phi_r); sinphi = Math.sin(phi-phi_r); costheta
     * = Math.cos(theta-theta_r); sintheta = Math.sin(theta-theta_r); term =
     * r2*cosphi*cosphi*sintheta*sintheta/a/a +
     * r2*sinphi*sinphi*sintheta*sintheta/b/b + r2*costheta*costheta/c/c; if
     * (term <= 1) sc.getType().set(on); } sc.close(); long end =
     * System.currentTimeMillis();
     * System.out.println("Ellipse creation done in " + (end-start) +
     * " ms."); System.out.println();
     *
     * ij.ImageJ.main(args); img.getDisplay().setMinMax();
     * ImageJFunctions.copyToImagePlus(img).show();
     *
     * start = System.currentTimeMillis(); BlobMorphology<UnsignedByteType>
     * bm = new BlobMorphology<UnsignedByteType>(img, calibration); SpotImp
     * spot = new SpotImp(center); spot.putFeature(Feature.RADIUS,
     * max_radius); bm.process(spot); end = System.currentTimeMillis();
     * System.out.println("Blob morphology analyzed in " + (end-start) +
     * " ms."); double phiv, thetav, lv; for (int j = 0; j < 3; j++) { lv =
     * spot.getFeature(featurelist_sa[j]); phiv =
     * spot.getFeature(featurelist_phi[j]); thetav =
     * spot.getFeature(featurelist_theta[j]);
     * System.out.println(String.format(
     * "For axis of semi-length %.1f, orientation is phi = %.1f°, theta = %.1f°"
     * , lv, Math.toDegrees(phiv), Math.toDegrees(thetav))); }
     * System.out.println(spot.echo());
     */
  }
Esempio n. 14
0
 public static void main(String args[]) {
   if (System.getProperty("java.version").substring(0, 3).compareTo("1.5") < 0) {
     javax.swing.JOptionPane.showMessageDialog(
         null, "ImageJ " + VERSION + " requires Java 1.5 or later.");
     System.exit(0);
   }
   boolean noGUI = false;
   int mode = STANDALONE;
   arguments = args;
   // System.setProperty("file.encoding", "UTF-8");
   int nArgs = args != null ? args.length : 0;
   boolean commandLine = false;
   for (int i = 0; i < nArgs; i++) {
     String arg = args[i];
     if (arg == null) continue;
     if (args[i].startsWith("-")) {
       if (args[i].startsWith("-batch")) noGUI = true;
       else if (args[i].startsWith("-debug")) IJ.setDebugMode(true);
       else if (args[i].startsWith("-ijpath") && i + 1 < nArgs) {
         if (IJ.debugMode) IJ.log("-ijpath: " + args[i + 1]);
         Prefs.setHomeDir(args[i + 1]);
         commandLine = true;
         args[i + 1] = null;
       } else if (args[i].startsWith("-port")) {
         int delta = (int) Tools.parseDouble(args[i].substring(5, args[i].length()), 0.0);
         commandLine = true;
         if (delta == 0) mode = EMBEDDED;
         else if (delta > 0 && DEFAULT_PORT + delta < 65536) port = DEFAULT_PORT + delta;
       }
     }
   }
   // If existing ImageJ instance, pass arguments to it and quit.
   boolean passArgs = mode == STANDALONE && !noGUI;
   if (IJ.isMacOSX() && !commandLine) passArgs = false;
   if (passArgs && isRunning(args)) return;
   ImageJ ij = IJ.getInstance();
   if (!noGUI && (ij == null || (ij != null && !ij.isShowing()))) {
     ij = new ImageJ(null, mode);
     ij.exitWhenQuitting = true;
   }
   int macros = 0;
   for (int i = 0; i < nArgs; i++) {
     String arg = args[i];
     if (arg == null) continue;
     if (arg.startsWith("-")) {
       if ((arg.startsWith("-macro") || arg.startsWith("-batch")) && i + 1 < nArgs) {
         String arg2 = i + 2 < nArgs ? args[i + 2] : null;
         Prefs.commandLineMacro = true;
         if (noGUI && args[i + 1].endsWith(".js")) Interpreter.batchMode = true;
         IJ.runMacroFile(args[i + 1], arg2);
         break;
       } else if (arg.startsWith("-eval") && i + 1 < nArgs) {
         String rtn = IJ.runMacro(args[i + 1]);
         if (rtn != null) System.out.print(rtn);
         args[i + 1] = null;
       } else if (arg.startsWith("-run") && i + 1 < nArgs) {
         IJ.run(args[i + 1]);
         args[i + 1] = null;
       }
     } else if (macros == 0 && (arg.endsWith(".ijm") || arg.endsWith(".txt"))) {
       IJ.runMacroFile(arg);
       macros++;
     } else if (arg.length() > 0 && arg.indexOf("ij.ImageJ") == -1) {
       File file = new File(arg);
       IJ.open(file.getAbsolutePath());
     }
   }
   if (IJ.debugMode && IJ.getInstance() == null) new JavaProperties().run("");
   if (noGUI) System.exit(0);
 }
Esempio n. 15
0
 public void windowActivated(WindowEvent e) {
   ImageJ ij = IJ.getInstance();
   if (IJ.isMacOSX() && ij != null && !ij.isActive() && !(this instanceof ThresholdAdjuster))
     ij.toFront();
   WindowManager.setWindow(this);
 }