public void removePathObject(PathObject pathObject) { if (!hasChildren()) return; if (pathObject.parent == this) pathObject.parent = null; //.setParent(null); childList.remove(pathObject); }
public void removePathObjects(Collection<PathObject> pathObjects) { if (!hasChildren()) return; for (PathObject pathObject : pathObjects) { if (pathObject.parent == this) pathObject.parent = null; } childList.removeAll(pathObjects); }
public void clearPathObjects() { if (!hasChildren()) return; for (PathObject pathObject : childList) { if (pathObject.parent == this) pathObject.parent = null; } childList.clear(); }
/** * Check if the hierarchy is empty (i.e. no objects apart from the root object, no feature maps) * * @return */ public synchronized boolean isEmpty() { return (tmaGrid == null || tmaGrid.nCores() == 0) && !rootObject.hasChildren();// && featureMaps.isEmpty(); }
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); } }
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; }
protected String objectCountPostfix() { ROI pathROI = getROI(); if (pathROI instanceof PathPoints) { int nPoints = ((PathPoints)pathROI).getNPoints(); if (nPoints == 1) return " - 1 point"; else return String.format(" - %d points", nPoints); } if (!hasChildren()) return ""; if (childList.size() == 1) return " - 1 object"; else return " - " + childList.size() + " objects"; }
/** * 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; }
@Override public void run() { try { if (!parentObject.hasChildren()) return;
/** * 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 (keepChildren) { for (PathObject child : children) { if (child.hasChildren()) { List<PathObject> newChildList = new ArrayList<>(child.getChildObjects()); newChildList.removeAll(pathObjects);
@Override protected Collection<PathObject> getParentObjects(final PluginRunner<T> runner) { PathObjectHierarchy hierarchy = runner.getImageData().getHierarchy(); List<PathObject> parents = new ArrayList<>(); if (hierarchy.getTMAGrid() != null) { logger.info("Smoothing using TMA cores"); for (TMACoreObject core : hierarchy.getTMAGrid().getTMACoreList()) { if (core.hasChildren()) parents.add(core); } } else { for (PathObject pathObject : hierarchy.getSelectionModel().getSelectedObjects()) { if (pathObject.isAnnotation() && pathObject.hasChildren()) parents.add(pathObject); } if (!parents.isEmpty()) logger.warn("Smoothing using annotations"); } return parents; }
/** * 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); } }
PathObject pathObject = iter.next(); if (pathObject.getPathClass() == null || (pointsOnly && !pathObject.isPoint()) || (!pathObject.isPoint() && !pathObject.hasChildren())) iter.remove(); else
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; }
} else if (!parentObject.hasChildren() || overlapAmount <= 0) { parentObject.addPathObjects(pathObjectsDetected); tryToSetObjectLock(parentObject, true); // Try to lock the parent tryToSetObjectLock(parentObject, parentObject.hasChildren()); // Update the log depending on child status
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; }
if (!pathObjectParent.hasChildren()) {