public static List<PathObject> getFlattenedObjectList(PathObject parentObject, List<PathObject> list, boolean includeParent) { if (list == null) list = new ArrayList<>(); if (includeParent) list.add(parentObject); for (PathObject child : parentObject.getChildObjects()) getFlattenedObjectList(child, list, true); return list; }
public static boolean containsChildOfClass(final PathObject pathObject, final Class<? extends PathObject> cls, final boolean allDescendents) { for (PathObject childObject : pathObject.getChildObjects()) { if (cls.isAssignableFrom(childObject.getClass())) return true; if (childObject.hasChildren() && allDescendents && containsChildOfClass(childObject, cls, allDescendents)) return true; } return false; }
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); } }
/** * Count the descendants of a PathObject recursively. * * @param pathObject * @return */ public static int countDescendants(final PathObject pathObject) { int count = pathObject.nChildObjects(); for (PathObject childObject : pathObject.getChildObjects().toArray(new PathObject[0])) count += countDescendants(childObject); return count; }
/** * Count the descendants of a PathObject recursively, limited to a specific class. * * @param pathObject * @return */ public static int countChildren(final PathObject pathObject, final Class<? extends PathObject> cls, final boolean allDescendents) { int count = 0; for (PathObject childObject : pathObject.getChildObjects()) { if (cls.isAssignableFrom(childObject.getClass())) count++; if (childObject.hasChildren() && allDescendents) count += countChildren(childObject, cls, allDescendents); } return count; }
/** * Get all descendant objects with a specified type * * @param pathObject * @param pathObjects * @param type * @return */ public synchronized List<PathObject> getDescendantObjects(PathObject pathObject, List<PathObject> pathObjects, Class<? extends PathObject> cls) { if (pathObjects == null) pathObjects = new ArrayList<>(); if (pathObject == null || !pathObject.hasChildren()) return pathObjects; addPathObjectsRecursively(pathObject.getChildObjects(), pathObjects, cls); return pathObjects; }
/** * 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; }
if (previousParent.getChildObjects().equals(pathObjects) || previousParent.childList.equals(pathObjects)) { isChildList = true; lastBatchRemoveParent = previousParent;
/** * This doesn't acquire the lock! * * @param pathObject * @param removeChildren */ private void removeFromCache(PathObject pathObject, boolean removeChildren) { // If the cache isn't active, then nothing to remove if (!isActive()) return; //JClass<? extends PathObject> cls = pathObject.getClass(); PathObjectTileMap mapObjects = map.get(pathObject.getClass()); //J //JPathObjectTileMap mapObjects = map.get(cls); if (mapObjects != null) { mapObjects.remove(pathObject); } // Remove the children if (removeChildren) { for (PathObject child : pathObject.getChildObjects()) removeFromCache(child, removeChildren); } }
for (PathObject child : children) { if (child.hasChildren()) { List<PathObject> newChildList = new ArrayList<>(child.getChildObjects()); newChildList.removeAll(pathObjects); parent.addPathObjects(newChildList);
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; }
for (PathObject pathObject : hierarchy.getRootObject().getChildObjects()) { if (pathObject instanceof TMACoreObject) continue;
/** * Add a PathObject to the cache, optionally including children. * * The lock is not acquired here! * * @param pathObject * @param includeChildren */ private void addToCache(PathObject pathObject, boolean includeChildren) { // If the cache isn't active, we can ignore this... it will be constructed when it is needed if (!isActive()) return; if (pathObject.hasROI()) { Class<? extends PathObject> cls = pathObject.getClass(); PathObjectTileMap mapObjects = map.get(cls); if (mapObjects == null) { mapObjects = new PathObjectTileMap(tileSize); map.put(cls, mapObjects); } mapObjects.put(pathObject); } // Add the children if (includeChildren && !(pathObject instanceof TemporaryObject) && pathObject.hasChildren()) { for (PathObject child : pathObject.getChildObjects().toArray(new PathObject[0])) addToCache(child, includeChildren); } }
private synchronized void updateTMAHierarchy() { if (tmaGrid == null) return; // Assign annotations to cores List<PathObject> pathObjectChildren = new ArrayList<>(rootObject.getChildObjects()); rootObject.clearPathObjects(); // Add cores to the start of the object list rootObject.addPathObjects(tmaGrid.getTMACoreList()); // Add back any other objects for (PathObject pathObject : pathObjectChildren) addPathObject(pathObject, false, false); // Notify listeners of changes fireHierarchyChangedEvent(getRootObject()); }
List<PathObject> list = classifications.get(pathClass); list.addAll(pathObject.getChildObjects());
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();
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; }
return true; Collection<PathObject> pathObjects = pathObjectParent.getChildObjects(); if (avoidDuplicates && pathObjects.contains(pathObject)) { logger.warn("Warning: List already contains {}, will not be added again", pathObject);