synchronized void clearTMAGrid() { if (tmaGrid == null) return; removeObjects(new ArrayList<>(tmaGrid.getTMACoreList()), true); // for (TMACoreObject core : tmaGrid.getTMACoreList()) // removeObject(core, true); // this.tmaGrid = null; // Notify listeners of changes fireHierarchyChangedEvent(getRootObject()); }
/** * Add path object as descendant of the requested parent. * * @param pathObjectParent * @param pathObject * @param avoidDuplicates * @param fireUpdate * @return */ public synchronized boolean addPathObjectBelowParent(PathObject pathObjectParent, PathObject pathObject, boolean avoidDuplicates, boolean fireUpdate) { if (pathObjectParent == null) return addPathObject(pathObject, avoidDuplicates, fireUpdate); else return addPathObjectToList(pathObjectParent, pathObject, avoidDuplicates, fireUpdate); }
public synchronized void fireObjectsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) { fireObjectsChangedEvent(source, pathObjects, false); }
public synchronized void setHierarchy(PathObjectHierarchy hierarchy) { if (this == hierarchy) return; rootObject = hierarchy.getRootObject(); tmaGrid = hierarchy.tmaGrid; fireHierarchyChangedEvent(rootObject); }
/** * Get a flattened list containing all PathObjects in the hierarchy (apart from the root object). * * @param list - optional list into which the objects should be added (may be null) * @return */ public synchronized List<PathObject> getFlattenedObjectList(List<PathObject> list) { if (list == null) list = new ArrayList<>(nObjects()); getObjects(list, PathObject.class); return list; }
if (hierarchy == null || hierarchy.isEmpty() || pathObjects.isEmpty()) { logger.warn("Combine annotations: Cannot combine - no annotations found"); return; hierarchy.removeObjects(pathObjects, true); if (areaNew.isEmpty()) { logger.debug("No area ROI remains"); hierarchy.addPathObjects(objectsToAdd, false); hierarchy.fireHierarchyChangedEvent(null);
public static void clearAllObjects(final Class<? extends PathObject> cls) { if (cls == null) { clearAllObjects(); return; } PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return; List<PathObject> pathObjects = hierarchy.getObjects(null, cls); hierarchy.removeObjects(pathObjects, true); PathObject selected = hierarchy.getSelectionModel().getSelectedObject(); if (selected != null && selected.getClass().isAssignableFrom(cls)) hierarchy.getSelectionModel().setSelectedObject(null); }
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()); }
@Override public void taskComplete() { parentObject.clearPathObjects(); parentObject.addPathObjects(tiles); imageData.getHierarchy().fireHierarchyChangedEvent(this, parentObject); if (params.getBooleanParameterValue("removeParentAnnotation") && params.getBooleanParameterValue("makeAnnotations") && parentObject.isAnnotation()) { imageData.getHierarchy().removeObject(parentObject, true); } }
public static void runClassifier(final PathObjectHierarchy hierarchy, final PathObjectClassifier classifier) { // Apply classifier to everything // If we have a TMA grid, do one core at a time long startTime = System.currentTimeMillis(); TMAGrid tmaGrid = hierarchy.getTMAGrid(); List<PathObject> pathObjects = new ArrayList<>(); int nClassified = 0; // tmaGrid = null; if (tmaGrid != null) { for (TMACoreObject core : tmaGrid.getTMACoreList()) { pathObjects = hierarchy.getDescendantObjects(core, pathObjects, PathDetectionObject.class); nClassified += classifier.classifyPathObjects(pathObjects); pathObjects.clear(); } } else { pathObjects = hierarchy.getObjects(null, PathDetectionObject.class); nClassified = classifier.classifyPathObjects(pathObjects); } long endTime = System.currentTimeMillis(); logger.info(String.format("Classification time: %.2f seconds", (endTime-startTime)/1000.)); // Fire a change event for all detection objects if (nClassified > 0) hierarchy.fireObjectClassificationsChangedEvent(classifier, hierarchy.getObjects(null, PathDetectionObject.class)); else logger.warn("No objects classified!"); }
public synchronized boolean addPathObjects(Collection<PathObject> pathObjects, boolean avoidDuplicates) { boolean changes = false; int n = pathObjects.size(); int counter = 0; for (PathObject pathObject : pathObjects) { if (n > 10000) { if (counter % 1000 == 0) logger.info("Adding {} of {}", counter, n); } else if (n > 1000 && counter % 100 == 0) logger.info("Adding {} of {}", counter, n); changes = addPathObjectToList(getRootObject(), pathObject, avoidDuplicates, false) || changes; counter++; } if (changes) fireHierarchyChangedEvent(getRootObject()); // fireChangeEvent(getRootObject()); return changes; }
private static List<PathObject> getAnnotations(PathObjectHierarchy hierarchy) { if (hierarchy == null) return Collections.emptyList(); else return hierarchy.getObjects(null, PathAnnotationObject.class); }
/** * Trigger an update for the specified hierarchy. * * This should be called after any (non-standard) modifications are made to the hierarchy * to ensure that all listeners are notified (including for any GUI). * * @param hierarchy */ public static void fireHierarchyUpdate(final PathObjectHierarchy hierarchy) { if (hierarchy != null) hierarchy.fireHierarchyChangedEvent(QP.class); }
public static void resetTMAMetadata(final PathObjectHierarchy hierarchy, final boolean includeMeasurements) { if (hierarchy == null || hierarchy.getTMAGrid() == null) return; for (TMACoreObject core : hierarchy.getTMAGrid().getTMACoreList()) { core.clearMetadata(); if (includeMeasurements) { core.getMeasurementList().clear(); } } hierarchy.fireObjectsChangedEvent(QP.class, hierarchy.getTMAGrid().getTMACoreList()); }
/** * Delete the selected objects from the current hierarchy, optoonally keeping their child (descendant) objects. * * @param keepChildren */ public static void clearSelectedObjects(boolean keepChildren) { PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return; Collection<PathObject> selectedRaw = hierarchy.getSelectionModel().getSelectedObjects(); List<PathObject> selected = selectedRaw.stream().filter(p -> !(p instanceof TMACoreObject)).collect(Collectors.toList()); hierarchy.removeObjects(selected, keepChildren); hierarchy.getSelectionModel().clearSelection(); }
/** * Reset the intensity classifications for all detections in the specified hierarchy. * * This means setting the classification to the result of <code>getNonIntensityAncestorPathClass(pathObject)</code> * * @param hierarchy */ public static void resetIntensityClassifications(final PathObjectHierarchy hierarchy) { List<PathObject> pathObjects = hierarchy.getObjects(null, PathDetectionObject.class); resetIntensityClassifications(pathObjects); hierarchy.fireObjectClassificationsChangedEvent(QP.class, pathObjects); }
@Override protected void addRunnableTasks(final ImageData<T> imageData, final PathObject parentObject, List<Runnable> tasks) { ParameterList params = getParameterList(imageData); if (params.getBooleanParameterValue("clearAnnotations")) { PathObjectHierarchy hierarchy = imageData.getHierarchy(); List<PathObject> annotations = hierarchy.getDescendantObjects(parentObject, null, PathAnnotationObject.class); hierarchy.removeObjects(annotations, true); } tasks.add(new ClassificationToAnnotationRunnable(params, imageData, parentObject)); }
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; }
Collection<PathObject> overlapObjects = imageData.getHierarchy().getObjectsForRegion(cls, ImageRegion.createInstance(pathROI), null); if (!overlapObjects.isEmpty()) { imageData.getHierarchy().fireHierarchyChangedEvent(parentObject);
PathObjectHierarchy hierarchy2 = new PathObjectHierarchy(); hierarchy2.setHierarchy(hierarchy); hierarchy = hierarchy2; imageData.setImageType(imageType); imageData.getHierarchy().setHierarchy(hierarchy); logger.info(String.format("Hierarchy with %d object(s) read from %s in %.2f seconds", hierarchy.nObjects(), file.getAbsolutePath(), (endTime - startTime)/1000.));