Class BoundingBoxHierarchy

java.lang.Object
qupath.ext.braian.BoundingBoxHierarchy

public class BoundingBoxHierarchy extends Object
The class BoundingBoxHierarchy is data structure that helps in searching for specific PathObject based on their shape and in logarithmic time to the total number of object stored. The cost is paid at construction time, but it should be worth it if the look-up operation is performed at least two times.

BoundingBoxHierarchy was build targeting images with lots (1000+) of PathDetectionObject, but works with all PathObject.

For more information check Bounding volume hierarchy.

  • Constructor Summary

    Constructors
    Constructor
    Description
    BoundingBoxHierarchy(Collection<? extends qupath.lib.objects.PathObject> objects)
    Builds a top-down BVH of maximum 6 levels of hierarchy.
    BoundingBoxHierarchy(Collection<? extends qupath.lib.objects.PathObject> objects, int maxDepth)
    Builds a top-down BVH
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(qupath.lib.objects.PathObject object)
     
    Returns a rectangle in which all objects' ROI are inside
    int
    Compute the BoundingBoxHierarchy's maximum depth
    qupath.lib.objects.PathObject
    getOverlappingObject(qupath.lib.objects.PathObject object)
    Retrieves the object in the hierarchy whose centroid: is inside the specified object is the closest to the specified object's centroid It follows ROI.contains(double, double) definition of insideness for determining the overlap.
    Optional<qupath.lib.objects.PathObject>
    getOverlappingObjectIfPresent(qupath.lib.objects.PathObject object)
    Retrieves the object in the hierarchy whose centroid: is inside the specified object is the closest to the specified object's centroid It follows ROI.contains(double, double) definition of insideness for determining the overlap.
    boolean
     
    Stream<qupath.lib.objects.PathObject>
    Visits each element of the hierarchy and outputs all the objects contained as Stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BoundingBoxHierarchy

      public BoundingBoxHierarchy(Collection<? extends qupath.lib.objects.PathObject> objects)
      Builds a top-down BVH of maximum 6 levels of hierarchy.
      Parameters:
      objects - the given objects to insert into the hierarchy
    • BoundingBoxHierarchy

      public BoundingBoxHierarchy(Collection<? extends qupath.lib.objects.PathObject> objects, int maxDepth)
      Builds a top-down BVH
      Parameters:
      objects - the given objects to insert into the hierarchy
      maxDepth - the maximum depth that that hierarchy can have. Below maxDepth, the recursive structure stops and lists all the remaining objects
  • Method Details

    • getOverlappingObject

      public qupath.lib.objects.PathObject getOverlappingObject(qupath.lib.objects.PathObject object)
      Retrieves the object in the hierarchy whose centroid:
      • is inside the specified object
      • is the closest to the specified object's centroid
      It follows ROI.contains(double, double) definition of insideness for determining the overlap. Which, in turn, relies on Geometry.contains(Geometry) and DE-9IM intersection matrix.
      Parameters:
      object - the object to search the overlap for
      Returns:
      the closest PathObject in the hierarchy, or null if there is no overlap
      See Also:
    • contains

      public boolean contains(qupath.lib.objects.PathObject object)
    • getOverlappingObjectIfPresent

      public Optional<qupath.lib.objects.PathObject> getOverlappingObjectIfPresent(qupath.lib.objects.PathObject object)
      Retrieves the object in the hierarchy whose centroid:
      • is inside the specified object
      • is the closest to the specified object's centroid
      It follows ROI.contains(double, double) definition of insideness for determining the overlap. Which, in turn, relies on Geometry.contains(Geometry) and DE-9IM intersection matrix.
      Parameters:
      object - the object to search the overlap for
      Returns:
      the closest PathObject in the hierarchy as an Optional
      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if there are no PathObject inside
    • toStream

      public Stream<qupath.lib.objects.PathObject> toStream()
      Visits each element of the hierarchy and outputs all the objects contained as Stream.
      Returns:
      the stream of all saved objects
    • getBox

      public Rectangle2D getBox()
      Returns a rectangle in which all objects' ROI are inside
      Returns:
      the bounding box of all objects
    • getDepth

      public int getDepth()
      Compute the BoundingBoxHierarchy's maximum depth
      Returns:
      the maximum depth of the hierarchy. Returns -1 if the BoundingBoxHierarchy is empty.