Class IntersectingObjects<T>

Object
IntersectingObjects<T>
Type Parameters:
T - the type of elements stored in the structure, each of which must map to a ObjectMask.

public class IntersectingObjects<T> extends Object
A data-structure to efficiently determine which object-masks intersect in a collection.

It can store elements of any type, so long each element maps deterministically to an ObjectMask.

Internally, a r-tree data structure is used of object-masks (indexed via a derived bounding-box) for efficient queries. However, search methods check not only bounding-box overlap, but also that objects have at least one overlapping voxel.

All objects that are passed to the constructor are initially included. An existing object may be removed, but no additional object may be added.

Note that when an object is removed, it remains in the objects associated with the r-tree, but is removed from the index.

Author:
Owen Feehan
See Also:
  • Constructor Details

    • IntersectingObjects

      public IntersectingObjects(Collection<T> elements, Function<T,ObjectMask> extractObject)
      Creates an r-tree for particular objects, as extracted from elements.
      Parameters:
      elements - the elements, each corresponding to a unique object.
      extractObject - a function that extracts a unique ObjectMask from an element.
  • Method Details

    • create

      public static IntersectingObjects<ObjectMask> create(ObjectCollection objects)
      Creates from an ObjectCollection.
      Parameters:
      objects - the objects whose intersection will be checked.
      Returns:
      a newly created IntersectingObjects for objects.
    • contains

      public Set<T> contains(Point3i point)
      All elements that contain a particular point.

      Note that the point must exist as an on pixel on the actual ObjectMask, not just within the bounding box of the object.

      Parameters:
      point - the particular point that must exist in all objects that are searched for.
      Returns:
      a newly created set of all elements that contain point, being empty if no objects do.
    • intersectsWith

      public Set<T> intersectsWith(ObjectMask object)
      All elements that intersect with a particular object.
      Parameters:
      object - the object with which objects should intersect
      Returns:
      a newly created set of all elements that intersect with objectToIntersectWith, being empty if no objects intersect.
    • intersectsWithStream

      public Stream<T> intersectsWithStream(ObjectMask object)
      Like intersectsWith(ObjectMask) but returns the objects as a Stream rather than a Set.
      Parameters:
      object - the object with which objects should intersect
      Returns:
      a stream of all objects that intersect with objectToIntersectWith, being empty if no objects intersect.
    • intersectsWith

      public Set<T> intersectsWith(BoundingBox box)
      All elements that intersect with a particular bounding box.
      Parameters:
      box - the bounding-box with which objects should intersect.
      Returns:
      a newly created set of all objects that intersect with box, being empty if no objects intersect.
    • remove

      public void remove(T element)
      Removes an object-mask, so that it is no longer considered in queries.

      Note the associated ObjectCollection remains unchanged.

      If no entry can be found matching exactly the object, no change happens. No error is reported.

      If multiple entries exist that match exactly the object,then all entries are removed.

      Parameters:
      element - the element to remove
    • spatiallySeparate

      public Set<Set<T>> spatiallySeparate()
      Splits the collection of objects into spatially separate clusters.

      Any objects whose bounding-boxes intersect belong to the same cluster, but otherwise not.

      This is similar to a simplified DB Scan algorithm.

      Returns:
      a list of object-collections, each object-collection is guaranteed to be spatially separate from the others.
    • asGraph

      public GraphWithoutPayload<T> asGraph()
      Constructs a graph where each vertex is an element and an edge exists between any elements that intersect.
      Returns:
      a newly created graph, reusing the existing elements as vertices.
    • size

      public int size()
      Number of items in the r-tree.
      Returns:
      the number of items