@Override public String toString() { String postfix; if (getPathClass() == null) postfix = objectCountPostfix(); else postfix = " (" + getPathClass().getName() + ")"; if (getName() != null) return getName() + postfix; if (getROI() != null) return getROI().toString() + postfix; return "Unassigned" + postfix; // Entire image }
pathObjectSet.sort((o1, o2) -> Integer.compare(o2.getLevel(), o1.getLevel())); PathObject parent = pathObject.getParent(); if (parent == null) continue; PathObject parent = entry.getKey(); List<PathObject> children = entry.getValue(); parent.removePathObjects(children); if (keepChildren) { for (PathObject child : children) { if (child.hasChildren()) { List<PathObject> newChildList = new ArrayList<>(child.getChildObjects()); newChildList.removeAll(pathObjects); parent.addPathObjects(newChildList);
static Integer getDisplayedColor(final PathObject pathObject, final Integer defaultColor) { // Check if any color has been set - if so, return it Integer color = pathObject.getColorRGB(); if (color != null) return color; // Check if any class has been set, if so then use its color PathClass pathClass = pathObject.getPathClass(); if (pathClass != null) color = pathClass.getColor(); if (color != null) return color; return defaultColor; }
public String getDisplayedName() { String nameDisplayed = name; if (nameDisplayed == null) { PathClass pathClass = getPathClass(); if (pathClass != null) nameDisplayed = pathClass.getName(); else nameDisplayed = getClass().getSimpleName(); } if (getParent() != null && getParent().isTMACore()) nameDisplayed = getParent().getDisplayedName() + " - " + nameDisplayed; return nameDisplayed; }
if (pathObject != null && !pathObject.isDetection()) logger.info("Adding {} to hierarchy", pathObject); if (!pathObjectParent.hasChildren()) { pathObjectParent.addPathObject(pathObject); Collection<PathObject> pathObjects = pathObjectParent.getChildObjects(); if (avoidDuplicates && pathObjects.contains(pathObject)) { logger.warn("Warning: List already contains {}, will not be added again", pathObject); ROI pathROI = pathObject.getROI(); ROI pathROIInner = useCellNucleiForInsideTest && (pathObject instanceof PathCellObject) ? ((PathCellObject)pathObject).getNucleusROI() : pathROI; //J if (useTileCentroidsForInsideTest && pathObject instanceof PathDetectionObject && !(pathROIInner instanceof PointsROI)) { ROI tempROI = temp.getROI(); ROI tempROIInner = tempROI;; if (possibleParent == null) possibleParent = temp; else if (temp.getLevel() > possibleParent.getLevel()) // We want the highest level to be the parent, i.e. deepest in hierarchy possibleParent = temp; if (iterChild.next().getParent() != possibleParent) iterChild.remove(); pathObject.addPathObjects(possibleChildren); possibleParent.addPathObject(pathObject);
if (!(pathObject instanceof PathAnnotationObject) || !(pathObject.getROI() instanceof PathShape)) { logger.warn("Combine annotations: No annotation with ROI selected"); return; PathShape shapeMask = (PathShape)pathObject.getROI(); Area areaOriginal = PathROIToolsAwt.getArea(shapeMask); Area areaNew = new Area(areaOriginal); while (iter.hasNext()) { PathObject temp = iter.next(); Area areaTemp = PathROIToolsAwt.getArea(temp.getROI()); PathObject annotationNew = null; if (op == PathROIToolsAwt.CombineOp.SUBTRACT) { areaTemp.subtract(areaNew); PathShape shapeNew = PathROIToolsAwt.getShapeROI(areaTemp, shapeMask.getC(), shapeMask.getZ(), shapeMask.getT()); annotationNew = new PathAnnotationObject(shapeNew, temp.getPathClass()); } else if (op == PathROIToolsAwt.CombineOp.INTERSECT) { areaTemp.intersect(areaNew); PathShape shapeNew = PathROIToolsAwt.getShapeROI(areaTemp, shapeMask.getC(), shapeMask.getZ(), shapeMask.getT()); annotationNew = new PathAnnotationObject(shapeNew, temp.getPathClass()); } else { PathROIToolsAwt.combineAreas(areaNew, areaTemp, op); annotationNew.setColorRGB(temp.getColorRGB()); annotationNew.setName(temp.getName()); objectsToAdd.add(annotationNew); objectsToAdd.add(new PathAnnotationObject(shapeNew, pathObject.getPathClass()));
PathObject pathObject = iter.next(); if (pathObject.getPathClass() == null || (pointsOnly && !pathObject.isPoint()) || (!pathObject.isPoint() && !pathObject.hasChildren())) iter.remove(); else classifications.put(pathObject.getPathClass(), new ArrayList<>()); PathClass pathClass = pathObject.getPathClass(); List<PathObject> list = classifications.get(pathClass); list.addAll(pathObject.getChildObjects()); if (pathObject.isPoint()) { for (Point2 p : ((PointsROI)pathObject.getROI()).getPointList()) {
int temp = -Boolean.compare(o1.isRootObject(), o2.isRootObject()); if (temp != 0) return temp; temp = -Boolean.compare(o1.isTMACore(), o2.isTMACore()); if (temp != 0) return temp; temp = -Boolean.compare(o1.isAnnotation(), o2.isAnnotation()); if (temp != 0) return temp; temp = -Boolean.compare(o1.isDetection(), o2.isDetection()); if (temp != 0) return temp; temp = DefaultROIComparator.getInstance().compare(o1.getROI(), o2.getROI()); if (temp != 0) return temp; PathClass pc1 = o1.getPathClass(); PathClass pc2 = o2.getPathClass(); if (pc1 != null) return pc1.compareTo(pc2);
ROI roi = pathObject.getROI(); Shape shape = PathROIToolsAwt.getShape(pathObject.getROI()); PathObject parent = isErosion ? pathObject : pathObject.getParent(); if (constrainToParent && !isErosion) { Area parentShape; if (parent == null || parent.getROI() == null) parentShape = new Area(bounds); else parentShape = PathROIToolsAwt.getArea(parent.getROI()); area.intersect(parentShape); PathAnnotationObject annotation2 = new PathAnnotationObject(roi2, pathObject.getPathClass()); annotation2.setName(pathObject.getName()); annotation2.setColorRGB(pathObject.getColorRGB());
public synchronized boolean removeObject(PathObject pathObject, boolean keepChildren, boolean fireEvent) { // Check the object is within the hierarchy & has a valid parent (from which it can be removed) PathObject pathObjectParent = pathObject.getParent(); if (!inHierarchy(pathObject) || pathObjectParent == null) { logger.warn(pathObject + " could not be removed from the hierarchy"); return false; } // Can't keep children if there aren't any keepChildren = keepChildren && pathObject.hasChildren(); pathObjectParent.removePathObject(pathObject); // Assign the children to the parent object, if necessary if (keepChildren) { // We create a new array list because getPathObjectList returns an unmodifiable collection // List<PathObject> list = new ArrayList<>(pathObject.getPathObjectList()); pathObjectParent.addPathObjects(pathObject.getChildObjects()); // pathObject.clearPathObjects(); // Clear child objects, just in case } if (fireEvent) { if (keepChildren) fireObjectRemovedEvent(this, pathObject, pathObjectParent); else fireHierarchyChangedEvent(this, pathObjectParent); } return true; }
@Override public void run() { try { MeasurementList measurementList = parentObject.getMeasurementList(); ROI roi; if (parentObject instanceof PathCellObject) { roi = ((PathCellObject)parentObject).getNucleusROI(); if (roi instanceof PathArea) addMeasurements(measurementList, (PathArea)roi, "Nucleus Shape: ", pixelWidth, pixelHeight, unit, doArea, doPerimeter, doCircularity); roi = parentObject.getROI(); if (roi instanceof PathArea) addMeasurements(measurementList, (PathArea)roi, "Cell Shape: ", pixelWidth, pixelHeight, unit, doArea, doPerimeter, doCircularity); } else { roi = parentObject.getROI(); if (roi instanceof PathArea) addMeasurements(measurementList, (PathArea)roi, "ROI Shape: ", pixelWidth, pixelHeight, unit, doArea, doPerimeter, doCircularity); } measurementList.closeList(); } catch (Exception e) { e.printStackTrace(); throw(e); } } });
parentObject.getChildObjects().stream().map(p -> p.getPathClass()).collect(Collectors.toSet()) : Collections.singletonList(choice); if (pathClass != null) { Path2D path = null; for (PathObject pathObject : parentObject.getChildObjects()) { if ((pathObject instanceof PathTileObject) && (pathObject.getROI() instanceof PathShape) && pathClass.equals(pathObject.getPathClass())) { PathShape pathShape = (PathShape)pathObject.getROI(); if (path == null) path = new Path2D.Float(PathROIToolsAwt.getShape(pathShape)); ROI parentROI = parentObject.getROI(); if (parentROI != null) pathROINew = PathROIToolsAwt.getShapeROI(new Area(path), parentROI.getC(), parentROI.getZ(), parentROI.getT()); pathSingleAnnotation = new PathAnnotationObject(pathROINew, pathClass); if (!deleteTiles) pathSingleAnnotation.addPathObjects(tiles); PathShape pathShape = (PathShape)pathSingleAnnotation.getROI(); Area area = PathROIToolsAwt.getArea(pathShape); if (area.isSingular()) { while (iter.hasNext()) { PathObject next = iter.next(); ROI roi = next.getROI(); if (poly.contains(roi.getCentroidX(), roi.getCentroidY())) { iter.remove();
@Override public void taskComplete() { if (parentObject.getROI() == pathROI) { if (!Thread.currentThread().isInterrupted()) { parentObject.clearPathObjects(); tryToSetObjectLock(parentObject, false); // Try to unlock the parent parentObject.addPathObjects(pathObjectsDetected); tryToSetObjectLock(parentObject, true); // Try to lock the parent } else if (!parentObject.hasChildren() || overlapAmount <= 0) { parentObject.addPathObjects(pathObjectsDetected); tryToSetObjectLock(parentObject, true); // Try to lock the parent } else if (pathObjectsDetected != null && !pathObjectsDetected.isEmpty()) { if (tempObject.getROI() instanceof PathArea) { Shape shapeTemp = PathROIToolsAwt.getShape(tempObject.getROI()); Area areaTemp = new Area(shapeTemp); mapOld.put(areaTemp, tempObject); while (iterNew.hasNext() && !mapOld.isEmpty()) { PathObject pathObjectNew = iterNew.next(); PathArea pathAreaNew = pathObjectNew.getROI() instanceof PathArea ? (PathArea)pathObjectNew.getROI() : null; if (pathAreaNew == null) continue; PathArea pathAreaOld = (PathArea)entryOld.getValue().getROI(); if (pathAreaNew.getArea() > pathAreaOld.getArea()) { if (intersectionArea < pathAreaOld.getArea() * threshold) continue;
/** * Get the ROI of the selected object, if available, or null * @return */ public ROI getSelectedROI() { if (pathObjectSelected != null) return pathObjectSelected.getROI(); return null; }
/** * Count the descendants of a PathObject recursively, limited to a specific PathClass. * * @param pathObject * @return */ public static int countChildren(final PathObject pathObject, final PathClass pathClass, final boolean allDescendents) { int count = 0; for (PathObject childObject : pathObject.getChildObjects()) { if (pathClass.equals(childObject.getPathClass())) count++; if (childObject.hasChildren() && allDescendents) count += countChildren(childObject, pathClass, allDescendents); } return count; }
boolean checkAllTestsComplete() { if (map.isEmpty() && getParent() != null) { if (countdown == null) { hierarchy.removeObject(this, true); } else if (countdown.decrementAndGet() == 0) { PathObject parent = getParent(); List<PathObject> parallelObjects = new ArrayList<>(); for (PathObject temp : parent.getChildObjects()) { if (temp instanceof ParallelTileObject) { parallelObjects.add(temp); } } parent.removePathObjects(parallelObjects); for (PathObject temp : parallelObjects) parent.addPathObjects(temp.getChildObjects()); if (parent.hasChildren() && parent instanceof PathROIObject) ((PathROIObject)parent).setLocked(true); hierarchy.fireHierarchyChangedEvent(parent); } return true; // getParent().removePathObject(this); // getParent().addPathObjects(getPathObjectList()); } return false; }
PathObject pathObject = pathObjects.get(i); if (withinClass) pathClasses[i] = pathObject.getPathClass() == null ? null : pathObject.getPathClass().getBaseClass(); ROI roi = pathObject.getROI(); xCentroids[i] = (float)roi.getCentroidX(); yCentroids[i] = (float)roi.getCentroidY(); MeasurementList measurementList = pathObject.getMeasurementList(); int ind = 0; for (String name : measurements) { MeasurementList measurementList = pathObject.getMeasurementList(); float[] mValues = measurementValues[i]; float[] mWeighted = measurementsWeighted[i];
private static void addPathObjectsRecursively(Collection<PathObject> pathObjectsInput, List<PathObject> pathObjects, Class<? extends PathObject> cls) { for (PathObject childObject : pathObjectsInput) { if (cls == null || cls.isInstance(childObject)) { pathObjects.add(childObject); } if (childObject.hasChildren()) addPathObjectsRecursively(childObject.getChildObjects(), pathObjects, cls); } }
/** * Extract the specified measurement from a PathObject. * * @param pathObject * @param name * @return */ public static double measurement(final PathObject pathObject, final String measurementName) { return pathObject == null ? Double.NaN : pathObject.getMeasurementList().getMeasurementValue(measurementName); }
/** * Remove all the classifications for a particular class. * * @param pathClass */ public static void resetClassifications(final PathObjectHierarchy hierarchy, final PathClass pathClass) { List<PathObject> changedList = new ArrayList<>(); for (PathObject pathObject : getAnnotations(hierarchy)) { if (pathClass.equals(pathObject.getPathClass())) { pathObject.setPathClass(null); changedList.add(pathObject); } } if (!changedList.isEmpty()) hierarchy.fireObjectClassificationsChangedEvent(null, changedList); }