Ejemplo n.º 1
0
 public void run(ImageProcessor ip) {
   if (enlarge && gd.wasOKed())
     synchronized (this) {
       if (!isEnlarged) {
         enlargeCanvas();
         isEnlarged = true;
       }
     }
   if (isEnlarged) { // enlarging may have made the ImageProcessor invalid, also for the parallel
                     // threads
     int slice = pfr.getSliceNumber();
     if (imp.getStackSize() == 1) ip = imp.getProcessor();
     else ip = imp.getStack().getProcessor(slice);
   }
   ip.setInterpolationMethod(interpolationMethod);
   if (fillWithBackground) {
     Color bgc = Toolbar.getBackgroundColor();
     if (bitDepth == 8) ip.setBackgroundValue(ip.getBestIndex(bgc));
     else if (bitDepth == 24) ip.setBackgroundValue(bgc.getRGB());
   } else ip.setBackgroundValue(0);
   ip.rotate(angle);
   if (!gd.wasOKed()) drawGridLines(gridLines);
   if (isEnlarged && imp.getStackSize() == 1) {
     imp.changes = true;
     imp.updateAndDraw();
     Undo.setup(Undo.COMPOUND_FILTER_DONE, imp);
   }
 }
Ejemplo n.º 2
0
 private void openDirectory(File f, String path) {
   if (path == null) return;
   if (!(path.endsWith(File.separator) || path.endsWith("/"))) path += File.separator;
   String[] names = f.list();
   names = (new FolderOpener()).trimFileList(names);
   if (names == null) return;
   String msg = "Open all " + names.length + " images in \"" + f.getName() + "\" as a stack?";
   GenericDialog gd = new GenericDialog("Open Folder");
   gd.setInsets(10, 5, 0);
   gd.addMessage(msg);
   gd.setInsets(15, 35, 0);
   gd.addCheckbox("Convert to RGB", convertToRGB);
   gd.setInsets(0, 35, 0);
   gd.addCheckbox("Use Virtual Stack", virtualStack);
   gd.enableYesNoCancel();
   gd.showDialog();
   if (gd.wasCanceled()) return;
   if (gd.wasOKed()) {
     convertToRGB = gd.getNextBoolean();
     virtualStack = gd.getNextBoolean();
     String options = " sort";
     if (convertToRGB) options += " convert_to_rgb";
     if (virtualStack) options += " use";
     IJ.run("Image Sequence...", "open=[" + path + "]" + options);
     DirectoryChooser.setDefaultDirectory(path);
   } else {
     for (int k = 0; k < names.length; k++) {
       IJ.redirectErrorMessages();
       if (!names[k].startsWith(".")) (new Opener()).open(path + names[k]);
     }
   }
   IJ.register(DragAndDrop.class);
 }
Ejemplo n.º 3
0
 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
   angle = gd.getNextNumber();
   // only check for invalid input to "angle", don't care about gridLines
   if (gd.invalidNumber()) {
     if (gd.wasOKed()) IJ.error("Angle is invalid.");
     return false;
   }
   gridLines = (int) gd.getNextNumber();
   interpolationMethod = gd.getNextChoiceIndex();
   if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean();
   if (canEnlarge) enlarge = gd.getNextBoolean();
   return true;
 }
Ejemplo n.º 4
0
  public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
    int width = imp.getWidth();
    int height = imp.getHeight();
    type = gd.getNextChoice();
    areaPerPoint = gd.getNextNumber();
    color = gd.getNextChoice();
    randomOffset = gd.getNextBoolean();

    double minArea = (width * height) / 50000.0;
    if (type.equals(types[1]) && minArea < 144.0) minArea = 144.0;
    else if (minArea < 16) minArea = 16.0;
    if (areaPerPoint / (pixelWidth * pixelHeight) < minArea) {
      String err = "\"Area per Point\" too small";
      if (gd.wasOKed()) IJ.error("Grid", err);
      else IJ.showStatus(err);
      return true;
    }
    double tileSize = Math.sqrt(areaPerPoint);
    tileWidth = tileSize / pixelWidth;
    tileHeight = tileSize / pixelHeight;
    if (randomOffset) {
      xstart = (int) (random.nextDouble() * tileWidth);
      ystart = (int) (random.nextDouble() * tileHeight);
    } else {
      xstart = (int) (tileWidth / 2.0 + 0.5);
      ystart = (int) (tileHeight / 2.0 + 0.5);
    }
    linesV = (int) ((width - xstart) / tileWidth) + 1;
    linesH = (int) ((height - ystart) / tileHeight) + 1;
    if (gd.invalidNumber()) return true;
    if (type.equals(types[0])) drawLines();
    else if (type.equals(types[1])) drawCrosses();
    else if (type.equals(types[2])) drawPoints();
    else showGrid(null);
    return true;
  }