public static RoiEditor createInstance() { return new RoiEditor(); }
@Override void ensureHandlesUpdated() { if (handles == null) handles = new ArrayList<>(); else handles.clear(); addPointsToMutablePointList(handles, roi.getPolygonPoints()); }
public List<Point2> getHandles() { if (adjuster == null) return Collections.emptyList(); return createPoint2List(adjuster.getHandles()); }
public void setROI(ROI pathROI, boolean stopTranslating) { // if (stopTranslating) // System.out.println("Stopping translating: " + stopTranslating + " - " + pathROI); if (this.pathROI == pathROI) return; if (isTranslating() && stopTranslating) { finishTranslation(); activeHandle = null; } this.pathROI = pathROI; if (pathROI instanceof RectangleROI) adjuster = new RectangleHandleAdjuster((RectangleROI)pathROI); else if (pathROI instanceof EllipseROI) adjuster = new EllipseHandleAdjuster((EllipseROI)pathROI); else if (pathROI instanceof PolygonROI) adjuster = new PolygonHandleAdjuster((PolygonROI)pathROI); else if (pathROI instanceof LineROI) adjuster = new LineHandleAdjuster((LineROI)pathROI); else if (pathROI instanceof PointsROI) adjuster = new PointsHandleAdjuster((PointsROI)pathROI); else { adjuster = null; return; } }
if (!isTranslating()) return pathROI; setROI(((TranslatableROI)pathROI).translate(dx, dy), false); pTranslateCurrent.setLocation(x, y);
public void setROI(ROI pathROI) { setROI(pathROI, true); }
/** * Try to grab a ROI handle. * This will fail (return false, with an error logged) if isTranslating() return true. * * @param x * @param y * @param maxDist * @param modifiers - from a MouseEvent - may optionally be used to control how the handle is modified * @return */ public boolean grabHandle(double x, double y, double maxDist, boolean shiftDown) { if (adjuster == null) return false; if (isTranslating()) { logger.error("Cannot grab handle while ROI is being translated - request will be ignored"); return false; } activeHandle = adjuster.grabHandle(x, y, maxDist, shiftDown); return activeHandle != null; }
@Override public PolygonROI requestNewHandle(double x, double y) { if (activeHandle == null) return roi; // Can only add if there is an active handle - distance to this will be used // Move the active handle if it is very close to the requested region // (removed) // Don't add a handle at almost the sample place as an existing handle if (handles.size() >= 2 && activeHandle == handles.get(handles.size() - 1) && handles.get(handles.size() - 2).distanceSq(x, y) < 4) { return roi; } // // If we have 2 points, which are identical, shift instead of creating // if (handles.size() >= 2 && activeHandle == handles.get(handles.size() - 1) && activeHandle.distanceSq(handles.get(handles.size() - 2)) < 0.000001) { // System.err.println("UPDATING HANDLE"); // return updateActiveHandleLocation(x, y, false); // } activeHandle = new MutablePoint(x, y); handles.add(activeHandle); roi = new PolygonROI(createPoint2List(handles), roi.getC(), roi.getZ(), roi.getT()); // System.out.println("UPDATED HANDLES BY REQUEST: " + handles.size()); return roi; }
@Override void ensureHandlesUpdated() { if (handles == null) handles = new ArrayList<>(); else handles.clear(); addPointsToMutablePointList(handles, roi.getPolygonPoints()); // If we have a single point, create a second handle (which may be adjusted) if (handles.size() == 1) handles.add(new MutablePoint(handles.get(0).getX(), handles.get(0).getY())); }
@Override PolygonROI updateActiveHandleLocation(double xNew, double yNew, boolean shiftDown) { if (activeHandle == null) return roi; activeHandle.setLocation(xNew, yNew); roi = new PolygonROI(createPoint2List(handles), roi.getC(), roi.getZ(), roi.getT()); // System.out.println("UPDATED HANDLES: " + handles.size() + ", " + roi.nVertices()); return roi; }
@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; }
@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; }