@Override public TMACoreObject getTMACoreForPixel(double x, double y) { // TODO: Consider overlapping cores - would be slightly nicer to return core with closest centroid for (TMACoreObject core : cores) { if (ROIHelpers.areaContains(core.getROI(), x, y)) return core; } return null; }
public static PathShape combineROIs(PathShape shape1, PathShape shape2, CombineOp op, double flatness) { // Check we can combine if (!ROIHelpers.sameImagePlane(shape1, shape2)) throw new IllegalArgumentException("Cannot combine - shapes " + shape1 + " and " + shape2 + " do not share the same image plane"); Area area1 = getArea(shape1); Area area2 = getArea(shape2); // Do a quick check to see if a combination might be avoided if (op == CombineOp.INTERSECT) { if (area1.contains(area2.getBounds2D())) return shape2; if (area2.contains(area1.getBounds2D())) return shape1; } else if (op == CombineOp.ADD) { if (area1.contains(area2.getBounds2D())) return shape1; if (area2.contains(area1.getBounds2D())) return shape2; } combineAreas(area1, area2, op); // I realise the following looks redundant... however direct use of the areas with the // brush tool led to strange artefacts appearing & disappearing... performing an additional // conversion seems to help // area1 = new Area(new Path2D.Float(area1)); // Return simplest ROI that works - prefer a rectangle or polygon over an area return getShapeROI(area1, shape1.getC(), shape1.getZ(), shape1.getT(), flatness); }
public static Collection<PathObject> getObjectsForLocation(final PathObjectHierarchy hierarchy, final double x, final double y, final int zPos, final int tPos) { if (hierarchy == null) return Collections.emptyList(); Set<PathObject> pathObjects = new HashSet<>(8); hierarchy.getObjectsForRegion(PathObject.class, ImageRegion.createInstance((int)x, (int)y, 1, 1, zPos, tPos), pathObjects); removePoints(pathObjects); // Ensure we don't have any PointROIs // Ensure the ROI contains the click Iterator<PathObject> iter = pathObjects.iterator(); while (iter.hasNext()) { PathObject temp = iter.next(); // if ((temp.isHidden() && temp.hasChildren()) || !PathROIHelpers.areaContains(temp.getROI(), x, y)) if (!ROIHelpers.areaContains(temp.getROI(), x, y)) iter.remove(); } if (pathObjects.isEmpty()) { return Collections.emptyList(); } return pathObjects; }