Пример #1
0
 public void deleteHandle(double ox, double oy) {
   if (imp == null) return;
   if (nPoints <= 1) {
     imp.deleteRoi();
     return;
   }
   boolean splineFit = xSpline != null;
   xSpline = null;
   FloatPolygon points = getFloatPolygon();
   modState = NO_MODS;
   if (previousRoi != null) previousRoi.modState = NO_MODS;
   int pointToDelete = getClosestPoint(ox, oy, points);
   FloatPolygon points2 = new FloatPolygon();
   for (int i = 0; i < points.npoints; i++) {
     if (i != pointToDelete) points2.addPoint(points.xpoints[i], points.ypoints[i]);
   }
   if (type == POINT) imp.setRoi(new PointRoi(points2.xpoints, points2.ypoints, points2.npoints));
   else {
     if (subPixelResolution()) {
       Roi roi2 = new PolygonRoi(points2, type);
       roi2.setDrawOffset(getDrawOffset());
       imp.setRoi(roi2);
     } else
       imp.setRoi(
           new PolygonRoi(toInt(points2.xpoints), toInt(points2.ypoints), points2.npoints, type));
     if (splineFit) ((PolygonRoi) imp.getRoi()).fitSpline(splinePoints);
   }
 }
Пример #2
0
 public boolean contains(int x, int y) {
   if (!super.contains(x, y)) return false;
   if (xSpline != null) {
     FloatPolygon poly = new FloatPolygon(xSpline, ySpline, splinePoints);
     return poly.contains(x - this.x, y - this.y);
   } else if (xpf != null) {
     FloatPolygon poly = new FloatPolygon(xpf, ypf, nPoints);
     return poly.contains(x - this.x, y - this.y);
   } else {
     Polygon poly = new Polygon(xp, yp, nPoints);
     return poly.contains(x - this.x, y - this.y);
   }
 }
Пример #3
0
 void finishPolygon() {
   if (xpf != null) {
     FloatPolygon poly = new FloatPolygon(xpf, ypf, nPoints);
     Rectangle r = poly.getBounds();
     x = r.x;
     y = r.y;
     width = r.width;
     height = r.height;
     bounds = poly.getFloatBounds();
     float xbase = (float) bounds.getX();
     float ybase = (float) bounds.getY();
     for (int i = 0; i < nPoints; i++) {
       xpf[i] -= xbase;
       ypf[i] -= ybase;
     }
   } else {
     Polygon poly = new Polygon(xp, yp, nPoints);
     Rectangle r = poly.getBounds();
     x = r.x;
     y = r.y;
     width = r.width;
     height = r.height;
     for (int i = 0; i < nPoints; i++) {
       xp[i] = xp[i] - x;
       yp[i] = yp[i] - y;
     }
     bounds = null;
   }
   if (nPoints < 2
       || (!(type == FREELINE || type == POLYLINE || type == ANGLE)
           && (nPoints < 3 || width == 0 || height == 0))) {
     if (imp != null) imp.deleteRoi();
     if (type != POINT) return;
   }
   state = NORMAL;
   if (imp != null && !(type == TRACED_ROI)) imp.draw(x - 5, y - 5, width + 10, height + 10);
   oldX = x;
   oldY = y;
   oldWidth = width;
   oldHeight = height;
   if (Recorder.record
       && userCreated
       && (type == POLYGON
           || type == POLYLINE
           || type == ANGLE
           || (type == POINT && Recorder.scriptMode() && nPoints == 3)))
     Recorder.recordRoi(getPolygon(), type);
   if (type != POINT) modifyRoi();
   LineWidthAdjuster.update();
 }
Пример #4
0
 void addHandle(double ox, double oy) {
   if (imp == null || type == ANGLE) return;
   boolean splineFit = xSpline != null;
   xSpline = null;
   FloatPolygon points = getFloatPolygon();
   int n = points.npoints;
   modState = NO_MODS;
   if (previousRoi != null) previousRoi.modState = NO_MODS;
   int pointToDuplicate = getClosestPoint(ox, oy, points);
   FloatPolygon points2 = new FloatPolygon();
   for (int i2 = 0; i2 < n; i2++) {
     if (i2 == pointToDuplicate) {
       int i1 = i2 - 1;
       if (i1 == -1) i1 = isLine() ? i2 : n - 1;
       int i3 = i2 + 1;
       if (i3 == n) i3 = isLine() ? i2 : 0;
       double x1 = points.xpoints[i1] + 2 * (points.xpoints[i2] - points.xpoints[i1]) / 3;
       double y1 = points.ypoints[i1] + 2 * (points.ypoints[i2] - points.ypoints[i1]) / 3;
       double x2 = points.xpoints[i2] + (points.xpoints[i3] - points.xpoints[i2]) / 3;
       double y2 = points.ypoints[i2] + (points.ypoints[i3] - points.ypoints[i2]) / 3;
       points2.addPoint(x1, y1);
       points2.addPoint(x2, y2);
     } else points2.addPoint(points.xpoints[i2], points.ypoints[i2]);
   }
   if (type == POINT) imp.setRoi(new PointRoi(points2));
   else {
     if (subPixelResolution()) {
       Roi roi2 = new PolygonRoi(points2, type);
       roi2.setDrawOffset(getDrawOffset());
       imp.setRoi(roi2);
     } else
       imp.setRoi(
           new PolygonRoi(toInt(points2.xpoints), toInt(points2.ypoints), points2.npoints, type));
     if (splineFit) ((PolygonRoi) imp.getRoi()).fitSpline(splinePoints);
   }
 }
Пример #5
0
 void resetSubPixelBoundingRect() {
   float xbase = x, ybase = y;
   if (bounds != null) {
     xbase = (float) bounds.x;
     ybase = (float) bounds.y;
   }
   for (int i = 0; i < nPoints; i++) {
     xpf[i] = xpf[i] + xbase;
     ypf[i] = ypf[i] + ybase;
   }
   FloatPolygon poly = new FloatPolygon(xpf, ypf, nPoints);
   Rectangle r = poly.getBounds();
   x = r.x;
   y = r.y;
   width = r.width;
   height = r.height;
   bounds = poly.getFloatBounds();
   xbase = (float) bounds.getX();
   ybase = (float) bounds.getY();
   for (int i = 0; i < nPoints; i++) {
     xpf[i] -= xbase;
     ypf[i] -= ybase;
   }
 }