@Override public List<Point2> getPolygonPoints() { return getPointList(); }
public PointsROI(double x, double y, int c, int z, int t) { super(c, z, t); addPoint(x, y); recomputeBounds(); }
private Object readResolve() { PointsROI roi = new PointsROI(x, y, c, z, t); return roi; }
public static void writePoints(File file, PointsROI points) { try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file))); // String name = points.getName(); // if (name != null) // out.println(name); // else // out.println(); for (Point2 p : points.getPointList()) out.println(String.format(".%3f\t.%3f", p.getX(), p.getY())); out.close(); } catch (IOException e) { logger.error("Error writing {} to {}", points.toString(), file.getAbsolutePath()); e.printStackTrace(); } }
sb.append("Name\t").append(pathObject.getDisplayedName()).append("\n"); sb.append("Color\t").append(getDisplayedColor(pathObject, defaultColor)).append("\n"); sb.append("Coordinates\t").append(points.getNPoints()).append("\n"); out.write(sb.toString().getBytes(charset));
@Override public double getConvexArea() { PathArea hull = getConvexHull(); if (hull != null) return hull.getArea(); return Double.NaN; }
@Override public String toString() { // if (getName() != null) // return String.format("%s (%d points)", getName(), points.size()); return String.format("%s (%d points)", getROIType(), points.size()); }
@Override void ensureHandlesUpdated() { if (handles == null) handles = new ArrayList<>(); else handles.clear(); addPointsToMutablePointList(handles, roi.getPolygonPoints()); }
public static PointsROI readPointsFromString(String s) { List<Point2> pointsList = new ArrayList<>(); Scanner scanner = new Scanner(s); // String name = scanner.nextLine(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.length() == 0) break; String[] splits = line.split("\t"); double x = Double.parseDouble(splits[0]); double y = Double.parseDouble(splits[1]); pointsList.add(new Point2(x, y)); } scanner.close(); // if (name != null && name.length() > 0) // points.setName(name); return new PointsROI(pointsList); }
SerializationProxy(final PointsROI roi) { int n = roi.getNPoints(); this.x = new float[n]; this.y = new float[n]; int ind = 0; for (Point2 p : roi.points) { x[ind] = (float)p.getX(); y[ind] = (float)p.getY(); ind++; } this.name = null; // There used to be names... now there aren't this.c = roi.c; this.z = roi.z; this.t = roi.t; }
@Override public double getScaledConvexArea(double pixelWidth, double pixelHeight) { PathArea hull = getConvexHull(); if (hull != null) return hull.getScaledArea(pixelWidth, pixelHeight); return Double.NaN; }
@Override public PointsROI requestNewHandle(double x, double y) { activeHandle = new MutablePoint(x, y); handles.add(activeHandle); roi = new PointsROI(createPoint2List(handles), roi.getC(), roi.getZ(), roi.getT()); ensureHandlesUpdated(); activeHandle = grabHandle(x, y, Double.POSITIVE_INFINITY, false); // ensureHandlesUpdated(); // activeHandle = grabHandle(x, y, 1, false); // ensureHandlesUpdated(); // activeHandle = roi.getNearest(x, y, 0.01); return roi; }
pointsList.add(new Point2(x, y)); points = new PointsROI(pointsList);
public static String getPointsAsString(PointsROI points) { StringBuilder sb = new StringBuilder(); // String name = points.getName(); // if (name != null) // sb.append(name); // sb.append("\n"); for (Point2 p : points.getPointList()) sb.append(String.format("%.4f\t%.4f\n", p.getX(), p.getY())); return sb.toString(); }
public PointsROI(float[] x, float[] y, int c, int z, int t) { super(c, z, t); if (x.length != y.length) throw new IllegalArgumentException("Lengths of x and y arrays are not the same! " + x.length + " and " + y.length); for (int i = 0; i < x.length; i++) addPoint(x[i], y[i]); recomputeBounds(); }
PointsROI r1 = (PointsROI)o1; PointsROI r2 = (PointsROI)o2; return Integer.compare(r1.getNPoints(), r2.getNPoints());
@Override PointsROI updateActiveHandleLocation(double xNew, double yNew, boolean shiftDown) { if (activeHandle == null) return roi; activeHandle.setLocation(xNew, yNew); roi = new PointsROI(createPoint2List(handles), roi.getC(), roi.getZ(), roi.getT()); ensureHandlesUpdated(); activeHandle = grabHandle(xNew, yNew, Double.POSITIVE_INFINITY, shiftDown); // System.err.println("Calling: " + activeHandle + " - " + (handles == null ? 0 : handles.size())); return roi; }
public static PathObject readPointsObjectFromString(String s) { List<Point2> pointsList = new ArrayList<>(); Scanner scanner = new Scanner(s); String name = scanner.nextLine().split("\t")[1].trim(); Integer color = Integer.getInteger(scanner.nextLine().split("\t")[1]); // Skip the coordinate count line... int count = Integer.parseInt(scanner.nextLine().split("\t")[1]); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.length() == 0) break; String[] splits = line.split("\t"); double x = Double.parseDouble(splits[0]); double y = Double.parseDouble(splits[1]); pointsList.add(new Point2(x, y)); } scanner.close(); // if (name != null && name.length() > 0) // points.setName(name); if (count != pointsList.size()) logger.warn("Warning: {} points expected, {} points found", count, pointsList.size()); PointsROI points = new PointsROI(pointsList); PathAnnotationObject pathObject = new PathAnnotationObject(points); if (name != null && name.length() > 0 && !"null".equals(name)) pathObject.setName(name); pathObject.setColorRGB(color); return pathObject; }
for (Point2 p : ((PointsROI)pathObject.getROI()).getPointList()) {