示例#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);
   }
 }
示例#2
0
 public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
   this.pfr = pfr;
   String macroOptions = Macro.getOptions();
   if (macroOptions != null) {
     if (macroOptions.indexOf(" interpolate") != -1)
       macroOptions.replaceAll(" interpolate", " interpolation=Bilinear");
     else if (macroOptions.indexOf(" interpolation=") == -1)
       macroOptions = macroOptions + " interpolation=None";
     Macro.setOptions(macroOptions);
   }
   gd = new GenericDialog("Rotate", IJ.getInstance());
   gd.addNumericField("Angle (degrees):", angle, (int) angle == angle ? 1 : 2);
   gd.addNumericField("Grid Lines:", gridLines, 0);
   gd.addChoice("Interpolation:", methods, methods[interpolationMethod]);
   if (bitDepth == 8 || bitDepth == 24)
     gd.addCheckbox("Fill with Background Color", fillWithBackground);
   if (canEnlarge) gd.addCheckbox("Enlarge Image to Fit Result", enlarge);
   else enlarge = false;
   gd.addPreviewCheckbox(pfr);
   gd.addDialogListener(this);
   gd.showDialog();
   drawGridLines(0);
   if (gd.wasCanceled()) {
     return DONE;
   }
   if (!enlarge) flags |= KEEP_PREVIEW; // standard filter without enlarge
   else if (imp.getStackSize() == 1) flags |= NO_CHANGES; // undoable as a "compound filter"
   return IJ.setupDialog(imp, flags);
 }
示例#3
0
 void showDialog() {
   int width = imp.getWidth();
   int height = imp.getHeight();
   Calibration cal = imp.getCalibration();
   int places;
   if (cal.scaled()) {
     pixelWidth = cal.pixelWidth;
     pixelHeight = cal.pixelHeight;
     units = cal.getUnits();
     places = 2;
   } else {
     pixelWidth = 1.0;
     pixelHeight = 1.0;
     units = "pixels";
     places = 0;
   }
   if (areaPerPoint == 0.0)
     areaPerPoint =
         (width * cal.pixelWidth * height * cal.pixelHeight) / 81.0; // default to 9x9 grid
   ImageWindow win = imp.getWindow();
   GenericDialog gd = new GenericDialog("Grid...");
   gd.addChoice("Grid Type:", types, type);
   gd.addNumericField("Area per Point:", areaPerPoint, places, 6, units + "^2");
   gd.addChoice("Color:", colors, color);
   gd.addCheckbox("Random Offset", randomOffset);
   gd.addDialogListener(this);
   gd.showDialog();
   if (gd.wasCanceled()) showGrid(null);
 }
示例#4
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;
 }
示例#5
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;
  }