コード例 #1
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 void fitSpline() {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Spline");
     return;
   }
   int type = roi.getType();
   boolean segmentedSelection = type == Roi.POLYGON || type == Roi.POLYLINE;
   if (!(segmentedSelection
       || type == Roi.FREEROI
       || type == Roi.TRACED_ROI
       || type == Roi.FREELINE)) {
     IJ.error("Spline", "Polygon or polyline selection required");
     return;
   }
   if (roi instanceof EllipseRoi) return;
   PolygonRoi p = (PolygonRoi) roi;
   if (!segmentedSelection) {
     if (p.subPixelResolution()) p = trimFloatPolygon(p, p.getUncalibratedLength());
     else p = trimPolygon(p, p.getUncalibratedLength());
   }
   String options = Macro.getOptions();
   if (options != null && options.indexOf("straighten") != -1) p.fitSplineForStraightening();
   else if (options != null && options.indexOf("remove") != -1) p.removeSplineFit();
   else p.fitSpline();
   imp.draw();
   LineWidthAdjuster.update();
 }
コード例 #2
0
ファイル: PolygonRoi.java プロジェクト: oeway/Eva-ImageJ
 protected void moveHandle(int sx, int sy) {
   if (clipboard != null) return;
   int ox = ic.offScreenX(sx);
   int oy = ic.offScreenY(sy);
   if (xpf != null) {
     double offset = getOffset(-0.5);
     xpf[activeHandle] = (float) (ic.offScreenXD(sx) - x + offset);
     ypf[activeHandle] = (float) (ic.offScreenYD(sy) - y + offset);
   } else {
     xp[activeHandle] = ox - x;
     yp[activeHandle] = oy - y;
   }
   if (xSpline != null) {
     fitSpline(splinePoints);
     updateClipRect();
     imp.draw(clipX, clipY, clipWidth, clipHeight);
     oldX = x;
     oldY = y;
     oldWidth = width;
     oldHeight = height;
   } else {
     resetBoundingRect();
     if (type == POINT && width == 0 && height == 0) {
       width = 1;
       height = 1;
     }
     updateClipRectAndDraw();
   }
   String angle = type == ANGLE ? getAngleAsString() : "";
   IJ.showStatus(imp.getLocationAsString(ox, oy) + angle);
 }
コード例 #3
0
ファイル: PolygonRoi.java プロジェクト: oeway/Eva-ImageJ
 public void fitSpline() {
   double length = getUncalibratedLength();
   int evaluationPoints = (int) (length / 2.0);
   if (ic != null) {
     double mag = ic.getMagnification();
     if (mag < 1.0) evaluationPoints *= mag;
     ;
   }
   if (evaluationPoints < 100) evaluationPoints = 100;
   fitSpline(evaluationPoints);
 }
コード例 #4
0
ファイル: PolygonRoi.java プロジェクト: oeway/Eva-ImageJ
 /* Creates a spline fitted polygon with one pixel segment lengths
 that can be retrieved using the getFloatPolygon() method. */
 public void fitSplineForStraightening() {
   fitSpline((int) getUncalibratedLength() * 2);
   if (splinePoints == 0) return;
   float[] xpoints = new float[splinePoints * 2];
   float[] ypoints = new float[splinePoints * 2];
   xpoints[0] = xSpline[0];
   ypoints[0] = ySpline[0];
   int n = 1, n2;
   double inc = 0.01;
   double distance = 0.0, distance2 = 0.0, dx = 0.0, dy = 0.0, xinc, yinc;
   double x, y, lastx, lasty, x1, y1, x2 = xSpline[0], y2 = ySpline[0];
   for (int i = 1; i < splinePoints; i++) {
     x1 = x2;
     y1 = y2;
     x = x1;
     y = y1;
     x2 = xSpline[i];
     y2 = ySpline[i];
     dx = x2 - x1;
     dy = y2 - y1;
     distance = Math.sqrt(dx * dx + dy * dy);
     xinc = dx * inc / distance;
     yinc = dy * inc / distance;
     lastx = xpoints[n - 1];
     lasty = ypoints[n - 1];
     // n2 = (int)(dx/xinc);
     n2 = (int) (distance / inc);
     if (splinePoints == 2) n2++;
     do {
       dx = x - lastx;
       dy = y - lasty;
       distance2 = Math.sqrt(dx * dx + dy * dy);
       // IJ.log(i+"   "+IJ.d2s(xinc,5)+"   "+IJ.d2s(yinc,5)+"   "+IJ.d2s(distance,2)+"
       // "+IJ.d2s(distance2,2)+"   "+IJ.d2s(x,2)+"   "+IJ.d2s(y,2)+"   "+IJ.d2s(lastx,2)+"
       // "+IJ.d2s(lasty,2)+"   "+n+"   "+n2);
       if (distance2 >= 1.0 - inc / 2.0 && n < xpoints.length - 1) {
         xpoints[n] = (float) x;
         ypoints[n] = (float) y;
         // IJ.log("--- "+IJ.d2s(x,2)+"   "+IJ.d2s(y,2)+"  "+n);
         n++;
         lastx = x;
         lasty = y;
       }
       x += xinc;
       y += yinc;
     } while (--n2 > 0);
   }
   xSpline = xpoints;
   ySpline = ypoints;
   splinePoints = n;
 }