Esempio n. 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);
   }
 }
Esempio n. 2
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);
   }
 }