Class PathObjectHierarchy
- All Implemented Interfaces:
- Serializable
This essentially contains a single PathRootObject from which all other objects can be reached using the child object lists. However, by adding/removing objects via this hierarchy (rather than through the child lists directly), it is possible to maintain a more consistent structure (e.g. by automatically inserting objects as children of the objects whose ROI completely contains the object to be added), along with a spatial cache so that objects can be extracted if their ROIs overlap with a specified region.
Note: Be cautious when deserializing - it may not result in a hierarchy in a valid state. As a workaround, you can construct a new PathObjectHierarchy and call setHierarchy(deserializedHierarchy) to ensure that you have a properly-constructed hierarchy with the same data within it.
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Comparator<PathObject> Comparator to use when looking for a parent annotation in the hierarchy.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddListener(PathObjectHierarchyListener listener) Add a hierarchy change listener.booleanaddObject(PathObject pathObject) Add an object to the hierarchy, firing an event.booleanaddObject(PathObject pathObject, boolean fireUpdate) Add an object to the hierarchy, optionally firing an event.booleanaddObjectBelowParent(PathObject pathObjectParent, PathObject pathObject, boolean fireUpdate) Add path object as descendant of the requested parent.booleanaddObjects(Collection<? extends PathObject> pathObjects) Add multiple objects to the hierarchy.voidclearAll()Remove all objects from the hierarchy.findAllNeighbors(PathObject pathObject) Find all neighbors of a PathObject, having the same class as the object (e.g.findNearestNeighbor(PathObject pathObject) Find the nearest neighbor of a PathObject, having the same class as the object (e.g.voidfireHierarchyChangedEvent(Object source) Fire a hierarchy update indicating the hierarchy structure has changed.voidfireHierarchyChangedEvent(Object source, PathObject pathObject) Fire a hierarchy update indicating the hierarchy structure has changed, impacting descendants of a specified object.voidfireObjectClassificationsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) Fire a hierarchy update indicating object classifications have changed.voidfireObjectMeasurementsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) Fire a hierarchy update indicating object measurements have changed.voidfireObjectMeasurementsChangedEvent(Object source, Collection<? extends PathObject> pathObjects, boolean isChanging) Fire a hierarchy update indicating object measurements have changed.voidfireObjectsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) Fire a hierarchy update indicating objects have changed.voidfireObjectsChangedEvent(Object source, Collection<? extends PathObject> pathObjects, boolean isChanging) Fire a hierarchy update indicating objects have changed, and may still be changing.getAllDetectionsForRegion(ImageRegion region) Get all the detection objects overlapping or close to a specified region.getAllDetectionsForRegion(ImageRegion region, Collection<PathObject> pathObjects) Get all the detection objects overlapping or close to a specified region, optionally adding to an existing collection.Get all the detection objects with centroids falling within the specified ROI - including subclasses of detections, such as cells and tiles.getAllObjects(boolean includeRoot) Get all the objects in the hierarchy, optionally including the root object.getAllObjectsForRegion(ImageRegion region) Get all the objects overlapping or close to a specified region.getAllObjectsForRegion(ImageRegion region, Collection<PathObject> pathObjects) Get all the objects overlapping or close to a specified region, optionally adding to an existing collection.getAllObjectsForROI(ROI roi) Get all objects for a ROI.Get all annotation objects in the hierarchy that have a point (or multi-point) ROI.Get all objects in the hierarchy that have a point (or multi-point) ROI.Get all annotation objects in the hierarchy.getAnnotationsForRegion(ImageRegion region) Get all the annotation objects overlapping or close to a specified region.getAnnotationsForRegion(ImageRegion region, Collection<PathObject> pathObjects) Get all the annotation objects overlapping or close to a specified region, optionally adding to an existing collection.getAnnotationsForROI(ROI roi) Get all the annotations covered by the specified ROI.Get a subdivision containing annotation objects.Get all cell objects in the hierarchy.getCellsForROI(ROI roi) Get all the cell objects with centroids falling within the specified ROI.getCellSubdivision(ImagePlane plane) Get a subdivision containing cell objects.Get all detection objects in the hierarchy (including sub-classes of detections).Get a subdivision containing detections.longGet the number of events that were fired.getFlattenedObjectList(List<PathObject> list) Get a flattened list containing all PathObjects in the hierarchy (including from the root object).getObjects(Collection<PathObject> pathObjects, Class<? extends PathObject> cls) Get all objects in the hierarchy, optionally filtering to return only objects that are instances of a specific class.getObjectsForRegion(Class<? extends PathObject> cls, ImageRegion region, Collection<PathObject> pathObjects) Deprecated.getObjectsForROI(Class<? extends PathObject> cls, ROI roi) Get the objects within a specified ROI, as defined by the general rules for resolving the hierarchy.getPointObjects(Class<? extends PathObject> cls) Deprecated.v0.6.0; usegetAllPointObjects()instead, and filter by object type if required.Get the root object.Get the selection model, which handles the selection status of objects.getSubdivision(PathObject pathObject) Get the subdivision containing a specific PathObject.Get all tile objects in the hierarchy.getTilesForROI(ROI roi) Get all the tile objects with centroids falling within the specified ROI.Get the TMAGrid, or null if there is no TMA grid associated with this hierarchy.booleanhasAnnotationsForRegion(ImageRegion region) Returns true if the hierarchy contains any annotation objects intersecting a specific region.booleanhasDetectionsForRegion(ImageRegion region) Returns true if the hierarchy contains any detection objects (including subclasses) intersecting a specific region.booleanhasObjectsForRegion(Class<? extends PathObject> cls, ImageRegion region) Returns true if the hierarchy contains objects overlapping a specific region, optionally filtering to identify only objects of a specific class.booleanhasObjectsForRegion(ImageRegion region) Returns true if the hierarchy contains any objects intersecting a specific region.booleaninsertPathObject(PathObject pathObject, boolean fireChangeEvents) Insert an object into the hierarchy.booleaninsertPathObjects(Collection<? extends PathObject> pathObjects) Insert a collection of objects into the hierarchy, firing a change event on completion.booleanisEmpty()Check if the hierarchy is empty (i.e.intnObjects()Number of objects in the hierarchy, excluding the root.voidremoveListener(PathObjectHierarchyListener listener) Remove a hierarchy change listener.booleanremoveObject(PathObject pathObject, boolean keepChildren) Remove a single object from the hierarchy, firing a remove event.voidremoveObjects(Collection<? extends PathObject> pathObjects, boolean keepChildren) Remove a collection of objects, firing a single 'hierarchy changed' event afterwards to notify listeners if anything happened (i.e.booleanremoveObjectWithoutUpdate(PathObject pathObject, boolean keepChildren) Remove a single object from the hierarchy, without firing a remove event.voidAttempt to resolve the parent-child relationships between all objects within the hierarchy.voidsetHierarchy(PathObjectHierarchy hierarchy) Set the contents of this hierarchy to be the same as that of another hierarchy.voidsetTMAGrid(TMAGrid tmaGrid) Set the tma grid for this hierarchy.toString()voidupdateObject(PathObject pathObject, boolean isChanging) Update an object that is already in the hierarchy (e.g.
- 
Field Details- 
HIERARCHY_COMPARATORComparator to use when looking for a parent annotation in the hierarchy. The logic is:- Sort by area (smallest first)
- Sort by hierarchy level (deepest first)
- Sort by DefaultPathObjectComparator
 
 
- 
- 
Constructor Details- 
PathObjectHierarchypublic PathObjectHierarchy()Default constructor, creates an empty hierarchy.
 
- 
- 
Method Details- 
isEmptypublic boolean isEmpty()Check if the hierarchy is empty (i.e. no objects apart from the root object, no feature maps)- Returns:
 
- 
addListenerAdd a hierarchy change listener.- Parameters:
- listener-
- Since:
- v0.4.0; replaced addPathObjectListener(PathObjectHierarchyListener)
 
- 
removeListenerRemove a hierarchy change listener.- Parameters:
- listener-
- Since:
- v0.4.0; replaced removePathObjectListener(PathObjectHierarchyListener)
 
- 
getRootObjectGet the root object. All other objects in the hierarchy are descendants of the root.- Returns:
 
- 
getTMAGridGet the TMAGrid, or null if there is no TMA grid associated with this hierarchy.- Returns:
 
- 
getSelectionModelGet the selection model, which handles the selection status of objects.- Returns:
 
- 
setTMAGridSet the tma grid for this hierarchy. If identical to the current TMA grid, nothing will happen. Otherwise, if null then any existing TMA grid will be removed.- Parameters:
- tmaGrid-
 
- 
insertPathObjectInsert an object into the hierarchy. This differs fromaddObject(PathObject, boolean)in that it will seek to place the object in an appropriate location relative to existing objects, using the logic ofHIERARCHY_COMPARATOR.- Parameters:
- pathObject- the object to add
- fireChangeEvents- if true, an event will be added after adding the object. Choose false if a single event should be added after making multiple changes.
- Returns:
- true if the hierarchy changed as a result of this call, false otherwise
 
- 
insertPathObjectsInsert a collection of objects into the hierarchy, firing a change event on completion. This differs fromaddObjects(Collection)in that it will seek to place the object in an appropriate location relative to existing objects, using the logic ofHIERARCHY_COMPARATOR.- Parameters:
- pathObjects- the objects to add
- Returns:
- true if the hierarchy changed as a result of this call, false otherwise
 
- 
resolveHierarchypublic void resolveHierarchy()Attempt to resolve the parent-child relationships between all objects within the hierarchy.
- 
removeObjectRemove a single object from the hierarchy, firing a remove event.- Parameters:
- pathObject- the object to remove
- keepChildren- if true, retain all children and descendants of the object being removed; if false, remove these also
- Returns:
 
- 
removeObjectWithoutUpdateRemove a single object from the hierarchy, without firing a remove event.- Parameters:
- pathObject- the object to remove
- keepChildren- if true, retain all children and descendants of the object being removed; if false, remove these also
- Returns:
 
- 
removeObjectsRemove a collection of objects, firing a single 'hierarchy changed' event afterwards to notify listeners if anything happened (i.e. if any of the objects really were found within the hierarchy) & removed.- Parameters:
- pathObjects- the objects to remove
- keepChildren- if true, retain children and descendants of the objects being removed
 
- 
addObjectAdd an object to the hierarchy, firing an event.- Parameters:
- pathObject-
- Returns:
 
- 
addObjectAdd an object to the hierarchy, optionally firing an event.- Parameters:
- pathObject-
- fireUpdate-
- Returns:
- Since:
- v0.4.0; replaces addPathObjectWithoutUpdate(PathObject)
 
- 
addObjectBelowParentpublic boolean addObjectBelowParent(PathObject pathObjectParent, PathObject pathObject, boolean fireUpdate) Add path object as descendant of the requested parent.- Parameters:
- pathObjectParent-
- pathObject-
- fireUpdate-
- Returns:
- Since:
- v0.4.0 (replaces addPathObjectBelowParent(PathObject, PathObject, boolean)
 
- 
addObjectsAdd multiple objects to the hierarchy.- Parameters:
- pathObjects-
- Returns:
- Since:
- v0.4.0; replaces addPathObjects(Collection)
 
- 
clearAllpublic void clearAll()Remove all objects from the hierarchy.
- 
getPointObjectsDeprecated.v0.6.0; usegetAllPointObjects()instead, and filter by object type if required.Get objects that contain Point ROIs.- Parameters:
- cls-
- Returns:
 
- 
getAllPointObjectsGet all objects in the hierarchy that have a point (or multi-point) ROI.- Returns:
 
- 
getAllPointAnnotationsGet all annotation objects in the hierarchy that have a point (or multi-point) ROI.- Returns:
 
- 
getCellObjectsGet all cell objects in the hierarchy.- Returns:
 
- 
getTileObjectsGet all tile objects in the hierarchy.- Returns:
 
- 
getDetectionObjectsGet all detection objects in the hierarchy (including sub-classes of detections).- Returns:
 
- 
getAnnotationObjectsGet all annotation objects in the hierarchy.- Returns:
 
- 
getObjectspublic Collection<PathObject> getObjects(Collection<PathObject> pathObjects, Class<? extends PathObject> cls) Get all objects in the hierarchy, optionally filtering to return only objects that are instances of a specific class. Note that this method returns the root object, unless it has been filtered out.- Parameters:
- pathObjects-
- cls-
- Returns:
 
- 
updateObjectUpdate an object that is already in the hierarchy (e.g. because its ROI has changed).- Parameters:
- pathObject- the object to update
- isChanging- if true, indicate that the object is still being changed. Some listeners may delay processing in expectation of an update event where isChanging is false.
 
- 
getFlattenedObjectListGet a flattened list containing all PathObjects in the hierarchy (including from the root object).To get a flattened list containing all PathObjects without the root object, one can run the following:
 getFlattenedObjectList(null).stream().filter(p -> !p.isRootObject()).toList()Or, since v0.4.0, just use getAllObjects(boolean)instead.- Parameters:
- list-
- Returns:
- Since:
- getAllObjects(boolean)
 
- 
getAllObjectsGet all the objects in the hierarchy, optionally including the root object.- Parameters:
- includeRoot-
- Returns:
- Since:
- v0.4.0
 
- 
nObjectspublic int nObjects()Number of objects in the hierarchy, excluding the root.- Returns:
 
- 
setHierarchySet the contents of this hierarchy to be the same as that of another hierarchy. In practice, this means copying the root and TMA grid of the second hierarchy.- Parameters:
- hierarchy-
 
- 
getObjectsForROIGet the objects within a specified ROI, as defined by the general rules for resolving the hierarchy. This relies on centroids for detections (including subclasses), and a 'covers' rule for others (annotations, TMA cores).Note: Since v0.6.0 use of this method is discouraged, and it may be deprecated and/or removed in a future release. Instead use getAllObjectsForROI(ROI)and filter the returned collection; or, alternatively, usegetAnnotationsForROI(ROI),getCellsForROI(ROI),getAllDetectionsForROI(ROI)orgetTilesForROI(ROI).- Parameters:
- cls- class of PathObjects (e.g. PathDetectionObject), or null to accept all
- roi-
- Returns:
 
- 
getAllObjectsForROIGet all objects for a ROI. This uses the same rules asresolveHierarchy(): annotations must be completely covered by the ROI, while detections need only have their centroid within the ROI.- Parameters:
- roi-
- Returns:
- Since:
- v0.6.0
- See Also:
 
- 
getAnnotationsForROIGet all the annotations covered by the specified ROI.- Parameters:
- roi- the ROI to use for filtering
- Returns:
- a collection of annotation objects that are completely covered by the specified ROI
- Since:
- v0.6.0
- See Also:
- Implementation Requirements
- This does not return all annotations that intersect with the ROI,
           but rather only those that are covered by the ROI - consistent with the
           behavior of resolveHierarchy().
 
- 
getTilesForROIGet all the tile objects with centroids falling within the specified ROI. Tile objects are a special subclass of detections.- Parameters:
- roi- the ROI to use for filtering
- Returns:
- a collection of tile objects with centroids contained within the specified ROI
- Since:
- v0.6.0
- See Also:
- Implementation Requirements
- This does not return all tiles that intersect with the ROI,
           but rather only those whose centroid falls within the ROI - consistent with the
           behavior of resolveHierarchy().
 
- 
getCellsForROIGet all the cell objects with centroids falling within the specified ROI. Cell objects are a special subclass of detections.- Parameters:
- roi- the ROI to use for filtering
- Returns:
- a collection of cell objects with centroids contained within the specified ROI
- Since:
- v0.6.0
- See Also:
- Implementation Requirements
- This does not return all cells that intersect with the ROI,
           but rather only those whose centroid falls within the ROI - consistent with the
           behavior of resolveHierarchy().
 
- 
getAllDetectionsForROIGet all the detection objects with centroids falling within the specified ROI - including subclasses of detections, such as cells and tiles.- Parameters:
- roi- the ROI to use for filtering
- Returns:
- a collection of detection objects with centroids contained within the specified ROI
- Since:
- v0.6.0
- See Also:
- Implementation Requirements
- This does not return all cells that intersect with the ROI,
           but rather only those whose centroid falls within the ROI - consistent with the
           behavior of resolveHierarchy().
 
- 
getObjectsForRegion@Deprecated public Collection<PathObject> getObjectsForRegion(Class<? extends PathObject> cls, ImageRegion region, Collection<PathObject> pathObjects) Deprecated.v0.6.0, usegetAllObjectsForRegion(ImageRegion, Collection)or its related methods instead.Get the objects overlapping or close to a specified region. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- cls- class of object to return (subclasses are included)
- region- requested region overlapping the objects ROI
- pathObjects- optionally collection to which objects will be added
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- See Also:
 
- 
getAllObjectsForRegionpublic Collection<PathObject> getAllObjectsForRegion(ImageRegion region, Collection<PathObject> pathObjects) Get all the objects overlapping or close to a specified region, optionally adding to an existing collection. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- region- requested region overlapping the objects ROI
- pathObjects- optional collection to which objects will be added
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- Since:
- v0.6.0
- See Also:
 
- 
getAllObjectsForRegionGet all the objects overlapping or close to a specified region. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- region- requested region overlapping the objects ROI
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- Since:
- v0.6.0
- See Also:
 
- 
getAnnotationsForRegionpublic Collection<PathObject> getAnnotationsForRegion(ImageRegion region, Collection<PathObject> pathObjects) Get all the annotation objects overlapping or close to a specified region, optionally adding to an existing collection. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- region- requested region overlapping the objects ROI
- pathObjects- optional collection to which objects will be added
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- Since:
- v0.6.0
- See Also:
 
- 
getAnnotationsForRegionGet all the annotation objects overlapping or close to a specified region. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- region- requested region overlapping the objects ROI
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- Since:
- v0.6.0
- See Also:
 
- 
getAllDetectionsForRegionpublic Collection<PathObject> getAllDetectionsForRegion(ImageRegion region, Collection<PathObject> pathObjects) Get all the detection objects overlapping or close to a specified region, optionally adding to an existing collection. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- region- requested region overlapping the objects ROI
- pathObjects- optional collection to which objects will be added
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- Since:
- v0.6.0
- See Also:
 
- 
getAllDetectionsForRegionGet all the detection objects overlapping or close to a specified region. Note that this performs a quick check; the results typically should be filtered if a more strict test for overlapping is applied.- Parameters:
- region- requested region overlapping the objects ROI
- Returns:
- collection containing identified objects (same as the input collection, if provided)
- Since:
- v0.6.0
- See Also:
 
- 
hasObjectsForRegionReturns true if the hierarchy contains objects overlapping a specific region, optionally filtering to identify only objects of a specific class.- Parameters:
- cls-
- region-
- Returns:
- Since:
- v0.6.0
 
- 
hasObjectsForRegionReturns true if the hierarchy contains any objects intersecting a specific region. This is similar togetAllObjectsForRegion(ImageRegion, Collection), but does not return the objects themselves.- Parameters:
- region-
- Returns:
- true if objects are found, false otherwise.
- Since:
- v0.6.0
- See Also:
 
- 
hasAnnotationsForRegionReturns true if the hierarchy contains any annotation objects intersecting a specific region. This is similar togetAnnotationsForRegion(ImageRegion, Collection), but does not return the objects themselves.- Parameters:
- region-
- Returns:
- true if annotations are found, false otherwise.
- Since:
- v0.6.0
- See Also:
 
- 
hasDetectionsForRegionReturns true if the hierarchy contains any detection objects (including subclasses) intersecting a specific region. This is similar togetAllDetectionsForRegion(ImageRegion, Collection), but does not return the objects themselves.- Parameters:
- region-
- Returns:
- true if detections are found, false otherwise.
- Since:
- v0.6.0
- See Also:
 
- 
fireObjectMeasurementsChangedEventpublic void fireObjectMeasurementsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) Fire a hierarchy update indicating object measurements have changed.- Parameters:
- source-
- pathObjects-
 
- 
fireObjectMeasurementsChangedEventpublic void fireObjectMeasurementsChangedEvent(Object source, Collection<? extends PathObject> pathObjects, boolean isChanging) Fire a hierarchy update indicating object measurements have changed.- Parameters:
- source-
- pathObjects-
- isChanging-
 
- 
fireObjectClassificationsChangedEventpublic void fireObjectClassificationsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) Fire a hierarchy update indicating object classifications have changed.- Parameters:
- source-
- pathObjects-
 
- 
fireObjectsChangedEventFire a hierarchy update indicating objects have changed.- Parameters:
- source-
- pathObjects-
 
- 
fireObjectsChangedEventpublic void fireObjectsChangedEvent(Object source, Collection<? extends PathObject> pathObjects, boolean isChanging) Fire a hierarchy update indicating objects have changed, and may still be changing.- Parameters:
- source-
- pathObjects-
- isChanging- is true, listeners may choose not to respond until an event is fired with isChanging false
 
- 
fireHierarchyChangedEventFire a hierarchy update indicating the hierarchy structure has changed, impacting descendants of a specified object.- Parameters:
- source-
- pathObject-
 
- 
fireHierarchyChangedEventFire a hierarchy update indicating the hierarchy structure has changed. This is often a good choice of event if multiple changes may have occurred, of if one is unsure what exactly has changed.- Parameters:
- source-
 
- 
getEventCountpublic long getEventCount()Get the number of events that were fired.Important notes: - This is a transient property (not stored in the data file)
- The value is incremented before> listeners have been notified (so that a listener may query it)
 - Returns:
- a timestamp
- Since:
- v0.6.0
 
- 
findAllNeighborsFind all neighbors of a PathObject, having the same class as the object (e.g. detection, cell, annotation). This is based on centroids and Delaunay triangulation. It also assumes 'square' pixels, and searches for neighbors only on the same 2D plane (z and t).- Parameters:
- pathObject-- This is an experimental method added in v0.6.0, subject to change. 
- Returns:
- Since:
- v0.6.0
 
- 
findNearestNeighborFind the nearest neighbor of a PathObject, having the same class as the object (e.g. detection, cell, annotation). This is based on centroids and Delaunay triangulation. It also assumes 'square' pixels, and searches for neighbors only on the same 2D plane (z and t).This is an experimental method added in v0.6.0, subject to change. - Parameters:
- pathObject-
- Returns:
- Since:
- v0.6.0
 
- 
getSubdivisionGet the subdivision containing a specific PathObject. This is based on centroids and Delaunay triangulation in 2D. It supports #findAllNeighbors(PathObject) and #findNearestNeighbor(PathObject); obtaining the subdivision enables a wider range of spatial queries.This is an experimental method added in v0.6.0, subject to change. - Parameters:
- pathObject-
- Returns:
- Since:
- v0.6.0
 
- 
getDetectionSubdivisionGet a subdivision containing detections. This does not include sub-classes such as 'cell' or 'tile'.This is an experimental method added in v0.6.0, subject to change. - Parameters:
- plane-
- Returns:
- Since:
- v0.6.0
 
- 
getCellSubdivisionGet a subdivision containing cell objects.This is an experimental method added in v0.6.0, subject to change. - Parameters:
- plane-
- Returns:
- Since:
- v0.6.0
 
- 
getAnnotationSubdivisionGet a subdivision containing annotation objects.This is an experimental method added in v0.6.0, subject to change. - Parameters:
- plane-
- Returns:
- Since:
- v0.6.0
 
- 
toString
 
- 
getAllObjectsForRegion(ImageRegion, Collection)or its related methods instead.