Ejemplo n.º 1
0
 /**
  * Creates a dialog box, allowing the user to enter the requested width, height, x & y
  * coordinates, slice number for a Region Of Interest, option for oval, and option for whether x &
  * y coordinates to be centered.
  */
 void showDialog() {
   Calibration cal = imp.getCalibration();
   int digits = 0;
   if (scaledUnits && cal.scaled()) digits = 2;
   Roi roi = imp.getRoi();
   if (roi == null) drawRoi();
   GenericDialog gd = new GenericDialog("Specify");
   gd.addNumericField("Width:", width, digits);
   gd.addNumericField("Height:", height, digits);
   gd.addNumericField("X coordinate:", xRoi, digits);
   gd.addNumericField("Y coordinate:", yRoi, digits);
   if (stackSize > 1) gd.addNumericField("Slice:", iSlice, 0);
   gd.addCheckbox("Oval", oval);
   gd.addCheckbox("Constrain square/circle", square);
   gd.addCheckbox("Centered", centered);
   if (cal.scaled()) {
     boolean unitsMatch = cal.getXUnit().equals(cal.getYUnit());
     String units = unitsMatch ? cal.getUnits() : cal.getXUnit() + " x " + cal.getYUnit();
     gd.addCheckbox("Scaled units (" + units + ")", scaledUnits);
   }
   fields = gd.getNumericFields();
   gd.addDialogListener(this);
   gd.showDialog();
   if (gd.wasCanceled()) {
     if (roi == null) imp.deleteRoi();
     else // *ALWAYS* restore initial ROI when cancelled
     imp.setRoi(roi);
   }
 }
Ejemplo n.º 2
0
 protected void updateRoi() {
   // System.out.println("image:"+currentImage.getTitle()+ " slice:"+currentImage.getSlice());
   Roi r = currentROIs.get(currentImage.getSlice());
   if (r != null) {
     currentImage.setRoi(r);
   } else {
     currentImage.killRoi();
   }
   currentImage.updateAndDraw();
 }
Ejemplo n.º 3
0
 protected void handleRoiMouseDown(MouseEvent e) {
   int sx = e.getX();
   int sy = e.getY();
   int ox = offScreenX(sx);
   int oy = offScreenY(sy);
   Roi roi = imp.getRoi();
   int handle = roi != null ? roi.isHandle(sx, sy) : -1;
   boolean multiPointMode =
       roi != null
           && (roi instanceof PointRoi)
           && handle == -1
           && Toolbar.getToolId() == Toolbar.POINT
           && Toolbar.getMultiPointMode();
   if (multiPointMode) {
     imp.setRoi(((PointRoi) roi).addPoint(ox, oy));
     return;
   }
   setRoiModState(e, roi, handle);
   if (roi != null) {
     if (handle >= 0) {
       roi.mouseDownInHandle(handle, sx, sy);
       return;
     }
     Rectangle r = roi.getBounds();
     int type = roi.getType();
     if (type == Roi.RECTANGLE
         && r.width == imp.getWidth()
         && r.height == imp.getHeight()
         && roi.getPasteMode() == Roi.NOT_PASTING
         && !(roi instanceof ImageRoi)) {
       imp.killRoi();
       return;
     }
     if (roi.contains(ox, oy)) {
       if (roi.modState == Roi.NO_MODS) roi.handleMouseDown(sx, sy);
       else {
         imp.killRoi();
         imp.createNewRoi(sx, sy);
       }
       return;
     }
     if ((type == Roi.POLYGON || type == Roi.POLYLINE || type == Roi.ANGLE)
         && roi.getState() == roi.CONSTRUCTING) return;
     int tool = Toolbar.getToolId();
     if ((tool == Toolbar.POLYGON || tool == Toolbar.POLYLINE || tool == Toolbar.ANGLE)
         && !(IJ.shiftKeyDown() || IJ.altKeyDown())) {
       imp.killRoi();
       return;
     }
   }
   imp.createNewRoi(sx, sy);
 }
Ejemplo n.º 4
0
 void drawRoi() {
   double xPxl = xRoi;
   double yPxl = yRoi;
   if (centered) {
     xPxl -= width / 2;
     yPxl -= height / 2;
   }
   double widthPxl = width;
   double heightPxl = height;
   Calibration cal = imp.getCalibration();
   if (scaledUnits && cal.scaled()) {
     xPxl /= cal.pixelWidth;
     yPxl /= cal.pixelHeight;
     widthPxl /= cal.pixelWidth;
     heightPxl /= cal.pixelHeight;
     prevPixelWidth = cal.pixelWidth;
   }
   Roi roi;
   if (oval) roi = new OvalRoi(xPxl, yPxl, widthPxl, heightPxl);
   else roi = new Roi(xPxl, yPxl, widthPxl, heightPxl);
   imp.setRoi(roi);
   prevRoi = roi.getBounds();
   // prevPixelWidth = cal.pixelWidth;
 }